/* alevel.css — see docs/ALEVEL.md §5. Brand tokens from app.css only; everything works at 360 px.
   Prefixes: .course-switch + .topnav-more (student top bar: the two-course switch and its "More" menu) ·
   .al-* A Level shell and pages (page header, mastery chips, home, course map, progress) · rich-text additions
   (render.js: code blocks, logic figures, callout-exam, table scrollers) · .al-editor (editor.js) · .hl-* syntax
   colours (highlight.js, shared by code blocks and the editor). Practice, exam-style questions and mock papers (the
   hub and the paper runner): alevel-study.css; lesson additions, question cards and flashcards: alevel-lesson.css;
   code lab, exercises and tools: alevel-code.css. */

/* `hidden` must win over component display rules. */
.al-page [hidden], .al-home [hidden], .al-learn [hidden], .al-progress [hidden], .al-rich [hidden],
.al-editor [hidden], .al-setup [hidden], .al-goal-form [hidden], .topnav-more-menu[hidden] { display: none !important; }

/* =========================================================================
   Top bar: course switch + "More"
   ========================================================================= */
.course-switch-slot { display: flex; flex: none; }
.course-switch-slot:empty { display: none; }
.course-switch { display: inline-flex; gap: 2px; padding: 3px; border: 1px solid var(--line); border-radius: 999px; background: var(--bg); }
.course-switch-link {
  display: inline-flex; align-items: center; min-height: 30px; padding: 0 11px; border-radius: 999px;
  color: var(--muted); font-size: 13px; font-weight: 700; text-decoration: none; white-space: nowrap;
}
.course-switch-link:hover { color: var(--ink); }
.course-switch-link.active { background: var(--card); color: var(--brand-dark); box-shadow: var(--shadow); }
/* The switch takes the place of the name (it is in the log-out button's tooltip and on the home page). */
.topbar.has-course-switch .topbar-name { display: none; }
@media (max-width: 760px) {
  .course-switch-slot { margin-left: auto; }
  .topbar.has-course-switch .topbar-user { margin-left: 0; }
}
@media (max-width: 480px) {
  .topbar.has-course-switch .brand-text { display: none; }
  .topbar.has-course-switch .topbar-inner { gap: 10px; }
  .course-switch-link { padding: 0 10px; }
}

