:root {
  --bg: #0f172a;
  --bg-alt: #111827;
  --panel: rgba(17, 24, 39, 0.82);
  --panel-border: rgba(148, 163, 184, 0.14);
  --text: #f8fafc;
  --text-muted: #cbd5f5;
  --accent: #38bdf8;
  --accent-soft: rgba(56, 189, 248, 0.2);
  --danger: #f87171;
  --success: #34d399;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.35);
  --radius-lg: 24px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --transition: 0.18s ease;
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

[data-theme="light"] {
  --bg: #f1f5f9;
  --bg-alt: #e2e8f0;
  --panel: rgba(255, 255, 255, 0.9);
  --panel-border: rgba(15, 23, 42, 0.08);
  --text: #0f172a;
  --text-muted: #475569;
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, 0.12);
  --shadow: 0 16px 30px rgba(15, 23, 42, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: clamp(16px, 2.5vw, 40px);
  position: relative;
}

body::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 15% 25%, rgba(99, 102, 241, 0.32), transparent 55%),
              radial-gradient(circle at 80% 20%, rgba(56, 189, 248, 0.28), transparent 50%),
              radial-gradient(circle at 35% 80%, rgba(244, 114, 182, 0.23), transparent 55%);
  pointer-events: none;
  z-index: -1;
}

.container {
  width: min(1080px, 100%);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
  border-radius: var(--radius-lg);
  padding: clamp(20px, 2.2vw, 32px);
  display: grid;
  gap: clamp(20px, 2vw, 28px);
}

.header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.header h1 {
  margin: 0;
  font-size: clamp(1.8rem, 3vw, 2.4rem);
  letter-spacing: 0.04em;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 14px;
}

.difficulty-control {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

#difficultySelect {
  background: rgba(15, 23, 42, 0.38);
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 0.95rem;
  min-width: 120px;
  transition: border var(--transition), background var(--transition);
}

[data-theme="light"] #difficultySelect {
  background: rgba(255, 255, 255, 0.9);
}

#difficultySelect:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.difficulty-badge {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.82rem;
  max-width: 240px;
  line-height: 1.4;
}

.score-panel {
  display: flex;
  gap: clamp(12px, 2vw, 24px);
  flex-wrap: wrap;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  background: rgba(15, 23, 42, 0.35);
  border: 1px solid var(--panel-border);
}

.score-item {
  display: grid;
  gap: 2px;
  min-width: 90px;
}

.score-item span:first-child {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
}

.score-item span:last-child {
  font-size: 1.35rem;
  font-weight: 600;
}

.game-container {
  display: grid;
  gap: 18px;
}

.target-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.targets {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.target-chip {
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.15);
  color: var(--accent);
  font-size: 0.85rem;
  border: 1px solid rgba(56, 189, 248, 0.25);
}

.moves-progress {
  background: rgba(15, 23, 42, 0.35);
  border-radius: var(--radius-md);
  padding: 16px;
  border: 1px solid var(--panel-border);
  display: grid;
  gap: 10px;
}

.moves-progress__meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.moves-progress__track {
  background: rgba(148, 163, 184, 0.18);
  border-radius: 999px;
  position: relative;
  height: 10px;
  overflow: hidden;
}

.moves-progress__fill {
  position: absolute;
  inset: 0;
  width: 40%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #7dd3fc);
  transition: width 0.25s ease;
}

.game-board {
  --board-size: 8;
  display: grid;
  grid-template-columns: repeat(var(--board-size), 1fr);
  gap: 10px;
  padding: 16px;
  border-radius: var(--radius-lg);
  background: rgba(15, 23, 42, 0.4);
  border: 1px solid var(--panel-border);
  min-height: 420px;
  transition: transform var(--transition);
}

.game-board button {
  position: relative;
  aspect-ratio: 1 / 1;
  border: none;
  border-radius: 20%;
  cursor: pointer;
  background: transparent;
  padding: 0;
  transition: transform 0.14s ease, box-shadow 0.14s ease;
}

