/* course.css — shared stylesheet for the AI Engineering course.
   Tufte-inspired: serif body, generous margins, readable measure, calm palette.
   Every lesson and reference doc links this file so the course reads as one work. */

:root {
  --ink:        #1a1a1a;
  --ink-soft:   #4a4a4a;
  --ink-faint:  #767676;
  --bg:         #fdfcf9;
  --rule:       #e3e0d8;
  --accent:     #7a1f1f;   /* deep oxblood — links, emphasis */
  --accent-soft:#f3e9e9;
  --accent-bg:  #f7efe9;
  --good:       #1f6b3a;
  --bad:        #9b2226;
  --code-bg:    #f3f1ea;
  --tag-bg:     #efe7dc;
  --card-bg:    #ffffff;   /* tables, quizzes, players, cards */
  --soft-bg:    #f6f4ee;   /* asides, neutral quiz feedback */
  --hover-bg:   #faf8f2;
  --hover-rule: #cfc9bb;
  --good-bg:    #eaf5ee;
  --bad-bg:     #f7eaea;
  --video-tag-bg: #e9eef3;
  --video-tag-fg: #2b5876;
  --buffered:   #e0dbd0;
  --link-rule:  rgba(122,31,31,0.28);
  --shadow:     rgba(0,0,0,0.07);
  --shadow-menu:rgba(0,0,0,0.12);
  --measure:    38rem;      /* ~66 characters */
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans:  ui-sans-serif, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono:  "Cascadia Code", "SF Mono", Consolas, "Liberation Mono", monospace;
}

/* ---- Dark theme ----
   Applied two ways so the switcher (assets/site.js) can pick System / Light / Dark:
   - system preference, unless the user explicitly chose light;
   - explicit choice via data-theme="dark" on <html>. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink:        #e8e4da;
    --ink-soft:   #b8b2a6;
    --ink-faint:  #8a847a;
    --bg:         #171512;
    --rule:       #3a362e;
    --accent:     #d98b7f;   /* oxblood, brightened for dark-bg contrast */
    --accent-soft:#3a2a27;
    --accent-bg:  #2c221f;
    --good:       #7fc99a;
    --bad:        #e39a9d;
    --code-bg:    #24211c;
    --tag-bg:     #2e2a23;
    --card-bg:    #211e1a;
    --soft-bg:    #26231d;
    --hover-bg:   #2a2620;
    --hover-rule: #4d4739;
    --good-bg:    #1d2f24;
    --bad-bg:     #362124;
    --video-tag-bg: #22303b;
    --video-tag-fg: #9fc3dc;
    --buffered:   #3f3a31;
    --link-rule:  rgba(217,139,127,0.35);
    --shadow:     rgba(0,0,0,0.45);
    --shadow-menu:rgba(0,0,0,0.6);
  }
}
:root[data-theme="dark"] {
  --ink:        #e8e4da;
  --ink-soft:   #b8b2a6;
  --ink-faint:  #8a847a;
  --bg:         #171512;
  --rule:       #3a362e;
  --accent:     #d98b7f;
  --accent-soft:#3a2a27;
  --accent-bg:  #2c221f;
  --good:       #7fc99a;
  --bad:        #e39a9d;
  --code-bg:    #24211c;
  --tag-bg:     #2e2a23;
  --card-bg:    #211e1a;
  --soft-bg:    #26231d;
  --hover-bg:   #2a2620;
  --hover-rule: #4d4739;
  --good-bg:    #1d2f24;
  --bad-bg:     #362124;
  --video-tag-bg: #22303b;
  --video-tag-fg: #9fc3dc;
  --buffered:   #3f3a31;
  --link-rule:  rgba(217,139,127,0.35);
  --shadow:     rgba(0,0,0,0.45);
  --shadow-menu:rgba(0,0,0,0.6);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

/* ---- Accessibility ---- */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0.5rem;
  z-index: 100;
  font-family: var(--sans);
  font-size: 0.9rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.5em 1em;
}
.skip-link:focus {
  left: 0.5rem;
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.quiz-options li:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  html { scroll-behavior: auto !important; }
}

