:root {
  --bg: #0e0f13;
  --panel: #161821;
  --panel2: #1c1f2b;
  --line: #2a2e3d;
  --text: #e7e9f0;
  --dim: #9aa0b4;
  --accent: #6ee7b7;
  --accent2: #60a5fa;
  --err: #f87171;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* topbar */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 5px 12px; border-bottom: 1px solid var(--line);
  background: var(--panel);
  flex-wrap: nowrap;            /* never stack: the nav scrolls instead */
}
.brand { font-size: 15px; flex: none; }
.brand .sub { color: var(--dim); font-size: 12px; margin-left: 6px; }
.stats { color: var(--dim); font-size: 12px; margin-left: auto; white-space: nowrap; }
.actions { display: flex; gap: 8px; margin-left: auto; flex: none; }

/* top nav tabs (Music / Movies / Books), shared across pages.
   The tabs outgrew the width on phones; the row scrolls sideways instead of
   wrapping into a second line, and the scrollbar itself is hidden. */
.nav {
  display: flex; gap: 4px; flex-wrap: nowrap;
  overflow-x: auto; overflow-y: hidden;
  min-width: 0; scrollbar-width: none; -ms-overflow-style: none;
  overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch;
}
.nav::-webkit-scrollbar { display: none; }
.navlink {
  color: var(--dim); text-decoration: none; font-size: 13px; font-weight: 500;
  padding: 5px 10px; border-radius: 8px; border: 1px solid transparent;
  white-space: nowrap; flex: none;
}
.navlink:hover { color: var(--text); background: var(--panel2); }
.navlink.active { color: var(--text); background: var(--panel2); border-color: var(--line); }
button {
  background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  padding: 7px 12px; border-radius: 8px; cursor: pointer; font-size: 13px;
}
button:hover { border-color: var(--accent2); }
button.primary { background: var(--accent); color: #06281d; border-color: var(--accent); font-weight: 600; }
button.ghost { background: transparent; }
button:disabled { opacity: .5; cursor: default; }

/* modal (Sources) */
.modal-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.6);
  display: flex; align-items: flex-start; justify-content: center; padding: 64px 16px; }
.modal-backdrop[hidden] { display: none; }
/* transcript can open on top of the search modal */
#transcriptModal { z-index: 60; }
.modal { width: min(840px, 94vw); max-height: 84vh; overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 24px 70px rgba(0,0,0,.55); }
.modal-head { display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); }
.modal-title { font-weight: 600; }
.modal-close { background: transparent; border: 1px solid var(--line); color: var(--dim);
  border-radius: 8px; padding: 4px 10px; cursor: pointer; font-size: 14px; }
.modal-close:hover { color: var(--text); border-color: var(--accent2); }

/* sources (inside the modal) */
.sources { padding: 14px 16px; display: flex; flex-direction: column; gap: 14px; }
.src-block { display: flex; flex-direction: column; gap: 8px; }
.src-head { display: flex; align-items: center; gap: 10px; }
.src-name { font-weight: 600; }
.src-state { color: var(--dim); font-size: 12px; }
.src-state.ok { color: var(--accent); }
.src-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.src-input { background: var(--panel2); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 7px 10px; font-size: 13px; min-width: 240px; }
.src-input:focus { outline: none; border-color: var(--accent2); }
.src-textarea { background: var(--panel2); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 8px 10px; font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  width: 100%; max-width: 760px; height: 90px; resize: vertical; }
.src-textarea:focus { outline: none; border-color: var(--accent2); }
.src-hint { color: var(--dim); font-size: 12px; }
.src-hint code { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px;
  padding: 2px 6px; font-size: 12px; color: var(--accent2); user-select: all; }
