/* registered color tokens can be transitioned: palette changes (cover colors, theme) ease in */
@property --accent { syntax: "<color>"; inherits: true; initial-value: #00a89b; }
@property --accent-text { syntax: "<color>"; inherits: true; initial-value: #ffffff; }
@property --bg { syntax: "<color>"; inherits: true; initial-value: #f5f6f8; }
@property --surface { syntax: "<color>"; inherits: true; initial-value: #ffffff; }
@property --surface-2 { syntax: "<color>"; inherits: true; initial-value: #eef0f3; }
@property --border { syntax: "<color>"; inherits: true; initial-value: #dde1e6; }
@property --muted { syntax: "<color>"; inherits: true; initial-value: #69717c; }

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --border: #dde1e6;
  --text: #15181c;
  --muted: #69717c;
  --accent: #00a89b;
  --accent-text: #ffffff;
  --danger: #d23c3c;
  --warn: #c98a00;
  --ok: #1f9d55;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  color-scheme: light;
}
/* theme: data-theme="light" | "dark" forces one, no attribute follows the system */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1013;
    --surface: #171a1f;
    --surface-2: #20242a;
    --border: #2b3038;
    --text: #e8eaed;
    --muted: #8b939e;
    --accent: #00d1c1;
    --accent-text: #0b0d10;
    --danger: #ff6b6b;
    --warn: #f2b84b;
    --ok: #4cd08a;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #0e1013;
    --surface: #171a1f;
    --surface-2: #20242a;
    --border: #2b3038;
    --text: #e8eaed;
    --muted: #8b939e;
    --accent: #00d1c1;
    --accent-text: #0b0d10;
    --danger: #ff6b6b;
    --warn: #f2b84b;
    --ok: #4cd08a;
    --shadow: none;
    color-scheme: dark;
}
/* smooth switch between themes (not on first paint: the class is added after load) */
.theme-anim, .theme-anim * { transition: background-color .3s, color .3s, border-color .3s !important; }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 22px 0 10px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }

button {
  font: inherit; cursor: pointer; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); padding: 8px 14px;
}
button:hover { border-color: var(--muted); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.ghost { background: transparent; }
button.danger { color: var(--danger); }
button.link { background: none; border: none; color: var(--accent); padding: 0; }
button.icon { padding: 6px 10px; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 9px; padding: 9px 12px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 50%, transparent); border-color: var(--accent); }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 20px; padding: 10px 24px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; }
.brand .muted { font-weight: 400; margin-left: 2px; }
.logo { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: var(--accent-text); }
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.tabs button { border: none; background: none; color: var(--muted); padding: 8px 12px; white-space: nowrap; }
.tabs button.active { color: var(--text); background: var(--surface-2); }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: var(--accent-text); font-size: 12px; font-weight: 700; text-align: center; }
.account { display: flex; align-items: center; gap: 8px; font-size: 13px; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--muted); }
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--danger); }

main { max-width: 1180px; margin: 0 auto; padding: 24px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }

/* Login */
.login { margin-bottom: 24px; }
.code-box { font: 700 28px/1 ui-monospace, monospace; letter-spacing: .15em; padding: 14px 18px; background: var(--surface-2); border-radius: 10px; display: inline-block; margin: 8px 0; }

