:root {
  --bg: #0e0e10;
  --bg-elev: #17171b;
  --bg-elev-2: #1f1f25;
  --bg-bar: rgba(14, 14, 16, 0.85);
  --fg: #ececf1;
  --fg-muted: #8a8a93;
  --accent: #6ee7b7;
  --accent-fg: #053b2a;
  --danger: #f87171;
  --border: #2a2a32;
  --shadow: 0 -8px 24px rgba(0, 0, 0, 0.5);
  --radius: 12px;
  --footer-h: 88px;
  --seek-h: 4px;
  --aside-w: 240px;
  --lyrics-h: 220px;     /* stima altezza pannello lyrics, usato per compensare scroll */
  --app-px: 16px;        /* padding orizzontale di #app — sincronizza topbar/sticky-controls */
  --topbar-h: 64px;      /* aggiornata da JS al runtime */
}
@media (max-width: 540px)  { :root { --app-px: 12px; } }
@media (min-width: 900px)  { :root { --app-px: 32px; } }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  width: 100%;
  /* overflow-x: clip invece di hidden — clip non crea un nuovo
     scroll container, così position: sticky sui figli funziona
     correttamente (hidden lo rompe su iOS Safari). */
  overflow-x: clip;
  /* Niente double-tap zoom su mobile: tap = click immediato, senza i 300ms
     di attesa per riconoscere il "tap doppio". pinch-zoom resta abilitato. */
  touch-action: manipulation;
}
button, input, .tracks li, .filter-chip, .lyric-line { touch-action: manipulation; }

body {
  padding-bottom: calc(var(--footer-h) + env(safe-area-inset-bottom, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  transition: padding-bottom 0.25s ease-out;
}
/* Quando il pannello lyrics è aperto, allarghiamo il padding-bottom del
   body così l'ultimo brano della lista non finisce sotto il pannello. */
body.lyrics-open {
  padding-bottom: calc(var(--footer-h) + var(--lyrics-h) + env(safe-area-inset-bottom, 0px));
}

/* ─── SHELL: aside + main ─────────────────────────────────────────────── */
.shell { display: flex; align-items: stretch; min-height: 100vh; }

.library-nav {
  width: var(--aside-w);
  flex-shrink: 0;
  background: #0a0a0c;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 30;
}
.library-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}
.library-head h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -0.02em;
}
/* Bottone X dentro l'aside: visibile solo su mobile per chiudere il drawer. */
.library-close {
  display: none;
  background: transparent;
  border: none;
  color: var(--fg-muted);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}
.library-close:hover { background: var(--bg-elev); color: var(--fg); }
.library-close svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
@media (max-width: 899px) {
  .library-close { display: inline-flex; }
}
.library-section { padding: 14px 12px; }
.library-section-label {
  font: 600 10px/1 inherit;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-muted);
  margin: 0 0 8px 8px;
}
.library-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.lib-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--fg-muted);
  transition: background 0.1s, color 0.1s;
  position: relative;
}
.lib-item:hover { background: var(--bg-elev); color: var(--fg); }
.lib-item.is-active {
  background: var(--bg-elev-2);
  color: var(--fg);
  font-weight: 600;
}
.lib-item.is-active::before {
  content: "";
  position: absolute;
  left: 0; top: 6px; bottom: 6px;
  width: 3px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}
.lib-item-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-item-count {
  font-size: 11px;
  opacity: 0.7;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.lib-new {
  background: transparent;
  color: var(--fg-muted);
  font: 600 13px/1 inherit;
  padding: 8px 12px;
  border: 1px dashed var(--border);
  border-radius: 6px;
  cursor: pointer;
  margin-top: 6px;
  text-align: left;
  transition: border-color 0.15s, color 0.15s;
}
.lib-new:hover { border-color: var(--accent); color: var(--accent); }

.library-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 25;
  border: none;
  padding: 0;
  cursor: pointer;
}

/* Mobile: aside come drawer (off-screen, transform al toggle) */
@media (max-width: 899px) {
  .library-nav {
    position: fixed;
    left: 0; top: 0;
    width: 260px;
    height: 100dvh;
    transform: translateX(-100%);
    transition: transform 0.25s ease-out;
    z-index: 70;
  }
  .library-nav.is-open { transform: translateX(0); box-shadow: 6px 0 24px rgba(0, 0, 0, 0.5); }
  .library-backdrop.is-open { display: block; }
}

