/* /player app shell — sidebar/topbar layout, Library/Series/Collections/Book
   views, and the extended transport bar. Builds on player.css's tokens and
   its `.ctrl`/`.scrub`/`.shelf`/`.shelf-card`/`.panel` styles (both files
   are loaded together on this page only) rather than redefining them. */

/* Author-stylesheet rules that set `display` (e.g. `.btn { display:
   inline-flex }`) beat the browser's default `[hidden] { display: none }`
   UA rule regardless of specificity, because author styles always outrank
   user-agent styles in the cascade -- so any element that is both
   `.hidden`-toggled and carries a class with its own explicit `display`
   (`.btn`, `.cover`, ...) would otherwise stay visible. This one rule
   re-asserts `hidden` as the highest-priority signal on this page. */
[hidden] { display: none !important; }

/* Default (light) value for the one token this file adds beyond player.css's
   own palette -- the dark/night blocks further down override it. */
:root { --transport-bg: rgba(244, 238, 225, 0.96); }

/* ── top bar: logo left, sign-in/stats/profile right ─────────────────────── */

.app-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
}
.app-top .brand { display: flex; align-items: center; gap: 0.65rem; text-decoration: none; color: inherit; }
.app-top .brand img { width: 40px; height: 40px; filter: drop-shadow(0 1px 2px rgba(31, 29, 26, 0.3)); }
.app-top .brand span {
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.35rem;
}
.app-top-right { display: flex; align-items: center; gap: 0.6rem; }

/* Dimmer: a small sun icon in the top-right cluster (not a permanent
   slider -- that pushed the header wider than the viewport on narrower
   screens) that opens a short slider in a popover, same pattern as the
   transport bar's other icon-triggered controls. Only shown at all while
   night is the *effective* theme. */
.dimmer-panel { width: 160px; }
.dimmer-panel input[type="range"] { width: 100%; }
.stats-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid var(--rule);
  background: none;
  color: var(--ink);
  border-radius: 999px;
  padding: 0.45rem 0.95rem;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}
.stats-btn:hover { border-color: var(--accent-soft); color: var(--accent); }
.stats-btn svg { width: 1rem; height: 1rem; fill: currentColor; }

/* ── shell: sidebar (desktop) / icon row (mobile) + main ─────────────────── */

.app-body { display: grid; grid-template-columns: 200px minmax(0, 1fr); max-width: 1200px; margin: 0 auto; }

.app-nav {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 1.5rem 1rem;
  align-self: start;
  position: sticky;
  top: 65px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  text-align: left;
  padding: 0.6rem 0.9rem;
  border-radius: 8px;
  background: none;
  border: 0;
  cursor: pointer;
  font: inherit;
  font-size: 0.95rem;
  color: var(--ink);
}
.nav-item svg { width: 1.1rem; height: 1.1rem; fill: currentColor; flex: none; }
.nav-item:hover { background: var(--paper-3); }
.nav-item.active { background: var(--paper-3); color: var(--accent); font-weight: 500; }
.nav-item .label { white-space: nowrap; }

.app-main { padding: 1.5rem 1.5rem 9rem; min-width: 0; }

@media (max-width: 860px) {
  .app-body { display: block; }
  .app-nav {
    flex-direction: row;
    position: sticky;
    top: 65px;
    z-index: 40;
    background: var(--paper);
    border-bottom: 1px solid var(--rule);
    padding: 0.6rem 1rem;
    gap: 0.4rem;
    overflow-x: auto;
  }
  .nav-item { flex: 0 0 auto; padding: 0.5rem 0.8rem; font-size: 0.85rem; }
  .nav-item .label { display: inline; }
  .app-main { padding: 1.25rem 1rem 9rem; }
}

.view[hidden] { display: none; }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.view-head h1 { margin: 0; font-size: clamp(1.5rem, 3vw, 2rem); }

/* ── library search ───────────────────────────────────────────────────────*/

.library-search {
  width: 100%;
  max-width: 420px;
  padding: 0.6rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: var(--paper-2);
  font: inherit;
  font-size: 0.92rem;
  margin-bottom: 1.5rem;
  color: var(--ink);
}

.cover {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 8px;
  background: var(--paper-3);
  display: block;
  margin-bottom: 0.6rem;
}
.shelf-card .cover + .t { margin-top: 0; }

.shelf-card { position: relative; }
.shelf-card > .popover { position: absolute; top: 0.6rem; right: 0.6rem; }
.shelf-card > .popover > .tbtn {
  background: var(--paper);
  box-shadow: var(--shadow);
  border-radius: 50%;
  width: 1.8rem;
  height: 1.8rem;
  justify-content: center;
  padding: 0;
}
.shelf-card > .icon-btn { margin-top: 0.5rem; align-self: flex-start; }

