:root {
  --bg: #f7f4ee; --panel: #fffdf9; --ink: #23211d; --muted: #77716a; --line: #e4ded3;
  --accent: #2f6f62; --accent-ink: #fff; --hl: #fbe7a6; --hover: #e3efe9; --read: #a8a196;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, "Segoe UI", Roboto, sans-serif;
}
:root { color-scheme: light; }
/* Dark: chosen with the ◐ button, or by the device when the button is on automatic */
:root[data-theme=dark] {
  color-scheme: dark;
  --bg: #161513; --panel: #201e1b; --ink: #ece7de; --muted: #9a938a; --line: #35322d;
  --accent: #6bb3a2; --accent-ink: #102420; --hl: #5a4a17; --hover: #2c3d38; --read: #6a655d;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme=light]) {
    color-scheme: dark;
    --bg: #161513; --panel: #201e1b; --ink: #ece7de; --muted: #9a938a; --line: #35322d;
    --accent: #6bb3a2; --accent-ink: #102420; --hl: #5a4a17; --hover: #2c3d38; --read: #6a655d;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 var(--sans); display: flex; flex-direction: column; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-variant-numeric: tabular-nums; }
button, select { font: inherit; color: inherit; }
button { border: 1px solid var(--line); background: var(--panel); padding: 6px 14px; border-radius: 7px; cursor: pointer; }
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.ghost { background: transparent; border-color: transparent; font-size: 18px; padding: 4px 8px; }
button.ghost:hover { border-color: var(--line); }
button.round { width: 44px; height: 44px; border-radius: 50%; padding: 0; font-size: 16px; }
/* SVG player icons (crisp, same colour as the text, never emoji) */
.ico { width: 20px; height: 20px; display: block; flex: none; }
button.icon { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; padding: 0;
  color: var(--ink); border-radius: 50%; }
button.icon:hover { background: var(--hover); border-color: transparent; }
button.icon:disabled { opacity: .35; cursor: default; background: transparent; }
button.round { display: inline-flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 8px color-mix(in srgb, var(--accent) 35%, transparent); transition: transform .1s, filter .15s; }
button.round:hover { filter: brightness(1.08); }
button.round:active { transform: scale(.94); }
button.round .ico { width: 22px; height: 22px; }
button.round.is-play .ico { transform: translateX(1.5px); }   /* a triangle looks off-centre when centred exactly */
.primary-btn { display: inline-flex; align-items: center; justify-content: center; width: 42px; height: 42px; flex: none;
  border-radius: 50%; background: var(--accent); color: var(--accent-ink); }
.primary-btn .ico { width: 20px; height: 20px; transform: translateX(1.5px); }
select { background: var(--panel); border: 1px solid var(--line); border-radius: 7px; padding: 5px 8px; }

header.top { display: flex; align-items: baseline; gap: 16px; padding: 12px 24px; border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { font: 600 19px var(--serif); color: var(--ink); text-decoration: none; }
.theme { margin-left: auto; align-self: center; width: 36px; height: 36px; padding: 0; }
main { flex: 1; min-height: 0; overflow-y: auto; }
.wrap { max-width: 820px; margin: 0 auto; padding: 24px 24px 60px; }
h1 { font: 600 30px/1.2 var(--serif); margin: 8px 0 10px; }
h2.section { font: 600 13px var(--sans); text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin: 32px 0 10px; }
.intro { max-width: 62ch; margin-bottom: 24px; }
.back { text-decoration: none; color: var(--muted); }
.back:hover { color: var(--ink); }

/* Library */
.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.cards li a { display: block; padding: 18px 22px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  color: inherit; text-decoration: none; }
.cards li a:hover { border-color: var(--accent); }
.cards .t { font: 600 22px var(--serif); }
.cards .a { color: var(--muted); margin: 2px 0 8px; }
.cards .d { margin: 0; }
.cards .n { margin-top: 10px; font-size: 13px; color: var(--muted); }
.continue { display: flex; align-items: center; gap: 16px; padding: 16px 20px; border-radius: 12px; margin-bottom: 20px;
  background: var(--panel); border: 1px solid var(--accent); color: inherit; text-decoration: none; }
.continue > div { flex: 1; }
.continue .t { font: 19px var(--serif); }

/* Book page */
#b-desc { font: 17px/1.55 var(--serif); max-width: 62ch; }
.chapters { list-style: none; padding: 0; margin: 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--panel); }
.chapters li { border-top: 1px solid var(--line); }
.chapters li:first-child { border-top: 0; }
.chapters a, .chapters .na { display: flex; gap: 12px; align-items: baseline; padding: 11px 18px; color: inherit; text-decoration: none; }
.chapters a:hover { background: var(--hover); }
.chapters .ct { flex: 1; font: 16px var(--serif); }
.chapters .na { color: var(--read); }
.chapters .done .ct::after { content: " ✓"; color: var(--accent); }
.chapters .cur .ct { font-weight: 600; }
.credits { margin-top: 28px; color: var(--muted); font-size: 13px; }
.credits dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; }
.credits dt { text-transform: capitalize; }
.credits dd { margin: 0; }

