:root {
  --bg: #0f1419;
  --panel: #1a2332;
  --text: #e8eef7;
  --muted: #9aabbf;
  --yes: #1f8a4c;
  --no: #b33a3a;
  --accent: #3d7ea6;
  --line: #2a3a4f;
  font-family: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(1200px 600px at 20% -10%, #243247, var(--bg));
  color: var(--text);
}
h1, h2 { margin: 0 0 0.6rem; font-weight: 650; }
.meta { color: var(--muted); margin: 0.2rem 0; font-size: 0.95rem; }
.panel {
  background: color-mix(in srgb, var(--panel) 92%, black);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem;
  margin: 0.75rem 0;
}
.player-shell {
  max-width: 520px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}
label { display: grid; gap: 0.35rem; margin-bottom: 0.75rem; }
input, select {
  background: #0c121a;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  font: inherit;
}
.btn {
  border: 0;
  border-radius: 10px;
  padding: 0.7rem 1rem;
  font: inherit;
  font-weight: 650;
  cursor: pointer;
  background: #2b3b51;
  color: var(--text);
}
.btn.danger {
  background: #7a3030;
}
.btn.danger:hover { filter: brightness(1.08); }
.btn.tiny {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  border-radius: 6px;
}
.archive-list {
  display: grid;
  gap: 0.45rem;
}
.archive-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  align-items: center;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0c121a;
}
.archive-row.active {
  border-color: var(--accent);
}
.archive-actions { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.rank-edit {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.35rem;
  align-items: center;
}
.rank-edit select,
.rank-edit input {
  font-size: 0.8rem;
  padding: 0.25rem 0.4rem;
  max-width: 7rem;
}
.player-tile-head .tile-actions {
  display: flex;
  gap: 0.35rem;
  align-items: center;
}
.round-toolbar { margin-bottom: 0.5rem; }
.btn.yes { background: var(--yes); font-size: 1.4rem; min-height: 4.5rem; flex: 1; }
.btn.no { background: var(--no); font-size: 1.4rem; min-height: 4.5rem; flex: 1; }
.btn.yes.flash-yes, .btn.no.flash-no {
  animation: buzz-pulse 0.45s ease-out;
  transform: scale(1.06);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.35);
}
@keyframes buzz-pulse {
  0% { transform: scale(1); filter: brightness(1); }
  40% { transform: scale(1.08); filter: brightness(1.25); }
  100% { transform: scale(1); filter: brightness(1); }
}
.buzz-feedback {
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.15s ease, transform 0.15s ease;
  font-weight: 750;
  font-size: 1.15rem;
  min-height: 1.4rem;
  margin: 0.4rem 0 0.2rem;
}
.buzz-feedback.show { opacity: 1; transform: translateY(0); }
.buzz-feedback.yes { color: #5ddea0; }
.buzz-feedback.no { color: #f08a8a; }
.conn-status {
  margin: 0.35rem 0 0.15rem;
  padding: 0.4rem 0.65rem;
  border-radius: 8px;
  font-weight: 650;
  font-size: 0.9rem;
  border: 1px solid var(--line);
}
.conn-status.ok {
  background: rgba(31, 138, 76, 0.18);
  color: #9be7bc;
}
.conn-status.warn {
  background: rgba(196, 163, 90, 0.2);
  color: #ffd39a;
}
.conn-status.bad {
  background: rgba(179, 58, 58, 0.22);
  color: #f08a8a;
}
.player-page.is-offline .buzzer-row .btn,
.player-page.is-offline #draw-panel {
  opacity: 0.45;
  pointer-events: none;
}
.buzzer-row { display: flex; gap: 0.75rem; }
.draw-wrap canvas {
  width: 100%;
  max-width: 100%;
  background: #fff;
  border-radius: 8px;
  touch-action: none;
}
.draw-tools { display: flex; gap: 0.5rem; margin-top: 0.5rem; align-items: center; }
.host-header { padding: 1rem 1.25rem 0; }
.host-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 0.75rem;
  padding: 0.75rem 1.25rem 2rem;
}
.panel-wide { grid-column: 1 / -1; }
.player-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.75rem;
}
.player-tile {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0c121a;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.player-tile-head {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: baseline;
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 80%, black);
}
.player-tile-head strong { font-size: 0.95rem; }
.player-tile-meta { color: var(--muted); font-size: 0.75rem; }
.player-stage-wrap {
  position: relative;
  aspect-ratio: 16 / 10;
  background:
    linear-gradient(90deg, rgba(61, 126, 166, 0.1) 1px, transparent 1px),
    linear-gradient(rgba(61, 126, 166, 0.1) 1px, transparent 1px),
    #141c26;
  background-size: 32px 32px, 32px 32px, auto;
}
.player-stage-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
}
.player-stage-hint {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  pointer-events: none;
  text-align: center;
  padding: 0.5rem;
}
.player-stage-hint.is-hidden { display: none; }
.player-tile-foot {
  padding: 0.45rem 0.7rem;
  border-top: 1px solid var(--line);
  font-size: 0.8rem;
  color: var(--muted);
  min-height: 1.8rem;
}
.player-tile-foot .btn-chip {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-weight: 650;
  color: #fff;
}
.player-tile-foot .btn-chip.yes { background: var(--yes); }
.player-tile-foot .btn-chip.no { background: var(--no); }
.player-tile.tile-flash {
  animation: tile-buzz 0.5s ease-out;
}
@keyframes tile-buzz {
  0% { box-shadow: 0 0 0 0 rgba(61, 126, 166, 0.0); }
  30% { box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.45); }
  100% { box-shadow: 0 0 0 0 rgba(61, 126, 166, 0.0); }
}
.stage-wrap {
  position: relative;
  margin-top: 0.5rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(61, 126, 166, 0.08) 1px, transparent 1px),
    linear-gradient(rgba(61, 126, 166, 0.08) 1px, transparent 1px),
    #101820;
  background-size: 48px 48px, 48px 48px, auto;
  aspect-ratio: 16 / 9;
}
#replay-canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: transparent;
}
.stage-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  pointer-events: none;
  text-align: center;
  padding: 1rem;
}
.stage-empty.is-hidden { display: none; }
.category-form-inline {
  grid-template-columns: 1fr auto auto;
  align-items: end;
}
@media (max-width: 700px) {
  .category-form-inline { grid-template-columns: 1fr; }
}
.category-actions {
  list-style: none;
  margin: 0.75rem 0;
  padding: 0;
  display: grid;
  gap: 0.5rem;
}
.category-actions li {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  background: #0c121a;
}
.score-board, .bar-board, .category-boards {
  margin-top: 0.5rem;
}
.round-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: start;
  margin-bottom: 0.75rem;
}
.round-question {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
}
.round-timer {
  min-width: 4.5rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-size: 1.6rem;
  font-weight: 800;
  padding: 0.35rem 0.7rem;
  border-radius: 10px;
  background: #243247;
  border: 1px solid var(--line);
}
.round-timer.warn { background: #5a3a1f; color: #ffd39a; }
.round-timer.done { background: #1f3a2c; color: #9be7bc; }
.rank-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.45rem;
}
.rank-row {
  display: grid;
  grid-template-columns: 2.2rem 1fr auto;
  gap: 0.6rem;
  align-items: center;
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  background: #0c121a;
  border: 1px solid var(--line);
}
.rank-row.is-correct { border-color: color-mix(in srgb, var(--yes) 55%, var(--line)); }
.rank-row.is-wrong { border-color: color-mix(in srgb, var(--no) 45%, var(--line)); opacity: 0.85; }
.rank-row.podium-1 { background: linear-gradient(90deg, rgba(196,163,90,0.22), #0c121a 55%); }
.rank-row.podium-2 { background: linear-gradient(90deg, rgba(158,170,186,0.18), #0c121a 55%); }
.rank-row.podium-3 { background: linear-gradient(90deg, rgba(176,112,74,0.18), #0c121a 55%); }
.rank-pos {
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-weight: 800;
  background: #243247;
}
.rank-name { font-weight: 650; }
.rank-meta { color: var(--muted); font-size: 0.8rem; margin-top: 0.15rem; }
.rank-points {
  font-size: 1.25rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.rank-points.zero { color: var(--muted); font-weight: 600; }
.score-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
@media (max-width: 900px) {
  .score-split { grid-template-columns: 1fr; }
}
.score-split h3 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}
.bar-row {
  display: grid;
  grid-template-columns: minmax(5rem, 28%) 1fr auto;
  gap: 0.55rem;
  align-items: center;
  margin: 0.4rem 0;
}
.bar-track {
  height: 1.15rem;
  border-radius: 999px;
  background: #1a2433;
  border: 1px solid var(--line);
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #5ddea0);
  transition: width 0.45s ease;
}
.bar-value {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  min-width: 2.5rem;
  text-align: right;
}
.category-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  margin-bottom: 0.65rem;
  background: #0c121a;
}
.category-card h4 {
  margin: 0 0 0.4rem;
  font-size: 0.95rem;
}
.row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin: 0.5rem 0; }
.stack { display: grid; gap: 0.45rem; }
.log, .log-list {
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
  max-height: 220px;
  overflow: auto;
  background: #0c121a;
  border-radius: 8px;
  padding: 0.5rem;
}
.log-list { list-style: none; margin: 0; }
.dot {
  width: 0.55rem; height: 0.55rem; border-radius: 50%;
  display: inline-block; margin-right: 0.35rem;
  vertical-align: middle;
}
.dot.on { background: #3dcc7a; }
.dot.off { background: #6a7688; }
