/* Books (books.js) and listening (listen.js): square covers, a book's page, authors and series,
   the mini-player at the foot of every page and the full player. Colours come from the theme's
   tokens (style.css), so every theme and the light scheme draw them. */

/* ---------- Covers and cards ---------- */
.book-card.poster .art, .book-tile .art { aspect-ratio: 1 / 1; }
.grid.book-grid, .grid.book-tiles { grid-template-columns: repeat(auto-fill, minmax(calc(10.5rem * var(--card-scale, 1)), 1fr)); }
.row.posters:has(> .book-card) { grid-auto-columns: calc(clamp(9rem, 15vw, 11.5rem) * var(--card-scale, 1)); }
.book-card .badge { left: 0.4rem; right: auto; }
.book-views { margin: -0.25rem 0 1rem; }

/* An author's or a series' tile: up to three covers fanned out. */
.book-fan { position: absolute; inset: 0; display: grid; place-items: center; background: linear-gradient(160deg, var(--raised), var(--surface)); }
.book-fan img { position: absolute; width: 58%; aspect-ratio: 1; object-fit: cover; border-radius: 0.4rem; box-shadow: 0 6px 18px rgb(0 0 0 / 0.35); }
.book-fan.fan-1 img { width: 70%; }
.book-fan.fan-2 img:nth-child(1) { transform: translateX(-16%) rotate(-5deg); }
.book-fan.fan-2 img:nth-child(2) { transform: translateX(16%) rotate(5deg); }
.book-fan.fan-3 img:nth-child(1) { transform: translateX(-24%) rotate(-8deg) scale(0.88); }
.book-fan.fan-3 img:nth-child(2) { transform: translateX(24%) rotate(8deg) scale(0.88); }
.book-fan.fan-3 img:nth-child(3) { z-index: 1; }
.author-tile .art { border-radius: 50%; }
.author-initials { position: absolute; inset: 0; display: grid; place-items: center; background: var(--raised); color: var(--muted);
  font: var(--title-weight, 600) 2.4rem/1 var(--font-display); }

/* ---------- A book's page ---------- */
.book-hero { overflow: hidden; }
.book-hero .hero-bg { background-size: cover; background-position: center; filter: blur(52px) saturate(1.3); transform: scale(1.3); opacity: 0.5; }
.book-hero .hero-inner > .art { aspect-ratio: 1 / 1; }
.book-hero .hero-inner { padding-bottom: 0.5rem; }
.book-hero .book-kicker { margin: 0 0 -0.5rem; color: var(--muted); }
.book-hero .book-kicker a, .book-people a { color: inherit; text-decoration: none; }
.book-hero .book-kicker a:hover, .book-people a:hover { text-decoration: underline; text-underline-offset: 3px; }
.book-people { margin: -0.25rem 0 0; color: var(--text); }
.book-subtitle { margin: 0 0 0.75rem; color: var(--muted); font-style: italic; }
.book-fold > summary { cursor: pointer; list-style: none; width: fit-content; }
.book-fold > summary::-webkit-details-marker { display: none; }
.book-fold > summary h2 { display: inline; margin: 0; font-size: 1.45rem; }
.book-fold > summary::after { content: ""; display: inline-block; width: 0.55rem; height: 0.55rem; margin-left: 0.6rem; border: solid currentColor; border-width: 0 2px 2px 0; transform: translateY(-0.25rem) rotate(45deg); opacity: 0.7; }
.book-fold[open] > summary::after { transform: translateY(0) rotate(225deg); }
.book-chapters { list-style: none; margin: 0.9rem 0 0; padding: 0; display: grid; gap: 0.15rem; max-width: 46rem; }
.book-chapter { display: grid; grid-template-columns: 3.2rem minmax(0, 1fr) auto; align-items: center; gap: 0.75rem; width: 100%; padding: 0.55rem 0.75rem;
  border: 0; border-radius: var(--radius); background: transparent; color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.book-chapter:hover { background: color-mix(in srgb, var(--text) 6%, transparent); }
.book-chapter:focus-visible { outline: 2px solid var(--ring); outline-offset: 1px; }
.bc-n { color: var(--muted); font-variant-numeric: tabular-nums; }
.bc-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bc-time { font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.book-facts { max-width: 40rem; }
.book-narrated { margin-top: 2.25rem; }
.series-head .series-covers { position: relative; width: 11rem; aspect-ratio: 1; border-radius: var(--radius); overflow: hidden; }
.book-match { width: min(44rem, calc(100vw - 2rem)); }
.match-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.35rem; max-height: 50vh; overflow-y: auto; }
.match-choice { display: grid; gap: 0.15rem; width: 100%; padding: 0.65rem 0.8rem; border: 1px solid color-mix(in srgb, var(--line) 60%, transparent);
  border-radius: var(--radius); background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.match-choice:hover, .match-choice:focus-visible { background: color-mix(in srgb, var(--text) 7%, transparent); }
.match-source { color: var(--accent); }
@media (max-width: 640px) {
  .series-head .series-covers { width: 8rem; }
  .book-chapter { grid-template-columns: 2.4rem minmax(0, 1fr) auto; padding-inline: 0.4rem; }
}

/* ---------- The mini-player ---------- */
:root { --listen-h: 4.25rem; }
.listen-bar:not([hidden]) { position: fixed; left: 0.75rem; right: 0.75rem; bottom: calc(var(--tabs, 0px) + 0.75rem); z-index: 28;
  display: flex; align-items: center; gap: 0.75rem; height: var(--listen-h); padding: 0 0.5rem 0 0.5rem; box-sizing: border-box;
  border-radius: var(--radius-lg); background: color-mix(in srgb, var(--container) 94%, transparent); color: var(--on-container);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--line) 50%, transparent), 0 12px 32px rgb(0 0 0 / 0.35);
  backdrop-filter: blur(14px); overflow: hidden; }
