:root {
  /* One block for both themes: kit theme.css sets color-scheme (Auto / Light / Dark button),
     light-dark() picks the side. The old data-theme rule had nothing switching it. */
  --bg: light-dark(#f7f6f3, #121211);
  --surface: light-dark(#ffffff, #1b1a19);
  --surface-2: light-dark(#efede8, #262523);
  --border: light-dark(#e2dfd8, #33312e);
  --text: light-dark(#1c1b19, #ecebe8);
  --muted: light-dark(#6f6b63, #9c978e);
  --accent: light-dark(#e25f14, #f27a33);
  --accent-soft: light-dark(#fbe6d9, #3a2517);
  --accent-ink: light-dark(#1a0e06, #1a0e06); /* text on orange fills; white was 3.6:1 in light */
  --good: light-dark(#2f8f4e, #52b873);
  --good-soft: light-dark(#dcefe2, #1b3022);
  --skip: light-dark(#a19c92, #6f6b63);
  --danger: light-dark(#c23b30, #e0645a);
  --focus: light-dark(#2d6cdf, #6b9cf5);

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --gutter: var(--s4); /* page side padding; the app bar bleeds by the same amount */
  --r1: 6px; --r2: 10px;
  --fs-sm: 13px; --fs-base: 15px; --fs-lg: 18px; --fs-xl: 26px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
}
/* Kit (metaproject ui/kit) tokens, mapped once. */
:root {
  --kit-bg: var(--bg); --kit-surface: var(--surface); --kit-surface-2: var(--surface-2);
  --kit-ink: var(--text); --kit-muted: var(--muted); --kit-line: var(--border);
  /* The orange is a fill here, never text; kit modules that put the accent on text get a darker one. */
  --kit-accent: light-dark(#a8430a, #f27a33); --kit-on-accent: light-dark(#ffffff, #1a0e06);
  --kit-danger: var(--danger); --kit-on-danger: var(--surface);
  --kit-toast-action: light-dark(#f27a33, #a8430a); /* on the inverted toast: dark fill in light, light fill in dark */
  --kit-gutter: var(--gutter);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: var(--fs-base)/1.4 var(--font);
}
button, input { font: inherit; color: inherit; }
svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }

/* Each side pads its own safe-area inset plus the gutter (never one value for both sides, never
   max(gutter, inset)): the iPhone Duo's home-screen app has an 84pt right inset for the status column. */
/* --corner: 8px more on each side where there's no top inset (Mac, iPhone Duo), 0 on a slab phone
   in portrait, so the app bar title clears the top corners and lines up with the content below. */
:root {
  --corner: clamp(0px, 24px - env(safe-area-inset-top, 0px), 8px);
  --pad-l: calc(env(safe-area-inset-left, 0px) + var(--gutter) + var(--corner));
  --pad-r: calc(env(safe-area-inset-right, 0px) + var(--gutter) + var(--corner));
}
.wrap { max-width: 1100px; margin: 0 auto; padding: 0 var(--pad-r) var(--s6) var(--pad-l); }

/* App bar (frontend-patterns standard): sticky, opaque page color, 44pt row, a fade below. */
.masthead {
  position: sticky; top: 0; z-index: 15;
  display: flex; align-items: center; gap: var(--s3);
  /* Header breathing room: 24px below the screen top where there's no top inset (Mac, iPhone Duo),
     the inset itself on a slab phone. Sides are the page column's (--pad-l / --pad-r). */
  --top: max(env(safe-area-inset-top, 0px), 24px);
  min-height: calc(var(--top) + 44px);
  margin: 0 calc(-1 * var(--pad-r)) var(--s4) calc(-1 * var(--pad-l));
  padding: var(--top) var(--pad-r) 0 var(--pad-l);
  background: var(--bg);
}
.masthead::after { content: ""; position: absolute; left: 0; right: 0; top: 100%; height: var(--s2); background: linear-gradient(var(--bg), transparent); pointer-events: none; }
.masthead h1 { margin: 0; font-size: 22px; line-height: 1.2; letter-spacing: -0.02em; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logo { width: 34px; height: 34px; stroke: none; color: var(--text); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: var(--s2);
  min-height: 36px; padding: 0 var(--s4);
  border: 1px solid var(--border); border-radius: var(--r1);
  background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; white-space: nowrap;
}
@media (hover: hover) { .btn:hover { background: var(--surface-2); } } /* not on touch: iOS leaves :hover stuck after a tap */
.btn:disabled { opacity: .6; cursor: progress; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
@media (hover: hover) { .btn-primary:hover { background: var(--accent); filter: brightness(1.07); } }
.btn-quiet { background: transparent; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }
@media (hover: hover) { .btn-danger:hover { background: var(--danger); filter: brightness(1.08); } }
.link-btn { background: none; border: 0; padding: 0; color: var(--muted); text-decoration: underline; cursor: pointer; }
@media (hover: hover) { .link-btn:hover { color: var(--danger); } }

/* Load form */
.load-form { display: flex; gap: var(--s2); }
.load-form input {
  flex: 1; min-width: 0; height: 44px; padding: 0 var(--s3);
  font-size: 16px; /* 16px keeps iOS from zooming on focus */
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r1);
}
.load-form .btn { min-height: 44px; padding: 0 var(--s5); }
.form-error { margin: var(--s2) 0 0; color: var(--danger); font-size: var(--fs-sm); }

/* Saved playlist chips */
.chips { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s4); }
.chip {
  display: inline-flex; align-items: center; max-width: 280px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface);
  font-size: var(--fs-sm);
}
.chip.active { border-color: var(--accent); background: var(--accent-soft); }
.chip-open { background: none; border: 0; padding: var(--s1) var(--s1) var(--s1) var(--s3); cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-remove { display: grid; place-items: center; width: 28px; height: 28px; background: none; border: 0; border-radius: 999px; cursor: pointer; color: var(--muted); }
@media (hover: hover) { .chip-remove:hover { color: var(--danger); } }
.chip-remove svg { width: 12px; height: 12px; }

/* Empty state */
.empty { margin-top: var(--s6); padding: var(--s5); border: 1px dashed var(--border); border-radius: var(--r2); max-width: 640px; }
.empty p { margin: 0 0 var(--s2); }
.empty p:last-child { margin: 0; font-size: var(--fs-sm); }

/* Playlist header */
.playlist { margin-top: var(--s5); }
.pl-head { display: flex; flex-wrap: nowrap; align-items: center; gap: var(--s4); }
.pl-cover { width: 64px; height: 64px; border-radius: var(--r1); object-fit: cover; background: var(--surface-2); flex: none; }
.pl-meta { flex: 1 1 auto; min-width: 0; }
.pl-name { margin: 0; font-size: var(--fs-lg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl-sub { margin: 2px 0 0; font-size: var(--fs-sm); text-wrap: pretty; }
.pl-actions { display: flex; gap: var(--s1); flex: none; }
.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.progress { display: flex; height: 6px; margin: var(--s4) 0 var(--s2); border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.seg { display: block; height: 100%; transition: width .25s ease; }
.seg-bought { background: var(--good); }
.seg-cart { background: var(--accent); }
.seg-skip { background: var(--skip); }
.notice { margin: var(--s2) 0 0; padding: var(--s2) var(--s3); border-radius: var(--r1); background: var(--surface-2); font-size: var(--fs-sm); }

/* Toolbar */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); margin: var(--s4) 0 var(--s2); flex-wrap: wrap; }
.tabs { display: flex; gap: 2px; padding: 3px; background: var(--surface-2); border-radius: var(--r2); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
/* Set by updateTabFade() in app.js when tabs are hidden past an edge. */
.tabs.fade-r { mask-image: linear-gradient(to right, #000 calc(100% - 32px), transparent); }
.tabs.fade-l { mask-image: linear-gradient(to left, #000 calc(100% - 32px), transparent); }
.tabs.fade-l.fade-r { mask-image: linear-gradient(to right, transparent, #000 32px, #000 calc(100% - 32px), transparent); }
.tabs button { border: 0; background: none; padding: var(--s1) var(--s3); border-radius: 7px; cursor: pointer; white-space: nowrap; font-size: var(--fs-sm); color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgb(0 0 0 / .08); }
.tabs .count { font-variant-numeric: tabular-nums; opacity: .75; font-weight: 400; margin-left: 2px; }
.search { width: 220px; height: 34px; padding: 0 var(--s3); border: 1px solid var(--border); border-radius: var(--r1); background: var(--surface); font-size: var(--fs-sm); }

/* Track list */
.tracks { list-style: none; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: var(--r2); background: var(--surface); overflow: hidden; }
.track {
  display: grid; align-items: center; gap: var(--s3);
  grid-template-columns: 40px minmax(0, 1fr) auto auto auto;
  grid-template-areas: "art info stores status more";
  padding: var(--s2) var(--s3);
  border-top: 1px solid var(--border);
}
.track:first-child { border-top: 0; }
@media (hover: hover) { .track:hover { background: color-mix(in srgb, var(--surface-2) 45%, transparent); } }
.art { grid-area: art; width: 40px; height: 40px; border-radius: 4px; background: var(--surface-2); object-fit: cover; }
.info { grid-area: info; min-width: 0; }
.title, .byline { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.title { font-weight: 600; }
.version { font-weight: 400; color: var(--muted); }
.byline { font-size: var(--fs-sm); color: var(--muted); }
.dur { font-family: var(--mono); font-size: 12px; }
.badge-new { display: inline-block; margin-left: var(--s1); padding: 0 5px; border-radius: 4px; background: var(--accent); color: var(--accent-ink); font-size: 11px; font-weight: 700; vertical-align: 2px; }

/* .acts only groups stores + status for the narrow layout; on wide screens its
   children sit in the row grid directly. */
.acts { display: contents; }
.stores { grid-area: stores; display: flex; gap: var(--s1); }
.store {
  display: inline-flex; align-items: center; min-height: 36px;
  padding: 0 var(--s2); border: 1px solid var(--border); border-radius: var(--r1);
  font-size: 12px; font-weight: 600; text-decoration: none; color: var(--text); white-space: nowrap;
}
@media (hover: hover) { .store:hover { border-color: var(--text); } }
.store:visited { color: var(--muted); }

.status { grid-area: status; display: flex; border: 1px solid var(--border); border-radius: var(--r1); overflow: hidden; }
.status button { display: grid; place-items: center; width: 36px; height: 36px; border: 0; background: none; cursor: pointer; color: var(--muted); }
.status button + button { border-left: 1px solid var(--border); }
@media (hover: hover) { .status button:hover { color: var(--text); background: var(--surface-2); } }
.status button[aria-pressed="true"][data-status="cart"] { background: var(--accent); color: var(--accent-ink); }
.status button[aria-pressed="true"][data-status="bought"] { background: var(--good); color: #fff; }
.status button[aria-pressed="true"][data-status="skip"] { background: var(--skip); color: #fff; }

.more { grid-area: more; display: grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: var(--r1); background: none; cursor: pointer; color: var(--muted); }
@media (hover: hover) { .more:hover { background: var(--surface-2); color: var(--text); } }

.track.is-bought .title, .track.is-skip .title { color: var(--muted); }
.track.is-bought .art, .track.is-skip .art { opacity: .5; }
.track.is-skip .title { text-decoration: line-through; text-decoration-color: var(--skip); }

.empty-list { padding: var(--s5); text-align: center; }

/* Overflow menu */
/* The box is a kit popover (.kit-pop.menu-pop); this is the list inside. */
.kit-pop.menu-pop { padding: var(--s1); border-radius: var(--r2); min-width: 190px; }
@media (pointer: coarse) { .menu a, .menu button { min-height: 44px; display: flex !important; align-items: center; } }
.menu a, .menu button {
  display: block; width: 100%; padding: var(--s2) var(--s3); border: 0; border-radius: var(--r1);
  background: none; text-align: left; color: var(--text); text-decoration: none; font-size: var(--fs-sm); cursor: pointer;
}
@media (hover: hover) { .menu a:hover, .menu button:hover { background: var(--surface-2); } }
.menu button:disabled { color: var(--muted); cursor: default; background: none; }

/* Dialog */
/* Centered inside the safe area: the modal's inset follows each side's safe-area inset. */
.dialog { inset: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px); max-width: min(400px, calc(100vw - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px) - 2 * var(--gutter))); border: 1px solid var(--border); border-radius: var(--r2); background: var(--surface); color: var(--text); padding: var(--s5); }
.dialog::backdrop { background: rgb(0 0 0 / .45); }
.dialog p { margin: 0 0 var(--s2); text-wrap: pretty; }
.dialog-actions { display: flex; justify-content: flex-end; gap: var(--s2); margin-top: var(--s4); }

.foot { display: flex; align-items: center; gap: 0 var(--s3); flex-wrap: wrap; margin-top: var(--s6); font-size: var(--fs-sm); color: var(--muted); }
.foot .kit-theme-ic { stroke-width: 1.4; } /* the kit's weight; the global svg rule would make it 2 */

/* Touch screens: 16px keeps iOS from zooming into the search field on focus,
   and the small controls get 36px hit areas. */
@media (pointer: coarse) {
  .search { font-size: 16px; height: 40px; }
  .tabs button { min-height: 36px; }
  .chip-open { min-height: 36px; }
  .chip-remove { width: 36px; height: 36px; }
  .link-btn { min-height: 36px; }
}

/* Narrow screens: title and byline get the full row (two lines each), store
   links and status buttons share the line below and wrap when they don't fit. */
@media (max-width: 760px) {
  :root { --gutter: var(--s3); }
  .track {
    grid-template-columns: 40px minmax(0, 1fr) auto;
    grid-template-areas: "art info more" "acts acts acts";
    padding: var(--s2) 10px;
    align-items: start;
    row-gap: var(--s2);
  }
  .art { margin-top: 2px; }
  .title, .byline {
    white-space: normal; overflow-wrap: anywhere;
    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;
    text-wrap: pretty;
  }
  .dur { white-space: nowrap; }
  .acts { grid-area: acts; display: flex; flex-wrap: wrap; align-items: center; gap: var(--s1) var(--s2); }
  .store { padding: 0 6px; }
  .status { margin-left: auto; }
  .toolbar { flex-wrap: wrap; }
  .tabs { max-width: 100%; }
  .tabs button { padding: var(--s1) 10px; }
  .search { width: 100%; }
  .pl-actions .btn span { display: none; }
  .pl-actions .btn { padding: 0 var(--s3); }
}

/* iPhone Duo closed (382 wide, or 466 less the 84pt status column as a home-screen app): one
   size down on the store links so they and the status buttons still share one line. A container
   query on the playlist section, since the viewport width doesn't say how much room the rows have. */
.playlist { container-type: inline-size; }
@container (max-width: 376px) {
  .acts { column-gap: var(--s1); }
  .store { font-size: 11px; padding: 0 4px; }
  .status button { width: 34px; }
  .tabs button { padding-inline: 7px; } /* the five filters fit without scrolling at small counts */
}
