/* ─── Base ───────────────────────────────────────────────────────────────── */
:root {
  --bg: #0a0a0c;
  --surface: #111114;
  --surface2: #18181d;
  --border: #2a2a32;
  --red: #e8001c;
  --red-dim: #8a0010;
  --red-glow: rgba(232,0,28,0.2);
  --amber: #f5a623;
  --green: #00e87a;
  --text: #f0f0f0;
  --text-dim: #b8b8b8;
  --text-muted: #787878;
  --font-display: 'Bebas Neue', sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
  --font-body: 'IBM Plex Sans', sans-serif;

  /* App height. On phones `vh` resolves to the viewport with the browser
     toolbars *retracted*, so a 100vh box is taller than what you can actually
     see and its bottom is unreachable. `dvh` tracks the visible area instead. */
  --app-h: 100vh;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

@supports (height: 100dvh) {
  :root { --app-h: 100dvh; }
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Touch ergonomics: no grey flash on tap, no 300ms double-tap-zoom delay. */
@media (pointer: coarse) {
  a, button, label, .action-player, .vote-card, .picker-item,
  .nb-chip, .location-tag, .assign-chip, .hand-chip {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }
}

/* Scanlines */
#scanline {
  pointer-events: none;
  position: fixed; inset: 0; z-index: 9999;
  background: repeating-linear-gradient(to bottom, transparent 0px, transparent 2px, rgba(0,0,0,0.08) 2px, rgba(0,0,0,0.08) 4px);
}

#noise {
  pointer-events: none;
  position: fixed; inset: 0; z-index: 9998;
  opacity: 0.03;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ─── Screens ─────────────────────────────────────────────────────────────── */
.screen {
  display: none; height: var(--app-h); overflow-y: auto;
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
}
.screen.active { display: flex; flex-direction: column; }

/* ─── Home ────────────────────────────────────────────────────────────────── */
.home-wrap {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; min-height: 100%; flex: 1 0 auto;
  padding: 2rem; gap: 3rem;
}

.logo-block { text-align: center; }

.logo-eye {
  font-size: 3rem; margin-bottom: 0.5rem;
  animation: pulse-eye 3s ease-in-out infinite;
}

@keyframes pulse-eye {
  0%, 100% { filter: drop-shadow(0 0 4px var(--red)); }
  50% { filter: drop-shadow(0 0 20px var(--red)); }
}

.logo-title {
  font-family: var(--font-display);
  font-size: clamp(4rem, 12vw, 8rem);
  letter-spacing: 0.15em;
  line-height: 1;
  background: linear-gradient(180deg, #fff 0%, #aaa 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
  position: relative;
}

.logo-title::after {
  content: 'SPYCRAFT';
  position: absolute; left: 0; top: 0; width: 100%;
  background: linear-gradient(180deg, var(--red) 0%, transparent 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
  opacity: 0; animation: glitch 6s infinite;
}

@keyframes glitch {
  0%, 90%, 100% { opacity: 0; transform: none; }
  92% { opacity: 0.8; transform: translateX(-3px) skewX(-2deg); }
  94% { opacity: 0; }
  96% { opacity: 0.5; transform: translateX(2px); }
  98% { opacity: 0; }
}

.logo-sub {
  font-family: var(--font-mono);
  font-size: 0.7rem; letter-spacing: 0.3em;
  color: var(--red); margin-top: 0.5rem;
}

.home-actions {
  display: flex; align-items: center; gap: 1.5rem;
  flex-wrap: wrap; justify-content: center;
  max-width: 720px; width: 100%;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 2rem; flex: 1; min-width: 240px;
  position: relative; overflow: hidden;
  transition: border-color 0.2s, transform 0.2s;
}
.card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0;
  height: 2px; background: var(--red);
  transform: scaleX(0); transform-origin: left;
  transition: transform 0.3s;
}
.card:hover { border-color: var(--red-dim); transform: translateY(-2px); }
.card:hover::before { transform: scaleX(1); }

.card-label {
  font-family: var(--font-mono); font-size: 0.65rem;
  letter-spacing: 0.2em; color: var(--red); margin-bottom: 0.5rem;
}
.card h2 {
  font-family: var(--font-display); font-size: 2rem;
  letter-spacing: 0.05em; margin-bottom: 0.5rem;
}
.card p { font-size: 0.85rem; color: var(--text-dim); margin-bottom: 1.5rem; line-height: 1.5; }

.card-divider {
  font-family: var(--font-mono); font-size: 0.75rem;
  color: var(--text-muted); padding: 0.5rem;
}

/* ─── Form Screens ────────────────────────────────────────────────────────── */
.form-screen {
  max-width: 520px; margin: 0 auto;
  padding: 2rem 1.5rem; width: 100%;
  min-height: 100%; flex: 1 0 auto;
  display: flex; flex-direction: column; gap: 1.5rem;
}

.form-title {
  font-family: var(--font-display);
  font-size: 3rem; letter-spacing: 0.1em;
  margin-top: 0.5rem;
}

.form-sub {
  font-family: var(--font-mono); font-size: 0.75rem;
  color: var(--text-dim); letter-spacing: 0.15em;
  margin-top: -1rem;
}

.form-group { display: flex; flex-direction: column; gap: 0.5rem; }

.form-group label {
  font-family: var(--font-mono); font-size: 0.65rem;
  letter-spacing: 0.25em; color: var(--red);
}

.hint {
  font-size: 0.6rem; color: var(--text-muted);
  text-transform: none; letter-spacing: 0.1em;
}

input[type="text"], input[type="number"] {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-mono); font-size: 1rem;
  padding: 0.75rem 1rem; outline: none;
  transition: border-color 0.2s;
}
input[type="text"]:focus, input[type="number"]:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 2px var(--red-glow);
}

.code-input {
  font-family: var(--font-display) !important;
  font-size: 2.5rem !important; letter-spacing: 0.3em;
  text-align: center; text-transform: uppercase;
}

.timer-controls {
  display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center;
}

.btn-timer {
  font-family: var(--font-mono); font-size: 0.7rem;
  padding: 0.4rem 0.75rem; letter-spacing: 0.1em;
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text-dim); cursor: pointer; transition: all 0.15s;
}
.btn-timer:hover, .btn-timer.active {
  background: var(--red); border-color: var(--red);
  color: white;
}
.btn-timer + input[type="number"] { flex: 1; min-width: 100px; }

/* File drop */
.file-drop {
  border: 1px dashed var(--border); background: var(--surface2);
  padding: 1.5rem; text-align: center; cursor: pointer; position: relative;
  transition: border-color 0.2s;
}
.file-drop:hover, .file-drop.drag-over { border-color: var(--red); }
.file-drop input[type="file"] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%;
}
.file-drop-inner { pointer-events: none; display: flex; flex-direction: column; gap: 0.25rem; }
.file-icon { font-size: 1.5rem; }
#file-label { font-family: var(--font-mono); font-size: 0.85rem; }
.file-format { font-size: 0.7rem; color: var(--text-muted); font-family: var(--font-mono); }
.csv-example {
  font-family: var(--font-mono); font-size: 0.65rem; color: var(--text-dim);
  background: var(--surface); border: 1px solid var(--border);
  padding: 0.5rem 0.6rem; margin-top: 0.4rem; white-space: pre;
  line-height: 1.6; text-align: left;
}

.csv-status {
  font-family: var(--font-mono); font-size: 0.75rem;
  padding: 0.5rem 0.75rem; border-left: 2px solid var(--green); color: var(--green);
}
.csv-status.error { border-color: var(--red); color: var(--red); }

