:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  background: #101523;
  color: #edf2ff;
  font-synthesis: none;
  --gap: 20px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(ellipse at top, #1d2b45, #101523 60%);
}

/* Layout: left menu | stage | right menu (right only during a game). */
.layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: var(--gap);
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--gap);
}
body.in-game .layout {
  grid-template-columns: 280px minmax(0, 1fr) 290px;
  max-width: none;
  height: 100vh;
}
.sidebar { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
body.in-game .sidebar { overflow-y: auto; }
.stage { display: flex; justify-content: center; align-items: flex-start; min-width: 0; }
#lobby { width: 100%; }
.name-field { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.lobby-divider { margin: 22px 0 14px; padding-top: 18px; border-top: 1px solid #2b3a56; }

body:not(.in-game) .in-game-only { display: none !important; }
body.in-game #lobby { display: none; }

header p { margin: 0; }
h1 { margin: 6px 0 10px; font-size: 2.6rem; line-height: 1; letter-spacing: -0.05em; }
h1 .domain { margin-left: 2px; color: #55d9ff; font-size: 0.42em; letter-spacing: 0; }
h2 { margin: 0 0 12px; }
h3 { margin: 0 0 10px; }
p { color: #aab8d2; }
.tagline { font-size: 0.95rem; }
.eyebrow { color: #57d8ff; font-weight: 800; letter-spacing: 0.2em; font-size: 0.75rem; }
.panel { padding: 18px; background: #182135; border: 1px solid #2b3a56; border-radius: 16px; }
#status { margin: 0; color: #edf2ff; }
#status:empty { display: none; }

form { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 16px; }
input, button { min-height: 42px; border-radius: 9px; font: inherit; }
input { width: 180px; padding: 0 12px; color: #edf2ff; background: #101827; border: 1px solid #35445e; }
input[type="checkbox"] { width: auto; min-height: auto; accent-color: #42d4ff; }
input[type="range"] { width: min(240px, 100%); padding: 0; accent-color: #55d9ff; }
select { min-height: 42px; padding: 0 12px; color: #edf2ff; background: #101827; border: 1px solid #35445e; border-radius: 9px; font: inherit; }
output { color: #55d9ff; font-weight: 800; }
.form-hint { flex-basis: 100%; color: #aab8d2; }
button { padding: 0 16px; border: 0; color: #06121d; font-weight: 800; background: #55d9ff; cursor: pointer; }
button:hover { background: #8be6ff; }
button.secondary { color: #d7e1f4; background: #2b3a56; }
.hidden { display: none !important; }

/* Left menu: room details, actions, controls help. */
#room-panel h2 { margin-bottom: 2px; }
#room-panel p { margin: 0 0 12px; }
.game-status { color: #edf2ff; }
.game-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.game-actions button { flex: 1 1 auto; }
.bot-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 14px; padding-top: 14px; border-top: 1px solid #2b3a56; }
.bot-controls select { flex: 1; }
.controls-help dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0; font-size: 0.9rem; }
.controls-help dt { color: #edf2ff; font-weight: 700; }
.controls-help dd { margin: 0; color: #aab8d2; }

/* Stage: the board fills the available height without scrolling. */
#game { display: flex; flex-direction: column; align-items: center; gap: 10px; width: 100%; }
/* Leave room for the timer above the board so the page still fits without scrolling. */
#game:has(.match-timer:not(.hidden)) #arena {
  width: min(100%, calc(100vh - 2 * var(--gap) - 52px));
}
.time-input { width: 90px; text-align: center; font-variant-numeric: tabular-nums; }
.match-timer {
  padding: 6px 16px; border-radius: 999px;
  font-size: 1.25rem; font-weight: 800; font-variant-numeric: tabular-nums;
  color: #edf2ff; background: #182135; border: 1px solid #2b3a56;
}
.match-timer.urgent { color: #ffca62; border-color: #ffca62; }
.match-timer.closing {
  color: #fff; background: #8f1d33; border-color: #ff4058;
  animation: timer-alarm 1s ease-in-out infinite;
}
@keyframes timer-alarm {
  50% { box-shadow: 0 0 18px rgba(255, 64, 88, 0.7); }
}
@media (prefers-reduced-motion: reduce) {
  .match-timer.closing { animation: none; }
}
#arena {
  display: block;
  width: min(100%, calc(100vh - 2 * var(--gap)));
  height: auto;
  image-rendering: pixelated;
  border: 2px solid #374862;
  border-radius: 8px;
}

/* Right menu: players and spectators. */
/* Lobby: open rooms as cards with Join / Watch buttons. */
#rooms { display: grid; gap: 10px; margin: 0; padding: 0; color: #c9d5ea; list-style: none; }
.room-card { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 12px 14px; background: #141d2e; border: 1px solid #2b3a56; border-radius: 12px; }
.room-info { display: flex; flex-direction: column; gap: 3px; flex: 1 1 260px; min-width: 0; }
.room-info small { color: #8f9db5; }
.room-actions { display: flex; gap: 8px; }
.room-phase { margin-left: 6px; padding: 2px 8px; border-radius: 999px; font-size: 0.75rem; font-weight: 700; vertical-align: middle; }
.phase-lobby { color: #06121d; background: #9cf276; }
.phase-countdown { color: #06121d; background: #79d7ff; }
.phase-playing { color: #06121d; background: #ffca62; }
.phase-finished { color: #d7e1f4; background: #2b3a56; }
.room-empty { color: #8f9db5; }
#room-panel .room-stats { color: #8f9db5; font-size: 0.9rem; }
#players { display: grid; grid-template-columns: 1fr; gap: 8px; margin: 0; padding: 0; color: #c9d5ea; list-style: none; }
#players li { display: flex; align-items: center; gap: 10px; min-width: 0; padding: 6px 10px; background: #141d2e; border-radius: 10px; }
.player-info { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.player-info strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-info small { color: #8f9db5; }
#players li.out { color: #78869e; }
#players li.out .player-swatch { opacity: 0.35; }
.player-swatch { flex: none; width: 14px; height: 14px; border-radius: 50%; box-shadow: 0 0 0 2px #0f1626; }
.remove-bot { flex: none; width: 28px; min-height: 28px; padding: 0; font-size: 0.85em; }
.remove-bot:hover { color: #06121d; background: #ff738c; }
#spectator-heading { margin-top: 16px; }
#spectators { margin: 0; padding-left: 20px; color: #c9d5ea; }

/* Narrow screens: stack the menus around the board. */
@media (max-width: 1100px) {
  .layout,
  body.in-game .layout { grid-template-columns: minmax(0, 1fr); height: auto; }
  body.in-game .sidebar { overflow: visible; }
  #arena { width: min(100%, 80vh); }
}

@media (max-width: 600px) {
  :root { --gap: 12px; }
  .panel { padding: 14px; }
  form > input:not([type="checkbox"]) { flex: 1 1 140px; width: auto; }
}

/* Game-over modal with fireworks in the winner's color. */
#game-over {
  --winner-color: #8a99b8;
  width: 100%; max-width: 100%; height: 100%; max-height: 100%;
  margin: 0; padding: 16px; border: 0;
  display: none; place-items: center;
  color: #edf2ff; background: transparent;
}
#game-over[open] { display: grid; }
#game-over::backdrop { background: rgba(4, 9, 18, 0.72); backdrop-filter: blur(2px); }
#fireworks { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.game-over-card {
  position: relative; width: min(420px, 100%); padding: 32px 28px 26px;
  text-align: center; background: #182135;
  border: 2px solid var(--winner-color); border-radius: 20px;
  box-shadow: 0 0 60px color-mix(in srgb, var(--winner-color) 45%, transparent);
  animation: game-over-pop 420ms cubic-bezier(0.2, 1.4, 0.4, 1);
}
.game-over-card:focus { outline: none; }
.game-over-trophy { font-size: 3.6rem; line-height: 1; margin-bottom: 10px; }
#game-over h2 { margin: 6px 0 8px; font-size: 2.2rem; color: var(--winner-color); letter-spacing: -0.03em; }
#game-over p { margin: 0 0 8px; }
.game-over-time { font-size: 0.9rem; }
.game-over-actions { display: flex; justify-content: center; gap: 10px; margin-top: 18px; }
#game-over.draw h2 { color: #d7e1f4; }
@keyframes game-over-pop {
  from { opacity: 0; transform: scale(0.8) translateY(12px); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .game-over-card { animation: none; }
}
