:root {
  color-scheme: dark;
  --bg: #0b0a0f;
  --surface: #15141b;
  --surface-2: #1e1d26;
  --surface-3: #292833;
  --line: #2a2933;
  --text: #f4f1ec;
  --muted: #a29fab;
  --faint: #6d6a77;
  --accent: #ff8a3d;
  --accent-hover: #ffa463;
  --accent-ink: #1f0e02;
  --accent-soft: rgba(255, 138, 61, .14);
  --danger: #ff5c7a;
  --radius: 10px;
  --row-h: 48px;
  font-family: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  font-size: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { overflow: hidden; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

svg.i { width: 20px; height: 20px; fill: currentColor; display: block; flex: none; }

/* =========================================================
   Layout
   ========================================================= */
.app {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) 84px;
  grid-template-areas: "side main" "player player";
  height: 100dvh;
  gap: 8px;
  padding: 8px 8px 0;
}
.app.queue-open {
  grid-template-columns: 240px minmax(0, 1fr) 320px;
  grid-template-areas: "side main queue" "player player player";
}
.sidebar { grid-area: side; }
.main { grid-area: main; }
.queue-panel { grid-area: queue; }
.player { grid-area: player; }
.tabbar { display: none; }
.sidebar, .main, .queue-panel { background: var(--surface); border-radius: var(--radius); min-height: 0; }

/* =========================================================
   Sidebar
   ========================================================= */
.sidebar { display: flex; flex-direction: column; padding: 14px 8px; overflow: hidden; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 4px 10px 16px; letter-spacing: -.01em; }
.brand-logo { color: var(--accent-ink); background: var(--accent); border-radius: 8px; padding: 5px; }
.brand-logo svg { width: 18px; height: 18px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 6px;
  color: var(--muted); font-weight: 600;
}
.nav-item:hover { color: var(--text); background: var(--surface-2); }
.nav-item.active { color: var(--text); background: var(--surface-3); }
.badge {
  margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--accent); color: var(--accent-ink); font-size: 11px; font-weight: 700; display: grid; place-items: center;
}
.sidebar-heading {
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 10px 6px; color: var(--faint); font-weight: 700; text-transform: uppercase; font-size: 11px; letter-spacing: .08em;
}
.playlist-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.playlist-list li a { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-radius: 6px; }
.playlist-list li a:hover { background: var(--surface-2); }
.playlist-list li.active a { background: var(--surface-3); }
.playlist-list li.drop-target a { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
.pl-thumb { width: 36px; height: 36px; border-radius: 5px; }
.pl-text { min-width: 0; }
.pl-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.pl-count { font-size: 12px; color: var(--muted); }
.sidebar-empty { padding: 6px 10px; color: var(--faint); font-size: 13px; }

/* =========================================================
   Covers
   - default: crop to fill (small thumbnails)
   - .fit: whole image visible over a blurred fill (big covers; YouTube art is 16:9)
   ========================================================= */
.cover {
  position: relative; overflow: hidden; flex: none; display: grid; place-items: center;
  background: linear-gradient(135deg, #34323f, #1d1c24); color: var(--faint);
}
.cover.has-img { background: var(--img) center / cover no-repeat; }
.cover.has-img > svg { display: none; }
.cover.fit.has-img { background: #000; }
.cover.fit.has-img::before {
  content: ""; position: absolute; inset: -12%; background: var(--img) center / cover; filter: blur(22px) brightness(.55); transform: scale(1.1);
}
.cover.fit.has-img::after { content: ""; position: absolute; inset: 0; background: var(--img) center / contain no-repeat; }
.mosaic { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; place-items: stretch; }
.mosaic.has-img { background: none; }
.mosaic > i { background: var(--img) center / cover; }

/* =========================================================
   Main / top bar
   ========================================================= */
.main { overflow-y: auto; overflow-x: hidden; position: relative; }
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; gap: 10px; align-items: center;
  padding: 12px 20px; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(12px);
}
.add-form {
  flex: 1; max-width: 620px; display: flex; align-items: center; gap: 8px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 4px 4px 4px 14px;
}
.add-form:focus-within { border-color: var(--accent); }
.add-icon { color: var(--accent); }
.add-form input { flex: 1; min-width: 0; background: none; border: 0; outline: 0; padding: 6px 0; }
.add-form input::placeholder { color: var(--faint); }
.add-form { position: relative; }
.yt-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 30; max-height: min(70vh, 560px); overflow-y: auto;
  background: var(--surface-3); border: 1px solid #383744; border-radius: var(--radius); padding: 6px; box-shadow: 0 16px 40px rgba(0, 0, 0, .6);
}
.yt-results h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 8px 10px 4px; }
.yt-loading, .yt-none { display: flex; gap: 10px; align-items: center; padding: 14px 10px; color: var(--muted); }
.yt-item { display: flex; gap: 12px; align-items: center; padding: 6px 8px; border-radius: 8px; }
.yt-item:hover { background: var(--surface-2); }
.yt-thumb { width: 64px; aspect-ratio: 16 / 9; flex: none; border-radius: 4px; object-fit: cover; background: var(--surface-2); }
.yt-text { flex: 1; min-width: 0; }
.yt-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.yt-sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.yt-have { font-size: 12px; color: var(--accent); font-weight: 700; white-space: nowrap; }
.search {
  display: flex; align-items: center; gap: 8px; color: var(--muted); margin-left: auto;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 0 14px; width: 220px;
}
.search:focus-within { border-color: var(--muted); }
.search input { background: none; border: 0; outline: 0; padding: 9px 0; width: 100%; color: var(--text); }