body {
  font-family: var(--serif);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.55;
  font-size: 1.125rem;
  margin: 0;
  padding: 3.5rem 1.5rem 6rem;
}

.wrap { max-width: var(--measure); margin: 0 auto; }
.wrap-wide { max-width: 52rem; margin: 0 auto; }

/* ---- Masthead ---- */
.masthead { margin-bottom: 2.5rem; }
.eyebrow {
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0 0 0.6rem;
}
h1 {
  font-weight: 600;
  font-size: 2.1rem;
  line-height: 1.15;
  margin: 0 0 0.4rem;
  letter-spacing: -0.01em;
}
.subtitle {
  font-style: italic;
  color: var(--ink-soft);
  font-size: 1.15rem;
  margin: 0.2rem 0 0;
}

h2 {
  font-weight: 600;
  font-size: 1.4rem;
  margin: 2.6rem 0 0.8rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--rule);
}
h3 { font-weight: 600; font-size: 1.12rem; margin: 1.8rem 0 0.5rem; }

p { margin: 0 0 1.1rem; }
a { color: var(--accent); text-decoration: none; border-bottom: 1px solid var(--link-rule); }
a:hover { border-bottom-color: var(--accent); }

strong { font-weight: 600; }
em { font-style: italic; }

ul, ol { padding-left: 1.4rem; margin: 0 0 1.1rem; }
li { margin: 0.35rem 0; }

code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--code-bg);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}
pre {
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.5;
  background: var(--code-bg);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 1rem 1.1rem;
  overflow-x: auto;
}
pre code { background: none; padding: 0; }

kbd {
  font-family: var(--mono);
  font-size: 0.8em;
  background: var(--card-bg);
  border: 1px solid var(--rule);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0.05em 0.4em;
}

/* ---- Mission tag: ties a lesson to the FDE mission ---- */
.mission-tag {
  display: inline-block;
  font-family: var(--sans);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--tag-bg);
  border-radius: 999px;
  padding: 0.28em 0.8em;
  margin-bottom: 1.2rem;
}

/* ---- Data tables ---- */
.table-wrap { overflow-x: auto; margin: 1.4rem 0; }
table.data {
  border-collapse: collapse;
  width: 100%;
  font-family: var(--sans);
  font-size: 0.88rem;
  background: var(--card-bg);
  border: 1px solid var(--rule);
  border-radius: 10px;
}
table.data th {
  text-align: left;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  padding: 0.6rem 0.9rem;
  border-bottom: 2px solid var(--rule);
}
table.data td {
  padding: 0.55rem 0.9rem;
  border-bottom: 1px solid var(--rule);
}
table.data tr:last-child td { border-bottom: none; }
table.data td.num { font-family: var(--mono); font-size: 0.82rem; white-space: nowrap; }

/* ---- Callouts ---- */
.callout {
  border-left: 3px solid var(--accent);
  background: var(--accent-bg);
  padding: 0.9rem 1.1rem;
  border-radius: 0 8px 8px 0;
  margin: 1.4rem 0;
  font-size: 0.98rem;
}
.callout .label {
  font-family: var(--sans);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  display: block;
  margin-bottom: 0.35rem;
}
.aside {
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--ink-soft);
  background: var(--soft-bg);
  border-radius: 8px;
  padding: 0.8rem 1rem;
  margin: 1.4rem 0;
}
.aside .label {
  font-weight: 600; color: var(--ink); text-transform: uppercase;
  letter-spacing: 0.08em; font-size: 0.68rem; display:block; margin-bottom: 0.3rem;
}
/* Wide screens: asides become true margin notes in the right margin, book-style.
   (Below 68rem they stay inset boxes, which also suits mobile.) */
