/* audiobooks — every value here is a token in DESIGN.md. */
@font-face { font-family: "Literata"; font-style: normal; font-weight: 400 700; font-display: swap;
  src: url(/fonts/literata-latin.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Literata"; font-style: normal; font-weight: 400 700; font-display: swap;
  src: url(/fonts/literata-latin-ext.woff2) format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: "Instrument Sans"; font-style: normal; font-weight: 400 700; font-display: swap;
  src: url(/fonts/instrument-sans-latin.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Instrument Sans"; font-style: normal; font-weight: 400 700; font-display: swap;
  src: url(/fonts/instrument-sans-latin-ext.woff2) format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }

:root {
  --bg: #ffffff; --fg: #16181d; --muted: #5b6270; --line: #e3e5ea; --card: #f3f4f6; --chip: #e9ebef;
  --accent: #17695e; --danger: #b3261e;
  --serif: "Literata", Georgia, serif;
  --sans: "Instrument Sans", "Helvetica Neue", Arial, sans-serif;
  --ease: cubic-bezier(.2,.7,.2,1); --t: 180ms;
  --mini-h: 64px;
  --fresh: color-mix(in srgb, var(--fg) 22%, var(--card));
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111317; --fg: #eceef2; --muted: #9aa1ad; --line: #2a2e36; --card: #1b1e24; --chip: #23272e;
    --accent: #6cc9b6; --danger: #f2726a; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111317; --fg: #eceef2; --muted: #9aa1ad; --line: #2a2e36; --card: #1b1e24; --chip: #23272e;
  --accent: #6cc9b6; --danger: #f2726a; color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 400 1rem/1.5 var(--sans); -webkit-tap-highlight-color: transparent; }
body[data-player="1"] { padding-bottom: calc(var(--mini-h) + env(safe-area-inset-bottom)); }
a { color: var(--fg); text-underline-offset: 0.18em; text-decoration-thickness: 1px; }
img { display: block; max-width: 100%; }
button { font: inherit; color: inherit; }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
@media (prefers-reduced-motion: reduce) { :root { --t: 0ms; } }

/* ------------------------------------------------------------- header */
.top { display: flex; align-items: center; gap: 0.75rem; padding: 0.5rem 1rem; padding-top: max(0.5rem, env(safe-area-inset-top)); max-width: 68rem; margin: 0 auto; }
.wordmark { font-family: var(--serif); font-weight: 600; font-size: 1.375rem; letter-spacing: -0.01em; text-decoration: none; flex: none; line-height: 44px; }
.wordmark b { font-weight: 600; color: var(--accent); }
.top-search { flex: 1; display: flex; align-items: center; min-width: 0; margin-left: auto; max-width: 22rem; position: relative; }
.top-search input { width: 100%; min-width: 0; height: 40px; border: 1px solid var(--line); background: var(--card); color: var(--fg); border-radius: 8px; padding: 0 44px 0 0.75rem; font: 400 1rem var(--sans); }
.top-search input::placeholder { color: var(--muted); }
.top-search .ctl { position: absolute; right: 0; top: 50%; transform: translateY(-50%); }
input:focus-visible, button:focus-visible, a:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

main { max-width: 68rem; margin: 0 auto; padding: 0 1rem 2rem; }

/* ------------------------------------------------------------- controls */
.ctl { display: inline-grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 0; background: transparent; border-radius: 50%; cursor: pointer; color: var(--fg); flex: none; touch-action: manipulation; }
.ctl:active { background: var(--chip); }
.ctl-48 { width: 48px; height: 48px; }
.ctl-56 { width: 56px; height: 56px; }
.ctl-72 { width: 72px; height: 72px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; min-height: 44px; padding: 0 1rem; border: 1px solid var(--line); background: var(--bg); color: var(--fg); border-radius: 8px; font: 600 0.875rem var(--sans); text-decoration: none; cursor: pointer; touch-action: manipulation; }
.btn:active { background: var(--chip); }
.btn-primary, .btn-play { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.btn-primary:active, .btn-play:active { opacity: 0.85; background: var(--fg); }
/* One glyph at a time: play unless this control's book is playing. */
.i-pause { display: none; }
.is-playing > .i-play, [data-state="playing"] .js-toggle > .i-play { display: none; }
.is-playing > .i-pause, [data-state="playing"] .js-toggle > .i-pause { display: block; }

/* ------------------------------------------------------------- headings */
.page-head { padding: 1rem 0 0.5rem; }
.page-h { font: 600 1.75rem/1.2 var(--serif); letter-spacing: -0.01em; margin: 1rem 0 0.5rem; text-wrap: balance; }
.lede { color: var(--muted); margin: 0 0 1rem; max-width: 40rem; }
.sec-h { font: 650 1.375rem/1.25 var(--sans); letter-spacing: -0.01em; margin: 2rem 0 0.75rem; }
.intro { padding-top: 0.5rem; }
.more { margin: 0.75rem 0 0; font-size: 0.875rem; }
.empty { color: var(--muted); }

/* ------------------------------------------------------------- cover grid */
.grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.5rem 1rem; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 900px) { .grid { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
@media (min-width: 1200px) { .grid { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
.cv-a { display: block; text-decoration: none; }
.cv-art { display: block; aspect-ratio: 1; background: var(--card); border-radius: 4px; overflow: hidden; position: relative; }
.cv-art img { width: 100%; height: 100%; object-fit: cover; }
.cv-t { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font: 500 1.0625rem/1.3 var(--serif); margin-top: 0.5rem; overflow-wrap: anywhere; }
.cv-by { display: block; font-size: 0.875rem; color: var(--muted); margin-top: 0.25rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cv-len { margin-top: 0; font-variant-numeric: tabular-nums; }
.cv-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgb(0 0 0 / 0.35); }
.cv-bar > span { display: block; height: 100%; background: var(--accent); }
.cv-meta { display: flex; align-items: center; margin-top: 0.25rem; font-size: 0.75rem; color: var(--muted); min-width: 0; }
.cv-meta .fresh { flex: none; }
.cv-ch { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cv-x { margin-left: auto; }

/* ------------------------------------------------------------- lists of links */
.links { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr; }
@media (min-width: 560px) { .links { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 1.5rem; } }
@media (min-width: 900px) { .links { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.links li { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; border-bottom: 1px solid var(--line); min-height: 48px; }
.links a { flex: 1; min-width: 0; padding: 0.75rem 0; text-decoration: none; overflow-wrap: anywhere; }
.links .n { color: var(--muted); font-size: 0.75rem; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------- book page */
.book-head { display: grid; grid-template-columns: 1fr; gap: 1rem; padding-top: 1rem; }
.book-art { width: 60%; max-width: 240px; height: auto; aspect-ratio: 1; object-fit: cover; border-radius: 4px; background: var(--card); }
@media (min-width: 720px) { .book-head { grid-template-columns: 240px 1fr; gap: 2rem; } .book-art { width: 240px; } }
.book-t { font: 600 1.75rem/1.2 var(--serif); letter-spacing: -0.01em; margin: 0; text-wrap: balance; overflow-wrap: anywhere; }
.book-by { margin: 0.5rem 0 1rem; font-size: 1rem; }
.btn-play { min-height: 52px; padding: 0 1.5rem; font-size: 1rem; width: 100%; max-width: 22rem; }
.btn-play svg { width: 22px; height: 22px; }
.book-progress { margin: 0.5rem 0 0; font-size: 0.875rem; color: var(--muted); }
.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem 1rem; margin: 1.5rem 0 0; max-width: 28rem; }
.facts div { min-width: 0; }
.facts dt { font-size: 0.75rem; color: var(--muted); }
.facts dd { margin: 0; font-size: 0.875rem; overflow-wrap: anywhere; }
.desc { font: 400 1rem/1.6 var(--serif); max-width: 40rem; margin-top: 1.5rem; overflow-wrap: anywhere; }
.desc p { margin: 0 0 0.75rem; }
.src { font-size: 0.875rem; color: var(--muted); margin-top: 1.5rem; }
.src a { color: var(--muted); }

.chapters { list-style: none; margin: 0; padding: 0; max-width: 48rem; }
.chr { position: relative; border-bottom: 1px solid var(--line); }
.chr-b { display: grid; grid-template-columns: 2.25rem 1fr auto; align-items: center; gap: 0.5rem; width: 100%; min-height: 56px; padding: 0.5rem 0.25rem 0.5rem 0; border: 0; background: transparent; text-align: left; cursor: pointer; border-radius: 8px; touch-action: manipulation; }
.chr-b:active { background: var(--card); }
.chr-n { font-size: 0.75rem; color: var(--muted); font-variant-numeric: tabular-nums; text-align: center; }
.chr-text { min-width: 0; }
.chr-t { display: block; font: 400 1rem/1.35 var(--serif); overflow-wrap: anywhere; }
.chr-r { display: block; font-size: 0.75rem; color: var(--muted); margin-top: 0.25rem; }
.chr-d { font-size: 0.75rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.chr-p { position: absolute; left: 0; bottom: -1px; height: 2px; width: calc(var(--p, 0) * 100%); background: var(--accent); }
.chr.is-now::before { content: ""; position: absolute; left: -0.5rem; top: 0.5rem; bottom: 0.5rem; width: 3px; border-radius: 4px; background: var(--accent); }
.chr.is-now .chr-n { color: var(--accent); font-weight: 650; }
.chr.is-done .chr-t { color: var(--muted); }

/* ------------------------------------------------------------- pager, prose, forms */
.pager { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: 2rem 0 0; }
.pager-at { font-size: 0.875rem; color: var(--muted); }
.prose { max-width: 40rem; padding-top: 0.5rem; }
.prose p { line-height: 1.6; }
.prose code { font-size: 0.875rem; overflow-wrap: anywhere; }
.big-search { display: flex; gap: 0.5rem; margin: 0.5rem 0 1rem; max-width: 32rem; }
.big-search input { flex: 1; min-width: 0; height: 44px; border: 1px solid var(--line); background: var(--card); color: var(--fg); border-radius: 8px; padding: 0 0.75rem; font: 400 1rem var(--sans); }
.fb { display: grid; gap: 1rem; }
.fb-l { display: grid; gap: 0.25rem; font-size: 0.875rem; font-weight: 600; }
.fb-l .hint { font-weight: 400; color: var(--muted); }
.fb select, .fb textarea, .fb input { font: 400 1rem var(--sans); color: var(--fg); background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 0.5rem 0.75rem; min-height: 44px; width: 100%; }
.fb .btn { justify-self: start; }
.hp { position: absolute; left: -9999px; }
.err { color: var(--danger); font-weight: 600; }
.life { font-variant-numeric: tabular-nums; }

/* external links say so (baseline §12) */
a[target="_blank"] .ext { display: inline-block; width: 0.75em; height: 0.75em; margin-left: 0.2em; vertical-align: -0.05em; background: currentColor;
  -webkit-mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 12 12"><path d="M5 2H2v8h8V7M7 1h4v4M11 1 5.5 6.5" fill="none" stroke="black" stroke-width="1.4"/></svg>') center/contain no-repeat;
          mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 12 12"><path d="M5 2H2v8h8V7M7 1h4v4M11 1 5.5 6.5" fill="none" stroke="black" stroke-width="1.4"/></svg>') center/contain no-repeat; }

/* ------------------------------------------------------------- footer */
.foot { max-width: 68rem; margin: 2rem auto 0; padding: 1.5rem 1rem 2rem; border-top: 1px solid var(--line); font-size: 0.875rem; color: var(--muted); }
.foot p { margin: 0 0 0.75rem; max-width: 40rem; }
.foot-nav { display: flex; flex-wrap: wrap; gap: 0 1.5rem; }
.foot-nav a { color: var(--muted); display: inline-block; padding: 0.75rem 0; }

/* ------------------------------------------------------------- freshbar (house draining tag) */
button.fresh { display: inline-block; font: inherit; font-size: 0.75rem; line-height: 1.35; color: var(--fg); border: 0; border-radius: 4px;
  margin: -1px 0.5rem -1px 0; padding: 1px 6px; min-width: var(--fresh-w, 6.2em); text-align: left; font-variant-numeric: tabular-nums; cursor: help; vertical-align: baseline;
  background: linear-gradient(to right, var(--fresh) calc(var(--l, 0) * 25%), var(--chip) 0); box-shadow: inset 0 0 0 1px var(--line); position: relative; }
button.fresh::before { content: ""; position: absolute; inset: -12px -4px; }
.fresh-legend { color: var(--muted); font-size: 0.75rem; margin: -0.25rem 0 0.75rem; }
.fresh-pop { max-width: min(340px, calc(100vw - 32px)); border: 1px solid var(--line); border-radius: 8px; padding: 1rem; background: var(--bg); color: var(--fg); font-size: 0.875rem; }
.fresh-pop p { margin: 0.5rem 0 0.75rem; color: var(--muted); }
.fresh-pop::backdrop { background: rgb(0 0 0 / 0.25); }

/* ------------------------------------------------------------- player */
.player[hidden] { display: none; }
.mini { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; align-items: center; gap: 0.25rem; height: calc(var(--mini-h) + env(safe-area-inset-bottom)); padding: 0 0.5rem env(safe-area-inset-bottom) 0.5rem; background: var(--card); border-top: 1px solid var(--line); }
.mini-open { flex: 1; min-width: 0; display: flex; align-items: center; gap: 0.75rem; height: 100%; padding: 0 0.25rem; border: 0; background: transparent; text-align: left; cursor: pointer; }
.mini-open img { width: 44px; height: 44px; border-radius: 4px; object-fit: cover; background: var(--chip); flex: none; }
.mini-text { min-width: 0; display: grid; }
.mini-t { font: 500 0.875rem/1.3 var(--serif); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-s { font-size: 0.75rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player[data-state="error"] .mini-s, .status.is-err { color: var(--danger); }
.mini-bar { position: absolute; left: 0; right: 0; top: -1px; height: 2px; background: transparent; }
.mini-bar > span { display: block; height: 100%; width: 0; background: var(--accent); }
.player[data-state="loading"] .js-toggle { opacity: 0.6; }

.sheet { position: fixed; inset: 0; z-index: 30; background: var(--bg); display: flex; flex-direction: column; align-items: center; padding: max(0.5rem, env(safe-area-inset-top)) 1rem max(1.5rem, env(safe-area-inset-bottom));
  border-radius: 16px 16px 0 0; transform: translateY(100%); visibility: hidden; transition: transform var(--t) var(--ease), visibility 0s linear var(--t); overflow-y: auto; overscroll-behavior: contain; }
.player[data-open] .sheet { transform: none; visibility: visible; transition: transform var(--t) var(--ease); }
.sheet-top { display: flex; align-items: center; justify-content: space-between; width: 100%; max-width: 28rem; }
.sheet-book { font-size: 0.875rem; font-weight: 600; padding: 0.75rem; }
.sheet-art { width: min(78vw, 320px, 42vh); height: auto; aspect-ratio: 1; object-fit: cover; border-radius: 4px; background: var(--card); margin: 1rem 0 1.5rem; }
.sheet-t { font: 600 1.375rem/1.25 var(--serif); margin: 0; text-align: center; max-width: 28rem; overflow-wrap: anywhere; }
.sheet-s { font-size: 0.875rem; color: var(--muted); margin: 0.5rem 0 0; text-align: center; max-width: 28rem; }
.seek { width: 100%; max-width: 28rem; margin-top: 1.5rem; }
.seek input { width: 100%; margin: 0; height: 44px; background: transparent; -webkit-appearance: none; appearance: none; cursor: pointer; }
.seek input::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: linear-gradient(to right, var(--accent) var(--pct, 0%), var(--line) 0); }
.seek input::-moz-range-track { height: 4px; border-radius: 4px; background: linear-gradient(to right, var(--accent) var(--pct, 0%), var(--line) 0); }
.seek input::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: var(--accent); margin-top: -6px; border: 0; }
.seek input::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: var(--accent); border: 0; }
.seek-times { display: flex; justify-content: space-between; font-size: 0.75rem; color: var(--muted); font-variant-numeric: tabular-nums; margin-top: -0.25rem; }
.transport { display: flex; align-items: center; justify-content: center; gap: 0.5rem; margin-top: 1rem; }
.play-big { background: var(--fg); color: var(--bg); }
.play-big:active { background: var(--fg); opacity: 0.85; }
.play-big svg { width: 32px; height: 32px; }
.sheet-row { display: flex; gap: 0.75rem; margin-top: 1.5rem; }
.sheet-row .btn { font-variant-numeric: tabular-nums; min-width: 6rem; }
.sheet-row .btn.is-on { border-color: var(--accent); color: var(--accent); }
@media (min-width: 900px) {
  .sheet { inset: auto 1rem calc(var(--mini-h) + 0.5rem) auto; width: 26rem; max-height: calc(100vh - var(--mini-h) - 1.5rem); border-radius: 16px 16px 0 0; box-shadow: 0 8px 40px rgb(0 0 0 / 0.18); border: 1px solid var(--line); }
}
[data-state="loading"] .js-toggle > .i-play { display: none; }
[data-state="loading"] .js-toggle > .i-pause { display: block; }
