/* StoryKids AI design system: "the paper theatre" (docs/BRAND.md, docs/UI.md).
   Every screen is a small stage built from cut paper: cream card stock, pages with a dog-eared corner, the child's
   own drawing pinned on as torn cut-outs. Token NAMES are the contract; engineers use names, never raw hex
   (hex appears only for drawing data, palettes and the logo). The same block lives in internal/web/static/theme.css.
   Dark follows the OS until the toggle stores html[data-theme] (localStorage "sk-theme"). */
:root {
  color-scheme: light;
  --bg: #F7EEDD;          /* cream card stock */
  --bg-2: #EFE3CB;
  --surface: #FFFBF3;     /* a page */
  --surface-2: #FBF3E2;
  --fold: #EADCBF;        /* the turned-down corner of a page */
  --ink: #1E2A47;
  --muted: #5E6379;       /* AA on --bg (brief #6A6F85 is 4.4:1; this is 5.2:1) */
  --line: #E4D6BC;
  --line-strong: #C9B58E;
  --brand: #E8562A;       /* tangerine: art, accents, big marks */
  --cta: #C9421A;         /* tangerine for text-bearing fills (white on it is 4.8:1) */
  --cta-hover: #AE3615;
  --on-cta: #FFFFFF;
  --brand-ink: #B63A10;   /* tangerine as text on paper (AA) */
  --brand-soft: #FCE3D6;
  --teal: #1C9C98;        /* characters, confirmed */
  --teal-ink: #0F6E6B;
  --teal-soft: #D7EFEC;
  --plum: #6F4BB2;        /* outline, beats */
  --plum-soft: #E7DFF6;
  --sun: #F6B93B;         /* highlights, the free-story tag */
  --sun-soft: #FCEBC2;
  --ok: #2E8B57; --ok-ink: #1F6B40; --ok-soft: #D9EEDF;
  --warn: #C27A00; --warn-ink: #8A5200; --warn-soft: #F8E6C3;
  --bad: #C23B2A; --bad-ink: #A52F20; --bad-soft: #F8DAD3;
  --focus: #1E2A47; --focus-halo: #FFFBF3;
  --scrim: rgba(30,42,71,.5);
  --shadow: 0 1px 0 rgba(30,42,71,.06), 0 12px 24px -14px rgba(60,40,10,.38);
  --shadow-lift: 0 2px 0 rgba(30,42,71,.06), 0 22px 30px -16px rgba(60,40,10,.5);
  --cut-shadow: rgba(60,40,10,.42);
  --grain: .16;
  --r-page: 18px;
  --r-pill: 999px;
  --font-display: ui-rounded, "SF Pro Rounded", "Avenir Next Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-story: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", "Noto Serif", Georgia, serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --ease: cubic-bezier(.2,.7,.2,1);
  --bar-h: 60px; --tab-h: 64px; --gutter: 24px; --maxw: 1200px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #16192B; --bg-2: #11142A; --surface: #20243A; --surface-2: #272C46; --fold: #343A5C;
    --ink: #F4EBD8; --muted: #A5A9BD; --line: #343A58; --line-strong: #4B5278;
    --brand: #FF7A4D; --cta: #FF7A4D; --cta-hover: #FF9370; --on-cta: #1A1020; --brand-ink: #FF9B78; --brand-soft: #4A2A25;
    --teal: #35C2BD; --teal-ink: #5ADAD5; --teal-soft: #17413F; --plum: #9C80E0; --plum-soft: #34295A; --sun: #FFD166; --sun-soft: #4A3C16;
    --ok: #5CD39C; --ok-ink: #5CD39C; --ok-soft: #173A2C; --warn: #F2B24A; --warn-ink: #F2B24A; --warn-soft: #43320F; --bad: #FF8F85; --bad-ink: #FF8F85; --bad-soft: #472320;
    --focus: #F4EBD8; --focus-halo: #16192B; --scrim: rgba(5,7,20,.66);
    --shadow: 0 1px 0 rgba(0,0,0,.4), 0 14px 26px -14px rgba(0,0,0,.75); --shadow-lift: 0 2px 0 rgba(0,0,0,.4), 0 24px 34px -16px rgba(0,0,0,.85);
    --cut-shadow: rgba(0,0,0,.6); --grain: .07;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #16192B; --bg-2: #11142A; --surface: #20243A; --surface-2: #272C46; --fold: #343A5C;
  --ink: #F4EBD8; --muted: #A5A9BD; --line: #343A58; --line-strong: #4B5278;
  --brand: #FF7A4D; --cta: #FF7A4D; --cta-hover: #FF9370; --on-cta: #1A1020; --brand-ink: #FF9B78; --brand-soft: #4A2A25;
  --teal: #35C2BD; --teal-ink: #5ADAD5; --teal-soft: #17413F; --plum: #9C80E0; --plum-soft: #34295A; --sun: #FFD166; --sun-soft: #4A3C16;
  --ok: #5CD39C; --ok-ink: #5CD39C; --ok-soft: #173A2C; --warn: #F2B24A; --warn-ink: #F2B24A; --warn-soft: #43320F; --bad: #FF8F85; --bad-ink: #FF8F85; --bad-soft: #472320;
  --focus: #F4EBD8; --focus-halo: #16192B; --scrim: rgba(5,7,20,.66);
  --shadow: 0 1px 0 rgba(0,0,0,.4), 0 14px 26px -14px rgba(0,0,0,.75); --shadow-lift: 0 2px 0 rgba(0,0,0,.4), 0 24px 34px -16px rgba(0,0,0,.85);
  --cut-shadow: rgba(0,0,0,.6); --grain: .07;
}

