/* Legendo: components. Uses roles from tokens.css only. */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
/* No fake italics: Literata and Atkinson have real ones, and Chinese type, which has none,
   stays upright inside an italic line instead of being slanted. */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; font-synthesis: weight; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 1rem/var(--lh-ui) var(--font-ui);
  /* a word longer than its line breaks rather than running off the screen */
  overflow-wrap: break-word;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh; /* dvh where the browser has it: see the end of this file */
}
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
/* never under 16px: an iPhone zooms the page in on a smaller text box when it's tapped */
input, select, textarea { font-size: max(16px, 1em); }
a { color: var(--accent); text-underline-offset: 3px; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
[tabindex="-1"]:focus, [tabindex="-1"]:focus-visible { outline: none; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
p { margin: 0; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- shell ---------- */
.app-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: var(--s2);
  min-height: var(--header-h);
  padding: max(env(safe-area-inset-top), 0px) var(--s4) 0;
  background: var(--bg); /* translucent where the browser has color-mix(): see the end of this file */
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid transparent;
}
.app-header.scrolled { border-bottom-color: var(--rule); }
.app-header .title {
  flex: 1; min-width: 0;
  font-weight: 700; font-size: var(--fs-md);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  /* holds (and clips) the words only a screen reader hears, which would otherwise sit past the
     end of a long title and widen the whole page */
  position: relative;
}
/* a page's title: the book's title gives way to the page number when there isn't room, and
   with no room for any of it (very large text), the page number alone shows (page.js) */
.app-header .page-title { display: flex; align-items: baseline; }
.app-header .page-title .book { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-header .page-title .where { flex: none; white-space: pre; }
.app-header .page-title .compact { display: none; }
.app-header .page-title.tight > :not(.compact) { display: none; }
.app-header .page-title.tight > .compact { display: inline; overflow: hidden; text-overflow: ellipsis; }
.app-header .brand { font-family: var(--font-book); font-weight: 600; font-size: var(--fs-lg); letter-spacing: -0.01em; }
.app-header .brand::first-letter { color: var(--rubric); }
.app-header .actions { display: flex; gap: var(--s1); }

main#view {
  max-width: var(--content);
  margin: 0 auto;
  padding: var(--s4) var(--s4) calc(var(--nav-h) + var(--s7) + env(safe-area-inset-bottom));
}
main#view.no-nav { padding-bottom: calc(var(--s7) + env(safe-area-inset-bottom)); }

.bottom-nav {
  position: fixed; inset: auto 0 0 0; z-index: 30;
  display: flex; justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--rule);
}
.bottom-nav .inner { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); width: 100%; max-width: var(--content); }
.bottom-nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  height: var(--nav-h); min-width: 0; padding: 0 2px;
  /* the bar is a fixed height: its labels grow with the text size up to a point, then stop */
  color: var(--ink-faint); text-decoration: none; font-size: min(var(--fs-xs), 16px); font-weight: 700;
  text-align: center; line-height: 1.1; word-break: break-word; overflow-wrap: anywhere;
  position: relative;
}
.bottom-nav a svg { width: 24px; height: 24px; }
.bottom-nav a[aria-current="page"] { color: var(--accent); }
.bottom-nav a .badge {
  position: absolute; top: 8px; left: calc(50% + 6px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--accent); color: var(--accent-ink);
  font-size: 11px; line-height: 18px; text-align: center;
}

.banner {
  display: flex; gap: var(--s3); align-items: flex-start;
  margin: 0 0 var(--s4);
  padding: var(--s3) var(--s4);
  border-radius: var(--r-md);
  background: var(--warning-soft); color: var(--ink);
  font-size: var(--fs-sm);
}
.banner strong { font-weight: 700; }

/* The book's words and their explanations: a word longer than the screen is wide
   ("contransmagnificandjewbangtantiality") may break anywhere, even in a row that would
   otherwise widen to fit it. Only text, never buttons, so "Remembered" stays whole.
   (word-break: break-word, here and below, does the same in Safari before 15.4, which doesn't
   know "anywhere".) */
.paper, .quote, .ctx, .mean, .gl-plain, .gl-meaning, .gl-list, .note, .thought, .prompt, .answer > p,
.recap-headline, .beats, .pages .first, .word .w, .person .n, .in-your-words dd,
.shelf .t, .shelf .a, .book-head .h-page, .book-head .author, .bookplate .bt { word-break: break-word; overflow-wrap: anywhere; }
.banner.backup-note { background: var(--accent-soft); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 44px; padding: 0 var(--s4);
  border-radius: var(--r-md); border: 1px solid transparent;
  font-weight: 700; font-size: var(--fs-sm); line-height: 1.15; text-align: center;
  cursor: pointer; user-select: none; -webkit-user-select: none;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
  text-decoration: none;
}
.btn svg { width: 20px; height: 20px; flex: none; }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--rule-strong); }
.btn-ghost { background: transparent; color: var(--accent); }
.btn-danger { background: var(--surface); color: var(--danger); border-color: var(--danger); }
.btn-block { width: 100%; }
.btn-lg { min-height: 54px; font-size: var(--fs-md); border-radius: var(--r-lg); }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px; border-radius: 50%;
  background: transparent; border: 0; color: var(--ink); cursor: pointer;
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn[aria-pressed="true"] { color: var(--accent); background: var(--accent-soft); }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); font-weight: 700; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.link-btn svg { display: inline-block; width: 1.15em; height: 1.15em; vertical-align: -0.22em; margin-right: 6px; }

/* ---------- type helpers ---------- */
.muted { color: var(--ink-muted); }
.faint { color: var(--ink-faint); }
.small { font-size: var(--fs-sm); }
.xsmall { font-size: var(--fs-xs); }
.book-font { font-family: var(--font-book); }
.h-page { font-family: var(--font-book); font-weight: 600; font-size: var(--fs-xl); letter-spacing: -0.015em; }
.h-section { font-family: var(--font-book); font-size: var(--fs-lg); font-weight: 600; letter-spacing: -0.01em; margin: var(--s6) 0 var(--s3); }
.stack > * + * { margin-top: var(--s3); }
.stack-lg > * + * { margin-top: var(--s5); }
.row { display: flex; align-items: center; gap: var(--s3); }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- library ---------- */
.this-week {
  display: grid; grid-template-columns: 1fr auto; gap: var(--s2) var(--s4); align-items: center;
  padding: var(--s4) 0 var(--s5);
  border-bottom: 1px solid var(--rule);
  margin-bottom: var(--s2);
}
.this-week .label { font-weight: 700; }
.this-week .sub { font-size: var(--fs-sm); color: var(--ink-muted); }

.week-dots { display: flex; gap: 6px; }
.week-dots span {
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center;
  border: 1.5px solid var(--rule-strong);
  font-size: 11px; font-weight: 700; color: var(--ink-faint);
}
.week-dots span.read { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.week-dots span.is-today { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--highlight); }

.shelf { list-style: none; margin: 0; padding: 0; }
.shelf li + li { border-top: 1px solid var(--rule); }
.shelf a {
  display: grid; grid-template-columns: 50px 1fr auto; gap: var(--s4); align-items: center;
  padding: var(--s4) 0; text-decoration: none; color: inherit;
}
/* a cloth cover in the book's colour, its spine at the left and its title's first letter stamped on it */
.cover {
  position: relative; display: grid; place-items: center; width: 50px; height: 72px;
  border-radius: 2px 5px 5px 2px; background: var(--spine, var(--accent)); color: var(--cover-ink);
  box-shadow: inset 5px 0 0 rgb(0 0 0 / 0.2), inset 6px 0 0 rgb(255 255 255 / 0.12), 0 1px 2px rgb(0 0 0 / 0.25);
  padding-left: 4px; font-family: var(--font-book); font-weight: 500; font-size: 1.625rem; line-height: 1;
}
.cover::before { content: ""; position: absolute; inset: 5px 4px 5px 10px; border: 1px solid rgb(255 255 255 / 0.32); border-radius: 1px; }
.cover.slant { font-style: italic; }
.shelf .t { font-family: var(--font-book); font-weight: 600; font-size: var(--fs-lg); line-height: 1.25; }
.shelf .a { font-size: var(--fs-sm); color: var(--ink-muted); margin-top: 2px; }
.shelf .m { font-size: var(--fs-xs); color: var(--ink-faint); margin-top: 6px; }
.shelf .p { font-size: var(--fs-sm); color: var(--ink-muted); text-align: right; white-space: nowrap; }
.meter { height: 4px; border-radius: 2px; background: var(--rule); overflow: hidden; margin-top: 8px; }
.meter > i { display: block; height: 100%; background: var(--accent); border-radius: 2px; }

