:root {
  --bg-deep: #0a0a12;
  --bg-panel: rgba(255, 255, 255, 0.04);
  --border-subtle: rgba(255, 255, 255, 0.08);
  --text-primary: #f0f0f5;
  --text-muted: #8888a0;
  --accent-cyan: #00e5ff;
  --font: 'Outfit', system-ui, sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--bg-deep);
  color: var(--text-primary);
  min-height: 100vh;
  overflow: hidden;
}

.game-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ---- Header ---- */
.game-header {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
  flex-wrap: wrap;
}

.back-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  transition: color 0.2s;
}

.back-link:hover {
  color: var(--accent-cyan);
}

.game-header h1 {
  font-size: 1.5rem;
  font-weight: 600;
  background: linear-gradient(135deg, var(--text-primary), var(--accent-cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.size-picker {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.size-picker__label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.size-range {
  -webkit-appearance: none;
  appearance: none;
  width: 130px;
  height: 6px;
  border-radius: 100px;
  background: rgba(255, 255, 255, 0.12);
  cursor: pointer;
}

.size-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent-cyan);
  box-shadow: 0 0 10px rgba(0, 229, 255, 0.5);
  cursor: pointer;
}

.size-range::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: none;
  border-radius: 50%;
  background: var(--accent-cyan);
  box-shadow: 0 0 10px rgba(0, 229, 255, 0.5);
  cursor: pointer;
}

.size-picker__value {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent-cyan);
  min-width: 4.5rem;
}

.tool-btn {
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.5rem 1.1rem;
  border: 1px solid var(--border-subtle);
  border-radius: 100px;
  background: var(--bg-panel);
  color: var(--text-primary);
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s, opacity 0.2s;
}

.tool-btn:hover:not(:disabled) {
  border-color: rgba(0, 229, 255, 0.4);
  color: var(--accent-cyan);
}

.tool-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.tool-btn--primary {
  margin-left: auto;
}

/* ---- Container ---- */
.game-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 1rem;
  min-height: 0;
}

.stat-bar {
  display: flex;
  gap: 2rem;
}

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

.stat__label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.stat__value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent-cyan);
}

/* ---- Board ---- */
.board-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.board {
  position: relative;
  height: 100%;
  max-height: min(70vh, 620px);
  aspect-ratio: 1;
  max-width: 100%;
  display: grid;
  grid-template-columns: repeat(var(--cells, 5), 1fr);
  gap: clamp(3px, 0.8%, 8px);
  padding: clamp(6px, 1.6%, 16px);
  background:
    radial-gradient(circle at 30% 20%, rgba(0, 229, 255, 0.06), transparent 60%),
    radial-gradient(circle at 75% 85%, rgba(168, 85, 247, 0.06), transparent 60%),
    var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
}

.cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.02);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03);
}

/* ---- Bubbles ---- */
.bubble {
  position: relative;
  width: 86%;
  height: 86%;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  background: var(--bubble-grad);
  box-shadow:
    inset 0 2px 3px rgba(255, 255, 255, 0.5),
    inset 0 -4px 8px rgba(0, 0, 0, 0.35),
    0 3px 10px rgba(0, 0, 0, 0.35),
    0 0 14px var(--bubble-glow);
  transition: transform 0.14s ease, box-shadow 0.2s ease;
  animation: pop-in 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Glossy highlight */
.bubble::after {
  content: '';
  position: absolute;
  left: 20%;
  top: 12%;
  width: 34%;
  height: 22%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.38);
  filter: blur(2px);
  pointer-events: none;
  z-index: 1;
}

.cell:hover .bubble {
  transform: scale(1.06);
  box-shadow:
    inset 0 2px 3px rgba(255, 255, 255, 0.5),
    inset 0 -4px 8px rgba(0, 0, 0, 0.35),
    0 3px 12px rgba(0, 0, 0, 0.4),
    0 0 22px var(--bubble-glow);
}

