:root {
  --bg: #0e1726;
  --card: rgba(14, 23, 38, 0.88);
  --text: #ffffff;
  --muted: #b9c6dd;
  --accent: #ffd23f;
  --primary: #2f80ed;
  --danger: #ff4d6d;
  --ok: #3ddc84;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
#game { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; }
#video { display: none; }
.hidden { display: none !important; }

/* HUD — large, readable from the couch */
#hud { position: fixed; inset: 0; pointer-events: none; }
.phud {
  position: absolute; top: 0; display: flex; justify-content: space-between; align-items: center;
  padding: 2vh 2vw; font-weight: 800; font-size: clamp(18px, 4.2vh, 52px);
  text-shadow: 0 3px 0 rgba(0,0,0,.35); box-sizing: border-box;
}
.phud .tag { padding: .05em .45em; border-radius: .4em; color: #111; text-shadow: none; }
.phud .lives { letter-spacing: .15em; }
.phud.out { opacity: .55; }
.pmsg {
  position: absolute; top: 30vh; transform: translateX(-50%); font-weight: 900;
  font-size: clamp(28px, 9vh, 120px); text-shadow: 0 6px 0 rgba(0,0,0,.35); white-space: nowrap;
}
.pout {
  position: absolute; top: 40vh; transform: translateX(-50%); font-weight: 900; font-size: clamp(24px, 7vh, 90px);
  background: rgba(14,23,38,.75); padding: .2em .6em; border-radius: .4em; white-space: nowrap;
}
#message {
  position: fixed; top: 38%; left: 50%; transform: translate(-50%, -50%);
  font-size: clamp(36px, 14vh, 180px); font-weight: 900;
  text-shadow: 0 6px 0 rgba(0,0,0,.35); pointer-events: none; text-align: center;
  white-space: nowrap;
}
#message.small { font-size: clamp(24px, 6vh, 72px); white-space: normal; width: 90vw; }

#cam-panel {
  position: fixed; right: 16px; bottom: 16px; width: min(320px, 40vw);
  background: var(--card); border-radius: 14px; padding: 8px; font-size: 12px;
}
#preview { width: 100%; height: auto; border-radius: 8px; display: block; background: #000; }
.indicators { display: flex; gap: 6px; margin: 6px 0 4px; flex-wrap: wrap; align-items: center; }
.indicators b { font-weight: 900; }
.indicators span {
  padding: 3px 8px; border-radius: 6px; background: rgba(255,255,255,.12);
  font-weight: 700; color: var(--muted);
}
.indicators span.on { background: var(--accent); color: #222; }
#stats { color: var(--muted); font-family: ui-monospace, Menlo, monospace; white-space: pre; line-height: 1.35; }
#cam-panel.compact #stats { display: none; }

.overlay {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(10, 20, 40, .35); padding: 16px;
}
.card {
  background: var(--card); border-radius: 20px; padding: clamp(16px, 4vh, 40px) clamp(16px, 4vw, 48px);
  max-width: 900px; width: 100%; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
h1 { font-size: clamp(32px, 8vh, 80px); margin: 0 0 .2em; color: var(--accent); }
h2 { font-size: clamp(26px, 6vh, 64px); margin: 0 0 .3em; }
.sub { font-size: clamp(16px, 3vh, 28px); color: var(--muted); margin-top: 0; }
.row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin: 16px 0; }
label { color: var(--muted); font-size: 15px; }
select, button {
  font: inherit; font-size: 18px; border-radius: 12px; border: 0; padding: 12px 20px; cursor: pointer;
}
select { background: #1f2d45; color: var(--text); margin-left: 6px; max-width: 260px; }
button { background: #33435f; color: var(--text); font-weight: 700; }
button.primary { background: var(--primary); font-size: 22px; padding: 14px 28px; }
button:hover { filter: brightness(1.15); }
.hint { color: var(--muted); font-size: 14px; line-height: 1.6; }
.big-hint { font-size: clamp(20px, 4vh, 40px); font-weight: 800; color: var(--accent); }
.error { color: var(--danger); font-weight: 700; min-height: 1em; }

.progress { height: 28px; background: rgba(255,255,255,.12); border-radius: 14px; overflow: hidden; margin-top: 20px; }
#calib .card { margin-top: 35vh; max-width: 760px; }
#calib { background: transparent; align-items: flex-start; }

#final-score { font-size: clamp(40px, 10vh, 110px); font-weight: 900; color: var(--accent); }
#final-stats { margin: 8px auto 16px; border-collapse: collapse; font-size: clamp(16px, 2.8vh, 26px); }
#final-stats td { padding: 4px 16px; text-align: left; }
#final-stats td + td { text-align: right; font-weight: 700; }

#settings {
  position: fixed; top: 16px; left: 16px; width: min(360px, calc(100vw - 32px));
  background: var(--card); border-radius: 16px; padding: 16px 20px; z-index: 10;
}
#settings h3 { margin: 0 0 10px; }
#settings label { display: block; margin: 10px 0; }
#settings label span { float: right; color: var(--text); font-family: ui-monospace, Menlo, monospace; }
#settings input[type=range] { width: 100%; }
#settings .check { display: flex; gap: 8px; align-items: center; }

/* Latency test */
#latency-clock {
  position: fixed; top: 12vh; left: 50%; transform: translateX(-50%);
  font: 900 clamp(48px, 14vh, 160px) ui-monospace, Menlo, monospace;
  background: #000; color: #0f0; padding: 0 .3em; border-radius: 12px; z-index: 20;
}
#latency-flash {
  position: fixed; left: 50%; top: 40vh; transform: translateX(-50%);
  width: 30vh; height: 30vh; border-radius: 50%; background: #222; z-index: 20;
}
#latency-flash.on { background: #fff; box-shadow: 0 0 80px #fff; }
#latency-log {
  position: fixed; left: 16px; top: 16px; z-index: 20; background: var(--card); padding: 8px 12px;
  border-radius: 10px; font: 13px ui-monospace, Menlo, monospace; white-space: pre; max-width: 45vw;
}

