:root {
  --bg: #070d2e;
  --bg-2: #0e1a55;
  --panel: #13226b;
  --panel-2: #1a2d86;
  --line: rgba(255, 255, 255, 0.12);
  --text: #f4f6ff;
  --muted: #a9b3e0;
  --gold: #ffc93c;
  --gold-dark: #d99b00;
  --good: #2fd37f;
  --bad: #ff5a6a;
  --accent: #4f7bff;
  --radius: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  background: radial-gradient(circle at 50% -20%, var(--bg-2), var(--bg) 70%) fixed;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}

.wrap { max-width: 560px; margin: 0 auto; padding: 16px 16px 40px; }

h1, h2, h3 { margin: 0 0 12px; line-height: 1.15; }
h1 { font-size: 30px; }
h2 { font-size: 22px; }

.logo { font-size: 34px; font-weight: 900; letter-spacing: -0.5px; text-align: center; margin: 24px 0 4px; }
.logo span { color: var(--gold); }
.subtitle { text-align: center; color: var(--muted); margin-bottom: 24px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

.muted { color: var(--muted); }
.center { text-align: center; }
.row { display: flex; gap: 10px; align-items: center; }
.row > * { flex: 1; }
.stack > * + * { margin-top: 10px; }

button, .btn {
  appearance: none;
  border: 0;
  border-radius: 12px;
  padding: 14px 16px;
  font: inherit;
  font-weight: 700;
  color: var(--text);
  background: var(--panel-2);
  cursor: pointer;
  width: 100%;
  display: block;
  text-align: center;
  text-decoration: none;
}
button:disabled { opacity: 0.45; cursor: default; }
.btn-gold { background: var(--gold); color: #1d1500; }
.btn-ghost { background: transparent; border: 1px solid var(--line); }
.btn-small { padding: 8px 12px; font-size: 14px; width: auto; display: inline-block; }
.btn-danger { background: #5a1830; }

input[type=text], input[type=number], input:not([type]), textarea, select {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: #0a1445;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 13px 14px;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; }

.code-big { font-size: 46px; font-weight: 900; letter-spacing: 8px; color: var(--gold); text-align: center; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: var(--panel-2); border-radius: 999px; padding: 6px 12px; font-size: 15px; }
.chip.offline { opacity: 0.45; }

/* Табло вопросов */
.board { display: grid; gap: 6px; }
.board-row { display: grid; grid-template-columns: minmax(0, 1.6fr) repeat(5, minmax(0, 1fr)); gap: 6px; }
.board-theme {
  background: var(--panel-2);
  border-radius: 10px;
  padding: 8px;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  min-height: 52px;
  overflow-wrap: break-word;
  hyphens: auto;
  -webkit-hyphens: auto;
}
.board-cell {
  background: #1b3bb3;
  color: var(--gold);
  border-radius: 10px;
  font-weight: 900;
  font-size: 15px;
  padding: 0;
  min-height: 52px;
}
.board-cell.used { background: #0b1440; color: transparent; }
.board-cell:not(:disabled):active { transform: scale(0.96); }

/* Вопрос */
.q-meta { color: var(--gold); font-weight: 800; text-transform: uppercase; font-size: 14px; letter-spacing: 0.5px; }
.q-text { font-size: 23px; font-weight: 700; margin: 10px 0 4px; }
.answer-box { background: #0b5d34; border-radius: var(--radius); padding: 16px; text-align: center; }
.answer-box b { font-size: 26px; display: block; }

.buzz {
  height: 46vh;
  max-height: 340px;
  min-height: 200px;
  border-radius: 28px;
  font-size: 34px;
  font-weight: 900;
  background: radial-gradient(circle at 50% 35%, #ff7a5c, #e0233f);
  box-shadow: 0 10px 0 #8b0f22, 0 18px 40px rgba(224, 35, 63, 0.4);
  margin: 16px 0 10px;
  touch-action: manipulation;
  user-select: none;
}
.buzz:not(:disabled):active { transform: translateY(6px); box-shadow: 0 4px 0 #8b0f22; }
.buzz:disabled { background: #2a356e; box-shadow: none; font-size: 22px; }

.timer { font-size: 40px; font-weight: 900; color: var(--gold); text-align: center; }
.timer.urgent { color: var(--bad); }
.status-line { text-align: center; font-size: 20px; font-weight: 700; margin: 12px 0; }

.attempt { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.attempt:first-child { border-top: 0; }
.attempt .who { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.verdict-good { color: var(--good); font-weight: 800; }
.verdict-bad { color: var(--bad); font-weight: 800; }

.scores { display: grid; gap: 6px; }
.score-row { display: flex; justify-content: space-between; padding: 8px 12px; background: var(--panel-2); border-radius: 10px; }
.score-row.me { outline: 2px solid var(--gold); }
.score-row .pts { font-weight: 900; }

.top-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; font-size: 14px; color: var(--muted); }
.top-bar b { color: var(--text); }
.conn-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--good); display: inline-block; margin-right: 6px; }
.conn-dot.off { background: var(--bad); }

.theme-list { max-height: 260px; overflow: auto; display: grid; gap: 6px; }
.theme-option { display: flex; gap: 10px; align-items: center; padding: 6px 8px; background: #0a1445; border-radius: 10px; font-size: 15px; color: var(--text); margin: 0; }
.theme-option input { width: 20px; height: 20px; flex: none; }

.admin-panel { border-color: rgba(255, 201, 60, 0.4); }
.admin-panel summary { cursor: pointer; font-weight: 700; color: var(--gold); }

.podium { font-size: 22px; }
.podium .score-row:first-child { background: var(--gold); color: #1d1500; font-size: 26px; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(120px);
  background: #000c; padding: 12px 18px; border-radius: 12px; max-width: calc(100% - 32px);
  transition: transform 0.25s; z-index: 10; text-align: center;
}
#toast.show { transform: translateX(-50%) translateY(0); }

.qr { background: #fff; padding: 12px; border-radius: 14px; display: inline-block; }
.qr img, .qr canvas { display: block; }

/* Табло на большом экране */
.screen { max-width: none; padding: 3vh 3vw; min-height: 100vh; display: grid; grid-template-columns: 1fr 22vw; gap: 2.5vw; }
.screen .board-theme { font-size: 1.6vw; min-height: 9vh; padding: 1vw; }
.screen .board-cell { font-size: 2.6vw; min-height: 9vh; }
.screen .q-text { font-size: 3.6vw; }
.screen .q-meta { font-size: 1.4vw; }
.screen .score-row { font-size: 1.6vw; padding: 1vh 1vw; }
.screen .status-line { font-size: 2.2vw; }
.screen .timer { font-size: 5vw; }
.screen .answer-box b { font-size: 3.4vw; }
.screen .attempt { font-size: 1.6vw; }
.screen h2 { font-size: 2vw; }
@media (max-width: 800px) {
  .screen { grid-template-columns: 1fr; }
}

#offline-banner {
  position: fixed; left: 0; right: 0; top: 0; z-index: 20;
  display: flex; gap: 12px; align-items: center; justify-content: center;
  padding: 12px 16px; background: var(--bad); color: #fff; font-weight: 700; text-align: center;
  transform: translateY(-110%); transition: transform 0.25s;
}
#offline-banner.show { transform: translateY(0); }

/* Печать вопроса: ещё не «прочитанные» слова занимают место, но не видны */
.q-text .w.hide { visibility: hidden; }

/* Кнопка «Ответить», пока вопрос читается */
.buzz { position: relative; overflow: hidden; }
.buzz .buzz-label { position: relative; z-index: 1; }
.buzz .buzz-fill { position: absolute; left: 0; bottom: 0; width: 100%; height: 0; background: rgba(255, 255, 255, 0.18); }
.buzz.locked { background: #2a356e; box-shadow: none; font-size: 22px; }
.buzz.locked .buzz-fill { height: calc(var(--progress, 0) * 100%); transition: height 0.1s linear; }
.buzz.locked:active { transform: none; }

/* Полоска чтения на табло */
.read-bar { position: relative; overflow: hidden; border-radius: 999px; background: var(--panel); margin: 14px 0; padding: 10px 16px; text-align: center; color: var(--muted); }
.read-bar i { position: absolute; inset: 0 auto 0 0; width: calc(var(--progress, 0) * 100%); background: rgba(255, 201, 60, 0.25); }
.read-bar span { position: relative; }
.read-bar:not(.locked) { display: none; }

/* Суперигра */
.super-themes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 10px; }
.super-theme { background: var(--panel-2); border-radius: 12px; padding: 12px 10px; font-weight: 700; text-align: center; font-size: 15px; }
.super-theme:not(:disabled) { outline: 2px solid var(--gold); }
.super-theme:disabled { opacity: 1; cursor: default; }
.super-theme.removed { background: transparent; border: 1px dashed var(--line); color: var(--muted); text-decoration: line-through; opacity: .5; }
.chip-done { background: #0b5d34; }
.timer-inline { font-weight: 900; color: var(--gold); }
.screen .super-themes { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.screen .super-theme { font-size: 1.4vw; padding: 2vh 1vw; }

/* Картинка в вопросе и её проявление */
.media { position: relative; overflow: hidden; border-radius: 14px; margin-top: 12px; display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, .25); }
.media img { display: block; width: 100%; max-height: 30vh; object-fit: contain; user-select: none; -webkit-user-drag: none; }
.media-emoji { font-size: 54px; line-height: 1.2; padding: 14px 8px; text-align: center; letter-spacing: 4px; }
.media-emoji .e { display: inline-block; transition: opacity .4s, transform .4s; }
.media-emoji .e.hide { opacity: 0; transform: scale(.4); }
.media-color { width: 100%; height: 150px; }
.media-blur > * { filter: blur(calc(var(--hidden, 0) * 26px)); transform: scale(1.06); }
.media-zoom > * { transform: scale(calc(1 + var(--hidden, 0) * 5)); transform-origin: var(--origin, 50% 50%); }
.screen .media img { max-height: 48vh; }
.screen .media-emoji { font-size: 7vw; }
.screen .media-color { height: 40vh; }

/* Фото в редакторе */
.photo-preview { display: flex; gap: 10px; align-items: center; }
.photo-preview img { width: 96px; height: 72px; object-fit: cover; border-radius: 8px; }
label.btn { color: var(--text); }

/* Если в вопросе есть картинка — кнопка пониже, чтобы всё влезло в экран */
.card:has(.media) ~ .buzz { height: 26vh; min-height: 130px; margin-top: 10px; }