.btn { padding: 8px 16px; border-radius: 999px; font-weight: 700; background: var(--surface-3); white-space: nowrap; display: inline-block; text-decoration: none; color: inherit; }
.btn:hover { background: #363542; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { background: var(--danger); color: #1f0208; }
.btn.small { padding: 5px 12px; font-size: 13px; }
.btn.ghost { background: none; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--surface-2); }
.link-btn { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-weight: 600; }
.link-btn:hover { color: var(--text); }
.icon-btn { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; color: var(--muted); flex: none; }
.icon-btn:hover { color: var(--text); background: rgba(255, 255, 255, .07); }
.icon-btn.small { width: 28px; height: 28px; }
.icon-btn.small svg { width: 18px; height: 18px; }
.icon-btn.on { color: var(--accent); position: relative; }
.icon-btn.on::after { content: ""; position: absolute; bottom: 1px; width: 4px; height: 4px; border-radius: 50%; background: var(--accent); }

/* =========================================================
   View header
   ========================================================= */
.view { container-type: inline-size; padding: 0 20px 40px; }
.view-head { display: flex; align-items: center; gap: 18px; padding: 18px 0 14px; }
.view-head .head-cover { width: 96px; height: 96px; border-radius: 8px; box-shadow: 0 6px 24px rgba(0, 0, 0, .45); }
.view-head .head-cover svg { width: 40px; height: 40px; }
.head-text { min-width: 0; flex: 1; }
.head-text .eyebrow { margin: 0 0 2px; font-size: 12px; color: var(--muted); font-weight: 600; }
.head-text h1 { margin: 0; font-size: 28px; line-height: 1.15; letter-spacing: -.02em; overflow-wrap: anywhere; }
.head-text .meta { margin: 4px 0 0; color: var(--muted); }
.head-actions { display: flex; align-items: center; gap: 6px; }
.play-big {
  width: 48px; height: 48px; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; flex: none; transition: transform .1s;
}
.play-big:hover { transform: scale(1.05); background: var(--accent-hover); }
.play-big svg { width: 24px; height: 24px; }

/* =========================================================
   Review ("tidy up") panel
   ========================================================= */
