:root {
  --bg: #0f1020;
  --panel: #1a1b28;
  --panel-2: #212233;
  --accent: #6842ff;
  --text: #fff;
  --muted: #aaadbe;
  --secondary: #2a2b3d;
  --p1-hi: #ff9a8b;
  --p1: #ff4f5e;
  --p1-lo: #c21d3a;
  --p2-hi: #fff08a;
  --p2: #ffc629;
  --p2-lo: #d98300;
  --board-w: min(100%, 430px);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    "Nunito",
    ui-rounded,
    "SF Pro Rounded",
    system-ui,
    -apple-system,
    "Segoe UI",
    sans-serif;
  font-weight: 700;
  -webkit-tap-highlight-color: transparent;
}

body {
  overflow-x: hidden;
  background:
    radial-gradient(
      ellipse 70% 50% at 50% 35%,
      rgba(104, 66, 255, 0.22),
      transparent 70%
    ),
    var(--bg);
  min-height: 100%;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

button {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 3px solid #b9a6ff;
  outline-offset: 3px;
}

.c4 {
  position: relative;
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 16px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

/* ---------- HUD ---------- */
.hud {
  display: flex;
  gap: 8px;
  width: var(--board-w);
  justify-content: space-between;
}

.chip {
  position: relative;
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 42px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--panel-2);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.07),
    0 4px 12px rgba(0, 0, 0, 0.25);
  border: 2px solid transparent;
  transition:
    border-color 0.2s,
    box-shadow 0.2s,
    transform 0.2s;
  min-width: 0;
}

.chip-p1,
.chip-p2 {
  flex: 1 1 0;
}

.chip-p2 {
  flex-direction: row-reverse;
}

.chip-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chip strong {
  font-size: 20px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  margin-left: auto;
}

.chip-p2 strong {
  margin-left: 0;
  margin-right: auto;
}

.chip-draw {
  flex-direction: column;
  gap: 0;
  padding: 3px 14px;
  justify-content: center;
}

.chip-draw .chip-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.chip-draw strong {
  font-size: 16px;
  margin: 0;
  line-height: 1.1;
}

.chip-disc {
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
}

.chip-turn {
  position: absolute;
  top: -9px;
  left: 50%;
  transform: translateX(-50%) scale(0.6);
  opacity: 0;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #1a1030;
  transition:
    opacity 0.2s,
    transform 0.2s;
}

.chip-p1 .chip-turn {
  background: var(--p1-hi);
}
.chip-p2 .chip-turn {
  background: var(--p2);
}

