@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap');

/* --- VARIABILI OTTIMIZZATE (Zero Blur) --- */
:root {
  --amethyst: #8004b5;
  --amethyst-low: rgba(128, 4, 181, 0.15);
  --amethyst-mid: rgba(128, 4, 181, 0.4);
  --bg-dark: #121212;
  --bg-card: #1e1e1e;
  --bg-sidebar: #0f0f0f;
  --text-main: #e0e0e0;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- BASE --- */
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body, html {
  margin: 0; padding: 0;
  height: 100%;
  background: #121212; /* Colore solido invece di gradienti complessi per lo scroll */
  font-family: 'Poppins', sans-serif;
  color: var(--text-main);
  overflow-x: hidden;
}

.app-container {
  display: flex;
  flex-direction: column;
  padding: 20px 24px 160px;
  max-width: 1400px;
  margin: 0 auto;
}

/* --- HEADER --- */
header {
  display: flex;
  align-items: center;
  gap: 15px;
  margin-bottom: 30px;
}

header h1 {
  margin: 0;
  font-size: 2rem;
  color: var(--amethyst);
  letter-spacing: -1px;
}

header p {
  margin: 0;
  color: #666;
  font-style: italic;
}

/* --- SIDEBAR (Hardware Accelerated) --- */
/* Sidebar che si sovrappone a tutto */
#sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 280px;
  height: 100vh;
  background: rgba(15, 15, 15, 0.98); /* Quasi nero solido per performance */
  border-right: 1px solid var(--amethyst);
  z-index: 9999; /* Il valore più alto per stare sopra ricerca e player */
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform;
}

#sidebar.open {
  transform: translateX(0);
}

/* Overlay scuro con blur sul resto della pagina */
/* Aggiungeremo questo elemento via JS quando apri il menu */
.sidebar-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.7); /* Oscura lo sfondo */
  backdrop-filter: blur(8px);    /* Effetto blur solo quando il menu è aperto */
  -webkit-backdrop-filter: blur(8px);
  z-index: 9998; /* Appena sotto la sidebar */
  opacity: 0;
  animation: fadeIn 0.3s forwards;
}

@keyframes fadeIn {
  to { opacity: 1; }
}

#sidebar.open { transform: translateX(0); }

.sidebar-content { padding: 30px; }
.sidebar-content h3 { color: var(--amethyst); border-bottom: 1px solid var(--amethyst-low); padding-bottom: 10px; }
.sidebar-content ul { list-style: none; padding: 0; }
.sidebar-content li { margin-bottom: 10px; }
.sidebar-content a {
  color: #fff;
  text-decoration: none;
  padding: 10px 15px;
  border-radius: 8px;
  display: block;
  transition: background var(--transition);
}
.sidebar-content a:hover { background: var(--amethyst-low); color: var(--amethyst); }

#sidebarToggle {
  background: var(--amethyst-low);
  border: 1px solid var(--amethyst);
  color: var(--amethyst);
  font-size: 1.2rem;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
}

/* --- GRIDS (Playlist & Artisti) --- */
.app-container h2 { color: var(--amethyst); margin: 20px 0 15px; }

#playlistGrid, #artistGrid, #customPlaylists {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  width: 100%;
}

/* --- CARDS (Flat Modern Style) --- */
.track-card, .artist-card, .playlist-card {
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.05);
  border-radius: 12px;
  padding: 15px;
  cursor: pointer;
  transition: transform var(--transition), border-color var(--transition);
  will-change: transform;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.track-card:hover, .artist-card:hover {
  transform: translateY(-5px);
  border-color: var(--amethyst);
}

.track-card.active {
  background: var(--amethyst);
  color: white;
  border-color: #fff;
}

.track-card .card-cover, .artist-card img {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 8px;
  object-fit: cover;
  margin-bottom: 10px;
}

.artist-card { border-radius: 50% 50% 12px 12px; } /* Stile moderno per artisti */
.artist-card img { border-radius: 50%; }

/* --- SEARCH (Posizionata in alto a destra) --- */
#searchContainer {
  position: absolute; /* Per stare in alto rispetto al flusso */
  top: 20px;
  right: 24px;
  width: 250px;
  z-index: 2100; /* Sopra la sidebar se necessario */
}

#searchInput {
  width: 100%;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--amethyst-mid);
  background: var(--bg-card);
  color: #fff;
  font-size: 0.9rem;
  transition: all var(--transition);
}

#searchResults {
  background: var(--bg-panel);
  border: 1px solid var(--amethyst);
  border-radius: 12px;
  margin-top: 5px;
  max-height: 250px;
  overflow-y: auto;
}
 
