/* reader.css — reading-experience layer for the AI Engineer study site.
 *
 * Deployment-layer enhancement (same pipeline as resume.js /
 * pull-refresh.js: ships only in the Cloudflare deployment, re-applied
 * by sync-site.sh via apply-reader.py, which injects the <link> for
 * this file plus the reader.js <script> tag and a pre-paint theme
 * script into index.html).
 *
 * What lives here:
 * - Theme palettes keyed off html[data-theme="light"|"dark"], set by
 *   the pre-paint script / reader.js (Light / System / Dark modes).
 *   The base stylesheet defines light vars on :root (specificity
 *   0,1,0) and dark vars under @media (prefers-color-scheme:dark)
 *   (also 0,1,0 — a media query adds no specificity). The attribute
 *   selectors below are (0,1,1) and this file loads after the base
 *   <style>, so a manual choice beats the OS media query in BOTH
 *   directions: manual Light wins on a dark OS, manual Dark wins on
 *   a light OS. color-scheme is pinned the same way so scrollbars
 *   and form controls follow the chosen theme, not the OS.
 * - Book-like reading typography for the week view (.md only).
 * - Summary / checkpoint blockquotes as soft rounded cards; bold
 *   inside cards gets a mustard brush-stroke double underline (the
 *   exact SVG technique from the approved preview); bold in body
 *   text gets a soft marker-highlight tint.
 * - Pagination chrome (sticky reader bar, segmented progress, pager)
 *   and the compact theme / size controls.
 */

/* ---------- theme palettes (site's own values) ---------- */
html[data-theme="light"] {
  color-scheme: light;
  --paper: #f5f3ec;
  --ink: #20231f;
  --muted: #62685f;
  --panel: #fffdf7;
  --rule: #c9c8be;
  --accent: #c54f36;
  --accent2: #176e65;
  --soft: #e7e2d5;
  --code: #171b1a;
  --codeInk: #dce8df;
  --shadow: 0 18px 50px rgba(37, 35, 29, .09);
  --reader-marker: #f7e9b0;
  --reader-teal-bg: #e3efea;
  --reader-teal-border: #bcd8d0;
  --reader-terra-bg: #f7e8dd;
  --reader-terra-border: #ecc9b4;
  --reader-seg-off: #ddd6c2;
}
html[data-theme="dark"] {
  color-scheme: dark;
  --paper: #151816;
  --ink: #eef0e8;
  --muted: #aeb5aa;
  --panel: #1d211e;
  --rule: #3b413c;
  --accent: #ff7b5f;
  --accent2: #5cc8b9;
  --soft: #292e2a;
  --code: #0b0e0d;
  --codeInk: #dce8df;
  --shadow: 0 18px 50px rgba(0, 0, 0, .25);
  --reader-marker: rgba(227, 179, 65, .32);
  --reader-teal-bg: #1d211e;
  --reader-teal-border: #35544c;
  --reader-terra-bg: #292e2a;
  --reader-terra-border: #5a4038;
  --reader-seg-off: #363c37;
}

/* ---------- reading typography (week view only) ---------- */
#week .md {
  font-size: 20px;
  line-height: 1.75;
  max-width: 720px;
  margin-left: auto;
  margin-right: auto;
}
html[data-size="large"] #week .md { font-size: 23px; }
#week .md p { max-width: none; }
#week .md ul, #week .md ol { max-width: none; }
#week .md h2 { font-size: 34px; line-height: 1.15; }
#week .md h3 { font-size: 26px; line-height: 1.2; }
#week .md table { direction: ltr; text-align: left; }
#week .md .code { direction: ltr; text-align: left; max-width: none; }
#week .md pre, #week .md code { direction: ltr; }
.reader-tablewrap { overflow-x: auto; max-width: 100%; }
.reader-tablewrap table { margin-top: 0; margin-bottom: 0; }

/* Body bold: soft marker-highlight tint (no wash inside cards — see below). */
#week .md strong {
  background: var(--reader-marker);
  padding: .02em .28em;
  border-radius: 4px;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}

/* ---------- summary / checkpoint cards ---------- */
#week .md blockquote {
  border: 1px solid var(--reader-teal-border);
  border-radius: 14px;
  background: var(--reader-teal-bg);
  padding: 22px 24px;
  box-shadow: var(--shadow);
  max-width: none;
}
#week .md blockquote.checkpoint {
  background: var(--reader-terra-bg);
  border-color: var(--reader-terra-border);
}
/* Card bold: NO background wash — a mustard brush-stroke double
 * underline. Two smooth tapered arcs (filled SVG paths), one
 * continuous stroke stretched across the whole phrase
 * (background-size:100%, no-repeat, preserveAspectRatio="none"),
 * re-drawn per line fragment on wrapped phrases via
 * box-decoration-break:clone. Lifted exactly from the approved
 * reading-experience preview. */