#app {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 var(--app-px) 32px;  /* niente padding-top: la topbar sticky lo gestisce */
  flex: 1;
  min-width: 0;
}
@media (min-width: 900px) {
  #app {
    max-width: none;
    margin: 0;
  }
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  /* Sticky in cima al viewport, sopra la sticky-controls.
     L'altezza viene letta da JS e propagata in --topbar-h così che
     la barra di ricerca sappia di quanto offsettarsi. */
  position: sticky;
  top: 0;
  z-index: 41;
  background: var(--bg-bar);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  margin: 0 calc(-1 * var(--app-px)) 8px;
  padding: 16px var(--app-px) 8px;
}
.topbar-title { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.page-title {
  margin: 0;
  font-size: 26px;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar h1 { /* legacy */
  margin: 0;
  font-size: 28px;
  letter-spacing: -0.02em;
}
.topbar-menu {
  display: inline-flex;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
}
.topbar-menu svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

/* Desktop ≥900px: hamburger collassa la sidebar permanente.
   La main area si allarga per riempire lo spazio liberato. */
@media (min-width: 900px) {
  .shell.aside-collapsed .library-nav { display: none; }
}

.muted { color: var(--fg-muted); font-size: 13px; }

/* ─── STICKY CONTROLS (search + playlist + filter) ────────────────────── */
/* Wrapper che resta in cima al viewport durante lo scroll della lista.
   Il <h1>+contatore della topbar scrolla via normalmente. */
.sticky-controls {
  position: sticky;
  /* L'offset è l'altezza della topbar (anche essa sticky a top:0).
     Calcolata in JS via ResizeObserver e propagata via --topbar-h. */
  top: var(--topbar-h, 64px);
  z-index: 40;
  padding: 10px var(--app-px);
  margin: 0 calc(-1 * var(--app-px)) 12px;
  /* Riferimento posizionale per il popover dei filtri (position: absolute) */
  isolation: isolate;
  background: rgba(14, 14, 16, 0.78);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}
.sticky-controls > * { margin-bottom: 10px; }
.sticky-controls > *:last-child:not([hidden]) { margin-bottom: 0; }

/* Search-row: input + bottone filter accanto, fianco a fianco. */
.search-row { display: flex; gap: 8px; align-items: stretch; position: relative; }

.filter-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  flex-shrink: 0;
  background: var(--bg-elev);
  color: var(--fg-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.filter-btn:hover { color: var(--fg); border-color: var(--fg-muted); }
.filter-btn[aria-expanded="true"] {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--bg-elev-2);
}
.filter-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.filter-btn-dot {
  position: absolute;
  top: 6px;
  right: 8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-elev);
  box-sizing: border-box;
}
.filter-btn[aria-expanded="true"] .filter-btn-dot { border-color: var(--bg-elev-2); }

/* Pillole dei filtri attivi: testo + X, sopra la lista. Solo se attivi. */
.active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.active-filters[hidden] { display: none; }
.active-filter {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font: 600 12px/1 inherit;
  padding: 6px 4px 6px 12px;
  background: var(--accent);
  color: var(--accent-fg);
  border-radius: 999px;
}
.active-filter button {
  background: transparent;
  border: none;
  color: inherit;
  cursor: pointer;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 14px;
  line-height: 1;
  opacity: 0.7;
  transition: opacity 0.15s, background 0.15s;
}
.active-filter button:hover { opacity: 1; background: rgba(0, 0, 0, 0.18); }

/* Popover dei filtri disponibili: dropdown sotto la search-row. */
.filter-popover {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 45;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
  max-height: min(55vh, 420px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: filterPopIn 0.15s ease-out;
}
.filter-popover[hidden] { display: none; }
@keyframes filterPopIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
.filter-popover-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.filter-popover-head strong { font-size: 13px; letter-spacing: 0.02em; }
.filter-popover-clear {
  background: transparent;
  border: none;
  color: var(--fg-muted);
  font: 600 12px/1 inherit;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
}
.filter-popover-clear:hover { color: var(--accent); }
.filter-popover .filter-bar {
  flex: 1;
  overflow-y: auto;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 16px;
  /* override single-row scrolling — qui i chip vanno a capo liberamente */
  overflow-x: visible;
}

/* (regola rimossa: la sticky-controls usa già --app-px che si adatta ai breakpoint) */

/* ─── SEARCH BAR ──────────────────────────────────────────────────────── */
.search-bar {
  position: relative;
  margin: 0;
  display: flex;
  align-items: center;
  /* Riempie tutto lo spazio orizzontale rimanente nella search-row. */
  flex: 1 1 auto;
  min-width: 0;
}
.search-icon {
  position: absolute;
  left: 12px;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: var(--fg-muted);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}
.search-input {
  flex: 1;
  width: 100%;
  font: inherit;
  padding: 10px 36px 10px 38px;
  background: var(--bg-elev);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 999px;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.search-input::placeholder { color: var(--fg-muted); }
.search-input:focus { border-color: var(--accent); background: var(--bg-elev-2); }
/* Rimuove la X nativa di webkit (quella che ho già custom). */
.search-input::-webkit-search-cancel-button { -webkit-appearance: none; }
.search-input::-webkit-search-decoration { -webkit-appearance: none; }

.search-clear {
  position: absolute;
  right: 6px;
  width: 28px;
  height: 28px;
  background: transparent;
  border: none;
  border-radius: 50%;
  color: var(--fg-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.search-clear:hover { background: var(--bg-elev-2); color: var(--fg); }
.search-clear svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
}

.tracks-empty-search {
  text-align: center;
  padding: 32px 16px;
  color: var(--fg-muted);
}

/* ─── PLAYLIST BAR ────────────────────────────────────────────────────── */
/* Una sola riga, scroll orizzontale (swipe su touch, scroll wheel su desktop).
   Evita di rubare verticale quando ci sono molte playlist. */
.playlist-bar {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  margin: 0;
  align-items: center;
  overflow-x: auto;
  scrollbar-width: none; /* Firefox */
  -webkit-overflow-scrolling: touch;
}
.playlist-bar::-webkit-scrollbar { display: none; }
.playlist-bar > * { flex-shrink: 0; }
.playlist-bar:empty { display: none; }
.playlist-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: 600 12px/1 inherit;
  letter-spacing: 0.02em;
  padding: 7px 12px;
  background: var(--bg-elev);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.playlist-chip:hover { border-color: var(--fg-muted); }
.playlist-chip[aria-pressed="true"] {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
}
.playlist-chip-count {
  font-size: 11px;
  opacity: 0.7;
  font-variant-numeric: tabular-nums;
}
.playlist-new {
  background: transparent;
  color: var(--fg-muted);
  border: 1px dashed var(--border);
  font: 600 12px/1 inherit;
  padding: 7px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.playlist-new:hover { color: var(--accent); border-color: var(--accent); }

/* ─── FILTER BAR (chip generi) ───────────────────────────────────────── */
/* Stesso pattern della playlist-bar: 1 riga + swipe orizzontale. */
.filter-bar {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  margin: 0;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.filter-bar::-webkit-scrollbar { display: none; }
.filter-bar > * { flex-shrink: 0; }
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font: 600 12px/1 inherit;
  letter-spacing: 0.02em;
  padding: 6px 10px;
  background: var(--bg-elev);
  color: var(--fg-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.filter-chip:hover { color: var(--fg); border-color: var(--fg-muted); }
.filter-chip[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}
.filter-chip-count {
  font-size: 11px;
  opacity: 0.7;
  font-variant-numeric: tabular-nums;
}

/* Generi nelle righe = METADATA (non controlli). Stile testo "downtempo · house",
   niente pill, niente border — i pill restano solo per i controlli filter-bar. */
.tr-genres {
  font-size: 12px;
  color: var(--fg-muted);
  margin-left: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 1;
  min-width: 0;
}
.tr-genres span {
  background: transparent;
  border: 0;
  padding: 0;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  font-size: inherit;
}
.tr-genres span + span::before { content: " · "; opacity: 0.6; }
@media (max-width: 540px) { .tr-genres { display: none; } }
.error { color: var(--danger); padding: 16px; }
.empty { text-align: center; padding: 32px 0; }

/* ─── TRACK LIST ───────────────────────────────────────────────────────── */
.tracks {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.tracks li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
  /* Riserva spazio sopra/sotto per scrollIntoView in modo che la traccia
     attiva non finisca sotto il footer fisso o all'estremo bordo. */
  scroll-margin-top: 16px;
  scroll-margin-bottom: calc(var(--footer-h) + 16px);
}
.tracks li:last-child { border-bottom: none; }
.tracks li:hover { background: var(--bg-elev-2); }
.tracks li.active {
  background: var(--bg-elev-2);
  color: var(--accent);
}

/* Numero traccia + equalizer occupano la stessa cella (24px). Si scambiano sul brano attivo. */
.tr-num,
.tr-eq {
  width: 24px;
  text-align: center;
  flex-shrink: 0;
}
.tr-num {
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}
.tr-eq {
  display: none;
  align-items: flex-end;
  justify-content: center;
  gap: 2px;
  height: 14px;
}
.tr-eq span {
  display: block;
  width: 3px;
  background: var(--accent);
  border-radius: 1px;
  height: 30%;
  animation: eq 0.9s ease-in-out infinite;
  animation-play-state: paused; /* statico finché audio in pausa */
}
.tr-eq span:nth-child(2) { animation-delay: 0.15s; height: 60%; }
.tr-eq span:nth-child(3) { animation-delay: 0.3s; height: 45%; }

.tracks li.active .tr-num { display: none; }
.tracks li.active .tr-eq { display: inline-flex; }
body.is-playing .tracks li.active .tr-eq span { animation-play-state: running; }

@keyframes eq {
  0%, 100% { height: 30%; }
  50% { height: 100%; }
}

.tr-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tracks li.active .tr-title { font-weight: 600; }

/* Icon-button "Lyrics" nella riga del brano in playback (microfono in cerchio).
   Forma circolare, non si confonde con i chip rettangolari dei generi. */
.tr-lyrics {
  display: none;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  color: var(--accent);
  background: transparent;
  border: 1px solid var(--accent);
  border-radius: 50%;
  padding: 0;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.tracks li.active .tr-lyrics { display: inline-flex; }
.tr-lyrics:hover, .tr-lyrics:active { background: var(--accent); color: var(--accent-fg); }
.tr-lyrics svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Icon-button "Aggiungi a playlist" — apre menu floating con checkbox. */
.tr-addpl {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  color: var(--fg-muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 50%;
  padding: 0;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.tracks li:hover .tr-addpl, .tracks li.active .tr-addpl { color: var(--fg); border-color: var(--border); }
.tr-addpl:hover, .tr-addpl:active { background: var(--bg-elev-2); color: var(--accent); border-color: var(--accent); }
.tr-addpl svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
@media (max-width: 540px) { .tr-addpl { color: var(--fg); border-color: var(--border); } }

/* Menu floating "Aggiungi a…" */
.addpl-menu {
  position: fixed;
  z-index: 80;
  min-width: 240px;
  max-width: 320px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
  overflow: hidden;
  animation: filterPopIn 0.12s ease-out;
}
.addpl-head {
  padding: 10px 14px;
  font: 600 11px/1 inherit;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-muted);
  border-bottom: 1px solid var(--border);
}
.addpl-list { max-height: 280px; overflow-y: auto; padding: 4px 0; }
.addpl-empty { padding: 14px; color: var(--fg-muted); font-size: 12px; text-align: center; }
.addpl-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 13px;
}
.addpl-row:hover { background: var(--bg-elev-2); }
.addpl-row input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.addpl-row span:nth-child(2) { flex: 1; }
.addpl-count { color: var(--fg-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.addpl-create {
  display: flex;
  gap: 6px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.addpl-create input {
  flex: 1;
  font: inherit;
  padding: 7px 10px;
  background: var(--bg-elev);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
  font-size: 13px;
}
.addpl-create input:focus { border-color: var(--accent); }
.addpl-create button {
  background: var(--accent);
  color: var(--accent-fg);
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
}
.addpl-create button:hover { filter: brightness(1.1); }

/* Icon-button "Condividi" — sempre visibile, accanto a .tr-lyrics. */
.tr-share {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  color: var(--fg-muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 50%;
  padding: 0;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.tracks li:hover .tr-share, .tracks li.active .tr-share { color: var(--fg); border-color: var(--border); }
.tr-share:hover, .tr-share:active { background: var(--bg-elev-2); color: var(--accent); border-color: var(--accent); }
.tr-share svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
@media (max-width: 540px) {
  .tr-share { color: var(--fg); border-color: var(--border); }
}

/* Toast effimero — feedback breve "Link copiato" e simili. */
.toast {
  position: fixed;
  bottom: calc(var(--footer-h) + 16px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  background: var(--fg);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font: 600 13px/1 inherit;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.25s, transform 0.25s;
}
.toast[hidden] { display: none; }
.toast.fade-out { opacity: 0; transform: translate(-50%, 8px); }
body.lyrics-open .toast { bottom: calc(var(--footer-h) + var(--lyrics-h) + 16px + env(safe-area-inset-bottom, 0px)); }

/* ─── PLAYER FOOTER ────────────────────────────────────────────────────── */
.player-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 50;
  height: calc(var(--footer-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--bg-bar);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  /* niente border-top: il seek-bar full-width fa già da separatore visivo */
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}

/* Seek bar full-width all'interno del footer.
   Il fill (porzione già riprodotta) è un linear-gradient aggiornato da JS:
   --seek-pct viene impostato a ogni timeupdate.
   Il thumb è invisibile di default (il fill già comunica il progresso) e
   appare on hover/focus/active — sia desktop sia tap su mobile.

   IMPORTANTE: l'input ha altezza = thumb (12px) per dare spazio verticale
   al thumb; la "track" visibile è disegnata dagli pseudo-elementi runnable-track
   / range-track a 4px. Così il thumb è sempre centrato verticalmente. */
.seek-bar {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 12px;
  cursor: pointer;
  outline: none;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  display: block;
  flex-shrink: 0;
}
.seek-bar::-webkit-slider-runnable-track {
  height: var(--seek-h);
  border-radius: 0;
  background: linear-gradient(
    to right,
    var(--accent) 0%,
    var(--accent) var(--seek-pct, 0%),
    var(--bg-elev-2) var(--seek-pct, 0%),
    var(--bg-elev-2) 100%
  );
}
.seek-bar::-moz-range-track {
  height: var(--seek-h);
  border-radius: 0;
  background: linear-gradient(
    to right,
    var(--accent) 0%,
    var(--accent) var(--seek-pct, 0%),
    var(--bg-elev-2) var(--seek-pct, 0%),
    var(--bg-elev-2) 100%
  );
}
.seek-bar::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  background: var(--accent);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  /* track 4px, thumb 12px → offset = -(12-4)/2 = -4 dal top della track */
  margin-top: -4px;
  box-shadow: 0 0 0 2px var(--bg);
  opacity: 0;
  transition: opacity 0.15s, transform 0.15s;
}
.seek-bar::-moz-range-thumb {
  width: 12px;
  height: 12px;
  background: var(--accent);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 0 2px var(--bg);
  opacity: 0;
  transition: opacity 0.15s, transform 0.15s;
}
.seek-bar:hover::-webkit-slider-thumb,
.seek-bar:focus::-webkit-slider-thumb,
.seek-bar:active::-webkit-slider-thumb { opacity: 1; transform: scale(1.2); }
.seek-bar:hover::-moz-range-thumb,
.seek-bar:focus::-moz-range-thumb,
.seek-bar:active::-moz-range-thumb { opacity: 1; transform: scale(1.2); }

.player-row {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  min-width: 0;
}

/* ─── INFO (left) ─────────────────────────────────────────────────────── */
.player-info {
  min-width: 0;
  flex: 1 1 0;
}
.np-title {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.np-time {
  margin-top: 4px;
  font-size: 12px;
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
}
.np-sep { margin: 0 4px; opacity: 0.5; }

/* ─── CONTROLS (center) ───────────────────────────────────────────────── */
.player-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
}

.ctrl {
  background: transparent;
  border: none;
  color: var(--fg);
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s, transform 0.05s;
}
.ctrl:hover { background: var(--bg-elev-2); }
.ctrl:active { transform: scale(0.95); }
.ctrl svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.ctrl.small svg { width: 18px; height: 18px; }
.ctrl.primary {
  background: var(--fg);
  color: var(--bg);
  width: 40px;
  height: 40px;
  margin: 0 4px;
}
.ctrl.primary svg { fill: currentColor; stroke: none; width: 20px; height: 20px; }
.ctrl.primary:hover { background: var(--accent); color: var(--accent-fg); }

.ctrl.toggle { position: relative; }
.ctrl.toggle[aria-pressed="true"],
.ctrl.toggle[data-mode="all"],
.ctrl.toggle[data-mode="one"] { color: var(--accent); }
.ctrl.toggle[aria-pressed="true"]::after,
.ctrl.toggle[data-mode="all"]::after,
.ctrl.toggle[data-mode="one"]::after {
  content: "";
  position: absolute;
  bottom: 2px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
}

#btn-play .icon-pause { display: none; }
#btn-play.is-playing .icon-play { display: none; }
#btn-play.is-playing .icon-pause { display: inline-block; }

#btn-repeat .icon-repeat-one { display: none; }
#btn-repeat[data-mode="one"] .icon-repeat { display: none; }
#btn-repeat[data-mode="one"] .icon-repeat-one { display: inline-block; }

/* ─── EXTRAS: lyrics-toggle + volume (right) ─────────────────────────── */
.player-extras {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex: 1 1 0;
  min-width: 0;
}

/* Bottone lyrics: pill con icona microfono + label "Lyrics".
   Quando attivo, sfondo accent. Più visibile dei toggle puntinati. */
.btn-lyrics {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
}
.btn-lyrics-label { font-size: 13px; font-weight: 600; }
.btn-lyrics svg { width: 16px; height: 16px; }
.btn-lyrics[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}
/* Anche al :hover quando attivo, mantieni la coppia accent/accent-fg
   (.ctrl:hover { background: var(--bg-elev-2) } sovrascriverebbe). */
.btn-lyrics[aria-pressed="true"]:hover {
  background: var(--accent);
  color: var(--accent-fg);
  filter: brightness(1.1);
}
@media (max-width: 540px) {
  .btn-lyrics-label { display: none; }
  .btn-lyrics { padding: 6px 8px; }
}

.player-volume {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--fg-muted);
  min-width: 0;
}
.player-volume svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}
/* Volume slider: stesso pattern della seek-bar (input alto come thumb,
   track stilizzata via runnable-track). */
.player-volume input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100px;
  max-width: 100%;
  height: 12px;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  outline: none;
}
.player-volume input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(
    to right,
    var(--fg) 0%,
    var(--fg) var(--vol-pct, 80%),
    var(--bg-elev-2) var(--vol-pct, 80%),
    var(--bg-elev-2) 100%
  );
}
.player-volume input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(
    to right,
    var(--fg) 0%,
    var(--fg) var(--vol-pct, 80%),
    var(--bg-elev-2) var(--vol-pct, 80%),
    var(--bg-elev-2) 100%
  );
}
.player-volume input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  background: var(--fg);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  margin-top: -4px;
  box-shadow: 0 0 0 2px var(--bg);
  opacity: 0;
  transition: opacity 0.15s;
}
.player-volume input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  background: var(--fg);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 0 2px var(--bg);
  opacity: 0;
  transition: opacity 0.15s;
}
.player-volume:hover input[type="range"]::-webkit-slider-thumb,
.player-volume input[type="range"]:focus::-webkit-slider-thumb,
.player-volume input[type="range"]:active::-webkit-slider-thumb { opacity: 1; }
.player-volume:hover input[type="range"]::-moz-range-thumb,
.player-volume input[type="range"]:focus::-moz-range-thumb,
.player-volume input[type="range"]:active::-moz-range-thumb { opacity: 1; }

/* ─── RESPONSIVE ──────────────────────────────────────────────────────── */

/* Tablet */
@media (max-width: 768px) {
  :root { --footer-h: 80px; }
  .player-row { gap: 12px; padding: 0 12px; }
  .player-volume input[type="range"] { width: 70px; }
}

/* Mobile: nasconde volume (usa controlli del device), bottoni più spaziati e
   touch-friendly. Tap target ~40-44px come da Apple HIG. */
@media (max-width: 540px) {
  :root { --footer-h: 80px; }
  #app { padding: 0 var(--app-px) 24px; }
  .topbar h1 { font-size: 22px; }
  .tracks li { padding: 10px 12px; gap: 10px; }
  .player-row {
    gap: 8px;
    padding: 0 8px;
  }
  .player-volume { display: none; }
  .player-controls { gap: 4px; }
  .ctrl {
    padding: 10px;
    min-width: 40px;
    min-height: 40px;
  }
  .ctrl svg { width: 22px; height: 22px; }
  .ctrl.small svg { width: 18px; height: 18px; }
  .ctrl.primary {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    margin: 0 2px;
    padding: 0;
  }
  .ctrl.primary svg { width: 22px; height: 22px; }
  .np-title { font-size: 13px; }
  .np-time { font-size: 11px; }
}

/* Mobile stretto: nasconde shuffle/repeat per dare più aria a prev/play/next */
@media (max-width: 380px) {
  #btn-shuffle, #btn-repeat { display: none; }
  .player-controls { gap: 6px; }
}

/* ─── LYRICS PANEL ────────────────────────────────────────────────────── */
/* Finestra fissa di 5 righe (i±2 dalla corrente). Niente scroll. */
.lyrics-panel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--footer-h) + env(safe-area-inset-bottom, 0px));
  z-index: 49;
  background: var(--bg-bar);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  animation: slideUp 0.25s ease-out;
}
/* IMPORTANTE: classe + display:flex sovrascriverebbero [hidden]. */
.lyrics-panel[hidden] { display: none; }

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

.lyrics-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.lyrics-head strong {
  font-size: 13px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--fg-muted);
}

.lyrics-window {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 24px 16px;
  text-align: center;
}
.lyric-line {
  width: 100%;
  max-width: 600px;
  padding: 4px 8px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.3s, opacity 0.3s, font-size 0.3s, font-weight 0.3s;
  color: var(--fg);
}
.lyric-line:empty { visibility: hidden; min-height: 1em; }

.lyric-far-prev, .lyric-far-next { font-size: 13px; opacity: 0.3; }
.lyric-prev, .lyric-next         { font-size: 16px; opacity: 0.55; }
.lyric-current {
  font-size: 22px;
  opacity: 1;
  font-weight: 700;
  color: var(--accent);
}

.lyrics-empty { padding: 32px 16px; text-align: center; }

@media (max-width: 540px) {
  .lyrics-window { padding: 16px 12px; gap: 4px; }
  .lyric-far-prev, .lyric-far-next { font-size: 12px; }
  .lyric-prev, .lyric-next         { font-size: 14px; }
  .lyric-current                   { font-size: 18px; }
}

/* ─── EDITOR MODAL (<dialog>) ────────────────────────────────────────── */
/* IMPORTANTE: il default UA per <dialog>:not([open]) è display:none, ma una
   classe con display:flex lo sovrascrive (specificità maggiore). Espongo
   la regola sotto [open] perché il flex valga SOLO quando aperto. */
.editor[open] {
  display: flex;
  flex-direction: column;
  min-height: min(640px, 80vh);  /* altezza usabile anche con poco contenuto */
}
.editor {
  width: min(640px, 92vw);
  max-height: 88vh;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elev);
  color: var(--fg);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}
.editor::backdrop { background: rgba(0, 0, 0, 0.6); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }

.editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.editor-head strong { font-size: 15px; }

.editor-tabs { display: flex; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.editor-tab {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--fg-muted);
  font: 600 13px/1 inherit;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 14px 16px;
  cursor: pointer;
  position: relative;
}
.editor-tab[aria-selected="true"] { color: var(--accent); }
.editor-tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  bottom: -1px; left: 16px; right: 16px;
  height: 2px;
  background: var(--accent);
}