@media (min-width: 68rem) {
  .aside {
    float: right;
    clear: right;
    width: 14rem;
    margin: 0 -16.5rem 1rem 1rem;
    background: none;
    border-radius: 0;
    border-top: 1px solid var(--rule);
    padding: 0.55rem 0 0;
    font-size: 0.8rem;
    line-height: 1.45;
  }
}

/* ---- Theme switcher (injected by assets/site.js) ---- */
.theme-switch {
  position: fixed;
  top: 0.7rem;
  right: 0.8rem;
  z-index: 80;
  display: flex;
  gap: 0.15rem;
  font-family: var(--sans);
  background: var(--card-bg);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 0.18rem;
  box-shadow: 0 2px 10px var(--shadow);
}
.theme-switch button {
  cursor: pointer;
  border: none;
  background: none;
  color: var(--ink-faint);
  font-size: 0.78rem;
  line-height: 1;
  border-radius: 999px;
  padding: 0.35em 0.55em;
}
.theme-switch button:hover { color: var(--accent); background: var(--hover-bg); }
.theme-switch button.selected { background: var(--accent); color: #fff; }

/* ---- Recommended learning (end-of-lesson section) ---- */
.rec-learning { margin: 2rem 0; }
.rec-learning ul { list-style: none; padding: 0; margin: 0; }
.rec-learning li {
  display: flex;
  gap: 0.7rem;
  align-items: baseline;
  border-bottom: 1px solid var(--rule);
  padding: 0.65rem 0;
}
.rec-learning li:last-child { border-bottom: none; }
.rec-tag {
  flex-shrink: 0;
  font-family: var(--sans);
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 0.2em 0.7em;
  background: var(--tag-bg);
  color: var(--accent);
}
.rec-tag.video { background: var(--video-tag-bg); color: var(--video-tag-fg); }
.rec-learning .rec-title { font-weight: 600; }
.rec-learning .rec-why {
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--ink-soft);
  display: block;
  margin-top: 0.15rem;
}

/* ---- Citations ---- */
sup.cite { font-family: var(--sans); font-size: 0.62rem; line-height: 0; }
sup.cite a { border: none; font-weight: 600; }
.refs { font-family: var(--sans); font-size: 0.82rem; color: var(--ink-soft); }
.refs ol { padding-left: 1.2rem; }
.refs li { margin: 0.3rem 0; }

/* ---- Primary source card ---- */
.primary-source {
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 1.1rem 1.2rem;
  margin: 1.6rem 0;
  background: var(--card-bg);
}
.primary-source .label {
  font-family: var(--sans); font-size: 0.68rem; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--ink-faint); display:block; margin-bottom: 0.4rem;
}
.primary-source .title { font-weight: 600; font-size: 1.05rem; }
.primary-source .why { font-size: 0.92rem; color: var(--ink-soft); margin-top: 0.3rem; }