.checkbox-group { flex-direction: row; align-items: center; gap: 0.75rem; }
.checkbox-label {
  display: flex; align-items: center; gap: 0.75rem; cursor: pointer;
  font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.15em;
  color: var(--text-dim) !important;
}
.checkbox-label input[type="checkbox"] { display: none; }
.checkbox-custom {
  width: 18px; height: 18px; border: 1px solid var(--border);
  background: var(--surface2); display: inline-block; position: relative;
  transition: border-color 0.2s;
}
.checkbox-label input:checked + .checkbox-custom {
  border-color: var(--red); background: var(--red);
}
.checkbox-label input:checked + .checkbox-custom::after {
  content: '✓'; position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%); font-size: 12px; color: white;
}

/* ─── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  font-family: var(--font-mono); font-size: 0.8rem;
  letter-spacing: 0.15em; padding: 0.75rem 1.5rem;
  border: none; cursor: pointer; transition: all 0.15s;
  text-transform: uppercase;
}
.btn.full { width: 100%; }
.btn-primary {
  background: var(--red); color: white;
}
.btn-primary:hover { background: #ff0020; box-shadow: 0 0 20px var(--red-glow); }
.btn-outline {
  background: transparent; color: var(--text);
  border: 1px solid var(--border);
}
.btn-outline:hover { border-color: var(--red); color: var(--red); }
.btn-ghost {
  background: transparent; color: var(--text-dim);
  border: 1px solid transparent; font-size: 0.7rem;
}
.btn-ghost:hover { color: var(--text); }
.btn-ghost.small { padding: 0.3rem 0; }
.btn-danger { background: var(--red-dim); color: white; border: 1px solid var(--red); }
.btn-danger:hover { background: var(--red); }
.btn-skip { background: var(--surface2); color: var(--text-dim); border: 1px solid var(--border); }
.btn-skip:hover { border-color: var(--amber); color: var(--amber); }
.btn-back {
  font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.15em;
  background: none; border: none; color: var(--text-dim); cursor: pointer;
  padding: 0; align-self: flex-start;
}
.btn-back:hover { color: var(--red); }

.error-msg {
  font-family: var(--font-mono); font-size: 0.75rem;
  color: var(--red); padding: 0.5rem; border-left: 2px solid var(--red);
}
.hidden { display: none !important; }

/* ─── Game Layout ─────────────────────────────────────────────────────────── */
.game-layout {
  display: flex; height: 100%; min-height: 0; flex: 1; overflow: hidden;
}

.game-main {
  flex: 1; min-width: 0; min-height: 0;
  overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  padding: 1.5rem; padding-left: max(1.5rem, var(--safe-l));
  padding-right: max(1.5rem, var(--safe-r));
  padding-bottom: calc(1.5rem + var(--safe-b));
  display: flex; flex-direction: column; gap: 1.25rem;
}

/* ─── Chat Panel ──────────────────────────────────────────────────────────── */
.chat-panel {
  width: 280px; border-left: 1px solid var(--border);
  display: flex; flex-direction: column; background: var(--surface);
  flex-shrink: 0;
}
.chat-header {
  font-family: var(--font-mono); font-size: 0.65rem; letter-spacing: 0.3em;
  color: var(--red); padding: 0.75rem 1rem; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
}
.chat-messages {
  flex: 1; overflow-y: auto; padding: 0.75rem;
  display: flex; flex-direction: column; gap: 0.5rem;
}
.chat-msg {
  font-family: var(--font-mono); font-size: 0.72rem; line-height: 1.4;
}
.chat-msg .sender {
  color: var(--red); font-size: 0.65rem;
  letter-spacing: 0.05em; margin-bottom: 0.1rem;
}
.chat-msg .sender.spectator { color: var(--amber); }
.chat-msg .sender.system { color: var(--text-muted); }
.chat-msg .text { color: var(--text-dim); }
.chat-msg.system .text { color: var(--text-muted); font-style: italic; }