.chip.is-turn .chip-turn {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

.chip-p1.is-turn {
  border-color: var(--p1);
  box-shadow:
    0 0 0 3px rgba(255, 79, 94, 0.18),
    0 6px 18px rgba(255, 79, 94, 0.3);
}
.chip-p2.is-turn {
  border-color: var(--p2);
  box-shadow:
    0 0 0 3px rgba(255, 198, 41, 0.16),
    0 6px 18px rgba(255, 198, 41, 0.25);
}

.chip.bump strong {
  animation: bump 0.5s ease;
}

/* ---------- Discs ---------- */
.disc,
.chip-disc,
.turn-disc {
  border-radius: 50%;
}

.disc-p1 {
  background:
    radial-gradient(
      circle at 34% 28%,
      rgba(255, 255, 255, 0.85) 0 7%,
      rgba(255, 255, 255, 0) 24%
    ),
    radial-gradient(
      circle at 50% 50%,
      var(--p1) 0 52%,
      var(--p1-lo) 53% 62%,
      var(--p1) 64% 100%
    );
  box-shadow:
    inset 0 -4px 0 rgba(120, 0, 30, 0.35),
    inset 0 3px 2px rgba(255, 200, 190, 0.55),
    0 3px 6px rgba(0, 0, 0, 0.35);
}

.disc-p2 {
  background:
    radial-gradient(
      circle at 34% 28%,
      rgba(255, 255, 255, 0.9) 0 7%,
      rgba(255, 255, 255, 0) 24%
    ),
    radial-gradient(
      circle at 50% 50%,
      var(--p2) 0 52%,
      var(--p2-lo) 53% 62%,
      var(--p2) 64% 100%
    );
  box-shadow:
    inset 0 -4px 0 rgba(150, 70, 0, 0.35),
    inset 0 3px 2px rgba(255, 255, 220, 0.7),
    0 3px 6px rgba(0, 0, 0, 0.35);
}

/* ---------- Stage & board ---------- */
.stage {
  width: var(--board-w);
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.ghost-row {
  position: relative;
  aspect-ratio: 7 / 0.84;
}

.ghost {
  position: absolute;
  bottom: 4px;
  left: 0;
  width: calc(100% / 7);
  aspect-ratio: 1;
  transform: translateX(calc(var(--col, 3) * 100%)) scale(0.78);
  transition:
    transform 0.16s cubic-bezier(0.3, 1.4, 0.5, 1),
    opacity 0.15s;
  opacity: 0.95;
  animation: ghost-bob 1.2s ease-in-out infinite;
  pointer-events: none;
}

.ghost.is-hidden {
  opacity: 0;
}

.ghost.is-blocked {
  filter: grayscale(0.8) brightness(0.6);
}

.board {
  position: relative;
  width: 100%;
  aspect-ratio: 7 / 6;
  border-radius: 18px;
  filter: drop-shadow(0 14px 22px rgba(10, 6, 40, 0.6));
  touch-action: manipulation;
}

.board.shake {
  animation: shake 0.36s ease;
}

.board-back {
  position: absolute;
  inset: 1.5%;
  border-radius: 16px;
  background: radial-gradient(ellipse at 50% 20%, #232064, #110e33 75%);
}

.discs,
.win-rings,
.columns {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: repeat(6, 1fr);
}

.slot {
  position: relative;
}

.slot .disc {
  position: absolute;
  inset: 7%;
  transform: translateY(0);
}

.slot .disc.drop {
  animation: drop var(--dur, 0.5s) linear both;
}

.slot .disc.fade-out {
  animation: undo-pop 0.22s ease forwards;
}

.board.is-over .slot .disc:not(.win) {
  filter: brightness(0.55) saturate(0.7);
  transition: filter 0.4s;
}

.slot .disc.win {
  animation: win-pop 0.5s cubic-bezier(0.2, 1.6, 0.4, 1);
}

.frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}

.win-rings {
  pointer-events: none;
}

.ring {
  position: relative;
}

.ring::before {
  content: "";
  position: absolute;
  inset: 5%;
  border-radius: 50%;
  border: 4px solid #fff;
  box-shadow:
    0 0 14px 4px var(--glow, #fff),
    inset 0 0 12px 3px var(--glow, #fff);
  animation: ring-pulse 1s ease-in-out infinite alternate;
}

.columns {
  grid-template-rows: 1fr;
}

.col-btn {
  appearance: none;
  border: 0;
  margin: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  border-radius: 14px;
  position: relative;
}

.col-btn::after {
  content: "";
  position: absolute;
  inset: 0 6%;
  border-radius: 14px;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.1),
    rgba(255, 255, 255, 0.02)
  );
  opacity: 0;
  transition: opacity 0.15s;
}

.col-btn.is-active::after {
  opacity: 1;
}

.col-btn:focus-visible {
  outline-offset: -3px;
}

.col-btn:disabled {
  cursor: default;
}

.board-foot {
  height: 12px;
  margin: -4px 6% 0;
  border-radius: 0 0 14px 14px;
  background: linear-gradient(180deg, #25198a, #170f5a);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.4);
}

/* ---------- Actions ---------- */
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  align-items: center;
  width: var(--board-w);
}

.btn {
  appearance: none;
  border: 0;
  min-height: 42px;
  padding: 0 18px;
  border-radius: 999px;
  font-weight: 900;
  font-size: 15px;
  cursor: pointer;
  transition:
    transform 0.12s ease,
    filter 0.15s,
    background 0.15s;
  white-space: nowrap;
}

.btn:active {
  transform: translateY(2px) scale(0.97);
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.btn-primary {
  background: linear-gradient(180deg, #8264ff, var(--accent));
  box-shadow:
    0 5px 0 #4424c4,
    0 10px 22px rgba(104, 66, 255, 0.45);
}

.btn-primary:hover {
  filter: brightness(1.08);
}

.btn-primary:active {
  box-shadow:
    0 2px 0 #4424c4,
    0 6px 14px rgba(104, 66, 255, 0.4);
}

.btn-secondary {
  background: var(--secondary);
  box-shadow:
    0 4px 0 #1a1b29,
    inset 0 1px 0 rgba(255, 255, 255, 0.07);
}

.btn-secondary:hover {
  background: #34354b;
}

.btn-big {
  min-height: 54px;
  padding: 0 40px;
  font-size: 20px;
}

.mode-pill {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(104, 66, 255, 0.16);
  color: #cfc4ff;
  font-size: 13px;
  font-weight: 800;
  margin-right: auto;
}

.mode-pill[hidden] {
  display: none;
}

.help {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
  text-align: center;
  line-height: 1.8;
}

kbd {
  display: inline-block;
  min-width: 20px;
  padding: 0 5px;
  margin: 0 1px;
  border-radius: 6px;
  background: var(--secondary);
  color: #e6e6f5;
  font: inherit;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
  box-shadow: 0 2px 0 #14141f;
}

.btn svg {
  width: 17px;
  height: 17px;
  margin: -3px 6px 0 -2px;
  vertical-align: middle;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@media (hover: none) and (pointer: coarse) {
  .keys-help {
    display: none;
  }
}

.link {
  appearance: none;
  background: none;
  border: 0;
  color: #b9a6ff;
  text-decoration: underline;
  cursor: pointer;
  font-size: 12.5px;
  min-height: 32px;
  padding: 0 6px;
}

/* ---------- Overlays ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: rgba(10, 10, 26, 0.72);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  overflow-y: auto;
  animation: fade-in 0.25s ease;
}

.overlay[hidden] {
  display: none;
}

.card {
  position: relative;
  width: min(100%, 400px);
  padding: 22px 20px 22px;
  border-radius: 26px;
  background: linear-gradient(180deg, #25264a, var(--panel));
  box-shadow:
    0 20px 50px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  text-align: center;
  animation: card-in 0.4s cubic-bezier(0.2, 1.5, 0.4, 1);
}

.card h2 {
  margin: 4px 0 4px;
  font-size: clamp(28px, 7vw, 36px);
  font-weight: 900;
  letter-spacing: -0.01em;
  background: linear-gradient(180deg, #fff 30%, #d7ccff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 3px 0 #3a2a99);
}

.lead {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 14.5px;
  line-height: 1.4;
}

.logo {
  display: flex;
  justify-content: center;
  gap: 6px;
}

.logo .disc {
  width: 34px;
  height: 34px;
  animation: logo-hop 1.6s ease-in-out infinite;
}

.logo .disc:nth-child(2) {
  animation-delay: 0.12s;
}
.logo .disc:nth-child(3) {
  animation-delay: 0.24s;
}
.logo .disc:nth-child(4) {
  animation-delay: 0.36s;
}

.option {
  display: flex;
  gap: 4px;
  padding: 4px;
  margin: 0 auto 10px;
  border-radius: 999px;
  background: #11121f;
  align-items: center;
  max-width: 100%;
}

.option[hidden] {
  display: none;
}

.option-label {
  color: var(--muted);
  font-size: 13px;
  padding: 0 4px 0 10px;
}

.seg {
  flex: 1 1 0;
  appearance: none;
  border: 0;
  min-height: 40px;
  padding: 0 8px;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
  transition:
    background 0.15s,
    color 0.15s;
}

.seg[aria-checked="true"] {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 3px 10px rgba(104, 66, 255, 0.5);
}

.card .btn-big {
  margin-top: 6px;
  width: 100%;
}

.card-end {
  overflow: hidden;
}

.end-disc {
  width: 64px;
  height: 64px;
  margin: 0 auto 4px;
  animation: end-disc 0.7s cubic-bezier(0.2, 1.6, 0.4, 1);
}

.end-disc.is-draw {
  background: conic-gradient(var(--p1) 0 50%, var(--p2) 50% 100%);
  box-shadow:
    inset 0 0 0 5px rgba(255, 255, 255, 0.25),
    0 4px 10px rgba(0, 0, 0, 0.4);
}

.end-score {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 0 0 14px;
  flex-wrap: wrap;
}

.end-score span {
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--panel-2);
  font-size: 13px;
  color: var(--muted);
}

.end-score b {
  color: #fff;
  font-weight: 900;
}

.end-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: stretch;
}

.burst {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.confetti {
  position: absolute;
  top: 70px;
  left: 50%;
  width: 9px;
  height: 14px;
  border-radius: 3px;
  animation: confetti 1.3s cubic-bezier(0.15, 0.7, 0.4, 1) forwards;
}

/* ---------- Animations ---------- */
@keyframes drop {
  0% {
    transform: translateY(calc(var(--fall) * -116.3%));
    animation-timing-function: cubic-bezier(0.5, 0, 1, 1);
  }
  62% {
    transform: translateY(0) scale(1.04, 0.94);
    animation-timing-function: cubic-bezier(0, 0, 0.5, 1);
  }
  76% {
    transform: translateY(calc(var(--bounce, 1) * -16%));
    animation-timing-function: cubic-bezier(0.5, 0, 1, 1);
  }
  88% {
    transform: translateY(0) scale(1.02, 0.97);
    animation-timing-function: cubic-bezier(0, 0, 0.5, 1);
  }
  94% {
    transform: translateY(calc(var(--bounce, 1) * -4%));
  }
  100% {
    transform: translateY(0);
  }
}

@keyframes win-pop {
  50% {
    transform: scale(1.15);
  }
}

@keyframes undo-pop {
  to {
    transform: scale(0.2);
    opacity: 0;
  }
}

@keyframes ring-pulse {
  from {
    opacity: 0.75;
    transform: scale(0.97);
  }
  to {
    opacity: 1;
    transform: scale(1.04);
  }
}

@keyframes ghost-bob {
  0%,
  100% {
    translate: 0 0;
  }
  50% {
    translate: 0 -4px;
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-8px);
  }
  40% {
    transform: translateX(7px);
  }
  60% {
    transform: translateX(-5px);
  }
  80% {
    transform: translateX(3px);
  }
}

@keyframes bump {
  40% {
    transform: scale(1.45);
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

@keyframes card-in {
  from {
    transform: scale(0.8) translateY(20px);
    opacity: 0;
  }
}

@keyframes logo-hop {
  0%,
  60%,
  100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-9px);
  }
}

@keyframes end-disc {
  from {
    transform: scale(0) rotate(-180deg);
  }
}

@keyframes confetti {
  0% {
    transform: translate(-50%, 0) rotate(0);
    opacity: 1;
  }
  100% {
    transform: translate(calc(-50% + var(--dx)), var(--dy)) rotate(var(--rot));
    opacity: 0;
  }
}

/* ---------- Responsive ---------- */
@media (max-width: 420px) {
  .c4 {
    padding: 10px 12px 12px;
    gap: 8px;
  }
  .chip {
    padding: 6px 9px;
    gap: 5px;
  }
  .chip-label {
    font-size: 12px;
  }
  .chip strong {
    font-size: 18px;
  }
  .chip-draw {
    padding: 3px 9px;
  }
  .btn {
    padding: 0 14px;
    font-size: 14px;
  }
  .mode-pill {
    display: none;
  }
  .seg {
    font-size: 13px;
    padding: 0 6px;
  }
}

@media (max-width: 350px) {
  .chip-disc {
    display: none;
  }
  .option-label {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .confetti {
    display: none;
  }
}