#week .md blockquote strong {
  background-color: transparent;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 10' preserveAspectRatio='none'%3E%3Cpath d='M1 3.2 C30 1 70 1 99 3.2 C70 4.8 30 4.8 1 3.2 Z' fill='%23d9a419'/%3E%3Cpath d='M10 7.4 C32 5.6 66 5.6 90 7.4 C66 8.8 32 8.8 10 7.4 Z' fill='%23d9a419'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 0 100%;
  background-size: 100% .36em;
  padding: 0 0 .2em;
  border-radius: 0;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}
html[data-theme="dark"] #week .md blockquote strong {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 10' preserveAspectRatio='none'%3E%3Cpath d='M1 3.2 C30 1 70 1 99 3.2 C70 4.8 30 4.8 1 3.2 Z' fill='%23e3b341'/%3E%3Cpath d='M10 7.4 C32 5.6 66 5.6 90 7.4 C66 8.8 32 8.8 10 7.4 Z' fill='%23e3b341'/%3E%3C/svg%3E");
}

/* ---------- pagination ---------- */
.reader-page { display: none; }
.reader-page.active { display: block; }
.reader-hidden { display: none !important; }
/* A markdown "---" separator that lands as a page's last element is a
 * stray rule line floating above the pager — hide it. Mid-page rules
 * (not the last element child) still render normally. */
.reader-page > hr:last-child { display: none; }

/* ---------- sticky reader bar: label left, controls right ---------- */
.reader-bar {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
  padding: 10px 0 8px;
  margin-bottom: 6px;
}
.reader-bar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.reader-where {
  font-family: "IBM Plex Mono", monospace;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 0 1 auto;
}
/* The bar label is a button: it toggles the section jump menu.
 * It keeps the .reader-where text styling (mono, muted, ellipsis)
 * on its inner span; the button itself is a bare reset so the bar
 * layout is unchanged. */
.reader-where-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 1 auto;
  min-width: 0;
  margin: 0;
  padding: 4px 2px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
  text-align: left;
}
.reader-where-btn:focus-visible { outline: 2px solid var(--accent2); outline-offset: 2px; }
.reader-where-caret { flex: none; font-size: 12px; color: var(--muted); }
.reader-controls { display: flex; align-items: center; gap: 6px; flex: none; margin-left: auto; }
.reader-pill {
  display: flex;
  border: 1px solid var(--rule);
  border-radius: 99px;
  overflow: hidden;
  background: var(--panel);
}
.reader-pill button {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-family: "IBM Plex Mono", monospace;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1;
  padding: 5px 8px;
  white-space: nowrap;
}
.reader-pill button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.reader-pill button:focus-visible { outline: 2px solid var(--accent2); outline-offset: -2px; }

/* ---------- segmented progress ---------- */
.reader-segments { display: flex; gap: 6px; margin-top: 8px; }
.reader-segments button {
  flex: 1;
  height: 22px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
}
.reader-segments button i {
  display: block;
  width: 100%;
  height: 4px;
  border-radius: 99px;
  background: var(--reader-seg-off);
  transition: background .25s ease;
}
.reader-segments button.done i, .reader-segments button.now i { background: var(--accent2); }
.reader-segments button:focus-visible { outline: 2px solid var(--accent2); outline-offset: 2px; border-radius: 6px; }

/* ---------- section jump menu ----------
 * Panel anchored under the sticky bar (the bar is sticky, i.e.
 * positioned, so the absolute panel hangs from its bottom edge)
 * and overlays the content below. Solid panel background, card
 * radius/shadow, theme variables throughout so Light/Dark both
 * follow. Rows are >=44px tap targets with 15px titles; long
 * titles truncate with ellipsis. Earlier sections are dimmed
 * with a check mark; the current section is highlighted. */
