:root {
  --night: #0f1630;
  --night-2: #18213f;
  --night-3: #243056;
  --ivory: #f4ecdc;
  --ivory-dim: #c9bfae;
  --gold: #e3b955;
  --red: #c94a3a;
  --green: #6fbf73;
  --paper: #fbf5e8;
  --ink: #1f1a17;
  --radius: 16px;
  --bd: "Bangers", Impact, sans-serif;
  --hand: "Patrick Hand", cursive;
  --sans: "Inter", system-ui, -apple-system, sans-serif;
  --nav-h: 76px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: radial-gradient(ellipse at top, var(--night-3), var(--night) 65%) fixed;
  color: var(--ivory); font: 16px/1.5 var(--sans); min-height: 100dvh;
}
img { max-width: 100%; display: block; }
.bd { font-family: var(--bd); letter-spacing: .04em; font-weight: 400; }
h1.bd { font-size: clamp(2.2rem, 1.4rem + 4vw, 3.4rem); line-height: 1; margin: .2em 0; color: var(--gold); text-shadow: 3px 3px 0 #000; }
h2.bd { font-size: 1.9rem; line-height: 1.05; margin: 0 0 .3em; color: var(--gold); }
h3.bd { font-size: 1.5rem; margin: 0 0 .3em; color: var(--gold); }
.eyebrow { text-transform: uppercase; letter-spacing: .16em; font-size: .72rem; color: var(--gold); margin: 0 0 .3em; }
.lede { color: var(--ivory-dim); margin: .4em 0 1em; }
.note { color: var(--ivory-dim); font-size: .88rem; }

.btn {
  font: 600 1rem var(--sans); border: 0; border-radius: 999px; padding: .85em 1.3em; cursor: pointer;
  background: var(--gold); color: var(--night); transition: transform .12s, opacity .2s; text-decoration: none; display: inline-flex; justify-content: center; align-items: center;
}
.btn:active { transform: scale(.97); }
.btn.ghost { background: transparent; color: var(--gold); box-shadow: inset 0 0 0 1.5px var(--gold); }
.btn.small { padding: .5em .9em; font-size: .85rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.card { background: linear-gradient(180deg, rgba(36,48,86,.85), rgba(24,33,63,.95)); border: 1px solid rgba(227,185,85,.25); border-radius: var(--radius); padding: 16px; margin: 14px 0; }

/* ---------- Lobby & intro ---------- */
.lobby, .screen { max-width: 640px; margin: 0 auto; padding: 16px 16px calc(var(--nav-h) + 24px); }
.lobby { display: flex; flex-direction: column; gap: 12px; padding-bottom: 40px; }
.cover { border-radius: var(--radius); box-shadow: 0 20px 50px rgba(0,0,0,.5); max-height: 52vh; object-fit: cover; width: 100%; }
.invite b { color: var(--gold); }
.invite p { margin: .3em 0 .6em; color: var(--ivory-dim); font-size: .9rem; }
.invite-row { display: flex; gap: 8px; }
.invite-row input { flex: 1; min-width: 0; background: var(--night); color: var(--ivory); border: 1px solid var(--night-3); border-radius: 10px; padding: .5em; font-size: .75rem; }
.role-card { border: 1.5px dashed var(--gold); border-radius: var(--radius); padding: 14px 16px; margin: 14px 0; }
.role-card h2 { margin: .2em 0; font-family: var(--bd); color: var(--ivory); letter-spacing: .04em; }
.role-card p { margin: 0; color: var(--ivory-dim); }
.badge { display: inline-block; font-size: .7rem; text-transform: uppercase; letter-spacing: .12em; border: 1px solid var(--gold); color: var(--gold); border-radius: 999px; padding: .25em .7em; }
.rules { padding-left: 1.1em; color: var(--ivory-dim); }
.rules li { margin-bottom: .5em; }
.rules b { color: var(--ivory); }

/* ---------- Header & nav ---------- */
.top {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 10px; padding: 10px 16px 14px;
  background: rgba(15,22,48,.92); backdrop-filter: blur(8px); border-bottom: 1px solid rgba(227,185,85,.15);
}
.top .title { font-size: 1.3rem; color: var(--gold); flex: 1; }
.presence { width: 10px; height: 10px; border-radius: 50%; background: var(--red); flex: none; }
.presence.on { background: var(--green); box-shadow: 0 0 8px var(--green); }
.timer { font-variant-numeric: tabular-nums; font-size: .85rem; color: var(--ivory-dim); }
.tabs { display: flex; background: var(--night); border-radius: 999px; padding: 3px; }
.tabs button { border: 0; background: none; color: var(--ivory-dim); font: 600 .8rem var(--sans); padding: .4em .8em; border-radius: 999px; cursor: pointer; }
.tabs button.on { background: var(--gold); color: var(--night); }
.progress { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: rgba(255,255,255,.08); }
.progress i { display: block; height: 100%; background: var(--gold); transition: width .4s; }
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; gap: 8px; justify-content: space-between;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: rgba(15,22,48,.95); border-top: 1px solid rgba(227,185,85,.15);
}
.nav .btn { flex: 1; padding: .8em .6em; font-size: .92rem; }

/* ---------- Comics ---------- */
.chapter { margin: 6px 0 12px; }
.panels { display: flex; flex-direction: column; gap: 16px; }
.panel { margin: 0; background: var(--paper); color: var(--ink); border-radius: 12px; overflow: hidden; border: 3px solid #000; box-shadow: 0 10px 30px rgba(0,0,0,.4); }
.panel img { width: 100%; }
.panel figcaption { padding: 10px 12px 12px; }
.caption { background: #f2c94c; border: 2px solid #000; display: inline-block; padding: .2em .6em; margin: 0 0 8px; font: 600 .88rem/1.35 var(--sans); }
.panel.text-only { background: linear-gradient(160deg, #fff7e2, #f1e3c2); }
.panel.text-only figcaption { padding: 22px 16px; }
.panel.text-only .caption { font-size: 1.05rem; }
.bubble { display: flex; gap: 8px; align-items: flex-start; margin-top: 8px; }
.bubble div { background: #fff; border: 2px solid #000; border-radius: 16px; padding: .35em .75em; font: 1.08rem/1.25 var(--hand); }
.bubble b { color: var(--red); font-weight: 400; margin-right: .3em; }
.avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; border: 2px solid #000; flex: none; background: #d9cdb6; }
.avatar.sm { width: 34px; height: 34px; }
.avatar.lg { width: 84px; height: 84px; float: left; margin: 0 12px 6px 0; }
.avatar-empty { display: grid; place-items: center; font-weight: 700; color: var(--ink); }
.box-card p:last-child { margin: 0; }

/* ---------- Suspect files ---------- */
.files { display: flex; flex-direction: column; gap: 12px; }
.file { display: grid; grid-template-columns: 110px 1fr; gap: 12px; background: var(--paper); color: var(--ink); border-radius: 12px; padding: 12px; border: 2px solid #000; }
.file.compact { grid-template-columns: 64px 1fr; }
.mug { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; border: 2px solid #000; background: #d9cdb6; }
.file-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.file-head h3 { margin: 0; color: var(--ink); font-size: 1.4rem; }
.dossier { font-size: .75rem; font-weight: 700; color: var(--red); white-space: nowrap; }
.meta { margin: .2em 0 .4em; font-size: .82rem; color: #5a4e44; }
.file dl { margin: 0; font-size: .84rem; display: grid; gap: 2px; }
.file dt { font-size: .66rem; text-transform: uppercase; letter-spacing: .08em; color: #8a7a6a; margin-top: 4px; }
.file dd { margin: 0; }
.alibi { margin: .6em 0 0; background: #fff8e6; border-left: 4px solid #2d4f7c; padding: .4em .6em; font: 1.02rem/1.3 var(--hand); }
.accuse-btn { margin: -4px 0 6px; align-self: flex-end; }

/* ---------- Puzzles ---------- */
.solved { margin: 14px 0; background: rgba(111,191,115,.15); border: 1.5px solid var(--green); color: #c9f1cb; border-radius: 12px; padding: 12px 14px; font-weight: 600; }
.answer { display: flex; gap: 8px; margin-top: 12px; }
.answer input { flex: 1; min-width: 0; background: var(--night); color: var(--ivory); border: 1.5px solid var(--night-3); border-radius: 999px; padding: .7em 1em; font: 1rem var(--sans); text-transform: uppercase; }
.wordlist { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 14px; font: 600 1.05rem var(--sans); letter-spacing: .06em; }
.ws-grid { display: grid; grid-template-columns: repeat(var(--n), 1fr); gap: 2px; background: #000; border: 3px solid #000; border-radius: 10px; overflow: hidden; touch-action: manipulation; }
.ws-cell { aspect-ratio: 1; border: 0; background: var(--paper); color: var(--ink); font: 700 clamp(.85rem, 3.6vw, 1.15rem) var(--sans); cursor: pointer; padding: 0; }
.ws-cell.found { background: #f2c94c; }
.ws-cell.start { background: var(--red); color: #fff; }
.ws-cell.left { color: var(--red); background: #ffe9e4; }
.sudoku { display: grid; grid-template-columns: repeat(9, 1fr); border: 3px solid #000; background: #000; gap: 1px; border-radius: 6px; overflow: hidden; }
.sd-cell { aspect-ratio: 1; border: 0; background: var(--paper); color: #2d4f7c; font: 700 clamp(.95rem, 4.2vw, 1.3rem) var(--sans); position: relative; padding: 0; cursor: pointer; }
.sd-cell.given { color: var(--ink); cursor: default; }
.sd-cell.code { background: #d9cdb6; }
.sd-cell.sel { box-shadow: inset 0 0 0 3px var(--red); }
.sd-cell.c3 { box-shadow: 2px 0 0 #000; }
.sd-cell.r3 { box-shadow: 0 2px 0 #000; }
.sd-cell.c3.r3 { box-shadow: 2px 0 0 #000, 0 2px 0 #000; }
.sd-cell i { position: absolute; top: 1px; left: 3px; font: 700 .6rem var(--sans); color: var(--red); font-style: normal; }
.pad { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-top: 10px; }
.pad button { border: 0; border-radius: 10px; padding: .7em 0; background: var(--night-3); color: var(--ivory); font: 700 1.1rem var(--sans); cursor: pointer; }
.padlock { width: 220px; margin: 20px auto; position: relative; padding-top: 70px; }
.padlock .shackle { position: absolute; top: 0; left: 50%; width: 120px; height: 110px; transform: translateX(-50%); border: 16px solid #9aa5ab; border-bottom: 0; border-radius: 60px 60px 0 0; transition: transform .5s; }
.padlock.open .shackle { transform: translateX(-50%) translateY(-24px) rotate(-12deg); transform-origin: left bottom; }
.padlock .body { position: relative; background: linear-gradient(180deg, #c9a227, #8a6d14); border-radius: 18px; padding: 18px; display: flex; justify-content: center; gap: 14px; border: 3px solid #000; }
.wheel { display: flex; flex-direction: column; align-items: center; background: var(--paper); border-radius: 10px; border: 2px solid #000; color: var(--ink); }
.wheel span { font: 700 2rem var(--sans); padding: 0 .4em; }
.wheel button { border: 0; background: none; font-size: 1.1rem; padding: .3em .8em; cursor: pointer; color: var(--ink); }
.defs { padding-left: 2em; }
.defs li { margin-bottom: .6em; }
.defs small { color: var(--ivory-dim); }
.mgrid { display: flex; flex-direction: column; gap: 6px; overflow-x: auto; padding-bottom: 6px; }
.grow { display: flex; align-items: center; gap: 6px; }
.gn { width: 20px; text-align: right; font-weight: 700; color: var(--gold); flex: none; }
.gcells { display: grid; grid-template-columns: repeat(var(--w), minmax(24px, 32px)); gap: 2px; }
.gc { width: 100%; aspect-ratio: 1; border: 2px solid #000; border-radius: 4px; background: var(--paper); color: var(--ink); text-align: center; font: 700 1.05rem var(--sans); text-transform: uppercase; padding: 0; }
.gc.key { background: #f2c94c; }
.gc.blank { border: 0; background: none; }
.grow.ok .gc:not(.blank) { background: #d6f2d8; }
.grow.ok .gc.key { background: #b7e6a0; }
.suspects { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.suspect { border: 2px solid #000; border-radius: 12px; background: var(--paper); padding: 8px; cursor: pointer; display: flex; flex-direction: column; gap: 6px; align-items: center; }
.suspect span { color: var(--ink); font-size: 1.3rem; }
.suspect:disabled { cursor: default; opacity: .8; }
.story { overflow: hidden; }
.story p { margin: 0; }
.hint-card b { color: var(--gold); }

/* ---------- End ---------- */
.certificate { background: var(--paper); color: var(--ink); border-radius: var(--radius); border: 6px double #b8975a; padding: 18px; text-align: center; margin: 16px 0; }
.certificate h3 { color: var(--red); }
.stats { display: flex; justify-content: center; gap: 22px; margin: 12px 0; }
.stats b { display: block; font-size: 1.5rem; }
.stats span { font-size: .75rem; color: #5a4e44; }
.message { font: 1.3rem/1.35 var(--hand); }

/* ---------- Modal & toast ---------- */
dialog { border: 0; padding: 0; background: transparent; width: min(520px, calc(100vw - 24px)); color: var(--ivory); }
dialog::backdrop { background: rgba(5,8,20,.7); backdrop-filter: blur(3px); }
.modal { background: linear-gradient(180deg, var(--night-3), var(--night-2)); border: 1px solid var(--gold); border-radius: 18px; padding: 20px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.hints { padding-left: 1.2em; }
.hints li { margin-bottom: .6em; }
.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px); transform: translateX(-50%); background: var(--ivory); color: var(--night); padding: .65em 1.1em; border-radius: 999px; font-weight: 600; opacity: 0; transition: opacity .25s; pointer-events: none; z-index: 30; max-width: calc(100vw - 32px); text-align: center; }
.toast.show { opacity: 1; }

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