.review { background: linear-gradient(180deg, var(--accent-soft), transparent 140px), var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); margin: 4px 0 18px; }
.review-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px; }
.review-head .rh-text { flex: 1; min-width: 0; }
.review-head strong { display: block; font-size: 15px; }
.review-head span { color: var(--muted); font-size: 13px; }
.review-list { border-top: 1px solid var(--line); }
.review-item { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; gap: 14px; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line); }
.review-item:first-child { border-top: 0; }
.review-cover { width: 64px; height: 64px; border-radius: 6px; position: relative; }
.review-cover .cover-edit {
  position: absolute; inset: 0; z-index: 2; display: grid; place-items: center; background: rgba(0, 0, 0, .55);
  color: #fff; opacity: 0; transition: opacity .15s; font-size: 11px; font-weight: 600;
}
.review-cover:hover .cover-edit, .review-cover:focus-visible .cover-edit { opacity: 1; }
.review-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; min-width: 0; }
.review-fields label { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--muted); font-weight: 600; min-width: 0; }
.review-fields input {
  background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; outline: 0; font-size: 14px; min-width: 0;
}
.review-fields input:focus { border-color: var(--accent); }
.review-orig { grid-column: 1 / -1; font-size: 12px; color: var(--faint); display: flex; gap: 8px; align-items: baseline; min-width: 0; }
.review-orig span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.review-orig button { color: var(--muted); font-size: 12px; font-weight: 600; white-space: nowrap; }
.review-orig button:hover { color: var(--accent); }
.review-actions { display: flex; gap: 4px; align-items: center; }

/* =========================================================
   Track table
   ========================================================= */
.tracks { --cols: 40px minmax(0, 1.5fr) minmax(0, 1fr) minmax(0, .7fr) 56px 108px 52px 36px; }
.tracks-head, .row { display: grid; grid-template-columns: var(--cols); gap: 12px; align-items: center; padding: 0 10px; }
.tracks-head {
  position: sticky; top: 61px; z-index: 3; height: 34px; background: var(--surface);
  color: var(--faint); font-size: 11px; text-transform: uppercase; letter-spacing: .07em; border-bottom: 1px solid var(--line); margin-bottom: 6px;
}
.tracks-head button { display: inline-flex; align-items: center; gap: 2px; color: inherit; text-transform: inherit; letter-spacing: inherit; font-size: inherit; font-weight: 600; }
.tracks-head button:hover { color: var(--text); }
.tracks-head button.sorted { color: var(--accent); }
.tracks-head svg { width: 16px; height: 16px; }
.c-num, .c-plays, .c-time { text-align: right; justify-content: flex-end; font-variant-numeric: tabular-nums; }
.tracks-head .c-num, .tracks-head .c-plays, .tracks-head .c-time { display: flex; }

