:root {
  --paper: #f3ece1;
  --paper-2: #ebe2d4;
  --ink: #2a2320;
  --ink-soft: #6d6058;
  --red: #9d1c24;
  --red-deep: #6f1218;
  --gold: #e9c27a;
  --line: rgba(42, 35, 32, 0.16);
  --script: "Pinyon Script", cursive;
  --serif: "Cormorant Garamond", Georgia, serif;
  --mono: "Courier Prime", ui-monospace, monospace;
  --ease-spring: cubic-bezier(0.2, 0.9, 0.25, 1.15);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 500 18px/1.45 var(--serif);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible { outline: 2px solid var(--red); outline-offset: 3px; }

.screen { display: none; min-height: 100dvh; }
.screen.active { display: grid; }

.script { font-family: var(--script); font-weight: 400; }
.brand { font: 400 15px var(--mono); color: var(--ink-soft); margin: 0 0 18px; }
.fine { font-size: 14px; color: var(--ink-soft); margin: 10px 0 0; }

/* buttons */
.btn {
  border: 1px solid var(--ink);
  background: transparent;
  border-radius: 999px;
  padding: 13px 26px;
  font-weight: 600;
  font-size: 17px;
  transition: transform .15s, background .15s, color .15s;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--red); border-color: var(--red); color: #fbf3e8; box-shadow: 0 6px 18px -8px rgba(111, 18, 24, .6); }
.btn.primary:hover { background: var(--red-deep); }
.btn.ghost { border-color: rgba(255,255,255,.55); color: #fff; background: rgba(0,0,0,.18); backdrop-filter: blur(6px); }
.btn.small { padding: 7px 16px; font-size: 14px; }
.btn[disabled] { opacity: .5; pointer-events: none; }
kbd { font: 12px var(--mono); opacity: .75; margin-left: 6px; }
.link { background: none; border: 0; padding: 0; text-decoration: underline; text-underline-offset: 3px; color: var(--ink-soft); }

/* ---------- HOME ---------- */
#home { grid-template-columns: minmax(0, 1fr) minmax(0, 0.9fr); }
.home-copy { padding: clamp(28px, 6vw, 80px) clamp(16px, 5vw, 72px); max-width: 640px; align-self: center; }
h1 { margin: 0 0 26px; font-weight: 500; }
h1 .script { display: block; font-size: clamp(64px, 9vw, 112px); line-height: 1; color: var(--red); margin-left: -4px; }
h1 .sub { display: block; font: italic 400 clamp(20px, 2.2vw, 26px)/1.3 var(--serif); color: var(--ink-soft); margin-top: 12px; }
.steps { padding: 0; margin: 0 0 30px; list-style: none; counter-reset: s; display: grid; gap: 10px; }
.steps li { counter-increment: s; position: relative; padding-left: 34px; color: var(--ink-soft); }
.steps li::before { content: counter(s); position: absolute; left: 0; top: 3px; font: 400 15px var(--mono); color: var(--red); }
.steps b { color: var(--ink); font-weight: 600; }

.opt { border: 0; padding: 0; margin: 0 0 20px; min-width: 0; }
.opt legend { font: 400 14px var(--mono); color: var(--ink-soft); margin-bottom: 8px; padding: 0; }
.opt-row { display: flex; gap: 0 28px; flex-wrap: wrap; }

.layouts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.layouts button {
  border: 1px solid var(--line); background: rgba(255,255,255,.35); border-radius: 14px;
  padding: 14px 10px 12px; display: grid; justify-items: center; gap: 2px; transition: border-color .15s, background .15s;
}
.layouts button[aria-checked="true"] { border-color: var(--red); background: #fffaf2; box-shadow: inset 0 0 0 1px var(--red); }
.layouts span { font-weight: 600; font-size: 16px; }
.layouts small { font: 12px var(--mono); color: var(--ink-soft); }
.ico { display: grid; gap: 3px; padding: 4px; background: #fff; border: 1px solid var(--line); margin-bottom: 8px; height: 62px; }
.ico s { background: var(--ink); opacity: .78; border-radius: 1.5px; }
.ico.l14 { grid-template-columns: 16px; grid-template-rows: repeat(4, 1fr); width: 26px; }
.ico.l22 { grid-template-columns: repeat(2, 16px); grid-template-rows: repeat(2, 1fr); width: 44px; }
.ico.l23 { grid-template-columns: repeat(2, 16px); grid-template-rows: repeat(3, 1fr); width: 44px; }
.layouts button[aria-checked="true"] .ico s { background: var(--red); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips { position: relative; }
.chips button { position: relative; z-index: 1; border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 6px 14px; font-size: 15px; font-weight: 600; transition: color .3s, border-color .3s; }
.chips button[aria-checked="true"] { color: var(--paper); border-color: var(--ink); }
/* sliding highlight: app.js moves it under the chosen option */
.chips .pill { position: absolute; z-index: 0; border-radius: 999px; background: var(--ink); transition: left .45s var(--ease-spring), top .45s var(--ease-spring), width .45s var(--ease-spring), height .45s var(--ease-spring); }

.cta { margin-top: 12px; }

.home-preview {
  position: relative; overflow: hidden;
  background: radial-gradient(120% 90% at 30% 20%, #7b1a20 0%, #4a0d12 55%, #2b070a 100%);
  display: grid; place-items: center; padding: 40px 16px;
}
.home-preview::before { /* velvet curtain folds */
  content: ""; position: absolute; inset: 0; opacity: .5;
  background: repeating-linear-gradient(90deg, rgba(0,0,0,.35) 0 18px, rgba(255,255,255,.04) 30px, rgba(0,0,0,.3) 52px);
}
.preview-surface { position: relative; transform: rotate(-4deg); transition: transform .6s var(--ease-spring); }
.preview-surface:hover { transform: rotate(-2deg) translateY(-6px); }
#preview { display: block; max-height: min(78dvh, 760px); max-width: 100%; box-shadow: 0 30px 60px -20px rgba(0,0,0,.7), 0 4px 10px rgba(0,0,0,.35); }

/* ---------- BOOTH ---------- */
#booth { position: fixed; inset: 0; background: #0d0b0a; color: #fff; overflow: hidden; display: none; }
#booth.active { display: block; }
#cam, #overlay { position: absolute; inset: 0; width: 100%; height: 100%; }
#cam { object-fit: cover; transform: scaleX(-1); transition: filter .4s; }
.booth-top { position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: flex-start; padding: max(16px, env(safe-area-inset-top)) 20px 0; pointer-events: none; }
.wordmark { margin: 0; font: 400 clamp(38px, 5vw, 60px)/1 var(--script); color: #fff6ef; text-shadow: 2px 2px 0 rgba(176, 30, 40, .85), 0 0 18px rgba(255, 120, 120, .45); }
.booth-btns { display: flex; gap: 8px; pointer-events: auto; }
.icon-btn { width: 42px; height: 42px; border-radius: 50%; border: 1px solid rgba(255,255,255,.35); background: rgba(0,0,0,.25); backdrop-filter: blur(8px); display: grid; place-items: center; color: #fff; }
.icon-btn svg { width: 20px; height: 20px; fill: currentColor; }
.icon-btn[aria-pressed="true"] .wave { display: none; }
.icon-btn .slash { display: none; }
.icon-btn[aria-pressed="true"] .slash { display: inline; }
.icon-btn[hidden] { display: none; }

.loading { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 14px; background: #0d0b0a; font: italic 400 22px var(--serif); color: #e9dfd2; transition: opacity .5s; }
.loading.hide { opacity: 0; pointer-events: none; }
.loading .dot { width: 14px; height: 14px; border-radius: 50%; background: var(--red); box-shadow: 0 0 0 0 rgba(157,28,36,.7); animation: pulse 1.4s infinite; }
@keyframes pulse { to { box-shadow: 0 0 0 22px rgba(157,28,36,0); } }

.countdown {
  position: absolute; left: 50%; top: 44%; transform: translate(-50%, -50%);
  font: 400 min(42vh, 360px)/1 var(--script); pointer-events: none;
  color: transparent; -webkit-text-stroke: 1.5px rgba(255,255,255,.95);
  background-image: var(--glitter); background-size: 180px; -webkit-background-clip: text; background-clip: text;
  filter: drop-shadow(7px 6px 0 #c3222c) drop-shadow(0 0 26px rgba(255,255,255,.45));
}
.countdown.tick { animation: tick .62s var(--ease-spring); }
@keyframes tick { from { transform: translate(-50%, -50%) scale(1.5) rotate(-6deg); opacity: 0; } 30% { opacity: 1; } to { transform: translate(-50%, -50%) scale(1) rotate(0); } }

.flash { position: absolute; inset: 0; background: #fffaf2; opacity: 0; pointer-events: none; }
.flash.fill { opacity: .97; animation: none; }
.flash.go { animation: flash .55s ease-out; }
@keyframes flash { 0% { opacity: .95; } 100% { opacity: 0; } }

.print {
  position: absolute; left: 50%; top: 46%; width: min(56vw, 68vh); padding: 2.2% 2.2% 7%;
  background: #f7f3ec; box-shadow: 0 30px 60px -10px rgba(0,0,0,.6); pointer-events: none;
  transform: translate(-50%, -50%) rotate(-3deg); opacity: 0;
}
.print img { display: block; width: 100%; }
.print i { font-style: normal; display: inline-block; animation: wordIn .5s var(--ease-spring) backwards; animation-delay: calc(var(--i) * 70ms + 420ms); }
@keyframes wordIn { from { opacity: 0; transform: translateY(.45em); filter: blur(3px); } }
.print span { position: absolute; left: 4%; right: 4%; bottom: 1.6%; text-align: center; white-space: nowrap; overflow: hidden; font: 400 clamp(12px, 1.7vw, 22px) "Homemade Apple", cursive; color: #3a2a24; }

.booth-bottom { position: absolute; left: 0; right: 0; bottom: 0; padding: 0 16px max(14px, env(safe-area-inset-bottom)); text-align: center; background: linear-gradient(transparent, rgba(0,0,0,.45) 45%, rgba(0,0,0,.6)); }
.meta { margin: 0; font: italic 400 clamp(15px, 1.6vw, 19px) var(--serif); color: rgba(255,246,238,.88); text-shadow: 0 1px 6px rgba(0,0,0,.5); }
.instruction { margin: 0; font: 400 clamp(34px, 4.6vw, 58px)/1.15 var(--script); color: #fff; text-shadow: 2px 2px 0 rgba(176,30,40,.8), 0 2px 14px rgba(0,0,0,.45); min-height: 1.15em; }
.hint { margin: 2px 0 8px; font: 500 15px var(--serif); color: #ffe6b8; min-height: 1.4em; text-shadow: 0 1px 6px rgba(0,0,0,.6); }
.snap-row { margin-bottom: 10px; display: flex; gap: 8px; justify-content: center; }
.btn[hidden] { display: none; }
.link.light { color: #e9dfd2; margin-top: 8px; font-style: normal; }
.tray { list-style: none; padding: 0; margin: 0 auto; display: flex; gap: 8px; justify-content: center; }
.tray li { width: clamp(46px, 7vw, 76px); aspect-ratio: var(--cell, 1.27); border-radius: 6px; border: 1px solid rgba(255,255,255,.35); background: rgba(0,0,0,.35); overflow: hidden; position: relative; transition: border-color .2s, transform .3s var(--ease-spring); }
.tray li canvas { width: 100%; height: 100%; object-fit: contain; opacity: .55; }
.tray li img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tray li.now { border-color: var(--gold); transform: translateY(-4px); box-shadow: 0 0 0 2px rgba(233,194,122,.35); }
.tray li.now canvas { opacity: .95; }

/* ---------- RESULT ---------- */
#result { grid-template-columns: minmax(0, 1fr) minmax(320px, 440px); background: var(--paper); }
.result-stage { position: relative; display: grid; justify-items: center; align-content: start; padding: 26px 16px 40px; overflow: hidden; background: radial-gradient(100% 70% at 50% 0%, #6d161c, #3a0a0e 70%); }
.slot { width: min(430px, 82%); height: 30px; border-radius: 6px; background: linear-gradient(#1c1717, #050404); box-shadow: inset 0 3px 8px #000, 0 1px 0 rgba(255,255,255,.15); position: relative; z-index: 2; }
.slot span { position: absolute; left: 6%; right: 6%; top: 12px; height: 5px; border-radius: 3px; background: #000; }
.developing { margin-top: -14px; overflow: hidden; padding: 0 30px 40px; z-index: 1; }
/* The print feeds out of the slot, then "develops": a cream wash fades off it. Only transform + opacity
   animate (compositor-only), so a 2400x3600 image never has to be re-filtered every frame. */
.sheet { position: relative; display: block; transform: translateY(-104%); will-change: transform; }
.sheet::after { content: ""; position: absolute; inset: 0; background: #f1e9dc; opacity: 0; pointer-events: none; }
#strip-img { cursor: pointer; display: block; max-height: calc(100dvh - 120px); max-width: min(420px, 78vw); box-shadow: 0 24px 50px -16px rgba(0,0,0,.75); }
#result.printing .sheet { animation: feed 3.4s steps(26) forwards; }
#result.printing .sheet::after { animation: develop 4.8s ease-out forwards; }
@keyframes feed { to { transform: translateY(0); } }
@keyframes develop { 0% { opacity: .9; } 55% { opacity: .25; } 100% { opacity: 0; } }

.result-panel { padding: clamp(24px, 4vw, 56px) clamp(16px, 3vw, 40px); align-self: center; }
.result-panel h2 { font-size: 76px; line-height: 1; margin: 0; color: var(--red); }
.lede { color: var(--ink-soft); margin: 6px 0 22px; font-style: italic; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 22px; }
.more { display: flex; gap: 20px; margin: -10px 0 22px; flex-wrap: wrap; }
.restyle { border-top: 1px solid var(--line); padding-top: 18px; display: flex; flex-wrap: wrap; gap: 0 26px; }
.legend, .note span { display: block; font: 400 14px var(--mono); color: var(--ink-soft); margin-bottom: 8px; }
.note input { font: 500 16px var(--serif); color: var(--ink); background: #fffaf2; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; width: min(260px, 100%); }
.note input:focus { outline: 2px solid var(--red); outline-offset: 1px; }
.chips.num button { min-width: 36px; padding: 6px 0; }
.video-opts { display: flex; flex-wrap: wrap; gap: 0 26px; border-top: 1px solid var(--line); padding-top: 18px; }
#video-actions { margin: 0; align-items: center; }
.video-box { margin-top: 6px; display: grid; gap: 10px; }
.progress { height: 6px; border-radius: 3px; background: var(--paper-2); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--red); transition: width .2s; }
.progress-label { margin: 0; font: italic 400 16px var(--serif); color: var(--ink-soft); }
#video-out { width: min(260px, 100%); border-radius: 12px; background: #000; box-shadow: 0 16px 30px -14px rgba(0,0,0,.5); }
.secondary { margin-top: 26px; display: flex; gap: 22px; }

/* after the strip develops, the controls arrive one by one */
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
#result.printing .actions > *, #result.printing .more > * { animation: rise .6s var(--ease-spring) backwards; animation-delay: 3.3s; }
#result.printing .actions > :nth-child(2) { animation-delay: 3.4s; }
#result.printing .actions > :nth-child(3) { animation-delay: 3.5s; }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: .5s; }

@media (max-width: 860px) {
  #home, #result { grid-template-columns: 1fr; }
  .home-preview { order: -1; min-height: 46dvh; padding: 24px 16px; }
  #preview { max-height: 40dvh; }
  .result-stage { min-height: 70dvh; }
  .layouts { gap: 6px; }
  .tray li { width: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  .sheet { transform: none; }
  .chips .pill { transition: none; }
}