.src-hint a { color: var(--accent2); }
.btn { background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  padding: 6px 11px; border-radius: 8px; cursor: pointer; font-size: 13px; text-decoration: none; }
.btn:hover { border-color: var(--accent2); }
.btn.primary { background: var(--accent); color: #06281d; border-color: var(--accent); font-weight: 600; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: default; pointer-events: none; }
.src-prog { color: var(--dim); font-size: 12px; }
.src-prog div { padding: 1px 0; }

/* playlist picker */
#pickModal { z-index: 70; }
.modal.pick { width: min(460px, 94vw); display: flex; flex-direction: column; }
.pick-body { padding: 12px; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.pick-input { background: var(--panel2); border: 1px solid var(--line); color: var(--text);
  border-radius: 9px; padding: 10px 12px; font-size: 14px; width: 100%; }
.pick-input:focus { outline: none; border-color: var(--accent2); }
.pick-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; max-height: 46vh;
  border: 1px solid var(--line); border-radius: 9px; }
.pick-list li { padding: 9px 12px; cursor: pointer; font-size: 13px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 8px; }
.pick-list li:last-child { border-bottom: 0; }
.pick-list li:hover, .pick-list li.active { background: var(--panel2); }
.pick-list li.create { color: var(--accent); }
.pick-list li.create b { color: var(--text); }
.pick-list li .pl-count { margin-left: auto; color: var(--dim); font-size: 11px; }
.pick-list li.empty { color: var(--dim); cursor: default; justify-content: center; }
.pick-list li.empty:hover { background: transparent; }

/* progress */
.progress { padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.bar { height: 6px; background: var(--panel2); border-radius: 4px; overflow: hidden; }
.fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent2), var(--accent)); transition: width .3s; }
.ptext { color: var(--dim); font-size: 12px; margin-top: 4px; }

/* layout */
.layout { display: flex; flex: 1; min-height: 0; }
.sidebar {
  width: 320px; border-right: 1px solid var(--line); background: var(--panel);
  display: flex; flex-direction: column; min-height: 0;
}
.sidebar input { margin: 10px; padding: 8px 10px; background: var(--panel2);
  border: 1px solid var(--line); color: var(--text); border-radius: 8px; }