/* ---------- empty states ---------- */
.empty { padding: var(--s7) var(--s2) var(--s6); text-align: left; }
.empty h2 { font-family: var(--font-book); font-weight: 600; font-size: var(--fs-xl); margin-bottom: var(--s3); }
.empty p { color: var(--ink-muted); margin-bottom: var(--s5); max-width: 36ch; }
.empty .btns { display: flex; flex-direction: column; gap: var(--s3); max-width: 340px; }

/* maths, typeset (math.js); a formula on a line of its own wider than the screen scrolls sideways */
.math.display { display: block; margin: 0.4em 0; padding: 0.1em 0; overflow-x: auto; overflow-y: hidden; }
.math .katex { font-size: 1.05em; }

/* ---------- the first questions (views/intro.js): what the reader reads, and how much ---------- */
.intro { padding: var(--s4) 0 var(--s6); }
.intro h1 {
  font-family: var(--font-book); font-weight: 600; letter-spacing: -0.02em;
  font-size: clamp(2rem, 1.35rem + 2.9vw, 2.75rem); line-height: 1.08; text-wrap: balance; margin: var(--s3) 0 var(--s3);
}
.intro .lede { font-size: var(--fs-md); line-height: 1.5; color: var(--ink-muted); margin-bottom: var(--s5); max-width: 34em; }
.intro h2 { font-family: var(--font-book); font-weight: 600; font-size: var(--fs-lg); margin: var(--s6) 0 var(--s3); }
.intro .btns { display: flex; flex-direction: column; gap: var(--s2); margin-top: var(--s6); max-width: 360px; }
/* choices pressed in and out (any number), or one of a few (role radio) */
.choices { display: flex; flex-direction: column; gap: var(--s2); }
.choice {
  display: flex; align-items: center; gap: var(--s3); width: 100%; min-height: 56px; padding: var(--s3) var(--s4);
  border: 1px solid var(--rule-strong); border-radius: 12px; background: var(--surface); color: var(--ink);
  font: inherit; text-align: start; cursor: pointer;
}
.choice.compact { min-height: 50px; }
.choice .c-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.choice .c-name { font-family: var(--font-book); font-weight: 600; font-size: var(--fs-md); line-height: 1.3; }
.choice .c-what { font-size: var(--fs-sm); line-height: 1.4; color: var(--ink-muted); }
.choice .c-mark { flex: none; display: grid; place-items: center; width: 26px; height: 26px; border-radius: 13px;
  border: 1.5px solid var(--rule-strong); color: transparent; }
