:root {
  --bg: #0e0e0f;
  --fg: #f7f5f0;
  --muted: #9a958b;
  --accent: #f7f5f0;
  --accent-fg: #0e0e0f;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* Several elements below set display: flex / display: block, which would
   silently override the UA stylesheet's [hidden] { display: none } rule.
   Force the HTML hidden attribute to win, so JS toggling .hidden works
   reliably (e.g. share page swapping between #result-content and #not-found). */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.screen {
  display: none;
  flex: 1 1 auto;
  width: 100%;
  flex-direction: column;
  min-height: 0;
}
.screen.active { display: flex; }

/* ---------- landing ---------- */
.landing-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
  gap: 1.25rem;
  text-align: center;
}
.brand {
  font-size: clamp(2.5rem, 12vw, 4.5rem);
  font-weight: 800;
  letter-spacing: -0.04em;
}
.tagline {
  font-size: 1.05rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}
.steps {
  list-style: none;
  counter-reset: step;
  margin: 1rem 0 1.5rem;
  max-width: 22rem;
  width: 100%;
}
.steps li {
  counter-increment: step;
  padding: 0.85rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.steps li::before {
  content: counter(step);
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 50%;
  background: var(--fg);
  color: var(--bg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  flex-shrink: 0;
}
.hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 0.5rem;
}

/* ---------- buttons ---------- */
.primary {
  appearance: none;
  border: none;
  background: var(--accent);
  color: var(--accent-fg);
  font: inherit;
  font-weight: 700;
  padding: 0.95rem 2rem;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.1s ease, opacity 0.2s ease;
  letter-spacing: 0.02em;
}
.primary:active { transform: scale(0.97); }
.primary:disabled { opacity: 0.5; cursor: default; }
.primary.big { font-size: 1.1rem; padding: 1.15rem 3rem; }

/* ---------- booth ---------- */
#screen-booth { padding: 0; }
.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: #000;
  overflow: hidden;
}
#preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* mirror */
}
.vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,0.35) 100%),
    linear-gradient(to bottom, rgba(0,0,0,0.25), transparent 18%, transparent 70%);
  mix-blend-mode: multiply;
}
.flash {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.16s ease;
  z-index: 5;
}
.flash.on { opacity: 1; }

.shot-indicator {
  position: absolute;
  top: calc(1rem + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.45rem 1rem;
  border-radius: 999px;
  letter-spacing: 0.05em;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s ease;
  z-index: 4;
}
.shot-indicator.on { opacity: 1; }

.countdown {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(8rem, 32vw, 16rem);
  font-weight: 800;
  color: #fff;
  text-shadow: 0 4px 40px rgba(0,0,0,0.6);
  line-height: 1;
  pointer-events: none;
  z-index: 3;
  opacity: 0;
}
.countdown.tick {
  animation: countdown-pop 1s ease-out;
}
@keyframes countdown-pop {
  0%   { opacity: 0; transform: scale(1.6); }
  20%  { opacity: 1; transform: scale(1); }
  85%  { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(0.85); }
}

.strip-thumbs {
  position: absolute;
  top: calc(1rem + env(safe-area-inset-top));
  right: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  pointer-events: none;
  z-index: 4;
}
.strip-thumbs .slot {
  width: 52px;
  aspect-ratio: 4 / 3;
  border-radius: 0.4rem;
  background: rgba(255,255,255,0.06);
  border: 1.5px solid rgba(255,255,255,0.35);
  background-size: cover;
  background-position: center;
  transition: transform 0.25s ease, border-color 0.25s ease, background-color 0.25s ease;
}
.strip-thumbs .slot.filled {
  border-color: #fff;
  animation: slot-pop 0.4s ease-out;
}
.strip-thumbs .slot.active {
  border-color: #fff;
  background-color: rgba(255,255,255,0.18);
  box-shadow: 0 0 0 3px rgba(255,255,255,0.25);
}
@keyframes slot-pop {
  0%   { transform: scale(0.7); }
  60%  { transform: scale(1.08); }
  100% { transform: scale(1); }
}

.bottom-scrim {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 180px;
  background: linear-gradient(to top, rgba(0,0,0,0.55), transparent);
  pointer-events: none;
  z-index: 2;
}

.booth-controls {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(1.25rem + env(safe-area-inset-bottom));
  display: flex;
  justify-content: center;
  z-index: 6;
  pointer-events: none;
}
.booth-controls > * { pointer-events: auto; }

.take-cta {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  font-size: 1.05rem;
  font-weight: 700;
  padding: 1.05rem 1.75rem;
  background: #fff;
  color: #0e0e0f;
  border-radius: 999px;
  border: none;
  box-shadow: 0 12px 36px rgba(0,0,0,0.45), 0 0 0 4px rgba(255,255,255,0.12);
  letter-spacing: 0.02em;
}
.take-cta:active { transform: scale(0.97); }
.take-cta:disabled {
  opacity: 0.55;
  background: rgba(255,255,255,0.85);
}
.take-dot {
  display: inline-block;
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 50%;
  background: #d23b3b;
  box-shadow: 0 0 0 3px rgba(210,59,59,0.25);
}
.take-cta.recording .take-dot { animation: rec-pulse 1s ease-in-out infinite; }
@keyframes rec-pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(210,59,59,0.25); }
  50%      { box-shadow: 0 0 0 7px rgba(210,59,59,0.05); }
}