/* ---- Quiz component (see assets/quiz.js) ---- */
.quiz {
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 1.2rem 1.3rem;
  margin: 1.6rem 0;
  background: var(--card-bg);
}
.quiz-q { font-weight: 600; margin: 0 0 0.9rem; }
.quiz-scenario {
  font-size: 0.92rem; color: var(--ink-soft); font-style: italic;
  margin: 0 0 0.7rem;
}
.quiz-options { list-style: none; padding: 0; margin: 0; }
.quiz-options li {
  font-family: var(--sans);
  font-size: 0.95rem;
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 0.6rem 0.85rem;
  margin: 0.5rem 0;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.quiz-options li:hover { background: var(--hover-bg); border-color: var(--hover-rule); }
.quiz-options li.correct {
  background: var(--good-bg); border-color: var(--good); color: var(--good); cursor: default;
}
.quiz-options li.incorrect {
  background: var(--bad-bg); border-color: var(--bad); color: var(--bad);
}
.quiz-options li.locked { cursor: default; }
.quiz-feedback {
  font-family: var(--sans);
  font-size: 0.9rem;
  margin-top: 0.9rem;
  padding: 0.7rem 0.9rem;
  border-radius: 8px;
  background: var(--soft-bg);
}
.quiz-feedback.right { background: var(--good-bg); color: var(--good); }
.quiz-feedback.wrong { background: var(--bad-bg); color: var(--bad); }

/* ---- Navigation / footer ---- */
.lesson-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: space-between;
  margin-top: 3rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--rule);
  font-family: var(--sans);
  font-size: 0.9rem;
}
.lesson-nav .muted { color: var(--ink-faint); }
.lesson-nav.top {
  margin: 0 0 2rem;
  padding: 0 0 1rem;
  border-top: none;
  border-bottom: 1px solid var(--rule);
  font-size: 0.85rem;
}
.ask-teacher {
  font-family: var(--sans);
  font-size: 0.92rem;
  background: var(--accent-bg);
  border-radius: 10px;
  padding: 1rem 1.2rem;
  margin: 2.2rem 0 0;
  color: var(--ink-soft);
}
.ask-teacher strong { color: var(--accent); }

/* ---- Progress (assets/progress.js; stored in localStorage) ---- */
.time-meta {
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--ink-faint);
  margin: -0.6rem 0 1.2rem;
}
.complete-box {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  font-family: var(--sans);
  font-size: 0.9rem;
  color: var(--ink-soft);
  border: 1px dashed var(--rule);
  border-radius: 10px;
  padding: 0.9rem 1.1rem;
  margin: 2rem 0 0;
}
.complete-box.ready { border-style: solid; border-color: var(--good); }
.complete-box.done { border-style: solid; background: var(--good-bg); color: var(--good); }
.cb-btn {
  cursor: pointer;
  font-family: var(--sans);
  font-size: 0.82rem;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 999px;
  padding: 0.5em 1.2em;
}
.cb-btn:hover { filter: brightness(1.12); }
.complete-box.done .cb-btn { background: none; color: var(--ink-faint); border: 1px solid var(--rule); font-weight: 400; }

.fde-progress-card {
  font-family: var(--sans);
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--card-bg);
  padding: 1rem 1.2rem;
  margin: 1.6rem 0;
}
.pp-row { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; }
.pp-label {
  font-size: 0.7rem; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--accent); font-weight: 600;
}
.pp-stat { font-size: 0.85rem; color: var(--ink-soft); }
.pp-track {
  height: 0.5rem; border-radius: 999px; background: var(--code-bg);
  margin: 0.6rem 0 0.8rem; overflow: hidden;
}
.pp-fill { height: 100%; border-radius: 999px; background: var(--accent); transition: width 0.3s; }
.pp-actions { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.pp-continue {
  font-size: 0.82rem; font-weight: 600; color: #fff !important;
  background: var(--accent); border: none !important; border-radius: 999px; padding: 0.45em 1.1em;
}
.pp-continue:hover { filter: brightness(1.12); }
.pp-finished { font-size: 0.85rem; color: var(--good); font-weight: 600; }
.pp-io {
  cursor: pointer; font-family: var(--sans); font-size: 0.76rem;
  color: var(--ink-faint); background: none;
  border: 1px solid var(--rule); border-radius: 999px; padding: 0.4em 0.9em;
}
.pp-io:hover { color: var(--accent); border-color: var(--accent); }

.toc li.lesson-done { border-color: var(--good); }
.toc li.lesson-done .t::after { content: ""; }
.done-badge {
  display: inline-block; font-size: 0.62rem; font-weight: 700;
  color: var(--good); background: var(--good-bg);
  border-radius: 999px; padding: 0.15em 0.6em; letter-spacing: 0.05em;
}
.review-badge {
  display: inline-block; font-size: 0.62rem; font-weight: 600;
  color: var(--video-tag-fg); background: var(--video-tag-bg);
  border-radius: 999px; padding: 0.15em 0.6em; letter-spacing: 0.03em;
}
.quiz-retry {
  cursor: pointer; font-family: var(--sans); font-size: 0.78rem; font-weight: 600;
  color: var(--accent); background: none; border: 1px solid var(--accent);
  border-radius: 999px; padding: 0.3em 0.9em; margin-left: 0.6em;
}
.quiz-retry:hover { background: var(--accent-bg); }

/* Artifact tracker page */
.artifact-list { list-style: none; padding: 0; margin: 0; font-family: var(--sans); }
.artifact-list li {
  display: flex; gap: 0.8rem; align-items: flex-start;
  border-bottom: 1px solid var(--rule); padding: 0.75rem 0.2rem;
}
.artifact-list li:last-child { border-bottom: none; }
.artifact-list input[type="checkbox"] {
  width: 1.15rem; height: 1.15rem; margin-top: 0.2rem;
  accent-color: var(--accent); cursor: pointer; flex-shrink: 0;
}
.artifact-list .a-name { font-weight: 600; font-size: 0.98rem; }
.artifact-list .a-desc { font-size: 0.85rem; color: var(--ink-soft); display: block; margin-top: 0.15rem; }
.artifact-list li.artifact-done .a-name { color: var(--good); }
.artifact-list li.artifact-done .a-name::after { content: " ✓"; }
#artifact-count {
  font-family: var(--sans); font-size: 0.85rem; font-weight: 600; color: var(--accent);
}