.choice .c-mark svg { width: 16px; height: 16px; }
.choice[aria-pressed="true"], .choice[aria-checked="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.choice[aria-pressed="true"] .c-mark, .choice[aria-checked="true"] .c-mark { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.choice:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* a book's kind: in the book's italic, pencilled (upright in Chinese, Japanese and Korean) */
.kind-line { margin-top: 2px; font-family: var(--font-book); font-style: italic; font-size: var(--fs-sm); }
.kind-line a { color: var(--pencil); text-underline-offset: 3px; }
.shelf .m { display: flex; flex-wrap: wrap; column-gap: var(--s3); }
.shelf .m .kind { font-family: var(--font-book); font-style: italic; color: var(--pencil); }
:is(.kind-line, .shelf .m .kind):is(:lang(zh), :lang(ja), :lang(ko)) { font-style: normal; }

/* ---------- welcome (views/welcome.js): the shelf before the first book ---------- */
.welcome { padding: var(--s4) 0 var(--s5); }
.welcome h1 {
  font-family: var(--font-book); font-weight: 600; letter-spacing: -0.02em;
  font-size: clamp(2rem, 1.35rem + 2.9vw, 2.75rem); line-height: 1.08;
  text-wrap: balance; margin: var(--s3) 0 var(--s4);
}
.welcome .lede { font-size: var(--fs-md); line-height: 1.5; color: var(--ink-muted); max-width: 34em; }
/* the sample page, drawn as the page screen draws one (.paper, .para, .sent, .name), with an
   explanation written under its line */
.specimen {
  position: relative; margin: var(--s5) calc(var(--s1) * -1) calc(var(--s5) + 9px); border-radius: 4px;
  background: var(--surface); box-shadow: var(--leaves);
  padding: calc(var(--s3) + var(--fs-xs) * 1.3 + var(--s3)) var(--s5) var(--s5) calc(var(--s5) + 14px);
}
.spec-folios { position: absolute; top: var(--s3); left: var(--s5); right: var(--s4); display: flex; justify-content: space-between;
  font-family: var(--font-book); font-size: var(--fs-xs); line-height: 1.3; color: var(--pencil); font-variant-numeric: oldstyle-nums; }
.spec-folios span:first-child { font-style: italic; }
.spec-para { font-family: var(--font-book); font-size: 1.125rem; line-height: var(--lh-book); margin: 0 0 0.7em; text-wrap: pretty; }
.spec-sent, .spec-name {
  cursor: pointer; border-radius: 0.5em 0.25em 0.45em 0.3em; padding: 0.06em 0.18em; margin: 0 -0.18em;
  background-image: linear-gradient(100deg, transparent 0.1em, var(--highlight) 0.32em, var(--highlight) calc(100% - 0.28em), transparent); background-repeat: no-repeat;
  background-size: 0% 82%; background-position: 0 70%; transition: background-size 380ms var(--ease);
  -webkit-box-decoration-break: clone; box-decoration-break: clone;
}
.spec-name { border-bottom: 1px dotted var(--accent); border-radius: 3px 3px 0 0; }
.spec-sent.lit, .spec-name.lit { background-size: 100% 82%; color: var(--highlight-ink); }
.spec-name.lit { border-bottom-style: solid; }
.specimen [role="button"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
/* the gloss: the app's own words, in its own type, opened by a red paraph hung in the margin, as
   a gloss was rubricated */
.spec-gloss { position: relative; margin: -0.15em 0 1em; padding: 2px 0 2px 1.35em; font-size: var(--fs-sm); line-height: 1.45; }
.spec-gloss::before { content: "\00B6"; position: absolute; left: 0; top: 0; font-family: var(--font-book); font-size: 1.25em; line-height: 1.25; color: var(--rubric); }
.spec-gloss .label { font-family: var(--font-book); font-style: italic; }
.spec-gloss .plain { color: var(--ink); }
.spec-gloss .who, .spec-gloss .what { color: var(--ink-muted); font-size: var(--fs-xs); margin-top: var(--s1); }
.spec-gloss strong { font-weight: 700; color: var(--ink); }
.specimen figcaption { margin-top: var(--s4); padding-top: var(--s3); border-top: 1px solid var(--rule); font-size: var(--fs-xs); color: var(--pencil); }
/* As the screen opens: the line is marked, then its gloss written. Once, and not at all for anyone
   who has asked for less motion. */
/* (the gloss is uncovered from the top, as if written down, rather than faded in: its words are
   never paler than they're meant to be) */
.specimen.opening .spec-sent.lit { animation: mark-in 650ms var(--ease) 500ms both; }
.specimen.opening .spec-gloss { animation: gloss-in 650ms var(--ease) 1100ms both; }
@keyframes mark-in { from { background-size: 0% 82%; } }
@keyframes gloss-in { from { clip-path: inset(0 0 100% 0); } to { clip-path: inset(0 0 0 0); } }
@media (prefers-reduced-motion: reduce) {
  .specimen.opening .spec-sent.lit, .specimen.opening .spec-gloss { animation: none; }
}
@media (hover: hover) {
  .spec-sent:hover, .spec-name:hover { background-color: var(--accent-soft); }
}
.welcome .btns { display: flex; flex-direction: column; gap: var(--s3); max-width: 360px; }
/* a printer's ornament closing a part of a screen: a red lozenge between two rules */
.ornament { display: flex; align-items: center; justify-content: center; gap: 12px; margin: var(--s7) 0 var(--s5); }
.ornament::before, .ornament::after { content: ""; width: 56px; height: 1px; background: var(--rule-strong); opacity: 0.5; }
.ornament i { width: 7px; height: 7px; background: var(--rubric); transform: rotate(45deg); }
.welcome .ornament + h2 { margin-top: 0; }
.welcome h2 { font-family: var(--font-book); font-weight: 600; font-size: var(--fs-lg); margin: var(--s7) 0 var(--s2); }
.uses { margin: 0; }
.uses > div { position: relative; padding: var(--s3) 0 var(--s3) 1.5em; }
.uses dt { font-family: var(--font-book); font-weight: 600; font-size: var(--fs-md); }
.uses dt::before { content: "\00B6"; position: absolute; inset-inline-start: 0; font-weight: 400; color: var(--pencil); }
.uses dd { margin: 2px 0 0; color: var(--ink-muted); font-size: var(--fs-sm); line-height: 1.5; }
@media (min-width: 520px) {
  .uses > div { display: grid; grid-template-columns: 9.5rem 1fr; gap: var(--s4); align-items: baseline; }
  .uses dd { margin: 0; }
}
.welcome .back-again { margin-top: var(--s6); font-size: var(--fs-sm); }
.welcome .back-again + .back-again { margin-top: var(--s3); }
.welcome .back-again .link-btn { text-align: start; }

/* ---------- book ---------- */
.book-head { padding: var(--s2) 0 var(--s5); }
.book-head .author { color: var(--ink-muted); margin-top: var(--s1); }
.book-head .progress-line { display: flex; justify-content: space-between; font-size: var(--fs-sm); color: var(--ink-muted); margin-top: var(--s4); }

.previously {
  position: relative;
  margin: 0 0 var(--s5);
  padding: var(--s4) var(--s4) var(--s4) calc(var(--s4) + 6px);
  background: var(--surface);
  border-radius: var(--r-md);
  border: 1px solid var(--rule);
}
.previously::before {
  content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 4px;
  border-radius: 2px; background: var(--rubric);
}
.previously .k { font-weight: 700; }
.previously p { color: var(--ink-muted); font-size: var(--fs-sm); margin: var(--s1) 0 var(--s3); }

.scan-cta { margin: 0 0 var(--s4); }
.scan-alt { margin: var(--s3) 0 0; text-align: center; }
.quick { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s2); }
/* a long label (large text, a narrow phone) wraps inside its button rather than off the screen */
.quick .btn { justify-content: flex-start; min-height: 52px; min-width: 0; text-align: start; line-height: 1.2; word-break: break-word; overflow-wrap: anywhere; }

.log-reading {
  display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap;
  margin-top: var(--s4); padding: var(--s3) var(--s4);
  border: 1px dashed var(--rule-strong); border-radius: var(--r-md);
  font-size: var(--fs-sm);
}
.log-reading input { width: 5.5em; }
/* (close by its row, and when it wraps, barely set in from the box's edge) */
.log-reading .btn-ghost { padding-inline: var(--s2); }

.pages { list-style: none; margin: 0; padding: 0; }
.pages li + li { border-top: 1px solid var(--rule); }
.pages a { display: grid; grid-template-columns: 56px 1fr; gap: var(--s3); padding: var(--s3) 0; text-decoration: none; color: inherit; align-items: baseline; }
.pages .num { font-family: var(--font-book); font-weight: 600; color: var(--ink-muted); font-variant-numeric: oldstyle-nums; }
.pages .first { font-family: var(--font-book); color: var(--ink); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.pages .notes { font-size: var(--fs-xs); color: var(--pencil); margin-top: 2px; }

/* ---------- the page ---------- */
.paper {
  position: relative;
  background: var(--surface);
  border-radius: 4px;
  box-shadow: var(--leaves);
  padding: var(--s6) var(--s5) var(--s6) calc(var(--s5) + 14px);
  /* room for the running head and page number above the first line, whatever the text size */
  padding-top: max(var(--s6), calc(var(--s3) + var(--fs-xs) * 1.3 + var(--s2)));
  margin: 0 calc(var(--s1) * -1) var(--s5);
}
.paper .folios {
  position: absolute; top: var(--s3); left: var(--s5); right: var(--s4);
  display: flex; gap: var(--s3); align-items: baseline;
  font-family: var(--font-book); font-size: var(--fs-xs); line-height: 1.3; color: var(--ink-faint);
}
/* (the running head keeps to the far side from the number, a Hebrew or Arabic one too) */
.paper .folios .running { flex: 1 1 auto; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; text-align: left; }
.paper .folios .folio { flex: none; margin-inline-start: auto; font-variant-numeric: oldstyle-nums; }
/* below the page number and running head, which sit in the top margin */
.paper .hint { font-size: var(--fs-xs); color: var(--ink-faint); margin: 0 var(--s5) var(--s4) 0; }
/* the reader's text size: pages, explanations and review cards */
:root { --read-scale: 1; }
:root[data-text-size="s"] { --read-scale: 0.9; }
:root[data-text-size="l"] { --read-scale: 1.15; }
:root[data-text-size="xl"] { --read-scale: 1.32; }
.para {
  position: relative;
  font-family: var(--font-book);
  font-size: calc(1.125rem * var(--read-scale));
  line-height: var(--lh-book);
  hyphens: auto; -webkit-hyphens: auto;
  margin: 0 0 0.85em;
  text-wrap: pretty;
}
/* a poem, line by line: a line too long for the screen goes on indented, so it can't be taken
   for the next line of the poem */
.para.verse .line { display: block; padding-inline-start: 1.5em; text-indent: -1.5em; }
.para.initial::first-letter, .spec-para.initial::first-letter {
  float: left; font-size: 3.45em; line-height: 0.8; font-weight: 500; color: var(--rubric);
  margin: 0.11em 0.03em 0 -0.04em;
}
.para.has-note::before {
  content: ""; position: absolute; left: -18px; top: 0.7em;
  width: 6px; height: 6px; border-radius: 50%; background: var(--pencil);
}
/* a book read right to left has its margin, and the pencil dots, on the right */
.paper.rtl { padding-left: var(--s5); padding-right: calc(var(--s5) + 14px); }
.para[dir="rtl"].has-note::before { left: auto; right: -18px; }
.sent {
  cursor: pointer;
  border-radius: 0.5em 0.25em 0.45em 0.3em;
  /* (the stroke reaches a little past the words, and the words stay where they were) */
  padding: 0.06em 0.18em; margin: 0 -0.18em;
  background-image: linear-gradient(100deg, transparent 0.1em, var(--highlight) 0.32em, var(--highlight) calc(100% - 0.28em), transparent);
  background-repeat: no-repeat;
  background-size: 0% 82%;
  background-position: 0 70%;
  transition: background-size 380ms var(--ease);
  -webkit-box-decoration-break: clone; box-decoration-break: clone;
}
.sent.lit, .para.lit .sent { background-size: 100% 82%; color: var(--highlight-ink); }
.para.noted .sent { text-decoration: underline dotted var(--pencil); text-decoration-thickness: 2px; text-underline-offset: 4px; }
.sent.noted { text-decoration: underline dotted var(--pencil); text-decoration-thickness: 2px; text-underline-offset: 4px; }
.sent:focus-visible { outline-offset: 1px; }

.ask-bar {
  position: sticky; bottom: calc(var(--s4) + env(safe-area-inset-bottom));
  display: flex; gap: var(--s2); align-items: center;
  padding: var(--s2);
  background: var(--surface);
  border: 1px solid var(--rule-strong);
  border-radius: 28px;
  box-shadow: 0 6px 20px -12px rgb(0 0 0 / 0.35);
}
.ask-bar input { flex: 1; min-width: 0; border: 0; background: transparent; padding: 0 var(--s3); height: 40px; }
.ask-bar input:focus-visible { outline: none; }
.ask-bar:focus-within { border-color: var(--accent); }

/* ---------- sheet (the margin note) ---------- */
.scrim {
  position: fixed; inset: 0; z-index: 50;
  background: var(--scrim);
  opacity: 0; transition: opacity var(--t-med) var(--ease);
}
.scrim.open { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51;
  max-height: 86vh; overflow: auto; overscroll-behavior: contain;
  margin: 0 auto; max-width: var(--content);
  background: var(--surface);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  box-shadow: var(--sheet-shadow);
  padding: var(--s2) var(--s5) calc(var(--s5) + env(safe-area-inset-bottom));
  transform: translateY(100%);
  transition: transform var(--t-med) var(--ease);
}
.sheet.open { transform: translateY(0); }
.sheet .grab { width: 40px; height: 4px; border-radius: 2px; background: var(--rule-strong); margin: var(--s1) auto var(--s3); }
.sheet .sheet-head { position: sticky; top: calc(var(--s2) * -1); z-index: 2; display: flex; align-items: flex-start; gap: var(--s2); padding: var(--s2) 0 var(--s3); background: var(--surface); border-bottom: 2px solid var(--accent-soft); }
.sheet .sheet-head > :first-child { flex: 1; min-width: 0; } /* the title takes the room; close sits at the end */
.sheet .sheet-head .quote {
  flex: 1; font-family: var(--font-book); font-style: italic; color: var(--ink-muted);
  font-size: var(--fs-sm); line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.sheet .sheet-head .quote[dir="rtl"] { font-style: normal; } /* Hebrew and Arabic type have no italics */
/* a stanza shown as its lines, wherever the book's words are quoted */
.sheet .sheet-head .quote, .ctx { white-space: pre-line; }
.sheet h2.sheet-title { font-size: var(--fs-lg); font-weight: 700; flex: 1; }
.gl-partial .writing::after { content: ""; display: inline-block; width: 2px; height: 1em; margin-left: 2px; vertical-align: -0.12em;
  background: var(--accent); animation: caret 1s steps(1) infinite; }
@keyframes caret { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .gl-partial .writing::after { animation: none; } }
.gl-plain { position: relative; font-family: var(--font-book); font-size: calc(var(--fs-lg) * var(--read-scale)); line-height: 1.45; margin: var(--s4) 0 var(--s3);
  padding-inline-start: 1.15em; }
/* (the gloss's red paraph, hung in the margin, as on the welcome page) */
.gl-plain::before { content: "\00B6"; position: absolute; inset-inline-start: 0; top: 0; font-weight: 400; color: var(--rubric); }
.gl-meaning { font-size: calc(var(--fs-md) * var(--read-scale)); line-height: 1.55; }
/* a figure photographed to be explained: the photo heads its sheet, as the line heads an explanation's */
.figure-shot { display: block; max-width: 100%; max-height: min(28vh, 220px); border-radius: var(--r-sm);
  border: 1px solid var(--rule); background: var(--surface-2); }
.fig-title { margin: var(--s4) 0 0; font-size: var(--fs-sm); font-weight: 700; color: var(--ink-muted); }
.fig-title + .gl-plain { margin-top: var(--s2); }
.ask-bar.fig-ask { position: static; margin-top: var(--s5); box-shadow: none; }
.gl-list li { font-size: calc(var(--fs-md) * var(--read-scale)); }
.gl-section { margin-top: var(--s5); }
.gl-section h3 { font-size: var(--fs-sm); font-weight: 700; color: var(--ink-muted); margin-bottom: var(--s2); }
.gl-list { list-style: none; margin: 0; padding: 0; }
.gl-list li { padding: var(--s2) 0; border-top: 1px solid var(--rule); }
.gl-list li:first-child { border-top: 0; }
/* a reference's term over its note, as a kept word over its meaning */
.gl-term { display: block; font-family: var(--font-book); font-weight: 600; margin-bottom: 2px; }
.foreign { display: grid; grid-template-columns: 1fr auto; gap: var(--s1) var(--s3); align-items: center; }
.foreign .ph { font-family: var(--font-book); font-style: italic; font-size: var(--fs-md); }
.foreign .tr { grid-column: 1 / -1; color: var(--ink-muted); font-size: var(--fs-sm); }
.speaker { display: inline-flex; gap: var(--s2); align-items: center; font-size: var(--fs-sm); color: var(--ink-muted); }
.speaker > span:first-child { font-family: var(--font-book); font-style: italic; }
.speaker > span:first-child:is(:lang(zh), :lang(ja), :lang(ko)), .spec-gloss .label:is(:lang(zh), :lang(ja), :lang(ko)) { font-style: normal; }
.speaker b { color: var(--ink); }
.chips { display: flex; flex-wrap: wrap; gap: var(--s2); }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 36px; max-width: 100%; padding: 4px var(--s3);
  border-radius: 18px; border: 1px solid var(--rule-strong);
  background: var(--surface); font-size: var(--fs-sm); cursor: pointer; text-align: start;
}
/* a word longer than the sheet is wide ("contransmagnificandjewbangtantiality") breaks inside
   its chip rather than running off the screen */
.chip > span { min-width: 0; word-break: break-word; overflow-wrap: anywhere; }
.chip svg { width: 16px; height: 16px; }
.chip[aria-pressed="true"] { background: var(--success-soft); border-color: var(--success); color: var(--success); }
.chip .w { font-weight: 700; flex-shrink: 0; max-width: 100%; }
/* Words worth keeping: each word over its meaning, a row of its own, the whole row the button
   that saves it; the mark at its end says whether it's saved */
.keep-list { list-style: none; margin: 0; padding: 0; }
.keep-list li + li { border-top: 1px solid var(--rule); }
.keep {
  display: flex; align-items: center; gap: var(--s3); width: 100%; min-height: 48px;
  padding: var(--s2) 0; border: 0; background: none; color: inherit; font: inherit; text-align: start; cursor: pointer;
}
.keep-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.keep .w { font-family: var(--font-book); font-weight: 600; font-size: calc(var(--fs-md) * var(--read-scale)); overflow-wrap: anywhere; }
.keep .m { color: var(--ink-muted); font-size: calc(var(--fs-sm) * var(--read-scale)); line-height: 1.45; overflow-wrap: anywhere; }
.keep-mark {
  flex: none; display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%;
  border: 1px solid var(--rule-strong); color: var(--accent); background: var(--surface);
}
.keep-mark svg { width: 16px; height: 16px; }
.keep[aria-pressed="true"] .keep-mark { background: var(--success-soft); border-color: var(--success); color: var(--success); }
@media (hover: hover) { .keep:hover .keep-mark { border-color: var(--accent); } }
.keep:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-sm); }
.note-flag { display: flex; gap: var(--s2); align-items: flex-start; margin-top: var(--s4); padding: var(--s3); border-radius: var(--r-sm); background: var(--warning-soft); font-size: var(--fs-sm); }
.note-flag svg { width: 18px; height: 18px; flex: none; margin-top: 1px; color: var(--warning); }
.sheet-actions { display: flex; gap: var(--s2); flex-wrap: wrap; margin-top: var(--s5); padding-top: var(--s4); border-top: 1px solid var(--rule); }
/* the languages an explanation can be written again in, opened from "In another language" */
.lang-pick { display: grid; flex-basis: 100%; grid-template-columns: repeat(auto-fill, minmax(7.5em, 1fr)); gap: var(--s2);
  padding: var(--s2); border-radius: var(--r-md); background: var(--surface-2); }
