/* ---------- themes ----------
   Every colour the UI uses is a token. A theme only overrides tokens.
   :root (no data-theme) = Hazard, the default dark theme. */
:root,
:root[data-theme='hazard'] {
  --bg: #0c0d10;
  --surface: #17191f;
  --surface-2: #23262e;
  --border: rgba(255, 255, 255, 0.09);
  --text: #f1f1f4;
  --muted: #a3a3ad;
  --accent: #f97316;
  --accent-b: #ea580c;
  --accent-2: #fdba74;
  --on-accent: #1a0d00;
  --glow: rgba(249, 115, 22, 0.35);
  --stripe: #1d1f26;
  --tag-bg: #2a1d14;
  --tag-border: #5a3a1e;
  --hold-active: #3a2614;

  /* semantic colours, shared by all dark themes */
  --good: #22c55e;
  --bad: #ef4444;
  --warn: #f59e0b;
  --warn-bg: #3b2a0a;
  --warn-border: #7a5410;
  --warn-text: #ffd27a;
  --alarm-bg: #4a0d14;
  --ghost-bg: #1d2440;
  --ghost-border: #5a6aa8;
  --meet-bg: #3a2a07;
  --report-bg: #3d0f16;
  --imp-bg: #220d14;
  --imp-border: #7f1d1d;
  --sheriff-border: #78550f;
  --role-crew: #60a5fa;
  --role-sheriff: #fbbf24;
  --role-imp: #f87171;
  --end-crew: linear-gradient(160deg, #0c2d4a, #102040);
  --end-imp: linear-gradient(160deg, #4a0c14, #2a0a20);
  --scrim: rgba(6, 6, 12, 0.92);

  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
:root[data-theme='teal'] {
  --bg: #061317; --surface: #0d2127; --surface-2: #153039; --text: #eafaf8; --muted: #8fb3b8;
  --accent: #0d9488; --accent-b: #0e7490; --accent-2: #5eead4; --on-accent: #fff;
  --glow: rgba(13, 148, 136, 0.4); --stripe: #10272e; --tag-bg: #0f2e30; --tag-border: #1d5a58; --hold-active: #134044;
}
:root[data-theme='grape'] {
  --bg: #0f1020; --surface: #1a1b33; --surface-2: #24264a; --text: #eef0ff; --muted: #9aa0c8;
  --accent: #c026d3; --accent-b: #7c3aed; --accent-2: #e879f9; --on-accent: #fff;
  --glow: rgba(192, 38, 211, 0.35); --stripe: #1e1f3a; --tag-bg: #2a1f3d; --tag-border: #4c2d6e; --hold-active: #2f2560;
  --scrim: rgba(8, 8, 20, 0.92);
}
:root[data-theme='noir'] {
  --bg: #0d0d0d; --surface: #181818; --surface-2: #262626; --text: #f4f4f5; --muted: #a1a1aa;
  --accent: #b91c1c; --accent-b: #7f1d1d; --accent-2: #fca5a5; --on-accent: #fff;
  --glow: rgba(185, 28, 28, 0.4); --stripe: #1e1e1e; --tag-bg: #261515; --tag-border: #4a2020; --hold-active: #3a1a1a;
}
:root[data-theme='acid'] {
  --bg: #0a0f0b; --surface: #121b14; --surface-2: #1c2a1f; --text: #effbe9; --muted: #93a896;
  --accent: #a3e635; --accent-b: #65a30d; --accent-2: #d9f99d; --on-accent: #0a1400;
  --glow: rgba(163, 230, 53, 0.3); --stripe: #16211a; --tag-bg: #1c2a17; --tag-border: #3b5a22; --hold-active: #26381c;
}
:root[data-theme='daylight'] {
  --bg: #f2f3f6; --surface: #fff; --surface-2: #e8eaf0; --border: rgba(0, 0, 0, 0.09); --text: #12131a; --muted: #5b6070;
  --accent: #2563eb; --accent-b: #1d4ed8; --accent-2: #2563eb; --on-accent: #fff;
  --glow: rgba(37, 99, 235, 0.3); --stripe: #f1f3f8; --tag-bg: #eef2ff; --tag-border: #c7d2fe; --hold-active: #dbe4ff;
  --good: #16a34a; --bad: #dc2626;
  --warn-bg: #fff7e6; --warn-border: #f6c46a; --warn-text: #92400e;
  --alarm-bg: #fdecec; --ghost-bg: #eef1fb; --ghost-border: #9aa6d8; --meet-bg: #fff7e6; --report-bg: #fdecec;
  --imp-bg: #fdf0f0; --imp-border: #f3b4b4; --sheriff-border: #f1d08a;
  --role-crew: #1d4ed8; --role-sheriff: #b45309; --role-imp: #dc2626;
  --end-crew: linear-gradient(160deg, #dbeafe, #eff6ff); --end-imp: linear-gradient(160deg, #fee2e2, #fff1f2);
  --scrim: rgba(20, 22, 32, 0.6);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
  min-height: 100dvh;
}
a { color: var(--accent-2); }
h1, h2, h3 { margin: 0 0 0.5rem; line-height: 1.2; }
h2 { font-size: 1.1rem; }
h3 { font-size: 0.95rem; margin-top: 1rem; color: var(--muted); }
p { margin: 0.4rem 0; }
button, input { font: inherit; color: inherit; }

.app {
  max-width: 520px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 12px) 16px calc(var(--safe-bottom) + 24px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.good { color: var(--good); }
.bad { color: var(--bad); }
.danger-text { color: var(--bad) !important; }
.row { display: flex; gap: 8px; align-items: center; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.card.center { display: flex; flex-direction: column; align-items: center; gap: 4px; }

.note {
  background: var(--surface-2);
  border-radius: 12px;
  padding: 10px 14px;
  margin: 0;
  font-size: 0.92rem;
}

/* ---------- buttons ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.06s, filter 0.15s, background 0.15s;
  touch-action: manipulation;
  user-select: none;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.block { display: block; width: 100%; }
.btn.big { padding: 18px; font-size: 1.15rem; border-radius: 14px; }
.btn.small { padding: 7px 12px; font-size: 0.88rem; }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-b)); border-color: transparent; color: var(--on-accent); }
.btn.danger { background: var(--bad); border-color: transparent; color: #fff; }
.btn.warn { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn-text); }
.btn.ghost { background: transparent; }
.tag-btn { background: var(--tag-bg); border-color: var(--tag-border); }
.icon-btn {
  appearance: none; border: 0; background: var(--surface-2); color: var(--muted);
  width: 34px; height: 34px; border-radius: 50%; cursor: pointer; font-size: 1rem; flex: none;
}
.icon-btn.light { background: rgba(0, 0, 0, 0.5); color: #fff; }

/* ---------- inputs ---------- */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field span { font-size: 0.85rem; color: var(--muted); }
input:not([type='checkbox']) {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  outline: none;
  min-width: 0;
}
input:focus { border-color: var(--accent); }
.code-input { width: 110px !important; flex: none; text-align: center; letter-spacing: 0.25em; font-weight: 700; text-transform: uppercase; }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 0.85rem; margin: 14px 0; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* ---------- home ---------- */
.home { display: flex; flex-direction: column; gap: 14px; padding-top: 4vh; }
.brand { text-align: center; }
.brand .logo { display: inline-block; border-radius: 22px; box-shadow: 0 10px 40px var(--glow); }
.logo svg { display: block; width: 100%; height: 100%; }
.brand h1 { font-size: 2.2rem; margin: 12px 0 0; letter-spacing: -0.02em; }
.rules summary { cursor: pointer; font-weight: 600; }
.rules ol { padding-left: 1.2rem; margin: 10px 0 0; }
.rules li { margin-bottom: 6px; }
.foot { text-align: center; font-size: 0.85rem; }
.center-screen { min-height: 70vh; display: grid; place-content: center; justify-items: center; gap: 12px; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.who { display: flex; align-items: center; gap: 8px; min-width: 0; }
.who b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.code-chip { background: var(--surface-2); padding: 3px 10px; border-radius: 999px; font-weight: 700; letter-spacing: 0.15em; font-size: 0.85rem; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--bad); }
.dot.on { background: var(--good); box-shadow: 0 0 8px var(--good); }

.avatar { display: inline-block; flex: none; }
.avatar svg { width: 100%; height: 100%; display: block; }
.avatar.ghost { opacity: 0.4; filter: grayscale(0.6); }

/* ---------- lobby ---------- */
.big-code { font-size: 3rem; font-weight: 800; letter-spacing: 0.2em; line-height: 1.1; padding-left: 0.2em; }
.join-qr { width: 150px; background: #fff; border-radius: 12px; padding: 6px; margin: 8px 0; }
.join-qr svg { display: block; width: 100%; height: auto; }
.players { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.player { display: flex; align-items: center; gap: 10px; padding: 4px 0; }
.player .pname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.player.dead .pname { text-decoration: line-through; color: var(--muted); }
.player.offline { opacity: 0.6; }
.players.compact { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; }
.players.compact .player { font-size: 0.9rem; }
.badge { background: var(--surface-2); color: var(--accent-2); border-radius: 6px; padding: 1px 6px; font-size: 0.7rem; font-weight: 600; vertical-align: middle; }
.badge.dim { color: var(--muted); }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { width: 34px; height: 34px; border-radius: 50%; background: var(--c); border: 3px solid transparent; cursor: pointer; }
.swatch.sel { border-color: var(--surface); box-shadow: 0 0 0 2px var(--accent); }
.swatch:disabled { opacity: 0.15; cursor: not-allowed; }
.stations { display: flex; flex-direction: column; }
.summary { margin: 0; padding-left: 1.1rem; }
.sticky-actions {
  position: sticky; bottom: 0; padding: 12px 0 calc(var(--safe-bottom) + 4px);
  background: linear-gradient(transparent, var(--bg) 30%);
}

/* ---------- playing ---------- */
.banner { border-radius: var(--radius); padding: 12px 16px; display: flex; flex-direction: column; gap: 2px; }
.banner.alarm { background: var(--alarm-bg); border: 1px solid var(--bad); animation: pulse 1s infinite alternate; }
.banner.ghostly { background: var(--ghost-bg); border: 1px dashed var(--ghost-border); }
@keyframes pulse { from { box-shadow: 0 0 0 rgba(239, 68, 68, 0); } to { box-shadow: 0 0 24px rgba(239, 68, 68, 0.6); } }
.progress-card { padding: 0 2px; }
.bar { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 4px; }
.bar.big { height: 16px; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--good), #a3e635); border-radius: 99px; transition: width 0.3s; }
.actions { display: flex; flex-direction: column; gap: 10px; }

.role-card {
  appearance: none; text-align: left; width: 100%; cursor: pointer;
  border-radius: var(--radius); padding: 14px 16px; border: 1px solid var(--border);
  background: var(--surface); display: flex; flex-direction: column; gap: 2px;
}
.hidden-role { align-items: center; text-align: center; background: repeating-linear-gradient(-45deg, var(--surface), var(--surface) 10px, var(--stripe) 10px, var(--stripe) 20px); }
.role-name { font-size: 1.6rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; }
.role-name.huge { font-size: 2.6rem; }
.role-crewmate .role-name { color: var(--role-crew); }
.role-sheriff .role-name { color: var(--role-sheriff); }
.role-impostor .role-name { color: var(--role-imp); }
.role-card.role-impostor { border-color: var(--imp-border); background: var(--imp-bg); }
.role-card.role-sheriff { border-color: var(--sheriff-border); }
.role-extra p { margin: 6px 0; }
.role-extra .btn { margin-top: 6px; }
.role-tag { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); }
.role-tag.role-impostor { color: var(--role-imp); }
.role-tag.role-sheriff { color: var(--role-sheriff); }
.role-tag.role-crewmate { color: var(--role-crew); }
.cause { width: 100%; text-align: right; max-width: 40%; font-size: 0.75rem; }

.tasks { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.tasks li { display: flex; gap: 10px; align-items: center; }
.tick { width: 24px; height: 24px; border-radius: 6px; border: 2px solid var(--muted); display: grid; place-items: center; flex: none; font-size: 0.8rem; color: #fff; }
.tasks li.done .tick { background: var(--good); border-color: var(--good); }
.tasks li.done b { text-decoration: line-through; color: var(--muted); }

.countdown { font-variant-numeric: tabular-nums; font-weight: 700; }
.countdown.big { font-size: 2.2rem; }
.countdown.urgent { color: var(--bad); }

/* ---------- dead ---------- */
.dead-screen {
  min-height: calc(100dvh - 40px); display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 10px;
}
.dead-screen h1 { color: var(--bad); font-size: 1.8rem; }
.qr-box { background: #fff; padding: 10px; border-radius: 18px; width: min(82vw, 360px); aspect-ratio: 1; display: grid; place-items: center; }
.qr-box svg { width: 100%; height: 100%; display: block; }

/* ---------- meeting ---------- */
.meeting-head { text-align: center; padding: 14px; border-radius: var(--radius); background: var(--meet-bg); border: 1px solid var(--warn); }
.meeting-head.report { background: var(--report-bg); border-color: var(--bad); }
.meeting-head h1 { font-size: 1.6rem; }
.stages { list-style: none; display: flex; padding: 0; margin: 0; gap: 4px; }
.stages li { flex: 1; text-align: center; font-size: 0.78rem; padding: 6px 0; border-radius: 8px; background: var(--surface); color: var(--muted); }
.stages li.past { color: var(--text); opacity: 0.6; }
.stages li.cur { background: var(--accent); color: var(--on-accent); font-weight: 700; }
.timer { margin-bottom: 6px; }
.lead { font-size: 1.1rem; }
.votes { list-style: none; padding: 0; margin: 8px 0; width: 100%; display: flex; flex-direction: column; gap: 6px; }
.vote-row {
  width: 100%; display: flex; align-items: center; gap: 10px; text-align: left; cursor: pointer;
  padding: 8px 12px; border-radius: 12px; background: var(--surface-2); border: 2px solid transparent;
}
.vote-row:disabled { cursor: default; }
.vote-row .pname { flex: 1; }
.vote-row.mine { border-color: var(--accent); }
.voted { font-size: 0.75rem; color: var(--good); font-weight: 700; }
.tally { text-align: left; width: 100%; padding-left: 1.1rem; }

/* ---------- end ---------- */
.end-head { text-align: center; padding: 24px 16px; border-radius: var(--radius); background: var(--surface); }
.end-head.crew { background: var(--end-crew); }
.end-head.impostors { background: var(--end-imp); }
.end-head h1 { font-size: 2rem; }
.outcome { font-weight: 800; letter-spacing: 0.3em; color: var(--accent-2); }
.log { padding-left: 1.1rem; margin: 8px 0 0; font-size: 0.88rem; }

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50; background: var(--scrim);
  display: flex; align-items: center; justify-content: center; padding: calc(var(--safe-top) + 16px) 16px calc(var(--safe-bottom) + 16px);
  animation: fade 0.15s;
}
@keyframes fade { from { opacity: 0; } }
.ov-inner {
  width: 100%; max-width: 440px; max-height: 100%; overflow: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 20px;
  display: flex; flex-direction: column; gap: 10px;
}
.ov-inner.msg h2 { font-size: 1.4rem; }
.ov-inner.msg.bad h2 { color: var(--bad); }
.role-reveal { text-align: center; padding: 28px 20px; }
.role-reveal.role-impostor { border-color: var(--bad); box-shadow: 0 0 60px rgba(239, 68, 68, 0.35); }
.qr-show { align-items: center; text-align: center; }
.ov-qr { background: var(--bg); }

.ov-scanner { padding: 0; background: #000; }
.scanner { position: absolute; inset: 0; }
.scanner video { width: 100%; height: 100%; object-fit: cover; }
.scan-frame {
  position: absolute; top: 50%; left: 50%; width: min(70vw, 300px); aspect-ratio: 1; transform: translate(-50%, -55%);
  border-radius: 24px; box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.45); border: 3px solid var(--accent-2);
}
.scan-top {
  position: absolute; top: 0; left: 0; right: 0; padding: calc(var(--safe-top) + 14px) 16px 14px;
  display: flex; align-items: center; justify-content: space-between; font-weight: 600;
  background: linear-gradient(rgba(0, 0, 0, 0.6), transparent);
}
.scan-error { position: absolute; top: 40%; left: 16px; right: 16px; background: var(--surface); padding: 16px; border-radius: 14px; text-align: center; }
.scan-manual {
  position: absolute; left: 16px; right: 16px; bottom: calc(var(--safe-bottom) + 18px); display: flex; gap: 8px;
}
.scan-manual input { background: rgba(0, 0, 0, 0.6); }

/* ---------- tasks ---------- */
.task { min-height: 70vh; }
.task-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.task-body { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; text-align: center; width: 100%; }
.task-help { color: var(--muted); }
.hold-btn {
  position: relative; width: 200px; height: 200px; border-radius: 50%; border: 0; background: var(--surface-2);
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; cursor: pointer;
}
.hold-btn.active { background: var(--hold-active); }
.hold-btn svg { position: absolute; inset: 0; transform: rotate(-90deg); }
.hold-btn .ring-bg { fill: none; stroke: var(--bg); stroke-width: 8; }
.hold-btn .ring { fill: none; stroke: var(--good); stroke-width: 8; stroke-linecap: round; stroke-dasharray: 100; stroke-dashoffset: 100; }
.hold-btn span { position: relative; font-weight: 800; font-size: 1.4rem; letter-spacing: 0.1em; }
.seq-grid { display: grid; grid-template-columns: repeat(3, 76px); gap: 10px; }
.seq-cell { height: 76px; border-radius: 14px; border: 0; background: var(--surface-2); font-size: 1.6rem; font-weight: 800; cursor: pointer; }
.seq-cell.ok { background: var(--good); color: #fff; }
.code-display { font-size: 2.6rem; font-weight: 800; letter-spacing: 0.25em; font-variant-numeric: tabular-nums; min-height: 3.3rem; }
.code-display.hidden { color: var(--muted); }
.code-typed { font-size: 1.6rem; letter-spacing: 0.3em; min-height: 2.2rem; }
.keypad { display: grid; grid-template-columns: repeat(3, 72px); gap: 8px; }
.keypad button { height: 58px; border-radius: 12px; border: 0; background: var(--surface-2); font-size: 1.4rem; font-weight: 700; cursor: pointer; }
.keypad button:active { background: var(--accent); }
.wires { position: relative; display: flex; justify-content: space-between; width: 100%; max-width: 320px; height: 280px; }
.wire-lines { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.wire-col { display: flex; flex-direction: column; justify-content: space-around; z-index: 1; }
.wire-end { width: 48px; height: 36px; border-radius: 8px; border: 3px solid transparent; background: var(--w); cursor: pointer; }
.wire-end.sel { border-color: var(--text); transform: scale(1.12); }
.wire-end.done { opacity: 0.55; }
.shake { animation: shake 0.3s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }

/* ---------- misc ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 20px); transform: translateX(-50%); z-index: 100;
  background: var(--surface-2); border: 1px solid var(--border); padding: 12px 18px; border-radius: 14px;
  max-width: calc(100vw - 32px); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5); font-weight: 600; text-align: center;
}
.toast.bad { border-color: var(--bad); }
.toast.good { border-color: var(--good); }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 4px solid var(--surface-2); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- theme picker ---------- */
.theme-list { display: flex; flex-direction: column; gap: 8px; }
.theme-opt {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; cursor: pointer;
  padding: 10px 12px; border-radius: 12px; background: var(--surface-2); border: 2px solid transparent;
}
.theme-opt.sel { border-color: var(--accent); }
.theme-opt .grow { flex: 1; }
.theme-swatch { display: inline-flex; flex: none; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }
.theme-swatch i { display: block; width: 18px; height: 34px; }
.theme-check { color: var(--accent); font-weight: 800; }
.theme-btn svg { width: 18px; height: 18px; display: block; margin: auto; }