.chat-input-wrap {
  display: flex; border-top: 1px solid var(--border);
}
.chat-input-wrap input {
  flex: 1; border: none; border-right: 1px solid var(--border);
  font-size: 0.8rem; padding: 0.6rem 0.75rem; background: var(--surface);
}
.chat-input-wrap button {
  padding: 0 1rem; background: none; border: none; color: var(--red);
  font-size: 1.2rem; cursor: pointer;
}
.chat-input-wrap button:hover { color: white; }
.btn-clear-chat {
  color: #4da6ff !important; font-size: 0.85rem !important;
  padding: 0 0.75rem !important; border-left: 1px solid var(--border) !important;
}
.btn-clear-chat:hover { color: #80c4ff !important; }

/* ─── Lobby ───────────────────────────────────────────────────────────────── */
.lobby-header {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 1rem;
}
.room-code-display {
  display: flex; align-items: center; gap: 0.75rem;
}
.room-code-label {
  font-family: var(--font-mono); font-size: 0.6rem;
  letter-spacing: 0.25em; color: var(--text-muted);
}
.room-code-value {
  font-family: var(--font-display); font-size: 2.5rem;
  letter-spacing: 0.3em; color: var(--red);
  text-shadow: 0 0 20px var(--red-glow);
}
.btn-copy {
  background: none; border: 1px solid var(--border); color: var(--text-dim);
  padding: 0.3rem 0.5rem; cursor: pointer; font-size: 1rem;
  transition: all 0.15s;
}
.btn-copy:hover { border-color: var(--red); color: var(--red); }

.player-count-badge {
  font-family: var(--font-mono); font-size: 0.7rem;
  letter-spacing: 0.1em; color: var(--text-dim);
  padding: 0.3rem 0.75rem; border: 1px solid var(--border);
}

.section-label {
  font-family: var(--font-mono); font-size: 0.6rem;
  letter-spacing: 0.25em; color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.location-tags { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.location-tag {
  font-family: var(--font-mono); font-size: 0.65rem;
  padding: 0.25rem 0.6rem; border: 1px solid var(--border);
  color: var(--text-dim); background: var(--surface2);
}
.location-tag-clickable {
  cursor: pointer; transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.location-tag-clickable:hover {
  border-color: var(--red); color: var(--text); background: rgba(232,0,28,0.08);
}
.location-tag.loc-disabled { opacity: 0.35; border-style: dashed; }
.location-tag.loc-disabled .location-tag-name,
.location-tag.loc-disabled.location-tag-clickable { text-decoration: line-through; }
.location-tag-name { cursor: pointer; }
.loc-toggle-btn {
  background: none; border: none; cursor: pointer; padding: 0 0 0 0.35rem;
  font-size: 0.8rem; line-height: 1; color: var(--red); transition: color 0.15s;
  vertical-align: middle; font-family: var(--font-mono);
}
.loc-toggle-btn:hover { color: var(--red-dim); }

.players-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 0.75rem;
}

.player-tile {
  background: var(--surface2); border: 1px solid var(--border);
  padding: 0.75rem 1rem; position: relative;
  display: flex; align-items: center; gap: 0.5rem;
  transition: border-color 0.2s;
}
.player-tile.host { border-color: var(--red-dim); }
.player-tile.disconnected { opacity: 0.4; }
.player-tile-name {
  font-family: var(--font-mono); font-size: 0.85rem; font-weight: 600; flex: 1;
}
.player-tile-badge {
  font-size: 0.55rem; letter-spacing: 0.15em; color: var(--red);
  font-family: var(--font-mono);
}
.player-tile-dot {
  position: absolute; top: 0.5rem; right: 0.5rem;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--green);
}
.player-tile.disconnected .player-tile-dot { background: var(--text-muted); }

.lobby-controls { border-top: 1px solid var(--border); padding-top: 1.25rem; }
.timer-display {
  font-family: var(--font-mono); font-size: 0.75rem;
  color: var(--text-dim); margin-bottom: 0.75rem;
}
.waiting-msg {
  font-family: var(--font-mono); font-size: 0.75rem;
  color: var(--text-muted); letter-spacing: 0.1em;
  animation: blink 1.5s step-end infinite;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0.3} }

.timer-adjust { margin-bottom: 1rem; }
.timer-adjust label {
  font-family: var(--font-mono); font-size: 0.6rem;
  letter-spacing: 0.25em; color: var(--text-muted); display: block; margin-bottom: 0.4rem;
}
.timer-controls-small { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.btn-timer-sm {
  font-family: var(--font-mono); font-size: 0.65rem;
  padding: 0.3rem 0.6rem; background: var(--surface2);
  border: 1px solid var(--border); color: var(--text-dim);
  cursor: pointer; transition: all 0.15s; letter-spacing: 0.05em;
}
.btn-timer-sm:hover, .btn-timer-sm.active { background: var(--red); border-color: var(--red); color: white; }

/* ─── Playing Screen ──────────────────────────────────────────────────────── */
.playing-header {
  display: flex; gap: 1.5rem; align-items: center; flex-wrap: wrap;
}

.timer-circle {
  width: 110px; height: 110px; flex-shrink: 0; position: relative;
}
.timer-circle svg { transform: rotate(-90deg); width: 100%; height: 100%; }
.timer-bg { fill: none; stroke: var(--surface2); stroke-width: 6; }
.timer-progress {
  fill: none; stroke: var(--red); stroke-width: 6;
  stroke-linecap: butt;
  stroke-dasharray: 276.46;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 1s linear;
}
.timer-text {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  font-family: var(--font-display); font-size: 1.8rem; letter-spacing: 0.05em;
  color: var(--text);
}

.role-card {
  flex: 1; min-width: 200px; background: var(--surface2);
  border: 1px solid var(--border); padding: 1rem 1.25rem;
  position: relative;
}
.role-card::before {
  content: ''; position: absolute; top: 0; left: 0;
  width: 3px; height: 100%; background: var(--red);
}
.role-label {
  font-family: var(--font-mono); font-size: 0.6rem;
  letter-spacing: 0.25em; color: var(--text-muted); margin-bottom: 0.25rem;
}
.role-location {
  font-family: var(--font-display); font-size: 1.6rem; letter-spacing: 0.05em;
  margin-bottom: 0.1rem;
}
.role-location.spy-hidden { color: var(--red); letter-spacing: 0.1em; }
.role-name {
  font-family: var(--font-mono); font-size: 0.8rem; color: var(--text-dim);
}

.turn-indicator {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.75rem 1rem; background: var(--surface2);
  border-left: 3px solid var(--amber);
}
.turn-arrow { color: var(--amber); font-size: 0.8rem; animation: pulse-arrow 1s ease-in-out infinite; }
@keyframes pulse-arrow { 0%,100%{opacity:1;transform:translateX(0)} 50%{opacity:0.5;transform:translateX(3px)} }
.turn-text { font-family: var(--font-mono); font-size: 0.85rem; }
.turn-text strong { color: var(--amber); }

.question-target {
  font-family: var(--font-mono); font-size: 0.8rem;
  padding: 0.5rem 0.75rem; background: var(--surface2);
  border: 1px solid var(--amber); color: var(--amber); letter-spacing: 0.05em;
}

.players-action-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 0.6rem;
}

.action-player {
  background: var(--surface2); border: 1px solid var(--border);
  padding: 0.75rem; cursor: pointer; text-align: center;
  transition: all 0.15s; position: relative; overflow: hidden;
}
.action-player::after {
  content: 'ASK →'; position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.1em;
  background: var(--red); opacity: 0; transition: opacity 0.15s;
}
.action-player:not(.self):not(.disabled):hover::after { opacity: 1; }
.action-player:not(.self):not(.disabled):hover { border-color: var(--red); }
.action-player.self { cursor: default; border-style: dashed; }
.action-player.disabled { cursor: default; opacity: 0.5; }
.action-player .ap-name { font-family: var(--font-mono); font-size: 0.85rem; font-weight: 600; }
.action-player .ap-label { font-size: 0.6rem; color: var(--text-muted); letter-spacing: 0.1em; margin-top: 0.2rem; }
.action-player.current-turn { border-color: var(--amber) !important; }
.action-player.current-turn .ap-label { color: var(--amber); }
.action-player.being-asked { border-color: var(--green) !important; }

.playing-controls { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: center; }

.hands-raised {
  display: flex; flex-wrap: wrap; gap: 0.4rem;
}
.hand-entry {
  display: flex; align-items: center; gap: 0.2rem;
}
.hand-chip {
  font-family: var(--font-mono); font-size: 0.65rem;
  padding: 0.2rem 0.6rem; border: 1px solid var(--text-muted);
  color: var(--text-dim);
}
.btn-grant-turn {
  background: none; border: 1px solid var(--border);
  color: var(--green); font-size: 0.6rem; padding: 0.1rem 0.4rem;
  cursor: pointer; line-height: 1; transition: all 0.15s; font-family: var(--font-mono);
}
.btn-grant-turn:hover { border-color: var(--green); background: rgba(0,232,122,0.1); }
.btn-lower-hand {
  background: none; border: 1px solid var(--border);
  color: var(--red); font-size: 0.6rem; padding: 0.1rem 0.4rem;
  cursor: pointer; line-height: 1; transition: all 0.15s; font-family: var(--font-mono);
}
.btn-lower-hand:hover { border-color: var(--red); background: rgba(255,60,60,0.1); }

/* ─── Voting ──────────────────────────────────────────────────────────────── */
.voting-header { text-align: center; padding: 0.5rem 0 1rem; }
.voting-title {
  font-family: var(--font-display); font-size: 2.5rem; letter-spacing: 0.1em;
  color: var(--red);
}
.voting-sub { font-family: var(--font-mono); font-size: 0.75rem; color: var(--text-dim); margin: 0.25rem 0; }
.vote-progress { font-family: var(--font-mono); font-size: 0.8rem; margin-top: 0.5rem; }
.vote-countdown {
  font-family: var(--font-mono); font-size: 1.1rem; font-weight: 700;
  color: var(--text-dim); margin-top: 0.35rem; letter-spacing: 0.05em;
  transition: color 0.3s;
}
.vote-countdown-urgent { color: var(--red); animation: vote-blink 0.7s ease-in-out infinite alternate; }
@keyframes vote-blink { 0% { opacity: 1; } 100% { opacity: 0.45; } }

.voting-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 0.75rem;
}

.vote-card {
  background: var(--surface2); border: 1px solid var(--border);
  padding: 1.25rem; text-align: center; cursor: pointer;
  transition: all 0.15s; position: relative;
}
.vote-card:not(.self):not(.voted):hover {
  border-color: var(--red); transform: translateY(-2px);
  box-shadow: 0 4px 20px var(--red-glow);
}
.vote-card.voted-for { border-color: var(--red); background: rgba(232,0,28,0.1); }
.vote-card.voted-for::after {
  content: 'VOTED'; position: absolute; top: 0.4rem; right: 0.4rem;
  font-family: var(--font-mono); font-size: 0.5rem; letter-spacing: 0.15em;
  color: var(--red);
}
.vote-card.self { cursor: default; opacity: 0.5; border-style: dashed; }
.vote-card.voted:not(.voted-for) { cursor: default; }
.vote-card-name { font-family: var(--font-display); font-size: 1.5rem; letter-spacing: 0.05em; }
.voted-status {
  font-family: var(--font-mono); font-size: 0.55rem; letter-spacing: 0.1em;
  margin-top: 0.3rem; color: var(--green);
}
.voted-status.pending { color: var(--text-muted); }

/* ─── Results ─────────────────────────────────────────────────────────────── */
.results-wrap {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 100%; flex: 1 0 auto;
  gap: 1.5rem; padding: 2rem; padding-bottom: calc(2rem + var(--safe-b));
  text-align: center;
}

