:root {
  /* Dark is the app's default identity: a warm near-black with a dial-glow
     amber. Light is its daytime counterpart, not an inversion — the accent
     darkens to #9e5f00 so it stays legible on paper and still carries white
     text when used as a fill. */
  color-scheme: dark;
  --bg: #17130f;
  --surface: #211b15;
  --raised: #2b2219;
  --line: #352b21;
  --ink: #f3ece2;
  --muted: #a3907a;
  --dial: #e8a33d;
  --dial-dim: #6d4d18;
  --on-dial: #1a1208;
  --placeholder: #6e6154;
  --danger: #d9705a;
  --ok: #6fae7c;
  --glow: 0 0 9px var(--dial);
  --lift: 0 12px 40px rgba(0, 0, 0, .45);

  --ui: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --serif: ui-serif, "New York", "Iowan Old Style", Palatino, Georgia, serif;

  --pad: 1.125rem;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --tabbar: 3.6rem;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f0e8;
  --surface: #fffdf8;
  --raised: #ebe3d6;
  --line: #ded3c2;
  --ink: #2b221a;
  --muted: #756757;
  --dial: #9e5f00;
  --dial-dim: #c99a4e;
  --on-dial: #fffdf8;
  --placeholder: #9c8d79;
  --danger: #b23a26;
  --ok: #3d7a4e;
  --glow: none;          /* a glowing dot reads as a smudge on paper */
  --lift: 0 10px 30px rgba(74, 58, 38, .16);
}

* { box-sizing: border-box; }

/* The browser's own [hidden] rule lives in the UA stylesheet, and ANY author
   rule that sets display beats it — specificity does not come into it, author
   declarations simply outrank UA ones. .setup, .mini and .sheet all set
   display, so without this their hidden attribute does nothing and the
   full-screen now-playing sheet covers the app. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--ui);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
body { padding-top: var(--safe-t); }

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input { font: inherit; }
:focus-visible { outline: 2px solid var(--dial); outline-offset: 2px; border-radius: 3px; }

svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2;
      stroke-linecap: round; stroke-linejoin: round; }

/* --- first run ---------------------------------------------------------- */

.setup { min-height: 100svh; display: grid; place-items: center; padding: var(--pad); }
.setup-inner { width: 100%; max-width: 22rem; }
.setup-note { color: var(--muted); line-height: 1.55; margin: .25rem 0 1.5rem; }
.setup-note code { font-size: .9em; color: var(--ink); }

/* --- chrome ------------------------------------------------------------- */

.topbar {
  position: sticky; top: var(--safe-t); z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: .7rem var(--pad) .6rem;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.wordmark {
  margin: 0; font-family: var(--serif); font-size: 1.35rem;
  font-weight: 500; letter-spacing: .01em;
}
.wordmark::after {
  content: ""; display: inline-block;
  width: 6px; height: 6px; margin-left: .35rem;
  border-radius: 50%; background: var(--dial);
  box-shadow: var(--glow); vertical-align: .35em;
}
.wordmark.is-busy::after { animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .2; } }

.topbar-actions { display: flex; align-items: center; }

/* JS always resolves data-theme to an explicit value, so the icon showing is
   the appearance you would switch TO. */
.ico-moon { display: none; }
[data-theme="light"] .ico-sun { display: none; }
[data-theme="light"] .ico-moon { display: block; }

.icon-btn { display: grid; place-items: center; width: 42px; height: 42px;
            border-radius: 50%; color: var(--ink); }
.icon-btn:active { background: var(--raised); }
.icon-btn:disabled { opacity: .4; }

.view {
  max-width: 40rem; margin: 0 auto;
  padding: .25rem var(--pad) calc(var(--tabbar) + 6rem + var(--safe-b));
}

/* --- bottom tab bar ----------------------------------------------------- */

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
  display: flex;
  padding-bottom: var(--safe-b);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.tab {
  flex: 1; position: relative;
  display: flex; flex-direction: column; align-items: center; gap: .15rem;
  padding: .5rem 0 .45rem;
  color: var(--muted); font-size: .68rem;
}
.tab svg { width: 20px; height: 20px; }
.tab.is-current { color: var(--dial); }
.badge {
  position: absolute; top: .3rem; left: 55%;
  min-width: 1.05rem; padding: 0 .28rem;
  background: var(--dial); color: var(--on-dial);
  border-radius: 999px; font-size: .62rem; font-style: normal;
  font-weight: 700; line-height: 1.05rem; text-align: center;
}