.editor-panel {
  flex: 1;
  overflow-y: auto;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.editor-panel[hidden] { display: none; }

.ed-field { display: flex; flex-direction: column; gap: 8px; }
.ed-field > label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--fg-muted);
}
.ed-field input[type="text"],
.ed-field input[type="number"],
.editor-panel textarea {
  font: inherit;
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  transition: border-color 0.15s;
}
.ed-field input:focus, .editor-panel textarea:focus { border-color: var(--accent); }
.editor-panel textarea {
  resize: vertical;
  min-height: 360px;
  flex: 1;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  line-height: 1.6;
}

.lock-btn {
  background: transparent;
  border: none;
  font-size: 14px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  filter: grayscale(0.5);
  opacity: 0.6;
  transition: opacity 0.15s, filter 0.15s;
}
.lock-btn:hover { opacity: 1; }
.lock-btn[aria-pressed="true"] { filter: none; opacity: 1; color: var(--accent); }

.chip-input {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px;
  min-height: 42px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.chip-input input {
  flex: 1;
  min-width: 120px;
  border: none;
  background: transparent;
  padding: 4px 6px;
  font: inherit;
  color: var(--fg);
  outline: none;
}
.chip-input .chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-elev-2);
  color: var(--fg);
  border-radius: 999px;
  padding: 3px 4px 3px 10px;
  font-size: 12px;
  font-weight: 500;
}
.chip-input .chip button {
  background: transparent;
  border: none;
  color: var(--fg-muted);
  cursor: pointer;
  width: 18px; height: 18px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  line-height: 1;
  padding: 0;
}
.chip-input .chip button:hover { background: var(--danger); color: var(--bg); }