.result-verdict {
  font-family: var(--font-display); font-size: clamp(2.5rem, 8vw, 5rem);
  letter-spacing: 0.1em; animation: verdict-in 0.5s ease-out both;
}
.result-verdict.caught { color: var(--green); }
.result-verdict.escaped { color: var(--red); }

@keyframes verdict-in {
  from { opacity: 0; transform: scale(0.7); }
  to { opacity: 1; transform: scale(1); }
}

.spy-reveal {
  font-family: var(--font-mono); font-size: 1rem; color: var(--text-dim);
  animation: fade-up 0.5s 0.2s ease-out both;
}
.spy-reveal strong { color: var(--red); }

.result-location {
  font-family: var(--font-display); font-size: 2rem; letter-spacing: 0.1em;
  color: var(--amber); animation: fade-up 0.5s 0.4s ease-out both;
}

@keyframes fade-up {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.assignments-reveal {
  display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center;
  max-width: 600px; animation: fade-up 0.5s 0.6s ease-out both;
}

.assign-chip {
  font-family: var(--font-mono); font-size: 0.7rem;
  padding: 0.4rem 0.75rem; border: 1px solid var(--border); color: var(--text-dim);
  background: var(--surface2);
}
.assign-chip.is-spy { border-color: var(--red); color: var(--red); }
.assign-chip.is-spy span { color: white; }

/* ─── Scrollbars ──────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: var(--surface); }
::-webkit-scrollbar-thumb { background: var(--border); }
::-webkit-scrollbar-thumb:hover { background: var(--red-dim); }

/* Mobile COMMS toggle (hidden on desktop) */
.btn-float-chat {
  display: none; position: fixed; z-index: 5500;
  bottom: calc(1rem + var(--safe-b)); right: calc(1rem + var(--safe-r));
  font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: 0.1em;
  padding: 0.5rem 0.9rem; background: var(--surface2);
  border: 1px solid var(--amber); color: var(--amber); cursor: pointer;
  align-items: center; gap: 0.35rem; transition: all 0.15s;
}
.btn-float-chat:hover { background: var(--amber); color: var(--bg); }

/* Close button inside chat header (hidden on desktop) */
.btn-chat-close {
  display: none; background: none; border: none; color: var(--text-muted);
  font-size: 0.85rem; cursor: pointer; padding: 0 0.25rem; transition: color 0.15s;
  margin-left: auto; flex-shrink: 0;
}
.btn-chat-close:hover { color: var(--red); }

/* Compact layout: narrow phones, and any short viewport (phone landscape),
   where a fixed 280px side chat panel would leave nothing for the game. */
@media (max-width: 640px), (max-height: 560px) {
  /* Chat: hidden by default, shown as full-screen overlay when toggled */
  .chat-panel { display: none; }
  .chat-panel.mobile-open {
    display: flex; position: fixed; top: 0; left: 0; right: 0;
    /* --kb-h is how much the on-screen keyboard covers (set in app.js on
       browsers that don't shrink the layout viewport themselves). */
    height: calc(var(--app-h) - var(--kb-h, 0px)); z-index: 6000;
    width: 100%; flex-direction: column; background: var(--surface);
    padding-top: var(--safe-t);
  }
  .chat-panel.mobile-open .chat-input-wrap {
    padding-bottom: var(--safe-b);
    padding-left: var(--safe-l); padding-right: var(--safe-r);
  }
  .btn-chat-close { display: flex; }

  /* Content clears the floating COMMS / MUTE buttons and the home indicator. */
  .game-main {
    padding: 1rem; padding-left: max(1rem, var(--safe-l));
    padding-right: max(1rem, var(--safe-r));
    padding-bottom: calc(4.5rem + var(--safe-b));
  }
  .form-screen { padding-bottom: calc(4.5rem + var(--safe-b)); }
  .results-wrap {
    padding-bottom: calc(4.5rem + var(--safe-b));
    justify-content: flex-start;
  }

  /* Home screen: stack cards vertically, OR on its own line */
  .home-actions { flex-direction: column; gap: 0.75rem; }
  .card { min-width: 0; width: 100%; }
  .card-divider { padding: 0.25rem 0; }

  /* Floating COMMS button */
  .btn-float-chat { display: flex; }

  /* Notebook drawer spans the full width once the side panel is gone. */
  .notebook-panel { right: 0; }
}

/* Phone landscape: reclaim vertical space from oversized display type. */
@media (max-height: 560px) and (orientation: landscape) {
  .home-wrap { padding: 1rem; gap: 1rem; justify-content: flex-start; }
  .logo-title { font-size: clamp(2rem, 7vw, 3.5rem); }
  .logo-eye { font-size: 1.75rem; margin-bottom: 0.15rem; }
  .form-screen { padding-top: 1rem; gap: 1rem; }
  .form-title { font-size: 2rem; }
  .form-sub { margin-top: -0.5rem; }
  .voting-title { font-size: 1.75rem; }
  .result-verdict { font-size: clamp(2rem, 6vw, 3rem); }
  .timer-circle { width: 72px; height: 72px; }
  .timer-text { font-size: 1.1rem; }
  .room-code-value { font-size: 1.75rem; }
  .notebook-panel { max-height: 60%; }
}

/* ─── Leave button ───────────────────────────────────────────────────────── */
.lobby-header-right {
  display: flex; align-items: center; gap: 0.75rem;
}
.btn-leave {
  font-family: var(--font-mono); font-size: 0.65rem; letter-spacing: 0.1em;
  padding: 0.35rem 0.75rem; border: 1px solid var(--border);
  background: transparent; color: var(--text-muted); cursor: pointer;
  transition: all 0.15s;
}
.btn-leave:hover { border-color: var(--red); color: var(--red); }
.btn-rules {
  font-family: var(--font-mono); font-size: 0.65rem; letter-spacing: 0.1em;
  padding: 0.35rem 0.75rem; border: 1px solid var(--border);
  background: transparent; color: var(--text-dim); cursor: pointer;
  transition: all 0.15s;
}
.btn-rules:hover { border-color: var(--amber); color: var(--amber); }

/* ─── Scoreboard ─────────────────────────────────────────────────────────── */
.scoreboard-wrap {
  margin: 0.75rem 0; padding: 0.75rem 1rem;
  border: 1px solid var(--border); background: var(--surface2);
}
.scoreboard-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 0.6rem;
}
.scoreboard-list { display: flex; flex-direction: column; gap: 0.3rem; }

.score-row {
  display: flex; align-items: center; gap: 0.75rem;
  font-family: var(--font-mono); font-size: 0.75rem; padding: 0.25rem 0;
  border-bottom: 1px solid var(--border);
}
.score-row:last-child { border-bottom: none; }
.score-row.score-top .score-name { color: var(--amber); }
.score-rank { color: var(--text-muted); width: 1.2rem; text-align: right; }
.score-name { flex: 1; color: var(--text); }
.score-pts { color: var(--green); font-weight: 600; }

/* Results scoreboard */
.result-scoreboard {
  margin: 1rem auto; max-width: 340px; width: 100%;
  border: 1px solid var(--border); padding: 0.75rem 1rem;
  background: var(--surface2); text-align: left;
}
.result-actions {
  display: flex; gap: 1rem; align-items: center; justify-content: center;
  margin-top: 1rem; flex-wrap: wrap;
}

/* ─── Form row (two columns) ─────────────────────────────────────────────── */
.form-row-two {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1rem;
}
@media (max-width: 540px) { .form-row-two { grid-template-columns: 1fr; } }

/* ─── Tap-to-reveal role card ────────────────────────────────────────────── */
.role-card { position: relative; overflow: hidden; }

.role-reveal-overlay {
  position: absolute; inset: 0; z-index: 10;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 0.4rem; cursor: pointer;
  background: rgba(10,10,10,0.88);
  backdrop-filter: blur(6px);
  transition: opacity 0.25s;
}
.role-reveal-overlay.hidden { display: none; }
.role-reveal-overlay:hover { background: rgba(20,20,20,0.92); }