/* ---------- uploading: polaroid developing animation ---------- */
/*
 * Replaces the old spinner. We composite the user's strip locally and put
 * it inside a polaroid-style frame, then run a layered set of animations:
 *   .dev-strip   — blooms from blurred sepia into crisp color (4.5s)
 *   .dev-warmth  — radial sodium-lamp gradient fades out as it "develops"
 *   .dev-grain   — film-grain SVG noise dissolves
 *   .dev-text    — italic "developing…" caption pulses
 * The R2 upload runs in parallel with the animation. We always wait at
 * least MIN_DEV_MS (set in booth.js) so the effect completes even on a
 * fast network — that's the whole point: it's UX, not a progress bar.
 */
.dev-stage {
  position: relative;
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  padding: 2rem 1rem;
}
.dev-warmth {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 40%, rgba(255, 170, 90, 0.18), transparent 60%),
    radial-gradient(ellipse at 30% 80%, rgba(255, 90, 50, 0.10), transparent 60%);
  animation: dev-warmth 4.5s ease-out forwards;
}
@keyframes dev-warmth {
  0%   { opacity: 1; }
  85%  { opacity: 0.4; }
  100% { opacity: 0; }
}
.dev-strip-frame {
  position: relative;
  width: 100%;
  max-width: 280px;
  max-height: 65vh;
  border-radius: 0.5rem;
  overflow: hidden;
  background: #1a1a1a;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.dev-strip {
  display: block;
  width: 100%;
  height: auto;
  max-height: 65vh;
  object-fit: contain;
  filter: blur(18px) sepia(0.85) brightness(1.45) saturate(0.4) contrast(0.85);
  opacity: 0;
  animation: dev-emerge 4.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}
@keyframes dev-emerge {
  0%   { filter: blur(18px) sepia(0.85) brightness(1.45) saturate(0.4) contrast(0.85); opacity: 0; }
  10%  { opacity: 0.5; }
  35%  { filter: blur(10px) sepia(0.65) brightness(1.25) saturate(0.65) contrast(0.92); opacity: 0.85; }
  65%  { filter: blur(4px)  sepia(0.32) brightness(1.10) saturate(0.85) contrast(0.97); opacity: 1; }
  100% { filter: blur(0)    sepia(0)    brightness(1)    saturate(1)    contrast(1);    opacity: 1; }
}
.dev-grain {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.55;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0.6 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  background-size: 200px 200px;
  mix-blend-mode: overlay;
  animation: dev-grain 4.5s linear forwards;
}
@keyframes dev-grain {
  0%   { opacity: 0.7; }
  60%  { opacity: 0.35; }
  100% { opacity: 0; }
}
.dev-text {
  font-family: ui-serif, "New York", "Times New Roman", serif;
  font-style: italic;
  font-size: 1.05rem;
  color: rgba(247, 245, 240, 0.7);
  letter-spacing: 0.05em;
  animation: dev-text-pulse 1.6s ease-in-out infinite;
}
@keyframes dev-text-pulse {
  0%, 100% { opacity: 0.5; }
  50%      { opacity: 1; }
}
/* Restart the develop+grain+warmth animations on retry by removing the
   .replaying class, forcing a reflow, and re-adding it (see booth.js). */
