/* tilling.io shared styles.
   Layout: catalog = 200px filter rail + card grid; lesson = 290px outline rail + 660px reading column.
   One turquoise accent for actions, the current item and difficulty marks; everything else is neutral. */

:root {
  --bg: #fbfbfa;
  --surface: #ffffff;
  --line: #e6e8e7;
  --line-strong: #d6dad9;
  --ink: #1c1f1f;
  --ink-body: #2c3131;
  --ink-soft: #3d4343;
  --muted: #5f6666;
  --faint: #7b8584;
  --ghost: #c3c9c8;
  --accent: #127a71;
  --accent-deep: #0d5f58;
  --accent-dot: #2aa69a;
  --accent-soft: #e3f3f0;
  --on-accent: #ffffff;
  --bar-off: #dfe3e2;
  --stripe-a: #eef2f1;
  --stripe-b: #e6ecea;
  --danger: #b42318;
  --danger-soft: #fdecea;

  --font-ui: 'Hanken Grotesk', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-read: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  --font-mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  --gutter: 56px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111514;
    --surface: #181d1c;
    --line: #262d2c;
    --line-strong: #34403e;
    --ink: #e7ecea;
    --ink-body: #d2d9d7;
    --ink-soft: #b9c2c0;
    --muted: #9aa5a3;
    --faint: #7d8987;
    --ghost: #4a5654;
    --accent: #4cc2b4;
    --accent-deep: #8fe0d6;
    --accent-dot: #3bb5a8;
    --accent-soft: #163430;
    --on-accent: #08201d;
    --bar-off: #2c3634;
    --stripe-a: #1b2120;
    --stripe-b: #161c1b;
    --danger: #f97066;
    --danger-soft: #3a1c1a;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #111514;
  --surface: #181d1c;
  --line: #262d2c;
  --line-strong: #34403e;
  --ink: #e7ecea;
  --ink-body: #d2d9d7;
  --ink-soft: #b9c2c0;
  --muted: #9aa5a3;
  --faint: #7d8987;
  --ghost: #4a5654;
  --accent: #4cc2b4;
  --accent-deep: #8fe0d6;
  --accent-dot: #3bb5a8;
  --accent-soft: #163430;
  --on-accent: #08201d;
  --bar-off: #2c3634;
  --stripe-a: #1b2120;
  --stripe-b: #161c1b;
  --danger: #f97066;
  --danger-soft: #3a1c1a;
  color-scheme: dark;
}

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-deep); }
button { font: inherit; color: inherit; }
img { max-width: 100%; height: auto; }
h1, h2, h3 { text-wrap: balance; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.gutter {
  padding-left: max(var(--gutter), env(safe-area-inset-left, 0px));
  padding-right: max(var(--gutter), env(safe-area-inset-right, 0px));
}

.label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--faint);
}

/* ---------- Brand + difficulty mark (shared) ---------- */

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 18px;
  color: var(--ink);
}
.brand:hover { color: var(--ink); }
.brand-dot {
  flex: none;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--accent-dot);
}

.level {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
}
.level-bars { display: inline-flex; align-items: flex-end; gap: 3px; }
.level-bars i { width: 4px; border-radius: 1px; background: var(--bar-off); }
.level-bars i:nth-child(1) { height: 8px; }
.level-bars i:nth-child(2) { height: 11px; }
.level-bars i:nth-child(3) { height: 14px; }
.level-bars[data-level="1"] i:nth-child(-n+1),
.level-bars[data-level="2"] i:nth-child(-n+2),
.level-bars[data-level="3"] i { background: var(--accent-dot); }
/* The fourth level fills every bar in the warning colour. */
.level-bars[data-level="4"] i { background: var(--danger); }
.level:has(.level-bars[data-level="4"]) { color: var(--danger); }

/* ---------- Site header (catalog) ---------- */

.site-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding-block: 22px;
  border-bottom: 1px solid var(--line);
}
.site-nav { display: flex; gap: 32px; font-size: 15px; }
.site-nav a { color: var(--ink-soft); }
.site-nav a:hover { color: var(--ink); }
.site-nav a[aria-current="page"] { color: var(--ink); font-weight: 600; }
.menu-btn {
  display: none;
  grid-row: 1;
  grid-column: 2;
  justify-self: end;
  width: 44px; height: 44px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  flex-direction: column;
  justify-content: center;
  align-items: flex-end;
  gap: 5px;
}
.menu-btn span { width: 20px; height: 2px; border-radius: 1px; background: var(--ink); }

