* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: #0c0c12;
  color: #e4e4f0;
  cursor: none;
  -webkit-text-size-adjust: 100%;
}

body.ui-visible {
  cursor: default;
}

#canvas {
  display: block;
  width: 100%;
  height: 100%;
  position: fixed;
  inset: 0;
  z-index: 0;
}

/* =====================
   BACKGROUND GLOW
   ===================== */

.bg-glow {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: linear-gradient(
    to top,
    var(--glow-color, transparent) 0%,
    transparent 55%
  );
  transition: background 3s ease;
}

/* =====================
   UI AUTO-HIDE SYSTEM
   ===================== */

.top-bar,
.player-bar {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
}

body.ui-visible .top-bar,
body.ui-visible .player-bar {
  opacity: 1;
  pointer-events: auto;
}

/* =====================
   TOP STATION BAR
   ===================== */

.top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1.1rem 1rem 2rem;
  padding-top: max(1.1rem, env(safe-area-inset-top));
  background: linear-gradient(to bottom,
    rgba(12, 12, 22, 0.88) 0%,
    rgba(12, 12, 22, 0.0) 100%
  );
}

.station-track {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex: 1;
  overflow-x: auto;
  scroll-behavior: smooth;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  padding: 4px 2px;
}
.station-track::-webkit-scrollbar { display: none; }

.chip-divider {
  width: 1px;
  height: 20px;
  background: rgba(255, 255, 255, 0.12);
  flex-shrink: 0;
  margin: 0 0.2rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.38rem 0.85rem;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  font-size: 0.82rem;
  color: rgba(228, 228, 240, 0.85);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.chip:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.chip.active {
  background: rgba(150, 170, 240, 0.18);
  border-color: rgba(150, 170, 240, 0.5);
  color: #fff;
  font-weight: 500;
}

.chip-icon {
  font-size: 0.95rem;
  line-height: 1;
}

.arrow-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: rgba(228, 228, 240, 0.9);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s ease, opacity 0.2s ease;
}

.arrow-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

.arrow-btn:disabled {
  opacity: 0.25;
  cursor: default;
}

/* =====================
   BOTTOM PLAYER BAR
   ===================== */

.player-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.9rem 1.25rem 1.1rem;
  padding-bottom: max(1.1rem, env(safe-area-inset-bottom));
  background: linear-gradient(to top,
    rgba(12, 12, 22, 0.88) 0%,
    rgba(12, 12, 22, 0.0) 100%
  );
}

.bar-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: rgba(228, 228, 240, 0.85);
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, opacity 0.2s ease;
  flex-shrink: 0;
}

.icon-btn:hover { background: rgba(255, 255, 255, 0.16); color: #fff; }
.icon-btn:disabled { opacity: 0.3; cursor: default; }
.icon-btn.muted { color: rgba(240, 110, 110, 0.9); border-color: rgba(240,110,110,0.25); }

.volume-wrap { display: flex; align-items: center; }

.volume-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 72px;
  height: 3px;
  background: linear-gradient(to right, rgba(208,216,248,0.6) 100%, rgba(255,255,255,0.18) 100%);
  border-radius: 3px;
  cursor: pointer;
  outline: none;
}

.volume-slider::-moz-range-progress {
  background: rgba(208, 216, 248, 0.6);
  border-radius: 3px;
  height: 3px;
}

.volume-slider::-moz-range-track {
  background: rgba(255, 255, 255, 0.18);
  border-radius: 3px;
  height: 3px;
}

.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #d0d8f8;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}

.volume-slider::-webkit-slider-thumb:hover {
  transform: scale(1.25);
  background: #fff;
}

.volume-slider::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #d0d8f8;
  cursor: pointer;
  border: none;
}

.bar-now-playing {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.84rem;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.np-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #6ee87a;
  box-shadow: 0 0 6px #6ee87a;
  animation: blink 2s ease-in-out infinite;
  flex-shrink: 0;
}

.np-dot.idle {
  background: rgba(228, 228, 240, 0.25);
  box-shadow: none;
  animation: none;
}

.np-dot.paused {
  background: rgba(228, 228, 240, 0.35);
  box-shadow: none;
  animation: none;
}

.np-dot.buffering {
  background: #f0c060;
  box-shadow: 0 0 6px #f0c060;
  animation: pulse-buffer 1s ease-in-out infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}

@keyframes pulse-buffer {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%      { transform: scale(1.4); opacity: 0.5; }
}

.np-station {
  font-weight: 500;
  color: #f0f0fa;
  flex-shrink: 0;
}

.np-sep {
  color: rgba(228, 228, 240, 0.3);
  flex-shrink: 0;
}

.np-track {
  color: rgba(228, 228, 240, 0.68);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: opacity 0.35s ease;
}

.np-track.fading { opacity: 0; }

.hidden { display: none !important; }

/* =====================
   TOAST
   ===================== */
