/* Design tokens. A neutral scale plus one indigo accent; everything else is derived.
   To re-skin the app, change the accent values and the font stack below. */
:root,
:root[data-theme='dark'] {
  --bg: #09090b;
  --panel: #111113;
  --panel-2: #1a1a1e;
  --line: #27272c;
  --ink: #fafafa;
  --soft: #d4d4d8;
  --dim: #8e8e99;
  --accent: #5558ee;
  --accent-hover: #6669f5;
  --accent-ink: #ffffff;
  --accent-text: #a5a7ff;
  --ring: #5558ee55;
  --red: #f43f5e;
  --danger-ink: #fb7185;
  --green: #34d399;
  --input-bg: #0d0d10;
  --tile-bg: #1e1e23;
  --tile-line: #2f2f36;
  --ticket-shadow: 0 20px 60px #0008;
  color-scheme: dark;
}

:root[data-theme='light'] {
  --bg: #f4f4f5;
  --panel: #ffffff;
  --panel-2: #f1f1f3;
  --line: #e4e4e7;
  --ink: #09090b;
  --soft: #3f3f46;
  --dim: #71717a;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-ink: #ffffff;
  --accent-text: #4f46e5;
  --ring: #4f46e544;
  --red: #e11d48;
  --danger-ink: #e11d48;
  --green: #059669;
  --input-bg: #ffffff;
  --tile-bg: #f1f1f3;
  --tile-line: #e2e2e6;
  --ticket-shadow: 0 12px 32px #09090b1a;
  color-scheme: light;
}

:root {
  --tw: clamp(1.55rem, 6.6vw, 2.3rem);
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --radius: 12px;
  /* The ticket is white paper in both themes */
  --ticket-bg: #ffffff;
  --ticket-ink: #09090b;
  --ticket-dim: #71717a;
  --ticket-accent: #4f46e5;
  --ticket-perf: #d4d4d8;
  --ticket-pill: #eef0ff;
  --ticket-pill-ink: #4338ca;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
#app { max-width: 32rem; margin: 0 auto; padding: 1rem 1.25rem calc(2.5rem + env(safe-area-inset-bottom)); }
main { display: flex; flex-direction: column; gap: 1.25rem; }
h1, h2, h3, p { margin: 0; }
button, input { font: inherit; color: inherit; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--dim); font-size: .9rem; }
[hidden] { display: none !important; }
.ic { flex: none; vertical-align: -.16em; }

/* ---- Buttons ---- */
.btn {
  appearance: none; border: 1px solid var(--line); background: transparent; color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .8rem 1.2rem; border-radius: var(--radius); font-weight: 600; font-size: .95rem; cursor: pointer;
  transition: background .15s, border-color .15s, transform .08s;
  min-height: 3rem; text-align: center;
}
.btn:hover:not(:disabled) { background: var(--panel-2); }
.btn:active:not(:disabled) { transform: scale(.985); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn small { font-weight: 500; color: var(--accent-text); font-size: .8rem; }
.btn:focus-visible, .icon:focus-visible, .linkish:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; }
.icon { appearance: none; background: none; border: 0; line-height: 1; width: 2.75rem; height: 2.75rem; border-radius: 50%; cursor: pointer; color: var(--dim); display: grid; place-items: center; transition: background .15s, color .15s; }
.icon:hover { color: var(--ink); background: var(--panel-2); }
.linkish { appearance: none; background: none; border: 0; color: var(--dim); font-size: .9rem; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; padding: .6rem; align-self: center; }
.linkish:hover { color: var(--ink); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.row .btn { padding-inline: .5rem; white-space: nowrap; }

.eyebrow { font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; color: var(--dim); font-weight: 600; display: flex; align-items: center; gap: .45rem; }
.eyebrow.center { justify-content: center; text-align: center; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 1.25rem; display: flex; flex-direction: column; gap: .85rem; }
.card p { color: var(--soft); line-height: 1.5; }

/* ---- Home ---- */
.home { padding-top: .2rem; }
.home-top { display: flex; justify-content: flex-end; margin-bottom: -1.7rem; position: relative; z-index: 1; }
.logo { font-weight: 800; font-size: clamp(3.4rem, 19vw, 5rem); line-height: 1; text-align: center; letter-spacing: -.05em; color: var(--ink); margin-top: .9rem; }
.tag { text-align: center; color: var(--dim); margin-top: -.7rem; }
.demo-cap { text-align: center; color: var(--dim); font-size: .9rem; margin-top: 1rem; }
.demo-cap strong { color: var(--ink); font-weight: 600; }
.done-line { color: var(--soft); }
.done-line strong { color: var(--ink); }
.challenge { border-color: var(--accent); }
.challenge .eyebrow { color: var(--accent-text); }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); text-align: center; padding: .25rem 0; }
.stats div { display: flex; flex-direction: column; gap: .15rem; padding: .2rem; }
.stats div + div { border-left: 1px solid var(--line); }
.stats b { font-weight: 700; font-size: 1.5rem; line-height: 1.1; letter-spacing: -.02em; color: var(--ink); font-variant-numeric: tabular-nums; }
.stats span { font-size: .7rem; color: var(--dim); }
footer { text-align: center; color: var(--dim); font-size: .85rem; }
footer a { color: var(--soft); }

