:root {
  --bg: #120d09;
  --panel: #1e1610;
  --panel-2: #2a1f16;
  --line: #3b2c1f;
  --text: #f6ead8;
  --muted: #b9a58c;
  --orange: #ff8a1f;
  --orange-2: #ffb347;
  --shave: #ffd76a;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }

body {
  background: radial-gradient(ellipse at 50% -20%, #33200f 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font-family: 'Nunito', system-ui, -apple-system, sans-serif;
  display: grid;
  grid-template-rows: auto 1fr;
  grid-template-columns: minmax(0, 1fr); /* never let wide content push the page sideways */
  height: 100dvh;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- splash ---------- */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0;
  transition: opacity .4s ease;
  background:
    linear-gradient(to bottom, rgba(18,13,9,.6) 0%, rgba(18,13,9,0) 20%, rgba(18,13,9,0) 58%, rgba(18,13,9,.85) 80%, rgba(18,13,9,.97) 100%),
    url('assets/splash-wide.jpg') center 45% / cover no-repeat;
}
@media (max-aspect-ratio: 1/1) {
  body::before {
    background:
      linear-gradient(to bottom, rgba(18,13,9,.55) 0%, rgba(18,13,9,0) 16%, rgba(18,13,9,0) 62%, rgba(18,13,9,.85) 80%, rgba(18,13,9,.97) 100%),
      url('assets/splash-tall.jpg') center 40% / cover no-repeat;
  }
}
body.on-splash::before { opacity: 1; }

/* ---------- header ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
}
h1, h2, .steps span {
  font-family: 'Tilt Warp', 'Nunito', system-ui, sans-serif;
  font-weight: 400;
}
h1 {
  margin: 0;
  font-size: clamp(24px, 4.6vw, 34px);
  letter-spacing: .5px;
  color: var(--orange);
  text-shadow: 0 0 18px rgba(255, 138, 31, .45);
}
.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* Splash: big centred title with the progress pills underneath. */
body.on-splash .topbar { flex-direction: column; justify-content: center; gap: 10px; padding-top: max(18px, env(safe-area-inset-top)); }
body.on-splash h1 {
  font-size: clamp(44px, 11vw, 84px);
  line-height: 1;
  text-align: center;
  text-shadow: 0 0 28px rgba(255, 138, 31, .6), 0 3px 12px rgba(0, 0, 0, .85);
}
body.on-splash .topbar-right { justify-content: center; }
.btn.small { padding: 5px 12px; font-size: 13px; }
.steps { display: flex; flex-wrap: wrap; gap: 6px; font-size: 13px; }
.steps span {
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.steps span.on { background: var(--orange); border-color: var(--orange); color: #1a0f05; }

main { min-height: 0; min-width: 0; position: relative; }
.stage { display: none; height: 100%; flex-direction: column; }
.stage.active { display: flex; }

/* ---------- buttons ---------- */
.btn, .seg button {
  font: inherit;
  font-weight: 700;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  line-height: 1.1;
  transition: background .15s, border-color .15s, transform .1s;
  user-select: none;
}
.btn:hover:not(:disabled), .seg button:hover { border-color: var(--orange); }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .35; cursor: default; }
.btn.primary { background: var(--orange); border-color: var(--orange); color: #1a0f05; }
.btn.primary:hover:not(:disabled) { background: var(--orange-2); }
.btn.big { padding: 14px 24px; font-size: 17px; }
.btn.toggle[aria-pressed="true"] { background: #4a2a0c; border-color: var(--orange); color: var(--orange-2); }

.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 7px 12px; }
.seg button[aria-pressed="true"] { background: var(--orange); color: #1a0f05; }

.swatch { width: 14px; height: 14px; border-radius: 50%; display: inline-block; border: 2px solid rgba(255,255,255,.7); }
.swatch.cut { background: #000; }
.swatch.shave { background: var(--shave); }

/* ---------- capture ---------- */
/* Tagline up top, buttons at the bottom, so the splash pumpkin stays visible in between. */
.hero {
  flex: 1;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 8px 16px max(24px, env(safe-area-inset-bottom));
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.hero-actions { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.hero[hidden] { display: none; }
.lede { font-size: 18px; color: var(--text); margin: 0; text-shadow: 0 2px 10px rgba(0,0,0,.9); }
.hero .linkish { color: var(--text); text-shadow: 0 1px 6px rgba(0,0,0,.9); }
.hero .msg { text-shadow: 0 1px 6px rgba(0,0,0,.9); }
.btn-row { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.linkish {
  font: inherit; color: var(--muted); background: none; border: 0; padding: 4px;
  text-decoration: underline; text-underline-offset: 3px; cursor: pointer;
}
.linkish:hover { color: var(--orange-2); }
.msg { min-height: 1.2em; color: var(--orange-2); margin: 0; }

.camera { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.camera[hidden] { display: none; }
.video-wrap { flex: 1; min-height: 0; position: relative; margin: 0 12px; border-radius: 14px; overflow: hidden; background: #000; }
.video-wrap video { width: 100%; height: 100%; object-fit: contain; display: block; }
.video-wrap video.mirrored { transform: scaleX(-1); }
.camera-guide { position: absolute; inset: 8%; width: 84%; height: 84%; pointer-events: none; opacity: .8; }
.camera-tip {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); margin: 0;
  background: rgba(0,0,0,.55); padding: 4px 12px; border-radius: 999px; font-size: 13px; white-space: nowrap;
}
.camera-controls {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  padding-bottom: max(14px, env(safe-area-inset-bottom));
}
.camera-controls > :first-child { justify-self: end; }
.camera-controls > :last-child { justify-self: start; }
.snap {
  width: 70px; height: 70px; border-radius: 50%;
  border: 5px solid #fff; background: var(--orange);
  box-shadow: 0 0 0 3px var(--orange), 0 0 24px rgba(255,138,31,.6);
  cursor: pointer;
}
.snap:active { transform: scale(.94); }

/* ---------- canvases ---------- */
.canvas-wrap { flex: 1; min-height: 0; position: relative; margin: 0 12px; }
.canvas-wrap canvas {
  position: absolute;
  inset: 0;
  margin: auto;
  max-width: 100%;
  max-height: 100%;
  border-radius: 14px;
  touch-action: none;
  box-shadow: 0 10px 40px rgba(0,0,0,.5);
}

.busy { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.busy[hidden] { display: none; }
.busy span {
  background: rgba(10, 6, 3, .8); border: 1px solid var(--line); border-radius: 999px;
  padding: 10px 18px; font-weight: 800; color: var(--orange-2);
}
.seg button:disabled { opacity: .4; cursor: default; }

.zoom-btn {
  position: absolute; z-index: 2;
  width: 42px; height: 42px; padding: 0; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
  color: #fff; background: rgba(10, 6, 3, .62);
  border: 1px solid rgba(255, 255, 255, .28);
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
}
.zoom-btn[aria-pressed="true"] { color: var(--orange-2); border-color: var(--orange); }
.zoom-btn svg { width: 22px; height: 22px; }

/* ---------- toolbars ---------- */
.toolbar {
  padding: 10px 12px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.tool-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; align-items: center; }
.tool-row[hidden] { display: none; }
.hint { margin: 0; color: var(--muted); font-size: 14px; text-align: center; }

.field, .check {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 14px; font-weight: 700; color: var(--muted);
}
.field input[type="range"] { width: 110px; accent-color: var(--orange); }
.check input { accent-color: var(--orange); width: 16px; height: 16px; }
.size-dot { display: inline-block; border-radius: 50%; background: #000; border: 2px solid #fff; flex: none; }
.field.size { min-height: 42px; }

/* ---------- scene picker ---------- */
.scene-picker {
  display: flex; gap: 10px; max-width: 100%;
  overflow-x: auto; padding: 4px 2px; scrollbar-width: thin;
}
.scene-picker button {
  flex: none; width: 96px; padding: 0; border-radius: 12px; overflow: hidden; cursor: pointer;
  border: 2px solid var(--line); background: var(--panel); color: var(--muted);
  font: inherit; font-size: 12px; font-weight: 700;
}
.scene-picker button img { display: block; width: 100%; aspect-ratio: 16 / 10; object-fit: cover; }
.scene-picker button span { display: block; padding: 4px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scene-picker button[aria-checked="true"] { border-color: var(--orange); color: var(--text); box-shadow: 0 0 14px rgba(255,138,31,.4); }

@media (max-width: 560px) {
  .scene-picker button { width: 78px; }
  .steps span { padding: 3px 7px; font-size: 11px; }
  .btn, .seg button { padding: 8px 12px; }
  .seg button { padding: 7px 9px; }
  .field input[type="range"] { width: 80px; }
}