.lang-pick[hidden] { display: none; }
.lang-pick .btn { min-width: 0; padding-inline: var(--s2); }
/* what wrote an explanation, and what to do if it's wrong, at its foot */
.ai-note { margin: var(--s4) 0 0; font-size: var(--fs-xs); color: var(--ink-faint); }
.gl-foot { margin-top: var(--s4); }
.gl-foot .ai-note { margin: 0 0 var(--s1); }
.sheet-actions .btn { flex: 1 1 auto; }

/* ---------- skeleton ---------- */
.skel { display: block; height: 14px; border-radius: 7px; background: linear-gradient(90deg, var(--surface-2), var(--rule), var(--surface-2)); background-size: 300% 100%; animation: skel 1.4s ease-in-out infinite; }
.skel + .skel { margin-top: 10px; }
.skel.w60 { width: 60%; } .skel.w80 { width: 80%; } .skel.w40 { width: 40%; } .skel.tall { height: 22px; }
@keyframes skel { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: var(--s2); }
.field + .field { margin-top: var(--s5); }
.field > label, .field > .label { font-weight: 700; font-size: var(--fs-sm); }
.help, .field .help { font-size: var(--fs-xs); color: var(--ink-faint); }
.input, select.input, textarea.input {
  width: 100%; min-height: 48px; padding: var(--s3) var(--s3);
  border-radius: var(--r-md); border: 1px solid var(--rule-strong);
  background: var(--surface); color: var(--ink);
}
textarea.input { min-height: 96px; resize: vertical; line-height: 1.5; }
.input:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.input.book-font { font-family: var(--font-book); font-size: var(--fs-lg); }
/* equal parts on one line while they fit; with large text or a narrow phone, the options that
   don't fit go on to another line (each at least as wide as its own label) */
.seg { display: flex; flex-wrap: wrap; background: var(--surface-2); border: 1px solid var(--rule); border-radius: var(--r-md); padding: 3px; gap: 3px; width: 100%; }
.seg button { flex: 1 1 0; min-width: -webkit-fit-content; min-width: fit-content; max-width: 100%; padding: 4px 8px; line-height: 1.2;
  min-height: 40px; border: 0; border-radius: 7px; background: transparent; font-weight: 700; font-size: var(--fs-sm); color: var(--ink-muted); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / 0.12); }
