/* ============================================================
   NEON CHECKERS — retro synthwave UI
   ============================================================ */

:root {
  --pink: #ff2d95;
  --cyan: #00f0ff;
  --purple: #a64dff;
  --yellow: #ffd23f;
  --red: #ff4040;
  --green: #29df1c;
  --black: #1a0d2e;
  --bg: #0a0420;
  --bg2: #1d0b3a;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: white;
  font-family: 'Orbitron', 'Press Start 2P', sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

/* ----------------------- Screens ----------------------- */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}
.screen.show { display: flex; }
.hidden { display: none !important; }

/* ----------------------- Synthwave background ----------------------- */
.grid-bg {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, #1a0533 0%, #2a0e5a 35%, #560f6e 60%, #ff2d95 80%, #ffaf3f 100%);
  z-index: -2;
}
.grid-bg::before {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 55%;
  background-image:
    linear-gradient(transparent 0%, rgba(0,240,255,0.6) 100%),
    repeating-linear-gradient(90deg, transparent 0 39px, rgba(0,240,255,0.7) 39px 40px),
    repeating-linear-gradient(0deg, transparent 0 39px, rgba(0,240,255,0.7) 39px 40px);
  background-size: 100% 100%, 40px 40px, 40px 40px;
  transform: perspective(380px) rotateX(60deg);
  transform-origin: top center;
  opacity: 0.85;
  mask-image: linear-gradient(180deg, transparent 0%, black 25%, black 100%);
}
.grid-bg.dim { filter: brightness(0.55) saturate(1.1); }

.sun {
  position: absolute;
  width: 380px;
  height: 380px;
  border-radius: 50%;
  top: 12%;
  left: 50%;
  transform: translateX(-50%);
  background: radial-gradient(circle at 50% 60%, #ffd23f 0%, #ff4040 35%, #ff2d95 65%, transparent 75%);
  filter: blur(1px);
  z-index: -1;
  pointer-events: none;
}
.sun::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background:
    repeating-linear-gradient(0deg, transparent 0 22px, rgba(10,4,32,0.95) 22px 28px);
  mask-image: linear-gradient(180deg, transparent 50%, black 55%, black 100%);
}

/* ----------------------- Menu ----------------------- */
.menu-inner, .gameover-inner {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 40px;
  max-width: 720px;
}

.title {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(40px, 7vw, 88px);
  line-height: 1;
  letter-spacing: 4px;
  margin-bottom: 18px;
}
.title-line {
  display: block;
  text-shadow:
    0 0 10px var(--cyan),
    0 0 22px var(--cyan),
    3px 3px 0 var(--pink),
    6px 6px 0 var(--purple);
  animation: flicker 6s infinite;
}
.title-line.top { color: #fff; }
.title-line.bottom {
  color: var(--yellow);
  text-shadow:
    0 0 10px var(--pink),
    0 0 22px var(--pink),
    3px 3px 0 var(--cyan),
    6px 6px 0 var(--purple);
}

@keyframes flicker {
  0%, 96%, 100% { opacity: 1; }
  97% { opacity: 0.6; }
  98% { opacity: 1; }
  99% { opacity: 0.7; }
}

.tagline {
  font-family: 'Press Start 2P', monospace;
  font-size: 11px;
  color: var(--cyan);
  letter-spacing: 2px;
  margin-bottom: 36px;
  text-shadow: 0 0 8px var(--cyan);
}

.menu-buttons {
  display: flex;
  gap: 24px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.neon-btn {
  background: rgba(10, 4, 32, 0.7);
  color: white;
  border: 3px solid var(--cyan);
  padding: 18px 28px;
  font-family: 'Press Start 2P', monospace;
  font-size: 14px;
  letter-spacing: 2px;
  cursor: pointer;
  position: relative;
  border-radius: 4px;
  transition: all 0.18s ease-out;
  box-shadow:
    0 0 8px var(--cyan),
    inset 0 0 8px rgba(0,240,255,0.3);
  text-shadow: 0 0 6px var(--cyan);
  min-width: 220px;
}
.neon-btn:hover, .neon-btn.active {
  border-color: var(--pink);
  color: var(--yellow);
  text-shadow: 0 0 6px var(--pink);
  box-shadow:
    0 0 16px var(--pink),
    0 0 32px var(--pink),
    inset 0 0 12px rgba(255,45,149,0.3);
  transform: translateY(-2px);
}
.neon-btn:active { transform: translateY(1px); }
.neon-btn.primary {
  border-color: var(--yellow);
  text-shadow: 0 0 6px var(--yellow);
  box-shadow: 0 0 16px var(--yellow), inset 0 0 12px rgba(255,210,63,0.4);
}
.btn-line { display: block; }
.btn-sub {
  display: block;
  margin-top: 8px;
  font-size: 9px;
  color: var(--pink);
  text-shadow: 0 0 4px var(--pink);
  letter-spacing: 1.5px;
}

.difficulty-row {
  margin-top: 8px;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}
.diff-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 11px;
  color: var(--yellow);
  text-shadow: 0 0 6px var(--yellow);
}
.diff-btn {
  background: transparent;
  border: 2px solid var(--purple);
  color: white;
  padding: 8px 14px;
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  cursor: pointer;
  border-radius: 3px;
  letter-spacing: 1.5px;
  box-shadow: 0 0 6px var(--purple);
}
.diff-btn.active, .diff-btn:hover {
  background: var(--purple);
  color: var(--yellow);
  box-shadow: 0 0 14px var(--pink);
}

.footer-note {
  margin-top: 32px;
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  color: var(--purple);
  letter-spacing: 2px;
  animation: blink 1.4s steps(2) infinite;
}
@keyframes blink {
  50% { opacity: 0; }
}

/* ----------------------- HUD ----------------------- */
.hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 18px 24px;
  pointer-events: none;
}

