:root {
  --cyan: #ff6ec7;
  --magenta: #ff3b3b;
  --purple: #ffa3c5;
  --fast: #ffd166;
  --bg: #140a10;
  --bg-top: #3d0f2b;
  --bg-bottom: #0a0308;
  --panel: rgba(255, 255, 255, 0.04);
  --panel-border: rgba(255, 110, 199, 0.16);
  --text: #f7e8ee;
  --text-dim: #a67e8f;
  --mono: "SF Mono", ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1000px 700px at 18% -10%, rgba(var(--p1-rgb), 0.12), transparent 60%),
    radial-gradient(1000px 700px at 82% 115%, rgba(var(--p2-rgb), 0.1), transparent 60%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom)),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}

.scanlines {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    linear-gradient(rgba(255, 255, 255, 0.022) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.022) 1px, transparent 1px);
  background-size: 48px 48px, 48px 48px;
  mask-image: radial-gradient(ellipse at center, #000 30%, transparent 78%);
  -webkit-mask-image: radial-gradient(ellipse at center, #000 30%, transparent 78%);
}

.app {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: min(820px, 100%);
}

/* ── Top bar ─────────────────────────────── */

.topbar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 5px;
  color: var(--text);
}

.brand-mark {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: linear-gradient(135deg, var(--cyan), var(--purple));
  box-shadow: 0 0 12px rgba(var(--p1-rgb), 0.45);
}

.chip {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 2.5px;
  color: var(--text-dim);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 5px 12px;
  font-family: var(--mono);
}

/* ── Scoreboard ──────────────────────────── */

.scoreboard {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: stretch;
  width: fit-content;
  min-width: 340px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  backdrop-filter: blur(6px);
  border-radius: 14px;
  overflow: hidden;
}

.player {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 24px;
  min-width: 130px;
}

.player .name {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 3px;
  color: var(--text-dim);
}

.player .points {
  font-family: var(--mono);
  font-size: 34px;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.p1 .points { color: var(--cyan); text-shadow: 0 0 18px rgba(var(--p1-rgb), 0.35); }
.p2 .points { color: var(--magenta); text-shadow: 0 0 18px rgba(var(--p2-rgb), 0.35); }

.score-divider {
  display: flex;
  align-items: center;
  padding: 0 20px;
  border-left: 1px solid var(--panel-border);
  border-right: 1px solid var(--panel-border);
  color: var(--text-dim);
  font-weight: 700;
}

/* ── Canvas frame ────────────────────────── */

.canvas-wrap {
  position: relative;
  width: min(800px, 100%);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 4px;
  background:
    linear-gradient(var(--bg), var(--bg)) padding-box,
    linear-gradient(135deg, var(--cyan), var(--purple), var(--magenta)) border-box;
  box-shadow:
    0 24px 70px rgba(0, 0, 0, 0.55),
    0 0 60px rgba(255, 255, 255, 0.03);
}

.canvas-wrap canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 12px;
  background: var(--bg);
}

/* ── Options panels ──────────────────────── */

.game-options {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  display: grid;
  width: calc(100% - 24px);
  max-width: 320px;
}

.game-options > .panel.menu {
  grid-area: 1 / 1;
}

.game-options > .panel.hidden {
  visibility: hidden;
}

.winner-text {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--text);
  text-align: center;
  padding: 0 0 4px;
}

#menu-winner {
  align-self: center;
  justify-self: center;
  width: 100%;
}

#menu-winner.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

#menu-winner .label {
  text-align: center;
  color: rgba(var(--p1-rgb), 0.75);
}