.toast {
  position: fixed;
  bottom: 5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  padding: 0.6rem 1.2rem;
  background: rgba(20, 20, 36, 0.93);
  border: 1px solid rgba(160, 170, 220, 0.25);
  border-radius: 10px;
  font-size: 0.84rem;
  color: rgba(208, 216, 248, 0.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
  transition: opacity 0.3s ease;
}

.toast.show { opacity: 1; }

.toast.error {
  background: rgba(28, 16, 16, 0.93);
  border-color: rgba(240, 100, 100, 0.3);
  color: #f0b8b8;
}

/* =====================
   SLEEP BUTTON + INDICATOR
   ===================== */
.sleep-btn {
  margin-left: 0.15rem;
}

.sleep-btn.sleep-active {
  color: #a78bfa;
  border-color: rgba(167, 139, 250, 0.35);
  background: rgba(167, 139, 250, 0.1);
}

.sleep-indicator {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 15;
  padding: 0.3rem 0.65rem;
  font-size: 0.72rem;
  color: rgba(167, 139, 250, 0.8);
  letter-spacing: 0.03em;
  pointer-events: none;
  user-select: none;
}

/* =====================
   SITE WORDMARK
   ===================== */
.site-wordmark {
  margin-left: auto;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: rgba(208, 216, 248, 0.35);
  user-select: none;
  flex-shrink: 0;
  transition: color 0.3s ease;
}

.site-wordmark:hover {
  color: rgba(208, 216, 248, 0.6);
}

.wordmark-dot {
  background: linear-gradient(135deg, #ff6b6b, #339af0, #cc5de8);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.site-credit {
  font-size: 0.7rem;
  color: rgba(208, 216, 248, 0.35);
  user-select: none;
  white-space: nowrap;
  margin-left: 0.75rem;
}

.credit-link {
  color: inherit;
  text-decoration: none;
  transition: color 0.2s ease;
}

.credit-link:hover {
  color: rgba(208, 216, 248, 0.7);
}

/* =====================
   KEYBOARD HINT OVERLAY
   ===================== */
.hint-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  cursor: pointer;
}

.hint-overlay.hidden {
  display: none !important;
}

.hint-box {
  background: rgba(20, 20, 36, 0.97);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 1.6rem 2rem;
  min-width: 280px;
  max-width: 90vw;
  box-shadow: 0 24px 64px rgba(0,0,0,0.5);
  pointer-events: none;
}

.hint-title {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(228, 228, 240, 0.4);
  margin-bottom: 1.1rem;
}

.hint-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 0.7rem;
  font-size: 0.88rem;
  color: rgba(228, 228, 240, 0.85);
}

.hint-row span {
  margin-left: auto;
  color: rgba(228, 228, 240, 0.5);
  font-size: 0.82rem;
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 26px;
  padding: 0 0.4rem;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.78rem;
  color: #d0d8f8;
}

.hint-close {
  margin-top: 1.2rem;
  font-size: 0.72rem;
  color: rgba(228, 228, 240, 0.25);
  text-align: center;
}

/* =====================
   MOBILE / RESPONSIVE
   ===================== */

@media (max-width: 640px) {
  .top-bar {
    gap: 0.3rem;
    padding: 0.75rem 0.5rem 1.5rem;
    padding-top: max(0.75rem, env(safe-area-inset-top));
  }

  .arrow-btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
  }

  .chip {
    padding: 0.5rem 0.75rem;
    font-size: 0.78rem;
    min-height: 40px;
  }

  .chip-icon {
    font-size: 1.05rem;
  }

  .player-bar {
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.7rem 0.75rem 0.9rem;
    padding-bottom: max(0.9rem, env(safe-area-inset-bottom));
  }

  .bar-controls {
    gap: 0.4rem;
  }

  .icon-btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
  }

  .icon-btn svg {
    width: 18px;
    height: 18px;
  }

  .volume-slider {
    width: 56px;
    height: 4px;
  }

  .volume-slider::-webkit-slider-thumb {
    width: 20px;
    height: 20px;
  }

  .volume-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
  }

  .site-wordmark {
    display: none;
  }

  .bar-now-playing {
    order: 1;
    flex-basis: 100%;
    font-size: 0.78rem;
    gap: 0.35rem;
    justify-content: center;
  }

  .np-station {
    max-width: 50%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .toast {
    left: 1rem;
    right: 1rem;
    transform: none;
    text-align: center;
    white-space: normal;
    font-size: 0.82rem;
  }
}

@media (max-width: 380px) {
  .chip {
    padding: 0.45rem 0.6rem;
    font-size: 0.74rem;
  }

  .volume-wrap {
    display: none;
  }

  .bar-now-playing {
    font-size: 0.74rem;
  }
}

@media (hover: none) and (pointer: coarse) {
  .chip:hover {
    background: rgba(255, 255, 255, 0.06);
    color: rgba(228, 228, 240, 0.85);
  }
  .chip.active:hover {
    background: rgba(150, 170, 240, 0.18);
    color: #fff;
  }
  .arrow-btn:hover {
    background: rgba(255, 255, 255, 0.08);
  }
  .icon-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: rgba(228, 228, 240, 0.85);
  }
}

@media (display-mode: standalone) {
  .top-bar {
    padding-top: max(2rem, env(safe-area-inset-top));
  }
}

/* =====================
   REDUCED MOTION
   ===================== */

@media (prefers-reduced-motion: reduce) {
  .np-dot,
  .np-dot.buffering {
    animation: none;
  }

  .top-bar,
  .player-bar {
    transition: none;
  }

  .chip {
    transition: none;
  }

  .np-track {
    transition: none;
  }

  .toast {
    transition: none;
  }

  .icon-btn {
    transition: none;
  }

  .arrow-btn {
    transition: none;
  }

  .volume-slider::-webkit-slider-thumb {
    transition: none;
  }
}