.row { height: var(--row-h); border-radius: 6px; color: var(--muted); user-select: none; -webkit-user-select: none; position: relative; cursor: default; }
.row:hover { background: var(--surface-2); }
.row.selected { background: var(--accent-soft); }
.row.selected:hover { background: rgba(255, 138, 61, .2); }
.row .c-num { display: flex; align-items: center; }
.row .c-num .row-play { display: none; color: var(--text); }
.row:hover .c-num .n { display: none; }
.row:hover .c-num .row-play { display: grid; }
.c-title { display: flex; align-items: center; gap: 12px; min-width: 0; }
.row .thumb { width: 36px; height: 36px; border-radius: 4px; }
.row .thumb svg { width: 16px; height: 16px; }
.tt { min-width: 0; }
.t-title { color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.t-sub { display: none; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.c-artist, .c-genre, .c-added { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row.playing .t-title, .row.playing .c-num { color: var(--accent); }
.row .c-more { display: flex; justify-content: flex-end; }
.row .more { opacity: 0; }
.row:hover .more, .row.selected .more, .row .more:focus-visible { opacity: 1; }
.row .grip { display: none; touch-action: none; cursor: grab; }
.new-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); margin-left: 6px; vertical-align: middle; }

.row.drop-before::before, .row.drop-after::after {
  content: ""; position: absolute; left: 8px; right: 8px; height: 2px; background: var(--accent); border-radius: 1px;
}
.row.drop-before::before { top: -1px; }
.row.drop-after::after { bottom: -1px; }
.row.dragging { opacity: .35; }
body.is-dragging, body.is-dragging * { cursor: grabbing !important; }

/* pending download rows */
.row.pending { cursor: default; }
.row.pending .c-title { grid-column: 2 / -2; }
.row.pending .thumb { opacity: .7; }
.row.pending .t-sub { display: block; }
.row.pending.error .t-sub { color: var(--danger); white-space: normal; }
.row.pending.error { height: auto; min-height: var(--row-h); padding-top: 6px; padding-bottom: 6px; }
.row-progress { position: absolute; left: 10px; right: 10px; bottom: 2px; height: 2px; background: var(--line); border-radius: 1px; overflow: hidden; }
.row-progress > div { height: 100%; background: var(--accent); transition: width .4s; }
.row-progress.indeterminate > div { width: 30% !important; animation: slide 1.2s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(340%); } }
.spinner { width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.pending-actions { display: flex; gap: 2px; }

.eq { display: inline-flex; gap: 2px; align-items: flex-end; height: 14px; }
.eq i { width: 3px; background: var(--accent); animation: eq .9s ease-in-out infinite; }
.eq i:nth-child(2) { animation-delay: -.3s; }
.eq i:nth-child(3) { animation-delay: -.6s; }
.is-paused .eq i { animation-play-state: paused; }
@keyframes eq { 0%, 100% { height: 3px; } 50% { height: 14px; } }

/* genre filter chips */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 6px 12px; border-radius: 999px; background: var(--surface-2); color: var(--muted);
  font-size: 13px; font-weight: 600; white-space: nowrap;
}
.chip:hover { color: var(--text); background: var(--surface-3); }
.chip.on { background: var(--accent); color: var(--accent-ink); }
.chip .n { opacity: .6; font-weight: 500; margin-left: 4px; }

.empty { text-align: center; color: var(--muted); padding: 48px 16px; line-height: 1.6; }
.empty strong { display: block; color: var(--text); font-size: 18px; margin-bottom: 6px; }

/* medium width: drop secondary columns */
@container (max-width: 760px) {
  .tracks { --cols: 40px minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, .7fr) 52px 36px; }
  .c-plays, .c-added { display: none !important; }
}
/* narrow (phone): two-line rows */
@container (max-width: 540px) {
  .tracks { --cols: minmax(0, 1fr) auto; }
  .tracks-head { display: none; }
  .row { padding: 0 2px 0 4px; --row-h: 56px; }
  .row .c-num, .row .c-artist, .row .c-genre, .row .c-time { display: none; }
  .row .thumb { width: 44px; height: 44px; }
  .t-sub { display: block; }
  .row .more { opacity: 1; }
  .row:hover { background: none; }
  .row.selected { background: var(--accent-soft); }
  .row.pending .c-title { grid-column: 1; }
  .review-item { grid-template-columns: 52px minmax(0, 1fr); }
  .review-cover { width: 52px; height: 52px; }
  .review-fields { grid-template-columns: 1fr; }
  .review-actions { grid-column: 1 / -1; justify-content: flex-end; }
  .view-head .head-cover { width: 72px; height: 72px; }
  .head-text h1 { font-size: 22px; }
}
@media (hover: none) {
  .row .grip { display: grid; }
  .row .c-num .row-play { display: none !important; }
  .row .c-num .n { display: inline !important; }
}

/* =========================================================
   Playlists grid
   ========================================================= */