/* ---------- Catalog ---------- */

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 24px 40px;
  padding-top: 56px;
  padding-bottom: 36px;
}
.page-head h1 {
  margin: 0;
  font-size: 40px;
  line-height: 1.1;
  font-weight: 600;
  letter-spacing: -.02em;
}
.page-head p { margin: 10px 0 0; font-size: 16px; color: var(--muted); }

.search { width: 360px; max-width: 100%; }
.search input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
}
.search input::placeholder { color: var(--faint); }
.search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.catalog {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  gap: 48px;
  padding-bottom: 72px;
}

.filters { display: flex; flex-direction: column; gap: 32px; font-size: 15px; }
.filter-group { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; min-width: 0; }

.filter-opt,
.topic-opt {
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  text-align: left;
  font-size: 15px;
  color: var(--ink);
}
.filter-opt { display: flex; align-items: center; gap: 10px; }
.filter-opt:hover, .topic-opt:hover { color: var(--accent); }
.filter-opt .box {
  flex: none;
  display: grid;
  place-items: center;
  width: 16px; height: 16px;
  border-radius: 4px;
  border: 1.5px solid var(--ghost);
}
.filter-opt[aria-pressed="true"] .box { background: var(--accent); border-color: var(--accent); }
.filter-opt[aria-pressed="true"] .box::after {
  content: "";
  width: 8px; height: 4px;
  border-left: 2px solid var(--on-accent);
  border-bottom: 2px solid var(--on-accent);
  transform: translateY(-1px) rotate(-45deg);
}
.topic-opt[aria-pressed="true"] { color: var(--accent); font-weight: 600; }

.results { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.results-count { margin: 0; font-size: 14px; color: var(--faint); }

.course-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 20px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.course {
  display: flex;
  flex-direction: column;
  height: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  overflow: hidden;
  color: var(--ink);
  transition: border-color .15s;
}
a.course:hover { color: var(--ink); border-color: var(--accent-dot); }
a.course:hover .course-title { color: var(--accent-deep); }
.course-cover {
  flex: none;
  height: 136px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: repeating-linear-gradient(135deg, var(--stripe-a) 0 10px, var(--stripe-b) 10px 20px);
  font: 11px var(--font-mono);
  color: var(--faint);
  overflow: hidden;
}
.course-cover img { width: 100%; height: 100%; object-fit: cover; }
.course-body { flex: 1; display: flex; flex-direction: column; gap: 10px; padding: 20px 20px 22px; min-width: 0; }
.course-title { font-size: 18px; font-weight: 600; line-height: 1.3; }
.course-desc { font-size: 14px; line-height: 1.5; color: var(--muted); }
.course-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin-top: auto;
  padding-top: 4px;
  font-size: 13px;
  color: var(--faint);
}
.course-meta .soon { color: var(--muted); font-weight: 600; }

.empty { padding-block: 40px; font-size: 15px; color: var(--muted); }
.empty p { margin: 0 0 8px; }
.link-btn { padding: 0; border: 0; background: none; cursor: pointer; color: var(--accent); font-weight: 600; }
.link-btn:hover { color: var(--accent-deep); }

@media (max-width: 1180px) {
  .course-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  :root { --gutter: 20px; }

  .site-header { grid-template-columns: 1fr auto; padding-block: 10px; }
  .brand { font-size: 17px; gap: 8px; }
  .brand-dot { width: 10px; height: 10px; }
  .menu-btn { display: flex; }
  .site-nav { display: none; grid-column: 1 / -1; flex-direction: column; gap: 0; padding-block: 8px; }
  .site-header.is-open .site-nav { display: flex; }
  .site-nav a { padding-block: 12px; font-size: 16px; }

  .page-head { flex-direction: column; align-items: stretch; gap: 16px; padding-top: 24px; padding-bottom: 16px; }
  .page-head h1 { font-size: 30px; }
  .page-head p { margin-top: 6px; font-size: 15px; }
  .search { width: 100%; }
  .search input { padding: 13px 14px; }

  .catalog { grid-template-columns: minmax(0, 1fr); gap: 12px; padding-bottom: 28px; }
  .filters { gap: 8px; }
  .filter-group {
    flex-direction: row;
    gap: 8px;
    overflow-x: auto;
    scrollbar-width: none;
    margin-left: calc(-1 * var(--gutter));
    margin-right: calc(-1 * var(--gutter));
    padding-left: var(--gutter);
    padding-right: var(--gutter);
  }
  .filter-group::-webkit-scrollbar { display: none; }
  .filter-group .label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .filter-opt, .topic-opt {
    flex: none;
    padding: 10px 14px;
    border: 1px solid var(--line-strong);
    border-radius: 999px;
    font-size: 14px;
    white-space: nowrap;
  }
  .filter-opt .box { display: none; }
  .filter-opt[aria-pressed="true"], .topic-opt[aria-pressed="true"] {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent);
    font-weight: 600;
  }

  .results { gap: 8px; }
  .course-grid { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .course {
    flex-direction: row;
    gap: 14px;
    padding-block: 16px;
    border: 0;
    border-top: 1px solid var(--line);
    border-radius: 0;
    background: none;
    overflow: visible;
  }
  .course-cover { width: 72px; height: 72px; border-radius: 8px; font-size: 0; }
  .course-body { gap: 5px; padding: 0; }
  .level { font-size: 12px; }
  .course .level-bars { display: none; }
  .course-title { font-size: 16px; }
  .course-desc { display: none; }
  .course-meta { gap: 0; padding-top: 0; }
  .course-meta span + span::before { content: "\00B7"; margin-inline: 6px; color: var(--faint); font-weight: 400; }
}