.form-actions { display: flex; flex-wrap: wrap; gap: var(--s3); margin-top: var(--s6); }
.form-actions .btn { flex: 1; max-width: 100%; }
.error-text { color: var(--danger); font-size: var(--fs-sm); }

/* ---------- lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
/* "Show more" at the end of a long list */
li.more { list-style: none; padding: var(--s4) 0 0; border-top: 0 !important; }
.list > li { padding: var(--s4) 0; border-top: 1px solid var(--rule); }
.list > li:first-child { border-top: 0; }
/* A long list's rows (saved words and notes, a novel's who's-who) are laid out as they come
   near the screen, not all at once when the list opens. Such a row draws nothing outside
   itself, so it has room at its sides for a focus ring, and its rule is drawn inside it,
   where the border was. */
.list > li.word, .list > li.person {
  content-visibility: auto; contain-intrinsic-size: auto 160px;
  position: relative; margin-inline: -6px; padding-inline: 6px; border-top: 0;
}
.list > li.word:not(:first-child), .list > li.person:not(:first-child) { padding-top: calc(var(--s4) + 1px); }
.list > li.word:not(:first-child)::before, .list > li.person:not(:first-child)::before {
  content: ""; position: absolute; top: 0; left: 6px; right: 6px; border-top: 1px solid var(--rule);
}
/* a row "Show more" moved keyboard focus to (a note: its text first, its link last) */
.list > li[tabindex="-1"]:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: var(--r-md); }
.person .n { font-family: var(--font-book); font-weight: 600; font-size: var(--fs-lg); }
.person .al { font-size: var(--fs-sm); color: var(--ink-muted); margin-top: 2px; }
.person .note { margin-top: var(--s2); }
.person .seen { font-size: var(--fs-xs); color: var(--ink-faint); margin-top: var(--s2); }
.word .w { font-family: var(--font-book); font-weight: 600; font-size: var(--fs-lg); }
.word .mean { margin-top: 2px; }
.word .ctx { font-family: var(--font-book); font-style: italic; color: var(--ink-muted); font-size: var(--fs-sm); margin-top: var(--s2); }
.word .meta { font-size: var(--fs-xs); color: var(--ink-faint); margin-top: var(--s2); display: flex; gap: var(--s3); align-items: center; }
.search { margin-bottom: var(--s4); }

/* ---------- recap ---------- */
.recap-headline { font-family: var(--font-book); font-size: var(--fs-xl); font-weight: 500; line-height: 1.3; margin: var(--s2) 0 var(--s5); }
.beats { margin: 0; padding: 0; list-style: none; counter-reset: beat; }
.beats li { position: relative; padding: var(--s3) 0 var(--s3) 36px; border-top: 1px solid var(--rule); line-height: 1.5; }
.beats li:first-child { border-top: 0; }
.beats li::before { counter-increment: beat; content: counter(beat); position: absolute; left: 0; top: var(--s3); width: 24px; height: 24px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: var(--fs-xs); display: grid; place-items: center; }
details.more { margin-top: var(--s4); }
details.more summary { cursor: pointer; font-weight: 700; color: var(--accent); min-height: 44px; display: flex; align-items: center; }
.thread { font-family: var(--font-book); font-style: italic; }

/* ---------- review ---------- */
.review-progress { display: flex; justify-content: space-between; font-size: var(--fs-sm); color: var(--ink-muted); margin-bottom: var(--s3); }
.flashcard {
  /* (a phone held sideways keeps "Show answer" on the screen) */
  min-height: min(300px, 40vh);
  display: flex; flex-direction: column;
  background: var(--surface); border-radius: var(--r-md);
  border: 1px solid var(--rule);
  padding: var(--s5);
  box-shadow: var(--paper-shadow);
}
.flashcard .src { font-size: var(--fs-xs); color: var(--ink-faint); }
.flashcard .prompt { font-family: var(--font-book); font-size: var(--fs-xl); line-height: 1.35; margin: var(--s4) 0; }
.flashcard .prompt.split { font-family: var(--font-ui); font-size: var(--fs-lg); line-height: 1.4; }
.flashcard .prompt.split .q { font-weight: 700; margin: 0 0 var(--s3); }
.flashcard .prompt.split .quote { margin: 0; padding-inline-start: var(--s3); border-inline-start: 3px solid var(--highlight); /* on the right in a book read right to left */
  font-family: var(--font-book); font-size: calc(var(--fs-lg) * var(--read-scale)); line-height: 1.5; white-space: pre-line; }
.size-preview { margin: var(--s3) 0 0; padding: var(--s3) var(--s4); background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-md); }
/* keyboard shortcuts mean nothing on a phone */
@media (hover: none) and (pointer: coarse) { .keys-hint { display: none; } }
.flashcard .answer { border-top: 2px solid var(--accent-soft); padding-top: var(--s4); font-size: calc(var(--fs-md) * var(--read-scale)); line-height: 1.55; }
/* the longer explanation under a card's answer: set as the explanation is, a paragraph to read,
   not a quotation in italics */
.flashcard .answer .ctx { color: var(--ink-muted); margin-top: var(--s3); font-size: calc(var(--fs-sm) * var(--read-scale)); line-height: 1.55; }
.pages.results mark { background: var(--highlight); color: var(--highlight-ink); border-radius: 2px; padding: 0 1px; }
#find-in-pages { margin-bottom: var(--s3); }
.page-links { margin-top: var(--s3); }
.page-links .k { font-size: var(--fs-xs); font-weight: 700; color: var(--ink-muted); }
.page-links ul { display: flex; flex-wrap: wrap; gap: var(--s2); list-style: none; margin: var(--s2) 0 0; padding: 0; }
.page-links a, .page-links [aria-current] { display: inline-flex; align-items: center; min-height: 36px; padding: 0 var(--s3);
  border-radius: 999px; border: 1px solid var(--rule-strong); font-size: var(--fs-sm); text-decoration: none; }
.page-links [aria-current] { background: var(--accent-soft); border-color: transparent; color: var(--ink); font-weight: 700; }
.thoughts .k { font-size: var(--fs-xs); font-weight: 700; color: var(--ink-muted); margin-top: var(--s4); }
.thought { margin: var(--s2) 0 0; padding-left: var(--s3); border-left: 2px solid var(--rule); font-size: var(--fs-sm); line-height: 1.5; white-space: pre-wrap; }
.thought .when { display: block; font-size: var(--fs-xs); color: var(--ink-faint); }
.thought .said { display: block; }
.thought-form { display: grid; gap: var(--s2); }
.text-fix { font-family: var(--font-book); font-size: var(--fs-md); line-height: 1.5; min-height: 40vh; resize: vertical; }
.thought-form .row { justify-content: flex-end; }
.grades { position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + var(--s2)); z-index: 5;
  /* three side by side, each wide enough for "Remembered" on one line (6.25em of its type, set a
     little smaller on a narrow phone so the three still fit); with very large text, as many as fit */
  font-size: clamp(0.8125rem, (100vw - 90px) / 19.5, var(--fs-sm));
  display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, calc(6.4em + 10px)), 1fr)); gap: var(--s2); margin-top: var(--s4);
  padding: var(--s2); border-radius: var(--r-lg); background: var(--bg);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
@media (max-width: 389px) { .grades { gap: 6px; padding: 6px; } }
.grades.static { position: static; }
.btn.reveal { position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + var(--s2)); z-index: 5; }
.grades .btn { flex-direction: column; gap: 2px; min-height: 60px; min-width: 0; padding-left: 4px; padding-right: 4px; font-size: inherit;
  white-space: normal; text-align: center; hyphens: auto; -webkit-hyphens: auto; overflow-wrap: anywhere; }
.grades .btn small { font-weight: 400; font-size: var(--fs-xs); opacity: 0.85; }

/* ---------- progress ---------- */
.ledger { list-style: none; margin: 0; padding: 0; }
.ledger li { display: flex; gap: var(--s2); align-items: baseline; padding: var(--s2) 0; }
/* (each total set as a table of contents sets a page number: dotted leaders to it) */
.ledger li > :first-child { flex: 1; min-width: 0; display: flex; gap: var(--s2); align-items: baseline; }
.ledger li > :first-child::after { content: ""; flex: 1; min-width: var(--s4); border-bottom: 2px dotted var(--rule-strong); opacity: 0.55; transform: translateY(-0.3em); }
.ledger .v { font-family: var(--font-book); font-weight: 600; font-size: var(--fs-xl); font-variant-numeric: oldstyle-nums; }
/* the reading log on Progress (views/readingLog.js): a row a book a day, each one a button */
.reading-log { list-style: none; margin: 0; padding: 0; }
.reading-log li + li { border-top: 1px solid var(--rule); }
.log-row { display: grid; grid-template-columns: auto 1fr; column-gap: var(--s3); row-gap: 2px; width: 100%; padding: var(--s3) 0;
  background: none; border: 0; color: inherit; font: inherit; text-align: start; cursor: pointer; }
