/* Navy and blue brand colors; the icon is scripts/brand-icons.mjs. Layout and icons
   follow the design canvas (Player-web, Favorites-web, Tags-web, Tag-detail-web and
   the phone artboards). */
:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eaeff7;
  --ink: #0f1b2d;
  --ink-2: #46546b;
  --ink-3: #5f6b80;
  --line: #dce3ee;
  --line-soft: #edf1f7; /* between rows */
  --line-strong: #c5d1e4; /* outlined buttons */
  --brand: #13274a;
  --accent: #2b63c6;
  --accent-ink: #ffffff;
  --accent-soft: #e7eef9;
  --solid: #13274a; /* navy buttons: Done, chosen sort */
  --solid-ink: #ffffff;
  --selbar: #13274a; /* the "2 selected" bar */
  --selbar-ink: #ffffff;
  --selbar-ink-2: #c9d7ee;
  --scrim: rgb(15 27 45 / 0.5);
  --ok: #2f6b3a;
  --ok-soft: #dcebdc;
  --warn: #8a4b12;
  --warn-soft: #f6e3cf;
  --danger: #a3271c;
  --focus: #2b63c6;
  --shadow: 0 -6px 24px rgb(15 27 45 / 0.12);
  --pop-shadow: 0 18px 40px rgb(15 27 45 / 0.18);
  /* The player bar follows the phone's setting: white in light mode, navy in dark. */
  --player-bg: #ffffff;
  --player-ink: #0f1b2d;
  --player-ink-2: #46546b;
  --player-line: #dce3ee;
  --player-btn: #eaeff7;
  --player-icon: #13274a;
  --player-play-bg: #13274a;
  --player-play-ink: #ffffff;
  --player-art: #13274a;
  --player-ring: #c5d1e4;
  --player-accent: #2b63c6;
  --player-warn: #8a4b12;
  --radius: 10px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1424;
    --surface: #121e33;
    --surface-2: #1a2943;
    --ink: #e8eef7;
    --ink-2: #b5c3da;
    --ink-3: #8d9cb6;
    --line: #263753;
    --line-soft: #1c2a44;
    --line-strong: #34486b;
    --brand: #e8eef7;
    --accent: #8eb4f2;
    --accent-ink: #0b1424;
    --accent-soft: #1d3157;
    --solid: #e8eef7;
    --solid-ink: #0b1424;
    --selbar: #1d3157;
    --selbar-ink: #ffffff;
    --selbar-ink-2: #c9d7ee;
    --scrim: rgb(0 0 0 / 0.6);
    --ok: #8fcf98;
    --ok-soft: #22331f;
    --warn: #e8b27a;
    --warn-soft: #3a2a18;
    --danger: #f19a8f;
    --focus: #8eb4f2;
    --shadow: 0 -6px 24px rgb(0 0 0 / 0.5);
    --pop-shadow: 0 18px 40px rgb(0 0 0 / 0.55);
    --player-bg: #13274a;
    --player-ink: #ffffff;
    --player-ink-2: #c9d7ee;
    --player-line: rgb(255 255 255 / 0.08);
    --player-btn: rgb(255 255 255 / 0.1);
    --player-icon: #ffffff;
    --player-play-bg: #ffffff;
    --player-play-ink: #13274a;
    --player-art: rgb(255 255 255 / 0.1);
    --player-ring: rgb(255 255 255 / 0.28);
    --player-accent: #8eb4f2;
    --player-warn: #f3c58b;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 var(--sans);
  padding-bottom: 190px; /* room for the player */
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
a { color: var(--accent); }

