/* The browser edition, in the site's look: the same tokens as index.html. Phone width first. */
:root {
  --bg: #faf6ef; --card: #ffffff; --ink: #2b2620; --muted: #6f665a; --on-accent: #2b2620;
  --accent: #f08c3a; --accent-ink: #b35c14; --line: #e7dfd2; --ok: #3d8b57; --err: #b3442e;
  --accent-soft: rgba(240, 140, 58, .16);
  --bar: 9.2rem;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17150f; --card: #201d16; --ink: #efe8dc; --muted: #9a9184; --on-accent: #2b2620;
    --accent: #f08c3a; --accent-ink: #f5a763; --line: #363126; --ok: #6cc08c; --err: #e07a63;
    --accent-soft: rgba(240, 140, 58, .22);
  }
}
/* A chosen theme (theme.js sets data-theme) outranks the device setting above. */
:root[data-theme="light"] {
  --bg: #faf6ef; --card: #ffffff; --ink: #2b2620; --muted: #6f665a; --on-accent: #2b2620;
  --accent: #f08c3a; --accent-ink: #b35c14; --line: #e7dfd2; --ok: #3d8b57; --err: #b3442e;
  --accent-soft: rgba(240, 140, 58, .16);
}
:root[data-theme="sepia"] {
  --bg: #f1e7d0; --card: #faf3e3; --ink: #3b3127; --muted: #6b5f4e; --on-accent: #2b2620;
  --accent: #f08c3a; --accent-ink: #9e4f0f; --line: #e0d3b8; --ok: #3d7f52; --err: #a8402c;
  --accent-soft: rgba(240, 140, 58, .2);
}
:root[data-theme="dark"] {
  --bg: #17150f; --card: #201d16; --ink: #efe8dc; --muted: #9a9184; --on-accent: #2b2620;
  --accent: #f08c3a; --accent-ink: #f5a763; --line: #363126; --ok: #6cc08c; --err: #e07a63;
  --accent-soft: rgba(240, 140, 58, .22);
}
* { box-sizing: border-box; margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 system-ui, "Segoe UI", sans-serif; padding: 1.2rem 16px 3rem; overflow-x: hidden; }
body.reading { padding-bottom: calc(var(--bar) + 1.5rem + env(safe-area-inset-bottom, 0px)); }
.wrap { max-width: 880px; margin: 0 auto; }
header { display: flex; align-items: center; gap: .9rem; margin-bottom: 1.2rem; }
header svg { flex: none; display: block; }
header h1 { font-size: 1.5rem; letter-spacing: .01em; }
header p { color: var(--muted); font-size: .92rem; }
/* The theme switch: Auto, Light, Sepia, Dark; the pressed one is filled. Sits at the header's end
   and drops to its own line when the title needs the width; headers without one are untouched. */