.pl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 16px; padding-top: 8px; }
.pl-card { background: var(--surface-2); border-radius: var(--radius); padding: 12px; display: block; transition: background .15s; }
.pl-card:hover { background: var(--surface-3); }
.pl-card .cover { width: 100%; aspect-ratio: 1; border-radius: 6px; margin-bottom: 10px; }
.pl-card .cover svg { width: 40px; height: 40px; }
.pl-card .pl-name { font-weight: 600; }
.pl-card.new { display: grid; place-items: center; text-align: center; color: var(--muted); border: 1px dashed var(--line); background: none; min-height: 200px; }
.pl-card.new:hover { color: var(--text); border-color: var(--muted); }
.cover.round { border-radius: 50%; }
.artist-card { text-align: center; }
.sub-head { font-size: 16px; margin: 28px 0 10px; display: flex; gap: 10px; align-items: baseline; }
.sub-head span { font-size: 13px; font-weight: 400; color: var(--muted); }
a.chip { display: inline-flex; }
.artist-link { color: inherit; }
.artist-link:hover { color: var(--text); text-decoration: underline; }
.eyebrow a { color: inherit; }
.eyebrow a:hover { text-decoration: underline; }
button.np-artist { display: block; max-width: 100%; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: none; border: 0; padding: 0; margin-top: 2px; font: inherit; color: var(--muted); font-size: 16px; cursor: pointer; }
button.np-artist:hover { color: var(--text); text-decoration: underline; }
.album-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.more-artist { margin: 8px 0 4px; }
.more-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 28px 0 10px; }
.more-head .sub-head { margin: 0; }
.more-head .btn { display: inline-flex; align-items: center; gap: 6px; }
.more-head .btn svg { width: 16px; height: 16px; }
.more-hint { color: var(--muted); font-size: 14px; margin: 0; }
#more-artist-list h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 10px 8px 4px; }
@container (max-width: 540px) { .pl-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; } }

/* =========================================================
   Queue panel
   ========================================================= */
.queue-panel { display: flex; flex-direction: column; overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 10px 6px 18px; }
.panel-head h2 { margin: 0; font-size: 17px; }
.queue-body { overflow-y: auto; padding: 0 8px 16px; container-type: inline-size; flex: 1; }
.q-label { display: flex; justify-content: space-between; align-items: center; padding: 14px 10px 6px; color: var(--muted); font-size: 12px; font-weight: 700; }
.q-row { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 6px 6px 6px 10px; border-radius: 6px; position: relative; user-select: none; -webkit-user-select: none; }
.q-row:hover { background: var(--surface-2); }
.q-row .thumb { width: 40px; height: 40px; border-radius: 4px; }
.q-row .t-sub { display: block; color: var(--muted); }
.q-row.current .t-title { color: var(--accent); }
.q-row .q-actions { display: flex; opacity: 0; }
.q-row:hover .q-actions, .q-row .q-actions:focus-within { opacity: 1; }
.q-row .grip { touch-action: none; cursor: grab; }
.q-row.drop-before::before, .q-row.drop-after::after { content: ""; position: absolute; left: 8px; right: 8px; height: 2px; background: var(--accent); }
.q-row.drop-before::before { top: -1px; }
.q-row.drop-after::after { bottom: -1px; }
.q-row.dragging { opacity: .35; }
.q-empty { color: var(--faint); padding: 8px 10px; font-size: 13px; }
@media (hover: none) { .q-row .q-actions { opacity: 1; } }

/* =========================================================
   Player bar
   ========================================================= */
