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

@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

body {
  background: #0a0a1a;
  color: #e5e7eb;
  font-family: 'Inter', system-ui, sans-serif;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ===== SPLASH ===== */
#splash {
  position: relative;
  width: 100%;
  height: 100vh;
  background: radial-gradient(ellipse at center, #1a1a3e 0%, #0a0a1a 70%);
  overflow: hidden;
}

/* Animated falling blocks background */
#splash-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0.35;
}

.splash-content {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  animation: fadeIn 0.8s ease-out;
}

.splash-title {
  font-family: 'Press Start 2P', monospace;
  font-size: 2.8rem;
  font-weight: 400;
  letter-spacing: 0.15em;
  background: linear-gradient(135deg, #3b82f6, #a855f7, #10b981);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 1rem;
  filter: drop-shadow(0 0 30px rgba(139, 92, 246, 0.3));
}

.splash-sub {
  font-family: 'Press Start 2P', monospace;
  font-size: 1rem;
  color: #9ca3af;
  margin-bottom: 3rem;
  text-shadow: 0 0 4px rgba(156,163,175,0.3);
}

.btn-play {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 1rem 2.5rem;
  font-family: 'Press Start 2P', monospace;
  font-size: 0.95rem;
  font-weight: 400;
  letter-spacing: 0.1em;
  color: #10b981;
  background: #0d1117;
  border: 2px solid #10b981;
  border-radius: 4px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, color 0.15s, background 0.15s;
  text-shadow: 0 0 8px rgba(16,185,129,0.4);
  box-shadow: 0 0 10px rgba(16,185,129,0.15);
}

.btn-play:hover {
  transform: translateY(-2px);
  color: #fff;
  background: #10b981;
  text-shadow: none;
  box-shadow: 0 0 30px rgba(16,185,129,0.4), 0 0 60px rgba(16,185,129,0.15);
}

/* Insert coin blinking text */
.insert-coin {
  font-family: 'Press Start 2P', monospace;
  font-size: 1.1rem;
  color: #fbbf24;
  letter-spacing: 0.1em;
  text-shadow: 0 0 10px rgba(251,191,36,0.5), 0 0 20px rgba(251,191,36,0.2);
  animation: blink 1s step-end infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Play area drops in from above like a tetris piece */
.play-area-drop {
  animation: dropIn 0.6s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes dropIn {
  0% { transform: translateY(-300px); opacity: 0; }
  60% { transform: translateY(10px); opacity: 1; }
  80% { transform: translateY(-4px); }
  100% { transform: translateY(0); opacity: 1; }
}

.splash-hint {
  margin-top: 1.5rem;
  font-family: 'Press Start 2P', monospace;
  font-size: 0.85rem;
  color: #6b7280;
  line-height: 2;
}

/* ===== COUNTDOWN ===== */
#countdown {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(10, 10, 26, 0.92);
}

.countdown-number {
  font-family: 'Press Start 2P', monospace;
  font-size: 6rem;
  color: #fbbf24;
  animation: countPop 0.7s ease-out forwards;
  text-shadow: 0 0 40px rgba(251,191,36,0.5), 0 0 80px rgba(251,191,36,0.2);
}

@keyframes countPop {
  0% { transform: scale(2.5); opacity: 0; }
  30% { transform: scale(1); opacity: 1; }
  80% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.8); opacity: 0; }
}

/* ===== GAME ===== */
#game {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100vh;
  animation: fadeIn 0.4s ease-out;
  overflow: hidden;
}

.game-bg {
  position: absolute;
  inset: 0;
  background: url('bg-game.webp') center/cover no-repeat;
  opacity: 0.15;
  z-index: 0;
}

.game-layout {
  position: relative;
  z-index: 1;
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
}

#board {
  border: 2px solid #3b82f6;
  border-radius: 2px;
  background: #0d1117;
  box-shadow: 0 0 20px rgba(59, 130, 246, 0.12), 0 0 60px rgba(59, 130, 246, 0.05), inset 0 0 60px rgba(0,0,0,0.4);
}

/* Side panel — arcade style */
.side-panel {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: 150px;
}

.panel-box {
  background: #0d1117;
  border: 2px solid #3b82f6;
  border-radius: 4px;
  padding: 0.65rem 0.75rem;
  text-align: center;
  box-shadow: 0 0 8px rgba(59,130,246,0.15), inset 0 0 20px rgba(0,0,0,0.4);
}

.panel-label {
  display: block;
  font-family: 'Press Start 2P', monospace;
  font-size: 0.9rem;
  letter-spacing: 0.08em;
  color: #3b82f6;
  margin-bottom: 0.5rem;
  text-shadow: 0 0 6px rgba(59,130,246,0.4);
}