/* Not over the video player, nor the sign-in screen. */
body:has(> #player:not([hidden])) > .listen-bar, body:has(> #auth:not([hidden])) > .listen-bar { display: none; }
body.listening > #page { padding-bottom: calc(3rem + var(--listen-h) + 1rem); }
body.listening > .toasts { bottom: calc(var(--tabs, 0px) + var(--listen-h) + 1.75rem); }
.lb-progress { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: color-mix(in srgb, var(--text) 12%, transparent); }
.lb-progress span { display: block; height: 100%; background: var(--accent); }
.lb-open { display: flex; align-items: center; gap: 0.75rem; flex: 1 1 auto; min-width: 0; height: 100%; padding: 0 0.25rem; border: 0; background: none; color: inherit;
  font: inherit; text-align: left; cursor: pointer; border-radius: var(--radius); }
.lb-open:focus-visible { outline: 2px solid var(--ring); outline-offset: -2px; }
.lb-cover { flex: none; width: 3.1rem; height: 3.1rem; border-radius: 0.45rem; object-fit: cover; background: var(--raised); }
.lb-text { display: grid; min-width: 0; }
.lb-title, .lb-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-title { font-weight: 600; }
.lb-sub { color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.lb-controls { display: flex; align-items: center; gap: 0.25rem; flex: none; }
.lb-btn, .lf-btn { display: grid; place-items: center; width: 2.75rem; height: 2.75rem; padding: 0; border: 0; border-radius: 50%; background: transparent; color: inherit; cursor: pointer; }
.lb-btn svg, .lf-btn svg { width: 1.5rem; height: 1.5rem; fill: currentColor; }
.lb-btn:hover, .lf-btn:hover { background: color-mix(in srgb, var(--text) 10%, transparent); }
.lb-btn:focus-visible, .lf-btn:focus-visible { outline: 2px solid var(--ring); outline-offset: 1px; }
.lb-play { background: var(--accent); color: var(--on-accent); }
.lb-play:hover { background: color-mix(in srgb, var(--accent) 88%, var(--text)); }
.lb-stop svg { width: 1.25rem; height: 1.25rem; }
@media (min-width: 900px) {
  .listen-bar:not([hidden]) { left: 50%; right: auto; width: min(44rem, calc(100vw - 2rem)); transform: translateX(-50%); }
}
@media (max-width: 480px) {
  .lb-skip:first-child { display: none; }
  .listen-bar:not([hidden]) { left: 0.5rem; right: 0.5rem; bottom: calc(var(--tabs, 0px) + 0.5rem); gap: 0.4rem; }
}

/* ---------- The full player ---------- */
dialog.modal.listen-full { width: min(58rem, calc(100vw - 2rem)); padding: 1rem 1.5rem 1.75rem; }
.lf-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 0.5rem; }
.lf-head svg { width: 1.2rem; height: 1.2rem; }
.lf-main { display: grid; grid-template-columns: minmax(10rem, 20rem) minmax(0, 1fr); gap: 2rem; align-items: center; }
.lf-main[hidden], .lf-panel[hidden] { display: none; }
.lf-art { aspect-ratio: 1; border-radius: var(--radius); overflow: hidden; background: var(--raised); box-shadow: 0 12px 34px rgb(0 0 0 / 0.35); }
.lf-cover { width: 100%; height: 100%; object-fit: cover; display: block; }
.lf-info { display: grid; gap: 0.6rem; min-width: 0; }
.lf-title { margin: 0; font-size: clamp(1.4rem, 3vw, 2rem); line-height: 1.15; }
.lf-people, .lf-chapter, .lf-book-left { margin: 0; }
.lf-chapter { font-weight: 600; min-height: 1.5em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lf-timeline { display: grid; gap: 0.2rem; }
.lf-range { width: 100%; accent-color: var(--accent); margin: 0; }
.lf-times { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.lf-book-left { font-size: 0.9rem; }
.lf-controls { display: flex; align-items: center; justify-content: center; gap: 0.5rem; margin: 0.4rem 0; }
.lf-btn { width: 3.25rem; height: 3.25rem; }
.lf-btn svg { width: 1.75rem; height: 1.75rem; }
.lf-play { width: 4.25rem; height: 4.25rem; background: var(--accent); color: var(--on-accent); }
.lf-play svg { width: 2.1rem; height: 2.1rem; }
.lf-play:hover { background: color-mix(in srgb, var(--accent) 88%, var(--text)); }
.lf-pills { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.5rem; }
.lf-pill { display: inline-flex; align-items: center; gap: 0.45rem; min-height: 2.5rem; padding: 0 1rem; border: 0; border-radius: var(--control-radius, 1.25rem);
  background: var(--tonal); color: var(--on-tonal); font: 600 0.9rem/1 var(--font-body); cursor: pointer; font-variant-numeric: tabular-nums; }
.lf-pill svg { width: 1.2rem; height: 1.2rem; fill: currentColor; }
.lf-pill.on { background: var(--accent); color: var(--on-accent); }
.lf-pill:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.lf-panel { display: grid; gap: 0.75rem; min-height: 18rem; align-content: start; }
.lf-panel-head { display: flex; align-items: center; gap: 1rem; }
.lf-panel-head h3 { margin: 0; font-size: 1.2rem; }
.lf-panel-head svg { width: 1.2rem; height: 1.2rem; transform: rotate(90deg); }
.lf-choices { display: grid; grid-template-columns: repeat(auto-fill, minmax(7rem, 1fr)); gap: 0.5rem; }
.lf-choice { min-height: 2.75rem; border: 1px solid color-mix(in srgb, var(--line) 70%, transparent); border-radius: var(--radius); background: transparent; color: inherit;
  font: 600 0.95rem/1 var(--font-body); cursor: pointer; font-variant-numeric: tabular-nums; }
.lf-choice:hover { background: color-mix(in srgb, var(--text) 7%, transparent); }
.lf-choice.on { background: var(--tonal); color: var(--on-tonal); border-color: var(--tonal); }
.lf-choice:focus-visible, .lf-row:focus-visible { outline: 2px solid var(--ring); outline-offset: 1px; }
.lf-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.15rem; max-height: min(60vh, 32rem); overflow-y: auto; }
.lf-row { display: flex; justify-content: space-between; gap: 1rem; width: 100%; padding: 0.6rem 0.75rem; border: 0; border-radius: var(--radius); background: transparent;
  color: inherit; font: inherit; text-align: left; cursor: pointer; font-variant-numeric: tabular-nums; }
.lf-row:hover { background: color-mix(in srgb, var(--text) 7%, transparent); }
.lf-row.on { background: var(--tonal); color: var(--on-tonal); }
.lf-row.on .muted { color: inherit; opacity: 0.8; }
.lf-row-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lf-marks { display: grid; gap: 0.75rem; justify-items: start; align-content: start; }
.lf-marks .lf-list { width: 100%; }
.lf-mark { display: flex; align-items: center; gap: 0.35rem; }
.lf-mark .lf-row { flex: 1; min-width: 0; }
@media (max-width: 640px) {
  dialog.modal.listen-full { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; padding: 0.75rem 1rem 1.25rem; }
  .lf-main { grid-template-columns: minmax(0, 1fr); gap: 1.1rem; justify-items: stretch; }
  .lf-art { width: min(72vw, 20rem); justify-self: center; }
  .lf-btn { width: 2.9rem; height: 2.9rem; }
}

/* ---------- App passwords (Your settings) ---------- */
.app-password-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; max-width: 40rem; }
.app-password { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 0.75rem 1rem; border-radius: var(--radius);
  background: color-mix(in srgb, var(--text) 5%, transparent); }
.app-password p { margin: 0.15rem 0 0; }
.app-password-made { margin-top: 1rem; max-width: 40rem; }
.app-password-made p { margin: 0.25rem 0; }
.app-password-line { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; }
.app-password-code { font: 600 1.25rem/1.3 ui-monospace, "Cascadia Mono", Consolas, monospace; letter-spacing: 0.04em; user-select: all; }

/* ---------- On a TV ---------- */
html.tv .listen-bar:not([hidden]) { bottom: var(--safe-y, 1.5rem); left: 50%; right: auto; width: min(46rem, 80vw); transform: translateX(-50%); }
html.tv :is(.lb-btn, .lf-btn, .lb-open, .lf-pill, .lf-choice, .lf-row, .book-chapter):focus { outline: var(--ring-w, 3px) solid var(--ring); outline-offset: 0.15rem; }
html.tv .lf-pill:focus, html.tv .lf-choice:focus, html.tv .lf-row:focus, html.tv .book-chapter:focus { background: var(--text); color: var(--bg); }
html.tv dialog.modal.listen-full { width: min(64rem, 88vw); }

/* ---------- Reading (reader.html has the reader itself) ---------- */
/* The same book in another library: its audiobook, or its ebook. */
.book-editions { margin: 0 0 0.75rem; }
.book-editions a { color: var(--accent); }
/* A book to read, on a TV, says where it can be read. */
.book-tv-note { margin: 0.25rem 0 0; }
a.play-main, a.play-over { text-decoration: none; }