/* ---- Title tiles ---- */
.marquee { padding: 1.4rem 1rem; border-radius: 20px; background: var(--panel); border: 1px solid var(--line); }
.tiles { display: flex; flex-wrap: wrap; justify-content: center; gap: .6rem 1.1rem; min-height: calc(var(--tw) * 1.4); }
.word { display: flex; gap: 4px; flex-wrap: nowrap; }
.word.flat { flex-wrap: wrap; justify-content: center; }
.tile {
  width: var(--tw); height: calc(var(--tw) * 1.3); display: grid; place-items: center;
  font-weight: 700; font-size: calc(var(--tw) * .68); line-height: 1; color: var(--ink);
  background: var(--tile-bg); border: 1px solid var(--tile-line); border-radius: 8px;
}
.tiles .word:not(.flat) .tile { animation: pop .3s ease backwards; }
.tiles .word:not(.flat) .tile:nth-child(2) { animation-delay: .03s; }
.tiles .word:not(.flat) .tile:nth-child(3) { animation-delay: .06s; }
.tiles .word:not(.flat) .tile:nth-child(n+4) { animation-delay: .09s; }
@keyframes pop { from { transform: translateY(-6px) scale(.92); opacity: 0; } }

/* ---- Leaderboard ---- */
.bar-title { flex: 1; text-align: center; font-weight: 600; font-size: 1rem; }
.lb, #lb-body { display: flex; flex-direction: column; gap: 1.5rem; }
.lb-head { display: flex; align-items: baseline; justify-content: space-between; gap: .5rem; margin-bottom: .6rem; }
.lb-head h3 { font-size: 1.25rem; font-weight: 700; letter-spacing: -.02em; }
.lb-head span { color: var(--dim); font-size: .8rem; }
.lb-list { list-style: none; margin: 0; padding: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; overflow: hidden; }
.lb-list li { display: grid; grid-template-columns: 2rem 1fr auto; align-items: center; gap: .5rem; padding: .8rem 1rem; }
.lb-list li + li { border-top: 1px solid var(--line); }
.lb-list li.me { background: var(--panel-2); }
.lb-list .rk { color: var(--dim); font-weight: 600; font-variant-numeric: tabular-nums; }
.lb-list li:nth-child(-n+3) .rk { color: var(--accent-text); }
.lb-list .nm { display: flex; flex-direction: column; min-width: 0; }
.lb-list .nm b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-list .nm em { font-style: normal; font-size: .7rem; font-weight: 600; color: var(--accent-text); }
.lb-list .sc { font-weight: 700; font-variant-numeric: tabular-nums; }
.lb-empty { color: var(--dim); text-align: center; padding: 1rem 0; }

