:root {
  --bg: #17151f;
  --bg2: #241f33;
  --card: rgba(255, 255, 255, 0.05);
  --line: rgba(255, 255, 255, 0.1);
  --ink: #ece8f4;
  --muted: #a49db6;
  --lcd0: #9bbc0f;
  --lcd3: #0f380f;
  --accent: #9bbc0f;
  --body: #cdc9c2;
  --dw: min(94vw, 420px, calc((100svh - 70px) / 1.6));
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100svh;
  background: radial-gradient(1200px 700px at 50% 0%, var(--bg2), var(--bg)) fixed, var(--bg);
  color: var(--ink);
  font: 15px/1.5 Inter, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; }

.stage {
  display: grid;
  grid-template-columns: minmax(220px, 280px) auto minmax(240px, 300px);
  gap: 32px;
  justify-content: center;
  align-items: start;
  padding: 20px 16px 32px;
}

/* ---------------------------------------------------------------- side cards */
.side { display: flex; flex-direction: column; gap: 16px; padding-top: 12px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px 18px;
}
.card h2 {
  font: 10px/1.6 'Press Start 2P', monospace;
  letter-spacing: 0.04em;
  margin: 0 0 12px;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 8px;
}
.card p { margin: 0 0 10px; color: var(--muted); font-size: 14px; }
.card p b { color: var(--ink); }
.live {
  font: 600 10px Inter, sans-serif;
  color: #0f380f;
  background: var(--accent);
  border-radius: 99px;
  padding: 1px 7px 1px 16px;
  position: relative;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.live::before {
  content: '';
  position: absolute;
  left: 6px; top: 50%;
  width: 6px; height: 6px;
  margin-top: -3px;
  border-radius: 50%;
  background: #0f380f;
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.2; } }