/* Reader */
.reader { display: flex; flex-direction: column; height: 100%; }
.r-bar { display: flex; align-items: center; gap: 14px; padding: 8px 18px; border-bottom: 1px solid var(--line); background: var(--panel); }
.r-bar .back { font-size: 20px; }
.r-titles { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#r-chapter { font: 600 15px var(--serif); border: 0; padding: 2px 0; background: transparent; max-width: 100%; text-overflow: ellipsis; }
.r-mode { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; flex: none; }
.seg button { border: 0; border-radius: 0; background: transparent; padding: 5px 10px; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed=true] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

/* Shown while LibriVox's spoken introduction plays, before the book's text starts */
.intro-bar { display: flex; align-items: center; gap: 12px; padding: 10px 18px; font-size: 14px; line-height: 1.35;
  background: color-mix(in srgb, var(--accent) 14%, var(--panel)); border-bottom: 1px solid var(--line); }
.intro-bar > div { flex: 1; }
.intro-bar button { flex: none; background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }

/* One sentence at a time */
.focus { flex: 1; overflow-y: auto; display: flex; padding: 24px 20px; }
.f-card { margin: auto; width: 100%; max-width: 760px; text-align: center; }
.f-where { margin-bottom: 22px; }
.f-fr { font: calc(30px * var(--fs))/1.45 var(--serif); }
.f-fr .w { border-radius: 4px; cursor: pointer; }
.f-fr .w:hover { background: var(--hover); }
.f-fr .w.now { background: var(--hl); }
.f-fr.aside { font-style: italic; color: var(--muted); }
.f-en { margin-top: calc(22px * var(--fs)); font: calc(19px * var(--fs))/1.5 var(--sans); color: var(--muted); transition: filter .15s; }
.f-en.mt { font-style: italic; }
.f-en .note { display: block; font-size: 12.5px; font-style: normal; opacity: .8; margin-bottom: 4px; }
.focus.tr-blur .f-en:not(.reveal) { filter: blur(6px); cursor: pointer; }
.focus.tr-hide .f-en { display: none; }
.f-card.upcoming .f-fr, .f-card.upcoming .f-en { opacity: .45; }
.f-card.in { animation: f-in .22s ease-out; }
@keyframes f-in { from { opacity: 0; transform: translateY(8px); } }
@media (prefers-reduced-motion: reduce) { .f-card.in { animation: none; } }

/* --ts: the chosen text size (1 = medium); --fs: the sentence view's size, fitted to the screen on Auto */
.reader { --ts: 1; --fs: 1; }
.transcript { flex: 1; overflow-y: auto; padding: 28px max(24px, calc(50% - 360px)) 40vh; font: calc(21px * var(--ts))/1.7 var(--serif); }
.transcript .w { border-radius: 3px; cursor: pointer; }
.transcript .w:hover { background: var(--hover); }
.transcript .w.now { background: var(--hl); }
.transcript .sent.past { color: var(--read); }
.transcript h2.chapter { font: 600 25px/1.35 var(--serif); text-align: center; margin: 1.8em 0 1.1em; }
.transcript h2.chapter:first-child { margin-top: .3em; }
.transcript h2.chapter::before { content: "❦"; display: block; color: var(--accent); font-size: 20px; margin-bottom: .4em; opacity: .8; }
.transcript h2.chapter .trl { font-size: calc(15px * var(--ts)); font-weight: 400; text-align: center; }
.transcript p { margin: 0 0 1.5em; }
.transcript p > .sblock:first-child .sent { padding-left: 1.6em; }
.transcript p.aside { font-size: 16px; font-style: italic; color: var(--muted); border-left: 3px solid var(--line); padding-left: 14px; }
.transcript p.aside .sent { padding-left: 0 !important; }
.transcript .sblock { display: block; margin-bottom: .5em; cursor: pointer; }
.transcript .sblock:hover .sent { background: color-mix(in srgb, var(--hover) 45%, transparent); border-radius: 4px; }
.transcript .trl { display: block; font: calc(15px * var(--ts))/1.45 var(--sans); color: var(--muted); margin-top: 1px; user-select: none; transition: filter .15s; }
.transcript .trl:empty { display: none; }
.transcript .trl.mt { font-style: italic; }
.transcript .trl.mt::before { content: "machine · "; font-size: 12px; font-style: normal; opacity: .7; }
.transcript .sblock.current .trl { color: var(--ink); }
/* The English phrase for what's being read */
.trl .e, .f-en .e { border-radius: 3px; transition: background-color .12s; }
.trl .e.now, .f-en .e.now { background: color-mix(in srgb, var(--hl) 70%, transparent); color: var(--ink); }
.transcript.tr-blur .trl { filter: blur(5px); }
.transcript.tr-blur .trl:hover, .transcript.tr-blur .trl.reveal { filter: none; }
.transcript.tr-hide .sblock { display: inline; margin: 0; }
.transcript.tr-hide .trl { display: none; }
.transcript.tr-hide p { text-indent: 1.6em; margin-bottom: .9em; }
.transcript.tr-hide p > .sblock:first-child .sent { padding-left: 0; }
.transcript ::selection { background: var(--hover); }
.end-card { text-align: center; margin: 2em 0; font-family: var(--sans); font-size: 15px; }

.player { display: flex; align-items: center; gap: 6px; padding: 8px 14px; border-top: 1px solid var(--line); background: var(--panel); }
.player input[type=range] { flex: 1; min-width: 60px; accent-color: var(--accent); }

/* Word meanings */
.tip { position: fixed; z-index: 10; max-width: min(380px, 94vw); min-width: 200px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: 0 8px 28px rgba(0,0,0,.18); padding: 12px 14px; font-size: 14px; }
.tip .src { font: italic 17px var(--serif); }
.tip .entry { margin-top: 6px; }
.tip .hw { font-weight: 600; }
.tip .pos { color: var(--muted); font-style: italic; }
.tip li.fits { font-weight: 600; }
.tip ol { margin: 2px 0 0; padding-left: 20px; }
.tip .form { color: var(--muted); font-size: 12.5px; }
.tip table { border-collapse: collapse; width: 100%; margin-top: 4px; }
.tip td { padding: 2px 8px 2px 0; vertical-align: top; }
.tip td:first-child { font-style: italic; white-space: nowrap; }
.tip .ctx { border-top: 1px solid var(--line); margin-top: 8px; padding-top: 6px; color: var(--muted); font-size: 13px; transition: filter .15s; }
.tip .ctx.blur { filter: blur(4px); }
.tip .ctx.blur:hover { filter: none; }

@media (max-width: 640px) {
  .tagline { display: none; }
  .wrap { padding: 16px 16px 48px; }
  h1 { font-size: 25px; }
  .transcript { font-size: 19px; padding: 18px 16px 40vh; }
  .player { flex-wrap: wrap; justify-content: center; }
  .player input[type=range] { order: 10; flex-basis: 100%; }
  #p-prevch, #p-nextch { display: none; }
  .r-mode { font-size: 12px; }
  .r-mode-l { display: none; }
  .r-bar { gap: 8px; padding: 8px 12px; }
  header.top { padding: 8px 16px; }
  .seg button { padding: 5px 8px; }
  .transcript { font-size: calc(19px * var(--ts)); }
  .f-fr { font-size: calc(25px * var(--fs)); }
  .f-en { font-size: calc(17px * var(--fs)); }
  .focus { padding: 14px 16px; }
  .f-where { margin-bottom: 12px; }
}