/* ---------- Lesson reader ---------- */

.lesson-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-block: 18px;
  padding-left: max(40px, env(safe-area-inset-left, 0px));
  padding-right: max(40px, env(safe-area-inset-right, 0px));
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.crumbs { display: flex; align-items: center; gap: 16px; min-width: 0; font-size: 15px; }
.crumbs .sep { color: var(--ghost); }
.crumbs a:not(.brand), .crumbs .here { color: var(--muted); }
.crumbs a:not(.brand):hover { color: var(--ink); }
.crumbs .here { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lesson-count { font-size: 14px; color: var(--muted); white-space: nowrap; }
.back-link, .contents-btn { display: none; }

.lesson-layout { display: grid; grid-template-columns: 290px minmax(0, 1fr); }

.outline { border-right: 1px solid var(--line); }
.outline-inner {
  position: sticky;
  top: 0;
  max-height: 100vh;
  overflow-y: auto;
  padding: 32px 24px;
}
.outline-head { display: flex; justify-content: space-between; align-items: center; margin: 0 12px 14px; }
.outline-close { display: none; }
.outline ol { display: flex; flex-direction: column; gap: 2px; margin: 0; padding: 0; list-style: none; }
.outline a {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 11px 12px;
  border-radius: 8px;
  color: var(--ink-body);
}
.outline a:hover { background: var(--stripe-a); color: var(--ink); }
.outline-name { font-size: 15px; line-height: 1.35; }
.outline-meta { font-size: 12px; color: var(--faint); }
.outline a[aria-current] { background: var(--accent-soft); }
.outline a[aria-current] .outline-name { color: var(--accent-deep); font-weight: 600; }
.outline a[aria-current] .outline-meta { color: var(--accent); }

.reading { display: flex; justify-content: center; min-width: 0; padding: 60px 40px 72px; }

.prose { width: 100%; max-width: 660px; display: flex; flex-direction: column; gap: 22px; min-width: 0; }
.prose > * { margin: 0; }
.lesson-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; font-size: 14px; color: var(--muted); }
.lesson-meta .level { font-size: 14px; }
.prose h1 { font-size: 44px; line-height: 1.1; font-weight: 600; letter-spacing: -.02em; }
.prose h2 { margin-top: 14px; font-size: 24px; line-height: 1.25; font-weight: 600; letter-spacing: -.01em; }
.prose h3 { margin-top: 6px; font-size: 19px; line-height: 1.3; font-weight: 600; }
.prose p,
.prose li {
  font-family: var(--font-read);
  font-size: 20px;
  line-height: 1.65;
  color: var(--ink-body);
  text-wrap: pretty;
}
.prose ul, .prose ol { display: flex; flex-direction: column; gap: 8px; padding-left: 1.3em; }
.prose li::marker { color: var(--faint); }
.prose p a, .prose li a { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.prose strong { font-weight: 600; color: var(--ink); }
.prose code {
  padding: 2px 5px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  font-family: var(--font-mono);
  font-size: .82em;
}
.prose pre {
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  overflow-x: auto;
  font: 15px/1.6 var(--font-mono);
  color: var(--ink-soft);
}
.prose pre code { padding: 0; border: 0; background: none; font-size: inherit; }
.prose mark {
  padding: 2px 4px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-weight: 600;
}

.example {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px 22px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}
.example-label { font-size: 13px; font-weight: 600; color: var(--faint); }
.example-sample { font: 17px/1.5 var(--font-mono); color: var(--muted); overflow-wrap: anywhere; }
.example-note { font-size: 15px; line-height: 1.5; color: var(--ink-soft); }

.prose > .lesson-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-top: 28px;
  padding-top: 28px;
  border-top: 1px solid var(--line);
}
.prev-link { display: flex; flex-direction: column; gap: 4px; color: var(--ink); }
.prev-link:hover { color: var(--accent-deep); }
.prev-link small { font-size: 13px; color: var(--faint); }
.prev-link span { font-size: 16px; font-weight: 600; }
.next-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 20px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 15px;
  font-weight: 600;
  text-align: center;
}
.next-btn:hover { background: var(--accent-deep); color: var(--on-accent); }

