:root {
  color-scheme: dark;
  --ink: #f7f3ff;
  --muted: #bdb3dc;
  --bg: #0e0a1c;
  --panel: rgba(24, 15, 52, 0.7);
  --line: rgba(255, 255, 255, 0.14);
  --gold: #ffd36b;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--bg); }

.game-shell {
  display: grid;
  justify-items: center;
  gap: 1rem;
  min-height: 100vh;
  padding: 1.5rem 1rem 3rem;
  background: radial-gradient(circle at 50% -10%, #3c2574, var(--bg) 68%);
}

.masthead {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  width: min(960px, 100%);
}
.eyebrow { margin: 0; color: #d8aaff; font-size: 0.75rem; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; }
h1 {
  margin: 0.1rem 0 0;
  font-size: clamp(2rem, 5vw, 3.2rem);
  font-style: italic;
  font-weight: 900;
  letter-spacing: -0.02em;
  text-shadow: 0 3px 0 #7b3fd1, 0 6px 0 #3c1d74, 0 10px 18px rgba(0, 0, 0, 0.45);
}
.toolbar { display: flex; align-items: center; gap: 0.75rem; color: var(--muted); font-size: 0.85rem; font-weight: 700; }

button {
  border: 0;
  border-radius: 0.6rem;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
}
button:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
.toggle-button { padding: 0.45rem 0.8rem; background: rgba(255, 255, 255, 0.1); color: var(--ink); border: 1px solid var(--line); }
.toggle-button[aria-pressed="false"] { color: var(--muted); text-decoration: line-through; }

kbd {
  display: inline-block;
  min-width: 1.5em;
  padding: 0.05em 0.35em;
  border: 1px solid #8876ac;
  border-bottom-width: 3px;
  border-radius: 0.3em;
  background: #292043;
  color: #fff;
  font: 800 0.8em/1.4 inherit;
  text-align: center;
}

/* ---------- Arena and overlays ---------- */

.stage-frame {
  position: relative;
  width: min(960px, 100%);
  container-type: inline-size;
}
#game {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  border: 3px solid rgba(216, 170, 255, 0.35);
  border-radius: 1rem;
  background: #120c33;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.5);
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: safe center;
  gap: 0.9cqw;
  padding: 1.6cqw;
  overflow: auto;
  border-radius: 1rem;
  background: linear-gradient(rgba(12, 7, 30, 0.55), rgba(12, 7, 30, 0.82));
  backdrop-filter: blur(2px);
  font-size: clamp(8px, 1.5cqw, 14.5px);
}
.overlay[hidden] { display: none; }

.logo {
  margin: 0;
  font-size: 4.1em;
  font-style: italic;
  font-weight: 900;
  line-height: 0.95;
  letter-spacing: -0.03em;
  text-transform: uppercase;
  background: linear-gradient(#fffbe0 10%, #ffbf3a 55%, #ff5d3a 95%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0.06em 0 #6b1d9e) drop-shadow(0 0.06em 0 #35105a) drop-shadow(0 0.15em 0.2em rgba(0, 0, 0, 0.55));
}
.logo span { background: linear-gradient(#e6fbff 10%, #4cc2ff 60%, #7b3fd1 100%); -webkit-background-clip: text; background-clip: text; }
.logo.small { font-size: 4em; }
.note { margin: 0; color: var(--muted); font-size: 1.05em; font-weight: 700; text-align: center; }

.slots { display: grid; grid-template-columns: repeat(4, 13.5em); gap: 1em; }
.seat { position: relative; display: grid; }
.char-arrow {
  position: absolute;
  top: 3.4em;
  z-index: 1;
  width: 1.9em;
  height: 2.6em;
  padding: 0;
  border: 0.12em solid var(--c);
  border-radius: 0.5em;
  background: rgba(12, 7, 28, 0.8);
  color: var(--c);
  font-size: 1em;
}
.char-arrow:hover { background: var(--c); color: #160c2c; }
.char-arrow.prev { left: -0.5em; }
.char-arrow.next { right: -0.5em; }
.char-arrow[hidden] { display: none; }
.slot-card {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 0.25em;
  padding: 0.7em 0.6em 0.6em;
  border: 0.22em solid var(--c);
  border-radius: 1em;
  background: radial-gradient(circle at 50% 30%, color-mix(in srgb, var(--c) 35%, transparent), rgba(20, 12, 44, 0.92) 70%);
  color: var(--ink);
  text-align: center;
  font-size: 1em;
  transition: transform 0.12s ease, opacity 0.12s ease;
}
.slot-card:hover { transform: translateY(-0.2em); }
.slot-card canvas { width: 6em; height: 6em; }
.slot-card strong { font-size: 1.35em; font-style: italic; font-weight: 900; text-transform: uppercase; color: var(--c); }
.slot-tag {
  position: absolute;
  top: 0.5em;
  left: 0.6em;
  padding: 0.05em 0.45em;
  border-radius: 0.4em;
  background: var(--c);
  color: #160c2c;
  font-weight: 900;
  font-style: italic;
}
.slot-blurb { color: var(--muted); font-size: 0.85em; font-weight: 700; }
.slot-type {
  margin-top: 0.2em;
  padding: 0.15em 0.8em;
  border-radius: 999px;
  background: var(--c);
  color: #160c2c;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.slot-card.is-cpu .slot-type { background: transparent; color: var(--c); box-shadow: inset 0 0 0 0.15em var(--c); }
.slot-keys { color: var(--muted); font-size: 0.85em; font-weight: 800; letter-spacing: 0.25em; line-height: 1.35; }
.slot-phone { display: none; color: var(--muted); font-size: 0.85em; font-weight: 800; line-height: 2.7; }
.slot-card.is-phone .slot-keys { display: none; }
.slot-card.is-phone .slot-phone { display: block; }
.slot-card.is-off { opacity: 0.4; filter: grayscale(0.85); }
.slot-card.in-team { box-shadow: 0 0 0 0.25em var(--team), 0 0 1.2em color-mix(in srgb, var(--team) 60%, transparent); }
.slot-wins { min-height: 1.2em; color: var(--gold); font-size: 0.85em; font-weight: 900; }
.teams { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.6em; }
.teams[hidden] { display: none; }
.team-pill { padding: 0.35em 0.9em; border: 0.15em solid var(--c); border-radius: 999px; background: color-mix(in srgb, var(--c) 25%, transparent); color: var(--ink); font-size: 0.95em; font-weight: 900; }
.team-pill:disabled { opacity: 0.35; }
.standings .award { color: var(--gold); font-style: italic; }
.standings .wins { color: var(--gold); }
.slot-card.is-off .slot-type { background: #4b4360; color: #d9d3ea; }

.rules { display: flex; flex-wrap: wrap; justify-content: center; gap: 1.6em; }
.rule { display: flex; align-items: center; gap: 0.5em; font-weight: 800; }
.rule-label { color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.9em; }
.rule output { min-width: 1.6em; font-size: 1.5em; font-style: italic; font-weight: 900; text-align: center; }
.step { width: 2em; height: 2em; background: rgba(255, 255, 255, 0.12); color: var(--ink); font-size: 1.05em; }
.segmented { display: flex; padding: 0.2em; border-radius: 0.7em; background: rgba(255, 255, 255, 0.08); }
.segmented button { padding: 0.35em 0.9em; background: transparent; color: var(--muted); font-size: 1em; }
.segmented button[aria-pressed="true"] { background: var(--gold); color: #24123a; }

.cta {
  display: inline-flex;
  align-items: center;
  gap: 0.6em;
  padding: 0.6em 1.6em;
  border-radius: 0.8em;
  background: linear-gradient(#ffe68a, #ffb340);
  color: #2a1240;
  font-size: 1.5em;
  font-style: italic;
  font-weight: 900;
  text-transform: uppercase;
  box-shadow: 0 0.2em 0 #b8611c, 0 0.5em 1.2em rgba(0, 0, 0, 0.4);
}
.cta:hover { filter: brightness(1.06); }
.cta:active { transform: translateY(0.1em); box-shadow: 0 0.1em 0 #b8611c; }
.cta:disabled { opacity: 0.45; cursor: not-allowed; filter: grayscale(0.6); }
.cta kbd { font-size: 0.5em; font-style: normal; }
.ghost { padding: 0.6em 1.2em; background: rgba(255, 255, 255, 0.1); color: var(--ink); border: 1px solid var(--line); font-size: 1.15em; }
.actions { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 1em; }

.winner {
  margin: 0;
  color: var(--c, #fff);
  font-size: 4.2em;
  font-style: italic;
  font-weight: 900;
  text-transform: uppercase;
  text-shadow: 0 0.06em 0 #2a0f4a, 0 0.12em 0 #140a26, 0 0.25em 0.4em rgba(0, 0, 0, 0.5);
}
.winner-quote { margin: -0.4em 0 0.2em; color: var(--muted); font-size: 1.15em; font-style: italic; font-weight: 700; }
.standings { border-collapse: collapse; min-width: 60%; font-size: 1.1em; }
.standings th { padding: 0.4em 0.8em; color: var(--muted); font-size: 0.75em; text-transform: uppercase; letter-spacing: 0.08em; text-align: left; }
.standings td { padding: 0.45em 0.8em; border-top: 1px solid var(--line); font-weight: 800; }
.standings .place { font-style: italic; font-weight: 900; color: var(--gold); }
.standings .who { display: flex; align-items: center; gap: 0.5em; color: var(--c); }
.standings .who small { color: var(--muted); font-weight: 700; }
.swatch { width: 0.8em; height: 0.8em; border-radius: 50%; background: var(--c); }

/* ---------- Phone join strip ---------- */

.phones {
  display: flex;
  align-items: center;
  gap: 1.2rem;
  width: min(960px, 100%);
  padding: 1rem 1.2rem;
  border: 1px solid var(--line);
  border-left: 4px solid var(--gold);
  border-radius: 0.8rem;
  background: var(--panel);
}
.qr { flex: none; width: 132px; height: 132px; padding: 0; border-radius: 0.5rem; overflow: hidden; background: #fff; }
.qr[hidden] { display: none; }
.qr svg { display: block; width: 100%; height: 100%; }
.phones-copy h2 { margin: 0 0 0.3rem; font-size: 1.25rem; font-style: italic; font-weight: 900; text-transform: uppercase; color: var(--gold); }
.phones-copy p { margin: 0 0 0.35rem; color: var(--muted); line-height: 1.5; }
.phone-url { color: var(--ink); font-weight: 800; word-break: break-all; }
.phone-status { color: var(--ink) !important; font-weight: 700; }

/* ---------- Controls ---------- */

.controls { display: grid; gap: 1rem; width: min(960px, 100%); }
.pads { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.8rem; }
.pad { padding: 0.8rem; border: 1px solid var(--line); border-top: 3px solid var(--c); border-radius: 0.8rem; background: var(--panel); }
.pad h3 { margin: 0 0 0.6rem; font-size: 1rem; font-style: italic; font-weight: 900; text-transform: uppercase; color: var(--c); }
.pad h3 span { padding: 0 0.35em; border-radius: 0.3em; background: var(--c); color: #160c2c; }
.keys { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.4rem; }
.key { display: grid; justify-items: center; gap: 0.15rem; }
.key kbd { width: 100%; padding: 0.3rem 0; font-size: 1rem; }
.key small { color: var(--muted); font-size: 0.7rem; font-weight: 700; }
.moves {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.4rem 1.2rem;
  margin: 0;
  padding: 0.9rem 1rem;
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.5;
  list-style: none;
}
.moves b { color: var(--ink); }

/* On small screens the menus sit under the arena instead of on top of it. */
@container (max-width: 600px) {
  .overlay {
    position: static;
    gap: 0.9rem;
    margin-top: 0.75rem;
    padding: 1rem;
    border: 1px solid var(--line);
    background: var(--panel);
    backdrop-filter: none;
    font-size: 11px;
  }
  .slots { grid-template-columns: repeat(2, minmax(0, 1fr)); width: 100%; }
  .logo { font-size: 3.4em; text-align: center; }
  .winner { font-size: 3em; text-align: center; }
  .standings { min-width: 0; width: 100%; font-size: 1em; }
  .standings th, .standings td { padding: 0.4em 0.35em; }
}

@media (max-width: 760px) {
  .phones { flex-direction: column; align-items: start; }
  .pads { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .moves { grid-template-columns: 1fr; }
  .masthead { flex-direction: column; align-items: start; }
}
@media (max-width: 420px) {
  .pads { grid-template-columns: 1fr; }
}

/* ---------- Full-screen play ---------- */

body.playing { overflow: hidden; background: #000; }
body.playing .game-shell { padding: 0; min-height: 100vh; background: #000; }
body.playing .masthead,
body.playing .phones,
body.playing .controls { display: none; }
body.playing .stage-frame {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  background: #000;
  container-type: normal;
}
body.playing #game {
  width: min(100vw, calc(100dvh * 16 / 9));
  height: auto;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
body.playing .overlay {
  inset: 50% auto auto 50%;
  width: min(100vw, calc(100dvh * 16 / 9));
  height: min(100dvh, calc(100vw * 9 / 16));
  transform: translate(-50%, -50%);
  border-radius: 0;
  font-size: clamp(10px, 1.5vmin, 22px);
}
.phone-lan { font-size: 0.92em; }

.phone-create { margin: 6px 0 0; color: var(--muted, #bdb3dc); font-size: 14px; line-height: 1.4; }
.room-code { margin: 4px 0 8px; color: var(--muted); font-size: 14px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em; }
.room-code b { margin-left: 8px; color: #fff; font-size: 30px; letter-spacing: 0.18em; font-style: italic; }

/* Phone visitors: the main page is the big screen, so point them to joining or to a laptop. */
.phone-visitor {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: max(20px, env(safe-area-inset-top)) 18px max(20px, env(safe-area-inset-bottom));
  background: radial-gradient(circle at 50% -10%, #3a1f6e, #0e0a1c 70%);
  overflow-y: auto;
}
.phone-visitor[hidden] { display: none; }
.phone-visitor-card { display: grid; gap: 14px; justify-items: center; max-width: 30rem; text-align: center; }
.phone-visitor-card p { margin: 0; color: var(--muted); font-size: 17px; font-weight: 700; line-height: 1.45; }
.phone-visitor-card .cta { text-decoration: none; display: inline-block; }
.phone-visitor-card .ghost { padding: 12px 18px; font-size: 16px; }
.phone-visitor-card .link { background: none; border: 0; color: var(--muted); text-decoration: underline; font-size: 14px; font-weight: 700; }
.site-foot { padding: 18px 0 28px; text-align: center; font-size: 13px; }
.site-foot a { color: var(--muted); }
