:root {
  --bg: #08133f;
  --bg2: #0f2272;
  --panel: #13287f;
  --line: #2b44a8;
  --gold: #ffcc33;
  --text: #f3f5ff;
  --muted: #9aa6d6;
  --ok: #2fbf71;
  --bad: #e5484d;
  --accent: #5b8cff;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: radial-gradient(ellipse at top, var(--bg2), var(--bg) 70%) fixed;
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
}
a { color: var(--gold); }
h1, h2, h3 { margin: 0 0 .5em; }
.muted { color: var(--muted); }
.wrap { max-width: 1100px; margin: 0 auto; padding: 16px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.grow { flex: 1; }
.center { text-align: center; }
.hidden { display: none !important; }

button, .btn {
  font: inherit; font-weight: 600;
  background: var(--accent); color: #fff;
  border: 0; border-radius: 10px;
  padding: 10px 16px; cursor: pointer;
  text-decoration: none; display: inline-block;
}
button:hover:not(:disabled), .btn:hover { filter: brightness(1.12); }
button:disabled { opacity: .45; cursor: default; }
button.ok { background: var(--ok); }
button.bad { background: var(--bad); }
button.gold { background: var(--gold); color: #1a1a1a; }
button.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
button.small { padding: 5px 10px; font-size: 14px; }
button.big { font-size: 20px; padding: 14px 22px; }

input, textarea, select {
  font: inherit; color: var(--text);
  background: #0a1850; border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 11px; width: 100%;
}
textarea { resize: vertical; min-height: 60px; }
label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 4px; }

.card { background: rgba(19, 40, 127, .75); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stack > * + * { margin-top: 12px; }

/* Табло */
.board {
  display: grid;
  grid-template-columns: minmax(120px, 1.6fr) repeat(var(--rows), 1fr);
  gap: 6px;
}
.theme-name, .cell {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  min-height: 56px; display: flex; align-items: center; justify-content: center; text-align: center;
  padding: 6px 10px;
}
.theme-name { justify-content: flex-start; text-align: left; font-weight: 600; }
.cell { color: var(--gold); font-size: 22px; font-weight: 800; }
button.cell { cursor: pointer; }
button.cell:hover { background: #1d3aa8; }
.cell.used { background: transparent; border-style: dashed; opacity: .35; }

/* Гравці */
.players { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.player {
  background: var(--panel); border: 2px solid var(--line); border-radius: 10px;
  padding: 8px 14px; min-width: 120px; text-align: center; transition: .2s;
}
.player.active { border-color: var(--gold); box-shadow: 0 0 18px rgba(255, 204, 51, .5); }
.player.chooser { border-color: var(--accent); }
.player.offline { opacity: .5; }
.player-name { font-weight: 600; }
.player-score { color: var(--gold); font-size: 22px; font-weight: 800; }
.player-score.neg { color: var(--bad); }

/* Питання */
.q-head { color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-size: 14px; }
.q-head b { color: var(--gold); }
.q-text { font-size: 26px; font-weight: 600; }
.badge { display: inline-block; background: var(--gold); color: #1a1a1a; border-radius: 6px; padding: 2px 8px; font-weight: 700; font-size: 13px; }
.answer { border-left: 4px solid var(--ok); padding: 8px 12px; background: rgba(47, 191, 113, .12); border-radius: 6px; }
.media { display: block; max-width: 100%; max-height: 50vh; margin: 12px auto; border-radius: 8px; }
.gallery { display: grid; gap: 8px; align-items: center; justify-items: center; }
.gallery.n2 { grid-template-columns: repeat(2, 1fr); }
.gallery.n3 { grid-template-columns: repeat(3, 1fr); }
.gallery.n4 { grid-template-columns: repeat(2, 1fr); }
.gallery .media { margin: 0; max-width: 100%; object-fit: contain; }
.gallery.n2 .media, .gallery.n3 .media { max-height: 40vh; }
.gallery.n4 .media { max-height: 25vh; }
.media-audio { text-align: center; }
.media-audio .note { font-size: 64px; color: var(--gold); }
.media-audio audio { width: 100%; max-width: 420px; }

.timer { position: relative; height: 10px; background: #0a1850; border-radius: 5px; overflow: hidden; margin: 10px 0; }
.timer-bar { position: absolute; inset: 0 auto 0 0; background: var(--gold); transition: width .1s linear; }
.timer span { position: absolute; right: 6px; top: -4px; font-size: 12px; display: none; }

.status { font-size: 20px; font-weight: 600; text-align: center; padding: 10px; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 40px);
  background: #222a4d; border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px;
  opacity: 0; transition: .25s; pointer-events: none; z-index: 100; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.code { font-family: ui-monospace, Menlo, monospace; letter-spacing: .15em; color: var(--gold); font-weight: 800; }
.qr { background: #fff; border-radius: 10px; padding: 8px; width: 180px; height: 180px; }
.list-item { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.strike { text-decoration: line-through; opacity: .4; }
.pill-ok { color: var(--ok); font-weight: 700; }
.pill-bad { color: var(--bad); font-weight: 700; }

@media (max-width: 640px) {
  .board { grid-template-columns: minmax(90px, 1.3fr) repeat(var(--rows), 1fr); gap: 4px; }
  .theme-name, .cell { min-height: 44px; font-size: 13px; padding: 4px; }
  .cell { font-size: 16px; }
  .q-text { font-size: 20px; }
}
