:root {
  color-scheme: light dark;
  --bg: #0f172a;
  --panel: rgba(15, 23, 42, 0.72);
  --panel-light: rgba(30, 41, 59, 0.75);
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-2: #a78bfa;
  --success: #22c55e;
  --danger: #f97316;
  --tile-gap: 6px;
  --board-max: clamp(240px, 70vmin, 520px);
}

body {
  background: radial-gradient(circle at top, #1e293b 0%, #0f172a 55%, #020617 100%);
  color: var(--text);
}

main.container {
  padding-top: 24px;
  padding-bottom: 48px;
}

.brain-crush-hero {
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
}

.brain-crush-hero h1 {
  font: 700 32px/1.2 Poppins, sans-serif;
  margin: 0;
}

.brain-crush-hero p {
  font: 400 16px/1.6 Nunito, system-ui, sans-serif;
  color: var(--muted);
  margin: 0;
  max-width: 760px;
}

.game-shell {
  display: grid;
  gap: 20px;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
}

.game-panel {
  background: var(--panel);
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 20px 40px rgba(2, 6, 23, 0.35);
  backdrop-filter: blur(12px);
}

.stats-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.stat-card {
  background: var(--panel-light);
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 12px;
  padding: 12px 14px;
  display: grid;
  gap: 4px;
}

.stat-card span {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stat-card strong {
  font: 700 20px/1.2 Poppins, sans-serif;
}

.controls-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.button {
  border: 1px solid rgba(148, 163, 184, 0.4);
  background: rgba(15, 23, 42, 0.7);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 10px;
  font: 600 14px/1 Poppins, sans-serif;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}

.button:hover,
.button:focus-visible {
  transform: translateY(-1px);
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.15);
  outline: none;
}

.button.primary {
  background: linear-gradient(120deg, rgba(56, 189, 248, 0.9), rgba(167, 139, 250, 0.9));
  border-color: transparent;
  color: rgba(248, 250, 252, 0.92);
}

.button.toggle.active {
  background: rgba(34, 197, 94, 0.18);
  border-color: rgba(34, 197, 94, 0.7);
  color: #dcfce7;
}

.game-layout {
  display: grid;
  gap: 20px;
  grid-template-columns: minmax(0, 1fr);
  justify-items: center;
}

.board-wrap {
  display: grid;
  gap: 14px;
  justify-items: center;
  position: relative;
  width: 100%;
}

.board {
  position: relative;
  width: min(92vw, var(--board-max), calc(100vh - 280px));
  aspect-ratio: 1 / 1;
  height: min(92vw, var(--board-max), calc(100vh - 280px));
  background: rgba(15, 23, 42, 0.65);
  border: 2px solid rgba(148, 163, 184, 0.2);
  border-radius: 18px;
  padding: var(--tile-gap);
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  gap: var(--tile-gap);
  touch-action: none;
  user-select: none;
  min-height: 280px;
}

.tile {
  position: relative;
  border: none;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-size: 20px;
  font-weight: 700;
  color: rgba(248, 250, 252, 0.92);
  cursor: pointer;
  transition: transform 220ms ease, opacity 160ms ease, box-shadow 220ms ease;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.35), 0 8px 14px rgba(15, 23, 42, 0.25);
  overflow: hidden;
}

.tile:focus-visible {
  outline: 3px solid rgba(248, 250, 252, 0.9);
}

.tile::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 25% 20%, rgba(255, 255, 255, 0.5), transparent 55%);
  opacity: 0.65;
  pointer-events: none;
}

.tile svg {
  width: 52%;
  height: 52%;
  fill: rgba(248, 250, 252, 0.9);
  opacity: 0.9;
  filter: drop-shadow(0 2px 4px rgba(15, 23, 42, 0.35));
}

.tile[data-type="0"] { background: linear-gradient(135deg, #facc15, #f59e0b); }
.tile[data-type="1"] { background: linear-gradient(135deg, #fb7185, #f43f5e); }
.tile[data-type="2"] { background: linear-gradient(135deg, #34d399, #10b981); }
.tile[data-type="3"] { background: linear-gradient(135deg, #60a5fa, #3b82f6); }
.tile[data-type="4"] { background: linear-gradient(135deg, #a78bfa, #8b5cf6); }
.tile[data-type="5"] { background: linear-gradient(135deg, #f97316, #fb923c); }

.tile.empty {
  opacity: 0;
  pointer-events: none;
  box-shadow: none;
}

.tile.selected {
  outline: 3px solid #f8fafc;
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.6), 0 12px 18px rgba(15, 23, 42, 0.35);
  transform: scale(1.05);
  z-index: 3;
}

.tile.swap-back {
  animation: shake 240ms ease;
}

.tile.fade {
  opacity: 0;
}

.tile.line-clear::after,
.tile.color-bomb::after {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.7);
}

.tile.line-clear::before {
  content: "";
  position: absolute;
  inset: 45% 12%;
  height: 4px;
  background: rgba(255, 255, 255, 0.9);
}

.tile.line-clear.vertical::before {
  inset: 12% 45%;
  width: 4px;
  height: auto;
}

.tile.color-bomb {
  background: radial-gradient(circle at top, #f8fafc, #0f172a 75%);
  color: #f8fafc;
}

.tile.color-bomb::after {
  content: "★";
  font-size: 18px;
  color: #f8fafc;
  border: none;
  box-shadow: none;
}

.board.paused {
  filter: grayscale(0.3) blur(1px);
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  text-align: center;
  z-index: 4;
  border-radius: 18px;
}

.overlay.active {
  display: flex;
}

.overlay-card {
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 16px;
  padding: 20px 24px;
  max-width: 320px;
}

.overlay-card h2 {
  margin: 0 0 8px;
  font: 700 22px/1.2 Poppins, sans-serif;
}

.overlay-card p {
  margin: 0 0 14px;
  color: var(--muted);
}

.how-to {
  margin-top: 14px;
  background: rgba(15, 23, 42, 0.65);
  border-radius: 14px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  padding: 12px 14px;
  color: var(--muted);
}

.how-to summary {
  cursor: pointer;
  font-weight: 600;
  color: #f8fafc;
}

.how-to ul {
  padding-left: 18px;
  margin: 10px 0 0;
}

.toast-stack {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: grid;
  gap: 8px;
  z-index: 20;
}

.toast {
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(148, 163, 184, 0.4);
  color: #f8fafc;
  padding: 10px 14px;
  border-radius: 10px;
  font: 600 13px/1.2 Poppins, sans-serif;
  box-shadow: 0 10px 20px rgba(2, 6, 23, 0.4);
  animation: toast-in 250ms ease;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.ad-slot {
  margin-top: 28px;
  background: rgba(15, 23, 42, 0.6);
  border: 1px dashed rgba(148, 163, 184, 0.4);
  border-radius: 12px;
  padding: 18px;
  text-align: center;
  color: var(--muted);
}

@media (min-width: 980px) {
  .game-shell {
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.7fr);
  }
}

@media (max-width: 600px) {
  .stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  }

  .button {
    flex: 1 1 auto;
  }

  .toast-stack {
    right: 12px;
    bottom: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
