/* chorusreader.app — shared stylesheet for the library, papers, listening and voice pages.
   Palette and type are the app's own (ChorusTheme, "Reading by Firelight"); see .impeccable.md. */
@font-face { font-family: 'Fraunces'; src: url('/fonts/fraunces-latin-standard-normal.woff2') format('woff2'); font-weight: 100 900; font-style: normal; font-display: swap; }
@font-face { font-family: 'JetBrains Mono'; src: url('/fonts/jetbrains-mono-latin-wght-normal.woff2') format('woff2'); font-weight: 100 800; font-style: normal; font-display: swap; }

:root {
  --bg: #1A1614; --surface: #2A2520; --surface-2: #3A332D;
  --text: #F5E6D3; --text-2: #A69888; --text-3: #9C8C76; --text-4: #6B5F52;
  --rule: #38322C; --rule-strong: #52483E;
  --accent: #D4A574; --accent-hot: #E8B888; --accent-tint: rgba(212, 165, 116, 0.22);
  --wood-hi: #996E47; --wood: #664224; --wood-dark: #382617;
  --serif: 'Fraunces', 'Iowan Old Style', 'Palatino', Georgia, serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --max: 1180px; --gutter: clamp(20px, 5vw, 56px); --header-h: 60px;
  --ease-out: cubic-bezier(.16, 1, .3, 1);
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; scroll-padding-top: calc(var(--header-h) + 16px); }
body { background: var(--bg); color: var(--text); font-family: var(--serif); font-optical-sizing: auto; font-size: clamp(17px, 1vw + 12px, 19px); line-height: 1.55; overflow-x: hidden; }
::selection { background: var(--accent-tint); }
img, svg { max-width: 100%; height: auto; display: block; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
a { color: inherit; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 0.16em; text-decoration-color: var(--rule-strong); }
a:hover { text-decoration-color: var(--accent); color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
h1, h2, h3 { font-weight: 500; letter-spacing: -0.012em; text-wrap: balance; }
p { text-wrap: pretty; }
.mono { font-family: var(--mono); font-size: 0.78rem; font-weight: 500; letter-spacing: 0.01em; font-variant-numeric: tabular-nums; }
.wrap { max-width: var(--max); margin-inline: auto; padding-inline: var(--gutter); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* ── Header ── */
.top { position: sticky; top: 0; z-index: 20; background: var(--bg); border-bottom: 1px solid var(--rule); }
.top-inner { max-width: none; height: var(--header-h); display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: clamp(12px, 2vw, 28px); }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 500; font-size: 1.05rem; white-space: nowrap; }
.brand:hover { color: var(--text); }
.brand img { width: 28px; height: 28px; border-radius: 6px; }
.transport { display: flex; align-items: center; gap: 12px; min-width: 0; padding-left: clamp(12px, 2vw, 28px); border-left: 1px solid var(--rule); height: 100%; }
.transport.idle { visibility: hidden; }
.tp-btn { flex: 0 0 auto; width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--accent); color: var(--accent); display: grid; place-items: center; transition: background .15s, color .15s; }
.tp-btn:hover { background: var(--accent); color: var(--bg); }
.tp-btn svg { width: 12px; height: 12px; fill: currentColor; }
.tp-btn .i-pause, .tp-btn.is-playing .i-play { display: none; }
.tp-btn.is-playing .i-pause { display: block; }
.tp-time { color: var(--text-3); flex: 0 0 auto; }
.tp-phrase { min-width: 0; flex: 1 1 auto; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.is-speaking .tp-phrase { color: var(--accent); }
.toc { display: flex; gap: clamp(12px, 1.4vw, 20px); align-items: center; }
.toc a { text-decoration: none; color: var(--text-2); font-size: 0.9rem; white-space: nowrap; padding-block: 4px; border-bottom: 1px solid transparent; }
.toc a:hover { color: var(--text); border-bottom-color: var(--text-3); }
.toc a[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); }
.cta { text-decoration: none; background: var(--accent); color: var(--bg); padding: 9px 14px; border-radius: 3px; font-size: 0.95rem; font-weight: 500; white-space: nowrap; transition: background .15s; }
.cta:hover { background: var(--accent-hot); color: var(--bg); }
.toc-toggle { display: none; font-family: var(--mono); font-size: 0.78rem; color: var(--text-2); padding: 8px 4px; }
.toc-toggle::before { content: '\2261'; margin-right: 6px; font-size: 1rem; line-height: 1; }
.toc-toggle[aria-expanded="true"]::before { content: '\00D7'; }
@media (max-width: 1023px) {
  .toc-toggle { display: inline-block; }
  .toc { display: none; position: absolute; left: 0; right: 0; top: 100%; background: var(--bg); border-bottom: 1px solid var(--rule); padding: 8px var(--gutter) 16px; flex-direction: column; align-items: flex-start; gap: 2px; }
  .toc.open { display: flex; }
  .toc a { font-size: 1.15rem; padding-block: 8px; width: 100%; border-bottom: 1px solid var(--rule); }
  .toc a:last-child { border-bottom-color: transparent; }
}
@media (max-width: 640px) { .tp-phrase { display: none; } .brand span { display: none; } }
@media (max-width: 420px) { .tp-time { display: none; } .cta { padding: 8px 10px; font-size: 0.9rem; } }

/* ── Page head: breadcrumbs + title ── */
.crumbs { display: flex; flex-wrap: wrap; gap: 6px 10px; color: var(--text-3); padding-top: clamp(20px, 3vw, 32px); }
.crumbs a { text-decoration: none; color: var(--text-3); }
.crumbs a:hover { color: var(--accent); }
.crumbs li { list-style: none; display: flex; gap: 10px; }
.crumbs li + li::before { content: '/'; color: var(--text-4); }
.lead { padding-block: clamp(28px, 5vw, 64px) clamp(28px, 4vw, 48px); border-bottom: 1px solid var(--rule); }
.lead h1 { font-size: clamp(2.1rem, 4vw, 3.4rem); line-height: 1.06; font-weight: 400; max-width: 24ch; margin-bottom: 0.45em; }
.lead .sub { font-size: 1.12em; color: var(--text-2); max-width: 58ch; line-height: 1.5; }
.lead .sub + .sub { margin-top: 0.8em; }
.lead .facts { margin-top: 1.4em; color: var(--text-3); }
.lead .facts b { color: var(--text); font-weight: 500; }

/* ── Chapters (marginalia) ── */
.ch { border-top: 1px solid var(--rule); padding-block: clamp(44px, 7vw, 96px); display: grid; grid-template-columns: 9.5rem minmax(0, 1fr); column-gap: clamp(24px, 4vw, 64px); }
.ch:first-of-type { border-top: 0; }
.ch-mark { position: sticky; top: calc(var(--header-h) + 28px); align-self: start; display: flex; flex-direction: column; gap: 4px; }
.ch-num { color: var(--accent); }
.ch-name { color: var(--text-3); }
.ch-body { min-width: 0; }
.ch h2 { font-size: clamp(1.7rem, 3.2vw, 2.6rem); line-height: 1.1; max-width: 24ch; margin-bottom: 0.45em; }
.ch .sub { font-size: 1.06em; color: var(--text-2); max-width: 58ch; line-height: 1.5; }
.prose { max-width: 62ch; }
.prose p { color: var(--text-2); }
.prose p + p, .prose ul + p, .prose p + ul { margin-top: 1em; }
.prose h2 { font-size: 1.5rem; margin-top: 1.8em; margin-bottom: 0.5em; }
.prose h2:first-child { margin-top: 0; }
.prose ul { padding-left: 1.2em; color: var(--text-2); }
.prose li + li { margin-top: 0.35em; }
.prose strong { color: var(--text); font-weight: 500; }
.more { margin-top: clamp(20px, 3vw, 32px); }
.more a { color: var(--accent); text-decoration-color: transparent; }
.more a:hover { text-decoration-color: var(--accent); }
@media (max-width: 900px) { .ch { grid-template-columns: minmax(0, 1fr); row-gap: 20px; } .ch-mark { position: static; flex-direction: row; gap: 12px; } }

/* ── Covers and shelves ── */
.cover { display: block; aspect-ratio: 2 / 3; width: 100%; background: var(--surface); overflow: hidden; border-radius: 2px; box-shadow: 0 1px 0 rgba(0,0,0,.35), inset 0 0 0 1px rgba(255,255,255,.04); position: relative; }
.cover img { width: 100%; height: 100%; object-fit: cover; }
.cover-type { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 8% 9%; color: rgba(255,255,255,.95); }
.cover-type::before, .cover-type::after { content: ''; position: absolute; left: 9%; right: 9%; height: 1px; background: rgba(255,255,255,.22); }
.cover-type::before { top: 7%; }
.cover-type::after { bottom: 7%; }
.cover-type b { font-weight: 600; font-size: clamp(0.72rem, 1.1vw, 0.95rem); line-height: 1.2; letter-spacing: 0.06em; text-transform: uppercase; display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
.cover-type i { display: block; width: 18%; height: 1px; background: rgba(255,255,255,.22); margin: 9% 0; }
.cover-type small { font-family: var(--mono); font-weight: 500; font-size: clamp(0.5rem, 0.7vw, 0.6rem); letter-spacing: 0.12em; text-transform: uppercase; color: rgba(255,255,255,.62); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.grid-books { display: grid; grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); gap: clamp(18px, 3vw, 32px) clamp(14px, 2vw, 24px); margin-top: clamp(22px, 3vw, 36px); list-style: none; }
.tile { display: block; text-decoration: none; }
.tile:hover { color: var(--text); }
.tile:hover .cover { box-shadow: 0 0 0 1px var(--accent); }
.tile .t { display: block; margin-top: 10px; font-size: 0.95rem; line-height: 1.25; font-weight: 500; }
.tile .a { display: block; color: var(--text-3); font-size: 0.8rem; margin-top: 3px; }
.tile .m { display: block; color: var(--text-4); margin-top: 4px; }
.shelf-block { margin-top: clamp(36px, 5vw, 56px); }
.shelf-block:first-child { margin-top: clamp(22px, 3vw, 36px); }
.shelf-block h3 { font-size: 1.45rem; }
.shelf-block .sub { color: var(--text-2); margin-top: 4px; }
.shelf-rail { height: 10px; margin-top: 18px; border-radius: 1px; background: linear-gradient(to bottom, var(--wood-hi), var(--wood) 42%, var(--wood-dark)); box-shadow: 0 2px 0 var(--wood-dark); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; list-style: none; }
.chips a { display: inline-block; text-decoration: none; font-family: var(--mono); font-size: 0.78rem; font-weight: 500; padding: 6px 10px; border: 1px solid var(--rule-strong); border-radius: 3px; color: var(--text-2); }
.chips a:hover { border-color: var(--accent); color: var(--accent); }
.chips .n { color: var(--text-4); margin-left: 6px; }
.cols { columns: 3 16rem; column-gap: clamp(24px, 4vw, 48px); margin-top: 18px; list-style: none; }
.cols li { break-inside: avoid; padding: 7px 0; border-bottom: 1px solid var(--rule); display: flex; justify-content: space-between; gap: 12px; }
.cols a { text-decoration: none; color: var(--text-2); }
.cols a:hover { color: var(--accent); }
.cols .n { color: var(--text-4); }

/* ── Book page ── */
.book-hero { display: grid; grid-template-columns: minmax(150px, 220px) minmax(0, 1fr); gap: clamp(24px, 4vw, 56px); padding-block: clamp(28px, 5vw, 64px) clamp(28px, 4vw, 48px); border-bottom: 1px solid var(--rule); align-items: start; }
.book-hero h1 { font-size: clamp(2rem, 3.8vw, 3.2rem); line-height: 1.06; font-weight: 400; margin-bottom: 0.3em; }
.byline { font-size: 1.15rem; color: var(--text-2); }
.byline a { text-decoration-color: transparent; }
.byline a:hover { text-decoration-color: var(--accent); }
.book-hero .blurb { margin-top: 1.1em; font-size: 1.12em; line-height: 1.5; max-width: 54ch; }
.book-hero .desc { margin-top: 1em; color: var(--text-2); max-width: 60ch; }
.book-hero .subjects { margin-top: 1.2em; }
.spec { border-top: 1px solid var(--rule-strong); margin-top: clamp(22px, 3vw, 32px); max-width: 44rem; }
.spec div { display: grid; grid-template-columns: 9.5rem minmax(0, 1fr); gap: 16px; padding: 11px 0; border-bottom: 1px solid var(--rule); }
.spec dt { color: var(--text-3); }
.spec dd { color: var(--text); }
.spec dd small { color: var(--text-3); }
@media (max-width: 640px) { .book-hero { grid-template-columns: minmax(0, 1fr); } .book-hero .cover { max-width: 180px; } .spec div { grid-template-columns: minmax(0, 1fr); gap: 4px; } }
.get { margin-top: clamp(24px, 4vw, 40px); display: flex; flex-wrap: wrap; align-items: center; gap: 16px 24px; }
.btn { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; background: var(--accent); color: var(--bg); padding: 13px 20px; border-radius: 3px; font-size: 1rem; font-weight: 500; transition: background .15s; }
.btn:hover { background: var(--accent-hot); color: var(--bg); }
.btn svg { width: 16px; height: 16px; fill: currentColor; }
.get .how { color: var(--text-3); max-width: 40ch; font-size: 0.95em; }

/* ── Passages and clips ── */
.passage-q { font-size: clamp(1.2rem, 1.9vw, 1.6rem); line-height: 1.4; font-weight: 400; letter-spacing: -0.005em; max-width: 46ch; white-space: pre-line; margin-top: clamp(18px, 3vw, 28px); color: var(--text); border-left: 2px solid var(--rule-strong); padding-left: clamp(16px, 2vw, 28px); }
.passage-q.verse { white-space: pre-line; }
.source { margin-top: 14px; color: var(--text-3); }
.source a { color: var(--text-2); }
.clips { list-style: none; margin-top: clamp(18px, 3vw, 28px); border-top: 1px solid var(--rule-strong); max-width: 46rem; }
.clip { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; align-items: center; column-gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--rule); position: relative; }
.clip-play { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--accent); color: var(--accent); display: grid; place-items: center; transition: background .15s, color .15s; }
.clip-play:hover, .clip.is-playing .clip-play { background: var(--accent); color: var(--bg); }
.clip-play svg { width: 12px; height: 12px; fill: currentColor; }
.clip-play .i-pause, .clip.is-playing .clip-play .i-play { display: none; }
.clip.is-playing .clip-play .i-pause { display: block; }
.clip-text { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.clip-name { font-size: 1.08rem; font-weight: 500; line-height: 1.2; }
.clip-name .eng { color: var(--text-3); font-weight: 400; }
.clip-name .eng::before { content: ' · '; color: var(--text-4); }
.clip-sub { color: var(--text-3); }
.clip-time { color: var(--text-3); }
.clip-bar { position: absolute; left: 54px; right: 0; bottom: -1px; height: 1px; background: var(--accent); transform-origin: left; transform: scaleX(0); }
.clip.is-playing { color: var(--accent); }
.clip.errored .clip-sub::after { content: ' · didn’t load'; color: var(--text-2); }
.clip-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); column-gap: clamp(20px, 3vw, 40px); margin-top: clamp(18px, 3vw, 28px); list-style: none; border-top: 1px solid var(--rule-strong); max-width: none; }
.clip-grid .clip { grid-template-columns: 36px minmax(0, 1fr) auto; }
.clip-grid .clip-play { width: 36px; height: 36px; }
.clip-grid .clip-bar { left: 50px; }
.trio { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: clamp(16px, 3vw, 40px); margin-top: clamp(22px, 3vw, 36px); }
.trio .clips { margin-top: 0; max-width: none; }
.trio h3 { font-size: 1.25rem; margin-bottom: 6px; }
.trio .tag { color: var(--text-3); margin-bottom: 10px; }
@media (max-width: 760px) { .trio { grid-template-columns: minmax(0, 1fr); } }
.note { margin-top: 18px; color: var(--text-3); max-width: 60ch; font-size: 0.95em; }

