:root {
  --bg: #14141a;
  --panel: #1d1d26;
  --panel-2: #262633;
  --text: #ececf3;
  --muted: #9a9ab0;
  --accent: #ff4d6d;
  --tap: 44px;
  --tabs-h: 52px;
  --player-h: 0px; /* set from the real player height by app.js */
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; color: var(--text); }
/* Plain colour on both elements, declared directly (no var(), no shorthand): iOS reads the <body> background-color
   for the browser's top bar. Keep it equal to --bg. */
html, body { background-color: #14141a !important; }
/* iOS 26 Safari ignores theme-color and tints its top bar from the page background and from fixed elements at the top edge:
   a thin fixed strip in the page colour keeps that bar dark. */
body::before { content: ''; position: fixed; top: 0; left: 0; right: 0; height: 2px; background: var(--bg); z-index: 50; pointer-events: none; }
body { font: 16px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; min-width: var(--tap); min-height: var(--tap); border-radius: 10px; }
button:active { background: var(--panel-2); }
[hidden] { display: none !important; }

.top { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 10px 12px 6px; padding-top: max(10px, env(safe-area-inset-top)); }
#search-form { display: flex; align-items: center; gap: 6px; }
#search-form > button:not(.avatar) { font-size: 22px; color: var(--muted); }
#q { flex: 1; min-width: 0; min-height: var(--tap); padding: 0 14px; border-radius: 22px; border: 1px solid var(--panel-2); background: var(--panel); }
/* Two equal columns; select and input share one look. iOS draws its own select (narrow, with up/down arrows) unless
   appearance is reset, and zooms the page for text under 16px. */
.filters { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; padding-top: 8px; }
.filters label { min-width: 0; font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.filters select, .filters input, .a-sort select {
  -webkit-appearance: none; appearance: none; box-sizing: border-box; margin: 0; width: 100%; min-width: 0; height: 40px; min-height: 40px;
  padding: 0 10px; font-size: 16px; line-height: 1.2; color: var(--text); background-color: var(--panel); border: 1px solid var(--panel-2); border-radius: 8px;
}
.filters select, .a-sort select {
  padding-right: 32px; text-overflow: ellipsis;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 256 256' fill='%239a9ab0'%3E%3Cpath d='M213.66 101.66l-80 80a8 8 0 0 1-11.32 0l-80-80a8 8 0 0 1 11.32-11.32L128 164.69l74.34-74.35a8 8 0 0 1 11.32 11.32Z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 14px;
}
.filters input::placeholder { color: var(--muted); opacity: 1; }

main { padding: 4px 12px calc(var(--tabs-h) + var(--safe-b) + 16px); max-width: 760px; margin: 0 auto; }
body.has-player main { padding-bottom: calc(var(--tabs-h) + var(--player-h) + var(--safe-b) + 16px); }

h2 { font-size: 18px; margin: 14px 0 8px; display: flex; align-items: center; gap: 8px; }
h2 .spacer { flex: 1; }
.muted { color: var(--muted); font-size: 14px; }
.empty { color: var(--muted); text-align: center; padding: 32px 8px; }
.error { color: #ff8a8a; padding: 16px 4px; }
.loading { color: var(--muted); padding: 16px 4px; text-align: center; }

.list { list-style: none; margin: 0; padding: 0; }
.track { display: flex; align-items: center; gap: 0; border-bottom: 1px solid var(--panel); }
.t-cover { position: relative; flex: none; width: 52px; height: 52px; border-radius: 8px; overflow: hidden; background: var(--panel-2); display: grid; place-items: center; color: var(--muted); font-size: 24px; }
.t-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.t-cover.failed .t-img { display: none; }
.track.playing .t-cover { box-shadow: 0 0 0 2px var(--accent); }
.player img.failed { visibility: hidden; }
.track.playing .t-title { color: var(--accent); }
.t-main { flex: 1; min-width: 0; text-align: left; padding: 8px 6px 8px 0; min-height: 56px; display: flex; align-items: center; gap: 12px; }
.t-text { flex: 1; min-width: 0; display: block; }
.t-title { font-size: 14.5px; line-height: 1.3; font-weight: 600; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.t-pr { color: var(--accent); font-weight: 600; margin-right: 8px; white-space: nowrap; }
.t-pr i { font-size: 12px; vertical-align: -1px; margin-right: 2px; }
.t-pr small { font-size: 10px; font-weight: 600; opacity: .75; margin-left: 3px; letter-spacing: .03em; }
.t-meta { display: block; font-size: 13px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.t-act { flex: none; min-width: 36px; font-size: 22px; display: grid; place-items: center; text-decoration: none; color: var(--muted); }
.t-act.on { color: var(--accent); }

.row { display: flex; align-items: center; width: 100%; min-height: var(--tap); padding: 10px 6px; text-align: left; border-bottom: 1px solid var(--panel); border-radius: 0; }
.row .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.more { display: block; width: 100%; margin: 12px 0; background: var(--panel); }
.chip { background: var(--panel); padding: 0 14px; }

.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; background: var(--panel); border-top: 1px solid var(--panel-2); padding-bottom: var(--safe-b); }
.tabs button { flex: 1; height: var(--tabs-h); border-radius: 0; font-size: 11px; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; }
.tabs button i { font-size: 22px; }
.tabs button .ph-fill { display: none; }
.tabs button.active .ph-fill { display: inline-block; }
.tabs button.active .ph { display: none; }
.tabs button.active { color: var(--accent); font-weight: 600; }

/* ---- player: a slim bar by default, expands on tap ---- */
.player { position: fixed; left: 0; right: 0; bottom: calc(var(--tabs-h) + var(--safe-b)); z-index: 9; background: var(--panel-2); padding: 8px 8px 8px 12px; display: grid; align-items: center; gap: 2px 8px; box-shadow: 0 -4px 16px #0006;
  grid-template-columns: 40px minmax(0, 1fr) auto auto; grid-template-areas: "cover meta ctrl close"; }
.player img { grid-area: cover; width: 40px; height: 40px; border-radius: 6px; object-fit: cover; background: var(--panel); }
.p-meta { grid-area: meta; min-width: 0; display: block; text-align: left; padding: 0 4px; min-height: 40px; border-radius: 6px; }
.p-title, .p-artist { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p-title { font-weight: 600; font-size: 15px; }
.p-artist { font-size: 12px; color: var(--muted); }
.p-controls { grid-area: ctrl; display: flex; align-items: center; }
.p-controls button { min-width: 40px; min-height: 40px; }
.p-controls button { font-size: 20px; }
.p-controls .big { font-size: 28px; }
.p-opt { display: none; }
.p-close { grid-area: close; min-width: 40px; min-height: 40px; color: var(--muted); font-size: 20px; }
.p-fold, .p-seek { display: none; }
.p-progress { position: absolute; left: 0; right: 0; top: 0; height: 2px; background: var(--panel); }
.p-progress span { display: block; height: 100%; width: 0; background: var(--accent); }

.player.expanded { padding: 8px 8px 6px 12px;
  grid-template-columns: 48px minmax(0, 1fr) auto auto; grid-template-areas: "cover meta fold close" "seek seek seek seek" "ctrl ctrl ctrl ctrl"; }
.player.expanded img { width: 48px; height: 48px; }
.player.expanded .p-fold { display: block; grid-area: fold; min-width: 40px; min-height: 40px; color: var(--muted); font-size: 20px; }
.player.expanded .p-progress { display: none; }
.player.expanded .p-seek { grid-area: seek; display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.player.expanded .p-seek input { flex: 1; min-width: 0; height: var(--tap); accent-color: var(--accent); }
.player.expanded .p-controls { justify-content: center; gap: 10px; }
.player.expanded .p-opt { display: block; }
.player.expanded .p-tgl { opacity: .5; } /* toggles (shuffle/repeat) are dim until switched on */
.player.expanded .p-tgl.on { opacity: 1; background: var(--panel); color: var(--accent); }
.player.expanded .p-controls .big { min-width: 56px; font-size: 34px; }
.player.expanded .p-opt { font-size: 20px; }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--panel-2); border-radius: 14px; width: min(92vw, 380px); padding: 16px; }
dialog::backdrop { background: #000a; }
dialog h3 { margin: 0 0 8px; }
.pl-new { display: flex; gap: 6px; margin: 10px 0; }
.pl-new input { flex: 1; min-width: 0; min-height: var(--tap); padding: 0 12px; border-radius: 10px; border: 1px solid var(--panel-2); background: var(--bg); }
.pl-new button, dialog .close { background: var(--panel-2); padding: 0 14px; }
dialog .close { width: 100%; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabs-h) + var(--player-h) + var(--safe-b) + 12px); background: #000d; padding: 10px 16px; border-radius: 20px; z-index: 20; max-width: 90vw; font-size: 14px; }

@media (min-width: 700px) {
  .player { max-width: 760px; margin: 0 auto; border-radius: 14px 14px 0 0; }
}

/* ---- account / auth ---- */
.avatar { flex: none; width: var(--tap); height: var(--tap); border-radius: 50%; background: var(--accent); color: #fff; font-weight: 700; text-transform: uppercase; }
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth form { width: min(100%, 360px); display: flex; flex-direction: column; gap: 12px; }
.auth h1 { margin: 0 0 4px; text-align: center; font-size: 26px; }
.auth input, dialog .field { min-height: var(--tap); padding: 0 14px; border-radius: 10px; border: 1px solid var(--panel-2); background: var(--panel); width: 100%; }
.auth-tabs { display: flex; background: var(--panel); border-radius: 10px; padding: 3px; }
.auth-tabs button { flex: 1; min-height: 38px; border-radius: 8px; color: var(--muted); }
.auth-tabs button.active { background: var(--panel-2); color: var(--text); font-weight: 600; }
.auth-error { color: #ff8a8a; font-size: 14px; }
.primary { background: var(--accent); color: #fff; font-weight: 600; min-height: var(--tap); }
dialog details { margin: 10px 0; }
dialog summary { min-height: var(--tap); display: flex; align-items: center; cursor: pointer; color: var(--muted); }
dialog .field { display: block; margin: 6px 0; }
.field-btn { background: var(--panel-2); width: 100%; }
.danger { width: 100%; background: #3a1d24; color: #ff8a8a; margin: 8px 0; }
body.signed-out .top, body.signed-out main, body.signed-out .tabs, body.signed-out .player { display: none; }

.dlg-actions { display: flex; gap: 8px; margin-top: 10px; }
.dlg-actions button { flex: 1; }
.dlg-actions .close { width: auto; }

/* ---- live filter ---- */
.filter { display: block; width: 100%; min-height: var(--tap); margin: 2px 0 8px; padding: 0 14px; border-radius: 22px; border: 1px solid var(--panel-2); background: var(--panel); }
.filter:focus { outline: 2px solid var(--accent); outline-offset: 0; }
mark { background: #ff4d6d44; color: inherit; border-radius: 3px; padding: 0 1px; }

/* playlist search hits */
.row.group { flex-direction: column; align-items: stretch; gap: 2px; }
.g-head { display: flex; align-items: center; gap: 8px; }
.g-hit { display: block; font-size: 13px; color: var(--muted); padding-left: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.more-hits { font-style: italic; }

.chips { display: flex; gap: 8px; margin: 4px 0 8px; }
.chip.on { background: var(--accent); color: #fff; }

/* ---- icons ---- */
.chip { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.chip i { font-size: 18px; }
.row i { color: var(--muted); font-size: 18px; flex: none; }
.row .grow i { color: var(--accent); margin-right: 4px; vertical-align: -2px; }
.empty i { vertical-align: -2px; color: var(--accent); }
.t-act.on { color: var(--accent); }
.g-hit { position: relative; padding-left: 12px; }
.g-hit::before { content: ""; position: absolute; left: 3px; top: 50%; width: 4px; height: 4px; margin-top: -2px; border-radius: 50%; background: var(--muted); opacity: .7; }
.more-hits::before { display: none; }

/* ---- three-dots action sheet ---- */
dialog.sheet { margin: auto auto 0; width: 100%; max-width: 560px; padding: 0; border: 0; border-radius: 16px 16px 0 0; background: var(--panel); }
.sheet::backdrop { background: #000a; }
.sheet-body { padding: 6px 12px calc(12px + env(safe-area-inset-bottom, 0px)); }
.sheet-track { display: flex; flex-direction: column; gap: 2px; padding: 12px 6px; border-bottom: 1px solid var(--panel-2); margin-bottom: 4px; }
.sheet-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.sheet-item { display: flex; align-items: center; gap: 16px; width: 100%; min-height: 52px; padding: 0 6px; text-align: left; font-size: 16px; color: var(--text); text-decoration: none; border-radius: 10px; }
.sheet-item:active { background: var(--panel-2); }
.sheet-item i { font-size: 22px; color: var(--muted); flex: none; }
.sheet-item.on i { color: var(--accent); }
.sheet-cancel { width: 100%; margin-top: 6px; background: var(--panel-2); }

/* ---- segmented switch (search mode, artist releases / all tracks) ---- */
.seg { display: flex; background: var(--panel); border-radius: 10px; padding: 3px; margin: 8px 0 0; }
.seg button { flex: 1; min-height: 36px; border-radius: 8px; color: var(--muted); font-size: 14px; }
.seg button.active { background: var(--panel-2); color: var(--text); font-weight: 600; }
.seg-wide { margin: 10px 0 8px; }
.chips { flex-wrap: wrap; }

/* ---- artist search rows ---- */
.person { gap: 12px; }
.person > i { color: var(--muted); font-size: 18px; flex: none; }
.p-avatar { position: relative; flex: none; width: 52px; height: 52px; border-radius: 50%; overflow: hidden; background: var(--panel-2); display: grid; place-items: center; color: var(--muted); font-size: 28px; }
.p-avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.p-avatar.failed img, .a-photo.failed img { display: none; }
.p-text { flex: 1; min-width: 0; display: block; }
.p-name { display: block; font-weight: 600; }
.p-sub { display: block; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---- artist screen ---- */
.a-card { display: flex; gap: 14px; align-items: center; padding: 4px 0 8px; }
.a-photo { position: relative; flex: none; width: 96px; height: 96px; border-radius: 50%; overflow: hidden; background: var(--panel-2); display: grid; place-items: center; color: var(--muted); font-size: 48px; }
.a-photo img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.online { position: absolute; right: 8px; bottom: 8px; width: 14px; height: 14px; border-radius: 50%; background: #3ddc84; border: 2px solid var(--bg); }
.a-info { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.a-name { font-size: 20px; font-weight: 700; line-height: 1.2; }
.a-line { font-size: 14px; color: var(--muted); display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.a-line i { font-size: 16px; }
.a-site { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; font-size: 14px; text-decoration: none; }
.a-site i { font-size: 16px; }
.link { min-height: 32px; min-width: 0; padding: 0 2px; color: var(--accent); }
.a-actions { display: flex; gap: 10px; margin: 10px 0 4px; }
.a-actions .primary, .chip-btn { flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px; border-radius: 22px; }
.chip-btn { background: var(--panel); }
.a-sort select { margin: 4px 0 6px; }
.a-count { padding: 6px 4px; font-size: 13px; }
.release { border-bottom: 1px solid var(--panel); }
.rel-head { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 48px; padding: 6px 4px; text-align: left; border-radius: 0; }
.rel-head i { color: var(--muted); flex: none; }
.rel-name { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.release .more { margin: 6px 0 10px; }
.player.expanded .p-artist { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