header:has(.theme-switch) { flex-wrap: wrap; }
header:has(.theme-switch) > div:not(.theme-switch) { flex: 1 1 0; min-width: 50%; }
.theme-switch { flex: none; margin-left: auto; display: inline-flex; gap: 2px; padding: 2px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); }
.theme-switch button { background: transparent; color: var(--muted); border: 0; border-radius: 999px; padding: .25rem .6rem; font: inherit; font-size: .8rem; font-weight: 500; line-height: 1.3; }
.theme-switch button[aria-pressed="true"] { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
.theme-switch button:hover { color: var(--ink); }
/* Small pill groups, like the theme switch: the Text row's font and size. */
.pills { display: inline-flex; align-items: center; gap: 2px; padding: 2px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); }
.pills button { background: transparent; color: var(--muted); border: 0; border-radius: 999px; padding: .2rem .6rem; font: inherit; font-size: .85rem; font-weight: 500; line-height: 1.3; }
.pills button[aria-pressed="true"] { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
.pills button:not(:disabled):hover { color: var(--ink); filter: none; }
.pills button:disabled { opacity: .4; }
.pills .val { padding: .2rem .3rem; font-size: .85rem; color: var(--ink); min-width: 5.2rem; text-align: center; }
a { color: var(--accent-ink); }
a.plain, a.logo { color: inherit; text-decoration: none; }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, .drop:focus-visible, .seg:focus-visible { outline: 2px solid var(--accent-ink); outline-offset: 2px; border-radius: 4px; }
/* The file input is hidden under its label; the label shows the ring for it. */
.drop label.btn:focus-within { outline: 2px solid var(--accent-ink); outline-offset: 2px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 1.1rem 1.2rem; margin-bottom: 1rem; }
h2 { font-size: 1.1rem; margin-bottom: .6rem; }
p + p { margin-top: .6rem; }
button, .btn { display: inline-block; background: var(--accent); border: 1px solid transparent; color: var(--on-accent); font: inherit; font-weight: 600; border-radius: 8px; padding: .45rem .9rem; cursor: pointer; text-decoration: none; line-height: 1.4; transition: background-color .15s ease, border-color .15s ease, color .15s ease, filter .15s ease, transform .1s ease; }
button.ghost, .btn.ghost { background: transparent; color: var(--accent-ink); border-color: var(--line); font-weight: 500; }
button:disabled { opacity: .5; cursor: default; }
/* Hover and press answer within the 50 to 150 ms people read as immediate. */
button:not(:disabled):hover, .btn:hover { filter: brightness(1.06); }
button.ghost:not(:disabled):hover, .btn.ghost:hover { border-color: var(--accent); filter: none; }
button:not(:disabled):active, .btn:active { transform: translateY(1px); }
.btns { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin-top: .9rem; }
.btns + .hint { margin-top: .6rem; }
.hint, .muted { color: var(--muted); font-size: .85rem; }
.muted { font-size: .92rem; }
.status { color: var(--muted); font-size: .9rem; min-height: 1.4em; margin-top: .5rem; }
.status.err, .err { color: var(--err); }
.status.ok { color: var(--ok); }
.status.warn { color: var(--ink); }
[hidden] { display: none !important; }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Library */
/* The promise strip: what this page does, in one glance, before anything else. */
.promise { list-style: none; padding: 0; margin: 0 0 1rem; display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: .5rem .7rem; }
.promise li { display: flex; gap: .55rem; align-items: flex-start; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: .6rem .75rem; font-size: .9rem; line-height: 1.4; }
.promise svg { flex: none; width: 20px; height: 20px; margin-top: .1rem; color: var(--accent-ink); }
.promise strong { color: var(--ink); }
/* The trust lines: three facts, each a bar in the accent colour. */
.trust-lines { list-style: none; padding: 0; margin: 0 0 .6rem; display: grid; gap: .5rem; }
.trust-lines li { padding-left: .8rem; border-left: 3px solid var(--accent); }
.notice { border-left: 3px solid var(--accent); }
.drop { border: 2px dashed var(--line); border-radius: 12px; padding: 1rem 1rem .8rem; text-align: center; color: var(--muted); transition: border-color .15s, background .15s; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }
.drop p { margin: 0; }
.drop .hint { margin-top: .5rem; }
.drop label.btn { margin-left: .2rem; cursor: pointer; position: relative; }
.drop input[type=file] { position: absolute; width: 1px; height: 1px; opacity: 0; left: 0; top: 0; }
/* The second door: a box for pasted text or one web address, under the drop zone. */
.paste { margin-top: .8rem; }
.paste textarea { display: block; box-sizing: border-box; width: 100%; min-height: 3rem; resize: vertical; background: transparent; color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: .5rem .7rem; font: inherit; font-size: 16px; line-height: 1.4; }
.paste textarea::placeholder { color: var(--muted); }
.paste .btns { margin-top: .5rem; }
/* Each book is its own card: a cover on the left drawn like a book, the title in a serif, the
   author under it, and one small-caps line of facts. The section around them is flat. */
.card.books-section { background: transparent; border: 0; padding: 0; }
.card.books-section h2 { margin-bottom: .7rem; }
.book { display: grid; grid-template-columns: auto 1fr auto; gap: .6rem 1.1rem; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: .9rem 1.1rem; margin-bottom: .75rem; box-shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 24px rgba(0, 0, 0, .05); }
.book .cover { width: 64px; height: 96px; border-radius: 3px 7px 7px 3px; overflow: hidden; background: var(--line); box-shadow: 2px 3px 10px rgba(0, 0, 0, .22), inset 4px 0 6px -4px rgba(0, 0, 0, .45); }
.book .cover img { display: block; width: 100%; height: 100%; object-fit: cover; }
.book .cover.generated { display: flex; flex-direction: column; justify-content: center; gap: .3rem; padding: .45rem .4rem; background: linear-gradient(160deg, hsl(var(--hue) 34% 46%), hsl(var(--hue) 36% 30%)); color: #fff; text-align: center; }
.book .cover .ct { font-family: Georgia, "Times New Roman", serif; font-size: .6rem; line-height: 1.15; font-weight: 600; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.book .cover .ca { font-size: .48rem; letter-spacing: .06em; text-transform: uppercase; opacity: .85; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book .info { min-width: 0; }
.book .title { font-family: Georgia, "Times New Roman", serif; font-size: 1.35rem; line-height: 1.2; font-weight: 600; overflow-wrap: anywhere; }
.book .by { font-family: Georgia, "Times New Roman", serif; color: var(--muted); font-size: 1rem; margin-top: .15rem; }
/* The file's name as it is on disk, so it is kept as typed: no small caps, a plain face, wrapped anywhere. */
.book .file { font-family: ui-monospace, "Cascadia Mono", Consolas, "Liberation Mono", Menlo, monospace; font-size: .8rem; color: var(--muted); margin-top: .35rem; overflow-wrap: anywhere; }
.book .meta { color: var(--muted); font-size: .74rem; letter-spacing: .09em; text-transform: uppercase; margin-top: .4rem; }
.book .acts { display: flex; gap: .5rem; flex-wrap: wrap; }
@media (max-width: 520px) {
  .book { grid-template-columns: auto 1fr; padding: .8rem .9rem; }
  .book .acts { grid-column: 1 / -1; }
  .book .title { font-size: 1.15rem; }
}

/* Reader */
.crumbs { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .9rem; margin-bottom: .8rem; }
.meta-card h2 { font-size: 1.25rem; margin-bottom: .1rem; overflow-wrap: anywhere; }
.meta-card .row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin-top: .7rem; font-size: .9rem; color: var(--muted); }
.meta-card .row select { flex: 1 1 200px; }
/* Fields are 16px: smaller text makes iOS WebKit zoom the page on focus and not back. */
select { background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: .4rem .5rem; font: inherit; font-size: 16px; max-width: 100%; min-width: 0; }
.strip { font-size: .88rem; color: var(--muted); border-left: 3px solid var(--accent); padding: .35rem .8rem; margin-bottom: 1rem; }
.strip.ok { border-left-color: var(--ok); }
.strip.warn { color: var(--ink); }
.strip.err { border-left-color: var(--err); color: var(--err); }
/* The book's text: the size and the font are the reader's (the Text row sets --text-size and
   data-font); the measure stays near seventy characters, where long lines stop being skipped. */
.transcript { font-size: var(--text-size, 1.05rem); line-height: 1.7; max-width: 72ch; }
.transcript[data-font="serif"] { font-family: Georgia, "Times New Roman", serif; }
.transcript p { margin: 0 0 .9rem; }
.transcript p:last-child { margin-bottom: 0; }
.transcript h3 { font-size: 1.07em; margin: 1.1rem 0 .5rem; }
.transcript h3:first-child { margin-top: 0; }
.seg { border-radius: 4px; padding: .05rem .15rem; margin: 0 -.15rem; cursor: pointer; transition: background .2s, color .2s, opacity .2s; }
.seg.heard { color: var(--ink); opacity: .8; }
.seg.ahead { color: var(--muted); } /* dimmed by colour alone: muted on the card stays above 4.5:1 in both schemes */
.seg.current { background: var(--accent-soft); color: var(--ink); opacity: 1; }
.transcript p.figure .seg { font-style: italic; }
.transcript + .hint { margin-top: .9rem; border-top: 1px solid var(--line); padding-top: .6rem; }

/* Player bar, pinned */
.bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; background: var(--card); border-top: 1px solid var(--line); padding: .6rem 16px calc(.6rem + env(safe-area-inset-bottom, 0px)); }
.bar-inner { max-width: 880px; margin: 0 auto; display: grid; gap: .5rem; }
.bar-row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.bar-row.main { justify-content: center; flex-wrap: nowrap; gap: .4rem; }
/* Five buttons and their gaps fit a 320 px screen inside the 16 px gutters. */
.bar .play { min-width: 6.2rem; }
.bar .step { min-width: 2.4rem; padding: .4rem .5rem; font-size: 1.15rem; line-height: 1.3; }
.bar label { display: flex; align-items: center; gap: .35rem; font-size: .85rem; color: var(--muted); }
.pos { margin-left: auto; font-size: .85rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.bar .own-voice { padding: .3rem .7rem; font-size: .85rem; text-decoration: none; }
/* Who speaks what, one line under the selects; the bar's height allows for it. */
.voices { font-size: .8rem; color: var(--muted); }
/* What is sounding: five bars that follow the audio leaving the player, and the voice it is in
   (app.js). Wide screens keep it at the left of the controls; narrower ones give it a line of
   its own, reserved while idle so the bar's height holds still. */
.aloud { display: flex; align-items: center; gap: .55rem; font-size: .85rem; color: var(--muted); margin: 0; visibility: hidden; }
.aloud.on { visibility: visible; }
.aloud .levels { display: inline-flex; align-items: flex-end; gap: 2px; height: 14px; }
.aloud .levels i { display: block; width: 3px; height: 14px; border-radius: 1.5px; background: var(--accent); transform-origin: bottom; transform: scaleY(.5); transition: transform .06s linear; }
@media (min-width: 700px) {
  .bar-inner { position: relative; }
  .aloud { position: absolute; left: 0; top: .7rem; }
}
@media (max-width: 699.98px) {
  .aloud { justify-content: center; height: 1.1rem; }
  :root { --bar: 10.8rem; }
}
@media (max-width: 520px) {
  .pos { width: 100%; margin-left: 0; text-align: center; }
  :root { --bar: 12.8rem; }
}

/* Ask */
.ask-form { position: relative; display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
input[type=text] { flex: 1 1 220px; min-width: 0; background: transparent; color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: .5rem .7rem; font: inherit; font-size: 16px; }
/* Enter's submit target, kept out of sight but in the box: a test can still click it. */
.submit-proxy { position: absolute; left: 0; top: 0; width: 1px; height: 1px; padding: 0; border: 0; opacity: 0; overflow: hidden; }
#speak-btn { min-width: 8.6rem; } /* the longest label, so the box does not jump as the label changes */
.ask-card .heard-as { margin-top: .4rem; }
.clips { margin-top: .9rem; border-top: 1px solid var(--line); padding-top: .7rem; }
.clips .check { display: flex; gap: .5rem; align-items: center; font-size: .9rem; cursor: pointer; }
.clips .check input { width: 1rem; height: 1rem; margin: 0; accent-color: var(--accent); }
.ask-card .clips .hint { margin-top: .4rem; }
.clips-row { margin-top: .5rem; }
/* A folded section: its summary reads as a heading; what it holds appears when opened. */
.more > summary { cursor: pointer; font-weight: 600; }
.more > summary h2 { display: inline; font-size: 1.05rem; margin: 0; }
.more > summary .hint { font-weight: 400; }
.more[open] > summary { margin-bottom: .6rem; }
.ask-card .more { margin-top: .9rem; border-top: 1px solid var(--line); padding-top: .7rem; }
.ask-card .more > summary + .clips { margin-top: .2rem; border-top: 0; padding-top: 0; }
/* The settings that were in the bar: chosen once and kept, so they sit with the other settings. */
.settings { margin-top: .3rem; }
.settings-row { display: flex; gap: .5rem .9rem; align-items: center; flex-wrap: wrap; }
.settings-row label { display: flex; align-items: center; gap: .35rem; font-size: .85rem; color: var(--muted); }
.settings .voices { margin-top: .5rem; }
.describe { display: flex; gap: .5rem; align-items: center; font-size: .9rem; cursor: pointer; margin-top: .9rem; }
.describe input { width: 1rem; height: 1rem; margin: 0; accent-color: var(--accent); }
.meter { height: 6px; background: var(--line); border-radius: 3px; margin-top: .7rem; overflow: hidden; }
.meter div { height: 100%; width: 0; background: var(--accent); transition: width .08s linear; }
#answer { margin-top: .4rem; font-size: 1.02rem; white-space: pre-wrap; }
#answer.uncovered { color: var(--accent-ink); }
#answer.err { color: var(--err); }
.after { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-top: .7rem; }
.ask-card .hint { margin-top: .7rem; }
/* Bookmarks and notes */
.note-form { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.notes-card .hint { margin-top: .6rem; }
.notes { list-style: none; padding: 0; margin: .8rem 0 0; }
.notes li { display: flex; gap: .6rem; align-items: flex-start; padding: .55rem 0; border-top: 1px solid var(--line); }
.notes .entry { flex: 1 1 200px; min-width: 0; }
.notes .spot { display: block; width: 100%; background: none; border: 0; padding: 0; color: var(--ink); font: inherit; text-align: left; cursor: pointer; }
.notes .spot:hover, .notes .spot:focus-visible { text-decoration: underline; }
.notes .where { color: var(--muted); font-size: .85rem; }
.notes .memo { display: block; margin-top: .2rem; color: var(--accent-ink); }
.study-row { margin-top: .9rem; border-top: 1px solid var(--line); padding-top: .8rem; }
.revisit-row { margin-top: .9rem; border-top: 1px solid var(--line); padding-top: .8rem; }
.revisit-row .hint { flex: 1 1 200px; }
.study-list { list-style: none; padding: 0; margin: .6rem 0 0; }
.study-list li { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; padding: .5rem 0; border-top: 1px solid var(--line); }
.study-list .what { flex: 1 1 220px; min-width: 0; }
.notes-card .status { margin-top: .4rem; }
footer { color: var(--muted); font-size: .85rem; text-align: center; margin-top: 1.6rem; }
/* State feedback for the ask loop: the card's data-state follows the status line (app.js).
   Listening pulses a ring from the one button, thinking spins a small ring before the status,
   speaking breathes a mark, and an answer fades in. Each lasts under a second per cycle. */
.ask-card[data-state="listening"] #speak-btn { animation: ring 1.3s ease-out infinite; }
@keyframes ring { 0% { box-shadow: 0 0 0 0 rgba(240, 140, 58, .55); } 100% { box-shadow: 0 0 0 14px rgba(240, 140, 58, 0); } }
.ask-card[data-state="thinking"] #ask-status::before { content: ''; display: inline-block; width: .75em; height: .75em; margin-right: .45em; vertical-align: -.08em; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.ask-card[data-state="speaking"] #ask-status::before { content: '\25CF'; color: var(--accent); margin-right: .4em; animation: breathe 1s ease-in-out infinite alternate; }
@keyframes breathe { from { opacity: 1; } to { opacity: .25; } }
#answer:not(:empty) { animation: fadein .2s ease-out; }
@keyframes fadein { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  .seg, .drop, .meter div, .aloud .levels i, button, .btn { transition: none; }
  .ask-card[data-state] #speak-btn, .ask-card[data-state] #ask-status::before, #answer:not(:empty) { animation: none; }
  .ask-card[data-state="listening"] #speak-btn { box-shadow: 0 0 0 3px rgba(240, 140, 58, .45); } /* a still ring still says listening */
  button:not(:disabled):active, .btn:active { transform: none; }
}
