:root {
  --bg: #1f2120;
  --violet: #7c47f5;
  --cyan: #27d6c1;
  --yellow: #facc15;
  --pink: #fb7185;
  --lime: #a3e635;
  --orange: #fb923c;
  --text: #fbf3e4;
  --muted: #b4bccb;
  --font: ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ---------- HUD ---------- */

.hud {
  position: fixed;
  z-index: 2;
  top: 8px;
  left: 10px;
  right: 10px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  pointer-events: none;
  font-size: clamp(14px, 1.2vmin + 10px, 20px);
}

.hud-side {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  height: 38px;
  padding: 0 0.8em;
  border-radius: 999px;
  background: rgb(31 33 32 / 0.72);
  border: 2px solid rgb(255 255 255 / 0.1);
  font-weight: 800;
  white-space: nowrap;
}

.pill .label {
  font-size: 0.66em;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.pill strong {
  font-variant-numeric: tabular-nums;
}

.mode-1p .duo,
.mode-2p .solo {
  display: none;
}

.player.p1 {
  border-color: rgb(163 230 53 / 0.55);
}

.player.p2 {
  border-color: rgb(251 113 133 / 0.55);
}

.player .label {
  color: var(--text);
}

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid #1f2120;
  box-shadow: 0 0 0 2px currentColor;
}

.p1 .swatch {
  color: var(--lime);
  background: var(--lime);
}

.p2 .swatch {
  color: var(--pink);
  background: radial-gradient(circle at 35% 35%, #fff 0 18%, var(--pink) 20%);
}

.pips {
  display: inline-flex;
  gap: 4px;
}

.pips i {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid rgb(255 255 255 / 0.55);
}

.p1 .pips i.on {
  background: var(--lime);
  border-color: var(--lime);
}

.p2 .pips i.on {
  background: var(--pink);
  border-color: var(--pink);
}

.icon-btn {
  display: none;
  pointer-events: auto;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 2px solid rgb(255 255 255 / 0.14);
  border-radius: 999px;
  background: rgb(31 33 32 / 0.72);
  color: var(--text);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.is-playing .icon-btn {
  display: inline-flex;
}

.icon-btn .bar {
  width: 5px;
  height: 16px;
  border-radius: 3px;
  background: currentColor;
}

.icon-btn:focus-visible,
.btn:focus-visible {
  outline: 3px solid var(--cyan);
  outline-offset: 3px;
}

/* ---------- Overlays ---------- */

.overlay {
  position: fixed;
  z-index: 5;
  inset: 0;
  display: flex;
  overflow-y: auto;
  padding: 16px;
  background: radial-gradient(ellipse at 50% 35%, rgb(124 58 237 / 0.3), transparent 65%), rgb(31 33 32 / 0.8);
  touch-action: manipulation;
}

.panel {
  margin: auto;
  width: 100%;
  max-width: 580px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(8px, 2.2vmin, 16px);
  text-align: center;
}

.overlay h1,
.overlay h2 {
  margin: 0;
  font-size: clamp(32px, 8vmin, 64px);
  font-weight: 900;
  line-height: 1.05;
  color: var(--lime);
  text-shadow: 0 4px 0 #2e1065, 0 8px 24px rgb(0 0 0 / 0.45);
}

.overlay h2 {
  font-size: clamp(28px, 6.5vmin, 54px);
}

.overlay p {
  margin: 0;
  color: var(--muted);
  line-height: 1.35;
}

.goal {
  max-width: 30em;
  font-size: clamp(15px, 1.2vmin + 11px, 19px);
  color: var(--text) !important;
}

.modes {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}

.controls {
  margin: 0;
  padding: 10px 16px;
  list-style: none;
  border-radius: 18px;
  background: rgb(255 255 255 / 0.06);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
}

.controls b {
  color: var(--yellow);
}

.tag {
  display: inline-block;
  padding: 0 8px;
  border-radius: 999px;
  font-weight: 800;
  color: #10140a;
}

.tag.p1 {
  background: var(--lime);
}

.tag.p2 {
  background: var(--pink);
  color: #2a0710;
}

.note {
  max-width: 26em;
  padding: 6px 12px;
  border-radius: 12px;
  background: rgb(251 113 133 / 0.14);
  color: #fecdd3 !important;
  font-size: 14px;
}

.reason {
  font-size: clamp(15px, 1vmin + 12px, 19px);
  color: var(--text) !important;
}

.result {
  font-size: clamp(20px, 2vmin + 14px, 30px);
  color: var(--text) !important;
}

.result strong {
  color: var(--yellow);
  font-size: 1.3em;
}

.best strong {
  color: var(--text);
}

.stats {
  font-size: 15px;
}

.board-score {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 4vmin, 28px);
  padding: 10px 18px;
  border-radius: 20px;
  background: rgb(255 255 255 / 0.06);
}

.board-score .side {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 84px;
  font-weight: 800;
}

.board-score .num {
  font-size: clamp(30px, 6vmin, 48px);
  font-weight: 900;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.board-score .p1 .num {
  color: var(--lime);
}

.board-score .p2 .num {
  color: var(--pink);
}

.board-score .dash {
  font-size: 28px;
  color: var(--muted);
}

.board-score .name {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
}

.hidden {
  display: none !important;
}

.btn {
  min-width: 160px;
  min-height: 54px;
  padding: 12px 28px;
  border: 0;
  border-radius: 999px;
  background: #ee5e24;
  color: #15130f;
  font: inherit;
  font-size: 21px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 6px 0 #b8400f;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.btn:hover {
  background: #d93d12;
}

.btn:active {
  transform: translateY(3px);
  box-shadow: 0 3px 0 #b8400f;
}

.btn-alt {
  background: #db2777;
  box-shadow: 0 6px 0 #831843;
}

.btn-alt:hover {
  background: #ec4899;
}

.btn-alt:active {
  box-shadow: 0 3px 0 #831843;
}

.btn-ghost {
  min-width: 120px;
  background: rgb(255 255 255 / 0.1);
  box-shadow: 0 6px 0 rgb(0 0 0 / 0.35);
}

.btn-ghost:hover {
  background: rgb(255 255 255 / 0.18);
}

.btn:disabled {
  cursor: not-allowed;
  background: #3b3f4d;
  color: #d9cfbd;
  box-shadow: 0 6px 0 #23262f;
}

.hint {
  font-size: 14px;
}

@media (max-height: 430px) {
  .overlay h1,
  .overlay h2 {
    font-size: clamp(26px, 9vmin, 40px);
  }

  .panel {
    gap: 7px;
  }

  .goal,
  .reason {
    font-size: 15px;
  }

  .controls {
    padding: 6px 14px;
    font-size: 13px;
  }

  .btn {
    min-height: 48px;
    font-size: 19px;
  }

  .board-score {
    padding: 6px 14px;
  }
}

@media (max-width: 360px) {
  .hud {
    font-size: 13px;
  }

  .pill {
    padding: 0 0.6em;
  }

  .pips i {
    width: 10px;
    height: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .btn {
    transition: none;
  }
}