@media (max-width: 600px) {
  #cam-panel { width: 45vw; right: 8px; bottom: 8px; }
  .hint { font-size: 12px; }
}

/* Phone pairing */
.pair-body { display: flex; gap: 32px; align-items: center; justify-content: center; flex-wrap: wrap; text-align: left; }
#pair-qr { width: min(280px, 60vw); background: #fff; border-radius: 12px; padding: 8px; }
#pair-qr:empty { display: none; }
#pair-qr svg { width: 100%; height: auto; display: block; }
.pair-steps { font-size: clamp(16px, 2.6vh, 24px); line-height: 1.5; max-width: 440px; margin: 0; padding-left: 1.2em; }
.pair-steps code { color: var(--accent); word-break: break-all; font-size: .85em; }
.pair-status { font-size: clamp(18px, 3vh, 30px); font-weight: 800; color: var(--muted); }
.pair-status.ok { color: var(--ok); }
.pair-code-line { font-size: clamp(18px, 3vh, 28px); color: var(--muted); margin: 0 0 16px; }
#pair-code { font: 900 clamp(36px, 8vh, 80px) ui-monospace, Menlo, monospace; color: var(--accent); letter-spacing: .15em; margin-left: .3em; vertical-align: middle; }

/* Calibration rows (one per player) */
.calib-row { display: flex; align-items: center; gap: 12px; margin-top: 14px; text-align: left; }
.calib-row b { font-size: clamp(18px, 3vh, 30px); min-width: 2.5em; }
.calib-row .progress { flex: 1; margin-top: 0; }
.calib-row .progress > div { height: 100%; width: 0; background: var(--ok); transition: width .1s linear; }
.calib-row small { color: var(--muted); min-width: 9em; font-size: clamp(14px, 2.2vh, 22px); }

/* Running as a Google Cast receiver: the phone already knows the room, so keep pairing simple. */
body.cast #btn-pair-cancel, body.cast #menu { display: none !important; }
body.cast .pair-steps .no-cast { display: none; }
body:not(.cast) .pair-steps .cast-only { display: none; }
.game-title { font-size: clamp(16px, 2.6vh, 24px); margin: -.4em 0 .6em; color: var(--text); }