/* ---- icons (public/js/icons.js) ---- */
svg.i { width: 20px; height: 20px; flex: none; display: block; }
svg.i.sm { width: 14px; height: 14px; }
svg.i.lg { width: 26px; height: 26px; }
.ic { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icf { fill: currentColor; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
.ic-knock { fill: none; stroke: var(--accent-ink); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.ic-t { font: 700 7px var(--sans); text-anchor: middle; fill: currentColor; }
.mk-mic { fill: none; stroke: currentColor; stroke-width: 3.2; stroke-linecap: round; }

/* ---- header ---- */
.top {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding: 14px 16px 0;
}
.brand h1 { font: 600 1.45rem/1.1 var(--serif); margin: 0; letter-spacing: 0.01em; color: var(--brand); display: flex; align-items: center; gap: 10px; }
.brand h1 em { font-style: italic; font-weight: 400; }
.logo { width: 32px; height: 32px; flex: none; }
.tagline { margin: 3px 0 6px 42px; color: var(--ink-3); font-size: 0.85rem; }
.tabs { display: flex; gap: 4px; align-items: flex-end; flex-wrap: wrap; }
.tabs button {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px;
  border: 0; background: none; padding: 0 12px; border-bottom: 3px solid transparent;
  color: var(--ink-2); white-space: nowrap; font-weight: 600;
}
.tabs button svg.i { width: 18px; height: 18px; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.tabs button[data-view="favorites"][aria-selected="true"] svg.i { color: var(--accent); }
.count { color: var(--ink-3); font-weight: 400; }
.count:empty { display: none; }
.caret { color: var(--ink-3); }
.tabs .caret { width: 14px; height: 14px; }

/* Library menu: which libraries the list shows */
.lib-picker { position: relative; }
.lib-menu {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 20; min-width: 250px;
  display: grid; gap: 2px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgb(15 27 45 / 0.18);
}
.lib-menu .check { padding: 9px 10px; border-radius: 6px; color: var(--ink); font-size: 0.95rem; cursor: pointer; }
.lib-menu .check:hover { background: var(--surface-2); }
.lib-menu .lib-all { font-weight: 600; border-bottom: 1px solid var(--line); border-radius: 6px 6px 0 0; }

main { max-width: 1032px; margin: 0 auto; padding: 0 16px; }

/* ---- toolbar ---- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; padding: 16px 0 10px; }
.search {
  flex: 1 1 240px; min-width: 0; display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink-3);
}
.search svg.i { width: 18px; height: 18px; }
.search input { flex: 1 1 auto; min-width: 0; border: 0; outline: none; background: transparent; color: var(--ink); padding: 0; }
.search:focus-within { outline: 2px solid var(--focus); outline-offset: 1px; }
.toolbar select, .page-tools select {
  min-height: 44px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0 10px; min-width: 0;
}
.toolbar select { flex: 0 1 220px; }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); font-size: 0.92rem; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
.link { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; }

/* Rounded buttons: Play all, Queue all, Select, New tag, Done */
.pill {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px;
  border: 0; border-radius: 999px; background: transparent; color: var(--accent); font-weight: 700; white-space: nowrap;
}
.pill svg.i { width: 16px; height: 16px; }
.pill.primary { background: var(--accent); color: var(--accent-ink); padding: 0 18px; }
.pill.outline { background: var(--surface); color: var(--brand); border: 1.5px solid var(--line-strong); }
.pill.outline svg.i { width: 18px; height: 18px; }
.pill.solid { background: var(--solid); color: var(--solid-ink); }
.pill.text[aria-pressed="true"] { background: var(--accent-soft); color: var(--brand); }
.pill.sm { min-height: 36px; padding: 0 12px; font-size: 0.94rem; }
.pill:disabled { opacity: 0.5; cursor: default; }

.summary { color: var(--ink-2); font-size: 0.9rem; padding: 4px 0 12px; display: flex; gap: 6px 12px; align-items: center; flex-wrap: wrap; }
.summary:empty { display: none; }
.note { color: var(--ink-3); font-size: 0.84rem; margin: 0 0 8px; }

/* One section per library, in Library-menu order */
.lib { margin: 0 0 26px; }
.lib-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; padding: 4px 0 8px; }
.lib-head h2 { font: 600 1.4rem/1.2 var(--serif); margin: 0; }
.lib-head .group-meta { margin-left: auto; }
.meter { flex: 1 1 160px; max-width: 280px; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--accent); width: 0; transition: width 0.3s; }

/* ---- lists ---- */
.group, .card { margin: 0 0 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
/* Thousands of rows: let the browser skip laying out groups that are off screen. */
.list > .lib > .group { content-visibility: auto; contain-intrinsic-size: auto 480px; }
.group > summary {
  list-style: none; cursor: pointer; padding: 14px 18px; display: flex; align-items: baseline; gap: 10px;
  font: 600 1.15rem/1.25 var(--serif);
}
.group > summary::-webkit-details-marker { display: none; }
.group > summary::before { content: "▸"; color: var(--ink-3); font-size: 0.8em; transition: transform 0.15s; }
.group[open] > summary::before { transform: rotate(90deg); }
.group-meta { margin-left: auto; font: 400 0.85rem var(--sans); color: var(--ink-3); white-space: nowrap; }

.session { border-top: 1px solid var(--line); }
.session-head { padding: 10px 18px 6px; display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }
.session-title { font-weight: 600; font-size: 0.95rem; }
.session-note { color: var(--ink-3); font-size: 0.82rem; flex-basis: 100%; }

.row {
  display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; gap: 12px; align-items: center;
  padding: 10px 18px; border-top: 1px solid var(--line-soft);
}
.card > .row:first-child, .session-head + .row, .group > .session-head + .row { border-top: 0; }
.row.playing { background: var(--accent-soft); box-shadow: inset 4px 0 0 var(--accent); }
.row.selected { background: var(--accent-soft); }
.row.listened .who, .row.listened .what { color: var(--ink-3); }
.row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
.row input.pick { width: 20px; height: 20px; accent-color: var(--brand); }
.row-main { min-width: 0; }
.row-title { display: flex; flex-wrap: wrap; gap: 0 8px; align-items: baseline; }
.who { font-weight: 700; }
.what { color: var(--ink-2); }
.row-sub { color: var(--ink-3); font-size: 0.875rem; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-top: 1px; }
.row.playing .row-sub { color: var(--ink-2); }
.row-actions { display: flex; flex-wrap: wrap; gap: 2px; align-items: center; justify-content: flex-end; }

/* Round icon buttons in rows and pages */
.ib {
  width: 40px; height: 40px; flex: none; display: inline-grid; place-items: center; padding: 0;
  border: 0; border-radius: 50%; background: transparent; color: var(--ink-3); text-decoration: none;
}
.ib:hover { background: var(--surface-2); color: var(--ink); }
.ib.on, .ib.on:hover { color: var(--accent); }
.ib[aria-expanded="true"] { background: var(--accent-soft); color: var(--accent); }
.ib.play { border: 1px solid var(--line); background: var(--surface); color: var(--brand); }
.ib.play svg.i { width: 14px; height: 14px; }
.ib.fav svg.i { width: 20px; height: 20px; }
.ib.tagb svg.i { width: 19px; height: 19px; }
.ib.dl svg.i { width: 18px; height: 18px; }
.ib:disabled { opacity: 0.45; cursor: default; }
.ib.busy { width: auto; min-width: 40px; padding: 0 6px; font-size: 0.8rem; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.now-label { display: none; align-items: center; gap: 6px; padding: 0 8px; font-size: 0.875rem; font-weight: 700; color: var(--brand); white-space: nowrap; }
.now-label svg.i { width: 16px; height: 16px; }
.row.playing .now-label { display: inline-flex; }
.row.playing [data-act="play"], .row.playing [data-act="play-index"] { display: none; }

/* Text links beside the icons: Read, Catalog */
.read { display: inline-flex; align-items: center; gap: 4px; min-height: 40px; padding: 0 8px; font-weight: 600; font-size: 0.94rem; text-decoration: none; white-space: nowrap; }
.read:hover { text-decoration: underline; }

/* A talk's tags */
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border: 0; border-radius: 999px;
  background: var(--accent-soft); color: var(--brand); font-size: 0.75rem; font-weight: 600; line-height: 1.5;
}
.chip svg.i { width: 11px; height: 11px; }
button.chip:hover { text-decoration: underline; }
.row.playing .chip, .row.selected .chip { background: var(--surface); }
.dl-note { display: inline-flex; align-items: center; gap: 4px; color: var(--accent); font-weight: 600; }
.dl-note svg.i { width: 13px; height: 13px; }
.heard { display: inline-flex; align-items: center; gap: 4px; color: var(--ok); font-weight: 600; }
.heard svg.i { width: 14px; height: 14px; }

.badge { display: inline-block; font-size: 0.72rem; font-weight: 600; letter-spacing: 0.02em; padding: 2px 7px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.ai { background: var(--accent-soft); color: var(--accent); }
.soon { color: var(--ink-3); font-size: 0.8rem; white-space: nowrap; padding: 0 8px; }

.program { margin: 0 18px 10px; font-size: 0.82rem; color: var(--ink-3); }
.program summary { cursor: pointer; }
.program ol { margin: 6px 0 0; padding-left: 18px; }
.program li.speaker { color: var(--ink-2); }

.empty { text-align: center; color: var(--ink-3); padding: 40px 0; }

.qrow .num { color: var(--ink-3); font-variant-numeric: tabular-nums; text-align: right; }

/* ---- Favorites, Tags and a tag's page ---- */
.crumbs { display: flex; align-items: center; gap: 6px; padding: 16px 0 0; font-size: 0.94rem; color: var(--ink-3); }
.crumbs [aria-current] { color: var(--ink-2); }
.crumb-back { display: inline-flex; align-items: center; gap: 4px; min-height: 36px; padding: 0; border: 0; background: none; color: var(--accent); font-weight: 600; }
.crumb-back svg.i { width: 16px; height: 16px; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; padding: 22px 0 8px; }
.crumbs + .page-head { padding-top: 8px; }
.page-icon { width: 44px; height: 44px; border-radius: 12px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex: none; }
.page-icon svg.i { width: 24px; height: 24px; }
.page-title { min-width: 0; }
.page-title h2 { margin: 0; font: 600 1.65rem/1.15 var(--serif); overflow-wrap: anywhere; }
.page-meta { margin: 2px 0 0; font-size: 0.875rem; color: var(--ink-3); }
.page-actions { margin-left: auto; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.page-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; padding: 10px 0 14px; }
.sort { display: inline-flex; align-items: center; gap: 10px; color: var(--ink-2); font-size: 0.94rem; }
.page-note { margin: 0 2px 8px; font-size: 0.875rem; color: var(--ink-3); }
.page-empty { margin: 0 0 14px; padding: 28px 18px; text-align: center; color: var(--ink-3); background: var(--surface); border: 1px dashed var(--line); border-radius: 14px; }

/* Segmented sort (Tags page) */
.seg { display: flex; padding: 3px; border-radius: 999px; background: var(--surface-2); }
.seg button { min-height: 38px; padding: 0 14px; border: 0; border-radius: 999px; background: transparent; color: var(--ink-2); font-weight: 600; font-size: 0.94rem; white-space: nowrap; }
.seg button[aria-pressed="true"] { background: var(--solid); color: var(--solid-ink); font-weight: 700; }

/* Multi-select bar */
.selbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; margin: 0 0 14px; padding: 10px 12px 10px 18px;
  border-radius: 14px; background: var(--selbar); color: var(--selbar-ink);
}
.sel-count { font-weight: 700; margin-right: auto; }
.selbar .pill { min-height: 40px; font-size: 0.94rem; }
.selbar .pill.light { background: #ffffff; color: #13274a; }
.selbar .pill.ghost { color: var(--selbar-ink); border: 1.5px solid rgb(255 255 255 / 0.35); padding: 0 14px; }
.selbar .pill.ghost svg.i { width: 14px; height: 14px; }
.selbar .pill.bare { color: var(--selbar-ink-2); padding: 0 12px; }
.selbar .pill.bare.all { margin-right: auto; padding-left: 0; }
.selbar :focus-visible { outline-color: #ffffff; }

/* Tag list */
.tag-row { display: flex; align-items: center; border-top: 1px solid var(--line-soft); }
.card > .tag-row:first-child { border-top: 0; }
.tag-open {
  flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 14px; padding: 12px 8px 12px 18px;
  border: 0; background: none; color: var(--ink); text-align: left;
}
.tag-open:hover .tag-name { text-decoration: underline; }
.tag-ic { width: 40px; height: 40px; border-radius: 50%; background: var(--accent-soft); color: var(--brand); display: grid; place-items: center; flex: none; }
.tag-ic svg.i { width: 18px; height: 18px; }
.tag-text { flex: 1 1 auto; min-width: 0; }
.tag-name { display: block; font-weight: 700; font-size: 1.06rem; overflow-wrap: anywhere; }
.tag-sub { display: block; font-size: 0.875rem; color: var(--ink-3); }
.tag-count { font-size: 0.94rem; color: var(--ink-2); white-space: nowrap; }
.tag-count strong { color: var(--ink); }
.tag-open .chev { width: 16px; height: 16px; color: var(--ink-3); }
.tag-row > .ib { margin-right: 8px; width: 44px; height: 44px; }
.tag-edit { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 10px 12px 10px 18px; border-top: 1px solid var(--line-soft); }
.card > .tag-edit:first-child { border-top: 0; }
.tag-edit input, .title-edit input {
  flex: 1 1 200px; min-width: 0; min-height: 42px; padding: 0 12px; border: 1.5px solid var(--accent); border-radius: var(--radius);
  background: var(--surface); outline: none;
}
.title-edit { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.title-edit input { font: 600 1.3rem var(--serif); }
.form-error { flex-basis: 100%; margin: 0; color: var(--danger); font-size: 0.875rem; }
.form-error:empty { display: none; }

/* ---- tag popover (wide) and bottom sheet (phones) ---- */
.layer { position: fixed; inset: 0; z-index: 30; }
.backdrop { position: absolute; inset: 0; }
.layer.sheet .backdrop { background: var(--scrim); }
.tag-panel {
  position: absolute; display: flex; flex-direction: column; gap: 8px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line); box-shadow: var(--pop-shadow);
}
.layer.pop .tag-panel { width: 300px; max-height: min(460px, calc(100vh - 16px)); padding: 14px; border-radius: 14px; }
.tp-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.tp-heading { min-width: 0; }
.tp-head h2 { margin: 0; }
.layer.pop .tp-head h2 { font-size: 0.8rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); }
.layer.pop .tp-sub, .layer.pop .close, .layer.pop .sheet-handle, .layer.pop .tp-done { display: none; }
.tp-sub { margin: 2px 0 0; font-size: 0.875rem; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tp-find { display: flex; align-items: center; gap: 8px; min-height: 42px; padding: 0 10px; border: 1.5px solid var(--accent); border-radius: var(--radius); color: var(--ink-3); flex: none; }
.tp-find svg.i { width: 16px; height: 16px; }
.tp-find input { flex: 1 1 auto; min-width: 0; border: 0; outline: none; background: transparent; color: var(--ink); padding: 0; }
.tp-list { display: flex; flex-direction: column; overflow-y: auto; overscroll-behavior: contain; min-height: 0; }
.tp-opt { display: flex; align-items: center; gap: 10px; min-height: 36px; font-size: 0.94rem; cursor: pointer; }
.tp-opt input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); flex: none; }
.tp-name { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.tp-opt.on .tp-name { font-weight: 600; }
.tp-count { font-size: 0.8rem; color: var(--ink-3); }
.tp-create, .tp-new {
  display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 4px; border: 0; background: transparent;
  color: var(--accent); font-weight: 700; text-align: left;
}
.tp-create svg.i, .tp-new svg.i { width: 16px; height: 16px; }
.tp-new { border-top: 1px solid var(--line-soft); margin-top: 4px; }
.tp-empty { margin: 4px 0; font-size: 0.875rem; color: var(--ink-3); }

.layer.sheet .tag-panel {
  left: 0; right: 0; bottom: 0; max-height: 85vh; gap: 14px;
  padding: 10px 20px calc(20px + env(safe-area-inset-bottom)); border: 0; border-radius: 24px 24px 0 0;
}
.sheet-handle { align-self: center; width: 40px; height: 5px; border-radius: 3px; background: var(--line); flex: none; }
.layer.sheet .tp-head h2 { font: 600 1.375rem/1.2 var(--serif); }
.layer.sheet .close { background: var(--surface-2); color: var(--brand); }
.layer.sheet .tp-find { min-height: 48px; border-radius: 12px; }
.layer.sheet .tp-find svg.i { width: 18px; height: 18px; }
.layer.sheet .tp-opt { min-height: 48px; gap: 12px; padding: 0 4px; border-bottom: 1px solid var(--line-soft); font-size: 1rem; }
.layer.sheet .tp-opt:last-child { border-bottom: 0; }
.layer.sheet .tp-opt input { width: 22px; height: 22px; accent-color: var(--brand); }
.layer.sheet .tp-count { font-size: 0.875rem; }
.layer.sheet .tp-create { min-height: 48px; gap: 12px; border-bottom: 1px solid var(--line-soft); font-size: 1rem; }
.layer.sheet .tp-create svg.i { width: 26px; height: 26px; padding: 5px; border-radius: 50%; background: var(--accent-soft); }
.layer.sheet .tp-new { display: none; }
.tp-done { min-height: 52px; font-size: 1.06rem; flex: none; }

/* A tag's ⋯ menu */
.menu {
  position: fixed; z-index: 31; min-width: 170px; padding: 6px; display: grid; gap: 2px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--pop-shadow);
}
.menu button { min-height: 40px; padding: 0 12px; border: 0; border-radius: 6px; background: none; text-align: left; color: var(--ink); }
.menu button:hover, .menu button:focus-visible { background: var(--surface-2); }
.menu .danger { color: var(--danger); }

.foot { color: var(--ink-3); font-size: 0.8rem; padding: 24px 0; border-top: 1px solid var(--line); margin-top: 20px; }
.foot-actions { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; }

/* ---- player ---- */
.player {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: var(--player-bg); color: var(--player-ink); border-top: 1px solid var(--player-line); box-shadow: var(--shadow);
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
}
.player a { color: var(--player-accent); }
.player :focus-visible { outline-color: var(--player-accent); }
.p-wrap { max-width: 1000px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }
.p-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 28px; }
.p-row2 { gap: 10px 24px; }
.now { flex: 1 1 240px; min-width: 0; display: flex; gap: 12px; align-items: center; }
.art { display: block; width: 56px; height: 56px; padding: 9px; border-radius: 10px; background: var(--player-art); color: #ffffff; flex: none; }
.art svg { display: block; width: 100%; height: 100%; }
.now-text { min-width: 0; flex: 1; }
.now-title { font: 600 1.06rem/1.3 var(--serif); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.now-sub { color: var(--player-ink-2); font-size: 0.875rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.controls { flex: 0 0 auto; display: flex; align-items: center; justify-content: center; gap: 10px; }
.p-actions { flex: 1 1 240px; display: flex; justify-content: flex-end; align-items: center; gap: 4px; }
.dl-slot { display: contents; }
.icon {
  width: 44px; height: 44px; flex: none; display: inline-grid; place-items: center; padding: 0;
  border: 0; border-radius: 50%; background: transparent; color: var(--player-icon); text-decoration: none;
}
.icon:hover { background: var(--player-btn); }
.icon.play { width: 52px; height: 52px; background: var(--player-play-bg); color: var(--player-play-ink); }
.icon.play svg.i { width: 20px; height: 20px; }
.icon.fav svg.i { width: 21px; height: 21px; }
.p-actions .icon { color: var(--player-ink-2); }
.p-actions .icon.on, .p-actions .icon[aria-pressed="true"] { color: var(--player-accent); }
.p-actions .icon.busy { width: auto; min-width: 44px; padding: 0 6px; font-size: 0.8rem; font-weight: 700; color: var(--player-accent); font-variant-numeric: tabular-nums; }
.icon.mark { border: 1.5px solid var(--player-ring); color: var(--player-icon); }
.icon.mark[aria-pressed="true"] { background: var(--player-accent); border-color: var(--player-accent); color: var(--player-bg); }
.scrub { flex: 1 1 360px; min-width: 0; display: flex; align-items: center; gap: 10px; }
.scrub input { flex: 1; min-width: 0; accent-color: var(--player-accent); }
.time { font-variant-numeric: tabular-nums; font-size: 0.8rem; color: var(--player-ink-2); min-width: 44px; }
.time:last-child { text-align: right; }
.speeds { flex: none; display: flex; gap: 2px; background: var(--player-btn); border-radius: 999px; padding: 3px; }
.speeds button { min-height: 32px; border: 0; background: none; border-radius: 999px; padding: 0 8px; font-size: 0.8rem; font-weight: 600; color: var(--player-ink-2); font-variant-numeric: tabular-nums; }
.speeds button[aria-pressed="true"] { background: var(--player-play-bg); color: var(--player-play-ink); font-weight: 700; }
.vol { display: inline-flex; align-items: center; gap: 6px; color: var(--player-ink-2); }
.vol input { width: 80px; accent-color: var(--player-accent); }
.player-msg { color: var(--player-warn); font-size: 0.85rem; margin: 0; }

@media (max-width: 900px) {
  .vol { display: none; }
}

@media (max-width: 640px) {
  body { padding-bottom: 250px; }
  .top { position: static; padding: 12px 12px 0; }
  .tagline { display: none; }
  .brand h1 { margin-bottom: 6px; }
  /* Favorites and Tags: icons only (aria-labels say which). */
  .tabs { gap: 0; }
  .tabs button { padding: 0 10px; }
  .tab-label { display: none; }
  main { padding: 0 12px; }
  .row { grid-template-columns: 24px minmax(0, 1fr); gap: 4px 10px; padding: 10px 12px; }
  .row-actions { grid-column: 2; justify-content: flex-start; margin-left: -8px; }
  .now-label { padding: 0 11px; }
  .nl-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .toolbar select { flex: 1 1 100%; }
  .page-head { padding-top: 16px; }
  .page-actions { margin-left: 0; width: 100%; }
  .page-title h2 { font-size: 1.5rem; }
  .sort { flex: 1 1 100%; }
  .sort select { flex: 1 1 auto; }
  .seg { flex: 1 1 100%; }
  .seg button { flex: 1 1 0; padding: 0 8px; }
  .tag-open { padding-left: 12px; gap: 12px; }
  .tag-ic { width: 36px; height: 36px; }

  /* Player, top to bottom: talk and its buttons, position, controls, speeds. */
  .player { padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
  .p-wrap { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
  .p-row { display: contents; }
  .now { order: 1; flex: 1 1 0; }
  .art { width: 44px; height: 44px; padding: 7px; border-radius: 9px; }
  .now-title { font-size: 1rem; }
  .now-sub { font-size: 0.8rem; }
  .p-actions { order: 2; flex: none; gap: 0; }
  .p-actions .icon { width: 40px; height: 40px; }
  .scrub { order: 3; flex: 1 1 100%; }
  .controls { order: 4; flex: 1 1 100%; }
  .speeds { order: 5; width: 100%; justify-content: space-between; }
  .player-msg { order: 6; flex: 1 1 100%; }
  .speeds button { padding: 0 4px; } /* nine speeds across a phone */
}
