:root {
  color: #31101d;
  background: #f8f0e7;
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  --wine: #5b1632;
  --wine-dark: #3e0e22;
  --ivory: #fffaf3;
  --line: #dac7bd;
  --muted: #735f67;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
    env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: linear-gradient(180deg, #f4e6dc, #fffaf3 18rem);
}

.topbar,
main {
  width: min(100% - 1.5rem, 48rem);
  margin-inline: auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-block: 1.4rem 1rem;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(2rem, 9vw, 3.3rem); letter-spacing: -.05em; }
h2 { font-size: 1.15rem; }
.eyebrow { margin-bottom: .2rem; color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; }

main { display: grid; gap: 1rem; padding-bottom: 3rem; }

.card {
  padding: 1rem;
  border: 1px solid rgba(91, 22, 50, .14);
  border-radius: 1.15rem;
  background: rgba(255, 250, 243, .94);
  box-shadow: 0 .75rem 2rem rgba(62, 14, 34, .08);
}

form, label { display: grid; gap: .4rem; }
form { gap: .8rem; }
input { min-width: 0; font: inherit; }
input:not([type="file"]) {
  width: 100%; min-height: 2.9rem; padding: .7rem .8rem;
  border: 1px solid var(--line); border-radius: .7rem; background: white;
}

button, .button-link, .file-cta {
  min-height: 2.85rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: .7rem .9rem;
  border: 0;
  border-radius: .75rem;
  background: var(--wine);
  color: white;
  font: 650 .95rem/1.2 inherit;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled { opacity: .45; cursor: not-allowed; }
.secondary, .secondary-file, .button-link.secondary { background: #eadbd3; color: var(--wine-dark); }
.danger { background: #812747; }
.actions { display: flex; flex-wrap: wrap; gap: .55rem; margin-top: .85rem; }
.actions > * { flex: 1 1 10rem; }
.file-cta { margin-bottom: .6rem; }
.file-cta input { position: absolute; width: 1px; height: 1px; opacity: 0; }

.muted { color: var(--muted); }
.notice { margin: .8rem 0 0; padding: .75rem; border-radius: .7rem; background: #f1e2b8; }
.pill { padding: .35rem .6rem; border-radius: 999px; background: #eadbd3; font-size: .8rem; }

.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; }
.facts div { min-width: 0; padding: .65rem; border-radius: .7rem; background: #f5ebe5; }
.facts dt { color: var(--muted); font-size: .75rem; }
.facts dd { margin: .2rem 0 0; overflow-wrap: anywhere; }

.log {
  min-height: 2.7rem;
  max-height: 15rem;
  overflow: auto;
  margin: .8rem 0 0;
  padding: .7rem;
  border-radius: .65rem;
  background: #26101a;
  color: #f8ece4;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: .76rem/1.45 ui-monospace, SFMono-Regular, Consolas, monospace;
}

.preview-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .7rem; margin-top: .9rem; }
figure { margin: 0; min-width: 0; }
figcaption { margin-bottom: .35rem; color: var(--muted); font-size: .8rem; }
.preview-grid img, .result-thumb {
  display: block; width: 100%; aspect-ratio: 4 / 5; object-fit: contain;
  border: 1px solid var(--line); border-radius: .8rem; background: #efe2da;
}
.result-thumb { max-height: 24rem; }
.progress-label, progress { width: 100%; margin-top: .8rem; }

.viewer {
  width: 100vw; max-width: none; height: 100dvh; max-height: none;
  margin: 0; padding: env(safe-area-inset-top) env(safe-area-inset-right)
    env(safe-area-inset-bottom) env(safe-area-inset-left);
  border: 0; background: #15090f; color: white; overflow: hidden;
}
.viewer::backdrop { background: #15090f; }
.viewer[open] { display: grid; grid-template-rows: auto 1fr auto; }
.viewer-close { position: relative; z-index: 2; justify-self: end; margin: .6rem; background: rgba(255,255,255,.16); }
.viewer-stage { min-height: 0; overflow: hidden; display: grid; place-items: center; touch-action: none; }
.viewer-stage img { width: min(90vw, 34rem); max-height: 78dvh; object-fit: contain; user-select: none; -webkit-user-drag: none; transform-origin: center; will-change: transform; }
.viewer-help { margin: .5rem 1rem 1rem; text-align: center; color: #dbcbd2; font-size: .8rem; }

@media (orientation: landscape) and (max-height: 35rem) {
  .topbar { padding-block: .5rem; }
  .viewer-help { display: none; }
  .viewer-stage img { max-height: 70dvh; }
}

@media (max-width: 28rem) {
  .facts { grid-template-columns: 1fr; }
  .preview-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
