:root {
  --cream: #FFF6E5;
  --cream-2: #FFEBC8;
  --ink: #3B2A1E;
  --muted: #7A6552;
  --orange: #E8590C;
  --orange-dark: #C2410C;
  --sun: #FFB020;
  --teal: #0F7C8A;
  --teal-light: #D5EEF1;
  --card: #FFFFFF;
  --line: #F1DDB8;
  --ok: #1E7F4F;
  --bad: #B3261E;
  --font: "Baloo 2", "Baloo Bhai 2", "Baloo Tamma 2", ui-rounded, "Avenir Next", system-ui, sans-serif;
  --radius: 20px;
  --shadow: 0 3px 0 rgba(120, 80, 20, .10), 0 8px 20px rgba(120, 80, 20, .08);
  --field: #FFFDF8;
  --selected: #FFF0DF;
  --orange-text: #C2410C;
  --hero-a: #FFE2A8;
  --hero-b: #FFC670;
  --note-ink: #0A5560;
  --alert-bg: #FFE3E0;
  --alert-line: #F5B5AF;
  --sun-ring: #FFD470;
  color-scheme: light;
}
/* Dark mode: a soft warm cocoa, not black, so the cartoon colours still glow. Auto follows the phone; the header
   button pins light or dark (theme.js stores it). Both blocks hold the same values. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --cream: #3B3029; --cream-2: #4A3D34; --card: #47392F; --field: #40342B; --ink: #FBEEDC; --muted: #D3C0A9;
    --line: #67574A; --orange: #F07A3E; --orange-dark: #B9531E; --orange-text: #FFA46E; --sun: #FFB547; --teal: #3EAFBE;
    --teal-light: #2E4C50; --ok: #5DC48C; --bad: #FF8D84; --selected: #57432F; --hero-a: #6E512F; --hero-b: #8C6230;
    --note-ink: #CDEFF2; --alert-bg: #5B2F2B; --alert-line: #8C4C45; --sun-ring: #C98A2E;
    --shadow: 0 3px 0 rgba(0, 0, 0, .22), 0 8px 20px rgba(0, 0, 0, .18); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --cream: #3B3029; --cream-2: #4A3D34; --card: #47392F; --field: #40342B; --ink: #FBEEDC; --muted: #D3C0A9;
  --line: #67574A; --orange: #F07A3E; --orange-dark: #B9531E; --orange-text: #FFA46E; --sun: #FFB547; --teal: #3EAFBE;
  --teal-light: #2E4C50; --ok: #5DC48C; --bad: #FF8D84; --selected: #57432F; --hero-a: #6E512F; --hero-b: #8C6230;
  --note-ink: #CDEFF2; --alert-bg: #5B2F2B; --alert-line: #8C4C45; --sun-ring: #C98A2E;
  --shadow: 0 3px 0 rgba(0, 0, 0, .22), 0 8px 20px rgba(0, 0, 0, .18); color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--cream); color: var(--ink);
  font: 400 17px/1.45 "Baloo 2", "Baloo Bhai 2", "Baloo Tamma 2", ui-rounded, "Avenir Next", system-ui, sans-serif;
}
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
main { max-width: 560px; margin: 0 auto; padding: 8px 16px 120px; }
main.wide, body.admin main { max-width: 980px; }
h1 { font-size: 28px; line-height: 1.15; margin: 12px 0 6px; }
h2 { font-size: 22px; margin: 0 0 8px; }
h3 { font-size: 18px; margin: 12px 0 6px; }
a { color: var(--teal); }
.muted { color: var(--muted); }
.small { font-size: 14px; color: var(--muted); }
.lead { font-size: 19px; }
.center { text-align: center; }
.top { max-width: 560px; margin: 0 auto; padding: 12px 16px 4px; display: flex; align-items: center; justify-content: space-between; }
body.admin .top { max-width: 980px; }
.brand { font-weight: 700; font-size: 26px; color: var(--orange); text-decoration: none; display: inline-flex; align-items: center; gap: 8px; }
.sun { width: 26px; height: 26px; border-radius: 50%; background: var(--sun); box-shadow: 0 0 0 4px var(--sun-ring), 0 0 0 8px rgba(255, 176, 32, .25); display: inline-block; }
.inline { display: inline; margin: 0; }
button.link { background: none; border: 0; color: var(--teal); font: inherit; text-decoration: underline; padding: 10px 6px; cursor: pointer; min-height: 44px; }
button.link.danger { color: var(--bad); }
.back { display: inline-block; padding: 10px 0; text-decoration: none; font-weight: 600; }

.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin: 12px 0; box-shadow: var(--shadow); border: 2px solid var(--line); }
.hero-card { background: linear-gradient(160deg, var(--hero-a), var(--hero-b)); border-radius: 28px; padding: 18px 16px 20px; margin: 10px 0; box-shadow: var(--shadow); }
.hero-card h1 { margin-top: 4px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 8px 22px; border-radius: 999px;
  border: 2px solid transparent; font: 700 17px/1.1 var(--font); text-decoration: none; cursor: pointer; text-align: center; color: var(--ink); background: var(--cream-2); }
.btn.primary { background: var(--orange); color: #fff; box-shadow: 0 4px 0 var(--orange-dark); }
.btn.primary:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--orange-dark); }
.btn.secondary { background: var(--card); border-color: var(--orange); color: var(--orange-text); }
.btn.teal { background: var(--teal); color: #fff; }
.btn.danger { background: var(--bad); color: #fff; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.big { min-height: 56px; font-size: 20px; }
.btn.full { width: 100%; }
.btn.small { min-height: 48px; padding: 6px 16px; font-size: 15px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; box-shadow: none; }
.btn:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; }
.btn.file { position: relative; }
.row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.row .btn { flex: 1; }

label.field { display: block; font-weight: 600; margin: 12px 0; }
label.field input[type=text], label.field input:not([type]), label.field select, label.field textarea, input[name=at_time], textarea, select, input[type=text] {
  display: block; width: 100%; margin-top: 6px; padding: 12px 14px; min-height: 48px; font: 400 17px var(--font); color: var(--ink);
  background: var(--field); border: 2px solid var(--line); border-radius: 14px; }
textarea { min-height: 96px; }
input[type=file] { margin-top: 6px; font-size: 15px; max-width: 100%; }
.stack > * { margin-bottom: 12px; }
label { font-weight: 600; }
.toggle { display: flex; align-items: center; gap: 8px; min-height: 48px; font-weight: 600; }
.toggle.small { font-size: 14px; min-height: 48px; }
.toggle.block { align-items: flex-start; padding: 8px 0; }
.toggle input { width: 26px; height: 26px; accent-color: var(--orange); flex: none; }

.chip { display: inline-block; font-size: 13px; font-weight: 700; padding: 2px 10px; border-radius: 999px; background: var(--cream-2); color: var(--muted); }
.chip.hero { background: #FFE2A8; color: #8A5200; margin-right: 4px; }
.chip.kid { background: var(--teal-light); color: var(--teal); margin-left: 4px; }
.chip.st-queued, .chip.st-changes_requested, .chip.st-awaiting_approval { background: #FFE9B8; color: #8A5200; }
.chip.st-generating { background: var(--teal-light); color: var(--teal); }
.chip.st-in_review { background: #EAD9FF; color: #5B2A9E; }
.chip.st-ready { background: #CDEFD9; color: var(--ok); }
.chip.st-failed { background: #FBD5D2; color: var(--bad); }
.chip.st-draft { background: #EEE; color: #555; }

.section { font-size: 20px; margin: 22px 0 6px; }
.video-list { list-style: none; margin: 0; padding: 0; }
.video-card { display: flex; align-items: center; gap: 12px; background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); padding: 10px; margin: 10px 0; text-decoration: none; color: var(--ink); box-shadow: var(--shadow); min-height: 72px; }
.thumb { width: 84px; height: 60px; border-radius: 14px; object-fit: cover; background: var(--cream-2); flex: none; }
.thumb.ph { display: inline-flex; align-items: center; justify-content: center; font-size: 30px; }
.vc-body { flex: 1; display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.play { font-size: 22px; color: var(--orange); width: 32px; text-align: center; }

.player { width: 100%; border-radius: 16px; background: #000; max-height: 70vh; }
.timeline { list-style: none; margin: 8px 0 0; padding: 0; }
.timeline li { display: flex; gap: 12px; align-items: flex-start; padding: 8px 0; position: relative; color: var(--muted); }
.timeline li:not(:last-child)::after { content: ""; position: absolute; left: 17px; top: 40px; bottom: -8px; width: 3px; background: var(--line); }
.timeline .dot { width: 36px; height: 36px; border-radius: 50%; background: var(--cream-2); border: 3px solid var(--line); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; flex: none; z-index: 1; }
.timeline li.done .dot { background: var(--ok); border-color: var(--ok); color: #fff; }
.timeline li.now { color: var(--ink); }
.timeline li.now .dot { background: var(--orange); border-color: var(--orange); color: #fff; box-shadow: 0 0 0 5px rgba(232, 89, 12, .2); }
.tl-text { padding-top: 4px; }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: 8px 0; border-bottom: 1px dashed var(--line); }

/* ----- wizard ----- */
body.wizard main { padding-bottom: 190px; }
.progress { height: 12px; background: var(--cream-2); border-radius: 999px; margin: 12px 0 6px; overflow: hidden; border: 2px solid var(--line); }
#progress-bar { height: 100%; width: 16%; background: linear-gradient(90deg, var(--sun), var(--orange)); border-radius: 999px; transition: width .25s; }
.step-label { margin: 0 0 6px; font-weight: 700; color: var(--muted); font-size: 15px; }
.alert { background: var(--alert-bg); color: var(--bad); border: 2px solid var(--alert-line); border-radius: 14px; padding: 10px 14px; margin: 8px 0; font-weight: 600; }
.busy-note { color: var(--teal); font-weight: 700; min-height: 0; margin: 0; }
body.busy .btn, body.busy button.link { pointer-events: none; opacity: .7; }
.theme-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 8px 0 12px; }
.theme-grid.two { grid-template-columns: repeat(2, 1fr); }
.theme { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 84px; padding: 10px 8px; text-align: center; border-radius: 18px;
  border: 3px solid var(--line); background: var(--card); font: 700 16px/1.15 var(--font); color: var(--ink); cursor: pointer; }