.log-row .when { font-weight: 700; font-size: var(--fs-sm); white-space: nowrap; }
.log-row .what { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--font-book); }
.log-row .nums { grid-column: 1 / -1; font-size: var(--fs-sm); color: var(--ink-muted); font-variant-numeric: tabular-nums; }
.log-row .fixed { margin-inline-start: var(--s2); padding: 0 var(--s2); border-radius: 999px; background: var(--surface-2); font-size: var(--fs-xs); }
.log-row.off .when, .log-row.off .what { color: var(--ink-faint); text-decoration: line-through; }
.log-row:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-sm); }
.log-edit .field + .field { margin-top: var(--s4); }
.log-edit .field.check label { display: flex; gap: var(--s2); align-items: center; font-weight: 400; }
.log-edit .error-text:empty { display: none; }
.week-card { padding: var(--s4) 0 var(--s2); }
.week-card .big { font-family: var(--font-book); font-size: var(--fs-2xl); font-weight: 600; line-height: 1; font-variant-numeric: oldstyle-nums; }
.week-card .big small { font-size: var(--fs-md); font-weight: 400; color: var(--ink-muted); margin-left: var(--s2); }
.week-card .week-dots { margin-top: var(--s4); }
.week-card .week-dots span { width: 36px; height: 36px; font-size: 12px; }
/* 16 weeks of squares, up to 16 px each; on a narrow phone they shrink so this week stays in view */
.heat { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, auto); grid-auto-columns: minmax(0, 16px); gap: 4px; justify-content: start; padding-bottom: var(--s1); }
.heat i { width: 100%; aspect-ratio: 1; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--rule); box-sizing: border-box; }
@media (max-width: 340px) { .heat { gap: 3px; } .heat i { border-radius: 3px; } }
.heat i.on { background: var(--accent); border-color: var(--accent); }
.heat i.future { visibility: hidden; }
.heat-legend { display: flex; gap: var(--s3); font-size: var(--fs-xs); color: var(--ink-faint); margin-top: var(--s2); }

.plates { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--s3); }
.continue { margin: var(--s3) 0 var(--s2); }
/* "Photograph a page of …" on one line, the title cut short at its end; with very large text,
   the words go on to another line rather than leave no room for the title */
.continue .words { display: flex; flex-wrap: wrap; justify-content: center; min-width: 0; white-space: pre-wrap; }
.continue .words .titled { display: flex; flex: 1 1 6em; max-width: -webkit-max-content; max-width: max-content; min-width: 0; }
.continue .words .title { overflow: hidden; text-overflow: ellipsis; white-space: pre; min-width: 0; font-family: var(--font-book); font-weight: 600; }
.continue .words .title.slant { font-style: italic; }
.continue .words .mark { flex: none; }
.continue .words .fixed { flex: 0 1 auto; min-width: 0; }
.in-your-words { margin-bottom: var(--s5); }
.in-your-words .h-section { margin-top: var(--s4); }
.in-your-words dl { margin: 0; }
.in-your-words dt { font-size: var(--fs-xs); font-weight: 700; color: var(--ink-muted); margin-top: var(--s3); }
.in-your-words dd { margin: var(--s1) 0 0; font-family: var(--font-book); font-size: calc(var(--fs-md) * var(--read-scale)); line-height: 1.5; white-space: pre-wrap; }
.stamps { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--s3); }
.stamp { width: 6rem; min-height: 6rem; border-radius: 50%; border: 2px solid var(--accent); display: grid; place-content: center;
  text-align: center; padding: var(--s2); background: var(--surface); }
.stamp b { font-family: var(--font-book); font-size: var(--fs-xl); line-height: 1; color: var(--accent); }
.stamp span { font-size: var(--fs-xs); color: var(--ink-muted); margin-top: 2px; }
.stamp small { font-size: 0.6875rem; color: var(--ink-faint); margin-top: 2px; }
.stamp.next { border-style: dashed; border-color: var(--rule-strong); background: transparent; }
.stamp.next b { color: var(--ink-muted); }
.bookplate {
  position: relative;
  padding: var(--s4) var(--s3);
  border: 1.5px solid var(--ink);
  border-radius: 2px;
  background: var(--surface);
  text-align: center;
  outline: 1px solid var(--rule-strong); outline-offset: -6px;
}
.bookplate .ex { font-family: var(--font-book); font-style: italic; font-size: var(--fs-xs); color: var(--ink-muted); }
.bookplate .bt { font-family: var(--font-book); font-weight: 600; font-size: var(--fs-md); margin: var(--s2) 0; line-height: 1.25; }
.bookplate .bd { font-size: var(--fs-xs); color: var(--ink-faint); }
.bookplate.big { padding: var(--s6) var(--s5); outline-offset: -10px; }
.bookplate.big .bt { font-size: var(--fs-xl); }
.bookplate.big .stats { display: flex; justify-content: center; gap: var(--s5); margin-top: var(--s4); font-size: var(--fs-sm); color: var(--ink-muted); }
.bookplate.big .stats b { display: block; font-family: var(--font-book); font-size: var(--fs-lg); color: var(--ink); font-variant-numeric: oldstyle-nums; }

/* ---------- feedback and contact (views/feedback.js) ---------- */
.feedback .field.check { margin-top: var(--s4); }
.feedback .field.check label { display: flex; gap: var(--s3); align-items: center; font-weight: 400; font-size: var(--fs-md); }
.feedback .field.check input { width: 22px; height: 22px; flex: none; accent-color: var(--accent); }
.feedback .error-text:empty { display: none; }
.contact-card { margin-top: var(--s6); padding: var(--s4); border: 1px solid var(--rule); border-radius: var(--r-md); background: var(--surface); }
.contact-card p { font-size: var(--fs-sm); color: var(--ink-muted); }
.contact-card .address { margin-top: var(--s1); display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--s2) var(--s4); color: var(--ink); }
.contact-card .address a { font-weight: 700; font-size: var(--fs-md); overflow-wrap: anywhere; }

/* ---------- the tour (views/guide.js) ---------- */
.tour { padding: var(--s2) 0 var(--s5); }
/* each step's picture, the same height on every step, so the words and buttons stay put */
.tour-fig { height: 214px; margin: var(--s2) 0 var(--s5); display: flex; flex-direction: column; justify-content: center; align-items: center; gap: var(--s3); }
.tour .h-page { font-size: var(--fs-2xl); line-height: 1.1; text-wrap: balance; }
.tour-text { margin-top: var(--s3); font-size: var(--fs-md); line-height: 1.55; max-width: 34em; }
.tour-text.more { color: var(--ink-muted); font-size: var(--fs-sm); }
.tour-actions { display: flex; gap: var(--s3); margin-top: var(--s6); }
.tour-actions .btn { flex: 1; }
.tour-actions.out { flex-direction: column; max-width: 360px; }
.tour-skip { margin-top: var(--s5); text-align: center; font-size: var(--fs-sm); }
/* a page in the camera's frame */
.tf-photo { position: relative; width: 168px; height: 196px; display: grid; place-items: center; }
.tf-photo .c { position: absolute; width: 26px; height: 26px; border: 3px solid var(--accent); }
.tf-photo .tl { top: 0; left: 0; border-right: 0; border-bottom: 0; border-top-left-radius: 6px; }
.tf-photo .tr { top: 0; right: 0; border-left: 0; border-bottom: 0; border-top-right-radius: 6px; }
.tf-photo .bl { bottom: 0; left: 0; border-right: 0; border-top: 0; border-bottom-left-radius: 6px; }
.tf-photo .br { bottom: 0; right: 0; border-left: 0; border-top: 0; border-bottom-right-radius: 6px; }
.tf-page { width: 124px; height: 156px; padding: 18px 14px; display: flex; flex-direction: column; gap: 9px; background: var(--surface); box-shadow: var(--leaves); border-radius: 2px; }
.tf-page i { display: block; height: 5px; border-radius: 3px; background: var(--rule); }
.tf-page i.lit { height: 9px; margin: -2px 0; background: var(--highlight); }
.tf-shutter { position: absolute; right: -14px; bottom: 22px; display: grid; place-items: center; width: 44px; height: 44px; border-radius: 22px; background: var(--accent); color: var(--accent-ink); box-shadow: var(--paper-shadow); }
.tf-shutter svg { width: 22px; height: 22px; }
/* a passage of the sample page, with its gloss (the welcome screen's: .spec-*) */
.tf-sheet { width: 100%; max-width: 420px; padding: var(--s4) var(--s4) var(--s2); background: var(--surface); box-shadow: var(--leaves); border-radius: 3px; }
.tf-sheet .spec-para { font-size: var(--fs-md); margin-bottom: 0.5em; }
.tf-sheet .spec-gloss { margin-bottom: var(--s2); }
.tf-langs { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; max-width: 420px; }
.tf-langs li { padding: 3px 10px; border: 1px solid var(--rule-strong); border-radius: 999px; font-size: var(--fs-xs); background: var(--surface); }
/* the book screen's buttons, as they look there */
.tf-quick { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); width: 100%; max-width: 360px; }
.tf-btn { display: flex; align-items: center; justify-content: center; gap: var(--s2); min-height: 44px; padding: 0 var(--s3); border: 1px solid var(--rule-strong);
  border-radius: var(--r-md); background: var(--surface); font-weight: 700; font-size: var(--fs-sm); }