.ed-lyrics-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
#ed-insert-ts {
  background: var(--accent);
  color: var(--accent-fg);
  border: none;
  padding: 8px 12px;
  border-radius: 8px;
  font: 600 13px/1 inherit;
  cursor: pointer;
}
#ed-insert-ts:hover { filter: brightness(1.1); }
#ed-insert-ts:disabled { opacity: 0.4; cursor: not-allowed; }

.editor-foot {
  border-top: 1px solid var(--border);
  padding: 14px 20px;
  flex-shrink: 0;
  background: var(--bg-elev);
}
.editor-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.editor-actions button {
  flex: 1;
  background: var(--bg-elev-2);
  color: var(--fg);
  border: 1px solid var(--border);
  padding: 10px 12px;
  border-radius: 8px;
  font: 600 13px/1 inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.editor-actions button:hover { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.editor-foot .hint { font-size: 12px; margin: 10px 0 0; }
.editor-foot code {
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
}

@media (max-width: 540px) {
  .editor { width: 100vw; max-height: 100vh; height: 100vh; border-radius: 0; border: none; }
  .editor-panel { padding: 14px 14px; }
  .editor-actions button { font-size: 12px; padding: 10px 8px; }
}

/* ─── EDITOR: tab playlist ───────────────────────────────────────────── */
.ed-hint { font-size: 12px; margin: 0 0 4px; }
.ed-hint code {
  background: var(--bg);
  padding: 2px 5px;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
}
.ed-playlist-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 280px;
  overflow-y: auto;
  padding: 4px 0;
}
.ed-playlist-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: border-color 0.15s;
}
.ed-playlist-row:hover { border-color: var(--fg-muted); }
.ed-playlist-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}
.ed-playlist-row .ed-playlist-name {
  flex: 1;
  font-weight: 500;
}
.ed-playlist-row .ed-playlist-count {
  font-size: 12px;
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
}
.ed-playlist-row .ed-playlist-action {
  background: transparent;
  border: none;
  color: var(--fg-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 13px;
}
.ed-playlist-row .ed-playlist-action:hover { color: var(--fg); background: var(--bg-elev-2); }
.ed-playlist-row .ed-playlist-action.danger:hover { color: var(--danger); }

.ed-playlist-create {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.ed-playlist-create input {
  flex: 1;
  font: inherit;
  padding: 10px 12px;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
}
.ed-playlist-create input:focus { border-color: var(--accent); }
.ed-playlist-create button {
  background: var(--accent);
  color: var(--accent-fg);
  border: none;
  padding: 10px 16px;
  border-radius: 8px;
  font: 600 13px/1 inherit;
  cursor: pointer;
}
.ed-playlist-create button:hover { filter: brightness(1.1); }
