:root {
  --bg: #0a0a0f;
  --bg-soft: #14141d;
  --bg-card: #1a1a26;
  --line: #2c2c3a;
  --ink: #ece9e2;
  --ink-dim: #989aa8;
  --accent: #d9a441;     /* amber */
  --accent-soft: #3a2e16;
  --teal: #3fb6c0;
  --danger: #d9544f;
  --ok: #5bbf73;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 17px; line-height: 1.45; -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
#app { min-height: 100%; }
h1,h2,h3 { font-family: "Iowan Old Style", Georgia, "Times New Roman", serif; letter-spacing: .01em; }
h2 { font-size: 1.5rem; margin: 0 0 .6rem; }
h3 { font-size: 1.1rem; }
.muted { color: var(--ink-dim); }
.center { text-align: center; }
[hidden] { display: none !important; }
.screen { min-height: 100vh; min-height: 100dvh; }

/* film grain overlay across everything */
.grain {
  position: fixed; inset: 0; pointer-events: none; z-index: 200; opacity: .045;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  mix-blend-mode: overlay;
}

/* inputs / buttons */
.text-input { width: 100%; padding: 14px 16px; font-size: 17px; color: var(--ink); background: var(--bg-soft); border: 1px solid var(--line); border-radius: var(--radius); outline: none; margin-bottom: 14px; }
.text-input:focus { border-color: var(--accent); }
textarea.text-input { resize: vertical; font-family: inherit; }
.code-input { text-transform: uppercase; letter-spacing: .5em; text-align: center; font-size: 1.6rem; font-weight: 700; }
.field-label { display: block; font-size: .85rem; color: var(--ink-dim); margin: 0 0 6px 2px; }
.btn { width: 100%; padding: 16px; font-size: 17px; font-weight: 600; border: none; border-radius: var(--radius); cursor: pointer; color: #fff; transition: transform .06s ease, opacity .2s; }
.btn:active { transform: scale(.985); }
.btn:disabled { opacity: .5; }
.btn-primary { background: var(--accent); color: #1a1300; }
.btn-ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn-danger { background: var(--danger); }
.btn + .btn { margin-top: 10px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--ink-dim); font-size: .8rem; margin: 18px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.error-text { color: var(--danger); text-align: center; margin-top: 14px; }

/* home / lobby */
.home-wrap, .lobby-wrap, .finished-wrap { max-width: 460px; margin: 0 auto; padding: calc(var(--safe-top) + 32px) 20px 40px; }
.lobby-wrap { text-align: center; }
.brand { text-align: center; margin-bottom: 28px; }
.brand-badge { font-size: 2.6rem; }
.brand h1 { font-size: 2.8rem; letter-spacing: .28em; margin: 6px 0 8px; text-shadow: 0 2px 24px rgba(217,164,65,.25); }
.tagline { color: var(--ink-dim); margin: 0 auto; max-width: 320px; }
.card { background: var(--bg-card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.room-code { font-family: ui-monospace, Menlo, monospace; font-size: 3rem; font-weight: 800; letter-spacing: .3em; color: var(--accent); background: var(--accent-soft); border: 1px dashed var(--accent); border-radius: var(--radius); padding: 14px 10px 14px 24px; margin: 10px 0; width: 100%; cursor: pointer; }
.copied-hint { color: var(--ok); font-size: .9rem; margin: -4px 0 10px; }
.section-title { text-align: left; margin: 24px 0 10px; color: var(--ink-dim); text-transform: uppercase; font-size: .8rem; letter-spacing: .1em; }
.player-list { list-style: none; padding: 0; margin: 0; text-align: left; }
.player-list li { display: flex; align-items: center; gap: 10px; padding: 13px 14px; background: var(--bg-card); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; }
.player-list .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ink-dim); flex: 0 0 auto; }
.player-list .dot.on { background: var(--ok); }
.player-list .pname { flex: 1; font-weight: 600; }
.player-list .badge { font-size: .72rem; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.player-list .badge.solved { background: rgba(91,191,115,.15); color: var(--ok); }
.player-list .qcount { font-size: .8rem; color: var(--ink-dim); }
.seg { display: flex; gap: 6px; background: var(--bg-soft); border: 1px solid var(--line); border-radius: 12px; padding: 5px; }
.seg-btn { flex: 1; padding: 11px 6px; border: none; background: none; color: var(--ink-dim); border-radius: 9px; font-size: .95rem; font-weight: 600; cursor: pointer; }
.seg-btn.active { background: var(--accent); color: #1a1300; }

/* spinner / center */
.center-screen { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; gap: 8px; }
.spinner { width: 46px; height: 46px; border: 4px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .9s linear infinite; margin-bottom: 16px; }
.spinner.small { width: 30px; height: 30px; border-width: 3px; margin: 0; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================ GAME STAGE ============================ */
.game-screen { position: relative; height: 100dvh; overflow: hidden; }
.stage { position: absolute; inset: 0; background: #05050a; }
.scene-img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity .6s ease; filter: saturate(.85) contrast(1.05); }
.scene-img.loaded { opacity: 1; }
.scene-img.swap { animation: sceneIn .6s ease; }
@keyframes sceneIn { from { opacity: 0; transform: scale(1.04); } to { opacity: 1; transform: scale(1); } }
.vignette { position: absolute; inset: 0; pointer-events: none; background: radial-gradient(ellipse at center, transparent 45%, rgba(0,0,0,.55) 100%), linear-gradient(180deg, rgba(0,0,0,.45) 0%, transparent 22%, transparent 60%, rgba(0,0,0,.6) 100%); }
.scene-loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.scene-loading[hidden] { display: none; }

/* hotspots */
.hotspots { position: absolute; inset: 0; }
.hotspot { position: absolute; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center; gap: 6px; cursor: pointer; background: none; border: none; padding: 0; font: inherit; color: var(--ink); }
.hotspot .ring { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-size: 1rem; background: rgba(10,10,15,.55); border: 2px solid var(--accent); box-shadow: 0 0 0 0 rgba(217,164,65,.5); animation: pulse 2.2s infinite; backdrop-filter: blur(2px); }
.hotspot.kind-suspect .ring { border-color: var(--teal); box-shadow: 0 0 0 0 rgba(63,182,192,.5); animation: pulseTeal 2.2s infinite; }
.hotspot.kind-travel .ring { border-color: #cfd3dc; }
.hotspot .tag { font-size: .72rem; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: rgba(10,10,15,.72); border: 1px solid var(--line); white-space: nowrap; max-width: 42vw; overflow: hidden; text-overflow: ellipsis; }
.hotspot.done .ring { border-color: var(--ok); animation: none; opacity: .7; }
.hotspot:active { transform: translate(-50%,-50%) scale(.92); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(217,164,65,.5);} 70%{box-shadow:0 0 0 14px rgba(217,164,65,0);} 100%{box-shadow:0 0 0 0 rgba(217,164,65,0);} }
@keyframes pulseTeal { 0% { box-shadow: 0 0 0 0 rgba(63,182,192,.5);} 70%{box-shadow:0 0 0 14px rgba(63,182,192,0);} 100%{box-shadow:0 0 0 0 rgba(63,182,192,0);} }

/* HUD */
.hud-top { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: flex-start; gap: 8px; padding: calc(var(--safe-top) + 12px) 12px 12px; background: linear-gradient(180deg, rgba(0,0,0,.6), transparent); z-index: 10; }
.hud-left { flex: 1; min-width: 0; }
.hud-scene { font-family: Georgia, serif; font-weight: 700; font-size: 1.15rem; text-shadow: 0 1px 6px #000; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-case { font-size: .72rem; color: var(--ink-dim); text-transform: uppercase; letter-spacing: .08em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip { flex: 0 0 auto; background: rgba(20,20,29,.7); border: 1px solid var(--line); color: var(--ink); border-radius: 999px; padding: 7px 11px; font-size: .82rem; font-weight: 700; cursor: pointer; backdrop-filter: blur(4px); }
#gh-code { font-family: ui-monospace, Menlo, monospace; color: var(--accent); border-color: var(--accent); background: rgba(58,46,22,.6); letter-spacing: .06em; }

.hud-bottom { position: absolute; bottom: 0; left: 0; right: 0; display: flex; gap: 10px; padding: 12px 14px calc(12px + var(--safe-bottom)); background: linear-gradient(0deg, rgba(0,0,0,.7), transparent); z-index: 10; }
.hud-btn { position: relative; flex: 1; background: rgba(20,20,29,.82); border: 1px solid var(--line); color: var(--ink); border-radius: 14px; padding: 11px 6px; font-size: .74rem; font-weight: 600; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 3px; backdrop-filter: blur(6px); }
.hud-btn span { font-size: 1.3rem; line-height: 1; }
.hud-btn.accuse { background: rgba(217,84,79,.2); border-color: var(--danger); color: #ffb3b0; }
.badge-count { position: absolute; top: -6px; right: 10px; background: var(--accent); color: #1a1300; font-size: .68rem; font-weight: 800; font-style: normal; min-width: 18px; height: 18px; border-radius: 999px; display: grid; place-items: center; padding: 0 4px; }

/* ============================ OVERLAYS ============================ */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.66); display: flex; align-items: flex-end; justify-content: center; z-index: 100; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.overlay-card { background: var(--bg-soft); border: 1px solid var(--line); border-top-left-radius: 22px; border-top-right-radius: 22px; width: 100%; max-width: 540px; padding: 18px 18px calc(20px + var(--safe-bottom)); max-height: 86dvh; overflow-y: auto; animation: slideUp .26s cubic-bezier(.2,.8,.2,1); }
@keyframes slideUp { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
.overlay-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.overlay-head h3 { margin: 0; }
.icon-btn { background: none; border: none; color: var(--ink-dim); font-size: 1.3rem; cursor: pointer; flex: 0 0 auto; }

/* evidence */
.evidence-card { position: relative; }
.evidence-stamp { position: absolute; top: 52px; right: 18px; transform: rotate(-12deg); border: 3px solid var(--danger); color: var(--danger); font-weight: 900; letter-spacing: .15em; padding: 2px 10px; border-radius: 6px; opacity: .8; font-family: Georgia, serif; pointer-events: none; }
.evidence-card p { font-size: 1.02rem; }

/* talk */
.talk-card .overlay-head { align-items: flex-start; }
.talk-who { display: flex; gap: 12px; align-items: center; min-width: 0; }
.portrait { width: 56px; height: 56px; border-radius: 12px; object-fit: cover; background: var(--bg-card); border: 1px solid var(--line); flex: 0 0 auto; }
.talk-name { font-weight: 700; font-size: 1.1rem; }
.talk-role { color: var(--accent); font-size: .85rem; }
.chat-area { display: flex; flex-direction: column; gap: 10px; min-height: 140px; max-height: 48dvh; overflow-y: auto; padding: 4px 0; }
.bubble { max-width: 86%; padding: 11px 14px; border-radius: 16px; font-size: .96rem; }
.bubble.me { align-self: flex-end; background: var(--accent); color: #1a1300; border-bottom-right-radius: 4px; }
.bubble.them { align-self: flex-start; background: var(--bg-card); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.bubble.typing { color: var(--ink-dim); font-style: italic; }
.ask-form { display: flex; gap: 8px; align-items: flex-start; margin-top: 12px; }
.ask-form .text-input { margin-bottom: 0; }
.btn-send { width: 52px; flex: 0 0 auto; font-size: 1.3rem; padding: 14px 0; }
.empty-hint { color: var(--ink-dim); text-align: center; padding: 24px 0; }

/* dossier */
.tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.tab { flex: 1; padding: 9px 6px; border: 1px solid var(--line); background: var(--bg-card); color: var(--ink-dim); border-radius: 10px; font-size: .85rem; font-weight: 600; cursor: pointer; }
.tab.active { background: var(--accent); color: #1a1300; border-color: var(--accent); }
.info-block { background: var(--bg-card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.info-block h3 { margin: 0 0 6px; color: var(--accent); }
.info-block p { margin: 0 0 8px; } .info-block p:last-child { margin: 0; }
.clue-empty { color: var(--ink-dim); text-align: center; padding: 20px; }
.people-card { display: flex; gap: 12px; align-items: center; background: var(--bg-card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 10px; }
.people-card .pc-body { min-width: 0; flex: 1; }
.people-card .pc-name { font-weight: 700; }
.people-card .pc-role { color: var(--accent); font-size: .82rem; }
.people-card .pc-alibi { color: var(--ink-dim); font-size: .88rem; margin-top: 4px; }
.people-card button { margin-top: 8px; padding: 8px 12px; background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent); border-radius: 9px; font-weight: 600; cursor: pointer; font-size: .85rem; }

/* map */
.map-list { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.map-tile { position: relative; border-radius: 14px; overflow: hidden; border: 1px solid var(--line); cursor: pointer; aspect-ratio: 3/2; background: var(--bg-card); }
.map-tile img { width: 100%; height: 100%; object-fit: cover; }
.map-tile .mt-name { position: absolute; left: 0; right: 0; bottom: 0; padding: 10px 10px 8px; font-weight: 700; font-size: .9rem; background: linear-gradient(0deg, rgba(0,0,0,.85), transparent); }
.map-tile.current { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }

/* accuse */
.accuse-suspects { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.accuse-suspects label { display: flex; align-items: center; gap: 12px; padding: 12px; background: var(--bg-card); border: 1px solid var(--line); border-radius: 12px; cursor: pointer; }
.accuse-suspects img { width: 38px; height: 38px; border-radius: 9px; object-fit: cover; flex: 0 0 auto; background: var(--bg-soft); }
.accuse-suspects input { width: 20px; height: 20px; accent-color: var(--danger); flex: 0 0 auto; }
.accuse-suspects label.sel { border-color: var(--danger); }
.feedback { margin-top: 14px; padding: 13px 15px; border-radius: 12px; text-align: center; }
.feedback.bad { background: rgba(217,84,79,.14); color: var(--danger); }
.feedback.warn { background: var(--accent-soft); color: var(--accent); }

/* finished */
.result-banner { text-align: center; font-size: 1.5rem; font-weight: 800; font-family: Georgia, serif; padding: 22px; border-radius: var(--radius); margin-bottom: 18px; }
.result-banner.win { background: rgba(91,191,115,.14); color: var(--ok); border: 1px solid var(--ok); }
.result-banner.lose { background: var(--bg-card); color: var(--ink); border: 1px solid var(--line); }
.info-block.reveal h3 { color: var(--ok); }

/* toast + confetti */
.toast { position: fixed; left: 50%; bottom: calc(96px + var(--safe-bottom)); transform: translateX(-50%); background: #000; color: #fff; padding: 12px 18px; border-radius: 999px; font-size: .92rem; z-index: 150; border: 1px solid var(--line); max-width: 90vw; text-align: center; }
.confetti { position: fixed; top: -10px; width: 9px; height: 14px; z-index: 180; pointer-events: none; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(105vh) rotate(540deg); opacity: .9; } }
