:root {
  color-scheme: dark;
  /* palette lifted from the box art */
  --bg: #080a18;
  --panel: #10142c;
  --line: #243066;
  --gold: #f8b818;
  --orange: #ee6a1a;
  --red: #d8281c;
  --text: #d6d9ee;
  --muted: #8a90b8;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font: 14px/1.5 ui-monospace, monospace; }
body {
  /* arena glow behind the page, like the lights in the box art */
  background:
    radial-gradient(ellipse 60% 40% at 25% 0%, #1b2a6a66, transparent),
    radial-gradient(ellipse 50% 40% at 85% 100%, #ee6a1a22, transparent),
    var(--bg);
  background-attachment: fixed;
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

main {
  max-width: 1180px; margin: 0 auto; padding: 20px 16px 32px;
  display: grid; gap: 24px; align-items: start; justify-items: center;
  grid-template-columns: minmax(220px, 340px) minmax(0, 1fr);
}
.box { margin: 0; position: sticky; top: 20px; }
.box img {
  display: block; width: 100%; height: auto; border-radius: 4px;
  box-shadow: 0 0 0 1px #000, 0 18px 40px #000c, 0 0 60px #ee6a1a30;
  transform: rotate(-1.5deg);
}
.play { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 12px; }

canvas {
  width: 100%;
  max-width: calc((100vh - 230px) * 1.3333);
  min-width: min(100%, 320px);
  aspect-ratio: 4 / 3; /* 320x200 was shown on 4:3 CRTs: slightly tall pixels */
  image-rendering: pixelated;   /* nearest-neighbour scaling */
  image-rendering: crisp-edges;
  image-rendering: pixelated;
  background: #000; outline: none;
  border: 3px solid var(--line); border-radius: 4px;
  box-shadow: 0 0 0 1px #000, 0 12px 32px #000a;
}
canvas:focus-visible { border-color: var(--gold); }
.help { max-width: 60em; margin: 0; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 12px; }
.controls { border-collapse: separate; border-spacing: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; text-align: center; }
.controls th, .controls td { padding: 6px 18px; border-top: 1px solid var(--line); }
.controls thead th { border-top: 0; color: #fff; }
.controls thead th.home { background: rgba(248, 184, 24, .18); border-bottom: 2px solid var(--gold); }
.controls thead th.away { background: rgba(60, 190, 90, .18); border-bottom: 2px solid #3cbe5a; }
.controls small { display: block; font-weight: normal; color: var(--muted); }
.controls tbody th { text-align: left; color: var(--muted); font-weight: normal; }
.controls kbd + kbd { margin-left: 4px; }
.tips { list-style: none; margin: 0; padding: 0; text-align: center; display: flex; flex-direction: column; gap: 4px; }
.tips b { color: var(--text); margin-right: 4px; }
#status { margin: 0; min-height: 1.4em; color: var(--gold); }
.status-row { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: center; }
.sound-toggle {
  font: inherit; font-size: 12px; color: var(--muted); background: var(--panel);
  border: 1px solid var(--line); border-radius: 3px; padding: 2px 10px; cursor: pointer;
}
.sound-toggle[aria-pressed="true"] { color: var(--gold); border-color: var(--gold); }
.sound-toggle:hover, .sound-toggle:focus-visible { border-color: var(--gold); color: #fff; outline: none; }
kbd { background: var(--panel); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 3px; padding: 0 6px; color: #fff; }
.join {
  max-width: 60em; text-align: center; padding: 10px 16px;
  border: 1px solid var(--line); border-left: 4px solid var(--orange); border-radius: 4px; background: var(--panel);
}
.join a { color: var(--gold); font-weight: bold; white-space: nowrap; }
.join a:hover, .join a:focus-visible { color: #fff; }

/* Online play panel */
.online { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.online[hidden], .online [hidden] { display: none; }
.online-row { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; align-items: center; }
.online form { display: flex; gap: 8px; align-items: center; }
.online input {
  font: inherit; width: 8ch; text-transform: uppercase; letter-spacing: .15em; text-align: center;
  background: var(--panel); color: #fff; border: 1px solid var(--line); border-radius: 3px; padding: 4px 6px;
}
.online button {
  font: inherit; color: #fff; background: var(--panel); border: 1px solid var(--line); border-radius: 3px;
  padding: 4px 12px; cursor: pointer;
}
.online button:hover, .online button:focus-visible, .online input:focus-visible { border-color: var(--gold); outline: none; }
#online-status { margin: 0; min-height: 1.4em; color: var(--gold); text-align: center; max-width: 60em; }

/* Narrow screens: box art becomes a compact banner above the game. */
/* Title menu */
.menu { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; }
.menu button, .menu-back, .cpu-setup button {
  font: inherit; font-size: 1.1rem; letter-spacing: .1em; text-transform: uppercase;
  color: #fff; background: var(--panel); border: 3px solid var(--line); border-radius: 4px;
  padding: 10px 24px; cursor: pointer; box-shadow: 0 4px 0 #000;
}
.menu button:hover, .menu button:focus-visible, .menu-back:hover, .menu-back:focus-visible,
.cpu-setup button:hover, .cpu-setup button:focus-visible {
  border-color: var(--gold); color: var(--gold); outline: none;
}
.menu[hidden], .menu-back[hidden], .menu button[hidden] { display: none; }
.menu-back { font-size: 14px; padding: 4px 12px; box-shadow: none; letter-spacing: 0; text-transform: none; }

/* VS CPU setup */
.cpu-setup { display: flex; flex-wrap: wrap; gap: 12px 24px; justify-content: center; align-items: flex-end; }
.cpu-setup[hidden] { display: none; }
.cpu-setup fieldset { border: 0; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.cpu-setup legend { padding: 0 0 4px; color: var(--muted); }
.cpu-setup label {
  position: relative; cursor: pointer; padding: 6px 14px; color: #fff; background: var(--panel);
  border: 2px solid var(--line); border-radius: 4px; text-transform: uppercase; letter-spacing: .08em;
}
.cpu-setup label small { color: var(--muted); text-transform: none; letter-spacing: 0; }
.cpu-setup input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.cpu-setup label:hover { border-color: var(--muted); }
.cpu-setup label:has(input:checked) { border-color: var(--gold); color: var(--gold); }
.cpu-setup label.away:has(input:checked) { border-color: #3cbe5a; color: #3cbe5a; }
.cpu-setup label:has(input:focus-visible) { outline: 2px solid #fff; outline-offset: 2px; }

/* Lobby */
.lobby { width: 100%; max-width: 60em; display: flex; flex-direction: column; gap: 10px; }
.lobby[hidden], .lobby [hidden] { display: none; }
.lobby input, .lobby button {
  font: inherit; color: #fff; background: var(--panel); border: 1px solid var(--line); border-radius: 3px; padding: 4px 8px;
}
.lobby button { cursor: pointer; padding: 4px 12px; }
.lobby button:hover, .lobby button:focus-visible, .lobby input:focus-visible { border-color: var(--gold); outline: none; }
.lobby button:disabled { opacity: .45; cursor: default; border-color: var(--line); }
#nick-form[hidden], #roster[hidden], #chat-log[hidden], #chat-form[hidden], #lobby-state[hidden] { display: none; }
#nick-form { display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: wrap; }
#lobby-retry { display: block; margin: 0 auto; }
#lobby-retry[hidden] { display: none; }
#lobby-state { margin: 0; min-height: 1.4em; color: var(--gold); text-align: center; }
.lobby-grid { display: grid; grid-template-columns: minmax(180px, 1fr) minmax(0, 2fr); gap: 12px; }
#roster, #chat-log { list-style: none; margin: 0; padding: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; }
#roster { display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow-y: auto; }
.player { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; }
.player-name { color: #fff; font-weight: bold; unicode-bidi: plaintext; }
.player-info { color: var(--muted); font-size: 12px; flex: 1 1 100%; }
.player-unreachable .player-name { color: var(--muted); }
.player button { padding: 0 8px; font-size: 12px; }
.chat { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
#chat-log { height: 220px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
#chat-log li { display: block; }
.chat-name { display: block; font-size: 12px; color: var(--gold); unicode-bidi: plaintext; }
.chat-mine .chat-name { color: var(--orange); }
.chat-text { display: block; text-align: start; unicode-bidi: plaintext; overflow-wrap: anywhere; }
.chat-system { color: var(--muted); font-style: italic; }
#chat-form { display: flex; gap: 8px; }
#chat-input { flex: 1; min-width: 0; unicode-bidi: plaintext; }
.lobby-note { margin: 0; text-align: center; color: var(--muted); font-size: 12px; }

.challenge-box {
  display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap;
  padding: 8px 12px; border: 1px solid var(--gold); border-left: 4px solid var(--gold); border-radius: 4px; background: var(--panel);
}
.challenge-box p { margin: 0; color: #fff; }
.lobby .challenge-box[hidden] { display: none; }

@media (max-width: 760px) {
  .lobby-grid { grid-template-columns: 1fr; }
  main { grid-template-columns: 1fr; }
  .box { position: static; width: min(55vw, 240px); }
  canvas { max-width: 100%; }
}