/* Search */
.searchbar { display: flex; gap: 10px; }
.searchbar input { font-size: 17px; padding: 12px 16px; }
.quick { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; margin: 10px 2px 8px; font-size: 13px; }
.results-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; display: flex; flex-direction: column; gap: 8px; box-shadow: var(--shadow); }
.tile .cover { aspect-ratio: 1; width: 100%; border-radius: 8px; background: var(--surface-2) center/cover no-repeat; display: grid; place-items: center; color: var(--muted); font-size: 28px; }
.tile.artist .cover { border-radius: 50%; }
.tile .t-title { font-weight: 600; line-height: 1.25; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.tile .t-sub { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tracklist { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.trow:first-child { border-top: none; }
.trow img, .trow .ph { width: 44px; height: 44px; border-radius: 6px; object-fit: cover; background: var(--surface-2); }
.trow .tt { min-width: 0; }
.trow .tt div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trow .tt .t-sub { color: var(--muted); font-size: 13px; }
.chip { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 5px; background: var(--surface-2); color: var(--muted); margin-left: 6px; vertical-align: 1px; }
.chip.hires { color: var(--warn); }
.chip.e { color: var(--text); }

/* Jobs */
.jobs { display: flex; flex-direction: column; gap: 12px; }
.job { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.job-head { display: flex; gap: 12px; align-items: center; }
.job-title { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); text-transform: uppercase; letter-spacing: .03em; }
.status.running { color: var(--accent); }
.status.done { color: var(--ok); }
.status.failed { color: var(--danger); }
.status.cancelled, .status.queued { color: var(--muted); }
.job-meta { font-size: 13px; color: var(--muted); margin-top: 6px; display: flex; gap: 14px; flex-wrap: wrap; }
.job-last { font: 12px ui-monospace, monospace; color: var(--muted); margin-top: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log { margin-top: 10px; max-height: 360px; overflow: auto; background: var(--surface-2); border-radius: 8px; padding: 10px 12px; font: 12px/1.5 ui-monospace, monospace; white-space: pre-wrap; word-break: break-all; }
.spinner { width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Files */
.breadcrumbs { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; font-size: 15px; }
.breadcrumbs button { border: none; background: none; padding: 4px 6px; color: var(--accent); }
.breadcrumbs span { color: var(--muted); }
.files { margin-top: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.frow { display: grid; grid-template-columns: 28px 1fr auto auto; gap: 12px; align-items: center; padding: 9px 14px; border-top: 1px solid var(--border); }
.frow:first-child { border-top: none; }
.frow .fname { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.frow .fname button { border: none; background: none; padding: 0; color: var(--text); text-align: left; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.frow .fname button:hover { color: var(--accent); }
.frow .size { color: var(--muted); font-size: 13px; }
.frow .ops { display: flex; gap: 4px; }
.frow .ops button { padding: 4px 9px; font-size: 13px; }
.empty { padding: 40px; text-align: center; color: var(--muted); }
.player { margin-top: 14px; display: flex; gap: 14px; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; }
.player-title { flex: 1; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player audio { width: 50%; min-width: 240px; }

/* Settings */
.grid2 { display: grid; grid-template-columns: 1fr 1.3fr; gap: 20px; align-items: start; }
.form { display: grid; gap: 12px; }
.form label { display: grid; gap: 5px; font-size: 13px; color: var(--muted); }
.form .check { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 14px; }
.form .check input { width: auto; }
textarea#config-text { min-height: 420px; font: 13px/1.5 ui-monospace, monospace; resize: vertical; margin-bottom: 12px; }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.45); display: grid; place-items: center; padding: 16px; }
.modal-box { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 22px; width: min(560px, 100%); max-height: 90vh; overflow: auto; }
.modal-close { position: absolute; right: 10px; top: 8px; border: none; background: none; font-size: 24px; color: var(--muted); }
.modal textarea { min-height: 160px; font: 13px ui-monospace, monospace; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* Toasts */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; font-size: 14px; max-width: 360px; box-shadow: 0 6px 20px rgba(0,0,0,.2); animation: pop .2s ease-out; }
.toast.error { background: var(--danger); color: #fff; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; padding: 10px 16px; gap: 10px; }
  .tabs { order: 3; flex-basis: 100%; }
  main { padding: 16px; }
  .grid2 { grid-template-columns: 1fr; }
  .results-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .trow .dur { display: none; }
  .frow { grid-template-columns: 24px 1fr auto; }
  .frow .size { display: none; }
  .player { flex-direction: column; align-items: stretch; }
  .player audio { width: 100%; }
}

/* Favorites */
.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pills button { border-radius: 999px; padding: 6px 14px; }
.pills button.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.pills .cnt { opacity: .6; margin-left: 4px; font-size: 13px; }
.fav-toolbar { display: flex; gap: 10px; align-items: center; margin: 14px 0 10px; flex-wrap: wrap; }
.fav-toolbar input[type=search] { flex: 1; min-width: 200px; }
.fav-toolbar select { width: auto; }
.check { display: inline-flex; gap: 8px; align-items: center; font-size: 14px; white-space: nowrap; cursor: pointer; }
.check input { width: auto; margin: 0; }
.selbar {
  position: sticky; top: 58px; z-index: 5; display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 12px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.grow { flex: 1; }
.tile { position: relative; }
.tile.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.trow.selected { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.chip.lib { color: var(--ok); }
@media (max-width: 760px) {
  .selbar { top: 104px; }
}
.heart { color: var(--muted); }
.heart.on { color: #e5484d; border-color: color-mix(in srgb, #e5484d 40%, var(--border)); }

/* Tiles: download + options below, heart / badges over the cover */
.cover-wrap { position: relative; }
.tile .cover { display: grid; text-decoration: none; }
.clickable { cursor: pointer; }
.tile .cover.clickable:hover { filter: brightness(1.06); }
.t-title .clickable:hover, .sublink:hover { text-decoration: underline; }
.sublink { color: inherit; text-decoration: none; }
.tile .actions { margin-top: auto; display: flex; gap: 6px; }
.tile .actions button { padding: 6px 8px; font-size: 13px; }
.tile .actions .primary { flex: 1; min-width: 0; }
.tile .actions .icon { flex: none; width: 34px; padding: 6px 0; }
.tile .sel { position: absolute; top: 8px; left: 8px; width: 20px; height: 20px; accent-color: var(--accent); cursor: pointer; }
.lib-badge { position: absolute; top: 8px; right: 8px; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; background: var(--ok); color: #fff; pointer-events: none; }
.cover-wrap .heart {
  position: absolute; right: 8px; bottom: 8px; width: 32px; height: 32px; padding: 0; border-radius: 50%;
  background: color-mix(in srgb, var(--surface) 85%, transparent); backdrop-filter: blur(4px); font-size: 16px; line-height: 1;
  opacity: 0; transition: opacity .15s;
}
.tile:hover .cover-wrap .heart, .cover-wrap .heart.on, .cover-wrap .heart:focus-visible { opacity: 1; }
@media (hover: none) { .cover-wrap .heart { opacity: 1; } }

/* Track rows */
.trow { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto auto; gap: 12px; align-items: center; padding: 8px 12px; border-top: 1px solid var(--border); }
.trow.sel-row { grid-template-columns: 20px 44px minmax(0, 1fr) auto auto; }
.trow.sel-row input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.trow .num { width: 44px; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }
.album-tracks .trow { grid-template-columns: 32px minmax(0, 1fr) auto auto; }
.album-tracks .trow .num { width: 32px; }
.row-actions { display: flex; gap: 6px; align-items: center; }
.row-actions button { width: 34px; height: 32px; padding: 0; }
.disc { padding: 10px 14px 6px; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; border-top: 1px solid var(--border); }
.disc:first-child { border-top: none; }

/* Link styled as a button */
a.btn { display: inline-grid; place-items: center; text-decoration: none; color: var(--text); border: 1px solid var(--border); background: var(--surface); border-radius: 9px; min-width: 38px; height: 38px; padding: 0 10px; }
a.btn:hover { border-color: var(--muted); }

/* Artist / album page */
.back { margin-bottom: 16px; padding: 6px 12px; }
.detail-head { display: flex; gap: 28px; align-items: flex-end; margin-bottom: 8px; }
.detail-cover { flex: none; width: 220px; height: 220px; border-radius: 12px; background: var(--surface-2) center/cover no-repeat; box-shadow: 0 8px 30px rgba(0,0,0,.18); }
.detail-cover.artist { border-radius: 50%; }
.detail-info { min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.kicker { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.detail-info h1 { margin: 0; font-size: clamp(26px, 4vw, 44px); line-height: 1.1; overflow-wrap: anywhere; }
.detail-info h1 .chip { vertical-align: middle; font-size: 12px; }
.detail-artists { font-weight: 600; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
.detail-actions button { height: 38px; }
.detail-actions .icon, .detail-actions .heart { width: 38px; padding: 0; }
.ok { color: var(--ok); }

@media (max-width: 760px) {
  .trow { grid-template-columns: 40px minmax(0, 1fr) auto; }
  .trow.sel-row { grid-template-columns: 20px 40px minmax(0, 1fr) auto; }
  .album-tracks .trow { grid-template-columns: 26px minmax(0, 1fr) auto; }
  .row-actions [data-opts] { display: none; }
  .detail-head { flex-direction: column; align-items: flex-start; gap: 16px; }
  .detail-cover { width: 160px; height: 160px; }
  .detail-actions .primary { flex: 1 0 100%; }
  .fav-toolbar select { flex: 1; }
}

/* Search entity toggles */
.search-types { margin-top: 12px; }
.search-types button { padding: 5px 12px; font-size: 14px; }
.search-types button.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.search-types button.all.on { background: var(--text); color: var(--bg); border-color: var(--text); }

/* ------------------------------------------------------------------ player */
:root { --pb-h: 76px; }
body.has-player main { padding-bottom: calc(var(--pb-h) + 32px + env(safe-area-inset-bottom)); }
body.has-player .toasts { bottom: calc(var(--pb-h) + 16px + env(safe-area-inset-bottom)); }
.topbar { padding-top: max(10px, env(safe-area-inset-top)); }

.player-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: minmax(180px, 1.2fr) auto minmax(200px, 2fr) auto; gap: 18px; align-items: center;
  height: calc(var(--pb-h) + env(safe-area-inset-bottom)); padding: 0 20px env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
}
.pb-progress { position: absolute; left: 0; right: 0; top: -1px; height: 3px; background: transparent; cursor: pointer; display: none; }
.pb-progress div { height: 100%; width: 0; background: var(--accent); }
.pb-now { display: flex; align-items: center; gap: 12px; min-width: 0; border: none; background: none; padding: 0; text-align: left; }
.pb-cover { flex: none; width: 52px; height: 52px; border-radius: 8px; background: var(--surface-2) center/cover no-repeat; box-shadow: 0 2px 8px rgba(0,0,0,.15); }
.pb-text { display: flex; flex-direction: column; min-width: 0; }
.pb-title, .pb-artist { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pb-title { font-weight: 600; }
.pb-artist { font-size: 13px; color: var(--muted); }
.pb-controls { display: flex; align-items: center; gap: 6px; }
.pb-btn { border: none; background: none; width: 40px; height: 40px; padding: 0; border-radius: 50%; font-size: 18px; color: var(--text); }
.pb-btn:hover { background: var(--surface-2); }
.pb-play { width: 46px; height: 46px; background: var(--text); color: var(--bg); font-size: 18px; }
.pb-play:hover { background: var(--text); filter: brightness(1.15); }
.pb-btn.on { color: var(--accent); }
.pb-seek { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.pb-extra { display: flex; align-items: center; gap: 10px; }
.pb-extra .heart { width: 34px; height: 34px; padding: 0; }
.pb-source { font-size: 11px; font-weight: 700; color: var(--muted); white-space: nowrap; }
#pb-volume { width: 90px; }
input[type=range] { -webkit-appearance: none; appearance: none; background: transparent; padding: 0; border: none; width: 100%; height: 20px; cursor: pointer; }
input[type=range]:focus { outline: none; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: var(--border); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--border); }
input[type=range]::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--accent); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; margin-top: -5px; border-radius: 50%; background: var(--accent); border: none; }
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); border: none; }

/* play affordances in lists */
.lead { position: relative; border: none; padding: 0; background: none; width: 44px; height: 44px; border-radius: 6px; display: grid; place-items: center; }
.lead img, .lead .ph { display: block; }
.lead .num { width: 100%; }
.album-tracks .lead { width: 32px; }
.lead-play { position: absolute; inset: 0; display: grid; place-items: center; border-radius: 6px; background: rgba(0,0,0,.45); color: #fff; font-size: 14px; opacity: 0; transition: opacity .12s; }
.lead.numbered .lead-play { background: var(--surface-2); color: var(--accent); }
.trow:hover .lead-play, .lead:focus-visible .lead-play { opacity: 1; }
.trow.playing { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.trow.playing .tt-title { color: var(--accent); font-weight: 600; }
.trow.playing .lead-play { opacity: 1; }
.tile-play {
  position: absolute; left: 8px; bottom: 8px; width: 38px; height: 38px; padding: 0; border-radius: 50%; border: none;
  background: var(--accent); color: var(--accent-text); font-size: 15px; box-shadow: 0 4px 12px rgba(0,0,0,.25);
  opacity: 0; transform: translateY(4px); transition: opacity .15s, transform .15s;
}
.tile:hover .tile-play, .tile-play:focus-visible { opacity: 1; transform: none; }
@media (hover: none) { .tile-play { opacity: 1; transform: none; width: 34px; height: 34px; } }

/* now playing */
.now-playing { position: fixed; inset: 0; z-index: 40; background: var(--bg); overflow-y: auto; overscroll-behavior: contain; animation: np-in .2s ease-out; }
@keyframes np-in { from { transform: translateY(24px); opacity: 0; } }
body.np-open { overflow: hidden; }
.np-inner { max-width: 1100px; margin: 0 auto; padding: max(16px, env(safe-area-inset-top)) 24px calc(24px + env(safe-area-inset-bottom)); }
.np-top { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.np-top .kicker { flex: 1; text-align: center; }
#np-close { font-size: 22px; width: 42px; height: 42px; padding: 0; }
.np-source { font-size: 12px; font-weight: 700; color: var(--muted); min-width: 42px; text-align: right; }
.np-main { display: grid; grid-template-columns: minmax(260px, 440px) 1fr; gap: 40px; align-items: start; }
.np-cover { width: 100%; aspect-ratio: 1; border-radius: 14px; background: var(--surface-2) center/cover no-repeat; box-shadow: 0 16px 50px rgba(0,0,0,.3); position: sticky; top: 16px; }
.np-panel { min-width: 0; }
.np-title { font-size: clamp(22px, 3vw, 32px); font-weight: 700; line-height: 1.2; overflow-wrap: anywhere; }
.np-artist { font-size: 17px; margin-top: 4px; }
.np-album { color: var(--muted); margin-top: 2px; }
.np-seek { margin-top: 18px; font-variant-numeric: tabular-nums; }
.np-controls { display: flex; justify-content: center; align-items: center; gap: 14px; margin: 8px 0 10px; }
.np-controls .pb-btn { width: 48px; height: 48px; font-size: 22px; }
.np-controls .np-play { width: 64px; height: 64px; font-size: 24px; }
.np-controls .np-small { font-size: 18px; opacity: .55; }
.np-controls .np-small.on { opacity: 1; background: color-mix(in srgb, var(--accent) 15%, transparent); }
.np-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-bottom: 8px; }
.np-actions .heart { width: 38px; height: 38px; padding: 0; }
.np-queue-head { margin-top: 18px; }
.np-queue-head h3 { margin: 0; }
.np-queue { margin-top: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.np-q { display: grid; grid-template-columns: 30px minmax(0, 1fr) auto auto; gap: 10px; align-items: center; padding: 7px 10px; border-top: 1px solid var(--border); cursor: pointer; }
.np-q:first-child { border-top: none; }
.np-q:hover { background: var(--surface-2); }
.np-q.current { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.np-q.current .np-q-title { color: var(--accent); font-weight: 600; }
.np-q-num { text-align: center; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.np-q-text { display: flex; flex-direction: column; min-width: 0; }
.np-q-title, .np-q-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.np-q-sub { font-size: 12px; color: var(--muted); }
.np-q button { padding: 2px 8px; }

/* login page */
.login-body { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); display: grid; gap: 14px; }
.login-card .brand { justify-content: center; margin-bottom: 6px; }
.login-card label { display: grid; gap: 5px; font-size: 13px; color: var(--muted); }
.login-card button { padding: 11px; }
.login-error { color: var(--danger); min-height: 1em; margin: 0; font-size: 14px; }

@media (max-width: 760px) {
  :root { --pb-h: 64px; }
  .hide-mobile { display: none !important; }
  .player-bar { grid-template-columns: minmax(0, 1fr) auto; gap: 8px; padding: 0 10px env(safe-area-inset-bottom); }
  .pb-progress { display: block; }
  .pb-cover { width: 44px; height: 44px; }
  .pb-play { width: 42px; height: 42px; }
  .np-inner { padding-left: 18px; padding-right: 18px; }
  .np-main { grid-template-columns: 1fr; gap: 20px; }
  .np-cover { position: static; width: min(100%, 360px); margin: 0 auto; }
  .np-meta { text-align: center; }
}

.ico { width: 22px; height: 22px; display: block; margin: auto; }
.pb-play .ico { width: 20px; height: 20px; }
.np-controls .ico { width: 26px; height: 26px; }
.np-controls .np-play .ico { width: 28px; height: 28px; }
.np-controls .np-small .ico { width: 21px; height: 21px; }
#np-close .ico { width: 24px; height: 24px; }
.pb-btn { display: grid; place-items: center; }
.ico-sm { width: 18px; height: 18px; }

/* track menu (⋯) */
.menu-btn { font-size: 18px; line-height: 1; letter-spacing: 1px; }
.ctx-menu {
  position: fixed; z-index: 45; min-width: 220px; max-width: min(320px, calc(100vw - 16px)); padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 12px 36px rgba(0,0,0,.22);
  display: flex; flex-direction: column; animation: pop .12s ease-out;
}
.ctx-menu button { border: none; background: none; text-align: left; padding: 9px 12px; border-radius: 8px; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ctx-menu button:hover, .ctx-menu button:focus-visible { background: var(--surface-2); outline: none; }
.ctx-menu button.danger { color: var(--danger); }
.ctx-sep { height: 1px; background: var(--border); margin: 4px 6px; }

/* playlist picker */
#pl-pick { display: flex; flex-direction: column; gap: 4px; max-height: 60vh; overflow-y: auto; margin-top: 8px; }
.pl-pick-row { display: flex; align-items: center; gap: 12px; border: none; background: none; text-align: left; padding: 6px; border-radius: 10px; }
.pl-pick-row:hover { background: var(--surface-2); }
.pl-pick-cover { flex: none; width: 44px; height: 44px; border-radius: 6px; background: var(--surface-2) center/cover no-repeat; display: grid; place-items: center; color: var(--muted); font-size: 20px; }
.pl-pick-row.new .pl-pick-cover { color: var(--accent); font-size: 24px; }
.pl-pick-text { display: flex; flex-direction: column; min-width: 0; }
.pl-pick-text b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.detail-desc { color: var(--muted); max-width: 70ch; white-space: pre-line; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.modal textarea[name=description] { min-height: 80px; font: inherit; }
.toasts { pointer-events: none; }
@media (max-width: 760px) {
  /* narrow rows: keep the title readable, the ellipsis must not look like the ⋯ button */
  .trow .tt-title .chip:not(.lib):not(.e) { display: none; }
  .trow .tt-title .lib-word { display: none; }
  .row-actions { gap: 4px; }
  .row-actions button { width: 32px; }
}

/* now playing: tabs + lyrics */
.np-tabs { display: flex; align-items: center; gap: 6px; margin-top: 18px; border-bottom: 1px solid var(--border); }
.np-tabs [data-np-tab] { border: none; background: none; border-radius: 0; padding: 8px 4px; margin-right: 12px; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.np-tabs [data-np-tab].on { color: var(--text); border-bottom-color: var(--accent); }
.np-tabs .ghost { margin-bottom: 4px; }
.np-queue { margin-top: 10px; }
.np-lyrics {
  margin-top: 6px; height: min(56vh, 560px); overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin;
  padding: 24px 4px 40px;
  -webkit-mask-image: linear-gradient(transparent, #000 8%, #000 88%, transparent);
  mask-image: linear-gradient(transparent, #000 8%, #000 88%, transparent);
}
.ly-lines { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }
.ly-line {
  border: none; background: none; text-align: start; padding: 6px 8px; border-radius: 8px; width: 100%;
  font-size: clamp(18px, 2.2vw, 24px); font-weight: 700; line-height: 1.3; color: var(--muted); opacity: .55;
  transition: color .25s, opacity .25s, transform .25s; transform-origin: left center;
}
[dir=rtl] .ly-line { transform-origin: right center; }
@media (hover: hover) { .ly-line:hover { opacity: .9; background: var(--surface-2); } } /* no sticky hover after a tap */
.ly-line.now { color: var(--text); opacity: 1; transform: scale(1.03); }
.ly-line.gap { font-size: 18px; }
.ly-plain { white-space: pre-line; font-size: 18px; line-height: 1.6; padding: 0 8px; }
.ly-empty { text-align: center; padding-top: 40px; }
.ly-source { margin-top: 24px; padding: 0 8px; font-size: 12px; color: var(--muted); }
.pb-lyrics { width: 34px; height: 34px; opacity: .55; }
.pb-lyrics.on { opacity: 1; color: var(--accent); }
@media (max-width: 760px) {
  .np-lyrics { height: 60vh; }
  .ly-line { font-size: 20px; }
}
.np-lyrics { position: relative; } /* offsetParent for line positions */

/* home */
.home-head h1 { margin: 0; font-size: clamp(24px, 3vw, 32px); }
.home-section { margin-top: 26px; }
.home-section h3 { margin-top: 0; }
.shelf {
  display: grid; grid-auto-flow: column; grid-auto-columns: 172px; gap: 16px;
  overflow-x: auto; overscroll-behavior-x: contain; scroll-snap-type: x proximity; scrollbar-width: thin;
  padding: 2px 2px 10px; margin: 0 -2px;
}
.shelf .tile { scroll-snap-align: start; }
.shortcuts { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.shortcut {
  display: flex; align-items: center; gap: 12px; min-width: 0; cursor: pointer; padding-right: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; box-shadow: var(--shadow);
}
.shortcut:hover { border-color: var(--muted); }
.shortcut-cover { flex: none; width: 60px; height: 60px; background: var(--surface-2) center/cover no-repeat; }
.shortcut-cover.artist { border-radius: 50%; width: 48px; height: 48px; margin-left: 6px; }
.shortcut-text { display: flex; flex-direction: column; min-width: 0; }
.shortcut-text b, .shortcut-text span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shortcut-text span { font-size: 12px; color: var(--muted); }
@media (max-width: 760px) {
  .shelf { grid-auto-columns: 142px; gap: 12px; }
  .shortcuts { grid-template-columns: 1fr 1fr; gap: 8px; }
  .shortcut-cover { width: 52px; height: 52px; }
  .shortcut-cover.artist { width: 40px; height: 40px; }
  .shortcut-text b { font-size: 13px; }
}

/* compact player bar: lyrics button only on phones; mini header only in full-screen lyrics */
.pb-lyrics-m, .np-mini { display: none; }

@media (max-width: 760px) {
  .pb-lyrics-m { display: grid; width: 38px; height: 38px; }
}

/* phones, also in landscape (low screens) */
@media (max-width: 760px), (max-height: 500px) {
  /* full-screen lyrics: header, lines filling the screen, seek + controls at the bottom */
  .now-playing.lyrics-mode { overflow: hidden; }
  .now-playing.lyrics-mode .np-inner {
    height: 100vh; height: 100dvh; display: flex; flex-direction: column;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }
  .now-playing.lyrics-mode .np-top { margin-bottom: 4px; }
  .now-playing.lyrics-mode .np-top .kicker,
  .now-playing.lyrics-mode .np-top .np-source,
  .now-playing.lyrics-mode .np-cover,
  .now-playing.lyrics-mode .np-meta,
  .now-playing.lyrics-mode .np-actions,
  .now-playing.lyrics-mode .np-tabs,
  .now-playing.lyrics-mode .np-queue { display: none !important; }
  .now-playing.lyrics-mode .np-mini { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
  .np-mini-cover { flex: none; width: 40px; height: 40px; border-radius: 6px; background: var(--surface-2) center/cover no-repeat; }
  .np-mini-text { display: flex; flex-direction: column; min-width: 0; }
  .np-mini-text b, .np-mini-text span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .np-mini-text span { font-size: 13px; color: var(--muted); }
  .now-playing.lyrics-mode .np-main { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 0; }
  .now-playing.lyrics-mode .np-panel { flex: 1; min-height: 0; width: 100%; display: flex; flex-direction: column; }
  .now-playing.lyrics-mode .np-main { width: 100%; }
  .now-playing.lyrics-mode .np-lyrics {
    order: 1; flex: 1; min-height: 0; height: auto; margin-top: 0; padding: 22vh 2px 26vh;
  }
  .now-playing.lyrics-mode .ly-line { font-size: 24px; }
  .now-playing.lyrics-mode .ly-plain { font-size: 20px; }
  .now-playing.lyrics-mode .ly-empty { padding-top: 0; }
  .now-playing.lyrics-mode .np-seek { order: 2; margin-top: 6px; }
  .now-playing.lyrics-mode .np-controls { order: 3; margin: 2px 0 0; }
}

/* landscape phones: little height, keep the controls on screen */
@media (max-height: 500px) {
  .now-playing.lyrics-mode .np-inner { padding-top: 8px; }
  .now-playing.lyrics-mode .np-lyrics { padding: 14vh 2px 18vh; }
  .now-playing.lyrics-mode .ly-line { font-size: 20px; padding: 4px 8px; }
  .now-playing.lyrics-mode .np-seek { margin-top: 0; }
  .now-playing.lyrics-mode .np-controls .pb-btn { width: 40px; height: 40px; }
  .now-playing.lyrics-mode .np-controls .np-play { width: 48px; height: 48px; }
}

/* lyrics toggle next to the controls: phones only */
.np-lyr-btn { display: none !important; }
@media (max-width: 760px), (max-height: 500px) {
  .np-lyr-btn { display: grid !important; }
  .np-lyr-btn.on { opacity: 1; color: var(--accent); background: color-mix(in srgb, var(--accent) 15%, transparent); }
  .np-controls { gap: 10px; }
  .np-mini { cursor: pointer; }
  .np-top { touch-action: pan-x; }

  /* entering full-screen lyrics: lines slide up, header and controls fade in */
  .now-playing.lyrics-mode .np-lyrics { animation: ly-in .68s cubic-bezier(.2, .8, .2, 1); }
  .now-playing.lyrics-mode .np-mini,
  .now-playing.lyrics-mode .np-seek,
  .now-playing.lyrics-mode .np-controls { animation: ly-fade .6s ease-out; }
  /* leaving: lines slide down, then the player view eases back */
  .now-playing.ly-leaving .np-lyrics { animation: ly-out .36s ease-in forwards; }
  .now-playing.ly-leaving .np-mini { animation: ly-fade-out .36s ease-in forwards; }
  .now-playing.ly-returning .np-cover { animation: ly-cover .32s cubic-bezier(.2, .8, .2, 1); }
  .now-playing.ly-returning .np-meta,
  .now-playing.ly-returning .np-actions,
  .now-playing.ly-returning .np-tabs,
  .now-playing.ly-returning .np-queue { animation: ly-fade .3s ease-out; }
}
@keyframes ly-in { from { opacity: 0; transform: translateY(40px); } }
@keyframes ly-out { to { opacity: 0; transform: translateY(40px); } }
@keyframes ly-fade { from { opacity: 0; } }
@keyframes ly-fade-out { to { opacity: 0; } }
@keyframes ly-cover { from { opacity: 0; transform: scale(.92); } }
@media (prefers-reduced-motion: reduce) {
  .now-playing, .now-playing * { animation: none !important; transition: none !important; }
}

/* no pull-to-refresh: pulling down at the top must not reload the app */
html, body { overscroll-behavior-y: none; }

/* wavy progress (canvas under a transparent range input) */
.wave-seek { position: relative; height: 28px; flex: 1; min-width: 0; }
.wave-seek canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.wave-seek input[type=range] { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.wave-seek:has(input:focus-visible) { outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; border-radius: 8px; }
.np-seek .wave-seek { height: 34px; }
.pb-seek .wave-seek { height: 24px; }

/* segmented control (theme switch) */
.segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border-radius: 11px; max-width: 100%; }
.segmented button { border: none; background: none; padding: 7px 14px; border-radius: 8px; font-size: 14px; color: var(--muted); white-space: nowrap; }
.segmented button.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
@media (max-width: 420px) { .segmented { display: flex; } .segmented button { flex: 1; padding: 7px 6px; font-size: 13px; } }
/* grid columns must not grow to the widest child (settings overflowed on phones) */
.grid2 > * { min-width: 0; }
.segmented button { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.form label, .form select, .form input { min-width: 0; max-width: 100%; }

/* colors from the cover: smooth hand-over between tracks (and themes), a soft glow behind the player */
:root {
  transition: --accent .8s ease, --accent-text .8s ease, --bg .8s ease, --surface .8s ease,
    --surface-2 .8s ease, --border .8s ease, --muted .8s ease;
}
:root.dyn .now-playing {
  background:
    radial-gradient(120% 70% at 50% -10%, color-mix(in srgb, var(--accent) 26%, transparent), transparent 70%),
    var(--bg);
}
.dyn-check { margin-top: 12px; }
@media (prefers-reduced-motion: reduce) { :root { transition: none !important; } }
.dev-btn { display: inline-flex; align-items: center; gap: 6px; }
.dev-btn .ico { margin: 0; }

/* download chooser (in #ctx-menu) */
.ctx-title { padding: 6px 12px 4px; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 280px; }
.ctx-menu button { display: flex; align-items: center; gap: 10px; }
.ctx-menu button .ico { flex: none; margin: 0; }
.ctx-menu button span { display: flex; flex-direction: column; min-width: 0; }
.ctx-menu button small { font-size: 11px; color: var(--muted); }
.ctx-menu button[disabled] { opacity: .5; cursor: default; }
.ctx-menu button[disabled]:hover { background: none; }

/* ---- layout fixes (audit at 360–1280 px) ---- */
/* button labels never break into two lines; long ones are cut where needed */
button, a.btn { white-space: nowrap; }
/* ...but form labels next to checkboxes do wrap (they overflowed the settings card) */
.form .check { white-space: normal; align-items: flex-start; }
.form .check input { margin-top: 3px; }
/* the jobs header row may wrap as a whole instead of squeezing the button */
#tab-jobs > .row { flex-wrap: wrap; row-gap: 8px; }

@media (max-width: 760px) {
  /* jobs: title on its own line, status + buttons below it */
  .job-head { flex-wrap: wrap; row-gap: 8px; }
  .job-head .job-title { order: -1; flex: 1 1 100%; white-space: normal; overflow-wrap: anywhere;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .job-head .status { margin-right: auto; }
}

/* player controls: always one row, shrinking on narrow phones */
.np-controls { flex-wrap: nowrap; }
@media (max-width: 420px) {
  .np-controls { gap: 4px; justify-content: space-between; }
  .np-controls .pb-btn { width: 44px; height: 44px; flex-shrink: 1; min-width: 36px; }
  .np-controls .np-play { width: 60px; height: 60px; flex-shrink: 0; }
}

/* playback on another device */
.remote-bar {
  position: fixed; left: 0; right: 0; z-index: 29; bottom: env(safe-area-inset-bottom);
  display: flex; align-items: center; gap: 12px; padding: 8px 16px;
  background: color-mix(in srgb, var(--accent) 16%, var(--surface)); border-top: 1px solid var(--border);
  animation: ly-fade .3s ease-out;
}
body.has-player .remote-bar { bottom: calc(var(--pb-h) + env(safe-area-inset-bottom)); }
body.has-remote main { padding-bottom: calc(var(--pb-h) + 96px + env(safe-area-inset-bottom)); }
.remote-icon { font-size: 20px; flex: none; }
.remote-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.remote-where { font-size: 12px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .03em; }
.remote-track { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.remote-take { flex: none; padding: 7px 12px; font-size: 14px; }
.np-remote { display: flex; align-items: center; gap: 10px; padding: 10px 12px; margin-bottom: 14px; border-radius: 12px;
  background: color-mix(in srgb, var(--accent) 14%, var(--surface)); }
.device-list { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.device { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; }
.device.me { border-color: var(--accent); }
@media (max-width: 420px) {
  .remote-bar { padding: 8px 10px; gap: 8px; }
  .remote-take { padding: 7px 10px; font-size: 13px; }
}
.remote-where { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