.topnav-more { position: relative; display: inline-flex; }
.topnav-more-btn { border: 0; background: none; font-family: inherit; cursor: pointer; }
.topnav-more-menu {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 35; min-width: 200px; padding: 6px;
  display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.topnav-more-link { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; color: var(--ink); font-size: 14px; font-weight: 600; text-decoration: none; }
.topnav-more-link:hover { background: var(--bg); }
.topnav-more-link.active { background: var(--brand-soft); color: var(--brand-dark); }
/* The SAT nav when it has more links than fit (app.js navSpec: beside the switch, or eight without it): Tasks, Progress
   and Leaderboard stay in the bar from 1220 px (app.css .topbar-inner), in "More" below. */
.topnav-more.is-narrow { display: none; }
@media (max-width: 1219.98px) {
  .topnav-wide-only { display: none; }
  .topnav-more.is-narrow { display: inline-flex; }
}

/* =========================================================================
   Shared page parts
   ========================================================================= */
.al-empty-icon { width: 60px; height: 60px; margin: 0 auto 12px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: flex; align-items: center; justify-content: center; }
.al-off .empty .small { margin-top: -6px; }

.al-head-text { min-width: 0; }
.al-crumbs ol { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 2px 0; font-size: 13px; color: var(--muted); }
.al-crumbs li { display: inline-flex; align-items: center; min-width: 0; overflow-wrap: anywhere; }
.al-crumbs a { color: var(--brand-dark); font-weight: 700; text-decoration: none; }
.al-crumbs a:hover { text-decoration: underline; }
.al-crumbs [aria-current] { color: var(--ink); font-weight: 600; }
.al-crumb-sep { margin: 0 7px; color: var(--faint); }

/* mastery chips (§6.1; the label is always written out) */
.al-chip { display: inline-flex; align-items: center; justify-content: center; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; background: var(--fill); color: var(--muted); }
.al-chip-learning { background: var(--bad-soft); color: var(--bad-text); }
.al-chip-developing { background: var(--warn-soft); color: var(--warn-text); }
.al-chip-secure { background: var(--info-soft); color: var(--info-text); }
.al-chip-ready { background: var(--ok-soft); color: var(--ok-text); }
.al-legend-list .al-chip { min-width: 96px; }

/* progress bars with a target line */
.al-bar { position: relative; height: 10px; overflow: visible; }
.al-bar > span { border-radius: 999px; }
.al-bar.is-ok > span { background: var(--ok); }
.al-bar.is-partial > span { opacity: .45; }
.al-bar-target { position: absolute; top: -4px; bottom: -4px; width: 3px; margin-left: -1.5px; border-radius: 2px; background: var(--ink); }
.al-key-target { display: inline-block; width: 3px; height: 12px; margin-right: 6px; border-radius: 2px; background: var(--ink); vertical-align: -1px; }

/* radio cards (AS / A Level) and the grade picker */
.al-choice-group, .al-seg-group { border: 0; margin: 0; padding: 0; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.al-choice-group > legend, .al-seg-group > legend { padding: 0; margin-bottom: 8px; }
.al-choice { display: flex; align-items: flex-start; gap: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); cursor: pointer; transition: border-color .15s, background .15s; }
.al-choice:hover { border-color: var(--line-strong); }
.al-choice input { flex: none; width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--brand); }
.al-choice:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.al-choice-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.al-choice-title { font-weight: 700; font-size: 15px; }
.al-choice-desc { font-size: 13px; color: var(--muted); }
.al-seg { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; max-width: 360px; }
.al-seg-opt { position: relative; display: block; }
.al-seg-opt input { position: absolute; top: 0; left: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.al-seg-opt span { display: flex; align-items: center; justify-content: center; min-height: 42px; border: 1px solid var(--line-input); border-radius: 10px; background: var(--card); font-size: 15px; font-weight: 800; }
.al-seg-opt input:checked + span { background: var(--brand); border-color: var(--brand); color: #fff; }
.al-seg-opt input:focus-visible + span { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
.al-seg-opt input:disabled { cursor: not-allowed; }
.al-seg-opt input:disabled + span { opacity: .4; text-decoration: line-through; }
.al-seg-group .field-hint:empty { display: none; }

/* tables that become cards on phones (data-label on the cells) */
.al-stack-table tbody th, .al-stack-table tfoot th { font-size: 14px; font-weight: 700; color: var(--ink); text-transform: none; letter-spacing: 0; white-space: normal; background: none; }
.al-stack-table th .muted { font-weight: 500; }
.al-stack-table tfoot td, .al-stack-table tfoot th { border-top: 2px solid var(--line); }
.al-stack-table tbody tr:last-child th { border-bottom: 0; }
.al-row-action { text-align: right; white-space: nowrap; }
@media (max-width: 760px) {
  .al-stack-wrap { overflow: visible; }
  .al-stack-table thead { display: none; }
  .al-stack-table, .al-stack-table tbody, .al-stack-table tfoot { display: block; width: 100%; }
  .al-stack-table tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
  .al-stack-table tr:last-child { border-bottom: 0; }
  .al-stack-table td, .al-stack-table th { display: block; padding: 0; border: 0; text-align: left; white-space: normal; }
  .al-stack-table .num { text-align: left; }
  .al-stack-table td[data-label]::before { content: attr(data-label); display: block; margin-bottom: 2px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
  .al-stack-table tbody th, .al-stack-table tfoot th, .al-stack-table .al-row-action { grid-column: 1 / -1; }
  .al-stack-table .al-row-action { text-align: left; }
  .al-stack-table tfoot td, .al-stack-table tfoot th { border-top: 0; }
  .al-stack-table tfoot tr { border-top: 2px solid var(--line); }
  .card-body .al-stack-table tr { padding-left: 0; padding-right: 0; }
}

/* =========================================================================
   Home (#/alevel/cs)
   ========================================================================= */
.al-home { display: flex; flex-direction: column; gap: 20px; }
.al-home > .page-head { margin-bottom: 0; }
.al-home-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.al-home-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; align-items: start; }
@media (max-width: 900px) { .al-home-grid { grid-template-columns: minmax(0, 1fr); } }
.al-plan .plan-goal-gap { line-height: 1.45; }
.al-plan .plan-title:focus:not(:focus-visible) { outline: none; } /* focused after the first-visit setup */
[aria-busy="true"] > .al-home { opacity: .6; transition: opacity .15s; } /* fresh data on its way (home.js quiet load) */

/* first visit */
.al-setup { border-color: var(--brand-line); background: linear-gradient(135deg, var(--brand-soft), var(--card) 60%); }
.al-setup-head { display: flex; align-items: flex-start; gap: 14px; margin-bottom: 18px; }
.al-setup-icon { flex: none; width: 48px; height: 48px; border-radius: 14px; background: var(--brand); color: #fff; display: inline-flex; align-items: center; justify-content: center; }
.al-setup-title { font-size: 20px; margin: 2px 0 4px; }
.al-setup-head p { margin: 0; max-width: 560px; }
.al-setup-form { max-width: 560px; }
.al-setup-form .notice, .al-goal-form .notice { margin: 0; }
.al-setup-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.al-setup-after { margin: 0; }
.al-goal-form .input-group .btn, .al-setup-form .input-group .btn { flex: none; }
@media (max-width: 480px) {
  .al-setup-head { flex-direction: column; gap: 10px; }
  .al-setup-actions .btn { flex: 1 1 100%; }
}

/* estimated grade */
.al-grade-top { display: flex; align-items: flex-start; gap: 16px; }
.al-grade-letter {
  flex: none; min-width: 72px; height: 72px; padding: 0 10px; border-radius: 18px; background: var(--brand-soft); color: var(--brand-dark);
  display: inline-flex; align-items: center; justify-content: center; font-size: 38px; font-weight: 800; letter-spacing: -.02em;
}
.al-grade-letter.is-met { background: var(--ok-soft); color: var(--ok-text); }
.al-grade-sum { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.al-grade-sum p { margin: 0; }
.al-grade-line { font-size: 15px; }
.al-grade-none { margin: 0; }
.al-grade-note { margin: 14px 0 0; }
.al-reasons { margin: 12px 0 0; padding-left: 1.2em; display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.al-grade-sum .al-reasons { margin-top: 4px; }
@media (max-width: 420px) { .al-grade-letter { min-width: 60px; height: 60px; font-size: 32px; } .al-grade-top { gap: 12px; } }

/* paper readiness */
.al-ready-list { display: flex; flex-direction: column; gap: 18px; }
.al-ready-top { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 2px 12px; margin-bottom: 7px; font-size: 14px; }
.al-ready-name { min-width: 0; overflow-wrap: anywhere; }
.al-ready-val { font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.al-ready-val.is-partial { color: var(--muted); font-weight: 600; }
.al-ready-notes { margin-top: 7px; font-size: 12.5px; color: var(--muted); }

/* continue learning */
.al-continue .card-body { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.al-continue-title { margin: 0; font-size: 19px; overflow-wrap: anywhere; }
.al-continue .card-body > p { margin: 0; }
.al-continue-summary { font-size: 14px; }
.al-continue-actions { gap: 8px; margin-top: 6px; }

/* weakest subtopics */
.al-focus-list { list-style: none; margin: 0; padding: 4px 18px; }
.al-focus-item { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 10px; padding: 12px 0; border-bottom: 1px dashed var(--line); }
.al-focus-item:last-child { border-bottom: 0; }
.al-focus-main { display: flex; flex-direction: column; gap: 4px; flex: 1 1 200px; min-width: 0; }
.al-focus-name { font-weight: 700; font-size: 14px; overflow-wrap: anywhere; }
.al-focus-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: 12.5px; color: var(--muted); }
.al-focus-links { display: flex; flex-wrap: wrap; gap: 2px; margin-right: -8px; }
.al-focus-links .btn { padding: 0 8px; }
.al-focus-none { margin: 0 0 12px; }

/* =========================================================================
   Course map (#/alevel/cs/learn) — builds on learn.css (.learn-*)
   ========================================================================= */
.al-learn-tools { display: flex; justify-content: flex-end; margin: -6px 0 -10px; }
.al-level { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.al-level-head .section-title { margin: 0; }
.al-level-head p { margin: 2px 0 0; }
.al-paper .card-header { align-items: flex-start; }
.al-paper .learn-group-head p.al-paper-note { margin-top: 4px; }
.al-topics { display: flex; flex-direction: column; gap: 8px; padding: 12px; }
.al-topic { border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
.al-topic.is-open { border-color: var(--line-strong); }
.al-topic-toggle {
  width: 100%; min-height: 58px; display: grid; grid-template-columns: 32px minmax(0, 1fr) auto 18px; align-items: center; gap: 12px;
  padding: 10px 12px; border: 0; border-radius: 12px; background: none; color: var(--ink); font: inherit; text-align: left; cursor: pointer;
}
.al-topic-toggle:hover { background: var(--bg); }
.al-topic-num { width: 32px; height: 32px; border-radius: 8px; background: var(--brand-soft); color: var(--brand-dark); display: inline-flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 800; font-variant-numeric: tabular-nums; }
.al-topic-main { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.al-topic-title { font-size: 15px; font-weight: 700; line-height: 1.3; overflow-wrap: anywhere; }
.al-topic-meta { font-size: 12.5px; color: var(--muted); }
.al-topic-ring { min-width: 44px; height: 26px; padding: 0 8px; border-radius: 999px; background: var(--fill); color: var(--muted); display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.al-topic-ring.is-done { min-width: 26px; padding: 0; background: var(--ok); color: var(--on-status); }
.al-topic-chev { color: var(--muted); transition: transform .15s; }
.al-topic.is-open .al-topic-chev, .al-fold.is-open > .al-fold-toggle .al-topic-chev { transform: rotate(180deg); }
.al-topic-body { display: flex; flex-direction: column; gap: 16px; padding: 14px 12px 14px; border-top: 1px solid var(--line); }
.al-sub { scroll-margin-top: calc(var(--topbar-h) + 16px); border-radius: 10px; }
.al-sub.is-target { box-shadow: 0 0 0 3px rgba(252, 91, 32, .18); padding: 8px; margin: -8px; }
.al-sub-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; margin-bottom: 8px; }
.al-sub-title { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.al-sub-title h4 { margin: 0; font-size: 14.5px; font-weight: 700; overflow-wrap: anywhere; }
.al-sub-id { color: var(--brand-dark); font-variant-numeric: tabular-nums; }
.al-sub-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.al-sub-links { display: flex; gap: 2px; margin-right: -8px; }
.al-sub-links .btn { padding: 0 8px; }
.al-sub-none { margin: 0; }
.al-fold-toggle {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px;
  border: 1px dashed var(--line-strong); border-radius: var(--radius); background: var(--card); color: var(--ink); font: inherit; text-align: left; cursor: pointer;
}
.al-fold-toggle:hover { border-color: var(--brand); background: var(--brand-soft); }
.al-fold-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.al-fold-text strong { font-size: 16px; }
.al-fold-body { display: flex; flex-direction: column; gap: 16px; }
@media (max-width: 480px) {
  .al-topics { padding: 8px; }
  .al-topic-toggle { grid-template-columns: 28px minmax(0, 1fr) auto 18px; gap: 10px; padding: 10px; }
  .al-topic-num { width: 28px; height: 28px; font-size: 13px; }
  .al-topic-body { padding: 12px 10px; }
}

/* =========================================================================
   Progress (#/alevel/cs/progress)
   ========================================================================= */
.al-progress > .page-head { margin-bottom: 0; }
.al-kpis .kpi-value { font-size: 26px; }
.al-ladder { display: flex; flex-direction: column; gap: 8px; }
.al-ladder p { margin: 0; }
.al-sub-h { margin: 0; font-size: 14px; }
.al-ladder-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 6px; }
.al-ladder-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); font-size: 14px; }
.al-ladder-grade { min-width: 26px; font-weight: 800; }
.al-ladder-pct { font-variant-numeric: tabular-nums; }
.al-ladder-row.is-you { border-color: var(--brand); background: var(--brand-soft); }
.al-ladder-row.is-target { grid-column: 1 / -1; border-style: dashed; border-color: var(--ink); }
.al-ladder-row.is-reached { border-style: solid; border-color: var(--ok); background: var(--ok-soft); }
.al-mock-chart p { margin: 6px 0 0; }
.al-prog-h { margin: 8px 0 0; }
.al-prog-lead { margin: -10px 0 0; }
.al-prog-paper-head { flex-wrap: wrap; align-items: center; }
.al-prog-paper-head h2 { font-size: 16px; }
.al-prog-paper-note { margin-top: 2px; max-width: 640px; }
.al-prog-paper-bar { flex: 0 1 220px; min-width: 120px; }
.al-prog-table td { white-space: nowrap; }
.al-prog-table tbody th.al-prog-name { min-width: 200px; }
.al-prog-table .al-prog-topic th { padding: 8px 12px; background: var(--bg); font-size: 13.5px; }
.al-prog-table .al-prog-topic .al-topic-num { width: 24px; height: 24px; margin-right: 4px; border-radius: 6px; font-size: 12px; vertical-align: middle; }
.al-prog-mastery { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
/* one <tbody> per topic: keep the line under each topic's last row (app.css drops it on every tbody's last row) */
@media (min-width: 760.02px) {
  .al-prog-table tbody:not(:last-child) tr:last-child > * { border-bottom: 1px solid var(--line); }
}
@media (max-width: 760px) {
  .al-prog-table tbody:not(:last-child) tr:last-child { border-bottom: 1px solid var(--line); }
  .al-prog-table tr.al-prog-topic { display: block; padding: 0; border-bottom: 0; }
  .al-prog-table tr.al-prog-topic th { display: block; padding: 8px 16px; }
  .al-prog-table tbody th.al-prog-name { min-width: 0; }
}

/* =========================================================================
   Rich text additions (render.js)
   ========================================================================= */
/* code blocks: a bar with the language, Copy and "Run in Code lab" over the highlighted, selectable code */
.al-code { margin: 1.1em 0; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); overflow: hidden; font-size: 15px; line-height: 1.4; }
.al-code-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 40px; padding: 4px 6px 4px 12px; border-bottom: 1px solid var(--line); background: var(--bg); font-family: var(--font); }
.al-code-lang { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.al-code-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; }
.al-code-btn { display: inline-flex; align-items: center; gap: 5px; min-height: 32px; padding: 0 10px; border: 1px solid transparent; border-radius: 8px; background: none; color: var(--ink); font: inherit; font-size: 13px; font-weight: 700; white-space: nowrap; cursor: pointer; }
.al-code-btn:hover { background: var(--card); border-color: var(--line); }
.al-code-run { color: var(--brand-dark); }
.al-rich pre.code, .al-code pre {
  margin: 0; padding: 12px 14px; overflow-x: auto; -webkit-overflow-scrolling: touch; background: none; color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-size: 14px; line-height: 1.55;
  white-space: pre; tab-size: 4; -moz-tab-size: 4; overflow-wrap: normal; word-break: normal; user-select: text; -webkit-user-select: text;
}
.al-code pre:focus-visible { outline-offset: -3px; }

/* syntax colours (highlight.js); the dark values are in the "Dark theme" section at the end */
:root { --al-hl-kw: #b3261e; --al-hl-type: #1e3a8a; --al-hl-fn: #1d4ed8; --al-hl-str: #137a40; --al-hl-num: #8a5a00; }
.hl-kw { color: var(--al-hl-kw); font-weight: 700; }
.hl-type { color: var(--al-hl-type); font-weight: 600; }
.hl-fn { color: var(--al-hl-fn); }
.hl-str { color: var(--al-hl-str); }
.hl-num { color: var(--al-hl-num); }
.hl-com { color: var(--muted); font-style: italic; }
.hl-op { color: var(--ink); font-weight: 700; }

/* logic circuits (figure.logic) and their truth tables */
.al-rich figure.logic { margin: 1.1em 0; padding: 14px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); text-align: center; }
.al-logic-svg { color: var(--ink); overflow-x: auto; }
.al-logic-svg svg { display: inline-block; max-width: 100%; height: auto; }
.al-rich figure.logic .al-table { display: inline-block; max-width: 100%; margin: 12px 0 0; vertical-align: top; }
.al-rich .al-table table.al-truth { width: auto; margin: 0; font-variant-numeric: tabular-nums; }
.al-rich .al-table .al-truth th, .al-rich .al-table .al-truth td { min-width: 2.75em; padding: 5px 10px; text-align: center; }
.al-rich .al-table .al-truth caption { text-align: center; }
.al-rich .al-truth .al-truth-out { background: var(--brand-soft); font-weight: 700; }
.al-rich figure.logic figcaption { margin-top: 8px; }
.al-logic-error { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border-radius: 8px; background: var(--warn-soft); color: var(--warn-text-strong); font-size: 14px; text-align: left; }
.al-logic-error .icon { flex: none; margin-top: 2px; }
.al-logic-expr { display: block; margin-top: 4px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; overflow-wrap: anywhere; }

/* tables in their own horizontal scroller (in lessons learn.css .lsn-table styles them further). Cells keep whole words:
   app.css .rich breaks anywhere, which let a wide table shrink to one letter per line on a phone instead of scrolling. */
.al-rich .al-table { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.al-rich .al-table > table { margin: .6em 0; }
.al-rich .al-table th, .al-rich .al-table td { overflow-wrap: normal; }

/* Callouts outside lessons (practice explanations, exam questions), in the SAT lesson geometry. :where() keeps these
   rules weaker than learn.css .lsn-body .callout, so inside a lesson the boxes look exactly like the SAT ones; the
   icon is placed by learn.css .lsn-callout-icon everywhere. .callout-exam is A Level only: it wins in lessons too. */
:where(.al-rich) .callout { position: relative; margin: 1em 0; padding: 14px 16px 14px 48px; border: 1px solid var(--brand-line); border-radius: 12px; background: var(--brand-soft); line-height: 1.55; }
:where(.al-rich) .callout > :last-child { margin-bottom: 0; }
:where(.al-rich) .callout-tip { background: var(--ok-soft); border-color: var(--ok-line); }
:where(.al-rich) .callout-tip .al-callout-icon { color: var(--ok); }
:where(.al-rich) .callout-trap { background: var(--bad-soft); border-color: var(--bad-line); }
:where(.al-rich) .callout-trap .al-callout-icon { color: var(--bad); }
.al-rich .callout-exam { background: var(--info-soft); border-color: var(--info-line); }
.al-rich .callout-exam .al-callout-icon { color: var(--info); }
@media (max-width: 400px) { :where(.al-rich) .callout { padding: 12px 14px 12px 42px; } }

/* =========================================================================
   Code editor (editor.js): a transparent textarea over a highlighted copy
   ========================================================================= */
.al-editor {
  --al-ed-lh: 1.5em; --al-ed-pad: 12px; --al-ed-digits: 2;
  position: relative; display: flex; align-items: stretch; overflow: hidden; border: 1px solid var(--line-input); border-radius: 10px; background: var(--card);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-size: 16px; line-height: var(--al-ed-lh);
}
/* 16 px on touch screens (iOS zooms into smaller text fields); 14 px with a mouse. */
@media (hover: hover) and (pointer: fine) { .al-editor { font-size: 14px; } }
.al-editor:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(252, 91, 32, .18); }
.al-editor.is-readonly { background: var(--surface-2); }
.al-editor-gutter {
  flex: none; position: relative; overflow: hidden; min-width: calc(var(--al-ed-digits) * 1ch + 20px); padding: var(--al-ed-pad) 8px var(--al-ed-pad) 10px;
  border-right: 1px solid var(--line); background: var(--bg); color: var(--muted); text-align: right; user-select: none; -webkit-user-select: none;
}
.al-editor-nums { white-space: pre; font: inherit; line-height: var(--al-ed-lh); }
.al-editor-main { position: relative; flex: 1; min-width: 0; }
.al-editor-hl, .al-editor-input {
  margin: 0; padding: var(--al-ed-pad) 14px; border: 0; border-radius: 0; font: inherit; font-size: 1em; line-height: var(--al-ed-lh);
  letter-spacing: normal; word-spacing: normal; text-transform: none; text-indent: 0; tab-size: 4; -moz-tab-size: 4;
  white-space: pre; overflow-wrap: normal; word-break: normal; font-variant-ligatures: none; font-feature-settings: "liga" 0, "calt" 0;
}
.al-editor-hl { position: absolute; top: 0; right: 0; bottom: 0; left: 0; overflow: hidden; pointer-events: none; background: transparent; color: var(--ink); }
.al-editor-code { display: block; font: inherit; }
/* Bold and italic can change a glyph's width in some fonts: the copy keeps the textarea's metrics exactly. */
.al-editor-hl [class^="hl-"] { font-weight: inherit; font-style: inherit; }
.al-editor-input {
  position: relative; display: block; width: 100%; min-height: calc(var(--al-ed-lh) + 2 * var(--al-ed-pad)); resize: none;
  overflow-x: auto; overflow-y: hidden; background: transparent; color: transparent; -webkit-text-fill-color: transparent;
  caret-color: var(--ink); outline: none; box-shadow: none; -webkit-appearance: none; appearance: none;
}
.al-editor-input::selection { background: rgba(37, 99, 235, .25); color: transparent; -webkit-text-fill-color: transparent; }
.al-editor.is-plain .al-editor-hl { display: none; }
.al-editor.is-plain .al-editor-input { color: var(--ink); -webkit-text-fill-color: var(--ink); }
.al-editor.is-plain .al-editor-input::selection { color: var(--ink); -webkit-text-fill-color: var(--ink); }
.al-editor-esc { position: absolute; right: 8px; bottom: 6px; z-index: 1; padding: 2px 8px; border-radius: 6px; background: var(--ink); color: var(--on-ink); font-family: var(--font); font-size: 12px; font-weight: 600; line-height: 1.5; pointer-events: none; }

/* =========================================================================
   Print: the page content only
   ========================================================================= */
@media print {
  body[data-course="alevel"] .topbar, body[data-course="alevel"] .bottomnav, body[data-course="alevel"] .brand-footer,
  .al-code-actions, .al-learn-tools, .al-sub-links, .al-focus-links, .al-row-action, .al-home .plan-step-btn,
  .al-home .plan-goal-edit, .al-setup-actions, .al-editor-esc { display: none !important; }
  body[data-course="alevel"] .page-content { padding: 0; max-width: none; }
  .al-home .card, .al-progress .card, .al-learn .card, .al-code, .al-rich figure.logic { box-shadow: none; break-inside: avoid; }
  .al-learn .al-topic-body[hidden], .al-learn .al-fold-body[hidden] { display: flex !important; }
  .al-code pre, .al-rich pre.code { white-space: pre-wrap; overflow: visible; }
  .al-home-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .al-home a, .al-progress a, .al-learn a { color: inherit; text-decoration: none; }
}

/* ---------- Dark theme ---------- */
/* the active course: the card colour is the top bar's in dark, and the shadow does not show */
:root[data-theme="dark"] .course-switch-link.active { background: var(--fill); box-shadow: inset 0 0 0 1px var(--line-strong); }
/* Everything above is coloured with app.css tokens; only the syntax colours need their own dark values (light ones
   would be dark-on-dark). Kept distinct per role and >= 7:1 on --card, --surface-2 and --bg. */
:root[data-theme="dark"] { --al-hl-kw: #ff8f87; --al-hl-type: #a9b4ff; --al-hl-fn: #6cb6ff; --al-hl-str: #7ee0a1; --al-hl-num: #f2c25c; }