.lb { list-style: none; margin: 0; padding: 0; font-variant-numeric: tabular-nums; }
.lb li {
  display: grid;
  grid-template-columns: 26px 1fr auto;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  animation: rise 0.4s ease-out;
}
.lb li:last-child { border-bottom: 0; }
.lb .rk { color: var(--muted); }
.lb .nm { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb .sc { font-weight: 800; }
.lb li:nth-child(1) .rk { color: #f2c94c; }
.lb li.me .nm { color: var(--accent); }
.lb .empty { display: block; color: var(--muted); border: 0; }
@keyframes rise { from { opacity: 0; transform: translateY(4px); } }

.qr { background: #e9f3c8; padding: 12px; border-radius: 10px; width: 100%; max-width: 200px; margin: 0 auto; }
.qr svg { display: block; width: 100%; height: auto; }
.qr svg rect[fill='#ffffff'] { fill: #e9f3c8; }
.url { text-align: center; font: 9px/1.6 'Press Start 2P', monospace; color: var(--ink) !important; margin: 10px 0 0 !important; word-break: break-all; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; margin: 0; }
.stats div { display: flex; flex-direction: column; }
.stats dt { color: var(--muted); font-size: 12px; }
.stats dd { margin: 0; font-weight: 800; font-size: 17px; font-variant-numeric: tabular-nums; }

.keys ul { list-style: none; margin: 0; padding: 0; color: var(--muted); font-size: 14px; }
.keys li { padding: 3px 0; }
kbd {
  display: inline-block;
  min-width: 22px;
  padding: 1px 6px;
  margin-right: 3px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  font: 600 12px Inter, sans-serif;
  text-align: center;
}

/* versus card */
.vs-room, .vs-board { display: none; }
body.in-room .vs-room { display: block; }
body.vs-live .vs-board { display: block; }
body.in-room .vs-idle { display: none; }
.room { font-size: 14px; }
.room b { font: 16px 'Press Start 2P', monospace; color: var(--accent); letter-spacing: 0.15em; margin-left: 6px; }
.hint { min-height: 1.5em; }
.vs-room a { color: var(--accent); font-size: 14px; }
.vs-board { margin-top: 14px; }
.opp-head { font: 11px 'Press Start 2P', monospace; text-align: center; margin-bottom: 8px; color: var(--ink); }
.opp-lcd {
  background: #5d5f6e;
  padding: 10px;
  border-radius: 10px;
  width: 64%;
  margin: 0 auto;
}
.opp-lcd canvas, .lcd-wrap canvas { display: block; width: 100%; height: auto; image-rendering: pixelated; }
.scoreline { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0 0; text-align: center; }
.scoreline dt { color: var(--muted); font-size: 12px; }
.scoreline dd { margin: 0; font-weight: 800; font-size: 18px; font-variant-numeric: tabular-nums; }
.scoreline dd.sub { font-weight: 400; font-size: 12px; color: var(--muted); }

/* ---------------------------------------------------------------- the handheld */
.device-wrap { display: flex; flex-direction: column; align-items: center; }
.device {
  --u: calc(var(--dw) / 100);
  font-size: var(--u);
  width: var(--dw);
  position: relative;
  padding: 0 7em 16em;
  border-radius: 4em 4em 20em 4em;
  background:
    radial-gradient(120% 60% at 30% 0%, rgba(255, 255, 255, 0.35), transparent 60%),
    linear-gradient(180deg, #d6d2cb, var(--body) 40%, #bfbab2);
  box-shadow:
    inset -0.8em -1em 2em rgba(0, 0, 0, 0.18),
    inset 0.6em 0.6em 1.4em rgba(255, 255, 255, 0.55),
    0 3em 7em rgba(0, 0, 0, 0.6),
    0 0.6em 0 #a9a49c;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.top-strip {
  height: 8em;
  margin: 0 -7em;
  padding: 0 9em;
  border-bottom: 0.35em solid rgba(0, 0, 0, 0.09);
  display: flex;
  align-items: center;
  color: #8f8a82;
  font: 700 2.3em Inter, sans-serif;
  letter-spacing: 0.08em;
}
.bezel {
  position: relative;
  margin-top: 5em;
  padding: 3em 9em 6em;
  border-radius: 3em 3em 12em 3em;
  background: linear-gradient(180deg, #686a79, #585a68);
  box-shadow: inset 0 0.4em 1em rgba(0, 0, 0, 0.35);
}
.bezel-lines {
  display: flex;
  align-items: center;
  gap: 2em;
  margin: 0 -5em 3em;
  color: #c5c7d6;
  font: 600 2.1em Inter, sans-serif;
  letter-spacing: 0.06em;
  white-space: nowrap;
}
.bezel-lines::before, .bezel-lines::after {
  content: '';
  flex: 1;
  height: 1.6em;
  background: linear-gradient(#8b1f45 0 30%, transparent 30% 70%, #2d3474 70%);
}
.led-wrap {
  position: absolute;
  left: 1.6em;
  top: 34%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.2em;
  color: #c5c7d6;
  font: 600 1.6em Inter, sans-serif;
  letter-spacing: 0.05em;
}
.led { width: 1.8em; height: 1.8em; border-radius: 50%; background: #3b1b20; box-shadow: inset 0 0 0.3em #000; transition: all 0.3s; }
body.on .led { background: #ff2a3c; box-shadow: 0 0 1em #ff2a3c, 0 0 2.4em rgba(255, 42, 60, 0.6); }
.led-wrap span { font-size: 1em; }
.lcd-wrap {
  position: relative;
  background: var(--lcd0);
  box-shadow: inset 0 0 0.8em rgba(0, 0, 0, 0.5);
  padding: 0;
  border-radius: 0.6em;
  overflow: hidden;
}
.lcd-wrap canvas { filter: brightness(0.7) saturate(0.4); transition: filter 0.6s; }
body.on .lcd-wrap canvas { filter: none; }
/* faint dot-matrix grid + glass sheen */
.lcd-wrap::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.1), transparent 40%),
    repeating-linear-gradient(0deg, rgba(15, 56, 15, 0.07) 0 1px, transparent 1px calc(100% / 144)),
    repeating-linear-gradient(90deg, rgba(15, 56, 15, 0.07) 0 1px, transparent 1px calc(100% / 160));
}
.brand {
  margin: 3.5em 0 0 1em;
  color: #2c3190;
  line-height: 1;
}
.brand b { font: italic 800 6.4em Inter, sans-serif; letter-spacing: -0.02em; }
.brand em { font: italic 400 6.4em Georgia, serif; margin-left: 0.15em; }

.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 9em;
}
.dpad { position: relative; width: 31em; height: 31em; }
.dpad button {
  position: absolute;
  border: 0;
  padding: 0;
  background: #26252d;
  cursor: pointer;
  touch-action: none;
  box-shadow: 0 0.6em 0 #121116;
}
.dpad .up, .dpad .down { left: 10.5em; width: 10em; height: 11.5em; }
.dpad .left, .dpad .right { top: 10.5em; width: 11.5em; height: 10em; }
.dpad .up { top: 0; border-radius: 1.2em 1.2em 0 0; }
.dpad .down { bottom: 0; border-radius: 0 0 1.2em 1.2em; }
.dpad .left { left: 0; border-radius: 1.2em 0 0 1.2em; }
.dpad .right { right: 0; border-radius: 0 1.2em 1.2em 0; }
.dpad .hub {
  position: absolute;
  left: 10.5em; top: 10.5em;
  width: 10em; height: 10em;
  background: #26252d;
  pointer-events: none;
}
.dpad .hub::after {
  content: '';
  position: absolute;
  inset: 2.5em;
  border-radius: 50%;
  background: radial-gradient(circle, #1a1920, #2d2c35);
}
.dpad button.pressed, .dpad button:active { background: #1b1a20; }
.dpad button.pressed { box-shadow: 0 0.2em 0 #121116; transform: translateY(0.4em); }

.ab { display: flex; gap: 4em; transform: rotate(-25deg); margin-right: 1em; }
.ab .a { transform: translateY(-5em); }
.btn-col, .pill-col { display: flex; flex-direction: column; align-items: center; gap: 1.6em; }
.btn-col button {
  width: 14em; height: 14em;
  border-radius: 50%;
  border: 0;
  background: radial-gradient(circle at 35% 30%, #c2376f, #9b2257 60%, #7c1844);
  box-shadow: 0 0.8em 0 #5e1233, 0 1.2em 1.6em rgba(0, 0, 0, 0.35);
  cursor: pointer;
  touch-action: none;
}
.btn-col button.pressed { transform: translateY(0.6em); box-shadow: 0 0.2em 0 #5e1233; }
.btn-col label, .pill-col label {
  color: #2c3190;
  font: 800 3em Inter, sans-serif;
  letter-spacing: 0.08em;
}
.pills { display: flex; justify-content: center; gap: 4em; margin-top: 10em; padding-right: 8em; }
.pill-col { transform: rotate(-25deg); }
.pill-col button {
  width: 13em; height: 3.6em;
  border-radius: 2em;
  border: 0;
  background: #8e8b95;
  box-shadow: inset 0 -0.4em 0 #6f6c76, 0 0.4em 0 #a8a49d;
  cursor: pointer;
  touch-action: none;
}
.pill-col button.pressed { background: #75727c; }
.pill-col label { font-size: 2.2em; }
.speaker {
  position: absolute;
  right: 9em;
  bottom: 10em;
  display: flex;
  gap: 2.4em;
  transform: rotate(-25deg);
}
.speaker i {
  width: 1.6em;
  height: 15em;
  border-radius: 1em;
  background: #8c877f;
  box-shadow: inset 0.3em 0.4em 0.5em rgba(0, 0, 0, 0.4);
}

.under {
  margin-top: 18px;
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  font-size: 13px;
  color: var(--muted);
}
.net::before { content: '●'; margin-right: 6px; color: #e2595b; }
.net.on::before { color: var(--accent); }
.mute {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 99px;
  padding: 4px 12px;
  cursor: pointer;
  font-size: 13px;
}
.mute:hover { border-color: var(--accent); }

/* ---------------------------------------------------------------- narrow screens */
@media (max-width: 1100px) {
  .stage { grid-template-columns: 1fr; justify-items: center; gap: 20px; padding-top: 12px; }
  .device-wrap { order: -1; }
  .side { width: min(100%, 460px); padding-top: 0; }
  .side.right { order: 0; }
  .side.left { order: 1; }
  :root { --dw: min(calc(100vw - 24px), 440px, calc((100svh - 40px) / 1.52)); }
}
@media (pointer: coarse) {
  .join, .keys { display: none; }
}

/* hidden input that brings up the phone keyboard for name / room code */
.kb { position: absolute; left: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; font-size: 16px; border: 0; padding: 0; }
.touch-hint { display: none; width: 100%; text-align: center; color: var(--ink); }
@media (pointer: coarse) { .touch-hint { display: block; } }