/* ── series ───────────────────────────────────────────────────────────────*/

.series-list { display: flex; flex-direction: column; gap: 2rem; }
.series-group h2 {
  font-size: 1.2rem;
  margin: 0 0 0.75rem;
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
}
.series-group h2 .count { font-family: var(--text); font-size: 0.78rem; color: var(--ink-soft); font-weight: 400; }
.series-books { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 1rem; }
.back-row { margin-bottom: 1rem; }
.back-row button { background: none; border: 0; color: var(--accent); font: inherit; cursor: pointer; padding: 0; }

/* ── collections ──────────────────────────────────────────────────────────*/

.collections-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.6rem; }
.collection-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.1rem;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  font: inherit;
  color: inherit;
}
.collection-row:hover { border-color: var(--accent-soft); }
.collection-row .count { color: var(--ink-soft); font-size: 0.85rem; }
.collection-row .auto-note { margin-left: 0.6rem; font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); }
.collections-empty { color: var(--ink-soft); padding: 1rem 0; list-style: none; }
.icon-btn {
  background: none;
  border: 0;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 0.3rem;
  border-radius: 6px;
  font: inherit;
  font-size: 0.85rem;
}
.icon-btn:hover { color: var(--accent); background: var(--paper-3); }
.add-to-collection { position: relative; }

/* ── tabs (book view: Chapters / Details) ─────────────────────────────────*/

.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--rule); margin-bottom: 1.1rem; }
.tab-btn {
  padding: 0.6rem 1.1rem;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  font: inherit;
  font-size: 0.95rem;
  color: var(--ink-soft);
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 500; }
.tab-panel[hidden] { display: none; }

.details-body { display: flex; gap: 1.5rem; flex-wrap: wrap; }
.details-body .cover { width: 180px; margin: 0; flex: none; }
.details-meta dl { display: grid; grid-template-columns: auto 1fr; gap: 0.3rem 1rem; margin: 0 0 1rem; font-size: 0.9rem; }
.details-meta dt { color: var(--ink-soft); }
.genre-tags { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.5rem 0; }
.genre-tag {
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
  font-size: 0.78rem;
  color: var(--ink-soft);
}

/* ── stats ─────────────────────────────────────────────────────────────── */

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.stat-tile { background: var(--paper-2); border: 1px solid var(--rule); border-radius: 12px; padding: 1rem 1.25rem; }
.stat-tile .n { font-family: var(--display); font-size: 1.9rem; font-weight: 600; line-height: 1.2; }
.stat-tile .l { color: var(--ink-soft); font-size: 0.8rem; }
.per-book-list { list-style: none; margin: 0 0 2rem; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.per-book-list li { display: flex; justify-content: space-between; padding: 0.55rem 0.9rem; background: var(--paper-2); border: 1px solid var(--rule); border-radius: 8px; font-size: 0.9rem; }
.daily-bars { display: flex; align-items: flex-end; gap: 3px; height: 70px; margin-bottom: 0.4rem; }
.daily-bar { flex: 1; background: var(--accent-soft); border-radius: 2px 2px 0 0; min-height: 2px; }
.daily-caption { color: var(--ink-soft); font-size: 0.78rem; }
.stats-signed-out { color: var(--ink-soft); }

/* ── extended transport ────────────────────────────────────────────────── */

.transport2 {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--transport-bg);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--rule);
  padding: 0.6rem 0 0.8rem;
  z-index: 50;
}
.transport2[hidden] { display: none; }
.transport2 .wrap { max-width: 1040px; margin: 0 auto; padding: 0 1.5rem; display: flex; flex-direction: column; gap: 0.4rem; }
.transport2 .now { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; font-size: 0.88rem; }
.transport2 .now .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.transport2 .now .time { color: var(--ink-soft); font-size: 0.78rem; font-variant-numeric: tabular-nums; flex: none; }
.transport2 .controls-row { display: flex; align-items: center; justify-content: center; gap: 0.3rem; flex-wrap: wrap; }
.transport2 .extra-row { display: flex; align-items: center; justify-content: center; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.15rem; }