/* ── Papers ── */
.paper { padding: clamp(18px, 3vw, 28px) 0; border-top: 1px solid var(--rule); }
.paper:first-of-type { border-top: 1px solid var(--rule-strong); margin-top: clamp(20px, 3vw, 32px); }
.paper h3 { font-size: 1.3rem; line-height: 1.25; max-width: 40ch; }
.paper h3 a { text-decoration-color: transparent; }
.paper h3 a:hover { text-decoration-color: var(--accent); }
.paper .authors { color: var(--text-2); margin-top: 6px; }
.paper .why { list-style: none; display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; color: var(--text-3); }
.paper .why li::before { content: '·'; color: var(--accent); margin-right: 8px; }
.paper details { margin-top: 12px; max-width: 66ch; }
.paper summary { cursor: pointer; color: var(--text-2); font-family: var(--mono); font-size: 0.78rem; font-weight: 500; letter-spacing: 0.01em; }
.paper summary:hover { color: var(--accent); }
.paper details p { margin-top: 10px; color: var(--text-2); }
.paper .links { margin-top: 12px; display: flex; gap: 18px; flex-wrap: wrap; }
.paper .links a { color: var(--text-2); }

/* ── Voice directory ── */
.voice-group { margin-top: clamp(26px, 4vw, 40px); }
.voice-group h3 { font-size: 1.3rem; }
.voice-group .sub { color: var(--text-3); margin-top: 2px; }