/* ---- Game ---- */
.bar { display: flex; align-items: center; gap: .5rem; }
.dots { display: flex; gap: .3rem; flex: 1; margin: 0 .5rem; }
.dots i { flex: 1; height: .3rem; border-radius: 2px; background: var(--line); }
.dots i.done { background: var(--accent); }
.dots i.now { background: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.total { font-weight: 700; font-size: 1.1rem; color: var(--ink); min-width: 2.75rem; text-align: right; font-variant-numeric: tabular-nums; }
.game section { display: flex; flex-direction: column; gap: 1.25rem; }
.actor-line { text-align: center; color: var(--soft); font-size: 1.05rem; min-height: 1.6rem; } /* reserved so the clue buttons don't jump */
.actor-line strong { color: var(--ink); font-weight: 600; }
.pips { display: inline-flex; gap: 3px; margin-left: .35rem; }
.pips i { width: .4rem; height: .4rem; border-radius: 50%; background: var(--line); }
.pips i.on { background: var(--accent-text); }

.meter { display: grid; gap: .6rem; }
.worth { display: flex; align-items: baseline; justify-content: center; gap: .5rem; }
.worth span { font-weight: 800; font-size: 3.5rem; line-height: 1; letter-spacing: -.04em; font-variant-numeric: tabular-nums; }
.worth small { color: var(--dim); font-size: .8rem; }
.track { height: 6px; background: var(--line); border-radius: 6px; overflow: hidden; }
.fill { height: 100%; border-radius: 6px; background: var(--accent); transition: width .15s linear; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; justify-content: center; min-height: 1.7rem; }
.chip { display: inline-flex; align-items: center; gap: .3rem; font-size: .78rem; font-weight: 500; padding: .2rem .6rem; border-radius: 8px; background: var(--panel-2); color: var(--soft); font-variant-numeric: tabular-nums; }

.clues { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.clue { font-size: .9rem; padding: .7rem .5rem; gap: .3rem .45rem; flex-wrap: wrap; background: var(--panel); }
#guess { display: flex; gap: .6rem; }
#guess input, .share input, .name-field input {
  min-width: 0; padding: .9rem 1rem; border-radius: var(--radius); font-size: 1.05rem;
  background: var(--input-bg); border: 1.5px solid var(--line); transition: border-color .15s, box-shadow .15s;
}
#guess input { flex: 1; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
#guess input::placeholder, .share input::placeholder, .name-field input::placeholder { color: var(--dim); text-transform: none; letter-spacing: 0; font-weight: 400; opacity: .8; }
#guess input:focus, .share input:focus, .name-field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--ring); }
#guess input.shake { animation: shake .35s; border-color: var(--red); }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
#feedback { min-height: 1.3rem; text-align: center; font-size: .95rem; margin-top: -.4rem; }
#feedback.warn { color: var(--accent-text); }
#feedback.bad { color: var(--danger-ink); }

.reveal { display: flex; flex-direction: column; align-items: center; gap: .8rem; text-align: center; padding: 2rem 1.25rem; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; animation: rise .4s ease; }
@keyframes rise { from { transform: translateY(12px); opacity: 0; } }
.reveal .verdict { line-height: 1; color: var(--accent-text); }
.reveal.lose .verdict { color: var(--danger-ink); }
.reveal h2 { font-weight: 800; font-size: clamp(1.7rem, 7.5vw, 2.3rem); letter-spacing: -.03em; line-height: 1.1; }
.reveal.lose h2 { color: var(--danger-ink); }
.reveal .pts { font-weight: 800; font-size: 3rem; line-height: 1; letter-spacing: -.04em; font-variant-numeric: tabular-nums; }
.reveal .parts { color: var(--dim); font-size: .9rem; line-height: 1.7; }
.reveal .parts em { font-style: normal; color: var(--ink); }
.reveal .btn { align-self: stretch; margin-top: .5rem; }

/* ---- Results / ticket ---- */
.ticket { background: var(--ticket-bg); color: var(--ticket-ink); border-radius: 20px; position: relative; overflow: hidden; box-shadow: var(--ticket-shadow); border: 1px solid var(--line); animation: rise .5s ease; }
.ticket-top { padding: 1.5rem 1rem 1.3rem; text-align: center; display: flex; flex-direction: column; gap: .6rem; align-items: center; }
.ticket .eyebrow { color: var(--ticket-dim); }
.verdicts { display: flex; gap: .7rem; justify-content: center; color: var(--ticket-accent); }
.big { font-weight: 800; font-size: 4.5rem; line-height: 1; color: var(--ticket-ink); letter-spacing: -.05em; font-variant-numeric: tabular-nums; }
.stamp { font-weight: 700; font-size: .75rem; letter-spacing: .1em; padding: .35rem .9rem; border-radius: 999px; background: var(--ticket-pill); color: var(--ticket-pill-ink); }
.perf { position: relative; border-top: 2px dashed var(--ticket-perf); margin: 0 1rem; }
.perf::before, .perf::after { content: ''; position: absolute; top: -1rem; width: 2rem; height: 2rem; border-radius: 50%; background: var(--bg); box-shadow: inset 0 0 0 1px var(--line); }
.perf::before { left: -2rem; }
.perf::after { right: -2rem; }
.film-list { list-style: none; margin: 0; padding: 1rem 1.1rem 1.3rem; display: grid; gap: .7rem; }
.film-list li { display: grid; grid-template-columns: 1.8rem 1fr auto; gap: .6rem; align-items: center; }
.film-list .v { color: var(--ticket-accent); display: grid; place-items: center; }
.film-list .t { display: flex; flex-direction: column; min-width: 0; }
.film-list b { font-size: .95rem; font-weight: 600; overflow-wrap: anywhere; }
.film-list small { color: var(--ticket-dim); font-size: .78rem; font-variant-numeric: tabular-nums; display: flex; flex-wrap: wrap; gap: .1rem .5rem; align-items: center; }
.film-list .s { font-weight: 700; font-size: 1.05rem; font-variant-numeric: tabular-nums; }

.versus .vs-row { display: flex; justify-content: space-between; align-items: baseline; color: var(--soft); }
.versus .vs-row b { font-weight: 800; font-size: 1.6rem; letter-spacing: -.03em; color: var(--ink); font-variant-numeric: tabular-nums; }
.versus p { text-align: center; font-weight: 600; color: var(--ink); }
.versus.won { border-color: var(--green); }
.versus.lost { border-color: var(--red); }
.streak-line { text-align: center; color: var(--dim); font-size: .95rem; }
.streak-line span:not(.ic) { color: var(--ink); font-variant-numeric: tabular-nums; }
.share label { font-size: .85rem; color: var(--dim); }

/* Results: one name field, then separate, explained actions */
.actions { display: flex; flex-direction: column; gap: 1rem; }
.name-field { display: flex; flex-direction: column; gap: .4rem; }
.name-field label { font-size: .85rem; font-weight: 600; color: var(--soft); }
.hint { font-size: .8rem; color: var(--dim); }
.action h3 { display: flex; align-items: center; gap: .5rem; font-size: 1rem; font-weight: 700; letter-spacing: -.01em; }
.action p { font-size: .92rem; }

/* ---- Help dialog + toast ---- */
dialog { max-width: min(30rem, calc(100vw - 2rem)); border: 1px solid var(--line); border-radius: 20px; background: var(--panel); color: var(--ink); padding: 1.5rem; line-height: 1.55; }
dialog::backdrop { background: #000a; backdrop-filter: blur(4px); }
dialog h2 { font-weight: 700; font-size: 1.35rem; letter-spacing: -.02em; margin-bottom: .5rem; }
dialog code { background: var(--panel-2); padding: .1rem .4rem; border-radius: .3rem; font-size: .9em; font-weight: 600; }
dialog ol { padding-left: 1.2rem; margin: .8rem 0; display: grid; gap: .6rem; }
.credit { font-size: .78rem; margin-top: .6rem; }
dialog ul { margin: .3rem 0 0; padding-left: 1.1rem; }
dialog .btn { width: 100%; margin-top: 1rem; }
#toast { position: fixed; left: 50%; bottom: calc(1.5rem + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: var(--ink); color: var(--bg); padding: .7rem 1.1rem; border-radius: 2rem; font-weight: 600; font-size: .92rem; opacity: 0; pointer-events: none; transition: .25s; z-index: 10; width: max-content; max-width: calc(100vw - 2rem); text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