/* --- BOTTOM BAR (Fixed & Flat) --- */
#bottomBar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 100px;
  background: #181818;
  border-top: 2px solid var(--amethyst);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 20px;
  z-index: 3000;
}

#playerContainer {
  width: 400px;
  height: 80px;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
}

iframe { width: 100%; height: 100%; border: none; }

.control-btn {
  background: var(--amethyst-low);
  border: 1px solid var(--amethyst);
  color: var(--amethyst);
  width: 45px; height: 45px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  transition: all var(--transition);
}

.control-btn:hover { background: var(--amethyst); color: #fff; }

/* --- NOW PLAYING --- */
#nowPlaying {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}

#nowPlaying img.cover {
  width: 60px; height: 60px;
  border-radius: 6px;
  object-fit: cover;
}

.info .title { color: var(--amethyst); font-weight: 700; display: block; }
.info .artist { font-size: 0.9rem; opacity: 0.7; }

/* --- POPUPS & DIALOGS (Solid) --- */
.artist-popup, .playlist-popup, .add-song-dialog {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: #1a1a1a;
  border: 2px solid var(--amethyst);
  border-radius: 16px;
  padding: 24px;
  z-index: 4000;
  max-width: 400px;
  width: 90%;
}

.track-item {
  padding: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  cursor: pointer;
}
.track-item:hover { background: var(--amethyst-low); }

/* --- FIX MOBILE: Tasti affiancati e Menu posizionato correttamente --- */
@media (max-width: 768px) {

        #sidebarToggle {
          position: static !important;
          display: block !important;
          margin-left: 0 !important;   /* Lo spinge a sinistra */
          margin-right: auto !important; /* Assicura che non ci sia spazio a sinistra */
          margin-top: 0px;            /* Distanza dalla barra di ricerca fissa */
          width: fit-content;          /* Impedisce al tasto di allargarsi a tutto schermo */
          background: var(--bg-panel);
          border: 1px solid var(--amethyst);
          padding: 8px 12px;
          border-radius: 8px;
          z-index: 1;
        }
        /* Stile tasto */
        background: var(--bg-panel);
        border: 1px solid var(--amethyst);
        padding: 8px 12px;
        border-radius: 8px;
        width: auto;
        display: block;
      }

  /* 2. Barra di ricerca fissa a tutto schermo */
  #searchContainer {
    position: fixed;
    top: 0; left: 0; right: 0;
    width: 100%;
    padding: 10px;
    background: var(--bg-dark);
    border-bottom: 1px solid var(--amethyst-mid);
    z-index: 3000;
  }

  /* 3. Forza i tasti del Player ad essere affiancati */
  #bottomBar {
    display: flex !important;
    flex-direction: row !important; /* Forza l'allineamento orizzontale */
    flex-wrap: wrap;               /* Permette al player di andare sotto se non c'è spazio */
    justify-content: center;
    align-items: center;
    gap: 10px;
    padding: 10px;
    height: auto;
  }

  /* Raggruppa i pulsanti di controllo */
  .control-btn {
    display: flex !important;
    width: 45px  !important; /* Impedisce che prendano tutta la larghezza */
    height: 45px;
    margin: 0 !important;
    padding: 0 ; /* Non permette ai tasti di espandersi */
      justify-content: center;
      align-items: center;
  }

  /* 4. Player e Info */
  #playerContainer {
    width: 100% !important; /* Il player sta su una riga tutta sua sotto i tasti */
    order: 3;
    height: 70px;
  }

  #nowPlaying {
    width: 100%;
    order: 1;
    justify-content: center;
    margin-bottom: 5px;
  }

  /* Nascondi tasto ingrandimento su mobile */
  #toggleNowPlayingBtn {
    display: none !important;
  }

  /* 5. Header centrato (sotto la barra di ricerca) */
  header {
    margin-top: 80px; 
    text-align: center;
    flex-direction: column;
  }

/* All'interno di @media (max-width: 768px) */

#searchResults {
  max-height: 300px;
}

/* Se i risultati della ricerca usano la classe .track-card o simili */
#searchResults .track-card, 
#searchResults .track-item {
  flex-direction: row; /* Disposizione orizzontale per risparmiare spazio */
  text-align: left;
  padding: 8px;
  gap: 10px;
}

#searchResults .card-cover, 
#searchResults img {
  width: 40px !important;  /* Copertina piccola tipo lista */
  height: 40px !important;
  margin-bottom: 0;       /* Rimuove il margine inferiore delle card standard */
}

#searchResults .info {
  font-size: 0.8rem;
}

  header h1 { font-size: 2.2rem; }

  /* Playlist e Brani più piccoli */
  #playlistGrid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)) !important;
  }
  .track-card { padding: 6px; font-size: 0.8rem; }
}