.tf-btn svg { width: 18px; height: 18px; flex: none; }
.tf-quick .tf-btn:last-child:nth-child(odd) { grid-column: 1 / -1; }
/* a plant from seed to flower, on one ground */
/* (each canvas is wider than its plant: they stand closer than their canvases) */
.tf-growth { position: relative; display: flex; justify-content: center; align-items: flex-end; width: 100%; max-width: 360px; }
.tf-growth::after { content: ""; position: absolute; inset: auto 0 0 0; height: 1px; background: var(--rule-strong); opacity: 0.55; }
.tf-growth .plant { position: relative; z-index: 1; margin-bottom: -5.9px; }
.tf-growth .plant + .plant { margin-left: -20px; }

/* ---------- each book's plant (garden.js) ---------- */
/* Growing under the book's progress, on a ground line: the plant's ground is 8 of its 160 units
   from its foot, so it stands that much below the row (a seed's root goes into the ground). */
.plant-row { position: relative; display: flex; align-items: flex-end; gap: var(--s4); margin-top: var(--s5); }
.plant-row::after, .garden .g-plant::after {
  content: ""; position: absolute; inset: auto 0 0 0; height: 1px; background: var(--rule-strong); opacity: 0.55;
}
.plant-row .plant, .garden .plant { flex: none; position: relative; z-index: 1; }
.plant-row .plant { margin-bottom: -6.4px; }
.plant-row .pr-text { min-width: 0; padding-bottom: var(--s3); }
.pr-name { font-family: var(--font-book); font-weight: 600; font-size: 1.1875rem; line-height: 1.25; }
.pr-days { margin-top: var(--s1); font-size: var(--fs-sm); }
.pr-next { margin-top: var(--s1); font-size: var(--fs-sm); line-height: 1.45; color: var(--ink-muted); }
/* Progress: the books being read, their plants side by side on one ground, on a sheet */
.garden {
  list-style: none; margin: 0; padding: var(--s3) var(--s2) var(--s4); display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); row-gap: var(--s5);
  background: var(--surface); border: 1px solid var(--rule); border-radius: 4px;
}
.garden a { display: flex; flex-direction: column; align-items: center; height: 100%; text-align: center; color: inherit; text-decoration: none; }
.garden a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-sm); }
.garden .g-plant { position: relative; align-self: stretch; display: flex; justify-content: center; }
.garden .plant { margin-bottom: -5.6px; }
.garden .g-title {
  margin-top: var(--s3); font-family: var(--font-book); font-size: var(--fs-sm); line-height: 1.3;
  overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.garden .g-title.slant { font-style: italic; }
.garden .g-days { margin-top: 2px; font-size: var(--fs-xs); color: var(--ink-muted); }
.garden .g-title, .garden .g-days { padding: 0 var(--s1); }
/* a finished book's, pressed, at the top of its bookplate */
.bookplate .plant { display: block; margin: 0 auto var(--s1); }
.pressed-note { margin: var(--s4) var(--s2) 0; text-align: center; font-size: var(--fs-sm); line-height: 1.45; color: var(--ink-muted); }

.day-picker { display: flex; gap: 6px; flex-wrap: wrap; }
.day-picker button { width: 44px; height: 44px; border-radius: 50%; border: 1.5px solid var(--rule-strong); background: var(--surface); font-weight: 700; font-size: var(--fs-xs); cursor: pointer; }
.day-picker button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* ---------- finish ---------- */
.steps-dots { display: flex; gap: 6px; margin-bottom: var(--s4); }
.steps-dots i { width: 28px; height: 4px; border-radius: 2px; background: var(--rule); }
.steps-dots i.on { background: var(--accent); }
.pick { display: flex; gap: var(--s3); align-items: flex-start; padding: var(--s3) 0; border-top: 1px solid var(--rule); }
.pick input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--accent); flex: none; }
.pick .kind { font-size: var(--fs-xs); color: var(--ink-faint); }

/* ---------- overlays ---------- */
.busy {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center;
  background: var(--bg);
}
.busy .box { text-align: center; padding: var(--s5); max-width: 320px; }
.busy img.thumb { width: 140px; height: 180px; object-fit: cover; border-radius: 4px; box-shadow: var(--paper-shadow); margin: 0 auto var(--s4); }
.busy .scanline { position: relative; width: 140px; height: 180px; margin: 0 auto var(--s4); overflow: hidden; border-radius: 4px; }
.busy .scanline img { width: 100%; height: 100%; object-fit: cover; }
.busy .scanline::after { content: ""; position: absolute; left: 0; right: 0; height: 30%; top: -30%; background: linear-gradient(transparent, var(--highlight), transparent); animation: sweep 1.6s var(--ease) infinite; }
@keyframes sweep { to { top: 100%; } }

/* The camera, in the app: the picture full screen and the controls over it */
.camera { position: fixed; inset: 0; z-index: 65; display: flex; flex-direction: column; justify-content: space-between;
  background: var(--camera-bg); color: var(--camera-ink); }
.camera video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.camera .cam-top, .camera .cam-bottom { position: relative; display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s4); }
.camera .cam-top { justify-content: space-between; padding-top: max(var(--s3), env(safe-area-inset-top)); }
.camera .cam-bottom { flex-direction: column; padding-top: var(--s6); padding-bottom: max(var(--s5), env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--camera-scrim) 35%); }
.camera .cam-hint { text-align: center; font-weight: 700; max-width: 30em; text-shadow: 0 1px 3px var(--camera-bg); }
.camera .cam-row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: var(--s3); width: 100%; max-width: 480px; }
.camera .cam-row > :first-child { justify-self: start; }
.camera .cam-row > :last-child { justify-self: end; }
.camera .cam-row.failed { display: flex; justify-content: center; flex-wrap: wrap; }
.camera .cam-btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--s1); min-height: 44px; padding: 0 var(--s3);
  border: 1px solid var(--camera-line); border-radius: 999px; background: var(--camera-scrim); color: var(--camera-ink); font: inherit; font-size: var(--fs-sm); }
.camera .cam-btn.round { width: 44px; padding: 0; }
.camera .cam-btn[aria-pressed="true"] { background: var(--camera-ink); color: var(--camera-bg); }
.camera .cam-btn svg { width: 20px; height: 20px; }
.camera :focus-visible { outline: 3px solid var(--camera-ready); outline-offset: 3px; }
/* the shutter, its ring filling as the picture holds steady */
.camera .shutter { position: relative; width: 76px; height: 76px; padding: 0; border: 0; border-radius: 50%;
  background: conic-gradient(var(--camera-ready) calc(var(--steady, 0) * 1turn), var(--camera-line) 0); }
