/* Reader view and the reading settings of a lesson or a unit page (the lesson-experience round, unit x-a11y).
   A sheet of its own, linked only from the pages that hold a lesson (tools/courses/render/page.py `head`), so the
   compiled site.css and its SCSS stay as they are. site/js/reading-init.js sets the attributes on the root element
   before the first paint; site/js/reading-settings.js holds the controls. With every setting at its default and Reader
   view off, no rule here changes the page as site.css draws it, but the sheet's own rows. */

@font-face { font-family: "Atkinson Hyperlegible Next"; src: url("fonts/atkinson-next.woff2") format("woff2"); font-weight: 200 800; font-style: normal; font-display: swap; }

/* ---- Text size and Reader view's own size ----
   The lesson's sizes are calc(<px> * var(--text-scale, 1)) (site/scss/_reading-type.scss, _lesson.scss). The page's three steps set
   --text-scale on the root (site/scss/_practice.scss). The fourth step, Huge, and Reader view set it again on the lesson
   alone: the step times the view, so Reader view reads 20 px where the page reads 18 px, at every step. */
:root { --qr-step: 1; --qr-view: 1; }
html[data-text-size="2"] { --qr-step: 1.125; }
html[data-text-size="3"] { --qr-step: 1.25; }
html[data-reading-size="4"] { --qr-step: 1.5; }
html[data-reading-mode="on"] { --qr-view: calc(20 / 18); }
/* The lesson's type tokens (site/scss/_reading-type.scss) are declared on the root, so they hold the root's scale: the
   lesson declares them again under its own, or Huge and Reader view would reach only the words sized from the scale. */
html[data-reading-size="4"] .th.lesson, html[data-reading-mode="on"] .th.lesson {
  --text-scale: calc(var(--qr-step) * var(--qr-view));
  --read-small: calc(15px * var(--text-scale)); --read-body: calc(18px * var(--text-scale)); --read-subhead: calc(22px * var(--text-scale));
  --read-heading: calc(28px * var(--text-scale)); --read-title: calc(36px * var(--text-scale));
}

/* ---- Line spacing: as written, Relaxed, Wide; Reader view opens the lines when the reader chose none ---- */
html[data-reading-spacing="relaxed"] { --qr-leading: 1.8; }
html[data-reading-spacing="wide"] { --qr-leading: 2.1; }
html[data-reading-mode="on"][data-reading-spacing="normal"] { --qr-leading: 1.75; }
html:is([data-reading-spacing="relaxed"], [data-reading-spacing="wide"], [data-reading-mode="on"]) .th.lesson,
html:is([data-reading-spacing="relaxed"], [data-reading-spacing="wide"], [data-reading-mode="on"]) .th.lesson :is(p, li, dd, dt, blockquote, figcaption, .s, .why, .q) { line-height: var(--qr-leading); }

/* ---- Reading font: Atkinson Hyperlegible Next for the lesson's words; mathematics, figures and source keep their own ---- */
html[data-reading-font="atkinson"] :is(.lesson-page, .unit-page) { --ui: "Atkinson Hyperlegible Next", "Hanken Grotesk", sans-serif; --display: "Atkinson Hyperlegible Next", "Hanken Grotesk", sans-serif; }
html[data-reading-font="atkinson"] :is(.lesson-head, .th.lesson),
html[data-reading-font="atkinson"] :is(.lesson-head, .th.lesson) :not(math):not(math *):not(svg):not(svg *):not(code):not(code *):not(pre):not(pre *):not(kbd):not(kbd *):not(samp):not(samp *) { font-family: "Atkinson Hyperlegible Next", "Hanken Grotesk", sans-serif !important; }

/* ---- Higher contrast: every text colour 7:1 or more on its ground, edges 7:1 on the page, in both looks ----
   A page's body redeclares the colours for its own kind (site/scss/_reading-scan.scss on .pg-lesson, unit-read.css on
   .pg-unit-read), so the body takes them too; :is(*, .pg-lesson) gives the rule a class's weight on any body. */