.role-reveal-icon { font-size: 1.6rem; }
.role-reveal-text {
  font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.15em;
  color: var(--text-muted);
}

.role-card-inner.blurred { filter: blur(8px); user-select: none; }

.role-reveal-overlay.revealed {
  background: rgba(0,0,0,0.15);
  backdrop-filter: none;
  justify-content: flex-end;
  padding-bottom: 0.35rem;
}
.role-reveal-overlay.revealed:hover { background: rgba(0,0,0,0.3); }
.role-reveal-overlay.revealed .role-reveal-icon { display: none; }
.role-reveal-overlay.revealed .role-reveal-text {
  font-size: 0.55rem; opacity: 0.5; letter-spacing: 0.1em;
}

/* ─── Home footer / About ─────────────────────────────────────────────────── */
.home-footer {
  width: 100%; text-align: center; padding-top: 0.5rem;
}
.btn-about {
  background: none; border: none; color: var(--text-muted);
  font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.1em;
  cursor: pointer; transition: color 0.15s; padding: 0.25rem 0.5rem;
}
.btn-about:hover { color: var(--red); }

/* About modal content */
.about-content { max-width: 420px; }
.about-section { margin-bottom: 1.25rem; }
.about-text {
  font-family: var(--font-body); font-size: 0.82rem; color: var(--text-dim);
  line-height: 1.65; margin-bottom: 0.5rem;
}
.about-text strong { color: var(--text); }
.about-credit { border-top: 1px solid var(--border); padding-top: 1rem; margin-top: 0.25rem; }
.about-link { color: var(--red); text-decoration: none; font-family: var(--font-mono); font-size: 0.78rem; }
.about-link:hover { text-decoration: underline; }

/* ─── Sound Toggle ────────────────────────────────────────────────────────── */
.btn-sound-toggle {
  font-family: var(--font-mono); font-size: 0.6rem; letter-spacing: 0.1em;
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; padding: 0; transition: color 0.15s; flex-shrink: 0;
}
.btn-sound-toggle:hover { color: var(--text); }
.btn-sound-toggle.muted { color: var(--red); }
.chat-header .btn-sound-toggle { color: var(--red); }
.chat-header .btn-sound-toggle.muted { opacity: 0.5; }
.btn-sound-toggle-fixed {
  position: fixed; z-index: 10000;
  bottom: calc(1rem + var(--safe-b)); left: calc(1rem + var(--safe-l));
  background: var(--surface); border: 1px solid var(--border);
  padding: 0.35rem 0.75rem;
}
.btn-sound-toggle-fixed:hover { border-color: var(--red); }

/* ─── Location Info Modal ─────────────────────────────────────────────────── */
.loc-info-modal {
  position: fixed; inset: 0; z-index: 20000;
  display: flex; align-items: center; justify-content: center;
  height: var(--app-h);
  padding: calc(1rem + var(--safe-t)) calc(1rem + var(--safe-r))
           calc(1rem + var(--safe-b)) calc(1rem + var(--safe-l));
}
.loc-info-modal.hidden { display: none; }
.loc-info-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.7); backdrop-filter: blur(4px);
}
.loc-info-content {
  position: relative; z-index: 1;
  background: var(--surface); border: 1px solid var(--border);
  padding: 1.5rem; min-width: 0; max-width: 340px; width: 100%;
  border-top: 2px solid var(--red);
  max-height: 100%; overflow-y: auto;
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
}
.loc-info-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem;
}
.loc-info-name {
  font-family: var(--font-display); font-size: 1.8rem;
  letter-spacing: 0.05em; color: var(--text);
}
.loc-info-close {
  background: none; border: 1px solid var(--border); color: var(--text-muted);
  padding: 0.2rem 0.5rem; cursor: pointer; font-size: 0.8rem;
  transition: all 0.15s; flex-shrink: 0;
}
.loc-info-close:hover { border-color: var(--red); color: var(--red); }
.loc-info-label {
  font-family: var(--font-mono); font-size: 0.6rem; letter-spacing: 0.25em;
  color: var(--red); margin-bottom: 0.75rem;
}
.loc-info-roles { display: flex; flex-direction: column; gap: 0.4rem; }
.loc-modal-role {
  font-family: var(--font-mono); font-size: 0.8rem; color: var(--text-dim);
  padding: 0.35rem 0.6rem; border-left: 2px solid var(--border);
}

/* ─── Picker info button ──────────────────────────────────────────────────── */
.picker-item-top {
  display: flex; align-items: center; justify-content: space-between; gap: 0.25rem;
}
.picker-info-btn {
  font-family: var(--font-mono); font-size: 0.6rem; font-weight: 600;
  color: var(--bg); background: var(--text-muted);
  cursor: pointer; flex-shrink: 0; padding: 0.15rem 0.4rem;
  line-height: 1.4; transition: all 0.15s; user-select: none; border: none;
}
.picker-info-btn:hover { background: var(--amber); }

/* ─── Build Theme Tab ─────────────────────────────────────────────────────── */
.build-empty {
  font-family: var(--font-mono); font-size: 0.7rem; color: var(--text-muted);
  text-align: center; padding: 1.5rem 0;
}
.build-row {
  border: 1px solid var(--border); background: var(--surface2);
  padding: 0.6rem 0.75rem; margin-bottom: 0.5rem; display: flex;
  flex-direction: column; gap: 0.4rem;
}
.build-row-main {
  display: flex; align-items: center; gap: 0.4rem;
}
.build-name-input {
  flex: 1; background: transparent; border: none; border-bottom: 1px solid var(--border);
  color: var(--text); font-family: var(--font-mono); font-size: 0.8rem;
  padding: 0.2rem 0.3rem; outline: none;
}
.build-name-input:focus { border-bottom-color: var(--red); }
.build-name-input::placeholder { color: var(--text-muted); }
.build-roles {
  display: flex; flex-wrap: wrap; gap: 0.3rem; align-items: center;
}
.build-role-wrap {
  display: flex; align-items: center; gap: 0.15rem;
}
.build-role-input {
  width: 90px; background: var(--surface); border: 1px solid var(--border);
  color: var(--text); font-family: var(--font-mono); font-size: 0.7rem;
  padding: 0.2rem 0.4rem; outline: none;
}
.build-role-input:focus { border-color: var(--red-dim); }
.build-role-input::placeholder { color: var(--text-muted); }
.build-remove-row {
  background: transparent; border: none; color: var(--text-muted);
  font-size: 1.1rem; cursor: pointer; line-height: 1; padding: 0 0.2rem;
  flex-shrink: 0;
}
.build-remove-row:hover { color: var(--red); }
.build-remove-role {
  background: transparent; border: none; color: var(--text-muted);
  font-size: 0.75rem; cursor: pointer; line-height: 1; padding: 0 0.1rem;
}
.build-remove-role:hover { color: var(--red); }
.build-add-role {
  background: transparent; border: 1px dashed var(--border);
  color: var(--text-muted); font-size: 0.85rem; cursor: pointer;
  padding: 0.15rem 0.45rem; line-height: 1;
}
.build-add-role:hover { border-color: var(--red-dim); color: var(--text); }
.build-footer {
  display: flex; gap: 0.5rem; align-items: center; margin-top: 0.25rem; flex-wrap: wrap;
}

/* ─── CSV preview grid ────────────────────────────────────────────────────── */
#csv-preview { margin-top: 0.75rem; }
.csv-preview-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 0.4rem;
}
.csv-preview-label {
  font-family: var(--font-mono); font-size: 0.6rem; letter-spacing: 0.2em;
  color: var(--text-muted);
}
.csv-preview-item {
  background: var(--surface2); border: 1px solid var(--border);
  padding: 0.5rem 0.65rem; display: flex; flex-direction: column; gap: 0.15rem;
}
.csv-preview-item-top {
  display: flex; align-items: center; justify-content: space-between; gap: 0.25rem;
}
.csv-preview-item-name {
  font-family: var(--font-mono); font-size: 0.75rem; font-weight: 600; color: var(--text);
}
.csv-preview-item-roles {
  font-family: var(--font-mono); font-size: 0.6rem; color: var(--text-muted); line-height: 1.4;
}

