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

:root {
  --bg1: #0f2557; --bg2: #274b9f;
  --ink: #1b2340; --panel: #ffffff;
  --gold: #ffc53d; --gold-dark: #b97e0e;
  --good: #22c55e; --bad: #ef4444;
  --radius: 18px;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  background: linear-gradient(160deg, var(--bg1), #173a7d 55%, var(--bg2));
  min-height: 100vh;
  color: var(--ink);
  padding: 20px 14px 40px;
}

.hidden { display: none !important; }
.screen { max-width: 1100px; margin: 0 auto; }

/* ---------- setup ---------- */
.hero { text-align: center; color: #fff; margin: 10px 0 24px; }
.hero h1 { font-size: clamp(2.4rem, 6vw, 4rem); letter-spacing: 1px; text-shadow: 0 4px 0 rgba(0,0,0,.3); }
.tagline { opacity: .92; font-size: 1.05rem; margin-top: 6px; }

.setup-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 820px) { .setup-grid { grid-template-columns: 1fr; } }

.card {
  background: var(--panel); border-radius: var(--radius);
  padding: 22px; box-shadow: 0 12px 30px rgba(0,0,0,.35);
}
.card h2 { font-size: 1.3rem; margin-bottom: 16px; display: flex; align-items: center; gap: 10px; }
.step {
  background: var(--gold); color: #231900; width: 30px; height: 30px;
  border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-size: 1rem; font-weight: 800; flex: none;
}

.join-text { font-size: 1rem; line-height: 1.45; margin-bottom: 10px; }
.pair-code {
  font-size: 2.6rem; font-weight: 900; letter-spacing: .35em; text-align: center;
  color: var(--gold); margin: 6px 0 10px; text-indent: .35em;
  text-shadow: 0 2px 0 rgba(0,0,0,.15);
}
.card .pair-code { color: #b97e0e; }
#joinQr { display: flex; justify-content: center; margin: 8px 0; }
#joinQr img, #joinQr canvas { background: #fff; padding: 8px; border-radius: 10px; border: 2px solid #e3e9f7; }

.status { margin-top: 12px; font-size: .95rem; min-height: 1.2em; }
.status.ok { color: #15803d; font-weight: 600; }
.status.err { color: #b91c1c; font-weight: 600; }

.lbl { display: block; font-weight: 700; margin: 16px 0 8px; }
.lbl:first-of-type { margin-top: 0; }
.pcount { color: #666; font-weight: 600; font-size: .9em; }

.player-list { display: flex; flex-wrap: wrap; gap: 8px; min-height: 44px; }
.no-players { color: #888; font-size: .95rem; }
.player-chip {
  display: inline-flex; align-items: center; gap: 8px;
  background: #eef2ff; border: 2px solid #c9d4f2; border-radius: 999px;
  padding: 7px 14px 7px 9px; font-weight: 800; font-size: 1rem;
}
.player-chip .pdot { width: 14px; height: 14px; border-radius: 50%; flex: none; box-shadow: 0 0 0 2px rgba(0,0,0,.12); }
.player-chip.away { opacity: .45; }
.lib-hint { font-size: .82rem; color: #777; margin-top: 10px; line-height: 1.45; }

.set-picker { display: flex; flex-direction: column; gap: 8px; }
.set-btn {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; text-align: left; cursor: pointer;
  background: #eef2ff; border: 2px solid #c9d4f2; border-radius: 12px;
  padding: 11px 14px; font-size: 1rem; font-weight: 800; color: var(--ink);
}
.set-btn .set-count { font-weight: 700; color: #666; font-size: .88rem; white-space: nowrap; }
.set-btn.on { background: #173a7d; border-color: #173a7d; color: #fff; }
.set-btn.on .set-count { color: #cfe0ff; }

.seg { display: inline-flex; flex-wrap: wrap; background: #e8edfb; border-radius: 999px; padding: 4px; gap: 4px; }
.seg button {
  border: 0; background: transparent; padding: 8px 15px; border-radius: 999px;
  font-size: 1rem; font-weight: 700; cursor: pointer; color: var(--ink);
}
.seg button.on { background: #173a7d; color: #fff; }
.board-info { margin-top: 10px; color: #555; font-size: .95rem; }
.more-games { margin-top: 16px; font-size: .92rem; color: #555; line-height: 1.5; }
.more-games a { color: #173a7d; font-weight: 700; }

/* ---------- buttons ---------- */
.btn {
  border: 2px solid #c9d4f2; background: #fff; color: var(--ink);
  padding: 10px 18px; border-radius: 999px; font-size: 1rem; font-weight: 700;
  cursor: pointer; transition: .15s;
}
.btn:hover { border-color: var(--gold); transform: translateY(-1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn-primary { background: #173a7d; border-color: #173a7d; color: #fff; }
.btn-ghost { background: transparent; border-color: rgba(255,255,255,.0); color: #33508f; }
#gameScreen .btn-ghost { color: #dbe6ff; border-color: rgba(255,255,255,.35); }
.btn-start { width: 100%; margin-top: 12px; background: var(--gold); border-color: var(--gold-dark); color: #231900; font-size: 1.1rem; padding: 14px; }
.btn-start:hover { border-color: #fff; }

/* ---------- game ---------- */
.topbar { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-bottom: 12px; }
.tbtn { padding: 7px 14px; font-size: .9rem; }

.round-head { display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap; margin-bottom: 8px; }
.round-label { color: #fff; font-weight: 800; font-size: 1.05rem; letter-spacing: .04em; }
.mult-badge { background: var(--bad); color: #fff; font-weight: 900; padding: 3px 12px; border-radius: 999px; font-size: .85rem; }

.question-text {
  text-align: center; color: #fff; font-weight: 900;
  font-size: clamp(1.4rem, 3.6vw, 2.2rem); margin: 10px 0 6px; text-shadow: 0 3px 0 rgba(0,0,0,.3);
}
.control-banner { text-align: center; color: #ffe9a8; font-size: 1.1rem; font-weight: 700; min-height: 1.4em; margin-bottom: 12px; }

.qrow { display: flex; align-items: center; gap: 16px; }
.qmain { flex: 1; min-width: 0; }
.timer-box {
  flex: none; width: 108px; height: 108px; border-radius: 50%;
  border: 3px solid var(--gold); background: rgba(0, 0, 0, .25); color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.timer-cap { font-size: .62rem; letter-spacing: .12em; opacity: .75; font-weight: 800; }
#timerValue { font-size: 1.9rem; font-weight: 900; font-variant-numeric: tabular-nums; line-height: 1.05; }
.timer-box.low { border-color: #e5484d; color: #ff8589; animation: timerPulse .5s ease-in-out infinite alternate; }
.timer-box.idle { opacity: .35; }
@keyframes timerPulse { from { transform: scale(1); } to { transform: scale(1.07); } }

.phase-zone { margin-top: 6px; }
.wait-line { text-align: center; color: #dbe6ff; font-size: 1.1rem; font-weight: 700; margin-top: 14px; min-height: 1.4em; }

/* fake phase: who's in */
.player-chips { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 18px; }
.fchip {
  display: inline-flex; align-items: center; gap: 9px;
  background: rgba(255,255,255,.1); border: 2px solid rgba(255,255,255,.35); border-radius: 999px;
  padding: 9px 18px 9px 11px; font-weight: 800; font-size: 1.1rem; color: #fff;
}
.fchip .pdot { width: 15px; height: 15px; border-radius: 50%; flex: none; box-shadow: 0 0 0 2px rgba(255,255,255,.35); }
.fchip .fstate { font-weight: 900; }
.fchip.done { background: rgba(34,197,94,.22); border-color: var(--good); }
.fchip.done .fstate { color: #8bf0a4; }
.fchip.away { opacity: .45; }

/* voting + reveal: lettered cards */
.options-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px;
  max-width: 980px; margin: 8px auto 0;
}
@media (max-width: 640px) { .options-grid { grid-template-columns: 1fr; } }
.opt-card {
  display: flex; align-items: center; gap: 13px;
  background: linear-gradient(180deg, #1d3f83, #122c5e);
  border: 2px solid #3f66b3; border-radius: 14px; padding: 14px 16px;
  color: #fff; min-height: 76px;
}
.opt-card .oletter {
  flex: none; width: 42px; height: 42px; border-radius: 50%;
  background: #0a1a3d; border: 2px solid var(--gold); color: var(--gold);
  display: flex; align-items: center; justify-content: center; font-size: 1.25rem; font-weight: 900;
}
.opt-card .otext { flex: 1; font-size: 1.3rem; font-weight: 800; overflow-wrap: anywhere; line-height: 1.2; }
.opt-card .ometa { flex: none; text-align: right; font-size: .85rem; line-height: 1.35; color: #cfe0ff; }
.opt-card .ometa .oauthor { font-weight: 800; color: #fff; }
.opt-card .ometa .ovoters { display: block; }
.opt-card.is-real {
  background: linear-gradient(180deg, #fdfdfd, #dfe8ff); color: var(--ink);
  border-color: var(--gold); box-shadow: 0 0 26px rgba(255,197,61,.55);
  animation: flipIn .45s ease;
}
.opt-card.is-real .oletter { background: var(--gold); color: #231900; border-color: var(--gold-dark); }
.opt-card.is-real .ometa { color: #44507a; }
.opt-card.is-real .ometa .oauthor { color: #b97e0e; }
.real-tag {
  display: inline-block; background: var(--good); color: #fff; font-weight: 900;
  border-radius: 7px; padding: 1px 9px; font-size: .8rem; margin-left: 8px; vertical-align: middle;
}
@keyframes flipIn { from { transform: rotateX(90deg); opacity: 0; } to { transform: rotateX(0); opacity: 1; } }

.round-points {
  text-align: center; color: #ffe9a8; font-size: 1.15rem; font-weight: 800;
  margin-top: 14px; min-height: 1.4em; line-height: 1.5;
}

/* standings */
.standings { display: flex; flex-direction: column; gap: 8px; max-width: 760px; margin: 12px auto 0; }
.standings .srow {
  display: flex; align-items: center; gap: 12px; padding: 11px 16px; border-radius: 12px;
  background: #fff; font-weight: 800; border-left: 8px solid #999; font-size: 1.1rem;
  box-shadow: 0 6px 16px rgba(0,0,0,.25);
}
.standings .srow .srank { flex: none; width: 34px; text-align: center; font-size: 1.2rem; }
.standings .srow .sname { flex: 1; overflow-wrap: anywhere; }
.standings .srow .sgain { color: #15803d; font-weight: 900; }
.standings .srow .sscore { font-weight: 900; font-size: 1.25rem; }
.standings .srow.first { background: #fff7e0; border-left-color: var(--gold); }

.game-controls { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 18px; }
.game-controls .btn-primary { font-size: 1.15rem; padding: 13px 34px; }

/* ---------- game over ---------- */
.winner-line { font-size: clamp(1.5rem, 4.5vw, 2.4rem); font-weight: 900; color: #ffe9a8; text-shadow: 0 3px 0 rgba(0,0,0,.3); margin-top: 8px; }
.over-card { max-width: 760px; margin: 0 auto; }
.modal-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 18px; }
.modal-actions .btn-primary { font-size: 1.1rem; padding: 13px 30px; }

/* ---------- go overlay ---------- */
.go-overlay {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(4, 10, 30, .55); z-index: 70; pointer-events: none;
}
.go-overlay span {
  font-size: clamp(3rem, 10vw, 6rem); font-weight: 900; color: #fff;
  text-shadow: 0 6px 0 rgba(0,0,0,.35); animation: goPop 1.2s ease;
}
@keyframes goPop { 0% { transform: scale(.4); opacity: 0; } 30% { transform: scale(1.1); opacity: 1; } 55% { transform: scale(1); } 100% { transform: scale(1); opacity: 1; } }

/* ---------- how to play page ---------- */
.rules-grid { display: grid; grid-template-columns: 1fr; gap: 16px; margin-bottom: 16px; }
.rules-list { display: flex; flex-direction: column; gap: 12px; text-align: left; }
.rule-step { display: flex; gap: 12px; align-items: flex-start; }
.rule-step p { margin: 0; line-height: 1.45; }
.rule-num {
  flex: none; width: 34px; height: 34px; border-radius: 50%;
  background: var(--gold); color: #231900; font-weight: 900; font-size: 1.15rem;
  display: flex; align-items: center; justify-content: center;
}
.example-card { text-align: left; }
.example-title { margin: 0 0 6px; font-size: 1.25rem; }
.example-q { font-size: 1.15rem; font-weight: 800; margin: 0 0 10px; }
.ex-board { display: flex; flex-direction: column; gap: 7px; margin-bottom: 12px; }
.ex-row {
  display: flex; align-items: center; gap: 10px;
  background: linear-gradient(180deg, #1d3f83, #122c5e);
  border: 2px solid #3f66b3; border-radius: 10px; padding: 8px 12px; color: #fff; font-weight: 800;
}
.ex-rank {
  flex: none; width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid var(--gold); color: var(--gold);
  display: flex; align-items: center; justify-content: center; font-size: .9rem;
}
.ex-text { flex: 1; }
.ex-story p { margin: 0 0 8px; line-height: 1.45; }
#rulesScreen .btn-start { width: 100%; }
@media (min-width: 900px) {
  .rules-grid { grid-template-columns: 1.1fr .9fr; }
}

/* ---------- TV mode: fit the whole game on one 16:9 screen ---------- */
body.tv { height: 100dvh; overflow: hidden; padding: 1.4vmin 1.8vmin; }
body.tv .screen { max-width: none; }
body.tv #setupScreen { height: 100%; overflow-y: auto; }
body.tv #gameScreen { height: 100%; display: flex; flex-direction: column; }
body.tv #gameScreen .topbar { margin-bottom: .6vmin; }
body.tv .round-head { margin-bottom: .4vmin; }
body.tv .round-label { font-size: 2vmin; }
body.tv .mult-badge { font-size: 1.8vmin; }
body.tv .qrow { gap: 2.5vmin; }
body.tv .timer-box { width: 13vmin; height: 13vmin; border-width: .5vmin; }
body.tv #timerValue { font-size: 4.2vmin; }
body.tv .timer-cap { font-size: 1.4vmin; }
body.tv .question-text { font-size: 4.6vmin; margin: .6vmin 0 .2vmin; }
body.tv .control-banner { font-size: 2.3vmin; margin-bottom: .8vmin; }
body.tv .phase-zone { flex: 1; min-height: 0; display: flex; flex-direction: column; justify-content: center; }
body.tv .phase-zone.hidden { display: none !important; }
body.tv .player-chips { margin-top: 0; gap: 1.6vmin; }
body.tv .fchip { font-size: 2.6vmin; padding: 1.2vmin 2.6vmin 1.2vmin 1.6vmin; }
body.tv .fchip .pdot { width: 2.2vmin; height: 2.2vmin; }
body.tv .wait-line { font-size: 2.3vmin; margin-top: 1.6vmin; }
body.tv .options-grid { width: 100%; max-width: none; gap: 1.4vmin; margin-top: 0; }
body.tv .opt-card { min-height: 0; padding: 1.4vmin 2vmin; }
body.tv .opt-card .oletter { width: 5.4vmin; height: 5.4vmin; font-size: 2.8vmin; }
body.tv .opt-card .otext { font-size: 3.1vmin; }
body.tv .opt-card .ometa { font-size: 1.9vmin; }
body.tv .round-points { font-size: 2.4vmin; margin-top: 1.4vmin; }
body.tv .standings { width: 100%; max-width: 110vmin; margin-top: 0; }
body.tv .standings .srow { font-size: 2.6vmin; padding: 1.2vmin 2vmin; }
body.tv .standings .srow .sscore { font-size: 3.1vmin; }
body.tv .game-controls { margin-top: .8vmin; }
body.tv .game-controls .btn { font-size: 2.1vmin; }
body.tv #overScreen { height: 100%; display: flex; flex-direction: column; justify-content: center; }
body.tv #overScreen .hero h1 { font-size: 5vmin; }
body.tv .pair-code { font-size: 4.6vmin; }
body.tv #rulesScreen { height: 100%; display: flex; flex-direction: column; }
body.tv #rulesScreen .rules-grid { flex: 1; min-height: 0; grid-template-columns: 1.1fr .9fr; }
body.tv #rulesScreen .card { overflow: hidden; }
body.tv #rulesScreen h1 { font-size: 5vmin; }
body.tv .rule-step p, body.tv .ex-story p { font-size: 2.25vmin; }
body.tv .rule-num { width: 4.6vmin; height: 4.6vmin; font-size: 2.4vmin; }
body.tv .example-title { font-size: 3vmin; }
body.tv .example-q { font-size: 2.7vmin; }
body.tv .ex-row { font-size: 2.3vmin; padding: 1vmin 1.6vmin; }
body.tv #rulesBackBtn { font-size: 2.4vmin; }

@media (max-width: 640px) {
  .timer-box { width: 84px; height: 84px; }
  #timerValue { font-size: 1.45rem; }
  .opt-card .otext { font-size: 1.1rem; }
}
