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

/* ── Body ────────────────────────────────────── */
body {
  font-family: "Space Grotesk", sans-serif;
  background: var(--cyber-black);
  background-image:
    radial-gradient(circle at 20% 50%, rgba(102,126,234,.15) 0%, transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(181,55,255,.15) 0%, transparent 50%),
    radial-gradient(circle at 40% 20%, rgba(255,0,110,.10) 0%, transparent 50%);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: -webkit-fill-available;
  overflow-x: hidden;
  position: relative;
  line-height: 1.6;
  /* Prevent text size adjustment on orientation change */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* Smoother momentum scrolling on iOS */
  -webkit-overflow-scrolling: touch;
}

/* Cyber grid overlay */
body::before {
  content: '';
  position: fixed; inset: 0;
  background-image:
    linear-gradient(rgba(0,247,255,.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0,247,255,.03) 1px, transparent 1px);
  background-size: 50px 50px;
  animation: gridMove 20s linear infinite;
  pointer-events: none;
  z-index: 0;
}

/* ── Particle canvas ─────────────────────────── */
#particle-canvas {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: .6;
}

/* ── Nav bar ─────────────────────────────────── */
.nav-bar {
  position: fixed; top: 0; left: 0; right: 0;
  height: 70px;
  background: rgba(10,10,10,.85);
  backdrop-filter: blur(30px) saturate(180%);
  border-bottom: 1px solid var(--glass-medium);
  box-shadow: 0 4px 30px rgba(0,0,0,.5), 0 0 60px rgba(102,126,234,.1);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  z-index: 1000;
  animation: navSlideDown .8s var(--ease-expo);
  /* Safe area for notch phones */
  padding-left: max(20px, env(safe-area-inset-left));
  padding-right: max(20px, env(safe-area-inset-right));
}

.nav-left, .nav-right { display: flex; align-items: center; gap: 12px; }

.nav-center {
  display: flex; align-items: center; gap: 15px;
  flex: 1; margin: 0 20px; justify-content: center;
  cursor: pointer;
}

/* ── Sidebar ─────────────────────────────────── */
.sidebar {
  position: fixed; top: 70px; left: -300px;
  width: 300px; height: calc(100vh - 70px);
  /* iOS safe height */
  height: calc(100dvh - 70px);
  background: rgba(10,10,10,.95);
  backdrop-filter: blur(40px) saturate(180%);
  border-right: 1px solid var(--glass-strong);
  transition: left .5s var(--ease-expo);
  z-index: 999; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: 4px 0 40px rgba(0,0,0,.5);
}
.sidebar.active { left: 0; }
.sidebar-content { padding: 30px 20px; }
.sidebar-section { margin-bottom: 30px; }
.sidebar-section-title {
  font-family: "Orbitron", sans-serif;
  font-size: .75rem; font-weight: 700;
  color: var(--neon-blue);
  text-transform: uppercase; letter-spacing: 2px;
  margin-bottom: 15px; padding-left: 5px;
  text-shadow: 0 0 10px rgba(0,247,255,.5);
}

/* ── Search overlay ──────────────────────────── */
.search-overlay {
  position: fixed; top: 70px; left: 0; right: 0;
  background: rgba(10,10,10,.98);
  backdrop-filter: blur(40px) saturate(180%);
  border-bottom: 1px solid var(--glass-strong);
  padding: 30px 20px;
  transform: translateY(-100%);
  transition: transform .5s var(--ease-expo);
  z-index: 998;
  box-shadow: 0 8px 40px rgba(0,0,0,.6);
}
.search-overlay.active { transform: translateY(0); }
.search-container { max-width: 700px; margin: 0 auto; }

/* ── Liked sidebar ───────────────────────────── */
.liked-sidebar {
  position: fixed; top: 70px; right: -100%;
  width: 100%; max-width: 350px;
  height: calc(100vh - 70px);
  height: calc(100dvh - 70px);
  background: rgba(10,10,10,.95);
  backdrop-filter: blur(40px) saturate(180%);
  border-left: 1px solid var(--glass-strong);
  transition: right .5s var(--ease-expo);
  z-index: 999; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: -4px 0 40px rgba(0,0,0,.5);
}
.liked-sidebar.active { right: 0; }

/* ── Main content ────────────────────────────── */
.main-content {
  margin-top: 70px;
  padding: 40px 20px 160px;
  /* Extra bottom padding for now-playing bar + home indicator on iOS */
  padding-bottom: max(160px, calc(90px + env(safe-area-inset-bottom)));
  max-width: 1400px;
  margin-left: auto; margin-right: auto;
  display: flex; flex-direction: column;
  min-height: calc(100vh - 70px);
  transition: opacity .3s ease;
  z-index: 2; position: relative;
}
.main-content.fade { opacity: .3; }

/* ── Hero ────────────────────────────────────── */
.hero-section {
  text-align: center;
  margin-bottom: 60px;
  padding: 60px 20px;
  position: relative;
  animation: heroFadeIn 1s var(--ease-expo) .3s both;
}

/* ── Results section ─────────────────────────── */
.results-section {
  margin-bottom: 60px; flex: 1;
  animation: fadeInUp 1s var(--ease-expo) 1.2s both;
  width: 100%;
}
.section-header {
  display: flex; align-items: center;
  justify-content: center; gap: 15px;
  margin-bottom: 30px;
}
.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px,1fr));
  gap: 20px;
}
#results:not(.results-grid) {
  display: flex; justify-content: center;
  align-items: flex-start; width: 100%;
}