/* ---- Review prompt (copyable AI-review prompt after each lab) ---- */
.review-prompt {
  border: 1px solid var(--rule);
  border-left: 3px solid var(--accent);
  border-radius: 0 10px 10px 0;
  background: var(--card-bg);
  padding: 1rem 1.2rem;
  margin: 1.4rem 0 1.8rem;
  font-family: var(--sans);
}
.review-prompt .label {
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 600;
  display: block;
  margin-bottom: 0.4rem;
}
.review-prompt .rp-intro {
  font-size: 0.88rem;
  color: var(--ink-soft);
  margin: 0 0 0.7rem;
}
.review-prompt pre.rp-text {
  font-size: 0.78rem;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 14rem;
  overflow-y: auto;
  margin: 0 0 0.7rem;
}
.rp-copy {
  cursor: pointer;
  font-family: var(--sans);
  font-size: 0.8rem;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 999px;
  padding: 0.45em 1.1em;
  transition: filter 0.12s;
}
.rp-copy:hover { filter: brightness(1.12); }

/* ---- Reference / glossary layout ---- */
.glossary-term {
  border-bottom: 1px solid var(--rule);
  padding: 0.9rem 0;
}
.glossary-term dt {
  font-weight: 600;
  font-size: 1.05rem;
}
.glossary-term .aka { font-style: italic; color: var(--ink-faint); font-size: 0.9rem; font-weight: 400; }
.glossary-term dd { margin: 0.3rem 0 0; color: var(--ink-soft); font-size: 0.98rem; }

/* ---- Audiobook player (MP3s generated via narration/generate.py) ----
   Sticky: stays pinned below the top edge while the reader scrolls,
   so play/pause/scrub are always reachable during read-along. */
.audio-player {
  position: sticky;
  top: 0.6rem;
  z-index: 40;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--card-bg);
  padding: 0.8rem 1rem;
  margin: 0 0 1.6rem;
  box-shadow: 0 3px 14px var(--shadow);
}
.audio-player .label {
  font-family: var(--sans);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  display: block;
  margin-bottom: 0.45rem;
}
/* Native <audio controls> is the no-JS fallback; audiobook.js hides it and
   builds the custom .p-row player below. */
.audio-player audio { width: 100%; display: block; }
.audio-player audio:not([controls]) { display: none; }

