*, *::before, *::after { box-sizing: border-box; }
:root {
  color-scheme: dark;
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface-2: #16213e;
  --surface-3: #22223a;
  --border: rgba(255, 255, 255, 0.1);
  --text: #f1f5f9;
  --muted: #94a3b8;
  --gold: #f59e0b;
  --gold-light: #fcd34d;
  --ok: #34d399;
  --bad: #fb7185;
  --info: #60a5fa;
  --radius: 10px;
}
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
  min-height: 100vh;
}
a { color: var(--gold-light); }
img { max-width: 100%; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 0.75rem; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.inline { display: inline; }
.hidden, [hidden] { display: none !important; }
.row { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.stack > * + * { margin-top: 1rem; }

/* ---------- layout */
.maintenance-banner {
  background: repeating-linear-gradient(45deg, #b91c1c, #b91c1c 14px, #991b1b 14px, #991b1b 28px);
  color: #fff; text-align: center; padding: 0.45rem 1rem; font-size: 0.9rem;
  position: sticky; top: 0; z-index: 50;
}
.maintenance-banner a { color: #fff; font-weight: 700; margin-left: 0.5rem; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  padding: 0.7rem 1.25rem; background: var(--surface-2); border-bottom: 1px solid var(--border);
}
.logo { font-size: 1.3rem; font-weight: 900; color: var(--gold); text-transform: uppercase; text-decoration: none; letter-spacing: 0.02em; }
.logo span { color: var(--text); }
.nav { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.nav a { color: var(--text); text-decoration: none; font-weight: 600; font-size: 0.9rem; }
.nav a:hover { color: var(--gold-light); }
.nav-user { display: inline-flex; align-items: center; gap: 0.45rem; }
.container { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.container.wide { max-width: 1500px; }
.narrow { max-width: 460px; margin: 2rem auto; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1.25rem; }
.card-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem;
}
.messages { max-width: 1100px; margin: 1rem auto 0; padding: 0 1rem; display: grid; gap: 0.5rem; }
.msg { padding: 0.6rem 0.9rem; border-radius: 8px; background: var(--surface-3); border-left: 4px solid var(--info); }
.msg.success { border-color: var(--ok); }
.msg.error { border-color: var(--bad); }
.msg.warning { border-color: var(--gold); }

/* ---------- controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.5rem 1rem; border-radius: 8px; border: 1px solid transparent; cursor: pointer;
  font: inherit; font-weight: 700; font-size: 0.9rem; text-decoration: none; white-space: nowrap;
  background: var(--gold); color: #1a1a2e; transition: background 0.15s, opacity 0.15s;
}
.btn:hover { background: var(--gold-light); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.ghost { background: rgba(255, 255, 255, 0.07); color: var(--text); border-color: var(--border); }
.btn.ghost:hover { background: rgba(255, 255, 255, 0.14); }
.btn.ok { background: rgba(52, 211, 153, 0.2); color: var(--ok); border-color: rgba(52, 211, 153, 0.45); }
.btn.bad, .btn.danger { background: rgba(190, 18, 60, 0.2); color: var(--bad); border-color: rgba(190, 18, 60, 0.45); }
.btn.sm { padding: 0.3rem 0.65rem; font-size: 0.8rem; }
.btn.lg { padding: 0.8rem 1.6rem; font-size: 1.05rem; }
.btn.block { width: 100%; }

input[type=text], input[type=password], input[type=number], input[type=email], input[type=url],
input:not([type]), select, textarea {
  width: 100%; background: rgba(255, 255, 255, 0.06); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.55rem 0.75rem; color: var(--text); font: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--gold); }
input[type=file] { color: var(--muted); max-width: 100%; }
input[type=range] { accent-color: var(--gold); width: 100%; }
input[type=checkbox], input[type=radio] { accent-color: var(--gold); }

/* Django's default <div> form rendering */
form.form > div, .form-fields > div { margin-bottom: 1rem; }
form.form label, .form-fields label { display: block; font-weight: 700; font-size: 0.85rem; margin-bottom: 0.3rem; color: var(--muted); }
form.form input[type=checkbox] + label, .form-fields input[type=checkbox] + label { display: inline; }
.helptext { display: block; font-size: 0.8rem; color: var(--muted); margin-top: 0.25rem; }
.errorlist { list-style: none; margin: 0.3rem 0; padding: 0; color: var(--bad); font-size: 0.85rem; }
.form-fields ul:not(.errorlist) { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.4rem; }
.form-fields ul:not(.errorlist) label { display: flex; gap: 0.5rem; align-items: center; color: var(--text); font-weight: 600; }

.avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.avatar.sm { width: 26px; height: 26px; font-size: 0.75rem; }
.avatar.lg { width: 96px; height: 96px; font-size: 2rem; }
.avatar.placeholder { display: inline-grid; place-items: center; background: var(--surface-3); color: var(--gold); font-weight: 900; }

.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th, .table td { text-align: left; padding: 0.55rem 0.5rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }
.table-wrap { overflow-x: auto; }
.badge { display: inline-block; padding: 0.1rem 0.5rem; border-radius: 999px; font-size: 0.72rem; font-weight: 800; background: var(--surface-3); color: var(--muted); }
.badge.ok { color: var(--ok); background: rgba(52, 211, 153, 0.12); }
.badge.bad { color: var(--bad); background: rgba(251, 113, 133, 0.12); }
.badge.gold { color: var(--gold); background: rgba(245, 158, 11, 0.12); }
.copy-field { display: flex; gap: 0.5rem; }
.copy-field input { font-family: ui-monospace, monospace; font-size: 0.8rem; }

/* ---------- home / lists */
.hero { text-align: center; padding: 2rem 1rem 1rem; }
.code-input { text-transform: uppercase; letter-spacing: 0.3em; text-align: center; font-size: 1.4rem !important; font-weight: 800; }
.list { display: grid; gap: 0.6rem; }
.list-item {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap;
  padding: 0.75rem 1rem; background: var(--surface-3); border: 1px solid var(--border); border-radius: 8px;
}
.list-item .title { font-weight: 700; }

/* ---------- editor */
.board-tabs { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 1rem; }
.board-tabs a { padding: 0.4rem 0.9rem; border-radius: 8px; background: var(--surface-3); color: var(--text); text-decoration: none; font-weight: 700; font-size: 0.85rem; border: 1px solid var(--border); }
.board-tabs a.active { background: var(--gold); color: #1a1a2e; }
.editor-grid-wrap { overflow-x: auto; }
.editor-grid { display: grid; gap: 0.5rem; min-width: 560px; }
.editor-cat {
  border-radius: 8px; padding: 0.6rem 0.5rem; text-align: center; color: #fff; font-weight: 800; font-size: 0.85rem;
  display: grid; gap: 0.35rem; align-content: space-between; min-height: 84px;
}
.editor-cat a { color: #fff; text-decoration: none; }
.editor-cat .tools { display: flex; justify-content: center; gap: 0.2rem; }
.editor-cat .tools button, .editor-cat .tools a { background: rgba(0, 0, 0, 0.25); border: 0; color: #fff; border-radius: 5px; padding: 0.1rem 0.45rem; cursor: pointer; font-size: 0.75rem; }
.editor-cell {
  display: grid; place-items: center; min-height: 72px; border-radius: 8px; text-decoration: none; color: var(--text);
  background: var(--surface-2); border: 2px dashed var(--border); font-weight: 900; font-size: 1.15rem; position: relative; padding: 0.4rem;
}
.editor-cell.filled { border-style: solid; border-color: rgba(245, 158, 11, 0.35); color: var(--gold); }
.editor-cell.incomplete { border-color: rgba(251, 113, 133, 0.5); }
.editor-cell .kind { position: absolute; top: 4px; right: 6px; font-size: 0.8rem; }
.editor-cell .preview { font-size: 0.7rem; color: var(--muted); font-weight: 600; text-align: center; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.editor-cell:hover { border-color: var(--gold); }
.add-cat { display: grid; place-items: center; border: 2px dashed var(--border); border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 800; min-height: 84px; }

.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0.8rem; }
.media-item { background: var(--surface-3); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; display: flex; flex-direction: column; }
.media-item .thumb { height: 120px; display: grid; place-items: center; background: #0b0b14; font-size: 2.4rem; }
.media-item .thumb img, .media-item .thumb video { width: 100%; height: 100%; object-fit: cover; }
.media-item audio { width: 100%; }
.media-item .meta { padding: 0.5rem 0.6rem; font-size: 0.8rem; display: grid; gap: 0.3rem; }
.media-item .name { font-weight: 700; word-break: break-all; }
.filters { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.filters a { padding: 0.25rem 0.7rem; border-radius: 999px; background: var(--surface-3); color: var(--text); text-decoration: none; font-size: 0.8rem; font-weight: 700; }
.filters a.active { background: var(--gold); color: #1a1a2e; }

.segment-tool { background: var(--surface-3); border: 1px solid var(--border); border-radius: 8px; padding: 0.75rem; margin-top: 0.5rem; display: grid; gap: 0.5rem; }
.segment-tool video, .segment-tool audio { width: 100%; max-height: 260px; }
.segment-tool .time { font-family: ui-monospace, monospace; color: var(--gold); }
.icon-input { width: 5rem !important; text-align: center; font-size: 1.3rem; }

/* ---------- game */
body.game-page { overflow-x: hidden; }
.game-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 1rem; padding: 1rem; max-width: 1600px; margin: 0 auto; }
@media (max-width: 900px) { .game-layout { grid-template-columns: 1fr; } }
.game-main { min-width: 0; display: grid; gap: 1rem; align-content: start; }
.game-side { display: grid; gap: 1rem; align-content: start; }
.status-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.65rem 1rem;
}
.status-text { font-weight: 700; }
.timer { height: 6px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.timer > div { height: 100%; background: var(--gold); width: 100%; transform-origin: left; }
.timer.low > div { background: var(--bad); }
.conn-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--bad); display: inline-block; }
.conn-dot.on { background: var(--ok); }
.ping { font-size: 0.75rem; color: var(--muted); font-family: ui-monospace, monospace; }

.board { display: grid; gap: 0.5rem; }
.board .cat { border-radius: 8px; padding: 0.7rem 0.4rem; text-align: center; color: #fff; font-weight: 800; font-size: clamp(0.7rem, 1.4vw, 1rem); display: grid; place-items: center; min-height: 64px; }
.board .cell {
  display: grid; place-items: center; min-height: clamp(56px, 11vh, 110px); border-radius: 8px; border: 2px solid rgba(245, 158, 11, 0.25);
  background: linear-gradient(160deg, #1d2a52, #16213e); color: var(--gold); font-weight: 900; font-size: clamp(1rem, 2.6vw, 2rem);
  transition: transform 0.12s, border-color 0.12s, opacity 0.2s; user-select: none;
}
.board .cell.empty { visibility: hidden; }
.board .cell.used { opacity: 0.15; }
.board.can-pick .cell:not(.used):not(.empty) { cursor: pointer; }
.board.can-pick .cell:not(.used):not(.empty):hover { transform: scale(1.04); border-color: var(--gold); }
.board .cell.active { border-color: #fff; box-shadow: 0 0 22px rgba(245, 158, 11, 0.6); }

.question {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem;
  display: grid; gap: 1rem; text-align: center; min-height: 50vh; align-content: start;
}
.q-head { display: flex; justify-content: center; gap: 0.6rem; flex-wrap: wrap; align-items: center; }
.q-badge { padding: 0.25rem 0.8rem; border-radius: 999px; color: #fff; font-weight: 800; font-size: 0.85rem; }
.q-points { color: var(--gold); font-weight: 900; font-size: 1.2rem; }
.q-prompt { font-size: clamp(1.2rem, 3vw, 2.2rem); font-weight: 800; white-space: pre-line; }
.q-media { display: grid; place-items: center; }
.q-media img, .q-media video { max-height: 55vh; max-width: 100%; border-radius: 8px; }
.q-countdown { font-size: 4rem; font-weight: 900; color: var(--gold); }
.audio-viz { display: flex; gap: 5px; align-items: flex-end; height: 56px; }
.audio-viz span { width: 8px; background: var(--gold); border-radius: 3px; animation: bar 0.9s ease-in-out infinite; }
.audio-viz span:nth-child(2) { animation-delay: 0.15s; } .audio-viz span:nth-child(3) { animation-delay: 0.3s; }
.audio-viz span:nth-child(4) { animation-delay: 0.45s; } .audio-viz span:nth-child(5) { animation-delay: 0.6s; }
.audio-viz.paused span { animation-play-state: paused; opacity: 0.4; }
@keyframes bar { 0%, 100% { height: 10px; } 50% { height: 52px; } }
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0.6rem; }
.choice { padding: 0.9rem; border-radius: 8px; background: var(--surface-3); border: 2px solid var(--border); color: var(--text); font: inherit; font-weight: 700; font-size: 1.05rem; }
button.choice { cursor: pointer; }
button.choice:hover:not(:disabled) { border-color: var(--gold); }
.choice.correct { border-color: var(--ok); color: var(--ok); }
.answer-box { font-size: clamp(1.2rem, 3vw, 2rem); font-weight: 900; color: var(--ok); }
.result { font-weight: 800; font-size: 1.1rem; }
.result.ok { color: var(--ok); } .result.bad { color: var(--bad); }

.buzzer {
  width: min(70vw, 240px); aspect-ratio: 1; border-radius: 50%; border: 0; cursor: pointer; margin: 0 auto;
  background: radial-gradient(circle at 35% 30%, #fb7185, #be123c 60%, #7f1d1d); color: #fff;
  font-size: 1.8rem; font-weight: 900; text-transform: uppercase; letter-spacing: 0.08em;
  box-shadow: 0 10px 0 #5f0f1f, 0 14px 30px rgba(0, 0, 0, 0.5); transition: transform 0.06s, box-shadow 0.06s, filter 0.2s;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.buzzer:active:not(:disabled) { transform: translateY(8px); box-shadow: 0 2px 0 #5f0f1f, 0 4px 10px rgba(0, 0, 0, 0.5); }
.buzzer:disabled { filter: grayscale(0.85) brightness(0.6); cursor: not-allowed; }
.buzzer.pressed { filter: brightness(1.2); }
.answer-form { display: flex; gap: 0.5rem; max-width: 560px; margin: 0 auto; width: 100%; }
.host-panel { display: grid; gap: 0.6rem; }
.host-answer { background: rgba(52, 211, 153, 0.08); border: 1px dashed rgba(52, 211, 153, 0.4); border-radius: 8px; padding: 0.6rem; text-align: left; }
.host-answer b { color: var(--ok); }

.players { display: grid; gap: 0.4rem; }
.player { display: flex; align-items: center; gap: 0.55rem; padding: 0.45rem 0.6rem; border-radius: 8px; background: var(--surface-3); border: 1px solid transparent; }
.player.me { border-color: rgba(245, 158, 11, 0.5); }
.player.picker { box-shadow: inset 3px 0 0 var(--gold); }
.player.answering { border-color: var(--info); }
.player.offline { opacity: 0.45; }
.player .pname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.player .pscore { font-weight: 900; color: var(--gold); font-variant-numeric: tabular-nums; }
.player .pscore.neg { color: var(--bad); }
.player .ptools { display: flex; gap: 0.2rem; }
.player .ptools button { background: rgba(255, 255, 255, 0.07); border: 1px solid var(--border); color: var(--text); border-radius: 5px; cursor: pointer; font-size: 0.75rem; padding: 0.05rem 0.35rem; }

.volume-panel { display: grid; gap: 0.4rem; font-size: 0.85rem; }
.volume-panel label { display: grid; grid-template-columns: 80px 1fr 38px; gap: 0.5rem; align-items: center; }
.lobby { text-align: center; display: grid; gap: 1rem; padding: 2rem 1rem; background: var(--surface); border-radius: var(--radius); border: 1px solid var(--border); }
.big-code { font-size: 3rem; font-weight: 900; letter-spacing: 0.3em; color: var(--gold); }
.podium { display: grid; gap: 0.5rem; max-width: 480px; margin: 0 auto; width: 100%; }
.podium .player { font-size: 1.1rem; }
.toast {
  position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); background: var(--surface-3); border: 1px solid var(--border);
  padding: 0.6rem 1rem; border-radius: 8px; z-index: 100; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
body.spectator .game-layout { grid-template-columns: minmax(0, 1fr) 260px; }

/* ---------- error pages */
.error-page { text-align: center; }
.error-code { font-size: 4.5rem; font-weight: 900; color: var(--gold); line-height: 1; margin-bottom: 0.5rem; letter-spacing: 0.05em; }