.camera .shutter::after { content: ""; position: absolute; inset: 5px; border-radius: 50%; background: var(--camera-ink); border: 3px solid var(--camera-bg); }
.camera .shutter:disabled { opacity: 0.5; }
.camera.taken::before { content: ""; position: absolute; inset: 0; z-index: 1; pointer-events: none; background: var(--camera-ink); animation: flash 350ms ease-out forwards; }
@keyframes flash { from { opacity: 0.8; } to { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .camera.taken::before { animation: none; opacity: 0; } }
.busy p { font-weight: 700; }
.busy .sub { font-weight: 400; color: var(--ink-muted); font-size: var(--fs-sm); margin-top: var(--s1); }
.busy .cancel { margin-top: var(--s4); }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--s4) + env(safe-area-inset-bottom)); z-index: 70;
  transform: translate(-50%, 20px); opacity: 0;
  max-width: min(92vw, 480px);
  padding: var(--s3) var(--s4); border-radius: var(--r-md);
  background: var(--ink); color: var(--bg); font-size: var(--fs-sm); font-weight: 700;
  box-shadow: 0 10px 30px -10px rgb(0 0 0 / 0.5);
  transition: opacity var(--t-med) var(--ease), transform var(--t-med) var(--ease);
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.top { top: calc(var(--s4) + env(safe-area-inset-top)); bottom: auto; transform: translate(-50%, -20px); }
.toast.top.show { transform: translate(-50%, 0); }
/* a sheet that opens while a toast is up: the toast moves out of the way of its buttons */
body:has(.sheet.open) .toast { top: calc(var(--s4) + env(safe-area-inset-top)); bottom: auto; }

/* as wide as the screen allows, up to 400px: a short question still gives its buttons room
   ("Keep editing", 继续编辑, on one line) */
dialog.confirm {
  border: 0; border-radius: var(--r-lg); padding: var(--s5); width: min(92vw, 400px); max-width: min(92vw, 400px);
  background: var(--surface); color: var(--ink); box-shadow: var(--sheet-shadow);
}
/* (a backdrop doesn't see the page's variables in older Safari: the scrim colours as they are) */
dialog.confirm::backdrop { background: rgb(17 22 30 / 0.45); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) dialog.confirm::backdrop { background: rgb(0 0 0 / 0.6); }
}
:root[data-theme="dark"] dialog.confirm::backdrop { background: rgb(0 0 0 / 0.6); }
/* <dialog> before Safari 15.4: shown by ui.js openModal as a fixed panel over a dimmed page */
dialog.modal-shim { display: block; position: fixed; z-index: 81; left: 50%; top: 50%; transform: translate(-50%, -50%);
  margin: 0; max-height: 90vh; overflow: auto; }
.modal-shim-backdrop { position: fixed; inset: 0; z-index: 80; background: var(--scrim); }
dialog.confirm h2 { font-size: var(--fs-lg); margin-bottom: var(--s2); }
dialog.confirm p { color: var(--ink-muted); }
dialog.confirm .form-actions { margin-top: var(--s5); }
dialog.confirm .choices { display: flex; flex-direction: column; gap: var(--s3); margin-top: var(--s5); }
dialog.confirm .choice .help { margin: var(--s1) 0 0; font-size: var(--fs-sm); }
/* the iPhone app's question before anything goes to the AI services (consent.js) */
.ai-consent .ai-list { margin: var(--s2) 0 var(--s3); padding-left: 1.2em; color: var(--ink-muted); }
.ai-consent .ai-list li { margin: var(--s1) 0; }
.ai-consent .small { margin-top: var(--s3); }
/* Legendo Plus (membership.js): the offer, the member's code, the plan in Settings */
.plus-offer p + p, .plus-welcome p + p { margin-top: var(--s2); }
.plus-offer .plus-deal, .plus-box .plus-deal { color: var(--accent); font-weight: 700; margin-top: var(--s2); }
.plus-offer .plus-terms { margin-top: var(--s4); }
.plus-offer .link-btn { margin-top: var(--s2); }
.member-code { display: flex; flex-direction: column; gap: var(--s1); margin: var(--s3) 0; }
.member-code .label { font-weight: 700; font-size: var(--fs-sm); color: var(--ink); }
.member-code-row { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; }
.member-code-row code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: var(--fs-lg); letter-spacing: 0.06em;
  padding: var(--s1) var(--s2); border-radius: var(--r-sm); background: var(--surface-2); color: var(--ink); user-select: all; }
.member-code-row .btn { min-height: 36px; padding: 0 var(--s3); }
.plus-box > p + p { margin-top: var(--s1); }

/* signing in (views/signIn.js) */
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s2); }
.dialog-head .icon-btn { margin: -10px -10px 0 0; flex: none; }
.sign-in .lead { margin: var(--s1) 0 var(--s4); }
.sign-in .ways { display: grid; gap: var(--s3); margin-bottom: var(--s4); }
.sign-in .ways .or { margin-top: var(--s2); }
.sign-in .field + .field { margin-top: var(--s4); }
.sign-in .error-text { color: var(--danger); margin-top: var(--s3); }
.sign-in .error-text:empty { display: none; }
.sign-in .form-actions { margin-top: var(--s4); }
.sign-in .switch { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s5); margin-top: var(--s4); }
.code-input { font-size: var(--fs-xl); letter-spacing: 0.25em; font-variant-numeric: tabular-nums; }
.btn-apple { background: var(--apple-bg); color: var(--apple-ink); }
.link-btn.danger { color: var(--danger); }
/* /auth/done (server/app.py): where signing in comes back to */
.auth-done { padding: var(--s7) 0; }
.auth-done p { margin-top: var(--s3); color: var(--ink-muted); max-width: 34em; }
.auth-done .btn { margin-top: var(--s3); }
.error-box { padding: var(--s4); border-radius: var(--r-md); background: var(--danger-soft); color: var(--ink); }
.error-box p + .btn { margin-top: var(--s3); }

@media (min-width: 720px) {
  .paper { padding: var(--s7) var(--s7) var(--s7) calc(var(--s7) + 6px); padding-top: max(var(--s7), calc(var(--s3) + var(--fs-xs) * 1.3 + var(--s2))); }
  /* (the pencil dots' margin on the right for a page read right to left, as on a phone) */
  .paper.rtl { padding-left: var(--s7); padding-right: calc(var(--s7) + 6px); }
  .para { font-size: calc(1.1875rem * var(--read-scale)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* names of people you've met, inside the page text */
.name { border-bottom: 1px dotted var(--accent); cursor: pointer; }
.name.back { border-bottom: 2px solid var(--pencil); }
.name:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

@media (hover: hover) {
  .btn-secondary:hover { border-color: var(--ink-muted); }
  .btn-ghost:hover { background: var(--accent-soft); }
  .icon-btn:hover { background: var(--surface-2); }
  .sent:hover { background-color: var(--accent-soft); }
  .name:hover { border-bottom-style: solid; }
}

/* ---------- newer CSS, where the browser has it ----------
   Phones still on iOS 15 or early 16 lack dynamic viewport units (Safari 15.4) and color-mix()
   (Safari 16.2). The rules above use plain values; these refine them where supported. */
@supports (height: 1dvh) {
  body { min-height: 100dvh; }
  .sheet { max-height: 86dvh; }
}
@supports (color: color-mix(in srgb, red 50%, blue)) {
  .app-header { background: color-mix(in srgb, var(--bg) 88%, transparent); }
  .btn-danger { border-color: color-mix(in srgb, var(--danger) 50%, var(--rule)); }
  .grades { background: color-mix(in srgb, var(--bg) 92%, transparent); }
  .busy { background: color-mix(in srgb, var(--bg) 92%, transparent); }
  .busy .scanline::after { background: linear-gradient(transparent, color-mix(in srgb, var(--highlight) 70%, transparent), transparent); }
  .name { border-bottom-color: color-mix(in srgb, var(--accent) 55%, transparent); }
  @media (hover: hover) {
    .btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, var(--ink)); }
    .sent:hover { background-color: color-mix(in srgb, var(--highlight) 22%, transparent); }
  }
}

/* Windows high-contrast and other forced-colour modes drop background images, which is how
   a highlighted sentence is drawn; use the system's own highlight colours instead. */
@media (forced-colors: active) {
  .sent.lit, .para.lit .sent, .spec-sent.lit, .spec-name.lit { background: Highlight; color: HighlightText; forced-color-adjust: none; }
  .cover { border: 1px solid CanvasText; }
  .choice[aria-pressed="true"], .choice[aria-checked="true"] { outline: 2px solid Highlight; }
  .page-links [aria-current] { border-color: Highlight; }
  .seg [aria-pressed="true"], .chip[aria-pressed="true"], .keep[aria-pressed="true"] .keep-mark { outline: 2px solid Highlight; }
}

/* the word being read aloud (CSS Custom Highlight API) */
::highlight(spoken-word) { background-color: var(--accent); color: var(--accent-ink); }