.sidebar-top { display: flex; gap: 6px; align-items: center; margin: 10px; }
.sidebar-top input { margin: 0; flex: 1; min-width: 0; }
#plSort {
  flex: none; margin: 0; padding: 8px 6px; font-size: 12px; max-width: 44%;
  background: var(--panel2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; cursor: pointer;
}
/* "Recent" groups the list: the ones you actually opened sit above the rest */
.playlists .plsep {
  padding: 10px 10px 4px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--dim); cursor: default; background: none;
}
.playlists .plsep:hover { background: none; }
.playlists .pwhen { color: var(--dim); font-size: 11px; flex: none; margin-left: 6px; }
#btnClean { flex: none; font-size: 12px; padding: 8px 10px; white-space: nowrap; }
.playlists { list-style: none; margin: 0; padding: 0 6px 10px; overflow: auto; flex: 1; }
.playlists li {
  padding: 8px 10px; border-radius: 8px; cursor: pointer;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.playlists li:hover { background: var(--panel2); }
.playlists li.active { background: var(--panel2); outline: 1px solid var(--accent2); }
.playlists .pname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.playlists .pcount { color: var(--dim); font-size: 12px; flex: none; }
.playlists .pdir { color: var(--dim); font-size: 11px; }
.playlists .porig { color: var(--dim); opacity: .7; font-style: italic; margin-left: 6px; }
/* per-row ⋯ menu button: hidden until hover/active to keep the list clean */
.playlists .pmenu {
  flex: none; opacity: 0; padding: 2px 7px; font-size: 13px; line-height: 1;
  background: transparent; border: 1px solid var(--line); color: var(--dim); border-radius: 6px;
}
.playlists li:hover .pmenu, .playlists li.active .pmenu { opacity: 1; }
.playlists .pmenu:hover { color: var(--text); border-color: var(--accent2); }
.pmenu-pop {
  position: fixed; z-index: 70; min-width: 150px; padding: 4px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 12px 36px rgba(0,0,0,.5); display: flex; flex-direction: column; gap: 2px;
}
.pmenu-pop button {
  text-align: left; background: transparent; border: 0; color: var(--text);
  padding: 8px 10px; border-radius: 7px; font-size: 13px; cursor: pointer;
}
.pmenu-pop button:hover { background: var(--panel2); }
.pmenu-pop button.danger { color: var(--err); }
.pmenu-pop button.danger:hover { background: #3a1010; }

/* content */
.content { flex: 1; overflow: auto; padding: 16px 20px; min-height: 0; }
.songs-head { font-size: 16px; font-weight: 600; margin-bottom: 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.songs-head .meta { color: var(--dim); font-size: 12px; font-weight: 400; margin-left: 8px; }
#dlAll { font-size: 12px; padding: 7px 12px; flex: none; }
.empty { color: var(--dim); margin-top: 40px; text-align: center; }

.song {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; margin-bottom: 12px;
}
.song .row { display: flex; align-items: center; gap: 10px; }
.song .row-lead { display: flex; align-items: center; gap: 10px; flex: none; }
.song .row-main { display: flex; align-items: baseline; gap: 10px; min-width: 0; flex: 1; }
.song .row-actions { display: flex; align-items: center; gap: 8px; flex: none; margin-left: auto; }
.song .row-actions .dlstate { margin-left: 0; }   /* cluster handles alignment now */
.song.tappable { cursor: pointer; }
.song.tappable:hover { border-color: #3a4055; }
.song .row-more { display: none; }   /* desktop shows all actions; this is a mobile affordance */
.songs-head .back-btn { display: none; }   /* mobile-only back button */
.song .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.song .artist { color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: none; max-width: 40%; }
.song .state { font-size: 11px; padding: 2px 8px; border-radius: 999px; flex: none; }
.state.pending { background: #2a2e3d; color: var(--dim); }
.state.done { background: #103a2c; color: var(--accent); }
.state.error { background: #3a1010; color: var(--err); }

.cands { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; margin-top: 10px; }
.cands.collapsed { display: none; }
.cand {
  background: var(--panel2); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px; color: var(--text);
  display: flex; flex-direction: column; gap: 8px;
}
.cand:hover { border-color: var(--accent2); }
.cand-link { display: flex; gap: 10px; text-decoration: none; color: var(--text); }
.cand .thumb { width: 96px; height: 54px; border-radius: 6px; object-fit: cover; flex: none; background: #000; }
.cand .ci { min-width: 0; }
.cand .rank { color: var(--accent); font-size: 11px; }
.cand .ct { font-size: 12px; line-height: 1.3; max-height: 32px; overflow: hidden; }
.cand .cc { color: var(--dim); font-size: 11px; margin-top: 2px; }
.cand .dl {
  font-size: 11px; padding: 5px 8px; align-self: flex-start;
  background: var(--panel); border: 1px solid var(--line); color: var(--accent2);
}
.cand .dl:hover:not(:disabled) { border-color: var(--accent2); background: var(--panel2); }
.cand .dllocal {
  font-size: 11px; padding: 5px 8px; align-self: flex-start; text-decoration: none;
  background: var(--panel); border: 1px solid var(--line); color: var(--dim);
  border-radius: 4px;
}
.cand .dllocal:hover { border-color: var(--accent); color: var(--accent); background: var(--panel2); }
.cand .tr {
  font-size: 11px; padding: 5px 7px; align-self: flex-start;
  background: var(--panel); border: 1px solid var(--line); color: var(--dim);
}
.cand .tr:hover { border-color: var(--accent2); color: var(--accent2); background: var(--panel2); }

/* transcript modal */
.tr-body { display: flex; flex-direction: column; gap: 10px; padding: 14px; }
.tr-meta { font-size: 13px; color: var(--text); }
.tr-status { font-size: 13px; color: var(--dim); }
.tr-text {
  width: 100%; min-height: 46vh; resize: vertical; font-size: 13px; line-height: 1.5;
  background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px; white-space: pre-wrap;
}
.tr-actions { display: flex; gap: 8px; }
.dlstate { font-size: 11px; padding: 2px 8px; border-radius: 999px; margin-left: auto; }
.dlstate.done { background: #102a3a; color: var(--accent2); }
.dlstate.downloading { background: #2a2e3d; color: var(--dim); }
.dlstate.error { background: #3a1010; color: var(--err); }
.song .nocands { color: var(--dim); font-size: 12px; margin-top: 8px; }
.song .retry { font-size: 11px; padding: 3px 8px; margin-left: 8px; }
.song .rowdl { font-size: 11px; padding: 3px 10px; margin-left: 8px;
  color: #06281d; background: var(--accent); border: 1px solid var(--accent); font-weight: 600; }
.song .rowdl:hover:not(:disabled) { filter: brightness(1.08); }
.song .rowdllocal { font-size: 11px; padding: 3px 10px; margin-left: 8px; text-decoration: none;
  background: var(--panel); border: 1px solid var(--line); color: var(--dim);
  border-radius: 4px; }
.song .rowdllocal:hover { border-color: var(--accent); color: var(--accent); background: var(--panel2); }
.song .jellyfin {
  font-size: 11px; padding: 3px 8px; border-radius: 6px;
  border: 1px solid #3a5a7a; color: var(--accent2); text-decoration: none;
}
.song .jellyfin:hover { background: #102a3a; }

/* compact controls: inline play + expand toggle for the candidate grid */
.song .playbtn {
  font-size: 11px; line-height: 1; padding: 0; flex: none;
  width: 26px; height: 26px; border-radius: 999px;
  background: var(--panel2); color: var(--accent); border: 1px solid var(--line);
}
.song .playbtn:hover { border-color: var(--accent); background: #103a2c; }
/* rank-1 video shown small inline next to the play button (collapsed view) */
.song .rowthumb {
  width: 64px; height: 36px; border-radius: 5px; object-fit: cover;
  background: #000; flex: none; cursor: pointer; border: 1px solid var(--line);
}
.song .rowthumb:hover { border-color: var(--accent2); }
.song .expand { font-size: 11px; padding: 3px 8px; margin-left: 8px; color: var(--dim); }
.song .expand.open { color: var(--text); border-color: var(--accent2); }
/* the row currently playing in the bar */
.song.playing { border-color: var(--accent); }
.song.playing .title { color: var(--accent); }

/* playback bar (fixed at the bottom, Spotify-like) */
.has-playbar .content { padding-bottom: 84px; }
.playbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  display: flex; align-items: center; gap: 16px;
  padding: 8px 16px; background: var(--panel); border-top: 1px solid var(--line);
  box-shadow: 0 -8px 30px rgba(0,0,0,.4);
}
.playbar[hidden] { display: none; }
.pb-now { display: flex; align-items: center; gap: 10px; width: 260px; min-width: 0; }
.pb-thumb { width: 48px; height: 48px; border-radius: 6px; object-fit: cover; background: #000; flex: none; }
.pb-meta { min-width: 0; }
.pb-title { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pb-channel { color: var(--dim); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pb-center { flex: 1; display: flex; align-items: center; gap: 12px; min-width: 0; }
.pb-toggle {
  flex: none; width: 38px; height: 38px; border-radius: 999px;
  font-size: 14px; line-height: 1; padding: 0;
  background: var(--accent); color: #06281d; border: 1px solid var(--accent); font-weight: 600;
}
.pb-toggle:hover { filter: brightness(1.08); }
.pb-nav {
  flex: none; width: 30px; height: 30px; border-radius: 999px; padding: 0;
  font-size: 13px; line-height: 1; background: transparent; color: var(--text);
  border: 1px solid var(--line);
}
.pb-nav:hover { border-color: var(--accent2); color: var(--accent); }
.pb-seekwrap { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; }
.pb-time { color: var(--dim); font-size: 11px; font-variant-numeric: tabular-nums; flex: none; width: 36px; }
.pb-time:last-child { text-align: right; }
.pb-seek { flex: 1; accent-color: var(--accent); height: 4px; cursor: pointer; }
/* playback speed: -  1×  + */
.pb-speed { display: flex; align-items: center; gap: 4px; flex: none; }
.pb-spd { width: 26px; height: 26px; padding: 0; line-height: 1; border-radius: 999px;
  font-size: 15px; background: var(--panel2); color: var(--text); border: 1px solid var(--line); }
.pb-spd:hover { border-color: var(--accent2); color: var(--accent); }
.pb-spdlabel { color: var(--dim); font-size: 12px; font-variant-numeric: tabular-nums;
  min-width: 30px; text-align: center; }
.pb-right { display: flex; align-items: center; gap: 8px; flex: none; }
/* keep a small live video so YouTube actually plays (it won't autoplay a 0x0 frame reliably) */
.pb-video { width: 110px; height: 62px; border-radius: 6px; overflow: hidden; background: #000; }
.pb-video iframe { width: 100%; height: 100%; border: 0; display: block; }
.pb-open, .pb-close {
  flex: none; width: 28px; height: 28px; line-height: 1; padding: 0; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--panel2); color: var(--dim); border: 1px solid var(--line); text-decoration: none;
}
.pb-open:hover, .pb-close:hover { color: var(--text); border-color: var(--accent2); }
.pb-queue {
  position: relative; flex: none; width: 28px; height: 28px; line-height: 1; padding: 0;
  border-radius: 8px; background: var(--panel2); color: var(--dim); border: 1px solid var(--line);
}
.pb-queue:hover { color: var(--text); border-color: var(--accent2); }
.q-badge {
  position: absolute; top: -6px; right: -6px; min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 999px; background: var(--accent); color: #06281d; font-size: 10px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}

/* inline "+ Queue" button on a song row (first-class, always visible) */
.song .qbtn {
  flex: none; font-size: 11px; padding: 4px 9px; border-radius: 999px;
  background: var(--panel2); color: var(--accent2); border: 1px solid var(--line); white-space: nowrap;
}
.song .qbtn:hover { border-color: var(--accent2); background: #102a3a; }
.song .qbtn.done { color: var(--accent); border-color: var(--accent); }
.song .rowrm { font-size: 11px; padding: 3px 8px; color: var(--err); border-color: #5a3a3a; }
.song .rowrm:hover { background: #3a1010; }

/* queue panel (slide-in from the right) */
.queue-panel { position: fixed; inset: 0; z-index: 65; background: rgba(0,0,0,.5);
  display: flex; justify-content: flex-end; }
.queue-panel[hidden] { display: none; }
.queue-card { width: min(420px, 92vw); height: 100%; background: var(--panel);
  border-left: 1px solid var(--line); display: flex; flex-direction: column;
  box-shadow: -16px 0 50px rgba(0,0,0,.5); }
.queue-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px;
  border-bottom: 1px solid var(--line); }
.queue-title { font-weight: 600; flex: 1; }
.queue-list { overflow: auto; flex: 1; padding: 8px; }
.q-empty { color: var(--dim); text-align: center; padding: 40px 16px; font-size: 13px; }
.q-item { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; }
.q-item:hover { background: var(--panel2); }
.q-thumb { width: 56px; height: 32px; border-radius: 5px; object-fit: cover; background: #000; flex: none; }
.q-meta { flex: 1; min-width: 0; }
.q-title { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.q-channel { color: var(--dim); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.q-play, .q-del { flex: none; width: 30px; height: 30px; padding: 0; border-radius: 999px;
  background: transparent; border: 1px solid var(--line); color: var(--dim); font-size: 12px; }
.q-play:hover { color: var(--accent); border-color: var(--accent); }
.q-del:hover { color: var(--err); border-color: #5a3a3a; }

/* sidebar action buttons (Search / New / Clean names) */
.sidebar-actions { display: flex; gap: 6px; margin: 10px 10px 0; flex-wrap: wrap; }
.sidebar-actions #btnSearch { flex: 1 1 100%; }
.sidebar-actions #btnNewPl { flex: 1; }
.sidebar-actions #btnClean { flex: 1; white-space: nowrap; }

/* search modal */
.srch-body { padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; }
.srch-input { background: var(--panel2); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 11px 12px; font-size: 15px; width: 100%; }
.srch-input:focus { outline: none; border-color: var(--accent2); }
.srch-results { display: flex; flex-direction: column; gap: 4px; min-height: 120px; }
.srch-note { color: var(--dim); font-size: 13px; padding: 16px 4px; text-align: center; }
.srch-more { display: block; width: 100%; margin: 10px 0 4px; padding: 10px;
  background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; cursor: pointer; font-size: 13px; }
.srch-more:hover { border-color: var(--accent2); }
.srch-more:disabled { opacity: .6; cursor: default; }
.srch-sec { color: var(--dim); font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  margin: 8px 2px 2px; }
.srch-row { display: flex; align-items: center; gap: 10px; padding: 7px 6px; border-radius: 10px; }
.srch-row:hover { background: var(--panel2); }
.srch-thumb { width: 64px; height: 36px; border-radius: 5px; object-fit: cover; background: #000; flex: none; }
.srch-meta { flex: 1; min-width: 0; }
.srch-title { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.srch-channel { color: var(--dim); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.srch-play { flex: none; width: 32px; height: 32px; padding: 0; border-radius: 999px;
  background: transparent; border: 1px solid var(--line); color: var(--accent); }
.srch-play:hover { border-color: var(--accent); background: #103a2c; }
.srch-tr { flex: none; width: 32px; height: 32px; padding: 0; border-radius: 999px;
  background: transparent; border: 1px solid var(--line); color: var(--dim); font-size: 13px; }
.srch-tr:hover { border-color: var(--accent2); color: var(--accent2); background: var(--panel2); }
.srch-queue { flex: none; font-size: 12px; padding: 7px 11px; white-space: nowrap;
  background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; }
.srch-queue:hover { border-color: var(--accent2); }
.srch-queue.done { color: var(--accent); border-color: var(--accent); }
.srch-add { flex: none; font-size: 12px; padding: 7px 11px; white-space: nowrap; }

/* login */
.login-body {
  display: flex; align-items: center; justify-content: center;
  height: 100vh; background: var(--bg);
}
.login-card {
  width: 320px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 28px 24px; display: flex; flex-direction: column; gap: 12px;
}
.login-brand { font-size: 22px; text-align: center; }
.login-sub { color: var(--dim); text-align: center; margin: 0 0 6px; font-size: 13px; }
.login-card label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--dim); }
.login-card input {
  background: var(--panel2); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 10px; font-size: 14px;
}
.login-card input:focus { outline: none; border-color: var(--accent2); }
.login-btn { margin-top: 6px; padding: 10px; font-size: 14px; }
.login-err { color: var(--err); font-size: 13px; text-align: center; }
.logout { font-size: 12px; }

/* ── mobile ──────────────────────────────────────────────────────────────────
   Phones/narrow screens: stack the music sidebar over the content, let the
   topbar wrap, and make modals/inputs fill the width. The song rows and the
   playback bar get a Spotify-style mobile layout (title takes a full line,
   actions wrap below, transport on its own row over a full-width scrubber).
   Reader + torrents pages carry their own media blocks. */
@media (max-width: 760px) {
  body { height: 100dvh; }

  /* tap targets: comfortable minimum, no iOS zoom on focus (>=16px inputs) */
  button, .btn { min-height: 40px; }
  .navlink { min-height: 34px; }

  .topbar { gap: 8px; padding: 4px 10px; flex-wrap: nowrap; }
  .brand .sub { display: none; }
  .nav { flex: 1 1 auto; min-width: 0; }
  .navlink { padding: 5px 9px; display: inline-flex; align-items: center; }
  /* the counters were forcing a whole extra row of chrome on a phone */
  .stats { display: none; }
  .actions { flex-wrap: wrap; gap: 6px; }

  /* ── two-screen nav (Spotify-style): the playlist list and the song list are
       separate full-screen views. By default show playlists; selecting one adds
       body.mobile-songs which hides the sidebar and shows the songs full-screen.
       A back button returns. Only one view occupies the screen at a time. ── */
  .layout { flex-direction: column; position: relative; }
  .sidebar { width: 100%; max-height: none; flex: 1; border-right: none; border-bottom: none; }
  .content { padding: 12px 12px; display: none; }     /* hidden until a playlist is picked */
  body.mobile-songs .sidebar { display: none; }
  body.mobile-songs .content { display: block; flex: 1; }

  .sidebar-top { flex-wrap: wrap; }
  .sidebar-top input { font-size: 16px; }      /* no zoom-on-focus */
  #btnClean { flex: 1 1 100%; }

  /* compact, Spotify-like playlist rows: one tight line, no source label */
  .playlists { padding: 4px 6px 10px; }
  .playlists li { padding: 9px 8px; gap: 10px; }
  .playlists .pdir { display: none; }           /* drop "spotify+youtube" on mobile */
  .playlists .pname { font-size: 15px; line-height: 1.2; }
  .playlists .pcount { font-size: 12px; }
  .playlists .pmenu { opacity: 1; min-height: 0; padding: 7px 9px; }  /* always tappable; not forced to 40px */

  .modal-backdrop { padding: 16px 8px; }
  .modal { width: 100%; max-height: 90vh; }
  .src-input { min-width: 0; width: 100%; font-size: 16px; }
  .src-row { gap: 6px; }

  .login-card { width: min(320px, 92vw); }

  /* hard safety net: the music content column never scrolls sideways */
  .content { overflow-x: hidden; }

  /* songs header: a sticky bar with [‹ Playlists] [title] [download] */
  .songs-head { flex-wrap: wrap; align-items: center; gap: 8px;
    position: sticky; top: 0; z-index: 5; background: var(--bg);
    margin: -12px -12px 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
  .songs-head .back-btn { display: inline-flex; align-items: center; flex: none;
    font-size: 14px; padding: 8px 12px; background: var(--panel2); }
  .songs-head .sh-title { flex: 1 1 100%; min-width: 0; font-size: 15px; overflow-wrap: anywhere; order: 3; }
  .songs-head .meta { margin-left: 0; display: block; }
  .songs-head #dlAll { flex: none; margin: 0; font-size: 12px; padding: 8px 10px; }

  /* ── compact song card: ONE line. thumb+play | title/artist | ⋯
       The action buttons (Jellyfin/Download/re-match) are hidden until ⋯ is
       tapped, so the resting card is small like a Spotify track row. ── */
  .song { padding: 8px 10px; }
  .song .row { flex-wrap: wrap; gap: 8px 8px; align-items: center; }
  .song .row-lead { order: 1; flex: none; }
  .song .row-main { order: 2; flex: 1 1 0; min-width: 0; flex-direction: column; align-items: stretch; gap: 1px; }
  /* keep the +Queue button first-class on mobile: a compact icon-ish chip */
  .song .qbtn { order: 3; flex: none; font-size: 11px; padding: 6px 9px; }
  .song .row-more { order: 4; display: inline-flex; align-items: center; justify-content: center;
    flex: none; width: 34px; height: 34px; padding: 0; font-size: 16px; line-height: 1;
    background: transparent; border: 1px solid var(--line); color: var(--dim); border-radius: 999px; }
  /* actions hidden by default; ⋯ reveals them on their own wrapped row */
  .song .row-actions { order: 5; flex: 1 1 100%; margin-left: 0; flex-wrap: wrap; gap: 8px;
    display: none; padding-top: 8px; margin-top: 4px; border-top: 1px solid var(--line); }
  .song.actions-open .row-actions { display: flex; }
  .song.actions-open .row-more { color: var(--accent); border-color: var(--accent2); }
  /* title: single line, ellipsis (compact); artist smaller underneath */
  .song .title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    max-width: 100%; font-size: 14px; line-height: 1.3; }
  .song .artist { max-width: 100%; overflow: hidden; text-overflow: ellipsis;
    white-space: nowrap; font-size: 12px; }
  .song .rowthumb { width: 48px; height: 48px; }
  .song .playbtn { width: 38px; height: 38px; font-size: 13px; }
  .song .state { order: 9; margin-left: auto; }
  .song .jellyfin, .song .rowdl, .song .rowdllocal, .song .expand, .song .retry { min-height: 38px;
    display: inline-flex; align-items: center; }

  /* candidate grid: one column when expanded */
  .cands { grid-template-columns: 1fr; }

  /* ── playback bar: two rows. Row 1: art + meta + close. Row 2: transport
       over a full-width scrubber. (Spotify-mobile mini-player feel.) ── */
  .has-playbar .content { padding-bottom: 116px; }
  .playbar { flex-wrap: wrap; gap: 6px 10px; padding: 8px 12px 10px; align-items: center; }
  .pb-now { width: auto; flex: 1 1 auto; order: 1; min-width: 0; }
  .pb-now .pb-meta { display: block; min-width: 0; }
  .pb-video { display: none; }
  .pb-open { display: none; }                /* drop the external-link chip on mobile */
  .pb-right { order: 2; flex: none; gap: 10px; }
  .pb-close { width: 34px; height: 34px; }
  /* the whole transport + scrubber spans the full second line */
  .pb-center { order: 3; flex: 1 1 100%; gap: 10px 12px; flex-wrap: wrap; justify-content: center; }
  .pb-toggle { width: 44px; height: 44px; font-size: 16px; }   /* primary action, bigger */
  .pb-nav { width: 40px; height: 40px; font-size: 15px; }
  .pb-seekwrap { flex: 1 1 100%; gap: 8px; }   /* seek on its own line */
  .pb-seek { height: 6px; }                  /* fatter, easier to drag */
  .pb-time { width: 34px; font-size: 12px; }
  .pb-queue { width: 34px; height: 34px; }   /* keep the queue toggle tappable */
  /* speed sits with the transport buttons on the controls line */
  .pb-speed { gap: 6px; }
  .pb-spd { width: 32px; height: 32px; font-size: 16px; }
  .pb-spdlabel { min-width: 34px; font-size: 13px; }

  /* sidebar actions stack full-width on mobile */
  .sidebar-actions { margin: 10px 10px 0; }
  .sidebar-actions #btnNewPl, .sidebar-actions #btnClean { flex: 1 1 0; }
  .sidebar-top input { font-size: 16px; }

  /* songs-head "Add songs" button sits with Download all */
  .songs-head #addSongs { flex: none; font-size: 12px; padding: 8px 10px; }

  /* queue + search take the full width on a phone */
  .queue-card { width: 100%; }
  .modal { width: 100%; max-height: 92vh; }
  .srch-input { font-size: 16px; }
  .srch-add { padding: 8px 10px; }
}

/* player mode toggles (shuffle / repeat) */
.pb-mode { opacity: .45; }
.pb-mode.active { opacity: 1; color: var(--accent); }
.pb-mode .sup { font-size: 9px; vertical-align: super; }

/* playlist "download all to desktop" link, styled as a button */
#dlAllLocal { display: inline-block; padding: 8px 14px; border-radius: 10px;
  background: var(--panel2); border: 1px solid var(--line); color: var(--text);
  font-size: 13px; text-decoration: none; }
#dlAllLocal:hover { border-color: var(--accent2); }

/* the page must never scroll sideways; wide rows scroll inside their own panes */
html, body { overflow-x: hidden; }


/* ── site nav drawer (phones) ──────────────────────────────────────────────
   The tab row cannot fit a phone, so below 820px it is replaced by a ☰ that
   opens a vertical drawer. Desktop keeps the inline row. */
.navtoggle { display: none; background: transparent; border: 1px solid var(--line);
  color: var(--text); border-radius: 8px; font-size: 15px; padding: 4px 9px; flex: none; }
.navtoggle:hover { border-color: var(--accent2); }
.navback { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 90;
  opacity: 0; pointer-events: none; transition: opacity .16s ease; }
.navback.open { opacity: 1; pointer-events: auto; }
.navdrawer { position: fixed; top: 0; left: 0; bottom: 0; width: 244px; max-width: 82vw;
  background: var(--panel); border-right: 1px solid var(--line); z-index: 91;
  transform: translateX(-100%); transition: transform .18s ease;
  padding: 12px 10px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.navdrawer.open { transform: none; }
.navdrawer-head { font-size: 13px; color: var(--dim); text-transform: uppercase;
  letter-spacing: .08em; padding: 4px 10px 10px; }
.navdrawer-link { display: block; color: var(--text); text-decoration: none;
  font-size: 15px; padding: 11px 12px; border-radius: 10px; border: 1px solid transparent; }
.navdrawer-link:hover { background: var(--panel2); }
.navdrawer-link.active { border-color: var(--accent2); background: var(--panel2); color: var(--accent); }

@media (max-width: 820px) {
  .topbar .nav { display: none; }
  .navtoggle { display: inline-flex; align-items: center; }
}


/* ------------------------------------------------------------ recommendations
   One panel serves "For you", a playlist radio and more-like-this; the rows are
   deliberately the same shape as a search result so the gestures carry over. */
.modal.rec { width: min(760px, 96vw); }
.rec-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.rec-basis { color: var(--dim); font-size: 12px; line-height: 1.5; }
.rec-basis b { color: var(--text); font-weight: 600; }
.rec-basis .tag {
  display: inline-block; margin: 3px 4px 0 0; padding: 2px 8px; border-radius: 999px;
  background: var(--panel2); border: 1px solid var(--line); font-size: 11px; color: var(--text);
}
.rec-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.rec-list { overflow: auto; display: flex; flex-direction: column; gap: 4px; max-height: 58vh; }
.rec-row {
  display: flex; align-items: center; gap: 10px; padding: 6px 8px;
  border-radius: 8px; border: 1px solid transparent;
}
.rec-row:hover { background: var(--panel2); border-color: var(--line); }
.rec-row .rthumb { width: 56px; height: 32px; object-fit: cover; border-radius: 4px; flex: none; background: var(--panel2); }
.rec-row .rmain { flex: 1; min-width: 0; }
.rec-row .rtitle { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rec-row .rsub { display: block; color: var(--dim); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rec-row .rbtn { flex: none; padding: 4px 8px; font-size: 12px; }
.rec-row .rscore { flex: none; color: var(--dim); font-size: 11px; width: 34px; text-align: right; }
.rec-empty { color: var(--dim); padding: 18px 4px; }
@media (max-width: 720px) {
  .rec-row .rscore, .rec-row .rthumb { display: none; }
  .rec-list { max-height: 62vh; }
}


/* ------------------------------------------------- Recommended (discovery)
   Sits under the playlist's own songs, Spotify's shape: music you do NOT own,
   each row addable. Deliberately quieter than a song row -- these are not in
   the library yet. */
.disco { margin: 26px 2px 40px; }
.disco-head { padding: 0 4px 10px; }
.disco-head h3 { margin: 0; font-size: 21px; }
.disco-sub { color: var(--dim); font-size: 12px; margin-top: 2px; }
.disco-list { display: flex; flex-direction: column; gap: 2px; }
.disco-row {
  display: flex; align-items: center; gap: 12px; padding: 6px 8px;
  border-radius: 8px; border: 1px solid transparent;
}
.disco-row:hover { background: var(--panel2); border-color: var(--line); }
.disco-row .dcover {
  width: 40px; height: 40px; flex: none; border-radius: 4px;
  object-fit: cover; background: var(--panel2);
}
.disco-row .dmain { flex: 1 1 40%; min-width: 0; display: flex; flex-direction: column; }
.disco-row .dtitle { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.disco-row .dartist { color: var(--dim); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.disco-row .dalbum {
  flex: 1 1 30%; min-width: 0; color: var(--dim); font-size: 12px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.disco-row .dadd {
  flex: none; padding: 5px 16px; border-radius: 999px; font-size: 12px;
  background: transparent; color: var(--text); border: 1px solid var(--line);
}
.disco-row .dadd:hover { border-color: var(--accent2); }
.disco-row .dadd.done { border-color: var(--accent2); color: var(--accent2); }
.disco-empty { color: var(--dim); padding: 14px 6px; }
.disco-foot { padding: 12px 6px 0; }
.disco-foot .dmore { background: transparent; border: 1px solid var(--line); color: var(--dim); }
@media (max-width: 720px) {
  .disco-row .dalbum { display: none; }
  .disco-head h3 { font-size: 18px; }
}