/* ---------- Lesson components ---------- */

/* Demo: a framed interactive panel. */
.demo {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  overflow: hidden;
}
.demo-head { display: flex; flex-direction: column; gap: 2px; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.demo-title { font-size: 16px; font-weight: 600; line-height: 1.35; color: var(--ink); }
.demo-body { container-type: inline-size; display: flex; flex-direction: column; gap: 20px; padding: 20px; }
.prose .demo-text { margin: 0; font-family: var(--font-ui); font-size: 15px; line-height: 1.55; color: var(--ink-soft); }

/* Note: a set-apart aside inside the reading column. */
.note {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 20px 22px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}
.note-title { font-size: 17px; font-weight: 600; line-height: 1.35; color: var(--ink); }
.prose .note p { margin: 0; font-size: 18px; line-height: 1.6; }

/* Steps: an ordered process with numbered markers. */
.prose ol.steps { gap: 22px; padding: 0; list-style: none; counter-reset: step; }
.steps > li {
  counter-increment: step;
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  gap: 4px 16px;
}
.steps > li::before {
  content: counter(step);
  grid-row: span 2;
  display: grid;
  place-items: center;
  width: 32px; height: 32px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  font: 600 14px var(--font-mono);
  color: var(--accent);
}
.step-title { align-self: center; font-family: var(--font-ui); font-size: 17px; font-weight: 600; line-height: 1.35; color: var(--ink); }
.step-text { font-size: 18px; line-height: 1.6; }

/* Tables scroll inside their own frame on narrow screens. */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.prose table { width: 100%; min-width: 520px; border-collapse: collapse; font-size: 15px; }
.prose th {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--faint);
}
.prose td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: top; line-height: 1.45; color: var(--ink-soft); }
.prose tr:last-child td { border-bottom: 0; }
.prose td:first-child { font-weight: 500; color: var(--ink); }

.pill {
  display: inline-block;
  padding: 2px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  color: var(--muted);
}
.pill-secret, .pill-pass { border-color: transparent; background: var(--accent-soft); color: var(--accent-deep); }
.pill-fail { border-color: transparent; background: var(--danger-soft); color: var(--danger); }

/* Checks: a list of pass/fail results. */
.prose ol.checks {
  gap: 0;
  padding: 0;
  list-style: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}
.checks > li {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  gap: 2px 12px;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
}
.checks > li:first-child { border-top: 0; }
.checks .pill { grid-row: span 2; align-self: start; justify-self: start; margin-top: 1px; }
.check-title { font-family: var(--font-ui); font-size: 15px; font-weight: 600; line-height: 1.35; color: var(--ink); }
.check-detail { font-family: var(--font-ui); font-size: 14px; line-height: 1.5; color: var(--muted); }

/* Controls */
.slider { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.slider-label { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; font-weight: 500; color: var(--ink-soft); }
.slider-value { font-family: var(--font-mono); color: var(--accent); font-variant-numeric: tabular-nums; }
.slider input[type="range"] { width: 100%; margin: 0; accent-color: var(--accent); cursor: pointer; }

.segmented { display: flex; flex-wrap: wrap; gap: 8px; }
.segmented button {
  padding: 8px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: none;
  cursor: pointer;
  font-size: 14px;
  color: var(--ink);
}
.segmented button:hover { border-color: var(--accent); color: var(--accent); }
.segmented button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }

.result {
  padding: 12px 16px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-size: 15px;
  font-weight: 600;
  text-align: center;
}

.result.is-fail { background: var(--danger-soft); color: var(--danger); }

.segmented.is-small { gap: 4px; }
.segmented.is-small button { padding: 5px 10px; font-size: 13px; }

/* Choices: answer buttons for quizzes and predictions. */
.choices { display: flex; flex-direction: column; gap: 8px; }
.choice {
  display: block;
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  text-align: left;
  font-size: 15px;
  line-height: 1.4;
  color: var(--ink);
}
.choice:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.choice:disabled { cursor: default; }
.choice.is-right { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-deep); font-weight: 600; }
.choice.is-wrong { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); }
.choice:disabled:not(.is-right):not(.is-wrong) { opacity: .55; }