.reader-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  max-width: 560px;
  max-height: 60vh;
  overflow-y: auto;
  margin-top: 4px;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 14px;
  box-shadow: var(--shadow);
  z-index: 5;
}
.reader-menu.open { display: block; }
.reader-menu-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  margin: 0;
  padding: 8px 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  cursor: pointer;
  text-align: left;
}
.reader-menu-row:hover { background: var(--soft); }
.reader-menu-row:focus-visible { outline: 2px solid var(--accent2); outline-offset: -2px; }
.reader-menu-num {
  flex: none;
  min-width: 2ch;
  text-align: right;
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  color: var(--muted);
}
.reader-menu-title {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reader-menu-row.done .reader-menu-title { color: var(--muted); }
.reader-menu-row.current { background: var(--soft); }
.reader-menu-row.current .reader-menu-title { font-weight: 700; }
.reader-menu-mark {
  flex: none;
  width: 1em;
  text-align: center;
  font-size: 12px;
  color: var(--accent2);
}

/* ---------- pager (top of article + bottom of page) ---------- */
.reader-pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 720px;
  margin: 0 auto;
  padding: 14px 0;
}
.reader-pager button {
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 99px;
  padding: 9px 16px;
  border: 1px solid var(--rule);
  background: var(--panel);
  color: var(--ink);
  white-space: nowrap;
}
.reader-pager button.reader-next { background: var(--ink); color: var(--paper); border-color: transparent; }
.reader-pager button:disabled { opacity: .32; cursor: default; }
.reader-pager button:focus-visible { outline: 2px solid var(--accent2); outline-offset: 2px; }
.reader-count {
  font-family: "IBM Plex Mono", monospace;
  font-size: 12.5px;
  color: var(--muted);
  text-align: center;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reader-pager-bottom { border-top: 1px solid var(--rule); margin-top: 18px; }

/* ---------- site-wide 12px legibility floor ----------
 * 2026-10-25 raised the reader bar's own chrome to 12px+; the rest of
 * the site's chrome still sat at 10–11px (overview stat labels and
 * chips, week objectives, code-bar labels and copy buttons, pitfall
 * leads, pager buttons, quiz toggles, table headers, chapter-jump
 * links, code-library counts, the reading meta line, and code
 * blocks on narrow phones). Those rules live in the artifact's
 * inline <style>, which this deployment layer must not hand-edit,
 * so the floor is enforced here instead: this file loads after
 * the base <style>, so equal-specificity rules below win. Sizes
 * only — no layout, spacing, or color changes. */
.brief dt { font-size: 12px; }
.chip { font-size: 12px; }
.objective { font-size: 12px; }
.code-label { font-size: 12px; }
.copy { font-size: 12px; }
.pitfall b { font-size: 12px; }
.week-nav button, .primary { font-size: 12px; }
.quiz-card button { font-size: 12px; }
.md th { font-size: 12px; }
.chapter-jump a { font-size: 12px; }
.lib-top-count { font-size: 12px; }
.lib-top-meta { font-size: 12px; }
.reading-meta { font-size: 12px; }
@media (max-width: 900px) {
  .mobile-select { font-size: 12px; }
}
@media (max-width: 600px) {
  /* Specificity matters here: the base rule is `.md .code pre`
   * (0,2,1), so a bare `.code pre` override loses and code stayed
   * 11px on phones. Match the selector and the later file wins. */
  .md .code pre { font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .reader-segments button i { transition: none; }
}

/* ---------- mobile: the bar parks under the app rail ----------
 * At <=900px the base stylesheet makes .rail a sticky top header
 * (position:sticky; top:0; z-index:4; opaque panel background;
 * ~130px of week select + view tools). This bar is sticky at
 * top:0 with z-index:3, so while scrolling it slid underneath
 * the rail and stayed completely hidden — no section indicator
 * was ever visible on a phone. reader.js measures the rail's
 * height in this layout and sets the bar's sticky top offset
 * inline (bar.style.top), parking the bar directly under the
 * rail for the whole scroll. The rules here slim the bar down
 * in this layout (it shares the frozen stack with the rail) and
 * give it a quiet frosted-glass finish so content passing under
 * it reads as background, not clutter. The translucent
 * background is gated on backdrop-filter support; without it
 * the bar keeps its solid paper background. */
@media (max-width: 900px) {
  .reader-bar { padding: 7px 0 6px; }
  .reader-segments { margin-top: 6px; }
  .reader-segments button { height: 18px; }
  .reader-pill button { padding: 5px 6px; }
  @supports (backdrop-filter: blur(8px)) or (-webkit-backdrop-filter: blur(8px)) {
    .reader-bar {
      background: color-mix(in srgb, var(--paper) 85%, transparent);
      -webkit-backdrop-filter: blur(8px);
      backdrop-filter: blur(8px);
    }
  }
}
