:root {
  --bg: #0a0d1a;
  --panel: #141a2e;
  --panel-2: #1c2440;
  --line: #2a3454;
  --ink: #eef2ff;
  --muted: #8b96b8;
  --accent: #ffc53d;
  --accent-ink: #1a1400;
  --ok: #34d399;
  --bad: #f87171;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  background-image: radial-gradient(1200px 600px at 50% -10%, #1b2440 0%, transparent 60%);
}

button {
  font: inherit;
  color: inherit;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background .12s, transform .06s, border-color .12s;
}
button:hover:not(:disabled) { background: #26304f; }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .4; cursor: not-allowed; }

button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
button.primary:hover:not(:disabled) { background: #ffd469; }
button.ok { background: #10402f; border-color: #1c6b4d; color: var(--ok); }
button.ok:hover:not(:disabled) { background: #14523c; }
button.bad { background: #40161a; border-color: #7a2a30; color: var(--bad); }
button.bad:hover:not(:disabled) { background: #521c22; }
button.ghost { background: transparent; }

input, select {
  font: inherit;
  color: var(--ink);
  background: #0f1425;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.hidden { display: none !important; }

/* ------------------------------------------------------------ вход */

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.gate-card {
  width: min(380px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
  display: grid;
  gap: 14px;
}
.gate h1 {
  margin: 0;
  font-size: 34px;
  letter-spacing: .18em;
  text-align: center;
  color: var(--accent);
}
.gate p { margin: 0; color: var(--muted); text-align: center; font-size: 14px; }
.err { color: var(--bad); font-size: 14px; min-height: 18px; text-align: center; }

/* ------------------------------------------------------------ игрок */

.player {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 12px;
  padding: 14px;
}
.p-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 16px;
}
.p-name { font-weight: 600; }
.p-score { font-size: 26px; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.p-score.neg { color: var(--bad); }

.p-mid {
  display: grid;
  place-items: center;
  text-align: center;
  gap: 14px;
  padding: 10px;
}
.p-theme { color: var(--muted); text-transform: uppercase; letter-spacing: .12em; font-size: 13px; }
.p-cost { font-size: 20px; color: var(--accent); font-weight: 700; }
.p-question { font-size: clamp(18px, 5vw, 26px); line-height: 1.35; max-width: 640px; }
.p-status { color: var(--muted); font-size: 15px; }
.p-answer {
  border-top: 1px solid var(--line);
  padding-top: 12px;
  color: var(--ok);
  font-size: 20px;
  font-weight: 600;
}

.buzz {
  width: 100%;
  height: 130px;
  border-radius: 20px;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: .04em;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
}
.buzz:disabled { background: #232b45; color: var(--muted); }
.buzz.mine { background: var(--ok); color: #06281c; }

.scores { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.chip {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 14px;
}
.chip.answering { border-color: var(--ok); color: var(--ok); }
.chip.locked { opacity: .45; }

.bar { height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); transition: width .2s linear; }

/* ------------------------------------------------------------ ведущий */

.host {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 16px;
  padding: 16px;
  min-height: 100vh;
  align-items: start;
}
@media (max-width: 900px) { .host { grid-template-columns: 1fr; } }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.card + .card { margin-top: 14px; }
.card h2 {
  margin: 0 0 12px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .14em;
  color: var(--muted);
  font-weight: 600;
}

.rounds { display: flex; gap: 8px; flex-wrap: wrap; }
.rounds button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.board { display: grid; gap: 8px; overflow-x: auto; }
.board-row {
  display: grid;
  grid-template-columns: var(--theme-col, 170px) repeat(var(--cols, 5), minmax(64px, 1fr));
  gap: 8px;
  align-items: stretch;
  min-width: min-content;
}
@media (max-width: 1100px) { .board-row { --theme-col: 120px; } }
.theme-name {
  display: flex;
  align-items: center;
  font-weight: 600;
  font-size: 14px;
  padding: 8px;
  background: var(--panel-2);
  border-radius: 10px;
}
.cell {
  padding: 14px 4px;
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.cell.taken { color: #39415f; background: #10152a; }
.cell .tag { display: block; font-size: 10px; letter-spacing: .1em; color: var(--muted); font-weight: 600; }

.qbox { display: grid; gap: 12px; }
.q-meta { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .1em; }
.q-text { font-size: 22px; line-height: 1.35; }
.q-answer {
  background: #10402f;
  border: 1px solid #1c6b4d;
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--ok);
  font-size: 19px;
  font-weight: 600;
}
.q-who {
  font-size: 20px;
  font-weight: 700;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px dashed var(--line);
}
.q-who.on { border: 1px solid var(--ok); color: var(--ok); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.tight { gap: 6px; }
.grow { flex: 1; min-width: 90px; }

.plist { display: grid; gap: 10px; }
.pcard {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  display: grid;
  gap: 8px;
}
.pcard.answering { border-color: var(--ok); }
.pcard.off { opacity: .5; }
.pcard .head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.pcard .nm { font-weight: 600; }
.pcard .sc { font-size: 22px; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.pcard .sc.neg { color: var(--bad); }
.pcard button { padding: 6px 8px; font-size: 13px; }

.code {
  font-size: 34px;
  font-weight: 800;
  letter-spacing: .2em;
  color: var(--accent);
  text-align: center;
}

.log { font-size: 13px; color: var(--muted); display: grid; gap: 4px; max-height: 180px; overflow: auto; }

.finaltable { width: 100%; border-collapse: collapse; font-size: 15px; }
.finaltable th, .finaltable td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); }
.finaltable th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .1em; }

/* ------------------------------------------------------------ табло на ТВ */

.tv {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 2vh;
  padding: 2.5vh 3vw;
}
.tv-head { display: flex; justify-content: space-between; align-items: baseline; gap: 2vw; }
.tv-round {
  font-size: clamp(20px, 2.4vw, 40px);
  letter-spacing: .2em;
  text-transform: uppercase;
  font-weight: 800;
  color: var(--accent);
}
.tv-hint {
  color: var(--muted);
  font-size: clamp(13px, 1.2vw, 22px);
  letter-spacing: .14em;
  text-transform: uppercase;
}

.tv-stage { display: grid; align-content: center; min-height: 0; }

.tv-board { display: grid; gap: 1.2vh; align-content: center; }
.tv-row { display: grid; grid-template-columns: 22% repeat(var(--cols, 5), 1fr); gap: 1vh 1vw; }
.tv-theme {
  display: flex;
  align-items: center;
  padding: 0 1.2vw;
  background: var(--panel);
  border-radius: 12px;
  font-weight: 700;
  font-size: clamp(13px, 1.4vw, 26px);
}
.tv-cell {
  display: grid;
  place-items: center;
  padding: 1.6vh 0;
  background: var(--panel-2);
  border-radius: 12px;
  color: var(--accent);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  font-size: clamp(18px, 2.6vw, 52px);
}
.tv-cell.taken { background: #0e1326; }

.tv-question {
  display: grid;
  align-content: center;
  justify-items: center;
  text-align: center;
  gap: 2.5vh;
  padding: 0 4vw;
}
.tv-qmeta {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .18em;
  font-size: clamp(13px, 1.3vw, 24px);
}
.tv-qtext {
  font-size: clamp(22px, 3.4vw, 64px);
  line-height: 1.25;
  font-weight: 600;
  max-width: 90%;
}
.tv-bar { width: min(700px, 70%); height: 10px; background: var(--panel-2); border-radius: 5px; overflow: hidden; }
.tv-bar > i { display: block; height: 100%; background: var(--accent); transition: width .2s linear; }
.tv-who { font-size: clamp(20px, 2.4vw, 44px); font-weight: 800; color: var(--ok); }
.tv-answer {
  border-top: 2px solid var(--line);
  padding-top: 2vh;
  font-size: clamp(20px, 2.6vw, 48px);
  font-weight: 800;
  color: var(--ok);
}

.tv-final { display: grid; gap: 1vh; width: min(900px, 92%); }
.tv-frow {
  display: grid;
  grid-template-columns: 1fr 2fr auto;
  gap: 2vw;
  align-items: baseline;
  background: var(--panel);
  border-radius: 12px;
  padding: 1.2vh 1.5vw;
  font-size: clamp(15px, 1.6vw, 28px);
  text-align: left;
}
.tv-fbet { color: var(--accent); font-weight: 800; font-variant-numeric: tabular-nums; }

.tv-players { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 1.5vw; }
.tv-p {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 1.6vh 1vw;
  text-align: center;
  transition: border-color .15s, background .15s;
}
.tv-p.turn { border-color: var(--accent); }
.tv-p.answering { border-color: var(--ok); background: #0f3226; }
.tv-p.locked { opacity: .45; }
.tv-pname { font-size: clamp(14px, 1.6vw, 30px); font-weight: 600; }
.tv-pscore {
  font-size: clamp(26px, 3.2vw, 60px);
  font-weight: 800;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.tv-pscore.neg { color: var(--bad); }

.plist.wide { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.code.screen { color: #7dd3fc; }
.codehint { color: var(--muted); font-size: 12px; text-align: center; margin-top: 6px; }
.codehint b { color: var(--ink); font-weight: 600; }
.pcard .grow { min-width: 56px; }

.tv-headright { display: flex; align-items: center; gap: 1.5vw; }
.tv-sound {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .6vh 1vw;
  font-size: clamp(14px, 1.2vw, 22px);
  line-height: 1;
  color: var(--muted);
}
.tv-sound.warn { border-color: var(--accent); color: var(--accent); }

/* многострочные вопросы (варианты а/б/в) */
.q-text, .p-question, .tv-qtext { white-space: pre-line; }

/* выбор темы финала в пульте */
.fopts { display: grid; gap: 6px; }
.fopt {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
}
.fopt.out { opacity: .45; }
.fopt.out .fopt-name { text-decoration: line-through; }
.fopt-name { flex: 1; font-weight: 600; }
.fopt button { padding: 5px 9px; font-size: 13px; }

/* темы финала на табло */
.tv-fopts { display: grid; gap: 1.2vh; }
.tv-fopt {
  font-size: clamp(18px, 2.4vw, 42px);
  font-weight: 700;
  transition: opacity .2s;
}
.tv-fopt.out { opacity: .3; text-decoration: line-through; color: var(--muted); }
