:root {
  --bg: #0f0f23;
  --surface: #1a1a2e;
  --cell-light: #1e2a45;
  --cell-dark: #192238;
  --grid-line: #2a3a5c;
  --cell-hover: rgba(255, 255, 255, 0.08);
  --text: #e0e0e0;
  --text-dim: #888;
  --accent: #4cc9f0;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex;
  justify-content: center;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#app {
  width: 100%;
  max-width: 520px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

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

h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--accent);
}

.score-area {
  display: flex;
  gap: 18px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.label {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-dim);
  letter-spacing: 1px;
}

#score-value, #best-value, #moves-value {
  font-size: 24px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

#board-container {
  width: 100%;
  max-width: 480px;
  aspect-ratio: 1;
  background: var(--surface);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

#board {
  display: block;
  width: 100%;
  height: 100%;
}

.cell-bg {
  cursor: pointer;
  transition: fill 0.15s;
}

.cell-bg:hover {
  fill: var(--cell-hover);
}

.cell-light { fill: var(--cell-light); }
.cell-dark  { fill: var(--cell-dark); }

.grid-line {
  stroke: var(--grid-line);
  stroke-width: 1;
}

.ball {
  transform-box: fill-box;
  transform-origin: center center;
  filter: url(#shadow);
  cursor: pointer;
}

.ball.selected {
  animation: pulse 0.7s ease-in-out infinite;
}

@keyframes pop-in {
  0%   { transform: scale(0); opacity: 0; }
  50%  { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes pop-out {
  0%   { transform: scale(1); opacity: 1; }
  50%  { transform: scale(1.15); opacity: 0.7; }
  100% { transform: scale(0); opacity: 0; }
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.15); }
}

@keyframes bounce-select {
  0%   { transform: translateY(0) scale(1); }
  25%  { transform: translateY(-10px) scale(1.05); }
  50%  { transform: translateY(0) scale(0.95); }
  70%  { transform: translateY(-4px) scale(1.02); }
  100% { transform: translateY(0) scale(1); }
}

.anim-appear {
  animation: pop-in 0.35s ease-out forwards;
}

.anim-disappear {
  animation: pop-out 0.35s ease-in forwards;
}

.anim-bounce {
  animation: bounce-select 0.4s ease-out forwards;
}

#preview-area {
  display: flex;
  align-items: center;
  gap: 10px;
}

#next-balls {
  display: flex;
  gap: 8px;
}

.preview-ball {
  width: 28px;
  height: 28px;
  border-radius: 50%;
}

#new-game-btn, #restart-btn {
  background: transparent;
  border: 2px solid var(--accent);
  color: var(--accent);
  font-size: 15px;
  font-weight: 600;
  padding: 10px 28px;
  border-radius: 8px;
  cursor: pointer;
  letter-spacing: 0.5px;
  transition: background 0.2s, color 0.2s;
}

#new-game-btn:hover, #restart-btn:hover {
  background: var(--accent);
  color: var(--bg);
}

#game-over {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

#game-over.hidden {
  display: none;
}

.overlay-content {
  background: var(--surface);
  padding: 40px;
  border-radius: 16px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.overlay-content h2 {
  font-size: 24px;
}

.overlay-content p {
  font-size: 18px;
  color: var(--text-dim);
}

#final-score {
  color: var(--accent);
  font-weight: 700;
  font-size: 24px;
}
