:root {
  --bg: #07070c;
  --panel: #12121c;
  --line: #2a2a3a;
  --ink: #e5e7eb;
  --muted: #8b8fa3;
  --red: #dc2626;
  --red-dark: #7f1d1d;
  --green: #16a34a;
  --amber: #f59e0b;
  font-family: Inter, system-ui, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); overflow: hidden; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center-text { text-align: center; }
.error { color: #f87171; font-weight: 600; margin: 0; }
.error:empty { display: none; }

.screen { position: fixed; inset: 0; }
.screen.center { display: grid; place-items: center; padding: 16px; overflow-y: auto; background: radial-gradient(circle at 50% 30%, #1b1b2e 0, var(--bg) 70%); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 22px; max-width: 420px; width: 100%; display: flex; flex-direction: column; gap: 12px; box-shadow: 0 20px 60px #000a; }
.panel.wide { max-width: 480px; }
.panel h2, .panel h3 { margin: 0; }
.panel p { margin: 0; line-height: 1.45; }
.big-emoji { font-size: 48px; text-align: center; }
.logo { font-family: Creepster, cursive; font-weight: 400; font-size: clamp(54px, 16vw, 84px); margin: 0; text-align: center; color: var(--red); text-shadow: 0 0 18px #dc262688, 0 4px 0 #000; letter-spacing: 2px; }
.tag { text-align: center; color: #c7c9d6; }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 14px; }
input { font: inherit; font-size: 16px; padding: 12px 14px; border-radius: 12px; border: 2px solid var(--line); background: #0b0b12; color: var(--ink); width: 100%; }
input:focus { outline: none; border-color: var(--red); }
.join { display: flex; gap: 10px; }
.join input { width: 45%; text-transform: uppercase; letter-spacing: 4px; text-align: center; font-weight: 800; }
.join .btn { flex: 1; }
.btn { font: inherit; font-weight: 800; font-size: 15px; border: 0; border-radius: 12px; padding: 12px 16px; background: #23233a; color: var(--ink); cursor: pointer; text-align: center; text-decoration: none; }
.btn:active { transform: scale(.97); }
.btn.big { font-size: 18px; padding: 15px; }
.btn.red { background: var(--red); color: #fff; box-shadow: 0 0 20px #dc262655; }
.btn.green { background: var(--green); color: #fff; }
.row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.row .btn { flex: 1; }
.how summary { cursor: pointer; font-weight: 700; }
.how ul { margin: 8px 0 0; padding-left: 4px; list-style: none; display: grid; gap: 6px; font-size: 14px; color: #c7c9d6; }
.by { text-align: center; font-size: 12px; color: var(--muted); text-decoration: none; }
.by b { color: #93c5fd; }
.room-code { font-family: Creepster, cursive; font-size: 64px; letter-spacing: 12px; text-align: center; color: var(--red); line-height: 1; }
.players { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.players li { display: flex; align-items: center; gap: 10px; background: #0b0b12; border-radius: 10px; padding: 10px; font-weight: 700; }
.dot { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.tag-host { margin-left: auto; font-size: 11px; color: var(--amber); }

/* Game */
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hud { position: absolute; left: 0; right: 0; pointer-events: none; padding: 10px 12px; }
.hud.top { top: 0; display: grid; gap: 6px; padding-top: max(10px, env(safe-area-inset-top)); }
.hud-row { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.clock { font-family: 'Special Elite', monospace; font-size: 20px; color: #fca5a5; text-shadow: 0 0 8px #dc2626aa; }
.clock.late { animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .4; } }
.pages { display: flex; gap: 6px; }
.pages span { width: 30px; height: 38px; border-radius: 4px; background: #1f1f2e; border: 1px dashed #444; display: grid; place-items: center; font: 800 18px 'Special Elite', monospace; color: #555; }
.pages span.got { background: #e8e0c8; color: #1a1208; border: 0; transform: rotate(-3deg); box-shadow: 0 2px 6px #000a; }
.bars { justify-content: flex-start; }
.bar { display: flex; align-items: center; gap: 4px; font-size: 13px; }
.bar i { width: 64px; height: 8px; background: #1f1f2e; border-radius: 999px; overflow: hidden; display: block; }
.bar b { display: block; height: 100%; background: #a3e635; width: 100%; transition: width .2s; }
.bar b.low { background: var(--red); }
.where { margin-left: auto; font-size: 12px; color: var(--muted); }
.objective { font-size: 13px; background: #000a; border-radius: 10px; padding: 6px 10px; max-width: 560px; color: #e5e7eb; }
.objective.alert { color: #fecaca; background: #450a0acc; }
.prompt {
  position: absolute; left: 50%; bottom: 190px; transform: translateX(-50%); background: #000c; border: 1px solid #ffffff33;
  border-radius: 999px; padding: 8px 14px; font-weight: 700; font-size: 14px; pointer-events: none; white-space: nowrap;
}
@media (pointer: fine) { .prompt { bottom: 40px; } }
.toast { position: absolute; left: 50%; top: 130px; transform: translateX(-50%); background: #000d; border: 1px solid #ffffff22; border-radius: 12px; padding: 10px 14px; font-weight: 600; max-width: calc(100% - 32px); text-align: center; pointer-events: none; }
.page-card {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%) rotate(-2deg); width: min(320px, 86vw); background: #efe6cc;
  color: #2a1d0b; font-family: 'Special Elite', monospace; padding: 18px; border-radius: 4px; box-shadow: 0 20px 60px #000; text-align: center; pointer-events: none;
  animation: pagein .35s ease;
}
.page-card .digit { font-size: 64px; line-height: 1; margin: 6px 0; color: #7f1d1d; }
@keyframes pagein { from { transform: translate(-50%, -40%) rotate(-8deg); opacity: 0; } }

/* Touch controls */
.touch { position: absolute; inset: auto 0 0 0; height: 180px; padding-bottom: env(safe-area-inset-bottom); }
.joy-zone { position: absolute; left: 0; bottom: 0; width: 55%; height: 100%; touch-action: none; }
.joy { position: absolute; left: 24px; bottom: 30px; width: 120px; height: 120px; border-radius: 50%; background: #ffffff10; border: 2px solid #ffffff22; }
.knob { position: absolute; left: 35px; top: 35px; width: 50px; height: 50px; border-radius: 50%; background: #ffffff40; }
.buttons { position: absolute; right: 12px; bottom: 24px; display: grid; grid-template-columns: repeat(2, 64px); gap: 10px; }
.tbtn { width: 64px; height: 64px; border-radius: 50%; border: 2px solid #ffffff30; background: #ffffff14; color: #fff; font-size: 24px; display: grid; place-items: center; padding: 0; touch-action: none; user-select: none; -webkit-user-select: none; }
.tbtn small { font-size: 9px; font-weight: 700; margin-top: -10px; }
.tbtn.on { background: #dc262666; border-color: var(--red); }

/* Keypad */
.modal { position: absolute; inset: 0; background: #000b; display: grid; place-items: center; padding: 16px; }
.hints { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; font-family: 'Special Elite', monospace; }
.hints span { background: #e8e0c8; color: #1a1208; border-radius: 4px; padding: 4px 8px; }
.hints span.missing { background: #1f1f2e; color: var(--muted); }
.entry { font: 800 40px 'Special Elite', monospace; letter-spacing: 14px; text-align: center; background: #000; border-radius: 10px; padding: 8px; color: #86efac; }
.keys { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.keys button { font: 800 22px Inter, sans-serif; padding: 12px 0; border-radius: 10px; border: 0; background: #23233a; color: #fff; cursor: pointer; }

/* Caught overlay + jumpscare */
.down { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; background: radial-gradient(circle, #450a0a99, #000d 70%); padding: 20px; pointer-events: none; }
.down h2 { font-family: Creepster, cursive; font-weight: 400; font-size: 48px; color: var(--red); margin: 0; }
.down .revive { width: 220px; height: 10px; background: #1f1f2e; border-radius: 999px; overflow: hidden; margin: 10px auto; }
.down .revive b { display: block; height: 100%; background: var(--green); }
.scare { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 50; }

/* End */
.result { font-family: Creepster, cursive; font-weight: 400; font-size: clamp(48px, 14vw, 72px); text-align: center; margin: 0; line-height: 1; }
.result.win { color: #86efac; text-shadow: 0 0 20px #16a34a88; }
.result.lose { color: var(--red); text-shadow: 0 0 20px #dc262688; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.stats div { background: #0b0b12; border-radius: 10px; padding: 10px 4px; }
.stats b { display: block; font-size: 22px; }
.stats span { font-size: 12px; color: var(--muted); }
.ucc { background: #0c1a2a; border: 1px solid #1e3a5f; border-radius: 12px; padding: 12px; font-size: 14px; }
.ucc a { color: #93c5fd; font-weight: 700; }

/* Story: inventory, chapter cards, cutscenes, journal, gate countdown */
.inv { display: flex; align-items: center; gap: 8px; pointer-events: auto; }
.inv-icon { font-size: 14px; background: #000a; border-radius: 999px; padding: 4px 8px; }
.journal-btn { font-size: 18px; background: #000a; border: 1px solid #ffffff22; border-radius: 10px; padding: 3px 8px; cursor: pointer; }
.objective b { display: block; font-family: 'Special Elite', monospace; color: #fca5a5; font-weight: 400; font-size: 12px; letter-spacing: 1px; text-transform: uppercase; }
.chapter-card {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center; pointer-events: none;
  background: radial-gradient(circle, #000a, #000e 70%); animation: chapter 4.2s ease forwards;
}
.chapter-card h2 { font-family: Creepster, cursive; font-weight: 400; font-size: clamp(36px, 10vw, 64px); color: var(--red); margin: 0; text-shadow: 0 0 20px #dc262699; }
.chapter-card p { font-family: 'Special Elite', monospace; color: #e5e7eb; max-width: 420px; margin: 8px auto 0; padding: 0 16px; }
@keyframes chapter { 0% { opacity: 0; } 12%, 78% { opacity: 1; } 100% { opacity: 0; } }
.gate-timer {
  position: absolute; left: 50%; top: 38%; transform: translate(-50%, -50%); text-align: center; pointer-events: none;
  font-family: Creepster, cursive; color: #fca5a5; text-shadow: 0 0 18px #dc2626; font-size: 22px;
}
.gate-timer b { display: block; font-size: 72px; line-height: 1; color: #fff; }
.cutscene { position: fixed; inset: 0; z-index: 40; background: #000; display: grid; place-content: center; text-align: center; padding: 24px; cursor: pointer; }
.cut-title { font-family: Creepster, cursive; font-size: clamp(40px, 12vw, 72px); color: var(--red); text-shadow: 0 0 20px #dc262688; min-height: 1em; }
.cut-text { font-family: 'Special Elite', monospace; font-size: clamp(17px, 4.6vw, 24px); line-height: 1.6; color: #e5e7eb; white-space: pre-line; max-width: 640px; min-height: 6em; margin: 16px auto; }
.cut-tag { font-family: 'Special Elite', monospace; color: #fbbf24; min-height: 1.2em; }
.cut-hint { position: fixed; bottom: 26px; left: 0; right: 0; color: #555; font-size: 12px; animation: blink 2s steps(2) infinite; }
.cut-skip { position: fixed; top: 16px; right: 16px; font-size: 13px; padding: 8px 12px; }
.journal-panel { max-height: 86vh; }
.journal-body { overflow-y: auto; display: grid; gap: 10px; }
.journal-body .entry-card { background: #efe6cc; color: #2a1d0b; font-family: 'Special Elite', monospace; border-radius: 4px; padding: 12px; white-space: pre-line; font-size: 14px; }
.journal-body .entry-card b { display: block; margin-bottom: 4px; color: #7f1d1d; }
.journal-body .locked { color: var(--muted); font-style: italic; font-size: 13px; }
.page-card { max-height: 70vh; overflow: hidden; white-space: pre-line; }
.page-card .title { font-weight: 700; color: #7f1d1d; margin-bottom: 6px; }
.page-card.memory { background: #d9cfb3; }

/* 3D: the effects overlay sits on top of the WebGL canvas and never takes input */
.fx { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