.dev-stage.replaying .dev-strip,
.dev-stage.replaying .dev-grain,
.dev-stage.replaying .dev-warmth { animation: none; }

.upload-detail {
  font-size: 0.85rem;
  color: var(--muted);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  min-height: 1.2em;
  text-align: center;
  max-width: 22rem;
}
.upload-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
  margin-top: 0.5rem;
}
/* link-btn is applied to both <a> and <button>; reset native button chrome
   so the back/redo controls actually look like text links, not gray boxes. */
.link-btn {
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  border: none;
  padding: 0.4rem 0.75rem;
  font: inherit;
  color: var(--muted);
  font-size: 0.9rem;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  touch-action: manipulation;
}
.link-btn:hover, .link-btn:focus-visible { color: var(--fg); }
.link-btn:active { transform: scale(0.97); }
/* ---------- denied ---------- */
.denied-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 2rem 1.5rem;
  gap: 1.25rem;
  max-width: 28rem;
  margin: 0 auto;
}
.denied-inner h2 {
  font-size: 1.75rem;
  letter-spacing: -0.02em;
}
.denied-inner p { color: var(--muted); }
.denied-steps {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.denied-steps li {
  background: rgba(255,255,255,0.04);
  padding: 0.9rem 1rem;
  border-radius: 0.75rem;
  font-size: 0.95rem;
}

/* ---------- result page ---------- */
.result-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1.5rem 1rem 2.5rem;
  gap: 1.5rem;
  overflow-y: auto;
  position: relative;
}

.not-found {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 3rem 1.5rem;
  text-align: center;
}
.not-found p { color: var(--muted); }
.not-found .primary { display: inline-block; text-decoration: none; margin-top: 0.5rem; }

