/* Ambient layer: particle background + audio controls for all pages */
:root {
  --ambient-border:     rgba(255,255,255,0.05);
  --ambient-accent-dim: rgba(0,229,160,0.06);
}

/* ── Canvas BG ── */
#scene-bg {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 0;
  pointer-events: none;
}

/* ── Audio toggle ── */
#audio-toggle {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  right: calc(24px + env(safe-area-inset-right, 0px));
  z-index: 500;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--ambient-border);
  background: rgba(8,8,13,0.75);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: var(--text-muted, #4a4a5e);
  transition: border-color 0.25s, color 0.25s, background 0.25s, opacity 0.25s;
  opacity: 0.55;
}
#audio-toggle:hover,
#audio-toggle:focus-visible {
  border-color: var(--accent, #00e5a0);
  color: var(--accent, #00e5a0);
  background: var(--ambient-accent-dim);
  opacity: 1;
  outline: none;
}
#audio-toggle.muted { opacity: 0.3; }
#audio-toggle.muted:hover,
#audio-toggle.muted:focus-visible { opacity: 0.7; }
#audio-toggle:not(.audio-unlocked) {
  animation: audio-hint 3s ease-in-out infinite;
}
@keyframes audio-hint {
  0%,100% { opacity: 0.55; }
  50%      { opacity: 0.85; border-color: rgba(0,229,160,0.25); }
}
#audio-toggle svg { width: 16px; height: 16px; fill: currentColor; pointer-events: none; }
#audio-toggle.audio-unlocked:not(.muted) {
  animation: heartbeat 1.8s ease-in-out infinite;
  opacity: 0.8;
}
#audio-toggle.audio-unlocked:not(.muted):hover,
#audio-toggle.audio-unlocked:not(.muted):focus-visible {
  opacity: 1;
  animation-play-state: paused;
}
#audio-toggle.audio-unlocked:not(.muted)::after {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 1px solid rgba(0,229,160,0.55);
  animation: pulse-ring 1.8s ease-out infinite;
  pointer-events: none;
}
@keyframes heartbeat {
  0%,100% { transform: scale(1); }
  6%       { transform: scale(1.09); }
  16%      { transform: scale(1); }
  24%      { transform: scale(1.05); }
  38%      { transform: scale(1); }
}
@keyframes pulse-ring {
  0%   { transform: scale(1);   opacity: 0.6; }
  80%  { transform: scale(1.9); opacity: 0; }
  100% { transform: scale(1.9); opacity: 0; }
}
.audio-icon-off { display: none; }

/* ── Song player widget (prev / name / next) ── */
#audio-player {
  position: fixed;
  bottom: calc(116px + env(safe-area-inset-bottom, 0px));
  right: calc(24px + env(safe-area-inset-right, 0px));
  z-index: 500;
  display: flex;
  align-items: center;
  gap: 1px;
  padding: 0 6px;
  height: 28px;
  border-radius: 14px;
  border: 1px solid var(--ambient-border);
  background: rgba(8,8,13,0.75);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  color: var(--text-muted, #4a4a5e);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.4s, transform 0.4s, border-color 0.25s;
  pointer-events: none;
}
#audio-player.visible {
  opacity: 0.6;
  transform: translateY(0);
  pointer-events: auto;
}
#audio-player:hover {
  opacity: 1;
  border-color: rgba(0,229,160,0.28);
}
#audio-player button {
  background: none;
  border: none;
  padding: 2px;
  cursor: pointer;
  color: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: color 0.2s;
  flex-shrink: 0;
}
#audio-player button:hover,
#audio-player button:focus-visible {
  color: var(--accent, #00e5a0);
  outline: none;
}
#audio-player button svg {
  width: 13px;
  height: 13px;
  fill: currentColor;
  pointer-events: none;
}
#audio-song-name {
  font-size: 9.5px;
  font-family: var(--font-mono, 'JetBrains Mono', monospace);
  letter-spacing: 0.07em;
  padding: 0 5px;
  white-space: nowrap;
  min-width: 46px;
  text-align: center;
  text-transform: uppercase;
}

/* ── SFX toggle ── */
#sfx-toggle {
  position: fixed;
  bottom: calc(70px + env(safe-area-inset-bottom, 0px));
  right: calc(24px + env(safe-area-inset-right, 0px));
  z-index: 500;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--ambient-border);
  background: rgba(8,8,13,0.75);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: var(--text-muted, #4a4a5e);
  transition: border-color 0.25s, color 0.25s, background 0.25s, opacity 0.25s;
  opacity: 0.4;
}
#sfx-toggle:hover,
#sfx-toggle:focus-visible {
  border-color: var(--accent, #00e5a0);
  color: var(--accent, #00e5a0);
  background: var(--ambient-accent-dim);
  opacity: 0.9;
  outline: none;
}
#sfx-toggle.sfx-off { opacity: 0.25; }
#sfx-toggle.sfx-off:hover,
#sfx-toggle.sfx-off:focus-visible { opacity: 0.7; }
#sfx-toggle svg { width: 15px; height: 15px; fill: currentColor; pointer-events: none; }

/* ── Safari/iOS: waiting for first tap to resume audio after cross-page navigation ── */
#audio-toggle.wants-resume {
  animation: safari-resume-hint 1.2s ease-in-out infinite !important;
  opacity: 0.95 !important;
  border-color: rgba(0,229,160,0.45);
  color: var(--accent, #00e5a0);
}
#audio-toggle.wants-resume::after {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 1px solid rgba(0,229,160,0.55);
  animation: pulse-ring 1.2s ease-out infinite;
  pointer-events: none;
}
@keyframes safari-resume-hint {
  0%,100% { transform: scale(1);    border-color: rgba(0,229,160,0.3); }
  50%      { transform: scale(1.1); border-color: rgba(0,229,160,0.7); }
}

/* ── Pixel burst animation ── */
@keyframes btn-sfx-burst {
  0%   { box-shadow: 0 0 0 0 rgba(0,229,160,0.35); }
  60%  { box-shadow: 0 0 0 8px rgba(0,229,160,0); }
  100% { box-shadow: 0 0 0 0 rgba(0,229,160,0); }
}
.btn-sfx-flash { animation: btn-sfx-burst 0.35s ease-out forwards; }

@media (prefers-reduced-motion: reduce) {
  #audio-toggle,
  #audio-toggle::after,
  #sfx-toggle { animation: none !important; }
  #audio-player { transition: none; }
}
