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

:root {
  --bg: #0a0e1a;
  --surface: #161b2e;
  --surface-2: #1f2740;
  --surface-3: #2a3556;
  --border: #3a4668;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #8b5cf6;
  --primary-light: #a78bfa;
  --primary-dark: #6d28d9;
  --accent: #06b6d4;
  --accent-light: #22d3ee;
  --green: #10b981;
  --red: #ef4444;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  background-image:
    radial-gradient(circle at 15% 25%, rgba(139, 92, 246, 0.08) 0%, transparent 40%),
    radial-gradient(circle at 85% 70%, rgba(6, 182, 212, 0.07) 0%, transparent 45%);
  background-attachment: fixed;
}

/* ── Topbar ── */
.topbar {
  background: rgba(10, 14, 26, 0.85);
  border-bottom: 1px solid var(--border);
  padding: 0.55rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.2s;
}
.back-link:hover { color: var(--text); }

.topbar-actions {
  display: flex;
  gap: 0.5rem;
}

.icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  width: 34px;
  height: 34px;
  border-radius: 0.5rem;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  line-height: 1;
}
.icon-btn:hover {
  background: var(--surface-2);
  border-color: var(--primary);
}

/* ── Header ── */
.game-header {
  background: linear-gradient(135deg, rgba(31, 39, 64, 0.6) 0%, rgba(10, 14, 26, 0.6) 100%);
  border-bottom: 1px solid var(--border);
  padding: 1.5rem 1.5rem 1rem;
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.title-block h1 {
  font-size: 2.2rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary-light) 0%, var(--accent-light) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.title-block p {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
  max-width: 480px;
  line-height: 1.5;
}

.status-block {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.35rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  font-size: 0.78rem;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: all 0.3s;
}
.status-dot.active {
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
  animation: pulse 1.5s ease-in-out infinite;
}

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

.status-counter {
  font-size: 0.75rem;
  color: var(--text-muted);
}
.status-counter #active-count {
  color: var(--primary-light);
  font-weight: 700;
}

/* ── Master Volume ── */
.master-section {
  max-width: 1100px;
  margin: 1.25rem auto 0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

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

.master-volume {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: var(--surface-2);
  border-radius: 999px;
  outline: none;
  cursor: pointer;
}
.master-volume::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  cursor: pointer;
  border: 2px solid var(--text);
  box-shadow: 0 0 8px rgba(139, 92, 246, 0.5);
}
.master-volume::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: 2px solid var(--text);
}

.master-value {
  font-size: 0.78rem;
  color: var(--primary-light);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 42px;
  text-align: right;
}

/* ── Presets ── */
.presets-section {
  max-width: 1100px;
  margin: 1.5rem auto 0;
  padding: 0 1.5rem;
}

.section-title {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  font-weight: 700;
  margin-bottom: 0.75rem;
}

.presets-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.preset-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.95rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.preset-btn:hover {
  background: var(--surface-2);
  border-color: var(--primary);
  transform: translateY(-1px);
}
.preset-btn .preset-emoji {
  font-size: 1rem;
  line-height: 1;
}

/* ── Sound Grid ── */
.game-main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 2rem;
}

.sound-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 0.85rem;
}

.sound-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.875rem;
  padding: 1rem 0.875rem 0.75rem;
  cursor: pointer;
  position: relative;
  user-select: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  overflow: hidden;
  transition: transform 0.18s ease, border-color 0.2s ease, background 0.2s ease;
}

.sound-tile::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--tile-color, var(--primary)) 0%, transparent 100%);
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.sound-tile:hover {
  border-color: var(--tile-color, var(--primary));
  transform: translateY(-2px);
  background: var(--surface-2);
}
.sound-tile:hover::before {
  opacity: 0.08;
}

.sound-tile.active {
  border-color: var(--tile-color, var(--primary));
  background: var(--surface-2);
  box-shadow: 0 0 0 1px var(--tile-color, var(--primary)), 0 8px 24px rgba(0, 0, 0, 0.3);
}
.sound-tile.active::before {
  opacity: 0.18;
  animation: shimmer 4s ease-in-out infinite;
}

@keyframes shimmer {
  0%, 100% { opacity: 0.12; }
  50% { opacity: 0.22; }
}

.sound-icon {
  font-size: 2.4rem;
  line-height: 1;
  position: relative;
  z-index: 1;
  transition: transform 0.3s;
}

.sound-tile.active .sound-icon {
  animation: bob 2.4s ease-in-out infinite;
}

@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

.sound-name {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text);
  position: relative;
  z-index: 1;
  text-align: center;
  line-height: 1.2;
}

/* Volume slider inside tile */
.tile-volume {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--surface-3);
  border-radius: 999px;
  outline: none;
  cursor: pointer;
  position: relative;
  z-index: 1;
  margin-top: 0.15rem;
  opacity: 0.4;
  transition: opacity 0.2s;
}
.sound-tile.active .tile-volume {
  opacity: 1;
}
.tile-volume::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--tile-color, var(--primary));
  cursor: pointer;
  border: 1px solid var(--text);
}
.tile-volume::-moz-range-thumb {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--tile-color, var(--primary));
  cursor: pointer;
  border: 1px solid var(--text);
}

.tile-value {
  font-size: 0.65rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  position: relative;
  z-index: 1;
  min-height: 0.8rem;
}
.sound-tile.active .tile-value {
  color: var(--tile-color, var(--primary-light));
}

/* ── Footer ── */
.game-footer {
  text-align: center;
  padding: 1.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

/* ── Mobile ── */
@media (max-width: 600px) {
  .header-inner {
    flex-direction: column;
    align-items: flex-start;
  }
  .status-block {
    align-items: flex-start;
    width: 100%;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }
  .title-block h1 {
    font-size: 1.7rem;
  }
  .sound-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.6rem;
  }
  .sound-icon {
    font-size: 2rem;
  }
  .sound-name {
    font-size: 0.75rem;
  }
}