.btn-secondary {
  align-self: flex-start;
  padding: 9px 16px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink-soft); cursor: pointer; }
.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
.prose .demo-output { margin: 0; font-size: 14px; line-height: 1.5; color: var(--muted); }

/* Worked calculations: a grid of small blocks showing each side's arithmetic. */
.math-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.math-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}
.math-keys { display: flex; flex-wrap: wrap; gap: 12px 20px; }
.math-keys .slider { flex: 1 1 120px; }
.math-eq { font: 15px/1.9 var(--font-mono); color: var(--ink); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.math-send { padding-top: 8px; border-top: 1px solid var(--line); font: 600 14px var(--font-mono); color: var(--ink-soft); }
.prose .preset-note { margin: 0; font-family: var(--font-ui); font-size: 14px; line-height: 1.5; color: var(--muted); }

@container (max-width: 540px) {
  .math-grid { grid-template-columns: minmax(0, 1fr); }
}

/* Plots drawn on a canvas. */
.plot {
  display: block;
  width: 100%;
  max-width: 100%;
  aspect-ratio: 4 / 3;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}
.plot-square { aspect-ratio: 1; max-width: 520px; margin-inline: auto; }

@media (max-width: 1040px) {
  .lesson-layout { grid-template-columns: 250px minmax(0, 1fr); }
  .reading { padding: 48px 32px 64px; }
  .prose h1 { font-size: 38px; }
}

@media (max-width: 860px) {
  body.lesson::before {
    content: "";
    position: fixed;
    inset: 0 0 auto;
    height: env(safe-area-inset-top, 0px);
    z-index: 10;
    background: var(--bg);
  }
  .lesson-header {
    position: sticky;
    top: env(safe-area-inset-top, 0px);
    z-index: 5;
    display: grid;
    grid-template-columns: 44px 1fr auto;
    padding-block: 10px;
    padding-left: max(8px, env(safe-area-inset-left, 0px));
    padding-right: max(12px, env(safe-area-inset-right, 0px));
  }
  .crumbs { display: none; }
  .back-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px; height: 44px;
    font-size: 20px;
    color: var(--ink);
  }
  .lesson-count { text-align: center; }
  .contents-btn {
    display: flex;
    align-items: center;
    height: 44px;
    padding: 0 10px;
    border: 0;
    background: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: var(--accent);
  }

  .lesson-layout { grid-template-columns: minmax(0, 1fr); }
  .outline {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 20;
    overflow-y: auto;
    border: 0;
    background: var(--bg);
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .outline.is-open { display: block; }
  body.outline-open { overflow: hidden; }
  .outline-inner {
    position: static;
    max-height: none;
    padding-top: 10px;
    padding-bottom: 32px;
    padding-left: max(20px, env(safe-area-inset-left, 0px));
    padding-right: max(20px, env(safe-area-inset-right, 0px));
  }
  .outline-head { margin: 0 0 8px 12px; }
  .outline-close {
    display: flex;
    align-items: center;
    height: 44px;
    padding: 0 10px;
    border: 0;
    background: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: var(--accent);
  }

  .reading {
    padding-top: 28px;
    padding-bottom: 0;
    padding-left: max(20px, env(safe-area-inset-left, 0px));
    padding-right: max(20px, env(safe-area-inset-right, 0px));
  }
  .prose { gap: 18px; }
  .lesson-meta { gap: 14px; font-size: 13px; }
  .lesson-meta .level { font-size: 13px; }
  .prose h1 { font-size: 30px; line-height: 1.15; }
  .prose h2 { margin-top: 8px; font-size: 21px; }
  .prose p, .prose li { font-size: 18px; line-height: 1.6; }
  .prose h2[id] { scroll-margin-top: 80px; }
  .example { padding: 16px 18px; }
  .example-sample { font-size: 15px; }
  .demo-head { padding: 12px 16px; }
  .demo-body { padding: 16px; }
  .note { padding: 16px 18px; }
  .prose .note p, .step-text { font-size: 17px; }

  .prose > .lesson-nav {
    position: sticky;
    bottom: 0;
    margin-top: 12px;
    margin-left: calc(-1 * max(20px, env(safe-area-inset-left, 0px)));
    margin-right: calc(-1 * max(20px, env(safe-area-inset-right, 0px)));
    padding-top: 12px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    padding-left: max(20px, env(safe-area-inset-left, 0px));
    padding-right: max(20px, env(safe-area-inset-right, 0px));
    background: var(--bg);
  }
  .prev-link { display: none; }
  .next-btn { flex: 1; height: 50px; font-size: 16px; }
  .next-btn .arrow { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
