:root {
  --bg: #0b1120;
  --surface: #0f172a;
  --surface2: #1e293b;
  --line: #243044;
  --text: #e8edf6;
  --dim: #8aa0bd;
  --accent: #38bdf8;
  --accent-ink: #04212e;
  --played: #475569;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }   /* beat #id/.class display rules below */

html, body {
  margin: 0; height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}
body { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }

button { font: inherit; color: inherit; cursor: pointer; border: none; background: none; }

/* ---- top bar (passive) ---- */
#topbar {
  flex: 0 0 auto;
  position: relative; z-index: 20;        /* keep the dropdown above the scroll area */
  display: flex; align-items: center; gap: 9px;
  height: calc(var(--safe-top) + 48px);   /* fixed → no height jump when back button toggles */
  padding: var(--safe-top) 8px 0;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.icon-btn {
  width: 38px; height: 38px; flex: 0 0 auto; margin-left: -6px;
  font-size: 30px; line-height: 1; border-radius: 12px;
  display: grid; place-items: center; color: var(--dim);
}
.icon-btn:active { background: var(--surface2); }
.icon-btn svg { width: 21px; height: 21px; display: block; }
.icon-btn.active { color: var(--accent); }
#barActions { display: flex; align-items: center; flex: 0 0 auto; margin-right: -4px; }
#barActions .icon-btn { width: 36px; margin-left: 0; }
#barArt { width: 34px; height: 34px; border-radius: 8px; object-fit: cover; background: var(--surface2); flex: 0 0 auto; }
#barTitle { flex: 1; min-width: 0; font-size: 16px; font-weight: 700; letter-spacing: -.2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---- home brand: logo · name · build version (tap to refresh) ---- */
#brand { flex: 1; min-width: 0; display: flex; align-items: center; gap: 9px; padding: 4px 4px; border-radius: 12px; }
#brand:active { background: var(--surface2); }
#brandLogo { width: 30px; height: 30px; border-radius: 8px; flex: 0 0 auto; }
#brandVer { font-size: 11px; color: var(--dim); font-feature-settings: "tnum"; white-space: nowrap; }
#brand.syncing #brandVer { color: var(--accent); }

/* ---- scroll area ---- */
#app { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px; }
.view { animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

/* ---- library grid ---- */
#library { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.tile { position: relative; text-align: left; border-radius: 16px; overflow: hidden; background: var(--surface); }
.tile:active { transform: scale(.98); }
.tile img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: var(--surface2); }
.tile.stale img { opacity: .5; }
.tile-warn { position: absolute; top: 6px; right: 6px; width: 22px; height: 22px; border-radius: 999px;
  display: grid; place-items: center; font-size: 12px; background: rgba(11,17,32,.78); color: #fbbf24; }

/* ---- episode list ---- */
.episode {
  padding: 15px 14px; margin-bottom: 10px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
}
.episode:active { transform: scale(.99); opacity: .9; }

/* desktop pointer affordance — gated so touch devices don't get sticky hover */
@media (hover: hover) {
  .episode:hover { border-color: var(--accent); background: var(--surface2); }
}
.episode.played { opacity: .55; }
.episode.current { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.ep-title { font-size: 15px; font-weight: 600; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ep-meta { margin-top: 6px; font-size: 12px; color: var(--dim); }
.ep-resume { color: var(--accent); }   /* "NN% played" resume cue — stands out from the dim meta */
.episode.played .ep-meta::after { content: " · played"; color: var(--played); }
.feed-err { color: var(--dim); font-size: 13px; padding: 10px 2px; }

/* ---- bottom thumb zone (player) ---- */
#player {
  flex: 0 0 auto;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding: 8px 12px calc(var(--safe-bottom) + 10px);
  display: flex; flex-direction: column; gap: 10px;
  box-shadow: 0 -8px 24px rgba(0,0,0,.35);
}
#scrub { display: flex; flex-direction: column; gap: 2px; }
#seek { width: 100%; height: 28px; margin: 0; accent-color: var(--accent); }
#times { display: flex; justify-content: space-between; font-size: 11px; color: var(--dim); }

#nowplaying { display: flex; align-items: center; gap: 11px; min-height: 44px; }
#npArt { width: 44px; height: 44px; border-radius: 10px; object-fit: cover; background: var(--surface2); flex: 0 0 auto; }
#npText { min-width: 0; }
#npTitle { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#npFeed { font-size: 12px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

#controls { display: flex; gap: 10px; }
.ctl {
  flex: 1; height: 58px; border-radius: 14px;
  background: var(--surface2); font-size: 17px; font-weight: 700;
  display: grid; place-items: center;
}
.ctl:active { background: var(--line); }
.ctl svg { width: 28px; height: 28px; display: block; }
.ctl.big { flex: 1.4; background: var(--accent); color: var(--accent-ink); font-size: 24px; }
.ctl.big:active { filter: brightness(.92); }

/* ---- about / backup sheet (tap the logo) ---- */
.overlay {
  position: fixed; inset: 0; z-index: 40;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0,0,0,.5);
  padding: 12px 12px calc(env(safe-area-inset-bottom,0px) + 16px);
}
.sheet {
  width: 100%; max-width: 420px;
  background: var(--surface2); border: 1px solid var(--line); border-radius: 16px;
  padding: 14px; box-shadow: 0 14px 40px rgba(0,0,0,.5);
  animation: sheet-in .16s ease;
}
@keyframes sheet-in { from { opacity: 0; transform: translateY(16px); } }
.about-tag { margin: 4px 6px 12px; font-size: 14px; color: var(--dim); text-align: center; line-height: 1.45; }
.sheet-btn {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 13px 14px; margin-top: 6px; border-radius: 12px;
  background: var(--surface); color: var(--text); font-size: 15px; text-align: left;
}
.sheet-btn:active { background: var(--line); }
.sheet-btn svg { width: 20px; height: 20px; flex: 0 0 auto; color: var(--dim); }