.p-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-family: var(--sans);
}
.p-row button {
  cursor: pointer;
  border: 1px solid var(--rule);
  background: var(--card-bg);
  color: var(--accent);
  transition: border-color 0.12s, background 0.12s, transform 0.12s;
}
.p-row button:hover { border-color: var(--accent); transform: translateY(-1px); }
.p-row button:active { transform: translateY(0); }
.p-play {
  flex-shrink: 0;
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent) !important;
  color: #fff !important;
  border-color: var(--accent) !important;
}
.p-play:hover { filter: brightness(1.12); }
.p-skip {
  flex-shrink: 0;
  font-size: 0.72rem;
  font-weight: 600;
  border-radius: 999px;
  padding: 0.42em 0.6em;
  background: var(--accent-bg);
  white-space: nowrap;
}
.p-skip span { font-size: 0.66rem; margin: 0 0.1em; }
.p-rate-wrap { position: relative; flex-shrink: 0; }
.p-rate {
  font-size: 0.72rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 0.42em 0.65em;
  min-width: 3.2em;
}
.p-rate-menu[hidden] { display: none !important; }
.p-rate-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 0.4rem);
  z-index: 60;
  display: flex;
  flex-direction: column;
  background: var(--card-bg);
  border: 1px solid var(--rule);
  border-radius: 10px;
  box-shadow: 0 6px 22px var(--shadow-menu);
  padding: 0.3rem;
  min-width: 4.6em;
}
.p-rate-item {
  font-size: 0.78rem;
  font-weight: 600;
  text-align: center;
  border: none !important;
  background: none !important;
  color: var(--ink-soft) !important;
  border-radius: 7px !important;
  padding: 0.45em 0.9em;
}
.p-rate-item:hover {
  background: var(--accent-bg) !important;
  color: var(--accent) !important;
  transform: none !important;
}
.p-rate-item.selected {
  background: var(--accent) !important;
  color: #fff !important;
}
.p-time {
  flex-shrink: 0;
  font-size: 0.72rem;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
  min-width: 2.6em;
  text-align: center;
}
.p-track {
  position: relative;
  flex: 1;
  min-width: 3rem;
  height: 0.45rem;
  background: var(--code-bg);
  border-radius: 999px;
  overflow: visible;
}
.p-buffered, .p-played {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  border-radius: 999px;
  width: 0;
  pointer-events: none;
}
.p-buffered { background: var(--buffered); }
.p-played { background: var(--accent); }
/* Invisible native range on top: handles click/drag/keyboard seeking */
.p-seek {
  position: absolute;
  left: 0; top: 50%;
  transform: translateY(-50%);
  width: 100%;
  height: 1.6rem;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
.p-seek:focus-visible { opacity: 1; accent-color: var(--accent); height: 0.45rem; }

/* Narrow screens: controls row wraps, track gets its own full-width line */
@media (max-width: 480px) {
  .p-row { flex-wrap: wrap; row-gap: 0.6rem; }
  .p-track { flex-basis: 100%; order: 10; }
}

/* Read-along highlight (driven by assets/audiobook.js) */
.narrating {
  background: var(--accent-bg);
  border-radius: 6px;
  box-shadow: 0 0 0 7px var(--accent-bg);
  transition: background 0.25s, box-shadow 0.25s;
}

/* ---- Print ---- */
@media print {
  :root { --bg: #fff; }
  body { padding: 0; font-size: 11pt; color: #000; }
  a { color: #000; border: none; }
  .quiz-options li { break-inside: avoid; }
  .lesson-nav, .ask-teacher, .audio-player, .theme-switch { display: none; }
  h2 { break-after: avoid; }
}

@media (max-width: 480px) {
  body { padding: 2rem 1.1rem 4rem; font-size: 1.05rem; }
  h1 { font-size: 1.7rem; }
}

.toc .tmeta {
  display: block;
  font-family: var(--sans);
  font-size: 0.72rem;
  color: var(--ink-faint);
  margin-top: 0.35rem;
}