.bubble--v1 { --bubble-grad: radial-gradient(circle at 35% 28%, #7ff4ff, #00e5ff 45%, #0088bb); --bubble-glow: rgba(0, 229, 255, 0.55); }
.bubble--v2 { --bubble-grad: radial-gradient(circle at 35% 28%, #d9b8ff, #a855f7 45%, #6d28d9); --bubble-glow: rgba(168, 85, 247, 0.55); }
.bubble--v3 { --bubble-grad: radial-gradient(circle at 35% 28%, #ffd08a, #f97316 45%, #d1418a); --bubble-glow: rgba(249, 115, 22, 0.6); }

/* Dots inside a bubble — sit above the gloss and carry a dark rim so the
   count stays legible against the bright bubble. */
.pip {
  position: absolute;
  z-index: 2;
  width: 21%;
  height: 21%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: #ffffff;
  box-shadow:
    0 0 0 1.5px rgba(10, 10, 24, 0.45),
    0 1px 2px rgba(0, 0, 0, 0.5),
    inset 0 -1px 2px rgba(0, 0, 0, 0.2);
  pointer-events: none;
}

.bubble.is-hit {
  animation: hit-pulse 0.34s ease;
}

.bubble.is-bursting {
  animation: burst 0.32s cubic-bezier(0.3, 0, 0.4, 1) forwards;
  pointer-events: none;
  z-index: 2;
}

/* ---- Sparks (the fired dots) ---- */
.spark {
  --sz: clamp(9px, 2.3%, 19px);
  position: absolute;
  width: var(--sz);
  height: var(--sz);
  margin-left: calc(var(--sz) / -2);
  margin-top: calc(var(--sz) / -2);
  border-radius: 50%;
  background: radial-gradient(circle, #ffffff 0%, #baf7ff 40%, #34d9ff 70%, rgba(0, 229, 255, 0));
  pointer-events: none;
  z-index: 6;
  transition: transform 0.36s cubic-bezier(0.3, 0.55, 0.35, 1), opacity 0.36s ease;
}

/* ---- Explosion shockwave + flash ---- */
.burst-ring {
  position: absolute;
  width: var(--rs);
  height: var(--rs);
  margin-left: calc(var(--rs) / -2);
  margin-top: calc(var(--rs) / -2);
  border-radius: 50%;
  border: 2.5px solid rgba(255, 255, 255, 0.95);
  box-shadow: 0 0 18px var(--fx-glow), inset 0 0 14px var(--fx-glow);
  pointer-events: none;
  z-index: 4;
  animation: ring-expand 0.55s cubic-bezier(0.2, 0.6, 0.3, 1) forwards;
}

.burst-flash {
  position: absolute;
  width: var(--rs);
  height: var(--rs);
  margin-left: calc(var(--rs) / -2);
  margin-top: calc(var(--rs) / -2);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.95) 0%, var(--fx-glow) 42%, rgba(255, 255, 255, 0) 72%);
  pointer-events: none;
  z-index: 3;
  animation: flash-out 0.4s ease-out forwards;
}

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

@keyframes hit-pulse {
  0% { transform: scale(1); }
  40% { transform: scale(1.28); }
  100% { transform: scale(1); }
}

@keyframes burst {
  0% { transform: scale(1); opacity: 1; filter: brightness(1); }
  28% { transform: scale(1.5); opacity: 1; filter: brightness(2.1) saturate(1.4); }
  55% { transform: scale(1.15); opacity: 0.85; filter: brightness(1.4); }
  100% { transform: scale(0.12); opacity: 0; filter: brightness(1); }
}

@keyframes ring-expand {
  0% { transform: scale(0.25); opacity: 0; }
  15% { opacity: 0.95; }
  100% { transform: scale(2.7); opacity: 0; }
}

@keyframes flash-out {
  0% { transform: scale(0.35); opacity: 0.95; }
  55% { transform: scale(1.25); opacity: 0.65; }
  100% { transform: scale(1.75); opacity: 0; }
}

/* ---- Hint + overlay ---- */
.hint-text {
  max-width: 40rem;
  text-align: center;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--text-muted);
}

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 10, 18, 0.75);
  backdrop-filter: blur(8px);
  z-index: 10;
}

.overlay--hidden {
  display: none;
}

.overlay-content {
  text-align: center;
  padding: 2.5rem;
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  backdrop-filter: blur(12px);
  max-width: 90vw;
  width: 30rem;
}

.overlay-content h2 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  background: linear-gradient(135deg, var(--text-primary), var(--accent-cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.overlay-content p {
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 1.5rem;
}

.overlay-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
}

.btn-start {
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 600;
  padding: 0.75rem 2rem;
  border: none;
  border-radius: 100px;
  background: linear-gradient(135deg, #00e5ff, #0099cc);
  color: #0a0a12;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.btn-start:hover {
  transform: scale(1.05);
  box-shadow: 0 0 30px rgba(0, 229, 255, 0.4);
}

@media (max-width: 620px) {
  .game-header { gap: 0.85rem; padding: 0.85rem 1rem; }
  .game-header h1 { font-size: 1.25rem; }
  .stat-bar { gap: 1.4rem; }
  .hint-text { font-size: 0.78rem; }
}