.player {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr) minmax(0, 1fr); align-items: center; gap: 16px;
  padding: 0 12px; position: relative;
}
.mini-progress { display: none; }
.now { display: flex; align-items: center; gap: 12px; min-width: 0; text-align: left; border-radius: 8px; padding: 4px; }
.now:hover .now-title { text-decoration: underline; }
.now-cover { width: 56px; height: 56px; border-radius: 6px; }
.now-text { min-width: 0; }
.now-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.now-artist { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.controls { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.buttons { display: flex; align-items: center; gap: 10px; }
.play-btn { width: 38px; height: 38px; border-radius: 50%; background: var(--text); color: #000; display: grid; place-items: center; flex: none; }
.play-btn:hover { transform: scale(1.06); }
.seek { display: flex; align-items: center; gap: 8px; width: 100%; max-width: 620px; }
.time { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; min-width: 36px; text-align: center; }
.side-controls { display: flex; align-items: center; justify-content: flex-end; gap: 2px; }
.side-controls input { width: 100px; }

input[type=range] {
  --pct: 0%;
  -webkit-appearance: none; appearance: none; flex: 1; height: 16px; background: transparent; cursor: pointer; margin: 0; min-width: 0;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px; background: linear-gradient(to right, var(--text) var(--pct), #46444f var(--pct));
}
input[type=range]:hover::-webkit-slider-runnable-track { background: linear-gradient(to right, var(--accent) var(--pct), #46444f var(--pct)); }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 12px; height: 12px; margin-top: -4px; border-radius: 50%; background: var(--text); opacity: 0;
}
input[type=range]:hover::-webkit-slider-thumb, input[type=range]:focus-visible::-webkit-slider-thumb { opacity: 1; }
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: #46444f; }
input[type=range]::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--text); }
input[type=range]::-moz-range-thumb { width: 12px; height: 12px; border: 0; border-radius: 50%; background: var(--text); }

/* =========================================================
   Now playing (full screen)
   ========================================================= */
.nowplaying {
  position: fixed; inset: 0; z-index: 45; display: flex; flex-direction: column; align-items: center; gap: 18px;
  padding: max(12px, env(safe-area-inset-top)) 24px max(24px, env(safe-area-inset-bottom));
  background: var(--bg); overflow: hidden; animation: rise .22s ease-out;
}
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
.np-backdrop { position: absolute; inset: -20%; z-index: -1; background: var(--img, none) center / cover; filter: blur(60px) brightness(.35) saturate(1.3); }
.np-head { width: 100%; max-width: 520px; display: flex; align-items: center; justify-content: space-between; font-weight: 600; font-size: 13px; color: var(--muted); }
.np-cover { width: min(520px, 100%, 52vh); aspect-ratio: 1; border-radius: 12px; box-shadow: 0 24px 60px rgba(0, 0, 0, .6); margin-top: auto; }
.np-cover svg { width: 30%; height: 30%; }
.np-meta { width: 100%; max-width: 520px; }
.np-title { font-size: 24px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.np-artist { color: var(--muted); font-size: 16px; margin-top: 2px; }
.np-seek { flex-direction: column; align-items: stretch; max-width: 520px; gap: 4px; }
.np-times { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.np-controls { width: 100%; max-width: 520px; display: flex; align-items: center; justify-content: space-between; }
.np-controls .big svg { width: 34px; height: 34px; }
.np-controls .icon-btn.big { width: 56px; height: 56px; color: var(--text); }
.play-btn.big { width: 72px; height: 72px; }
.play-btn.big svg { width: 34px; height: 34px; }
.np-foot { margin-bottom: auto; }

/* =========================================================
   Selection bar, menu, dialog, toast, drag ghost
   ========================================================= */
.selection-bar {
  position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%); z-index: 30;
  display: flex; align-items: center; gap: 4px; padding: 6px 6px 6px 16px; border-radius: 999px;
  background: var(--surface-3); box-shadow: 0 12px 32px rgba(0, 0, 0, .55); max-width: calc(100vw - 24px);
}
.selection-bar .count { font-weight: 700; margin-right: 8px; white-space: nowrap; }
.selection-bar .btn { background: none; padding: 7px 12px; }
.selection-bar .btn:hover { background: #3a3946; }
.selection-bar .btn.danger-text { color: var(--danger); }

.menu {
  position: fixed; z-index: 60; min-width: 220px; max-width: 300px; max-height: 70vh; overflow-y: auto;
  background: var(--surface-3); border: 1px solid #383744; border-radius: 8px; padding: 4px; box-shadow: 0 16px 40px rgba(0, 0, 0, .6);
}
.menu button { display: flex; gap: 10px; align-items: center; width: 100%; padding: 9px 12px; border-radius: 5px; text-align: left; }
.menu button:hover, .menu button:focus-visible { background: #3a3946; outline: 0; }
.menu button.danger { color: var(--danger); }
.menu .label { padding: 8px 12px 4px; color: var(--faint); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
.menu .menu-title { padding: 8px 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-bottom: 1px solid #383744; margin-bottom: 4px; }
.menu hr { border: 0; border-top: 1px solid #383744; margin: 4px 0; }

dialog {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line); border-radius: 12px; padding: 22px;
  width: min(420px, calc(100vw - 32px)); box-shadow: 0 16px 48px rgba(0, 0, 0, .7);
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog h2 { margin: 0 0 12px; font-size: 19px; }
dialog p { color: var(--muted); margin: 0 0 12px; }
dialog p:empty { display: none; }
dialog label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 12px; }
dialog input {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px; border-radius: 6px;
  background: var(--surface); border: 1px solid var(--line); outline: 0;
}
dialog input:focus { border-color: var(--accent); }
/* OK comes first in the DOM so Enter submits it; row-reverse shows it on the right. */
.dialog-actions { display: flex; flex-direction: row-reverse; gap: 8px; margin-top: 20px; }

.toast {
  position: fixed; left: 50%; bottom: 104px; transform: translateX(-50%); z-index: 70;
  background: var(--text); color: #000; padding: 10px 16px; border-radius: 8px; font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .5); max-width: calc(100vw - 32px); display: flex; gap: 14px; align-items: center;
}
.toast button { color: #b04800; font-weight: 700; }

.drag-ghost {
  position: fixed; z-index: 80; pointer-events: none; padding: 8px 14px; border-radius: 8px;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
  transform: translate(12px, 12px); max-width: 280px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* =========================================================
   Offline
   ========================================================= */
.offline-pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px 5px 9px; border-radius: 999px; flex: none;
  background: var(--surface-3); color: var(--muted); font-weight: 600; font-size: 13px;
}
.offline-pill svg { width: 18px; height: 18px; }
.dl-mark { display: none; color: var(--accent); margin-right: 5px; vertical-align: -3px; }
.dl-mark svg { width: 14px; height: 14px; display: inline-block; }
.row.dl .dl-mark { display: inline-block; }
body.is-offline .row:not(.dl) { opacity: .38; }
#offline-status { color: var(--accent); }
.inline-icon svg { display: inline-block; width: 16px; height: 16px; vertical-align: -3px; }

/* =========================================================
   Settings
   ========================================================= */
.settings { display: grid; gap: 14px; max-width: 720px; padding-bottom: 20px; }
.card { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.card h2 { margin: 0 0 10px; font-size: 15px; }
.setting { display: flex; align-items: center; gap: 16px; padding: 10px 0; cursor: default; }
.setting + .setting { border-top: 1px solid var(--line); }
label.setting { cursor: pointer; }
.s-text { flex: 1; min-width: 0; }
.s-label { font-weight: 600; }
.s-help { color: var(--muted); font-size: 13px; line-height: 1.5; margin: 2px 0 0; }
.s-line { margin: 0 0 4px; }
.s-note { margin: 10px 0 0; padding: 8px 12px; border-radius: 8px; background: var(--accent-soft); color: var(--text); font-size: 13px; line-height: 1.5; }
.s-control { display: flex; align-items: center; gap: 10px; flex: none; }
.s-control input[type=range] { width: 160px; }
.s-value { width: 32px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.s-actions { margin-top: 12px; display: flex; gap: 8px; }
.s-list { list-style: none; margin: 10px 0 0; padding: 0; }
.s-list li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-top: 1px solid var(--line); font-size: 13px; }
.s-list li span { color: var(--faint); flex: none; }
.s-list a { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.s-list a:hover { color: var(--accent); }
.s-details { margin-top: 12px; }
.s-details summary { cursor: pointer; color: var(--muted); font-weight: 600; font-size: 13px; }
.s-details summary:hover { color: var(--text); }
.card code { background: var(--surface-3); padding: 1px 5px; border-radius: 4px; font-size: 12px; overflow-wrap: anywhere; }
.switch {
  appearance: none; -webkit-appearance: none; flex: none; margin: 0; cursor: pointer;
  width: 40px; height: 22px; border-radius: 11px; background: #46444f; position: relative; transition: background .15s;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--text); transition: transform .15s;
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(18px); background: var(--accent-ink); }


/* =========================================================
   Phone
   ========================================================= */
@media (max-width: 820px) {
  .app, .app.queue-open {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto auto;
    grid-template-areas: "main" "player" "tabbar";
    padding: 0; gap: 0;
  }
  .sidebar { display: none; }
  .main { border-radius: 0; }
  .topbar { flex-wrap: wrap; padding: 10px 14px; gap: 8px; }
  .add-form { flex-basis: 100%; max-width: none; }
  .search { width: auto; flex: 1; margin: 0; }
  .setting { flex-wrap: wrap; }
  .s-control { width: 100%; }
  .s-control input[type=range] { flex: 1; width: auto; }
  .card { padding: 14px; }
  .view { padding: 0 14px 24px; }
  .tracks-head { top: 108px; }

  .queue-panel {
    position: fixed; inset: 0; z-index: 46; border-radius: 0; background: var(--bg);
    padding-top: env(safe-area-inset-top); animation: rise .2s ease-out;
  }

  .player {
    display: flex; gap: 8px; padding: 8px 10px 8px 8px; background: var(--surface-2);
    margin: 0 6px; border-radius: 10px;
  }
  .player .now { flex: 1; padding: 0; }
  .now-cover { width: 44px; height: 44px; }
  .player .desk, .side-controls { display: none !important; }
  .controls { flex-direction: row; }
  .player .play-btn { width: 36px; height: 36px; background: none; color: var(--text); }
  .player .play-btn svg { width: 28px; height: 28px; }
  .mini-progress { display: block; position: absolute; left: 10px; right: 10px; bottom: 0; height: 2px; background: rgba(255, 255, 255, .12); border-radius: 1px; overflow: hidden; }
  .mini-progress > div { height: 100%; width: 0; background: var(--text); }

  .tabbar {
    grid-area: tabbar; display: flex; justify-content: space-around;
    padding: 6px 0 max(6px, env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 30%);
  }
  .tabbar > * { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); padding: 4px 10px; position: relative; }
  .tabbar > .active { color: var(--text); }
  .tabbar svg { width: 24px; height: 24px; }
  .tabbar .badge { position: absolute; top: -2px; right: 8px; margin: 0; min-width: 16px; height: 16px; font-size: 10px; padding: 0 4px; }

  .selection-bar { bottom: 140px; }
  .selection-bar .btn .lbl { display: none; }
  .toast { bottom: 150px; }
}

/* =========================================================
   Sign in / join
   ========================================================= */
.auth { position: fixed; inset: 0; z-index: 100; background: var(--bg); display: grid; place-items: center; padding: 16px; overflow-y: auto; }
.auth-card { width: min(360px, 100%); background: var(--surface-2); border: 1px solid var(--line); border-radius: 16px; padding: 28px 24px 24px; }
.auth-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; margin-bottom: 22px; }
.auth-card h1 { margin: 0 0 6px; font-size: 22px; }
.auth-card p { margin: 0 0 16px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.auth-card p:empty { display: none; }
.auth-card label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 12px; }
.auth-card input {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px; font-size: 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; outline: none;
}
.auth-card input:focus { border-color: var(--accent); }
.auth-card .auth-error { color: var(--danger); }
.auth-card .btn { width: 100%; padding: 11px; margin-top: 6px; }
.auth-card .btn:disabled { opacity: .6; }

.people li { align-items: center; }
.people .p-name { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.people em { font-style: normal; font-weight: 400; color: var(--faint); }
.link-btn { color: var(--danger); margin-left: 10px; font-size: 13px; }
.link-btn:hover { text-decoration: underline; }
#invite-box { margin-top: 12px; }
.invite-link { display: flex; gap: 8px; margin-top: 8px; }
.invite-link input {
  flex: 1; min-width: 0; padding: 5px 10px; font-size: 13px; color: var(--muted);
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; outline: none;
}
