:root {
  --bg: #12121a;
  --surface: #1c1c27;
  --surface-2: #262634;
  --text: #ececf1;
  --muted: #9a9aab;
  --accent: #ff5c8a;
  --accent-2: #ffb347;
  --good: #4cd08a;
  --bad: #ff6b6b;
  --radius: 14px;
  --tabbar-h: 64px;
  --player-h: 0px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tabbar-h) + var(--player-h) + env(safe-area-inset-bottom) + 16px);
  -webkit-tap-highlight-color: transparent;
}
body.has-player { --player-h: 68px; }
button, input, textarea, select { font: inherit; color: inherit; }
/* Focus sempre visibile da tastiera (WCAG 2.4.7) */
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }
.text-input:focus-visible, input[type=search]:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 1px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
.hidden { display: none !important; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(8px);
}
.topbar h1 {
  margin: 0; font-size: 22px; font-weight: 800;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
main { max-width: 760px; margin: 0 auto; padding: 0 16px; }
.view { display: none; }
.view.active { display: block; }
h2 { font-size: 17px; margin: 24px 0 10px; }
.count { color: var(--muted); font-weight: 400; font-size: 14px; }
.hint { color: var(--muted); font-size: 14px; margin: 0 0 10px; }
.status { color: var(--muted); font-size: 14px; margin: 8px 0; min-height: 1.2em; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--surface-2); background: var(--surface);
  padding: 9px 14px; border-radius: 999px; cursor: pointer; font-size: 14px;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #12121a; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; }
.icon-btn {
  border: 0; background: var(--surface-2); width: 40px; height: 40px; border-radius: 50%;
  cursor: pointer; font-size: 16px; display: inline-grid; place-items: center; flex: none;
}
.icon-btn.big { width: 46px; height: 46px; background: var(--accent); color: #12121a; }
.icon-btn.on-good { background: var(--good); color: #0b2b19; }
.icon-btn.on-bad { background: var(--bad); color: #2b0b0b; }

.toolbar, .row-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0; }
.toolbar .btn.primary { margin-left: auto; }
.seg { display: inline-flex; background: var(--surface); border-radius: 999px; padding: 3px; }
.seg-btn { border: 0; background: transparent; padding: 7px 14px; border-radius: 999px; cursor: pointer; font-size: 14px; color: var(--muted); }
.seg-btn.active { background: var(--surface-2); color: var(--text); }

/* Cards suggerimenti */
.cards { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 620px) { .cards { grid-template-columns: 1fr 1fr; } }
.card {
  display: flex; gap: 12px; background: var(--surface); border-radius: var(--radius); padding: 10px;
  align-items: center; min-width: 0;
}
.card.playing { outline: 2px solid var(--accent); }
.cover { width: 72px; height: 72px; border-radius: 10px; object-fit: cover; flex: none; background: var(--surface-2); cursor: pointer; }
.card .meta { flex: 1; min-width: 0; }
.card .t, .item .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .a, .item .a { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .why { color: var(--accent-2); font-size: 12px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .actions { display: flex; gap: 6px; margin-top: 8px; }
.card .actions .icon-btn { width: 36px; height: 36px; font-size: 15px; }

/* Ricerca */
.field-label { display: block; margin: 12px 0 6px; font-size: 14px; color: var(--muted); }
.search-wrap { position: relative; }
input[type=search] {
  width: 100%; padding: 12px 14px; border-radius: var(--radius);
  border: 1px solid var(--surface-2); background: var(--surface); outline: none;
}
input[type=search]:focus { border-color: var(--accent); }
.search-results { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 10; background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: 0 8px 30px #0008; }
.search-results:empty { display: none; }
.sr-item { display: flex; align-items: center; gap: 10px; padding: 8px 12px; cursor: pointer; width: 100%; border: 0; background: none; text-align: left; }
.sr-item:hover, .sr-item:focus { background: var(--surface-2); }
.sr-item img { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; }
.sr-item small { color: var(--muted); display: block; }

.text-input {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--surface-2); background: var(--surface); outline: none; font-family: ui-monospace, monospace; font-size: 14px;
}
.text-input:focus { border-color: var(--accent); }
.copy-row { display: flex; gap: 8px; align-items: center; }
.copy-row code { flex: 1; min-width: 0; overflow-wrap: anywhere; background: var(--surface); padding: 8px 10px; border-radius: 10px; font-size: 13px; }
.warn { color: var(--accent-2); margin-top: 8px; }
a.btn { text-decoration: none; }
#sp-result p { margin: 0 0 10px; }
#sp-result ul { margin: 0 0 10px; padding-left: 18px; color: var(--muted); font-size: 14px; max-height: 30vh; overflow: auto; }

/* Profili e accesso */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.profile-chip { display: inline-flex; align-items: center; gap: 8px; border: 0; background: var(--surface); border-radius: 999px; padding: 4px 12px 4px 4px; cursor: pointer; font-size: 14px; max-width: 50%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar { width: 28px; height: 28px; border-radius: 50%; display: inline-grid; place-items: center; flex: none; font-weight: 700; color: #12121a; background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.gate { position: fixed; inset: 0; z-index: 100; background: var(--bg); overflow: auto; display: flex; align-items: flex-start; justify-content: center; padding: calc(env(safe-area-inset-top) + 48px) 16px 32px; }
body.gated { overflow: hidden; }
.gate-box { width: min(420px, 100%); }
.gate-box .logo { font-size: 30px; font-weight: 800; margin: 0 0 24px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.gate-box form, .gate-box > div { display: flex; flex-direction: column; gap: 12px; }
.gate-box .row-actions { flex-direction: row; }
#profile-new .text-input { flex: 1; min-width: 0; font-family: inherit; }
.profile-grid { display: flex; flex-direction: column; gap: 8px; }
.profile-btn { display: flex; align-items: center; gap: 12px; border: 1px solid var(--surface-2); background: var(--surface); padding: 10px 12px; border-radius: var(--radius); cursor: pointer; font-size: 16px; text-align: left; }
.profile-btn .avatar { width: 40px; height: 40px; font-size: 18px; }
.profile-btn.current { border-color: var(--accent); }
.item .by { color: var(--accent-2); font-size: 12px; }
#pl-list h2:first-child { margin-top: 8px; }

/* Viaggio */
.trip-form { display: flex; flex-direction: column; gap: 8px; }
.trip-form .field-label { margin: 8px 0 0; }
.trip-form select.text-input { font-family: inherit; }
.check-list { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 15px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.guest { display: flex; flex-direction: column; gap: 6px; padding: 10px; background: var(--surface-2); border-radius: 12px; margin-bottom: 6px; }
.guest .text-input { font-family: inherit; background: var(--bg); }
.guest .g-del { align-self: flex-end; }
dialog#dlg-trip { max-height: 90vh; overflow: auto; }
dialog#dlg-sp-import { max-height: 90vh; overflow: auto; }
#spi-list .item { cursor: pointer; }
#spi-list .item.muted { opacity: .5; }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 8px; background: var(--surface); border-radius: 999px; padding: 4px 6px 4px 4px; font-size: 14px; max-width: 100%; }
.chip img { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; }
.chip span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip button { border: 0; background: var(--surface-2); width: 22px; height: 22px; border-radius: 50%; cursor: pointer; font-size: 12px; flex: none; }
.empty { color: var(--muted); font-size: 14px; }

/* Liste */
.list { display: flex; flex-direction: column; gap: 6px; }
.item { display: flex; align-items: center; gap: 10px; background: var(--surface); border-radius: 12px; padding: 8px; min-width: 0; }
.item.playing { outline: 2px solid var(--accent); }
.item img { width: 48px; height: 48px; border-radius: 8px; object-fit: cover; flex: none; cursor: pointer; }
.item .meta { flex: 1; min-width: 0; cursor: pointer; }
.item .ops { display: flex; gap: 4px; flex: none; }
.item .ops .icon-btn { width: 32px; height: 32px; font-size: 13px; }
.item .num { width: 22px; text-align: right; color: var(--muted); font-size: 13px; flex: none; }
.pl-head h2 { font-size: 22px; margin: 12px 0 4px; word-break: break-word; }
.hint a { color: var(--accent-2); }
.links { display: flex; gap: 4px; font-size: 12px; margin-top: 2px; flex-wrap: wrap; }
.links a { display: inline-flex; align-items: center; min-height: 24px; padding: 0 4px; margin-left: -4px; margin-right: 4px; }
.links a { color: var(--muted); }

/* Player */
.player {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  height: 68px; z-index: 20; display: flex; align-items: center; gap: 8px; padding: 0 12px;
  background: var(--surface-2); border-top: 1px solid #ffffff10;
}
.player img { width: 48px; height: 48px; border-radius: 8px; object-fit: cover; }
.player-info { flex: 1; min-width: 0; }
.player .t { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player .a { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.progress { height: 3px; background: #ffffff20; border-radius: 2px; margin-top: 5px; overflow: hidden; }
.progress div { height: 100%; width: 0; background: var(--accent); }
.player .icon-btn { background: transparent; }
.player .icon-btn.big { background: var(--accent); }
.player .icon-btn.vote { display: none; width: 36px; height: 36px; font-size: 15px; }
.player.voting .icon-btn.vote { display: inline-grid; }
.player .icon-btn.on-good { background: var(--good); }
.player .icon-btn.on-bad { background: var(--bad); }
.player.radio #player-artist::before { content: "📻 "; }
@media (max-width: 420px) { .player.voting #player-prev { display: none; } .player { gap: 6px; padding: 0 8px; } }
.radio-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0 0 12px; }
.radio-row .hint { margin: 0; }

/* Tabbar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  display: flex; background: var(--surface); border-top: 1px solid #ffffff10;
}
.tab { flex: 1; border: 0; background: none; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 12px; cursor: pointer; }
.tab span { font-size: 20px; line-height: 1; }
.tab.active { color: var(--accent); }

/* Dialog */
dialog {
  border: 0; border-radius: 18px; background: var(--surface); color: var(--text);
  width: min(440px, calc(100vw - 32px)); padding: 18px; max-height: 80vh;
}
dialog::backdrop { background: #0009; }
dialog h3 { margin: 0 0 12px; }
dialog .list { max-height: 45vh; overflow: auto; margin-bottom: 8px; }
dialog .pl-pick { text-align: left; border: 0; background: var(--surface-2); padding: 12px; border-radius: 10px; cursor: pointer; }
textarea { width: 100%; background: var(--bg); border: 1px solid var(--surface-2); border-radius: 10px; padding: 10px; font-size: 13px; resize: vertical; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%) translateY(20px);
  bottom: calc(var(--tabbar-h) + var(--player-h) + env(safe-area-inset-bottom) + 12px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .25s; z-index: 50; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--muted); border-top-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }
.card .ban-row { font-size: 12px; color: var(--muted); margin-top: 4px; }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent-2); font: inherit; text-decoration: underline; cursor: pointer; }
.gusti-tabs { display: flex; width: 100%; margin-bottom: 14px; }
.gusti-tabs .seg-btn { flex: 1; padding: 8px 6px; }
.gusti-tabs .count { font-size: 12px; }
.gtab { display: none; }
.gtab.active { display: block; }
.row-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.row-head .btn { padding: 6px 12px; font-size: 13px; }
#track-results .sr-item img { border-radius: 6px; }
.list-tools { display: flex; gap: 8px; margin: 0 0 10px; }
.list-tools .text-input { font-family: inherit; padding: 8px 10px; }
.list-tools input { flex: 1; min-width: 0; }
.list-tools select { flex: 0 0 auto; width: auto; max-width: 48%; }
dialog#dlg-pick { width: min(560px, 100vw - 24px); max-height: 92vh; overflow: auto; }
.pick-bar { display: flex; justify-content: space-between; align-items: center; margin: 0 0 6px; }
.pick-list { max-height: 46vh; }
.pick-item { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 10px; cursor: pointer; }
.pick-item:hover { background: var(--surface-2); }
.pick-item input { width: 20px; height: 20px; accent-color: var(--accent); flex: 0 0 auto; }
.pick-item img { width: 40px; height: 40px; border-radius: 6px; object-fit: cover; flex: 0 0 auto; }
.pick-item .meta { min-width: 0; }
.pick-item .t, .pick-item .a { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pick-item .a { color: var(--muted); font-size: 13px; }
.pick-item.in { opacity: .55; cursor: default; }
.row-actions.tight { gap: 6px; flex-wrap: nowrap; }
#pick-mix { margin: 8px 0; }
.drag-handle { flex: 0 0 auto; width: 26px; text-align: center; font-size: 20px; line-height: 1; color: var(--muted); cursor: grab; touch-action: none; user-select: none; padding: 10px 0; border-radius: 6px; }
.drag-handle:focus-visible { outline: 2px solid var(--accent); }
#pl-tracks .item.dragging { position: relative; z-index: 5; background: var(--surface-2); box-shadow: 0 8px 24px #000a; cursor: grabbing; }
#pl-tracks .item.dragging .drag-handle { cursor: grabbing; color: var(--text); }
.tagline { font-size: 12px; color: var(--accent-2); margin-top: 2px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 10px; }
.tags:empty { display: none; }
.tag { border: 1px solid var(--surface-2); background: var(--surface); color: var(--muted); border-radius: 999px; padding: 5px 11px; font-size: 13px; cursor: pointer; font-family: inherit; }
.tag small { opacity: .7; }
.tag.on { background: var(--accent); border-color: var(--accent); color: #12121a; }
.tag.some { border-color: var(--accent); color: var(--text); }
#tags-list .tag:not(.on):not(.some) { border-style: dashed; }