.result-content {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}
.strip-preview {
  max-width: 320px;
  width: 100%;
  border-radius: 0.5rem;
  display: block;
}
.video-preview {
  max-width: 320px;
  width: 100%;
  border-radius: 0.5rem;
  background: #000;
}
.qr-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  background: #fff;
  color: #111;
  padding: 1.25rem 1.25rem 1rem;
  border-radius: 1.25rem;
  width: 100%;
  max-width: 320px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.35);
}
#qr-canvas { display: block; width: 220px; height: 220px; image-rendering: pixelated; }
.qr-card .qr-label { font-size: 0.9rem; color: #444; text-align: center; font-weight: 600; }
.qr-card .qr-url { font-size: 0.72rem; color: #888; font-family: ui-monospace, "SF Mono", Menlo, monospace; word-break: break-all; text-align: center; }
.actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: center;
}
.actions a, .actions button {
  appearance: none;
  border: 1px solid rgba(255,255,255,0.18);
  background: transparent;
  color: var(--fg);
  font: inherit;
  font-weight: 600;
  padding: 0.7rem 1.2rem;
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
}
.actions a:active, .actions button:active { transform: scale(0.97); }

/* ---------- frame picker ---------- */
.frame-picker-wrap {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: center;
}
.frame-picker-label {
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: lowercase;
}
.frame-picker {
  display: flex;
  gap: 0.65rem;
  width: 100%;
  overflow-x: auto;
  /* Extra horizontal padding so the first/last chip doesn't crash into the
     edge mid-scroll. Vertical padding gives chip shadows room to breathe. */
  padding: 0.5rem 0.5rem 0.85rem;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  /* pan-x only: vertical drags bubble up to .edit-inner so users can keep
     scrolling the form even when their finger lands on the chip row. */
  touch-action: pan-x;
}
.frame-picker::-webkit-scrollbar { display: none; }
.frame-chip {
  appearance: none;
  border: none;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  padding: 0;
  cursor: pointer;
  scroll-snap-align: center;
  flex-shrink: 0;
}
.frame-chip .frame-swatch {
  width: 64px;
  height: 88px;
  border-radius: 0.5rem;
  display: block;
  background-size: cover;
  background-position: top center;
  border: 2px solid transparent;
  transition: border-color 0.18s ease, transform 0.18s ease;
  box-shadow: 0 4px 12px rgba(0,0,0,0.35);
}
.frame-chip .frame-label {
  font-size: 0.7rem;
  color: var(--muted);
  letter-spacing: 0.05em;
  transition: color 0.18s ease;
}
.frame-chip.active .frame-swatch {
  border-color: var(--fg);
  transform: translateY(-2px);
}
.frame-chip.active .frame-label {
  color: var(--fg);
}
.frame-chip:active .frame-swatch { transform: scale(0.96); }

/* ---------- layout pick ---------- */
.layout-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  padding: 2rem 1.25rem;
  text-align: center;
}
.layout-title {
  font-size: 1.85rem;
  letter-spacing: -0.02em;
  font-weight: 800;
}
.layout-sub {
  color: var(--muted);
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
}
.layout-choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
  width: 100%;
  max-width: 26rem;
}
.layout-card {
  appearance: none;
  border: 1.5px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.03);
  color: var(--fg);
  font: inherit;
  padding: 1.1rem 0.85rem 1rem;
  border-radius: 1rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  transition: transform 0.15s ease, border-color 0.2s ease, background-color 0.2s ease;
}
.layout-card:hover, .layout-card:focus-visible {
  border-color: rgba(255,255,255,0.45);
  background: rgba(255,255,255,0.06);
}
.layout-card:active { transform: scale(0.97); }
.layout-preview {
  display: grid;
  width: 76px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 0.4rem;
  padding: 6px;
  gap: 4px;
}
.layout-preview span {
  background: rgba(255,255,255,0.55);
  border-radius: 2px;
}
.layout-preview--grid {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  aspect-ratio: 4 / 5;
  height: 95px;
}
.layout-preview--strip {
  grid-template-rows: 1fr 1fr 1fr 1fr;
  aspect-ratio: 1 / 3;
  height: 130px;
}
.layout-name {
  font-weight: 700;
  font-size: 1rem;
}
.layout-desc {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.3;
}

/* ---------- edit screen ---------- */
.edit-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  /* extra bottom space so the save button never collides with the home
     indicator on iPhone or the dock area on iPad in landscape. */
  padding: 1.25rem 1rem max(2rem, calc(env(safe-area-inset-bottom) + 1.25rem));
  width: 100%;
  max-width: 30rem;
  margin: 0 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.edit-title {
  font-size: 1.5rem;
  letter-spacing: -0.02em;
  font-weight: 800;
}
.edit-preview-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
}
.edit-preview {
  max-width: 280px;
  width: auto;
  height: auto;
  /* Cap height so a 1x4 strip (≈3:1 portrait) doesn't eat the viewport
     and push the frame picker + save button below the fold. */
  max-height: 38vh;
  object-fit: contain;
  border-radius: 0.5rem;
  display: block;
  background: #1a1a1a;
  box-shadow: 0 16px 48px rgba(0,0,0,0.5);
}
.edit-field {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.edit-label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: lowercase;
  letter-spacing: 0.06em;
}
.edit-input {
  appearance: none;
  background: rgba(255,255,255,0.06);
  border: 1.5px solid rgba(255,255,255,0.12);
  color: var(--fg);
  font: inherit;
  font-size: 1rem;
  padding: 0.75rem 0.95rem;
  border-radius: 0.6rem;
  outline: none;
  transition: border-color 0.18s ease, background 0.18s ease;
}
.edit-input:focus {
  border-color: rgba(255,255,255,0.45);
  background: rgba(255,255,255,0.09);
}
.edit-section-label {
  width: 100%;
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: lowercase;
  letter-spacing: 0.06em;
  margin-top: 0.25rem;
}
#edit-frame-picker {
  width: 100%;
  max-width: none;
}
.edit-actions {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.75rem;
}
.edit-actions .primary { width: 100%; }