.tbtn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border: 0;
  background: none;
  color: var(--ink-soft);
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}
.tbtn:hover { color: var(--accent); background: var(--paper-3); }
.tbtn svg { width: 1.05rem; height: 1.05rem; fill: currentColor; }
.tbtn.on { color: var(--accent); }
.tbtn.play {
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  justify-content: center;
}
.tbtn.play:hover { background: var(--accent-dark); color: #fff; }
.tbtn.play svg { width: 1.25rem; height: 1.25rem; }
.tbtn[disabled] { opacity: 0.35; cursor: not-allowed; }

.volume { display: flex; align-items: center; gap: 0.35rem; }
.volume input[type="range"] { width: 84px; accent-color: var(--accent); cursor: pointer; }

/* ── popovers (speed / sleep timer / bookmarks / settings) ────────────────*/

.popover { position: relative; display: inline-flex; }
.popover-panel {
  position: absolute;
  bottom: calc(100% + 12px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 1rem;
  min-width: 240px;
  max-width: min(320px, 90vw);
  z-index: 60;
  text-align: left;
  font-size: 0.88rem;
}
.popover-panel[hidden] { display: none; }
.popover-panel.below { bottom: auto; top: calc(100% + 8px); }
.popover-panel.align-right { left: auto; right: 0; transform: none; }
.popover-panel h3 { margin: 0 0 0.7rem; font-size: 0.95rem; font-family: var(--text); font-weight: 600; }
.popover-panel .field { margin-bottom: 0.75rem; }
.popover-panel label { display: block; margin-bottom: 0.3rem; color: var(--ink-soft); font-size: 0.8rem; }
.popover-panel input[type="number"],
.popover-panel input[type="text"] {
  width: 100%;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--rule);
  border-radius: 6px;
  font: inherit;
  background: var(--paper);
  color: var(--ink);
}

.rate-chips, .preset-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.5rem; }
.rate-chip, .preset-chip {
  border: 1px solid var(--rule);
  background: none;
  border-radius: 999px;
  padding: 0.3rem 0.7rem;
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  color: var(--ink-soft);
}
.rate-chip.active, .preset-chip.active { border-color: var(--accent); color: var(--accent); font-weight: 500; }
.checkbox-row { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.6rem; }
.checkbox-row label { margin: 0; color: var(--ink); font-size: 0.85rem; }

.sleep-status { color: var(--ink-soft); font-size: 0.82rem; margin: 0.4rem 0; }

