:root {
  --bg: #0f0f14;
  --bg2: #16161e;
  --bg3: #1e1e29;
  --line: #2a2a38;
  --text: #ececf1;
  --muted: #9a9aae;
  --accent: #8b5cf6;
  --accent2: #a78bfa;
  --danger: #f87171;
  --radius: 10px;
  --topbar: 56px;
  --mobile-nav: 0px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 20px; height: 20px; fill: currentColor; flex: none; }
img { display: block; }
code { background: var(--bg3); padding: 1px 6px; border-radius: 5px; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- topbar */
.topbar {
  height: var(--topbar);
  display: flex; align-items: center; gap: 16px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg2);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; }
.brand img { width: 30px; height: 30px; object-fit: contain; }
.where { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.listeners { color: var(--muted); font-size: 13px; white-space: nowrap; }
.nick { display: flex; align-items: center; gap: 6px; background: var(--bg3); border-radius: 999px; padding: 4px 10px; }
.nick svg { width: 16px; height: 16px; color: var(--muted); }
.nick input { background: none; border: 0; outline: 0; width: 110px; }

/* ---------------------------------------------------------------- layout */
.layout {
  height: calc(100% - var(--topbar) - var(--mobile-nav));
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
}
.library, .queue-panel { min-height: 0; display: flex; flex-direction: column; }
.queue-panel { border-left: 1px solid var(--line); background: var(--bg2); }

/* ---------------------------------------------------------------- bibliothèque */
.lib-top { padding: 14px 20px 0; display: flex; flex-direction: column; gap: 12px; border-bottom: 1px solid var(--line); }
.searchbox { display: flex; align-items: center; gap: 8px; background: var(--bg3); border-radius: 999px; padding: 8px 14px; border: 1px solid transparent; }
.searchbox:focus-within { border-color: var(--accent); }
.searchbox svg { color: var(--muted); }
.searchbox input { flex: 1; background: none; border: 0; outline: 0; min-width: 0; }
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tabs button {
  background: none; border: 0; padding: 8px 12px 10px;
  color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.tabs button:hover { color: var(--text); }

.lib-body { flex: 1; overflow-y: auto; padding: 16px 20px 40px; }
.lib-body h3 { margin: 20px 0 10px; font-size: 15px; }
.lib-body h3:first-child { margin-top: 0; }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.view-head select, .filter {
  background: var(--bg3); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; outline: 0;
}
.filter { flex: 1; max-width: 320px; }
.loading, .empty { color: var(--muted); padding: 24px 0; text-align: center; }
.error { color: var(--danger); padding: 24px 0; text-align: center; }
.sentinel { height: 1px; }

.back { display: inline-flex; align-items: center; gap: 4px; background: none; border: 0; color: var(--muted); padding: 0; margin-bottom: 12px; }
.back:hover { color: var(--text); }

/* Grille de cartes */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px; }
.card { position: relative; min-width: 0; cursor: pointer; border-radius: var(--radius); padding: 8px; transition: background .15s; }
.card:hover { background: var(--bg3); }
.card .cover { aspect-ratio: 1; }
.card .name { font-weight: 600; margin-top: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .sub { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card.round .cover, .card.round .cover img { border-radius: 50%; }
.card .quick {
  position: absolute; right: 14px; top: calc(100% - 92px);
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--accent); border: 0; color: white;
  display: grid; place-items: center;
  opacity: 0; transform: translateY(6px); transition: .15s;
  box-shadow: 0 6px 16px rgba(0,0,0,.4);
}
.card:hover .quick, .card .quick:focus-visible { opacity: 1; transform: none; }
@media (hover: none) { .card .quick { opacity: 1; transform: none; width: 34px; height: 34px; } }

.cover {
  width: 100%; border-radius: 8px; overflow: hidden; flex: none;
  background: linear-gradient(135deg, #2b2440, #1a1a26);
  position: relative;
}
.cover img { width: 100%; height: 100%; object-fit: cover; }
.cover.missing::after { content: "♪"; position: absolute; inset: 0; display: grid; place-items: center; color: #5b5470; font-size: 28px; }

/* Lignes de titres */
.songs { display: flex; flex-direction: column; }
.song {
  display: grid; grid-template-columns: 40px minmax(0, 1fr) auto auto; gap: 12px; align-items: center;
  padding: 6px 8px; border-radius: 8px;
}
.song:hover { background: var(--bg3); }
.song .cover { width: 40px; height: 40px; border-radius: 6px; }
.song .num { width: 40px; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }
.song .meta { min-width: 0; }
.song .title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.song .artist { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.song .dur { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }
.song .actions { display: flex; gap: 2px; }
.song .actions button { opacity: .55; }
.song:hover .actions button { opacity: 1; }
@media (hover: none) { .song .actions button { opacity: 1; } }

button.icon {
  background: none; border: 0; border-radius: 50%; width: 34px; height: 34px;
  display: inline-grid; place-items: center; color: var(--muted);
}
button.icon:hover { color: var(--text); background: rgba(255,255,255,.06); }
button.icon:disabled { opacity: .35; cursor: default; background: none; }

/* En-tête d'album / playlist / artiste */
.hero { display: flex; gap: 20px; align-items: flex-end; margin-bottom: 20px; }
.hero .cover { width: 180px; height: 180px; box-shadow: 0 10px 30px rgba(0,0,0,.45); }
.hero.round .cover, .hero.round .cover img { border-radius: 50%; }
.hero .kind { text-transform: uppercase; font-size: 11px; letter-spacing: .08em; color: var(--muted); }
.hero h2 { margin: 4px 0 6px; font-size: 28px; line-height: 1.15; word-break: break-word; }
.hero .sub { color: var(--muted); }
.hero .sub a { color: var(--text); cursor: pointer; }
.hero .sub a:hover { text-decoration: underline; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.btn {
  border: 1px solid var(--line); background: var(--bg3); border-radius: 999px; padding: 8px 16px;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: white; font-weight: 600; }
.btn.primary:hover { background: var(--accent2); }
.btn svg { width: 18px; height: 18px; }

/* Liste d'artistes compacte */
.rows { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; gap: 12px; padding: 6px 8px; border-radius: 8px; cursor: pointer; }
.row:hover { background: var(--bg3); }
.row .cover { width: 44px; height: 44px; border-radius: 50%; }
.row .cover img { border-radius: 50%; }
.row .name { font-weight: 500; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { color: var(--muted); font-size: 12.5px; }

/* ---------------------------------------------------------------- en cours */
.now { display: flex; gap: 14px; padding: 16px; border-bottom: 1px solid var(--line); }
.now-cover { width: 112px; height: 112px; border-radius: 10px; overflow: hidden; flex: none; background: linear-gradient(135deg, #2b2440, #1a1a26); }
.now-cover img { width: 100%; height: 100%; object-fit: cover; }
.now-cover img:not([src]) { display: none; }
.now-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.now-title { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.now-sub { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.progress { margin-top: auto; }
.bar { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.bar div { height: 100%; width: 0; background: var(--accent); transition: width .5s linear; }
.times { display: flex; justify-content: space-between; color: var(--muted); font-size: 11.5px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.controls { display: flex; justify-content: center; align-items: center; gap: 10px; margin-top: 4px; }
.controls .big { width: 44px; height: 44px; background: var(--text); color: var(--bg); }
.controls .big:hover { background: white; color: var(--bg); transform: scale(1.04); }
.controls .big svg { width: 22px; height: 22px; }

/* ---------------------------------------------------------------- file */
.queue-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 12px 16px 8px; }
.queue-head h2 { font-size: 15px; margin: 0; display: inline; }
#queueMeta { color: var(--muted); font-size: 12.5px; margin-left: 6px; }
.queue-tools { display: flex; align-items: center; gap: 2px; }
.queue-tools select { background: var(--bg3); border: 1px solid var(--line); border-radius: 8px; padding: 4px 6px; font-size: 12.5px; max-width: 150px; }
.queue { list-style: none; margin: 0; padding: 0 8px 24px; overflow-y: auto; flex: 1; position: relative; }
.queue-empty { color: var(--muted); text-align: center; padding: 30px 16px; flex: 1; }

.qitem {
  display: grid; grid-template-columns: 24px 40px minmax(0, 1fr) auto auto; align-items: center; gap: 8px;
  padding: 5px 6px; border-radius: 8px; background: var(--bg2);
}
.qitem:hover { background: var(--bg3); }
.qitem .cover { width: 40px; height: 40px; border-radius: 6px; }
.qitem .meta { min-width: 0; }
.qitem .title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qitem .artist { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qitem .by { color: var(--accent2); }
.qitem .dur { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.qitem .actions { display: flex; }
.qitem .actions button { width: 30px; height: 30px; }
.qitem .actions svg { width: 18px; height: 18px; }
.handle {
  color: var(--muted); cursor: grab; display: grid; place-items: center; height: 40px;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.handle:hover { color: var(--text); }
.qitem.dragging {
  position: fixed; z-index: 50; pointer-events: none; background: var(--bg3);
  box-shadow: 0 12px 30px rgba(0,0,0,.55); outline: 1px solid var(--accent);
}
.qitem.dragging .handle { cursor: grabbing; }
.placeholder { border: 1px dashed var(--accent); border-radius: 8px; background: rgba(139,92,246,.08); }
body.is-dragging { cursor: grabbing; user-select: none; -webkit-user-select: none; }
.qitem.flash { animation: flash 1s ease-out; }
@keyframes flash { from { background: rgba(139,92,246,.35); } }

/* ---------------------------------------------------------------- divers */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--mobile-nav)); transform: translate(-50%, 20px);
  background: var(--bg3); border: 1px solid var(--line); padding: 10px 16px; border-radius: 999px;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 100; max-width: 90vw;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; box-shadow: 0 10px 30px rgba(0,0,0,.4);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { border-color: var(--danger); }

.overlay { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(10,10,14,.92); z-index: 200; padding: 20px; }
.overlay-card { max-width: 420px; text-align: center; }
.overlay-card img { width: 96px; height: 96px; object-fit: contain; margin: 0 auto 10px; }
.overlay-card h1 { margin: 0 0 10px; }
body.mode-home .only-expired, body.mode-expired .only-home { display: none; }

.mobile-nav { display: none; }

/* ---------------------------------------------------------------- mobile */
@media (max-width: 860px) {
  :root { --mobile-nav: 60px; --topbar: 50px; }
  .layout { grid-template-columns: 1fr; }
  .layout[data-view="library"] .queue-panel { display: none; }
  .layout[data-view="queue"] .library { display: none; }
  .queue-panel { border-left: 0; }
  .where, .listeners { display: none; }
  .topbar { justify-content: space-between; }
  .lib-top { padding: 10px 12px 0; }
  .lib-body { padding: 12px 12px 40px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
  .hero { flex-direction: column; align-items: flex-start; }
  .hero .cover { width: 140px; height: 140px; }
  .hero h2 { font-size: 22px; }
  .song { grid-template-columns: 40px minmax(0, 1fr) auto; gap: 8px; }
  .song .dur { display: none; }
  .mobile-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; height: var(--mobile-nav);
    background: var(--bg2); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
  }
  .mobile-nav button {
    flex: 1; background: none; border: 0; color: var(--muted);
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 12px;
  }
  .mobile-nav button.active { color: var(--text); }
  .mobile-nav button.active svg { color: var(--accent2); }
}

.queue-head > div:first-child { white-space: nowrap; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