/* ── Coda + footer ── */
.coda { border-top: 1px solid var(--rule); padding-block: clamp(56px, 9vw, 120px); display: grid; grid-template-columns: 9.5rem minmax(0, 1fr); column-gap: clamp(24px, 4vw, 64px); }
.coda h2 { font-size: clamp(2.1rem, 4.5vw, 3.6rem); line-height: 1.02; font-weight: 400; margin-bottom: 0.4em; max-width: 20ch; }
.coda p { color: var(--text-2); margin-bottom: 1.6em; max-width: 52ch; }
.badge { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; background: var(--text); color: var(--bg); padding: 10px 16px 10px 13px; border-radius: 6px; transition: background .15s; }
.badge:hover { background: var(--accent-hot); color: var(--bg); }
.badge svg { width: 24px; height: 24px; fill: currentColor; }
.badge-text { display: flex; flex-direction: column; line-height: 1.1; }
.badge-text small { font-size: 0.7rem; font-family: var(--mono); font-weight: 500; opacity: .8; }
.badge-text strong { font-size: 1.25rem; font-weight: 500; }
.coda .mac { display: block; margin-top: 16px; color: var(--text-3); }
@media (max-width: 900px) { .coda { grid-template-columns: minmax(0, 1fr); } .coda .ch-mark { position: static; flex-direction: row; gap: 12px; margin-bottom: 20px; } }
.foot { border-top: 1px solid var(--rule); padding-block: 28px 40px; display: flex; flex-wrap: wrap; gap: 12px 32px; align-items: baseline; justify-content: space-between; color: var(--text-3); }
.foot ul { list-style: none; display: flex; flex-wrap: wrap; gap: 12px 20px; }
.foot a { color: var(--text-2); text-decoration: none; }
.foot a:hover { color: var(--accent); }
.colophon { width: 100%; font-size: 0.72rem; }

/* ── Support form ── */
.form { max-width: 40rem; margin-top: 8px; }
.form label { display: block; margin-top: 1.2em; margin-bottom: 0.35em; color: var(--text-2); }
.form input, .form select, .form textarea { width: 100%; padding: 11px 12px; background: var(--surface); color: var(--text); border: 1px solid var(--rule-strong); border-radius: 3px; font: inherit; font-size: 1rem; }
.form input:focus, .form select:focus, .form textarea:focus { border-color: var(--accent); outline: none; }
.form textarea { min-height: 140px; resize: vertical; }
.form button { margin-top: 1.4em; }

@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } * { transition: none !important; } }