html[data-reading-contrast="on"], html[data-reading-contrast="on"] body:is(*, .pg-lesson) {
  --bg: #FFFFFF; --panel: #FFFFFF; --ink: #000000; --dim: #1F1F1F; --line: #595959;
  --accent: #0B4F2C; --accent-soft: #E3F1E8; --read-bg: #E3F1E8; --read-line: #C4E4D0;
  --ok: #0B4F2C; --okbg: #E3F1E8; --warn: #7A1710; --warnbg: #FDECEB; --mid: #7A1710;
  --rulebg: #FFFFFF; --rule-edge: #0B4F2C; --curve: #0B4F2C; --gold: #5E3D00; --goldbg: #FBF3DF;
  --elements-line: #595959;   /* a table's edge (site/lesson-elements.css) */
}
html[data-theme="dark"][data-reading-contrast="on"], html[data-theme="dark"][data-reading-contrast="on"] body:is(*, .pg-lesson) {
  --bg: #000000; --panel: #000000; --ink: #FFFFFF; --dim: #E6E6E6; --line: #A6A6A6;
  --accent: #8FE3B4; --accent-soft: #0F2A20; --read-bg: #0F2A20; --read-line: #17402F;
  --ok: #8FE3B4; --okbg: #0F2A20; --warn: #FFB4AA; --warnbg: #3A1512; --mid: #FFB4AA;
  --rulebg: #000000; --rule-edge: #8FE3B4; --curve: #8FE3B4; --gold: #F3D58E; --goldbg: #2B2208;
  --elements-line: #A6A6A6;
}

/* ---- Underline links: a link never rests on its colour alone ---- */
html[data-reading-links="on"] :is(main, aside, footer, .crumbs) a { text-decoration-line: underline !important; text-decoration-thickness: from-font; text-underline-offset: .18em; }

/* ---- Motion: the reader's own choice wins over the device's, both ways ----
   Reduce: nothing animates or eases. An animation still ends at once, so a script that waits for its end goes on.
   Full, on a device that asks for less: the bar's progress and a step's entrance ease as they do elsewhere; the figures
   and the voice's scrolling follow the same choice through prefs.js lessMotion. */
html[data-reading-motion="reduce"] *, html[data-reading-motion="reduce"] *::before, html[data-reading-motion="reduce"] *::after { animation-duration: .001ms !important; animation-delay: 0s !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; transition-delay: 0s !important; scroll-behavior: auto !important; }
html[data-reading-motion="reduce"] { scroll-behavior: auto !important; }
@media (prefers-reduced-motion: reduce) {
  html[data-reading-motion="full"] .tp-fill { transition: width .2s ease; }
  html[data-reading-motion="full"] .ex-line:not([hidden]), html[data-reading-motion="full"] section.ex ol.steps > li:not([hidden]) { animation: ex-in 180ms ease-out; }
}

/* ---- Reader view: the lesson alone, in one centred column; Listen and its bar stay ---- */
html[data-reading-mode="on"] body:has(.th.lesson) :is(aside.contents, .toc-fold, .toc-opener, .crumbs, .lesson-head .where, .lesson-end .end-keys, .lesson-end .end-cards, footer.foot) { display: none !important; }
/* The course's rail, its lesson bar and outline key (site/course-navigation.css), the lesson's tag row and its estimates
   leave too: they are ways around the course, not the lesson's words. */
html[data-reading-mode="on"] body:has(.th.lesson) :is(.cn-rail, .cn-bar, .cn-open, .cn-resume, .cn-next, .lesson-head .cc-tag-scroll, .lf-meta) { display: none !important; }
/* The header keeps the mark, the look key, Reading and, under 900 px, the site menu's key, where Reading and the look
   key stand there (site/js/site-navigation.js). Search, the site's links and the other keys leave. */