/* ─── Location Picker ─────────────────────────────────────────────────────── */
.loc-source-tabs {
  display: flex; gap: 0.5rem; margin-bottom: 0.75rem;
}
.loc-tab {
  font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.1em;
  padding: 0.4rem 1rem; border: 1px solid var(--border);
  background: transparent; color: var(--text-muted); cursor: pointer;
  transition: all 0.15s;
}
.loc-tab:hover { border-color: var(--red-dim); color: var(--text); }
.loc-tab.active { border-color: var(--red); color: var(--red); background: rgba(220,38,38,0.08); }

.loc-tab-content { }
.loc-tab-content.hidden { display: none; }

.picker-toolbar {
  display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap;
  margin-bottom: 0.75rem;
}
.picker-count {
  font-family: var(--font-mono); font-size: 0.7rem; color: var(--amber);
  margin-left: auto;
}

.picker-set-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 0.4rem;
}
.picker-set-label {
  font-family: var(--font-mono); font-size: 0.6rem; letter-spacing: 0.15em;
  color: var(--text-muted);
}

.picker-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.4rem;
}

.picker-item {
  display: flex; flex-direction: column; gap: 0.15rem;
  padding: 0.5rem 0.65rem; border: 1px solid var(--border);
  background: var(--surface2); cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  position: relative; user-select: none;
}
.picker-item:hover { border-color: var(--red-dim); background: rgba(220,38,38,0.05); }
.picker-item.checked { border-color: var(--red); background: rgba(220,38,38,0.1); }
.picker-item input[type="checkbox"] { position: absolute; opacity: 0; width: 0; height: 0; }

.picker-item-name {
  font-family: var(--font-mono); font-size: 0.75rem; font-weight: 600;
  color: var(--text);
}
.picker-item.checked .picker-item-name { color: var(--red); }

.picker-item-roles {
  font-family: var(--font-mono); font-size: 0.6rem; color: var(--text-muted);
  line-height: 1.4;
}

/* ─── Lobby settings grid ────────────────────────────────────────────────── */
.lobby-settings-grid {
  display: flex; flex-direction: column; gap: 0.85rem; margin-bottom: 1rem;
}
.lobby-settings-actions {
  display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap;
  margin-bottom: 0.75rem;
}
#lobby-player-actions {
  margin-bottom: 0.5rem; display: flex; gap: 0.5rem; flex-wrap: wrap;
}
.btn-sm {
  font-size: 0.7rem !important; padding: 0.5rem 1rem !important;
}
#host-vote-control {
  display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap;
}

/* ─── Kick button ─────────────────────────────────────────────────────────── */
.btn-kick {
  position: absolute; bottom: 0.35rem; right: 0.35rem;
  background: none; border: none;
  color: var(--red-dim); font-size: 0.75rem;
  cursor: pointer; line-height: 1; padding: 0.1rem; transition: color 0.15s;
}
.btn-kick:hover { color: var(--red); }

/* ─── Spy guess modal ─────────────────────────────────────────────────────── */
.spy-guess-content {
  max-width: 480px; text-align: center;
}
.spy-guess-title {
  font-family: var(--font-display); font-size: 1.4rem; color: var(--red);
  letter-spacing: 0.1em; margin-bottom: 0.4rem;
}
.spy-guess-sub {
  font-family: var(--font-mono); font-size: 0.72rem; color: var(--text-muted);
  margin-bottom: 1.2rem;
}
.spy-guess-list {
  display: flex; flex-direction: column; gap: 0.4rem;
  max-height: 55vh; max-height: 55dvh; overflow-y: auto;
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
}
.spy-guess-btn {
  width: 100%; text-align: left; padding: 0.55rem 0.9rem;
  font-family: var(--font-mono); font-size: 0.8rem;
  background: var(--surface2); border: 1px solid var(--border); color: var(--text);
  cursor: pointer; border-radius: 3px; transition: border-color 0.15s, background 0.15s;
}
.spy-guess-btn:hover { border-color: var(--red); background: rgba(232,0,28,0.08); color: var(--red); }
.spy-guess-spinner { font-size: 2rem; margin-top: 1rem; }

/* ─── Toast notifications ─────────────────────────────────────────────────── */
#toast-container {
  position: fixed; top: calc(1.2rem + var(--safe-t)); left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 0.5rem;
  z-index: 15000; pointer-events: none;
  width: calc(100% - 2rem); max-width: 30rem;
}
.toast {
  font-family: var(--font-mono); font-size: 0.8rem; font-weight: 600;
  padding: 0.6rem 1.2rem; border-radius: 4px; letter-spacing: 0.04em;
  pointer-events: none; max-width: 100%; text-align: center;
  animation: toast-in 0.2s ease forwards;
}
.toast.error {
  background: rgba(18, 6, 6, 0.95); color: #ff4455;
  border: 1px solid #e8001c; box-shadow: 0 0 12px rgba(232,0,28,0.35);
}
.toast.info {
  background: rgba(6, 12, 18, 0.95); color: var(--text);
  border: 1px solid var(--border); box-shadow: 0 0 12px rgba(0,0,0,0.5);
}
.toast.fade-out { animation: toast-out 0.3s ease forwards; }
@keyframes toast-in  { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toast-out { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-8px); } }

/* ─── Guess countdown ─────────────────────────────────────────────────────── */
.guess-countdown {
  font-family: var(--font-mono); font-size: 1.1rem; font-weight: 700;
  color: var(--text-dim); margin-bottom: 0.75rem; letter-spacing: 0.05em;
  text-align: center; transition: color 0.3s; min-height: 1.4em;
}

/* ─── Ready-to-vote section ───────────────────────────────────────────────── */
.vote-ready-section {
  display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;
  padding: 0.6rem 0.75rem; background: var(--surface2);
  border: 1px solid var(--border);
}
.vote-ready-section.hidden { display: none !important; }
.vote-ready-status {
  font-family: var(--font-mono); font-size: 0.72rem; color: var(--text-muted);
  letter-spacing: 0.05em; flex: 1;
}
.btn-ready-vote {
  font-family: var(--font-mono); font-size: 0.75rem; letter-spacing: 0.1em;
  padding: 0.4rem 1rem; background: transparent;
  border: 1px solid var(--amber); color: var(--amber); cursor: pointer;
  transition: all 0.15s; text-transform: uppercase;
}
.btn-ready-vote:hover { background: rgba(245,166,35,0.12); }
.btn-ready-vote.is-ready { background: rgba(245,166,35,0.18); }
.ready-who-wrap { position: relative; }
.btn-who {
  font-family: var(--font-mono); font-size: 0.6rem; letter-spacing: 0.1em;
  background: none; border: 1px solid var(--border); color: var(--text-muted);
  cursor: pointer; padding: 0.25rem 0.55rem; transition: all 0.15s;
}
.btn-who:hover { border-color: var(--amber); color: var(--amber); }
.ready-who-list {
  position: absolute; bottom: calc(100% + 0.4rem); left: 0;
  background: var(--surface2); border: 1px solid var(--amber);
  min-width: 130px; z-index: 2000; padding: 0.4rem 0.6rem;
  font-family: var(--font-mono); font-size: 0.65rem;
}
.ready-who-list.hidden { display: none; }
.ready-who-entry { color: var(--green); padding: 0.15rem 0; }
.ready-who-entry::before { content: '✓ '; }
.ready-who-empty { color: var(--text-muted); padding: 0.15rem 0; font-style: italic; }
.player-tile-ready {
  position: absolute; top: 0.3rem; left: 0.3rem;
  font-size: 0.55rem; color: var(--green); line-height: 1;
}