.theme .ico { font-size: 30px; }
.theme.lang { min-height: 56px; }
.theme.selected, .tier.selected { border-color: var(--orange); background: var(--selected); box-shadow: 0 0 0 3px rgba(232, 89, 12, .2); }
.theme:last-child:nth-child(odd) { grid-column: 1 / -1; }
.tier-list { display: grid; gap: 10px; margin-top: 10px; }
.tier { display: flex; justify-content: space-between; align-items: center; min-height: 64px; padding: 10px 16px; border-radius: 18px; border: 3px solid var(--line); background: var(--card); font: 400 16px var(--font); color: var(--ink); cursor: pointer; text-align: left; }
.tier strong { font-size: 20px; }
.note { background: var(--teal-light); color: var(--note-ink); padding: 10px 14px; border-radius: 14px; font-weight: 600; }
ul.people { list-style: none; margin: 0; padding: 0; }
.person { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px dashed var(--line); }
.person:last-child { border-bottom: 0; }
.face { width: 72px; height: 72px; border-radius: 50%; object-fit: cover; flex: none; background: var(--cream-2); border: 3px solid var(--line); }
.face.ph { display: inline-flex; align-items: center; justify-content: center; font-size: 32px; }
.p-body { flex: 1; min-width: 0; }
.p-actions { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; margin-top: 6px; }
.qc { font-size: 14px; font-weight: 600; }
.qc.ok { color: var(--ok); }
.qc.bad { color: var(--bad); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.group-wrap { position: relative; margin: 12px 0; border-radius: 16px; overflow: hidden; line-height: 0; border: 3px solid var(--line); }
.group-img { width: 100%; height: auto; display: block; }
.facebox { position: absolute; border: 3px solid var(--sun); background: rgba(255, 176, 32, .12); border-radius: 12px; padding: 0; cursor: pointer; min-width: 36px; min-height: 36px; }
.facebox.assigned { border-color: var(--ok); background: rgba(30, 127, 79, .15); }
.facebox.picked { border-color: var(--orange); border-width: 4px; background: rgba(232, 89, 12, .2); }
.fb-name { position: absolute; left: 50%; bottom: -2px; transform: translate(-50%, 100%); background: var(--ok); color: #fff; font: 700 12px/1 var(--font); padding: 3px 7px; border-radius: 8px; white-space: nowrap; z-index: 1; }
.chooser { background: var(--cream-2); border-radius: 16px; padding: 12px; margin-top: 8px; }
.samples { list-style: none; padding: 0; margin: 8px 0 0; }
.samples li { display: flex; gap: 8px; align-items: center; padding: 6px 0; }
.samples li span { flex: 1; font-weight: 700; }
.voice-row { padding: 10px 0; }
.recorder { background: var(--cream-2); border-radius: 16px; padding: 12px; margin-top: 8px; }
.recorder blockquote { margin: 8px 0; padding: 8px 12px; background: var(--card); border-radius: 12px; border-left: 5px solid var(--sun); }
.rec-row { display: flex; align-items: center; gap: 12px; }
.rec-time { font-weight: 700; color: var(--bad); }
.preview { width: 100%; margin-top: 8px; }
.extra { padding: 4px 0; }
ul.summary { list-style: none; margin: 0; padding: 0; }
ul.summary li { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
ul.summary .k { flex: 0 0 110px; color: var(--muted); font-weight: 700; }
ul.summary .v { flex: 1; overflow-wrap: anywhere; }
ul.problems { color: var(--bad); font-weight: 600; padding-left: 20px; }
ul.quote { list-style: none; margin: 0; padding: 0; }
ul.quote li { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px dashed var(--line); }
ul.quote li.neg { color: var(--ok); }
ul.quote li.sum { font-weight: 700; border-bottom: 2px solid var(--line); }
ul.quote li.free { color: var(--ok); font-weight: 700; }
ul.quote li.total { font-weight: 700; font-size: 20px; border-bottom: 0; padding-top: 10px; }
.free { color: var(--ok); }

.bottom { position: fixed; left: 0; right: 0; bottom: 0; background: var(--cream); border-top: 3px solid var(--line); padding: 8px 16px calc(8px + env(safe-area-inset-bottom)); z-index: 10; box-shadow: 0 -6px 18px rgba(120, 80, 20, .10); }
.bottom > * { max-width: 560px; margin-left: auto; margin-right: auto; }
.nav-row { display: flex; gap: 10px; }
.nav-row .btn { flex: 1; }
.nav-row .btn[hidden] { display: none; }
.drawer-bar { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 48px; margin-top: 8px; padding: 6px 14px; border-radius: 16px; border: 2px solid var(--line); background: var(--card); font: 700 16px var(--font); color: var(--ink); cursor: pointer; }
.drawer-total { margin-left: auto; }
.chev { transition: transform .2s; font-size: 12px; color: var(--muted); }
.bottom.open .chev { transform: rotate(180deg); }
.drawer-body { max-height: 32vh; overflow: auto; background: var(--card); border: 2px solid var(--line); border-radius: 16px; padding: 8px 14px; margin-top: 6px; }
.drawer-body[hidden] { display: none; }

/* ----- admin ----- */
body.admin nav.admin { max-width: 980px; margin: 0 auto; padding: 0 16px; display: flex; gap: 6px; flex-wrap: wrap; }
body.admin nav.admin a { padding: 10px 16px; border-radius: 999px; text-decoration: none; font-weight: 700; color: var(--ink); background: var(--cream-2); }
body.admin nav.admin a.on { background: var(--orange); color: #fff; }
table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: 14px; overflow: hidden; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; font-size: 15px; }
th { background: var(--cream-2); }
pre, code { font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
pre { background: #2B2118; color: #FFE9C9; padding: 12px; border-radius: 12px; overflow: auto; max-height: 420px; }
.grid2 { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 760px) { .grid2 { grid-template-columns: 1fr 1fr; } }
.faces-row { display: flex; gap: 12px; flex-wrap: wrap; }
.faces-row figure { margin: 0; text-align: center; font-size: 13px; }
.faces-row img { width: 96px; height: 96px; border-radius: 12px; object-fit: cover; display: block; }
.linkbox { word-break: break-all; background: var(--selected); border: 2px dashed var(--orange); padding: 12px; border-radius: 14px; font-family: ui-monospace, Menlo, monospace; font-size: 14px; }
form.inline-form { display: inline; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

.fullw { width: 100%; height: auto; }
.mini-audio { width: 150px; }

input[type=file]::file-selector-button { font: 700 15px var(--font); min-height: 44px; padding: 8px 16px; margin-right: 10px; border-radius: 999px; border: 2px solid var(--orange); background: var(--card); color: var(--orange-text); cursor: pointer; }

.tablewrap { overflow-x: auto; border-radius: 14px; }

.story { white-space: pre-wrap; overflow-wrap: anywhere; display: block; background: var(--cream); border-radius: 10px; padding: 8px 10px; margin-top: 4px; }

/* live progress under "Making" (written by the worker, polled every 10 s) */
.stages { list-style: none; margin: 10px 0 4px; padding: 0; font-size: 15px; }
.stages li { display: flex; align-items: center; gap: 8px; padding: 3px 0; color: var(--muted); }
.stages .sdot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--line); background: var(--cream-2); flex: none; }
.stages li.sdone { color: var(--ink); }
.stages li.sdone .sdot { background: var(--ok); border-color: var(--ok); }
.stages li.snow { color: var(--ink); font-weight: 700; }
.stages li.snow .sdot { background: var(--orange); border-color: var(--orange); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 5px rgba(232, 89, 12, .2); } }
@media (prefers-reduced-motion: reduce) { .stages li.snow .sdot { animation: none; } }

/* header theme button */
.top { gap: 10px; }
.theme-btn { margin-left: auto; min-width: 44px; min-height: 44px; border-radius: 999px; border: 2px solid var(--line); background: var(--card);
  color: var(--ink); font: 700 15px var(--font); padding: 0 14px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.theme-btn:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; }
.top .theme-btn + form { margin-left: 4px; }

/* length slider (step 5) */
.len { margin: 14px 0 6px; }
.len-value { display: block; font: 700 30px/1.1 var(--font); color: var(--orange-text); margin-bottom: 8px; }
.len input[type=range] { width: 100%; height: 44px; accent-color: var(--orange); cursor: pointer; }
.len-ends { display: flex; justify-content: space-between; font-size: 14px; color: var(--muted); }
pre.live { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; max-height: 520px; }