/* ---------------------------------------------------------------- base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--bar-h) + 12px); }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink); font: 400 1rem/1.55 var(--font-ui); -webkit-font-smoothing: antialiased; }
/* the card-stock grain: one fixed layer, never in the way */
body::before { content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none; opacity: var(--grain); mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .45 0 0 0 0 .32 0 0 0 0 .15 0 0 0 .55 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E"); }
:root[data-theme="dark"] body::before { mix-blend-mode: screen; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) body::before { mix-blend-mode: screen; } }
body > * { position: relative; z-index: 1; }
h1, h2, h3, h4 { font-family: var(--font-display); line-height: 1.15; letter-spacing: -.01em; margin: 0; text-wrap: balance; }
h1 { font-size: clamp(1.8rem, 4.2vw, 2.6rem); font-weight: 800; }
h2 { font-size: 1.35rem; font-weight: 750; } h3 { font-size: 1.1rem; font-weight: 700; }
p { margin: 0; } a { color: var(--brand-ink); text-underline-offset: 3px; }
img { max-width: 100%; display: block; }
.muted { color: var(--muted); } .grow { flex: 1; } .num { font-variant-numeric: tabular-nums; }
.sr, .sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; box-shadow: 0 0 0 6px var(--focus-halo); border-radius: 6px; }
.skip { position: absolute; left: 12px; top: -60px; z-index: 100; padding: 10px 16px; border-radius: var(--r-pill); background: var(--ink); color: var(--bg); text-decoration: none; }
.skip:focus { top: 10px; }
[hidden] { display: none !important; }
.ico { width: 20px; height: 20px; flex: none; }
.eyebrow { margin: 0 0 6px; font: 700 .74rem/1 var(--font-ui); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.hint { font-size: .88rem; color: var(--muted); }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

/* ---------------------------------------------------------------- the shell: a stage edge */
.bar { position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: 14px; min-height: var(--bar-h); padding: 0 var(--gutter); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 2px dashed var(--line-strong); }
.brandmark { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font: 800 1.2rem var(--font-display); letter-spacing: -.02em; }
.brandmark svg { width: 34px; height: 34px; flex: none; }
.bar nav { display: flex; gap: 2px; margin-left: 10px; }
.bar nav a { position: relative; padding: 8px 14px; border-radius: var(--r-pill); color: var(--muted); text-decoration: none; font: 650 .95rem var(--font-ui); }
.bar nav a:hover { color: var(--ink); background: var(--surface-2); }
.bar nav a[aria-current="page"] { color: var(--ink); }
.bar nav a[aria-current="page"]::after { content: ""; position: absolute; left: 14px; right: 14px; bottom: 1px; height: 6px; background: no-repeat center / 100% 100% url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 60 6' preserveAspectRatio='none'%3E%3Cpath d='M1 3.5c6-3 9 2.5 15 0s9-3 15 0 9 2.5 14 0 9-1.5 14 0' fill='none' stroke='%23E8562A' stroke-width='2.4' stroke-linecap='round'/%3E%3C/svg%3E"); }
.iconbtn { display: inline-grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 50%; background: transparent; color: var(--ink); cursor: pointer; }
.iconbtn:hover { background: var(--surface-2); }
.ticket { display: inline-flex; align-items: center; gap: 8px; padding: 6px 14px 6px 10px; border-radius: 8px; background: var(--sun-soft); color: var(--ink); border: 1.5px dashed var(--sun); text-decoration: none; font: 700 .82rem var(--font-ui); white-space: nowrap; }
.ticket i { width: 9px; height: 9px; border-radius: 50%; border: 2px solid var(--sun); display: inline-block; margin-right: -3px; }
.ticket i.on { background: var(--sun); }
.avatar { display: grid; place-items: center; width: 40px; height: 40px; border: 2px solid var(--ink); border-radius: 50% 50% 50% 12%; background: var(--teal-soft); color: var(--teal-ink); font: 800 1rem var(--font-display); cursor: pointer; }
.profile { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 10px); z-index: 50; width: 270px; padding: 8px; border-radius: 14px; background: var(--surface); box-shadow: var(--shadow-lift); border: 1px solid var(--line-strong); }
.menu a, .menu button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; border: 0; border-radius: 10px; background: none; color: var(--ink); text-decoration: none; font: 500 .95rem var(--font-ui); cursor: pointer; text-align: left; }
.menu a:hover, .menu button:hover { background: var(--surface-2); } .menu hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }
.menu-head { display: grid; padding: 8px 12px 10px; } .menu-head span { color: var(--muted); font-size: .85rem; overflow-wrap: anywhere; }
.banners { display: grid; gap: 0; }
.banner { display: flex; align-items: center; gap: 14px; padding: 10px var(--gutter); background: var(--sun-soft); border-bottom: 1px solid var(--sun); font-size: .92rem; }
.banner.bad { background: var(--bad-soft); border-color: var(--bad); }
.page { position: relative; width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 30px var(--gutter) 64px; min-height: 60vh; outline: none; }
.pagehead { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 26px; }
.pagehead p.lede { margin-top: 8px; color: var(--muted); max-width: 58ch; }
.foot { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 22px; max-width: var(--maxw); margin: 0 auto; padding: 22px var(--gutter) 34px; color: var(--muted); font-size: .86rem; }
.foot a { color: var(--muted); }
.tabbar { display: none; }
.cta-bar { display: inline-flex; }
body.solo-cta .bar .cta-bar, body[data-page="create"] .bar .cta-bar, body[data-page="story"] .bar .cta-bar { display: none; }