html[data-reading-mode="on"] body:has(.th.lesson) .top-tools > :not(.theme):not(.reading):not(.sn-menu) { display: none !important; }
html[data-reading-mode="on"] body:has(.th.lesson) header.top > .sn-links { display: none !important; }
html[data-reading-mode="on"] body:has(.th.lesson) .lesson-head .head-keys > :not(.listen):not(.reading-view):not(.reader-view-key) { display: none !important; }
html[data-reading-mode="on"] body:has(.th.lesson) .top { justify-content: space-between; }
html[data-reading-mode="on"] body:has(.th.lesson) .top-tools { margin-left: auto; }
html[data-reading-mode="on"] body:has(.th.lesson) .lay, html[data-reading-mode="on"] body:has(.th.lesson) .lay.with-aside { display: block; max-width: none; margin-left: 0; }
html[data-reading-mode="on"] body:has(.th.lesson) :is(article.lesson-page, article.unit-page) { box-sizing: border-box; max-width: 42rem; margin-inline: auto; }

/* The key under Listen and its status line, in the lesson head's reading row: after Short / Full under 430 px, alone from
   430 px, where Short / Full joins the Start row. The Start row keeps Listen, its link and Short / Full, so it fits at
   every width. At 320 px Short / Full and "Leave reader view" share the row's 288 px with room to spare. */
.lesson-head .reading-view-row { align-items: center; gap: 10px; }
.lesson-head .reading-view-row .reader-view-key { padding: 0 14px; }
.reader-view-key { flex: none; box-sizing: border-box; display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 16px; border: 1px solid var(--accent); border-radius: 999px; background: transparent; color: var(--ink); font: 600 15px/1.2 var(--ui); white-space: nowrap; cursor: pointer; }
.reader-view-key:hover { background: var(--accent-soft); }
.reader-view-key:focus-visible, dialog.prefs .reading-settings :is(select, input):focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
html[data-reading-mode="on"] .reader-view-key { background: var(--accent-soft); }

/* ---- The Reading sheet's rows for these settings (its place, width and three forms stay site.css's) ---- */
dialog.prefs .reading-settings { margin: 10px 0; padding: 8px 0 4px; border-block: 1px solid var(--line); }
dialog.prefs .reading-settings .reader-view-key { width: 100%; margin: 2px 0 8px; }
dialog.prefs .reading-settings > label { flex-wrap: wrap; min-height: 44px; margin: 0; }
dialog.prefs .reading-settings > .rs-choice { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 12px; min-height: 44px; margin: 0; }
dialog.prefs .reading-settings > .rs-choice > label { margin: 0; }
/* The three lists share one width, so their edges line up down the sheet; "As my device asks" is the longest choice. */
dialog.prefs .reading-settings select { box-sizing: border-box; width: 13rem; min-height: 44px; max-width: 100%; padding: 4px 8px; border-color: var(--dim); font: 15px/1.45 var(--ui); }
dialog.prefs .reading-settings .pf-size { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; margin: 4px 0 10px; }
dialog.prefs .reading-settings .pf-size label { min-height: 44px; margin: 0; }
dialog.prefs .reading-settings .rs-note { margin: 0 0 8px; font: 15px/1.45 var(--ui); color: var(--ink); }
dialog.prefs .pf-less { font-size: 15px; color: var(--ink); }
/* The sheet's Short / Full keys (site/js/site-navigation.js) take the panel's ink and edge in both looks: the browser's own
   button colours fall under 4.5:1 on the dark panel. */
dialog.prefs .sn-view button { box-sizing: border-box; min-height: 44px; padding: 0 16px; border: 1px solid var(--dim); border-radius: 999px; background: var(--panel); color: var(--ink); font: 600 15px/1.2 var(--ui); cursor: pointer; }
dialog.prefs .sn-view button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }

/* ---- The line guide: a band over the line being read; it never takes a press and never hides the words ---- */
.reading-line-guide { position: fixed; z-index: 4; left: 0; top: 0; box-sizing: border-box; pointer-events: none; background: rgb(23 111 64 / .12); background: color-mix(in srgb, var(--accent) 12%, transparent); border-block: 2px solid var(--accent); }
.reading-line-guide[hidden] { display: none; }
@media (forced-colors: active) {
  .reading-line-guide { background: transparent; border-block: 2px solid Highlight; }
  .reader-view-key { border-color: ButtonText; }
}
@media print { .reading-line-guide, .reader-view-key { display: none !important; } }