.credits {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-top: 12px;
  margin-top: 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.credits-title {
  text-align: center;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 2px;
}

.credits-row {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  line-height: 1.6;
}

.credits-row .role {
  color: var(--text-dim);
}

.credits-row .who {
  color: var(--text);
  font-weight: 600;
}

.tracks-title {
  margin-top: 10px;
}

.track {
  display: flex;
  flex-direction: column;
  gap: 1px;
  text-align: center;
  font-family: var(--mono);
  font-size: 10px;
  line-height: 1.4;
  color: var(--text-dim);
  transition: color 0.15s ease;
}

.credits .track {
  margin-top: 3px;
}

.track:first-of-type {
  margin-top: 0;
}

.track .artist {
  font-size: 8px;
  letter-spacing: 0.5px;
  line-height: 1.3;
  opacity: 0.75;
}

.track.playing {
  color: var(--purple);
  text-shadow: 0 0 10px rgba(var(--p1-rgb), 0.4);
}

.track.playing::before {
  content: '\25B8 ';
}

.panel.menu {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-self: center;
  justify-self: center;
  width: 100%;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.055), rgba(255, 255, 255, 0.02)), rgba(6, 7, 13, 0.68);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 20px;
  backdrop-filter: blur(20px) saturate(1.3);
  -webkit-backdrop-filter: blur(20px) saturate(1.3);
  box-shadow:
    0 24px 60px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.menu-foot {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 2px;
}

.menu-foot button {
  flex: none;
  padding: 5px 14px;
  font-size: 11px;
}

.panel.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
}

.label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: var(--text-dim);
}

.segment {
  display: flex;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}

.segment button {
  flex: 1;
  background: transparent;
  color: var(--text-dim);
  border: none;
  border-radius: 7px;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.segment button:hover {
  color: var(--text);
}

.segment button:focus-visible {
  outline: 2px solid rgba(var(--p1-rgb), 0.6);
  outline-offset: 2px;
}

.segment button.active {
  background: linear-gradient(135deg, var(--cyan), var(--purple));
  color: #fff;
  box-shadow: 0 2px 10px rgba(var(--p1-rgb), 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

button.reset,
button.start,
button.music {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  padding: 8px 18px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 1px;
  transition: all 0.15s ease;
}

button.start {
  color: #fff;
  font-size: 13px;
  letter-spacing: 2px;
  text-transform: uppercase;
  padding: 10px;
  background: linear-gradient(135deg, var(--cyan), var(--purple));
  border: none;
  box-shadow: 0 4px 18px rgba(var(--p1-rgb), 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

button.reset:hover,
button.reset:focus-visible,
button.music:hover,
button.music:focus-visible,
button.start:focus-visible {
  outline: none;
  border-color: rgba(var(--p1-rgb), 0.5);
  color: var(--text);
}

button.start:hover {
  filter: brightness(1.12);
  transform: translateY(-1px);
  box-shadow: 0 6px 22px rgba(var(--p1-rgb), 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

button.start:active {
  transform: translateY(0);
  filter: brightness(0.98);
}

button.music.active {
  color: var(--purple);
  border-color: rgba(var(--p1-rgb), 0.4);
  background: rgba(var(--p1-rgb), 0.08);
  box-shadow: 0 0 10px rgba(var(--p1-rgb), 0.18);
}

button.reset:hover {
  border-color: rgba(var(--p2-rgb), 0.55);
  color: var(--magenta);
  box-shadow: 0 0 12px rgba(var(--p2-rgb), 0.2);
}

/* ── Theme switcher ──────────────────────── */

.theme-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 2px 1px;
}

.theme-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.15);
  outline: 2px solid transparent;
  outline-offset: 2px;
  padding: 0;
  cursor: pointer;
  transition: transform 0.15s ease, outline-color 0.15s ease, box-shadow 0.15s ease;
}

.theme-dot:hover {
  transform: scale(1.15);
}

.theme-dot:focus-visible {
  outline-color: rgba(var(--p1-rgb), 0.6);
}

.theme-dot.active {
  outline-color: var(--text);
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.35);
}

/* ── Footer hints ────────────────────────── */

.hints {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  justify-content: center;
  font-size: 12px;
  color: var(--text-dim);
}

.hint {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.hint.pu {
  margin-left: 6px;
  padding-left: 14px;
  border-left: 1px solid var(--panel-border);
}

.pu-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 5px;
}

.pu-icon svg {
  width: 12px;
  height: 12px;
  display: block;
}

.pu-icon.grow { color: var(--cyan); border: 1.5px solid var(--cyan); }
.pu-icon.shrink { color: var(--magenta); border: 1.5px solid var(--magenta); }
.pu-icon.fast { color: var(--fast); border: 1.5px solid var(--fast); }

kbd {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 3px 7px;
  min-width: 20px;
  text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}