/* ---------------------------------------------------------------- buttons, fields */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 20px; border: 2px solid var(--ink); border-radius: var(--r-pill); background: var(--surface); color: var(--ink); font: 700 .95rem var(--font-ui); text-decoration: none; cursor: pointer; transition: transform .12s var(--ease), background .12s, box-shadow .12s; box-shadow: 0 3px 0 var(--ink); }
.btn:hover { background: var(--surface-2); transform: translateY(-1px); box-shadow: 0 4px 0 var(--ink); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.btn.cta { background: var(--cta); border-color: var(--ink); color: var(--on-cta); }
.btn.cta:hover { background: var(--cta-hover); }
.btn.quiet { border-color: transparent; background: transparent; box-shadow: none; color: var(--ink); } .btn.quiet:hover { background: var(--surface-2); transform: none; box-shadow: none; }
.btn.danger { border-color: var(--bad-ink); color: var(--bad-ink); box-shadow: 0 3px 0 var(--bad-ink); } .btn.danger.fill { background: var(--bad-ink); color: var(--surface); }
.btn.sm { min-height: 38px; padding: 0 14px; font-size: .88rem; box-shadow: 0 2px 0 var(--ink); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; transform: none; box-shadow: 0 2px 0 var(--ink); }
.btn[aria-busy="true"] { position: relative; color: transparent !important; pointer-events: none; }
.btn[aria-busy="true"]::after { content: ""; position: absolute; width: 18px; height: 18px; border: 3px solid var(--ink); border-top-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
.btn.cta[aria-busy="true"]::after { border-color: var(--on-cta); border-top-color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }
.link { background: none; border: 0; padding: 0; color: var(--brand-ink); font: inherit; font-weight: 650; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.field { display: grid; gap: 6px; align-content: start; min-width: 0; }
.field > label, .field > .lbl, legend.lbl { font: 700 .88rem var(--font-ui); color: var(--ink); }
.input, .select, .textarea { width: 100%; min-height: 46px; padding: 0 14px; border: 2px solid var(--line-strong); border-radius: 12px; background: var(--surface); color: var(--ink); font: 500 1rem var(--font-ui); }
.textarea { padding: 12px 14px; min-height: 110px; resize: vertical; line-height: 1.5; }
.select { appearance: none; padding-right: 40px; text-overflow: ellipsis; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9' viewBox='0 0 14 9'%3E%3Cpath d='M1 1.5l6 6 6-6' fill='none' stroke='%235E6379' stroke-width='2.2' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 15px center; }
:root[data-theme="dark"] .select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9' viewBox='0 0 14 9'%3E%3Cpath d='M1 1.5l6 6 6-6' fill='none' stroke='%23A5A9BD' stroke-width='2.2' stroke-linecap='round'/%3E%3C/svg%3E"); }
.input:focus, .select:focus, .textarea:focus { border-color: var(--ink); outline-offset: 1px; }
.help { font-size: .84rem; color: var(--muted); }
.err { color: var(--bad-ink); font-size: .9rem; font-weight: 600; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; align-items: start; }
.check { display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; border: 2px solid var(--line-strong); border-radius: 12px; background: var(--surface); cursor: pointer; font-size: .95rem; }
.check input { width: 22px; height: 22px; margin: 1px 0 0; accent-color: var(--ink); flex: none; }
.check:has(input:checked) { border-color: var(--ink); background: var(--teal-soft); }
.check b { display: block; } .check span { color: var(--muted); font-size: .88rem; }
.seg { display: inline-flex; flex-wrap: wrap; gap: 8px; }
.seg label { position: relative; display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 16px; border: 2px solid var(--line-strong); border-radius: var(--r-pill); background: var(--surface); cursor: pointer; font-weight: 650; }
.seg input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.seg label:has(input:checked) { border-color: var(--ink); background: var(--sun-soft); box-shadow: 0 2px 0 var(--ink); }
.seg label:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---------------------------------------------------------------- paper: sheets, cut-outs, tags */
.sheet { position: relative; padding: 24px; border-radius: var(--r-page); background: var(--surface); box-shadow: var(--shadow); border: 1px solid var(--line); }
.sheet.fold::after { content: ""; position: absolute; top: -1px; right: -1px; width: 30px; height: 30px; border-top-right-radius: var(--r-page); background: linear-gradient(225deg, var(--bg) 0 50%, var(--fold) 50% 100%); box-shadow: -3px 3px 5px -2px rgba(60,40,10,.25); }
.tag { display: inline-flex; align-items: center; gap: 6px; padding: 3px 11px; border-radius: var(--r-pill); background: var(--surface-2); border: 1.5px solid var(--line-strong); font: 700 .76rem var(--font-ui); color: var(--ink); white-space: nowrap; }
.tag.teal { background: var(--teal-soft); border-color: var(--teal); color: var(--teal-ink); }
.tag.plum { background: var(--plum-soft); border-color: var(--plum); color: var(--plum); }
.tag.sun { background: var(--sun-soft); border-color: var(--sun); }
.tag.ok { background: var(--ok-soft); border-color: var(--ok); color: var(--ok-ink); } .tag.warn { background: var(--warn-soft); border-color: var(--warn); color: var(--warn-ink); } .tag.bad { background: var(--bad-soft); border-color: var(--bad); color: var(--bad-ink); }
/* a cut-out: the drawing's crop with a hand-torn edge. The shadow lives on the wrapper because clip-path would cut it. */
.cut { position: relative; display: block; filter: drop-shadow(0 7px 5px var(--cut-shadow)); transform: rotate(var(--tilt, -1.2deg)); }
.cut > .cut-face { display: block; width: 100%; height: 100%; object-fit: cover; background: var(--paper, #fff); clip-path: var(--torn); }
.cut-1 { --torn: polygon(1% 4%,9% 0,19% 2%,31% 0,44% 3%,58% 0,71% 2%,84% 0,95% 3%,100% 12%,98% 26%,100% 41%,97% 57%,100% 72%,98% 88%,94% 100%,80% 97%,66% 100%,52% 98%,38% 100%,24% 97%,11% 100%,2% 96%,0 82%,2% 66%,0 50%,3% 34%,0 18%); }
.cut-2 { --torn: polygon(0 6%,7% 1%,17% 3%,30% 0,46% 2%,60% 0,75% 3%,90% 0,100% 5%,98% 20%,100% 36%,97% 52%,100% 68%,97% 84%,100% 96%,88% 100%,73% 98%,58% 100%,43% 97%,27% 100%,13% 98%,3% 100%,1% 84%,3% 70%,0 52%,2% 36%,0 20%); }
.cut-3 { --torn: polygon(2% 2%,12% 0,26% 3%,40% 0,55% 2%,68% 0,82% 3%,97% 0,100% 14%,97% 30%,100% 46%,98% 62%,100% 78%,97% 94%,86% 100%,72% 97%,56% 100%,40% 98%,24% 100%,10% 97%,0 100%,2% 84%,0 68%,3% 52%,0 36%,2% 20%); }
.wash, .cut > .cut-face.wash { background: linear-gradient(145deg, var(--w1, var(--teal)), var(--w2, var(--sun)) 70%); }
.pin { position: absolute; top: -9px; left: 50%; width: 18px; height: 18px; margin-left: -9px; z-index: 2; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff8, transparent 40%), var(--brand); box-shadow: 0 3px 3px rgba(0,0,0,.3); }
.empty { display: grid; justify-items: center; gap: 10px; padding: 48px 20px; text-align: center; }
.empty p { max-width: 46ch; }
.err-state { display: grid; gap: 10px; justify-items: start; padding: 22px; border: 2px dashed var(--bad); border-radius: 14px; background: var(--bad-soft); color: var(--ink); }
.skels { display: grid; gap: 12px; } .skel { border-radius: 10px; background: linear-gradient(90deg, var(--surface-2), var(--bg-2), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
.skel.title { height: 32px; width: 40%; } .skel.line { height: 14px; } .skel.block { height: 140px; }
@keyframes shimmer { to { background-position: -200% 0; } }

.switch { position: relative; display: flex; align-items: center; gap: 14px; cursor: pointer; } .switch input { position: absolute; opacity: 0; width: 52px; height: 30px; margin: 0; cursor: pointer; }
.switch .sw { flex: none; position: relative; width: 52px; height: 30px; border-radius: 15px; border: 2px solid var(--ink); background: var(--surface-2); transition: background .15s; }
.switch .sw::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--ink); transition: transform .18s var(--ease); }
.switch input:checked + .sw { background: var(--teal); } .switch input:checked + .sw::after { transform: translateX(22px); background: #fff; }
.switch input:focus-visible + .sw { outline: 3px solid var(--focus); outline-offset: 2px; }
.switch b { display: block; }
.note { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; background: var(--sun-soft); border: 1.5px dashed var(--sun); } .note .ico { margin-top: 2px; flex: none; }

/* ---------------------------------------------------------------- dialogs, toasts */
dialog { width: min(520px, calc(100vw - 24px)); max-height: calc(100vh - 32px); padding: 26px; border: 2px solid var(--ink); border-radius: var(--r-page); background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lift); overflow: auto; }
dialog::backdrop { background: var(--scrim); }
dialog h2 { margin-bottom: 12px; padding-right: 40px; } dialog .x { position: absolute; right: 12px; top: 12px; }
dialog .body { display: grid; gap: 14px; } dialog .acts { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.toasts { position: fixed; z-index: 90; right: 16px; bottom: 16px; display: grid; gap: 10px; width: min(380px, calc(100vw - 32px)); }
.toast { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border: 2px solid var(--ink); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow-lift); font-size: .92rem; }
.toast.ok { background: var(--ok-soft); } .toast.bad { background: var(--bad-soft); } .toast.warn { background: var(--warn-soft); }
.toast .body { flex: 1; } .toast .x { border: 0; background: none; color: var(--muted); cursor: pointer; width: 24px; height: 24px; padding: 0; }
.toast .x .ico { width: 16px; height: 16px; }

/* ---------------------------------------------------------------- the camera: a full-screen viewfinder, always dark */
.cam{--cam-bg:#0e1020;--cam-accent:#FFD166;position:fixed;inset:0;z-index:95;background:var(--cam-bg);color:#fff;display:grid;grid-template-rows:minmax(0,1fr);overflow:hidden}
.cam-stage{position:absolute;inset:0;display:grid;place-items:center}
.cam-video{width:100%;height:100%;object-fit:cover;background:var(--cam-bg)}
.cam-guide{position:absolute;inset:12% 8% 22%;pointer-events:none;box-shadow:0 0 0 100vmax rgba(8,10,24,.5)}
.cam-guide i{position:absolute;width:34px;height:34px;border:4px solid var(--cam-accent)}
.cam-guide i:nth-child(1){left:-4px;top:-4px;border-right:0;border-bottom:0;border-top-left-radius:10px}
.cam-guide i:nth-child(2){right:-4px;top:-4px;border-left:0;border-bottom:0;border-top-right-radius:10px}
.cam-guide i:nth-child(3){left:-4px;bottom:-4px;border-right:0;border-top:0;border-bottom-left-radius:10px}
.cam-guide i:nth-child(4){right:-4px;bottom:-4px;border-left:0;border-top:0;border-bottom-right-radius:10px}
.cam-tip{position:absolute;left:12px;right:12px;top:calc(12% - 42px);text-align:center;font-size:.86rem;font-weight:650;color:rgba(255,255,255,.92);text-shadow:0 1px 4px rgba(0,0,0,.7);pointer-events:none}
.cam-hint{position:absolute;left:50%;bottom:calc(150px + env(safe-area-inset-bottom));transform:translateX(-50%);max-width:calc(100% - 32px);padding:8px 14px;border-radius:999px;background:rgba(14,16,32,.88);font-size:.88rem;font-weight:650;text-align:center;border:1.5px solid transparent}
.cam-hint[data-state="good"]{border-color:#3FA65B}
.cam-hint[data-state="dark"],.cam-hint[data-state="bright"],.cam-hint[data-state="blank"]{border-color:#FF8B2E}
.cam-top{position:absolute;left:0;right:0;top:0;display:flex;justify-content:space-between;gap:10px;padding:max(14px,env(safe-area-inset-top)) 14px 14px}
.cam-top-r{display:flex;gap:10px}
.cam-bottom{position:absolute;left:0;right:0;bottom:0;display:grid;grid-template-columns:1fr auto 1fr;align-items:center;padding:18px 26px calc(26px + env(safe-area-inset-bottom))}
.cam-bottom>:first-child{justify-self:start}
.cam-btn{position:relative;display:inline-grid;place-items:center;grid-auto-flow:column;gap:4px;min-width:48px;height:48px;padding:0 12px;border-radius:999px;border:0;background:rgba(14,16,32,.74);color:#fff;cursor:pointer}
.cam-btn:hover{background:rgba(14,16,32,.95)}
.cam-btn.on,.cam-btn[aria-pressed="true"]{background:var(--cam-accent);color:#1E2A47}
.cam-btn:focus-visible,.cam-shutter:focus-visible{outline:none;box-shadow:0 0 0 2px var(--cam-bg),0 0 0 4px #fff}
.cam-timer-n{font-size:.8rem;font-weight:800}.cam-timer-n:empty{display:none}
.cam-shutter{width:78px;height:78px;border-radius:50%;border:4px solid #fff;background:transparent;padding:4px;cursor:pointer}
.cam-shutter span{display:block;width:100%;height:100%;border-radius:50%;background:var(--cam-accent);transition:transform .1s}
.cam-shutter:active span{transform:scale(.88)}
.cam-shutter.busy span{background:#F25C3F;border-radius:12px;transform:scale(.55)}
.cam-count{position:absolute;display:grid;place-items:center;font:800 9rem/1 var(--font-display);color:#fff;text-shadow:0 4px 30px rgba(0,0,0,.6);pointer-events:none}
.cam-flash{position:absolute;inset:0;background:#fff;opacity:0;pointer-events:none}
@media (prefers-reduced-motion:no-preference){.cam-flash.go{animation:cam-flash .25s ease-out}@keyframes cam-flash{from{opacity:.9}to{opacity:0}}}
.cam-fail{position:absolute;inset:0;z-index:3;display:grid;place-items:center;padding:20px;background:var(--cam-bg)}
.cam-fail-card{display:grid;gap:14px;width:min(440px,100%);padding:24px;border-radius:18px;background:#20243A;border:1px solid #343A58}
.cam-fail-card h2{font-size:1.5rem;color:#F4EBD8}.cam-fail-text{margin:0;color:#D7D9E4}
.cam-fail-actions{display:grid;gap:10px}
.cam-fail-card .btn{background:#FFFBF3;color:#1E2A47;border-color:#FFFBF3;justify-content:flex-start;box-shadow:none}
.cam-fail-card .btn.quiet{background:transparent;color:#F4EBD8;border-color:#4B5278;justify-content:center}
@media (orientation:landscape) and (max-height:520px){.cam-guide{inset:12% 22% 12%}.cam-tip{display:none}.cam-hint{bottom:16px;left:24px;transform:none}.cam-bottom{grid-template-columns:auto 1fr auto}.cam-shutter{justify-self:end}}

/* ---------------------------------------------------------------- phones */
@media (max-width: 860px) {
  :root { --gutter: 16px; }
  .bar nav, .bar .cta-bar, .bar .ticket { display: none; }
  .bar { border-bottom-width: 1px; }
  .page { padding-top: 20px; padding-bottom: calc(var(--tab-h) + 40px); }
  .foot { padding-bottom: calc(var(--tab-h) + 30px); }
  .tabbar { position: fixed; z-index: 45; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: 1fr 1fr 76px 1fr 1fr; align-items: end; height: calc(var(--tab-h) + env(safe-area-inset-bottom)); padding: 0 6px env(safe-area-inset-bottom); background: var(--surface); border-top: 2px dashed var(--line-strong); }
  .tabbar a { display: grid; justify-items: center; gap: 2px; padding: 8px 0 10px; color: var(--muted); text-decoration: none; font: 700 .68rem var(--font-ui); }
  .tabbar a[aria-current="page"] { color: var(--ink); } .tabbar a[aria-current="page"] .ico { color: var(--brand-ink); }
  .tabbar .mid { justify-items: center; padding: 0 0 12px; }
  .tabbar .mid .pill { display: grid; place-items: center; width: 58px; height: 58px; margin-bottom: 4px; border: 2px solid var(--ink); border-radius: 50% 50% 50% 14%; background: var(--cta); color: var(--on-cta); box-shadow: 0 4px 0 var(--ink); transform: translateY(-14px) rotate(-4deg); }
  .tabbar .mid .pill .ico { width: 28px; height: 28px; }
  body.solo-cta .tabbar .mid, body[data-page="create"] .tabbar .mid, body[data-page="story"] .tabbar .mid { visibility: hidden; }
  .toasts { bottom: calc(var(--tab-h) + 16px); }
  dialog { width: calc(100vw - 16px); padding: 20px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; } }
@media print { .bar, .tabbar, .foot, .toasts, .banners { display: none !important; } body::before { display: none; } }