.game-board button:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.gem {
  width: 100%;
  height: 100%;
  border-radius: 22%;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.25), rgba(0, 0, 0, 0.25));
  box-shadow: inset 0 4px 7px rgba(255, 255, 255, 0.25), inset 0 -6px 12px rgba(15, 23, 42, 0.35);
  position: relative;
  transition: transform 0.18s ease, filter 0.18s ease;
}

.gem::after {
  content: '';
  position: absolute;
  inset: 18%;
  border-radius: 16%;
  background: var(--gem-color, #fff);
  opacity: 0.9;
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.32);
}

button:active .gem {
  transform: scale(0.94);
}

button.selected .gem {
  transform: scale(1.08);
  filter: brightness(1.15);
  box-shadow: 0 0 0 4px rgba(56, 189, 248, 0.65);
}

.gem--ruby { --gem-color: linear-gradient(135deg, #f43f5e, #be123c); }
.gem--sapphire { --gem-color: linear-gradient(135deg, #60a5fa, #2563eb); }
.gem--emerald { --gem-color: linear-gradient(135deg, #34d399, #059669); }
.gem--topaz { --gem-color: linear-gradient(135deg, #fbbf24, #f59e0b); }
.gem--amethyst { --gem-color: linear-gradient(135deg, #c084fc, #7c3aed); }
.gem--pearl { --gem-color: linear-gradient(135deg, #f8fafc, #cbd5f5); color: #1e293b; }

button.clearing .gem {
  transform: scale(0.6);
  opacity: 0.3;
  filter: blur(2px);
}

.combo-display {
  min-height: 24px;
  font-size: 0.95rem;
  color: var(--accent);
  text-align: center;
  letter-spacing: 0.08em;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.controls button {
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--panel-border);
  background: rgba(15, 23, 42, 0.45);
  color: var(--text);
  font-weight: 500;
  cursor: pointer;
  transition: transform var(--transition), background var(--transition), border var(--transition);
}

.controls button:hover {
  transform: translateY(-2px);
  background: rgba(56, 189, 248, 0.18);
  border-color: rgba(56, 189, 248, 0.35);
}

.controls button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.theme-toggle {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  font-size: 1.1rem;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(15, 23, 42, 0.68);
  backdrop-filter: blur(8px);
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.25s ease;
  padding: 20px;
  z-index: 20;
}

.modal.show {
  visibility: visible;
  opacity: 1;
}

.modal-content {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  padding: clamp(24px, 3vw, 36px);
  width: min(420px, 95vw);
  display: grid;
  gap: 16px;
  text-align: center;
  box-shadow: var(--shadow);
}

.modal-content button {
  justify-self: center;
}

.help-content {
  display: grid;
  gap: 8px;
  text-align: left;
  color: var(--text-muted);
}

.modal-content h2 {
  margin: 0;
  font-size: 1.6rem;
}

#pauseOverlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.62);
  backdrop-filter: blur(6px);
  display: none;
  place-items: center;
  z-index: 15;
}

#pauseOverlay.active {
  display: grid;
}

.pause-overlay__content {
  background: rgba(15, 23, 42, 0.85);
  padding: 20px 32px;
  border-radius: var(--radius-md);
  border: 1px solid var(--panel-border);
  font-size: 1.4rem;
  letter-spacing: 0.12em;
}

@media (max-width: 900px) {
  .container {
    padding: 20px;
  }

  .game-board {
    gap: 8px;
    padding: 14px;
  }
}

@media (max-width: 720px) {
  body {
    padding: 16px;
  }

  .header {
    flex-direction: column;
    align-items: flex-start;
  }

  .header-controls {
    width: 100%;
    justify-content: space-between;
  }

  .game-board {
    min-height: auto;
  }

  .controls {
    justify-content: stretch;
  }

  .controls button {
    flex: 1 1 45%;
  }
}

@media (max-width: 520px) {
  .score-panel {
    width: 100%;
    justify-content: space-between;
  }
}
