:root {
  --bg: #070b1f;
  --bg-2: #0d1330;
  --panel: rgba(18, 25, 56, 0.72);
  --panel-solid: #121938;
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.22);
  --text: #eef1ff;
  --muted: #9aa4cc;
  --accent: #5ec8f8;
  --accent-2: #a06cd5;
  --pink: #ff5ea8;
  --green: #39d0a0;
  --amber: #ffd93d;
  --danger: #ff6b6b;
  --b4: #ff5ea8;
  --b3: #a06cd5;
  --b2: #3f4a8f;
  --radius: 16px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: radial-gradient(1200px 700px at 50% -10%, #1a2150 0%, var(--bg) 55%, #04061a 100%);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 15px;
  overflow-x: hidden;
}

.stars {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    radial-gradient(1.6px 1.6px at 12% 18%, #fff, transparent),
    radial-gradient(1.4px 1.4px at 32% 62%, #cfe3ff, transparent),
    radial-gradient(1.8px 1.8px at 58% 12%, #fff, transparent),
    radial-gradient(1.2px 1.2px at 74% 44%, #ffe9b8, transparent),
    radial-gradient(1.6px 1.6px at 88% 72%, #fff, transparent),
    radial-gradient(1.3px 1.3px at 22% 86%, #d5c7ff, transparent),
    radial-gradient(1.1px 1.1px at 46% 34%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 66% 88%, #bfe6ff, transparent),
    radial-gradient(1.2px 1.2px at 92% 22%, #fff, transparent),
    radial-gradient(1.1px 1.1px at 6% 52%, #fff, transparent);
  opacity: .75;
}

h1, h2, h3, .logo, .room-code, .clue-display { font-family: Poppins, Inter, sans-serif; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); min-height: 18px; font-size: 14px; margin: 8px 0 0; }

/* ---------------- buttons + fields ---------------- */

.btn {
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 10px 18px;
  cursor: pointer;
  transition: transform .08s ease, background .15s ease, border-color .15s ease, opacity .15s;
}
.btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.16); transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  border-color: transparent;
  color: #08102c;
  font-weight: 800;
}
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%); }
.btn.big { padding: 14px 30px; font-size: 17px; border-radius: 14px; }
.btn.small { padding: 6px 12px; font-size: 13px; border-radius: 10px; }
.btn.ghost { background: transparent; }
.btn.danger { border-color: rgba(255, 107, 107, .5); color: #ffbdbd; }
.btn.link { background: none; border: none; color: var(--muted); text-decoration: underline; padding: 6px; font-weight: 500; }
.btn.link:hover { color: var(--text); background: none; transform: none; }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: rgba(8, 12, 32, .7);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 11px 14px;
  width: 100%;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(94, 200, 248, .18); }
select option { background: var(--panel-solid); }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }

.panel {
  position: relative;
  z-index: 1;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}
.panel h2 { margin: 0 0 16px; font-size: 20px; }
.panel h3 { margin: 0 0 12px; font-size: 15px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }

/* ---------------- screens ---------------- */

.screen { display: none; position: relative; z-index: 1; min-height: 100vh; min-width: 900px; }
.screen.active { display: block; }

/* ---------------- mobile gate ---------------- */

#mobile-gate {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  place-items: center;
  padding: 24px;
}
#mobile-gate.show { display: grid; }
.gate-card { max-width: 420px; text-align: center; }
.gate-icon { font-size: 54px; }
.gate-card h1 { font-size: 30px; margin: 10px 0; }
.gate-card p { color: var(--muted); line-height: 1.6; }
.gate-card #gate-override { margin-top: 14px; }
/* The gate is the one thing that must read well on a phone. */
@media (max-width: 899px) {
  #mobile-gate { font-size: 17px; }
  .gate-icon { font-size: 72px; }
  .gate-card h1 { font-size: 34px; }
}

/* ---------------- connection banner ---------------- */

.conn-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 90;
  background: var(--amber); color: #2a2200;
  text-align: center; padding: 7px; font-weight: 700; font-size: 14px;
}

/* ---------------- home ---------------- */

.home-wrap { max-width: 1040px; margin: 0 auto; padding: 60px 28px 40px; }
.brand { text-align: center; margin-bottom: 42px; }
.logo {
  font-size: 68px; font-weight: 800; letter-spacing: .14em; margin: 0;
  background: linear-gradient(180deg, #fff 30%, #9fc4ff 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.tagline { color: var(--muted); font-size: 18px; margin-top: 10px; }
.home-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; align-items: start; }
.home-panel { padding: 28px; }
.home-actions { margin-top: 8px; }
.btn.primary.big#btn-create { width: 100%; }
.or { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; margin: 16px 0; }
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.join-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.code-input {
  text-transform: uppercase; letter-spacing: .34em; font-weight: 800;
  font-size: 22px; text-align: center; font-family: Poppins, sans-serif;
}
.how { margin: 0; padding-left: 20px; line-height: 1.75; color: #d6ddff; }
.how li { margin-bottom: 8px; }
.home-foot { text-align: center; margin-top: 40px; }

/* ---------------- lobby ---------------- */

/* Full-height column: the settings scroll, the Start button never leaves the screen. */
#screen-lobby.active { display: flex; flex-direction: column; height: 100vh; }
.lobby-wrap {
  flex: 1; min-height: 0; width: 100%; max-width: 1120px; margin: 0 auto;
  display: flex; flex-direction: column; padding: 28px 28px 0;
}
.lobby-head { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 22px; }
.eyebrow { text-transform: uppercase; letter-spacing: .14em; font-size: 12px; color: var(--muted); margin: 0 0 4px; font-weight: 700; }
.room-code { font-size: 46px; font-weight: 800; letter-spacing: .2em; line-height: 1; color: #fff; }
.lobby-head-actions { display: flex; gap: 10px; }
.lobby-grid {
  display: grid; grid-template-columns: 1fr 1.05fr; gap: 22px; align-items: start;
  flex: 1; min-height: 0; overflow-y: auto; padding-bottom: 10px;
}
.count { color: var(--muted); font-weight: 500; font-size: 15px; }

.player-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.player-chip {
  display: flex; align-items: center; gap: 10px;
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--border);
  border-radius: 12px; padding: 10px 12px;
}
.player-chip .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.player-chip .pname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-chip .tag { font-size: 11px; color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: 2px 7px; }
.player-chip.offline { opacity: .45; }
.player-chip .chip-actions { margin-left: auto; display: flex; gap: 4px; }
.mini-btn { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px; padding: 2px 5px; border-radius: 6px; }
.mini-btn:hover { color: #fff; background: rgba(255,255,255,.1); }
.team-A { box-shadow: inset 3px 0 0 var(--accent); }
.team-B { box-shadow: inset 3px 0 0 var(--pink); }
.team-controls { display: flex; gap: 8px; margin-top: 14px; }

.settings-form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.settings-form .full { grid-column: 1 / -1; }
.setting { display: block; }
.setting > span { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 5px; font-weight: 700; }
.setting select, .setting input { padding: 9px 12px; }
.setting-desc { font-size: 12px; color: var(--muted); margin: 4px 0 0; }
.pack-list { display: flex; flex-wrap: wrap; gap: 8px; }
.pack-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border-strong); border-radius: 999px;
  padding: 7px 13px; cursor: pointer; font-size: 13px; font-weight: 600;
  background: rgba(255,255,255,.04); user-select: none;
}
.pack-toggle.on { background: rgba(94, 200, 248, .18); border-color: var(--accent); }
.pack-toggle input { display: none; }
.custom-pairs { display: grid; gap: 8px; }
.custom-row { display: grid; grid-template-columns: 1fr auto 1fr auto; gap: 8px; align-items: center; }
.custom-row .arrow { color: var(--muted); }
.host-only-tag { font-size: 12px; color: var(--muted); font-weight: 500; text-transform: none; letter-spacing: 0; }
.lobby-foot {
  text-align: center;
  flex: none;
  padding: 14px 0 18px;
  border-top: 1px solid var(--border);
}
.lobby-foot .error { min-height: 0; }
#btn-start { min-width: 240px; }

/* ---------------- game ---------------- */

#screen-game.active { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

.game-bar {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px;
  padding: 12px 22px; border-bottom: 1px solid var(--border);
  background: rgba(7, 11, 31, .6); backdrop-filter: blur(8px);
}
.gb-left { display: flex; align-items: center; gap: 14px; }
.gb-code { font-family: Poppins; font-weight: 800; letter-spacing: .18em; font-size: 18px; }
.gb-round { color: var(--muted); font-size: 14px; }
.gb-right { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

.timer { position: relative; width: 300px; height: 30px; border-radius: 999px; background: rgba(255,255,255,.07); overflow: hidden; border: 1px solid var(--border); }
.timer-fill { position: absolute; inset: 0; width: 100%; transform-origin: left; background: linear-gradient(90deg, var(--accent), var(--accent-2)); opacity: .55; transition: transform .25s linear; }
.timer-text { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 700; font-size: 13px; letter-spacing: .04em; }
.timer.urgent .timer-fill { background: linear-gradient(90deg, #ff9f6b, var(--danger)); opacity: .75; }
.timer.paused .timer-fill { background: var(--amber); opacity: .5; }

.game-main { flex: 1; display: grid; grid-template-columns: 250px 1fr 290px; gap: 16px; padding: 16px; min-height: 0; }
.side { padding: 16px; overflow-y: auto; }
.stage { display: flex; flex-direction: column; align-items: center; min-height: 0; overflow-y: auto; }

.spectrum-head { text-align: center; min-height: 86px; padding: 4px 0 2px; }
.clue-display { font-size: 34px; margin: 0; line-height: 1.15; min-height: 42px; }
.clue-display.placeholder { color: var(--muted); font-size: 22px; font-weight: 500; font-style: italic; }
.stage-sub { color: var(--muted); margin: 8px 0 0; font-size: 14px; }

.dial-holder { width: 100%; max-width: 720px; }
.dial-holder svg { display: block; width: 100%; height: auto; }

.action-panel { width: 100%; max-width: 720px; margin-top: 10px; padding-bottom: 12px; }
.action-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; text-align: center;
}
.action-card h4 { margin: 0 0 10px; font-size: 17px; font-family: Poppins; }
.action-card p { margin: 0 0 12px; color: var(--muted); }
.clue-form { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.clue-form input { font-size: 18px; padding: 14px 16px; }
.lock-row { display: flex; gap: 10px; justify-content: center; align-items: center; }
.lr-row { display: flex; gap: 12px; justify-content: center; }
.waiting-list { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 8px; }
.waiting-pill { font-size: 12px; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); }
.waiting-pill.done { border-color: var(--green); color: var(--green); }
.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.choice-btn {
  padding: 18px; border-radius: 14px; border: 1px solid var(--border-strong);
  background: rgba(255,255,255,.05); cursor: pointer; color: var(--text); font: inherit;
}
.choice-btn:hover { background: rgba(94,200,248,.15); border-color: var(--accent); }
.choice-btn strong { display: block; font-size: 18px; font-family: Poppins; }
.choice-btn span { color: var(--muted); font-size: 12px; }

.target-note { font-size: 15px; color: var(--amber); font-weight: 600; }
.kbd { font-family: ui-monospace, monospace; border: 1px solid var(--border-strong); border-radius: 5px; padding: 1px 6px; font-size: 12px; }

/* reveal */
.reveal-list { display: grid; gap: 7px; margin: 12px 0; text-align: left; }
.reveal-row { display: flex; align-items: center; gap: 10px; background: rgba(255,255,255,.05); border-radius: 10px; padding: 8px 12px; }
.reveal-row .dot { width: 11px; height: 11px; border-radius: 50%; flex: none; }
.reveal-row .rname { font-weight: 600; flex: 1; }
.reveal-row .rval { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.reveal-row .rpts { font-weight: 800; font-family: Poppins; min-width: 42px; text-align: right; }
.pts-4 { color: var(--b4); } .pts-3 { color: var(--b3); } .pts-2 { color: var(--accent); } .pts-0 { color: var(--muted); }
.lr-result { margin-top: 10px; font-weight: 600; }

/* scoreboard */
.score-row { display: flex; align-items: center; gap: 9px; padding: 8px 10px; border-radius: 10px; }
.score-row + .score-row { margin-top: 4px; }
.score-row.me { background: rgba(94,200,248,.12); }
.score-row .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.score-row .sname { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.score-row .spts { font-weight: 800; font-family: Poppins; font-variant-numeric: tabular-nums; }
.score-row .mini { font-size: 11px; color: var(--muted); }
.score-row.offline { opacity: .45; }
.team-block { border: 1px solid var(--border); border-radius: 12px; padding: 10px; margin-bottom: 10px; }
.team-block.active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(94,200,248,.15); }
.team-block h4 { margin: 0 0 8px; display: flex; justify-content: space-between; align-items: baseline; font-size: 14px; }
.team-block h4 .tscore { font-size: 22px; font-family: Poppins; }
.coop-total { text-align: center; padding: 14px 0; }
.coop-total .big-num { font-size: 44px; font-family: Poppins; font-weight: 800; }
.legend { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 14px; }
.legend h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.legend-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.chip { width: 16px; height: 10px; border-radius: 3px; }
.chip.b4 { background: var(--b4); } .chip.b3 { background: var(--b3); } .chip.b2 { background: var(--b2); }

/* chat */
.chat-side { display: flex; flex-direction: column; }
.chat-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 7px; padding-right: 4px; min-height: 120px; }
.chat-msg { font-size: 13px; line-height: 1.45; word-wrap: break-word; }
.chat-msg .cname { font-weight: 700; }
.chat-msg.system { color: var(--muted); font-style: italic; font-size: 12px; }
.chat-form { display: grid; grid-template-columns: 1fr auto; gap: 7px; margin-top: 10px; }
.chat-form input { padding: 9px 12px; font-size: 13px; }

/* ---------------- game over ---------------- */

.over-wrap { max-width: 640px; margin: 0 auto; padding: 70px 28px; text-align: center; }
.over-title { font-size: 48px; margin: 0; }
.over-sub { color: var(--muted); font-size: 18px; margin-bottom: 26px; }
.over-panel { text-align: left; }
.over-actions { margin-top: 24px; display: flex; gap: 12px; justify-content: center; }
.final-row { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 12px; }
.final-row + .final-row { margin-top: 6px; }
.final-row.first { background: linear-gradient(90deg, rgba(255,217,61,.18), transparent); border: 1px solid rgba(255,217,61,.35); }
.final-row .rank { width: 28px; font-family: Poppins; font-weight: 800; color: var(--muted); }
.final-row .fname { flex: 1; font-weight: 700; }
.final-row .fpts { font-family: Poppins; font-weight: 800; font-size: 20px; }

/* ---------------- toasts ---------------- */

#toast-holder { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: var(--panel-solid); border: 1px solid var(--border-strong);
  padding: 11px 20px; border-radius: 999px; font-weight: 600; font-size: 14px;
  box-shadow: var(--shadow); animation: pop .25s ease;
}
.toast.bad { border-color: var(--danger); color: #ffc9c9; }
@keyframes pop { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------------- dial ---------------- */

.dial-svg { user-select: none; }
.dial-svg.interactive { cursor: pointer; }
.dial-label { font-family: Poppins, sans-serif; font-weight: 700; font-size: 19px; fill: var(--text); }
.dial-label.dim { fill: var(--muted); }
.dial-arc-bg { fill: rgba(255, 255, 255, .06); stroke: rgba(255,255,255,.12); stroke-width: 1.5; }
.dial-tick { stroke: rgba(255,255,255,.14); stroke-width: 1.5; }
.dial-needle { stroke-width: 5; stroke-linecap: round; }
.dial-needle.me { stroke-width: 7; }
.dial-target-line { stroke: #fff; stroke-width: 3; stroke-dasharray: 6 5; }
.dial-hub { fill: var(--pink); stroke: rgba(255,255,255,.25); stroke-width: 2; }
.needle-label { font-size: 12px; font-weight: 700; fill: var(--text); text-anchor: middle; paint-order: stroke; stroke: rgba(4,6,26,.85); stroke-width: 4px; }
.band-4 { fill: var(--b4); } .band-3 { fill: var(--b3); } .band-2 { fill: var(--b2); }
.band-num {
  font-family: Poppins; font-weight: 800; font-size: 15px; text-anchor: middle;
  fill: rgba(255,255,255,.95);
  paint-order: stroke; stroke: rgba(4, 6, 26, .85); stroke-width: 4px; /* stay legible over the target line */
}