/* ─── Hint panel ─────────────────────────────────────────────────────────── */
#btn-hints { border-color: var(--green) !important; color: var(--green) !important; }
#btn-hints:hover { background: rgba(0,232,122,0.08) !important; }
.hint-panel {
  background: var(--surface2); border: 1px solid var(--border);
  border-left: 3px solid var(--border); padding: 0.65rem 0.85rem;
}
.hint-tabs { display: flex; gap: 0.4rem; margin-bottom: 0.55rem; }
.hint-tab {
  font-family: var(--font-mono); font-size: 0.62rem; letter-spacing: 0.1em;
  padding: 0.2rem 0.65rem; border: 1px solid #4da6ff;
  background: transparent; color: #4da6ff; cursor: pointer; transition: all 0.15s;
}
.hint-tab.active { border-color: var(--red); color: var(--red); }
.hint-tab:hover { border-color: #80c4ff; color: #80c4ff; }
.hint-body { display: flex; flex-direction: column; gap: 0.45rem; }
.hint-text {
  font-family: var(--font-mono); font-size: 0.8rem; color: var(--text);
  min-height: 1.1em; letter-spacing: 0.02em; line-height: 1.4;
}
.hint-footer { display: flex; align-items: center; gap: 0.75rem; }
.btn-get-hint {
  font-family: var(--font-mono); font-size: 0.62rem; letter-spacing: 0.1em;
  padding: 0.2rem 0.65rem; background: transparent;
  border: 1px solid var(--green); color: var(--green); cursor: pointer; transition: all 0.15s;
}
.btn-get-hint:hover:not(:disabled) { border-color: #6effa0; color: #6effa0; }
.btn-get-hint:disabled { opacity: 0.35; cursor: not-allowed; }
.hint-countdown { font-family: var(--font-mono); font-size: 0.62rem; color: var(--text-muted); }

/* ─── Vote breakdown (results screen) ────────────────────────────────────── */
.vote-breakdown {
  max-width: 440px; width: 100%; margin: 0 auto;
  border: 1px solid var(--border); padding: 0.75rem 1rem;
  background: var(--surface2); text-align: left;
}
.vote-tally-row {
  display: flex; align-items: center; justify-content: space-between;
  font-family: var(--font-mono); font-size: 0.76rem;
  padding: 0.28rem 0; border-bottom: 1px solid var(--border);
}
.vote-tally-row:last-of-type { border-bottom: none; }
.vote-tally-row.voted-spy { color: var(--red); }
.vote-tally-name { flex: 1; }
.vote-tally-count { color: var(--text-muted); font-size: 0.68rem; }
.vote-breakdown-detail {
  margin-top: 0.65rem; padding-top: 0.65rem;
  border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 0.18rem;
}
.vote-detail-row {
  display: flex; align-items: center; gap: 0.5rem;
  font-family: var(--font-mono); font-size: 0.68rem; color: var(--text-dim);
  padding: 0.15rem 0;
}
.vdr-voter { min-width: 6rem; color: var(--text); }
.vdr-text { flex: 1; }
.vdr-verdict { font-weight: 600; white-space: nowrap; }
.vdr-verdict.correct { color: var(--green); }
.vdr-verdict.incorrect { color: var(--red); }
.vdr-verdict.skipped { color: #4da6ff; }

/* ─── Notebook panel ──────────────────────────────────────────────────────── */
.notebook-panel {
  position: fixed; bottom: 0; left: 0; right: 280px;
  background: rgba(17,17,20,0.97); border-top: 2px solid var(--amber);
  z-index: 5000; transform: translateY(100%); transition: transform 0.22s ease;
  max-height: min(200px, 45%); display: flex; flex-direction: column;
  padding-bottom: var(--safe-b);
}
.notebook-panel.open { transform: translateY(0); }
.nb-panel-header {
  font-family: var(--font-mono); font-size: 0.6rem; letter-spacing: 0.25em;
  color: var(--amber); padding: 0.35rem 0.75rem;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.nb-tabs { display: flex; gap: 0.5rem; }
.nb-tab {
  font-family: var(--font-mono); font-size: 0.6rem; letter-spacing: 0.15em;
  background: none; border: none; border-bottom: 2px solid transparent;
  color: #4da6ff; cursor: pointer; padding: 0 0 0.15rem; transition: all 0.15s;
}
.nb-tab:hover { color: #80c4ff; }
.nb-tab.active { color: var(--amber); border-bottom-color: var(--amber); }
.nb-panel-hint { color: var(--text-muted); font-size: 0.55rem; }
.nb-close-btn {
  background: none; border: none; color: var(--text-muted); font-size: 0.75rem;
  cursor: pointer; padding: 0 0.2rem; line-height: 1; transition: color 0.15s;
}
.nb-close-btn:hover { color: var(--red); }
.nb-chips {
  display: flex; flex-wrap: wrap; gap: 0.35rem;
  padding: 0.5rem 0.75rem; overflow-y: auto;
}
.nb-chip {
  font-family: var(--font-mono); font-size: 0.7rem; padding: 0.2rem 0.55rem;
  border: 1px solid var(--border); background: var(--surface2); color: var(--text-dim);
  cursor: pointer; user-select: none; transition: all 0.1s;
}
.nb-chip:hover { border-color: var(--amber); color: var(--text); }
.nb-chip.ticked { opacity: 0.32; text-decoration: line-through; border-color: transparent; }
.btn-notebook-active { border-color: var(--amber) !important; color: var(--amber) !important; }

/* ─── Result outcome description ─────────────────────────────────────────── */
.result-outcome {
  font-family: var(--font-mono); font-size: 0.72rem; color: var(--text-muted);
  margin: 0.5rem auto 0.75rem; max-width: 420px; line-height: 1.6;
  text-align: center;
}
.result-outcome strong { color: var(--text); }

/* ─── Earned pts badge on result scoreboard ──────────────────────────────── */
.score-earned {
  font-family: var(--font-mono); font-size: 0.7rem; color: var(--green);
  min-width: 2.5rem; text-align: right;
}
.score-earned.earned-zero { color: var(--text-muted); }

/* ─── Round history (lobby) ──────────────────────────────────────────────── */
.round-history-wrap {
  margin-top: 1.25rem; border: 1px solid var(--border);
  background: var(--surface2); padding: 0.75rem 1rem;
}
.rh-toggle-header { user-select: none; }
.rh-toggle-header:hover .section-label { color: var(--text); }
.rh-toggle-arrow {
  font-family: var(--font-mono); font-size: 0.6rem;
  color: var(--text-muted); transition: color 0.15s;
}
.rh-toggle-header:hover .rh-toggle-arrow { color: var(--text); }
.round-history-list { display: flex; flex-direction: column; gap: 0.75rem; margin-top: 0.4rem; }
.rh-entry {
  border: 1px solid var(--border); background: var(--surface);
  padding: 0.55rem 0.75rem; font-family: var(--font-mono); font-size: 0.7rem;
}
.rh-header {
  display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
  margin-bottom: 0.35rem;
}
.rh-round { color: var(--amber); font-weight: 600; font-size: 0.65rem; letter-spacing: 0.1em; min-width: 4rem; }
.rh-location { color: var(--text); font-weight: 600; flex: 1; }
.rh-outcome-badge {
  font-size: 0.6rem; padding: 0.1rem 0.4rem; border: 1px solid;
  letter-spacing: 0.08em; white-space: nowrap;
}
.rh-outcome-badge.caught { color: var(--green); border-color: var(--green); }
.rh-outcome-badge.escaped { color: var(--red); border-color: var(--red); }
.rh-spies { color: var(--text-muted); font-size: 0.65rem; margin-bottom: 0.3rem; }
.rh-spies strong { color: var(--red); }
.rh-guess { color: var(--text-muted); font-size: 0.65rem; margin-bottom: 0.3rem; }
.rh-guess .correct { color: var(--green); }
.rh-guess .wrong { color: var(--red); }
.rh-earnings {
  display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.3rem;
  padding-top: 0.3rem; border-top: 1px solid var(--border);
}
.rh-earn-chip {
  font-size: 0.62rem; padding: 0.1rem 0.45rem;
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text-dim);
}
.rh-earn-chip .earn-pts { color: var(--green); font-weight: 600; }
.rh-earn-chip .earn-pts.zero { color: var(--text-muted); }

/* Vote Details (nested expandable inside round history) */
.rh-details-toggle {
  font-size: 0.65rem; color: var(--text-muted); cursor: pointer;
  margin-top: 0.3rem; user-select: none;
}
.rh-details-toggle:hover { color: var(--text); }
.rh-details-arrow { font-size: 0.6rem; margin-right: 0.2rem; }
.rh-details {
  margin-top: 0.25rem; padding-left: 0.5rem;
  border-left: 2px solid var(--border); font-size: 0.6rem;
}
.rh-vote-line { margin: 0.15rem 0; color: var(--text-muted); }
.rh-voter { color: var(--text); }
.rh-vote-correct { color: var(--green); font-weight: 600; }
.rh-vote-incorrect { color: var(--red); font-weight: 600; }
.rh-spy-name { color: var(--green); font-weight: 600; }
.rh-vote-pts { color: var(--gold, #ffd700); font-weight: 600; }
.rh-vote-reason { color: var(--text-muted); font-size: 0.55rem; }

/* ─── Mobile (≤480px) ────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  /* Form screens */
  .form-screen {
    padding: 1.5rem max(1rem, var(--safe-l)) calc(4.5rem + var(--safe-b)) max(1rem, var(--safe-r));
  }
  .form-title { font-size: 2rem; }

  /* Home screen */
  .home-wrap {
    padding: 1.5rem max(1rem, var(--safe-l)) calc(4.5rem + var(--safe-b)) max(1rem, var(--safe-r));
    gap: 1.5rem;
  }
  .logo-title { font-size: clamp(2rem, 8vw, 4rem); letter-spacing: 0.03em; }
  .logo-eye { font-size: 2.2rem; }

  /* Game main — already at 1rem from the compact query; tighten further */
  .game-main {
    padding: 0.75rem max(0.75rem, var(--safe-l)) calc(4.5rem + var(--safe-b)) max(0.75rem, var(--safe-r));
    gap: 0.75rem;
  }

  /* Playing screen — shrink timer so stacked layout is less tall */
  .timer-circle { width: 80px; height: 80px; }
  .timer-text { font-size: 1.3rem; }
  .role-card { min-width: 0; }

  /* Results screen */
  .results-wrap {
    padding: 1.25rem max(1rem, var(--safe-l)) calc(4.5rem + var(--safe-b)) max(1rem, var(--safe-r));
    gap: 0.75rem; justify-content: flex-start;
  }
  .result-scoreboard { max-width: 100%; }
  .vote-breakdown { max-width: 100%; }
  .result-outcome { max-width: 100%; }

  /* Grids: 2 columns fit even on 320px */
  .players-action-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
  .voting-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
  .picker-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }

  /* Modals: use full available width */
  .loc-info-content { min-width: 0; width: 100%; }
  .about-content { max-width: 100%; }

  /* Long room codes / titles must never widen the page */
  .room-code-value { font-size: 2rem; letter-spacing: 0.2em; }
  .lobby-header { gap: 0.6rem; }
  .lobby-header-right { gap: 0.5rem; flex-wrap: wrap; }
}

/* ─── Touch devices ──────────────────────────────────────────────────────── */
/* :hover sticks after a tap on touch screens, so hover styling that mirrors a
   selected state made buttons look active when they weren't. Only apply the
   hover treatments where a real pointer can hover away again. */
@media (hover: none) {
  .btn-timer:hover:not(.active),
  .btn-timer-sm:hover:not(.active) {
    background: var(--surface2); border-color: var(--border); color: var(--text-dim);
  }
  .loc-tab:hover:not(.active) { border-color: var(--border); color: var(--text-muted); }
  .hint-tab:hover:not(.active) { border-color: #4da6ff; color: #4da6ff; }
  .card:hover { border-color: var(--border); transform: none; }
  .card:hover::before { transform: scaleX(0); }
  .picker-item:hover:not(.checked) { border-color: var(--border); background: var(--surface2); }
  .vote-card:not(.self):not(.voted):hover { transform: none; box-shadow: none; }
  .nb-chip:hover:not(.ticked) { border-color: var(--border); color: var(--text-dim); }
  .location-tag-clickable:hover { border-color: var(--border); color: var(--text-dim); background: var(--surface2); }
  /* The "ASK →" wipe is a pointer affordance; on touch it just hid the name. */
  .action-player:not(.self):not(.disabled):hover::after { opacity: 0; }
  .action-player:not(.self):not(.disabled):hover { border-color: var(--border); }
}

@media (pointer: coarse) {
  /* Anything under 16px makes iOS Safari zoom the page in on focus and leave
     the layout shifted. Keep every focusable field at the no-zoom threshold. */
  input[type="text"], input[type="number"], input[type="search"],
  input[type="email"], input[type="tel"], select, textarea,
  .chat-input-wrap input, .build-name-input, .build-role-input {
    font-size: 16px;
  }
  .build-role-input { width: 7.5rem; }

  /* Comfortable tap targets — small icon buttons were as little as 13px. */
  .btn, .btn-timer, .btn-timer-sm, .loc-tab, .btn-leave, .btn-rules,
  .btn-copy, .btn-back, .btn-who, .btn-ready-vote, .btn-get-hint,
  .hint-tab, .nb-tab, .loc-info-close, .btn-chat-close, .btn-float-chat,
  .chat-input-wrap button, .btn-sound-toggle-fixed, .btn-about,
  .chat-header .btn-sound-toggle {
    min-height: 40px;
  }
  .btn-timer, .btn-timer-sm, .loc-tab, .btn-leave, .btn-rules, .btn-who,
  .btn-copy, .loc-info-close, .btn-chat-close, .btn-about,
  .chat-header .btn-sound-toggle {
    display: inline-flex; align-items: center; justify-content: center;
  }
  .btn-copy, .loc-info-close, .btn-chat-close, .nb-close-btn,
  .btn-timer, .btn-timer-sm, .chat-header .btn-sound-toggle { min-width: 40px; }
  /* Overlay file input — invisible, but keep it off the iOS zoom threshold. */
  .file-drop input[type="file"] { font-size: 16px; }
  .btn-back { padding: 0.5rem 0; }
  .loc-toggle-btn, .build-remove-row, .build-remove-role, .build-add-role,
  .btn-kick, .btn-grant-turn, .btn-lower-hand, .picker-info-btn {
    min-width: 36px; min-height: 36px;
    display: inline-flex; align-items: center; justify-content: center;
  }
  /* Visually hidden, but keep it off the iOS zoom threshold anyway. */
  .picker-item input[type="checkbox"] { font-size: 16px; }
  .btn-kick { bottom: 0; right: 0; }
  .player-tile { padding-right: 2rem; }
  /* Roomier rows so neighbouring locations aren't mis-tapped. */
  .location-tag { padding: 0.4rem 0.7rem; }
  .nb-chip { padding: 0.4rem 0.7rem; }
  .spy-guess-btn { padding: 0.7rem 0.9rem; }
}

/* The CSV sample keeps its literal line breaks but must not widen the page. */
.csv-example { overflow-x: auto; max-width: 100%; }