/* --- search ------------------------------------------------------------- */

.searchbar { display: flex; gap: .5rem; padding: .9rem 0 .4rem; }
.searchbar .field { margin: 0; }
.searchbar button { padding: 0 1.1rem; border-radius: 6px;
                    background: var(--dial); color: var(--on-dial); font-weight: 600; }

.result {
  display: grid; grid-template-columns: 3rem 1fr auto;
  gap: .85rem; align-items: center;
  padding: .9rem 0; border-bottom: 1px solid var(--line);
}
.result-art { width: 3rem; height: 3rem; border-radius: 50%;
              object-fit: cover; background: var(--raised); }
.result-name { font-family: var(--serif); font-size: 1.02rem; line-height: 1.3; }
.result-sub { font-size: .76rem; color: var(--muted); margin-top: .18rem;
              display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical;
              overflow: hidden; }

/* --- channel filter chips ----------------------------------------------- */

.filters {
  display: flex; gap: .45rem; overflow-x: auto;
  padding: .85rem 0 .9rem;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.filters::-webkit-scrollbar { display: none; }
.filters .chip { flex: 0 0 auto; }

/* --- episode / library rows --------------------------------------------- */

.row {
  display: grid; grid-template-columns: 4.5rem 1fr auto;
  gap: .85rem; align-items: start;
  padding: .9rem 0; border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.row-art { width: 4.5rem; height: 3.05rem; object-fit: cover;
           border-radius: 3px; background: var(--raised); }
.row-main { min-width: 0; }
.row-title {
  font-family: var(--serif); font-size: 1rem; line-height: 1.32; margin: 0 0 .3rem;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.row.is-current .row-title { color: var(--dial); }
.row.is-played .row-title { color: var(--muted); }
.row-meta { font-size: .76rem; color: var(--muted); display: flex; gap: .6rem; flex-wrap: wrap; }
/* Never let one long value wrap inside itself; a long channel name ellipsises
   instead so the length and date stay on the same line. */
.row-meta span { white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.row-meta .who { flex: 0 1 auto; min-width: 0; }
.row-action { align-self: center; }
.row-play { text-align: left; display: contents; }

.state { font-size: .76rem; }
.state.queued { color: var(--muted); }
.state.downloading { color: var(--dial); }
.state.error { color: var(--danger); }

.bar { grid-column: 2 / -1; height: 3px; margin-top: .55rem;
       background: var(--line); border-radius: 3px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--dial);
            transition: width .4s linear; }
.bar.indeterminate span { width: 35%; animation: slide 1.4s ease-in-out infinite; }
@keyframes slide { 0% { margin-left: -35%; } 100% { margin-left: 100%; } }
.heard { grid-column: 2 / -1; height: 2px; margin-top: .5rem;
         background: var(--line); border-radius: 2px; overflow: hidden; }
.heard span { display: block; height: 100%; background: var(--dial-dim); }

@media (prefers-reduced-motion: reduce) {
  .bar span, .bar.indeterminate span { transition: none; animation: none; }
}

/* --- shared bits -------------------------------------------------------- */

.group-head { font-size: .76rem; color: var(--muted); padding: 1.4rem 0 .25rem; }
.feedbar {
  display: flex; align-items: center; gap: .6rem;
  padding: .9rem; margin: .9rem 0 .3rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
}
.feedbar p { margin: 0; font-size: .78rem; color: var(--muted); line-height: 1.45; }
.feedbar strong { display: block; color: var(--ink); font-weight: 600; margin-bottom: .15rem; }

.empty { padding: 4rem 0; text-align: center; color: var(--muted); line-height: 1.6; }
.empty strong { display: block; color: var(--ink); font-family: var(--serif);
                font-size: 1.15rem; font-weight: 500; margin-bottom: .4rem; }
.notice { padding: .7rem .85rem; margin: .8rem 0; border-radius: 6px;
          background: var(--raised); color: var(--danger); font-size: .8rem; }

.spinner { display: block; margin: 3rem auto; width: 20px; height: 20px;
           border: 2px solid var(--line); border-top-color: var(--dial);
           border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

a.chip { display: inline-block; text-decoration: none; }
.chip.danger { color: var(--danger); border-color: var(--danger); }
.card-rule { border: 0; border-top: 1px solid var(--line); margin: 1.15rem 0 .95rem; }
.danger-note { margin: 0; font-size: .82rem; line-height: 1.5; color: var(--danger); }
.chip { padding: .42rem .85rem; border-radius: 999px; border: 1px solid var(--line);
        color: var(--muted); font-size: .8rem; white-space: nowrap; }
.chip.is-on { color: var(--dial); border-color: var(--dial-dim); }

.field { width: 100%; padding: .8rem .9rem; margin-bottom: .75rem;
         background: var(--surface); color: var(--ink);
         border: 1px solid var(--line); border-radius: 6px; }
.field::placeholder { color: var(--placeholder); }
.btn-primary { width: 100%; padding: .8rem; border-radius: 6px;
               background: var(--dial); color: var(--on-dial); font-weight: 600; }
.error { color: var(--danger); font-size: .84rem; margin: .75rem 0 0; }

/* --- player ------------------------------------------------------------- */

.mini {
  position: fixed; left: 0; right: 0; z-index: 34;
  bottom: calc(var(--tabbar) + var(--safe-b));
  display: flex; align-items: center; gap: .6rem;
  padding: .5rem var(--pad);
  background: var(--surface); border-top: 1px solid var(--line);
}
.mini-progress { position: absolute; top: 0; left: 0; right: 0; height: 2px; background: var(--line); }
.mini-progress span { display: block; height: 100%; width: 0; background: var(--dial); }
.mini-open { display: flex; align-items: center; gap: .7rem; flex: 1; min-width: 0; text-align: left; }
.mini-art { width: 2.3rem; height: 2.3rem; border-radius: 3px; object-fit: cover; background: var(--raised); }
.mini-text { min-width: 0; }
.mini-title { display: block; font-family: var(--serif); font-size: .93rem;
              white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-sub { display: block; font-size: .73rem; color: var(--muted);
            white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.play::before { content: ""; display: block; width: 0; height: 0;
  border-left: 13px solid currentColor; border-top: 8px solid transparent;
  border-bottom: 8px solid transparent; margin-left: 3px; }
.pause::before { content: ""; display: block; width: 13px; height: 15px;
  border-left: 4px solid currentColor; border-right: 4px solid currentColor; }
.big { width: 68px; height: 68px; background: var(--dial); color: var(--on-dial); }
.big.play::before { border-left-width: 20px; border-top-width: 12px;
                    border-bottom-width: 12px; margin-left: 5px; }
.big.pause::before { width: 20px; height: 23px; border-left-width: 6px; border-right-width: 6px; }

.sheet {
  position: fixed; top: 0; left: 0; right: 0; z-index: 40;
  /* Stops at the top of the tab bar rather than covering it, so the four tabs
     stay reachable while something is playing. */
  bottom: calc(var(--tabbar) + var(--safe-b));
  background: var(--bg);
  padding: calc(var(--safe-t) + .5rem) var(--pad) 1.5rem;
  display: flex; flex-direction: column; align-items: center; overflow-y: auto;
  animation: rise .28s cubic-bezier(.22,.8,.3,1);
}
@keyframes rise { from { transform: translateY(14%); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }

.sheet-close { align-self: flex-start; width: 42px; height: 42px; color: var(--muted); }
.np-art { width: min(78vw, 19rem); aspect-ratio: 1; object-fit: cover;
          border-radius: 6px; background: var(--raised); margin: .5rem 0 2rem; }
.np-title { font-family: var(--serif); font-weight: 500; font-size: 1.3rem; line-height: 1.3;
            text-align: center; margin: 0 0 .4rem; max-width: 28ch; }
.np-channel { color: var(--muted); font-size: .85rem; margin: 0 0 2rem; }

.scrub { width: 100%; max-width: 26rem; }
.seek { width: 100%; -webkit-appearance: none; appearance: none; background: none; height: 22px; }
.seek::-webkit-slider-runnable-track { height: 3px; border-radius: 3px; background: var(--line); }
.seek::-moz-range-track { height: 3px; border-radius: 3px; background: var(--line); }
.seek::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px;
  margin-top: -5.5px; border-radius: 50%; background: var(--dial); }
.seek::-moz-range-thumb { width: 14px; height: 14px; border: 0; border-radius: 50%; background: var(--dial); }
.times { display: flex; justify-content: space-between; font-size: .75rem;
         color: var(--muted); font-variant-numeric: tabular-nums; }

.transport {
  display: flex; align-items: center; justify-content: center;
  gap: 1rem; margin: 1.75rem 0 1.5rem; width: 100%; max-width: 26rem;
}
.transport-pad, .speed-btn { flex: 0 0 3.4rem; width: 3.4rem; }
.speed-btn {
  height: 2.1rem; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted);
  font-size: .8rem; font-variant-numeric: tabular-nums;
}
.speed-btn.is-on { color: var(--dial); border-color: var(--dial-dim); }

.speedpanel {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 46;
  bottom: calc(var(--tabbar) + var(--safe-b) + 1rem);
  width: min(84vw, 18rem); padding: 1rem 1.1rem .8rem;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: var(--lift);
}
.speedpanel .inline-field { margin-top: 0; }
.speedpanel .hint { margin: .55rem 0 0; text-align: center; }
.skip { font-size: .72rem; font-variant-numeric: tabular-nums; color: var(--muted); }
#np-back .skip::before { content: "\21BA\2009"; }
#np-fwd .skip::after { content: "\2009\21BB"; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar) + 4.5rem + var(--safe-b)); z-index: 50;
  background: var(--raised); border: 1px solid var(--line);
  padding: .6rem 1rem; border-radius: 999px; font-size: .84rem; max-width: 88vw;
}

/* A toast firing while the speed picker is open would otherwise land on top
   of the slider. Lift it clear of the panel instead. */
body.speed-open .toast { bottom: calc(var(--tabbar) + 8.5rem + var(--safe-b)); }

/* --- settings ----------------------------------------------------------- */

.card {
  padding: 1rem; margin: .9rem 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
}
.card h2 {
  margin: 0 0 .2rem; font-family: var(--serif);
  font-size: 1.05rem; font-weight: 500;
}
.card p { margin: .35rem 0 0; font-size: .82rem; color: var(--muted); line-height: 1.5; }
.card .field { margin: .85rem 0 .65rem; }
.card-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .9rem; }

.status { display: flex; align-items: baseline; gap: .45rem; margin-top: .6rem; font-size: .82rem; }
.status::before {
  content: ""; flex: 0 0 auto; width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted); transform: translateY(-1px);
}
.status.ok::before { background: var(--ok); }
.status.warn::before { background: var(--dial); }
.status.bad::before { background: var(--danger); }
.status.bad { color: var(--danger); }

.facts { margin: .8rem 0 0; font-size: .8rem; color: var(--muted); }
.facts div { display: flex; justify-content: space-between; gap: 1rem;
             padding: .3rem 0; border-bottom: 1px solid var(--line); }
.facts div:last-child { border-bottom: 0; }
.facts span:last-child { color: var(--ink); text-align: right;
                         font-variant-numeric: tabular-nums; }

.feedurl {
  margin: .8rem 0 0; padding: .55rem .7rem;
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .72rem; color: var(--muted);
  overflow-wrap: anywhere; user-select: all;
}

.field-name { flex: 0 0 4.4rem; }
.inline-field input:focus { border-color: var(--dial); outline: none; }

.filepick { display: block; margin: .85rem 0 0; font-size: .82rem; color: var(--muted); }
.filepick input { display: block; margin-top: .4rem; width: 100%; font-size: .8rem; }
.filepick input::file-selector-button {
  margin-right: .7rem; padding: .45rem .8rem; border: 1px solid var(--line);
  border-radius: 999px; background: var(--raised); color: var(--ink); font: inherit;
}

.inline-field { display: flex; align-items: center; gap: .6rem; margin-top: .85rem; }
.inline-field input {
  width: 4.6rem; padding: .6rem .7rem; text-align: center;
  background: var(--bg); color: var(--ink);
  border: 1px solid var(--line); border-radius: 6px;
  font-variant-numeric: tabular-nums;
}
.inline-field label { font-size: .82rem; color: var(--muted); }

.badge.warn { background: var(--danger); color: #fff; }
.pin.is-on { color: var(--dial); }