.bookmark-list { list-style: none; margin: 0 0 0.6rem; padding: 0; max-height: 220px; overflow-y: auto; display: flex; flex-direction: column; gap: 0.3rem; }
.bookmark-row { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; padding: 0.4rem 0.5rem; border-radius: 8px; }
.bookmark-row:hover { background: var(--paper-3); }
.bookmark-row button.seek { background: none; border: 0; text-align: left; flex: 1; min-width: 0; font: inherit; cursor: pointer; color: inherit; }
.bookmark-row .ts { color: var(--accent); font-variant-numeric: tabular-nums; font-size: 0.8rem; margin-right: 0.5rem; }
.bookmark-row .note { color: var(--ink-soft); font-size: 0.82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bookmark-empty { color: var(--ink-soft); font-size: 0.85rem; }

/* ── sign-in / state ───────────────────────────────────────────────────── */

.app-state { max-width: 640px; margin: 0 auto; padding: 4rem 1.5rem; text-align: center; color: var(--ink-soft); }
.app-state h2 { color: var(--ink); font-size: 1.5rem; margin: 0 0 0.5rem; }

/* ── profile button + appearance settings ─────────────────────────────── */

.avatar-btn {
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.avatar-btn:hover { filter: brightness(0.92); }
.profile-email { display: block; color: var(--ink-soft); font-size: 0.82rem; margin-bottom: 0.75rem; word-break: break-all; }
.profile-panel hr { border: 0; border-top: 1px solid var(--rule); margin: 0.75rem 0; }
.profile-panel .btn { width: 100%; justify-content: center; }

/* ── theme palettes: Dark and Night (red), toggled via data-theme on the
   root element. Light is the default :root palette above, unchanged --
   these two only redefine the same custom properties at higher
   specificity, so every rule in this file and player.css that already
   reads var(--paper) etc. repaints automatically, no rule duplication
   needed. Scoped to this file (loaded only on /player), so /listen is
   untouched regardless of what theme a /player visitor has picked. */
:root[data-theme="dark"] {
  /* a reading lamp in a green study */
  --paper: #121915;
  --paper-2: #18221c;
  --paper-3: #213027;
  --card: #1b261f;
  --ink: #ece4d2;
  --ink-soft: #a9a08b;
  --accent: #d4b06a;
  --accent-dark: #b8954f;
  --accent-soft: #9c8146;
  --rule: rgba(236, 228, 210, 0.13);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 8px 24px rgba(0, 0, 0, 0.4);
  --transport-bg: rgba(18, 25, 21, 0.97);
}
/* Strictly R-only: every value here is rgb(R, 0, 0) (or that at some
   alpha) -- no green or blue component anywhere, on purpose. Different UI
   elements are told apart by *how much* red (a fraction of 255), never by
   a different hue -- that's also why the dimmer (a brightness() filter,
   applied in player-app.js) is the right tool for "darker": scaling a
   pure rgb(R,0,0) down keeps G and B at zero at every step, so it can
   never drift the theme off pure red the way mixing in a second color
   would. --accent stays the max, 100% red; everything else is a lower
   fraction of it. */
:root[data-theme="night"] {
  --paper: #000000;
  --paper-2: #0d0000;
  --paper-3: #1a0000;
  --ink: #ff0000;
  --ink-soft: #800000;
  --accent: #ff0000;
  --accent-soft: #b30000;
  --accent-dark: #b30000;
  --card: #0d0000;
  --rule: rgba(255, 0, 0, 0.25);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.6), 0 8px 24px rgba(0, 0, 0, 0.6);
  --transport-bg: rgba(0, 0, 0, 0.97);
}
:root[data-theme="dark"] .btn:hover,
:root[data-theme="dark"] .ctrl.play:hover,
:root[data-theme="dark"] .tbtn.play:hover,
:root[data-theme="night"] .btn:hover,
:root[data-theme="night"] .ctrl.play:hover,
:root[data-theme="night"] .tbtn.play:hover {
  background: var(--accent-soft);
}
/* Night mode drops every image -- including the brand mark -- to
   grayscale-then-red-tint so nothing breaks the red-only look. */
:root[data-theme="night"] img { filter: grayscale(1) sepia(1) saturate(6) hue-rotate(-50deg) brightness(0.6); }

/* Night mode's whole point is "nothing but shades of dim red" -- white
   button/avatar text is the one thing the palette swap above can't reach
   (it's a literal #fff, not a var()), so it gets its own override. Ghost
   buttons are excluded: they're transparent, so their --accent-colored
   text is already on-theme and switching it to black would make them
   unreadable against the near-black page background. */
:root[data-theme="night"] .btn:not(.ghost),
:root[data-theme="night"] .tbtn.play,
:root[data-theme="night"] .avatar-btn {
  color: #000;
}

/* Gold buttons on the dark theme want dark lettering, not cream. */
:root[data-theme="dark"] .btn:not(.ghost),
:root[data-theme="dark"] .tbtn.play,
:root[data-theme="dark"] .avatar-btn {
  color: #121915;
}

/* A brightness() filter on the root element, driven by the dimmer slider
   in the top bar -- scales every channel of the night palette down
   uniformly (a literal dimmer, not a second color), so "how dark" stays a
   user preference independent of the palette itself. Only ever set by JS
   while night mode is the active theme; transitions smoothly either way. */
html { transition: filter 0.15s ease; }

/* ── custom range input: scrub bar + volume, both themes ──────────────────
   accent-color alone leaves the *unfilled* portion of a native range input
   on the browser's own default (a light grey that reads as "white" against
   a near-black night theme) -- full custom track/thumb removes that
   dependency so both ends of the bar are always drawn from our own,
   already theme-aware, --rule/--accent tokens. */
.styled-range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 20px;
  background: transparent;
  cursor: pointer;
  outline: none;
}
.styled-range::-webkit-slider-runnable-track { height: 6px; border-radius: 999px; background: var(--rule); }
.styled-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -4px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  cursor: pointer;
}
.styled-range::-moz-range-track { height: 6px; border-radius: 999px; background: var(--rule); }
.styled-range::-moz-range-progress { height: 6px; border-radius: 999px 0 0 999px; background: var(--accent); }
.styled-range::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; border: none; background: var(--accent); cursor: pointer; }

.theme-chips { display: flex; gap: 0.4rem; margin-bottom: 0.6rem; }
.theme-chip {
  flex: 1;
  border: 1px solid var(--rule);
  background: none;
  border-radius: 8px;
  padding: 0.5rem 0.4rem;
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  color: var(--ink-soft);
  text-align: center;
}
.theme-chip.active { border-color: var(--accent); color: var(--accent); font-weight: 500; }

/* ── account badge + links in the profile popover ─────────────────────── */

.tier-badge {
  display: inline-block; font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase;
  padding: 0.12rem 0.55rem; border-radius: 999px; margin-bottom: 0.6rem;
  border: 1px solid var(--accent-soft); color: var(--accent-soft);
}
.tier-badge.reader { border-color: var(--rule); color: var(--ink-soft); }
.profile-link { display: block; color: var(--ink); text-decoration: none; padding: 0.25rem 0; }
.profile-link:hover { color: var(--accent); }
.app-top-right .btn { padding: 0.45rem 1rem; font-size: 0.88rem; }
@media (max-width: 560px) {
  .app-top { padding: 0.8rem 1rem; }
  .app-top .brand span { display: none; }
  #join-btn { display: none; }
}

.flag-when { font-variant-numeric: tabular-nums; color: var(--accent); font-size: 0.9rem; margin: 0 0 0.4rem; }
.flag-help { color: var(--ink-soft); font-size: 0.85rem; margin: 0 0 0.6rem; max-width: 18rem; }
.flag-result { font-size: 0.85rem; margin: 0.5rem 0 0; min-height: 1em; }