/* ── DNA background ──────────────────────────── */
.dna-background { position: fixed; inset: 0; z-index: -1; overflow: hidden; }
.dna-line {
  position: absolute;
  background: linear-gradient(to bottom, transparent, var(--neon-blue), transparent);
  opacity: .15;
  animation: moveDNA 12s linear infinite;
  filter: blur(1px);
}

/* ── Now Playing bar ─────────────────────────── */
.now-playing-bar {
  position: fixed; bottom: -110px; left: 0; right: 0;
  z-index: 2000;
  background: rgba(10,10,10,.96);
  backdrop-filter: blur(30px) saturate(200%);
  border-top: 1px solid var(--glass-strong);
  box-shadow: 0 -8px 40px rgba(0,247,255,.15);
  transition: bottom .5s var(--ease-expo);
  /* Safe area for iPhone home indicator */
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.now-playing-bar.visible { bottom: 0; }
.np-progress { height: 3px; background: rgba(255,255,255,.08); width: 100%; }
.np-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--neon-blue), var(--neon-purple));
  width: 0%; transition: width 1s linear;
  box-shadow: 0 0 8px rgba(0,247,255,.6);
}
.np-content {
  display: flex; align-items: center;
  justify-content: space-between;
  padding: 12px 20px 14px; gap: 15px;
  max-width: 1400px; margin: 0 auto;
  /* Safe area sides */
  padding-left: max(20px, env(safe-area-inset-left));
  padding-right: max(20px, env(safe-area-inset-right));
}

/* ── Privacy notice ──────────────────────────── */
.privacy-notice {
  padding: 20px; text-align: center;
  font-size: .9rem; color: rgba(255,255,255,.6);
  background: var(--glass-light);
  backdrop-filter: blur(15px);
  border-radius: 15px; border: 1px solid var(--glass-medium);
  margin-top: auto;
  animation: fadeInUp 1s var(--ease-expo) 1.5s both;
}

/* ── Nav breadcrumb ──────────────────────────── */
.nav-breadcrumb {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 0 20px;
  animation: fadeInUp .4s var(--ease-expo);
}
.breadcrumb-sep   { color: var(--text-secondary); font-size: .8rem; }
.breadcrumb-current { font-size: .9rem; color: var(--text-secondary); font-weight: 500; font-style: italic; }

/* ── Liked sidebar nav row ───────────────────── */
.liked-sidebar-nav { display: flex; gap: 10px; padding: 0 0 15px; margin-bottom: 5px; border-bottom: 1px solid var(--glass-medium); }

/* ═══════════════════════════════════════════════
   RESPONSIVE — MOBILE FIRST
   ═══════════════════════════════════════════════ */

/* ── 768px and below ─────────────────────────── */
@media (max-width: 768px) {
  .nav-bar           { padding: 0 15px; height: 65px; }
  .nav-bar           { padding-left: max(15px, env(safe-area-inset-left)); padding-right: max(15px, env(safe-area-inset-right)); }
  .sidebar           { width: 280px; left: -280px; top: 65px; height: calc(100dvh - 65px); }
  .liked-sidebar     { max-width: 320px; top: 65px; height: calc(100dvh - 65px); }
  .search-overlay    { top: 65px; padding: 25px 15px; }
  .main-content      { margin-top: 65px; padding: 30px 15px; padding-bottom: max(140px, calc(80px + env(safe-area-inset-bottom))); }
  .hero-section      { padding: 40px 15px; }
  .results-grid      { grid-template-columns: repeat(auto-fill, minmax(160px,1fr)); gap: 14px; }
  .np-content        { padding: 10px 15px 12px; }
  .nav-breadcrumb    { padding: 8px 0 15px; gap: 8px; }
}

/* ── 480px and below ─────────────────────────── */
@media (max-width: 480px) {
  .results-grid      { grid-template-columns: repeat(2,1fr); gap: 12px; }
  .nav-center        { margin: 0 10px; }
  .main-content      { padding: 20px 12px; padding-bottom: max(130px, calc(80px + env(safe-area-inset-bottom))); }
  /* Full width liked sidebar on small screens */
  .liked-sidebar     { max-width: 100%; border-left: none; border-top: 1px solid var(--glass-strong); }
}

/* ── Landscape mode on mobile ────────────────── */
@media (max-height: 500px) and (orientation: landscape) {
  .nav-bar        { height: 55px; }
  .sidebar        { top: 55px; height: calc(100dvh - 55px); }
  .liked-sidebar  { top: 55px; height: calc(100dvh - 55px); }
  .search-overlay { top: 55px; }
  .main-content   { margin-top: 55px; padding-top: 15px; }
  .hero-section   { display: none; } /* hide hero in landscape to save space */
}

/* ── Touch targets — ensure minimum 44px on all interactive elements ── */
@media (pointer: coarse) {
  .hamburger-btn,
  .search-toggle-btn,
  .liked-nav-btn    { min-width: 44px; min-height: 44px; }

  .np-btn           { min-width: 44px; min-height: 44px; }
  .np-play          { min-width: 48px; min-height: 48px; }

  .history-chip     { padding: 10px 18px; }
  .sidebar-item     { padding: 16px; min-height: 48px; }
  .liked-song-card  { padding: 14px; min-height: 56px; }
  .like-btn         { min-height: 36px; padding: 10px 14px; }

  .playlist-card-overlay .playlist-play-btn { min-width: 48px; min-height: 48px; }

  /* Larger breadcrumb button */
  .breadcrumb-home-btn { padding: 12px 20px; min-height: 44px; }
  .playlist-back-btn   { padding: 12px 22px; min-height: 44px; }
}