.panel-value {
  display: block;
  font-family: 'Press Start 2P', monospace;
  font-size: 1.6rem;
  color: #fbbf24;
  text-shadow: 0 0 8px rgba(251,191,36,0.4);
}

#next-canvas {
  display: block;
  margin: 0.25rem auto 0;
}

/* Score popup */
.score-popup {
  position: fixed;
  z-index: 20;
  font-family: 'Press Start 2P', monospace;
  font-size: 1.2rem;
  font-weight: 400;
  color: #fbbf24;
  text-shadow: 0 0 10px rgba(251, 191, 36, 0.5);
  pointer-events: none;
  animation: scoreFloat 1s ease-out forwards;
}

@keyframes scoreFloat {
  0% { transform: translateY(0) scale(1.3); opacity: 1; }
  100% { transform: translateY(-60px) scale(0.8); opacity: 0; }
}

/* Line clear flash */
.line-flash {
  position: absolute;
  left: 0;
  height: 30px;
  width: 300px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.6), transparent);
  pointer-events: none;
  animation: flashLine 0.35s ease-out forwards;
  z-index: 5;
}

@keyframes flashLine {
  0% { opacity: 1; transform: scaleX(0.3); }
  50% { opacity: 1; transform: scaleX(1.1); }
  100% { opacity: 0; transform: scaleX(1.2); }
}

/* Right panel: legend + settings — arcade style */
.right-panel {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: 200px;
}

.legend-box { text-align: left; padding: 0.8rem 1rem; }

.legend {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-top: 0.5rem;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  font-family: 'Press Start 2P', monospace;
  font-size: 0.85rem;
  color: #9ca3af;
}

.legend-row kbd {
  display: inline-block;
  min-width: 75px;
  text-align: center;
  padding: 0.45rem 0.5rem;
  font-family: 'Press Start 2P', monospace;
  font-size: 0.8rem;
  color: #10b981;
  background: #0d1117;
  border: 1px solid #10b981;
  border-radius: 2px;
  text-shadow: 0 0 4px rgba(16,185,129,0.4);
  box-shadow: 0 0 4px rgba(16,185,129,0.1);
}

/* Toggle switch — arcade */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  gap: 0.5rem;
}

.toggle-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.85rem;
  color: #3b82f6;
  letter-spacing: 0.05em;
  text-shadow: 0 0 6px rgba(59,130,246,0.4);
}

.toggle-row input { display: none; }

.toggle-switch {
  position: relative;
  width: 36px;
  height: 20px;
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 3px;
  transition: background 0.2s, border-color 0.2s;
}

.toggle-switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  background: #6b7280;
  border-radius: 2px;
  transition: transform 0.2s, background 0.2s, box-shadow 0.2s;
}

.toggle-row input:checked + .toggle-switch {
  background: #0d1117;
  border-color: #10b981;
}

.toggle-row input:checked + .toggle-switch::after {
  transform: translateX(16px);
  background: #10b981;
  box-shadow: 0 0 6px rgba(16,185,129,0.5);
}

/* Mobile controls */
.mobile-controls {
  display: none;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 1rem;
  width: 100%;
}

.ctrl-btn {
  width: 56px;
  height: 56px;
  font-size: 1.3rem;
  font-weight: 700;
  background: #1f2937;
  color: #e5e7eb;
  border: 1px solid #374151;
  border-radius: 10px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.ctrl-btn:active { background: #374151; }
.ctrl-wide { width: 120px; font-size: 0.9rem; letter-spacing: 0.1em; }

/* Overlay (pause/game over) */
#overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10;
}

.overlay-content {
  text-align: center;
  animation: fadeIn 0.3s ease-out;
}

#overlay-title {
  font-family: 'Press Start 2P', monospace;
  font-size: 1.6rem;
  letter-spacing: 0.15em;
  margin-bottom: 0.75rem;
  color: #f87171;
  text-shadow: 0 0 20px rgba(248,113,113,0.5);
}

#overlay-sub {
  font-family: 'Press Start 2P', monospace;
  color: #9ca3af;
  margin-bottom: 1.5rem;
  font-size: 0.55rem;
  line-height: 1.8;
}

/* Responsive */
@media (max-width: 640px) {
  .game-layout {
    flex-direction: column;
    align-items: center;
  }

  .side-panel {
    flex-direction: row;
    min-width: auto;
    flex-wrap: wrap;
    justify-content: center;
  }

  .side-panel .panel-box { flex: 1; min-width: 70px; }

  #board { width: 240px; height: 480px; }

  .mobile-controls { display: flex; }

  .splash-title { font-size: 1.6rem; }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