.score-card {
  background: rgba(10, 4, 32, 0.85);
  border: 3px solid var(--cyan);
  padding: 10px 18px;
  border-radius: 6px;
  text-align: center;
  min-width: 130px;
  box-shadow: 0 0 14px var(--cyan), inset 0 0 8px rgba(0,240,255,0.2);
}
.score-card.red {
  border-color: var(--red);
  box-shadow: 0 0 14px var(--red), inset 0 0 8px rgba(255,64,64,0.25);
}
.score-card.black {
  border-color: var(--green);
  box-shadow: 0 0 14px var(--green), inset 0 0 8px rgba(41,223,28,0.25);
}
.score-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 11px;
  letter-spacing: 2px;
  margin-bottom: 4px;
}
.score-card.red .score-label { color: var(--red); text-shadow: 0 0 6px var(--red); }
.score-card.black .score-label { color: var(--green); text-shadow: 0 0 6px var(--green); }
.score-value {
  font-family: 'Orbitron', sans-serif;
  font-weight: 900;
  font-size: 38px;
  color: var(--yellow);
  text-shadow: 0 0 10px var(--yellow), 0 0 20px var(--pink);
  line-height: 1;
}
.score-pieces {
  margin-top: 4px;
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  color: var(--cyan);
  letter-spacing: 1px;
}

.turn-banner {
  background: rgba(10, 4, 32, 0.85);
  border: 3px solid var(--yellow);
  border-radius: 8px;
  padding: 12px 24px;
  font-family: 'Press Start 2P', monospace;
  font-size: 14px;
  letter-spacing: 2px;
  color: var(--yellow);
  text-shadow: 0 0 8px var(--yellow);
  box-shadow: 0 0 16px var(--yellow), inset 0 0 8px rgba(255,210,63,0.25);
  align-self: center;
  margin-top: 6px;
  animation: turnPulse 2.4s ease-in-out infinite;
}
@keyframes turnPulse {
  0%, 100% { box-shadow: 0 0 12px var(--yellow), inset 0 0 8px rgba(255,210,63,0.2); }
  50%      { box-shadow: 0 0 28px var(--pink),   inset 0 0 12px rgba(255,45,149,0.35); }
}

/* ----------------------- Canvas ----------------------- */
#canvas-wrap {
  position: absolute;
  inset: 0;
}
#canvas-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* ----------------------- Game controls ----------------------- */
.game-controls {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 14px;
  z-index: 5;
}
.ctrl-btn {
  background: rgba(10, 4, 32, 0.85);
  border: 2px solid var(--cyan);
  color: white;
  font-family: 'Press Start 2P', monospace;
  font-size: 11px;
  padding: 10px 18px;
  letter-spacing: 1.5px;
  border-radius: 4px;
  cursor: pointer;
  box-shadow: 0 0 8px var(--cyan);
  text-shadow: 0 0 4px var(--cyan);
}
.ctrl-btn:hover {
  border-color: var(--pink);
  box-shadow: 0 0 14px var(--pink);
  color: var(--yellow);
}

/* ----------------------- Toast ----------------------- */
#toast-container {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 10;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.toast {
  font-family: 'Press Start 2P', monospace;
  font-size: 28px;
  letter-spacing: 3px;
  padding: 22px 40px;
  border-radius: 8px;
  background: rgba(10, 4, 32, 0.92);
  border: 4px solid var(--yellow);
  color: var(--yellow);
  text-shadow:
    0 0 10px var(--yellow),
    0 0 24px var(--pink),
    3px 3px 0 var(--purple);
  box-shadow:
    0 0 30px var(--pink),
    0 0 60px var(--cyan),
    inset 0 0 20px rgba(255,210,63,0.3);
  animation: toastPop 1.6s cubic-bezier(0.2, 0.9, 0.3, 1.4) forwards;
  text-align: center;
  white-space: nowrap;
}
.toast .sub {
  display: block;
  margin-top: 10px;
  font-size: 12px;
  color: var(--cyan);
  text-shadow: 0 0 8px var(--cyan);
  letter-spacing: 2px;
}
.toast.king { border-color: var(--cyan); color: var(--cyan); text-shadow: 0 0 12px var(--cyan), 0 0 24px var(--pink); }
.toast.combo { border-color: var(--pink); color: var(--pink); }

@keyframes toastPop {
  0%   { transform: scale(0.4) rotate(-6deg); opacity: 0; }
  15%  { transform: scale(1.15) rotate(2deg); opacity: 1; }
  30%  { transform: scale(0.95) rotate(-1deg); }
  45%  { transform: scale(1.05) rotate(0); }
  80%  { transform: scale(1) rotate(0); opacity: 1; }
  100% { transform: scale(1) translateY(-30px); opacity: 0; }
}

/* Confetti spark dot */
.spark {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  pointer-events: none;
  box-shadow: 0 0 10px currentColor;
  animation: sparkFly 1.2s ease-out forwards;
}
@keyframes sparkFly {
  0%   { transform: translate(0,0) scale(1); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(0); opacity: 0; }
}

/* ----------------------- Game over ----------------------- */
.gameover-inner .title { font-size: clamp(38px, 6vw, 72px); }
.gameover-inner .neon-btn { margin: 10px; }

@media (max-width: 600px) {
  .title { font-size: 36px; }
  .neon-btn { padding: 14px 18px; font-size: 12px; min-width: 180px; }
  .score-value { font-size: 28px; }
  .score-card { min-width: 95px; padding: 8px 10px; }
  .turn-banner { font-size: 11px; padding: 8px 14px; }
  .toast { font-size: 18px; padding: 16px 22px; }
}
