:root {
    --primary-color: #2c3e50;
    --secondary-color: #3498db;
    --accent-color: #e74c3c;
    --bg-light: #f8f9fa;
    --bg-highlight: #fff3cd;
    --bg-insight: #d1ecf1;
    --border-color: #dee2e6;
}

/* Mobile hamburger from the navbar partial — not wired on desktop, hide it */
.navbar-toggle { display: none; }

* { box-sizing: border-box; }

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 1.25rem;
    line-height: 1.8;
    margin: 0;
    padding: 0;
    color: #333;
    background-color: #fff;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Layout — edge-to-edge presentation style */
.container {
    flex: 1;
    width: 100%;
    padding: 2rem 3rem;
}

/* Main Content */
.main-content {
    width: 100%;
}

/* Figures — responsive, centered, stacked on mobile */
.main-content img {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 1.25rem auto;
    border-radius: 4px;
}
.main-content p:has(> img) {
    text-align: center;
}
.main-content p:has(> img) + p {
    text-align: center;
}
/* Optional side-by-side figure rows: flex on wide screens, stack on mobile */
.main-content .figure-row {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    justify-content: center;
    align-items: flex-start;
    margin: 1.25rem 0;
}
.main-content .figure-row > * {
    flex: 1 1 320px;
}

/* Navbar */
.navbar {
    background-color: var(--primary-color);
    color: white;
    padding: 1rem 4rem 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.navbar-brand { font-size: 1.2rem; font-weight: bold; }
.navbar-brand a { color: white; text-decoration: none; }

.navbar-nav { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }

/* Nav Dropdowns */
.nav-dropdown { position: relative; }
.nav-dropdown-btn {
    color: #ecf0f1;
    background: none;
    border: 1px solid rgba(255,255,255,0.3);
    padding: 0.4rem 0.8rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    transition: all 0.2s;
    white-space: nowrap;
}
.nav-dropdown-btn:hover { background-color: rgba(255,255,255,0.1); border-color: var(--secondary-color); }
.nav-dropdown-btn::after { content: '\25BC'; font-size: 0.65rem; }
.nav-dropdown-btn.video-btn { border-color: rgba(255,0,0,0.5); }
.nav-dropdown-btn.video-btn:hover { border-color: #ff0000; background-color: rgba(255,0,0,0.15); }

.nav-dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 0.5rem;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    min-width: 280px;
    max-height: 400px;
    overflow-y: auto;
    display: none;
    z-index: 1001;
}
.nav-dropdown-menu.show { display: block; }

.nav-dropdown-menu .nav-list { list-style: none; padding: 0.5rem 0; margin: 0; }
.nav-dropdown-menu .nav-item { margin: 0; }
.nav-dropdown-menu .nav-link {
    display: block;
    padding: 0.5rem 1rem;
    color: var(--primary-color);
    text-decoration: none;
    font-size: 0.9rem;
    border-left: 3px solid transparent;
    transition: all 0.2s;
}
.nav-dropdown-menu .nav-link:hover,
.nav-dropdown-menu .nav-link.active {
    background-color: var(--bg-light);
    border-left-color: var(--secondary-color);
    color: var(--secondary-color);
}
.nav-dropdown-menu .nav-link.external::after {
    content: ' \2197';
    font-size: 0.75rem;
    opacity: 0.6;
}

/* Dark Mode Toggle Button */
.theme-toggle {
    color: #ecf0f1;
    background: none;
    border: 1px solid rgba(255,255,255,0.3);
    padding: 0.4rem 0.8rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
    white-space: nowrap;
}
.theme-toggle:hover { background-color: rgba(255,255,255,0.1); border-color: var(--secondary-color); }

/* Floating Navigation Buttons */
.float-nav {
    position: fixed;
    right: 2rem;
    bottom: 2rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 999;
    opacity: 0;
    transition: opacity 0.35s ease;
    pointer-events: auto;
}
.float-nav:hover, .float-nav:focus-within { opacity: 1; }

.float-nav-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    transition: all 0.3s;
}

.float-nav-btn:hover {
    background-color: var(--secondary-color);
    transform: scale(1.1);
}

.float-nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.float-nav-btn:disabled:hover {
    transform: none;
    background-color: var(--primary-color);
}

/* Navigation Arrows */
.page-nav {
    display: flex;
    justify-content: space-between;
    margin-top: 4rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border-color);
}
.nav-btn {
    text-decoration: none;
    color: var(--primary-color);
    border: 1px solid var(--border-color);
    padding: 0.8rem 1.5rem;
    border-radius: 6px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.nav-btn:hover { background-color: var(--bg-light); border-color: var(--secondary-color); }
.nav-btn.disabled { opacity: 0.5; pointer-events: none; }

/* Content Styles — presentation scale */
h1 {
    color: var(--primary-color);
    border-bottom: 3px solid var(--secondary-color);
    padding-bottom: 0.5rem;
    margin-top: 2rem;
    font-size: 2.5rem;
}
.title-home-link {
    color: inherit;
    text-decoration: none;
}
.title-home-link:hover {
    opacity: 0.8;
}
h2 { color: var(--primary-color); border-bottom: 2px solid var(--border-color); padding-bottom: 0.3rem; margin-top: 2.5rem; scroll-margin-top: 80px; font-size: 2rem; }
h3 { color: var(--secondary-color); margin-top: 1.5rem; scroll-margin-top: 80px; font-size: 1.5rem; }

/* Coloured callouts — each block uses a left-accent strip and a 50%
 * transparent background tinted from the same hue family. The 50% alpha
 * lets the page's parchment / dark-canvas show through, so the block
 * reads as a tinted region of the page rather than a hard-edged card.
 * Learning Objectives uses orange (per user feedback 2026-05-15);
 * Context Pause warm yellow, Insight Note cool cyan, Definition
 * wedgwood blue. */

.learning-objectives { background-color: rgba(255, 240, 220, 0.3); border-left: 6px solid #f79009; padding: 1.5rem 2rem; margin: 2rem 0; border-radius: 0 8px 8px 0; font-size: 1.2rem; }
.learning-objectives ol { margin: 0.5rem 0; padding-left: 1.5rem; }

.context-pause { background-color: rgba(255, 243, 205, 0.3); border-left: 6px solid #ffc107; padding: 1.5rem 2rem; margin: 2rem 0; border-radius: 0 8px 8px 0; }
.context-pause::before { content: "Context Pause"; font-weight: bold; display: block; margin-bottom: 0.5rem; color: #856404; font-size: 1.3rem; }
/* Sidebar layout: context-pause + insight-note take the right third and
 * let body text wrap around. Only these two float (definitions etc. stay
 * full-width — they're load-bearing reading). Mobile reverts to stack. */
.context-pause,
.insight-note {
    float: right;
    clear: right;
    width: 33%;
    margin: 0 0 1rem 1.5rem;
}
h2, h3 { clear: right; }
/* BFC for full-width block callouts so they shrink beside the floated
 * sidebars instead of letting their background extend under the float. */
.definition,
.example,
.problem,
.try-it-now,
.learning-objectives,
.key-terminology,
.problem-set,
.important-rule {
    display: flow-root;
}

/* Callout + definition pairing — see style-bookshelf.css for the
 * canonical comment. The Phase A fixup `pair_callout_with_definition`
 * wraps adjacent trios so callout-bottom aligns with definition-bottom. */
.callout-def-pair {
    display: grid;
    grid-template-columns: 1fr 33%;
    gap: 1.5rem;
    align-items: stretch;
    margin: 2rem 0;
}
.callout-def-pair-main { display: flow-root; }
.callout-def-pair-aside {
    display: flex;
    flex-direction: column;
}
.callout-def-pair-aside > .context-pause,
.callout-def-pair-aside > .insight-note {
    float: none;
    clear: none;
    width: auto;
    margin: 0;
    flex: 1;
}
@media (max-width: 768px) {
    .callout-def-pair { grid-template-columns: 1fr; }
    .callout-def-pair-aside { order: -1; }
}
@media (max-width: 768px) {
    .context-pause,
    .insight-note {
        float: none;
        clear: none;
        width: auto;
        margin: 2rem 0;
    }
}

.insight-note { background-color: rgba(209, 236, 241, 0.3); border-left: 6px solid #17a2b8; padding: 1.5rem 2rem; margin: 2rem 0; border-radius: 0 8px 8px 0; }
.insight-note::before { content: "Insight Note"; font-weight: bold; display: block; margin-bottom: 0.5rem; color: #0c5460; font-size: 1.3rem; }

.definition { background-color: rgba(227, 234, 242, 0.3); border-left: 6px solid #4a6a8a; padding: 1.5rem 2rem; margin: 2rem 0; border-radius: 0 8px 8px 0; }
.definition-title { font-weight: bold; color: var(--primary-color); margin-bottom: 0.5rem; font-size: 1.3rem; }

.example { background-color: #fff; border: 3px solid var(--secondary-color); padding: 2rem; margin: 2rem 0; border-radius: 8px; scroll-margin-top: 80px; }
.example-title { font-weight: bold; color: var(--secondary-color); font-size: 1.4rem; margin-bottom: 1rem; }

details.solution { background-color: var(--bg-light); border: 1px solid var(--border-color); border-radius: 8px; margin-top: 1rem; overflow: hidden; }
details.solution summary { background-color: var(--primary-color); color: white; padding: 1rem 1.5rem; cursor: pointer; font-weight: bold; font-size: 1.1rem; list-style: none; display: flex; align-items: center; }
details.solution summary::-webkit-details-marker { display: none; }
details.solution summary::before { content: "\25B6"; margin-right: 0.75rem; transition: transform 0.2s; }
details.solution[open] summary::before { transform: rotate(90deg); }
details.solution[open] summary { border-bottom: 1px solid var(--border-color); }
.solution-content { padding: 1.5rem 2rem; }
details.solution > :not(summary) { padding-left: 2rem; padding-right: 2rem; }
details.solution > p, details.solution > :not(summary):last-child { padding-bottom: 1rem; }

/* Manim graphic figures — responsive sizing for any device */
figure.manim-figure { margin: 1rem 0; max-width: 100%; }
figure.manim-figure video, figure.manim-figure img { width: 100%; max-width: 100%; height: auto; display: block; border-radius: 6px; background: #010B13; }

/* Collapsible wrapper for definition animations */
details.manim-collapse { background-color: var(--bg-light); border: 1px solid var(--border-color); border-radius: 8px; margin-top: 1rem; overflow: hidden; }
details.manim-collapse summary { background-color: var(--secondary-color); color: white; padding: 0.75rem 1.25rem; cursor: pointer; font-weight: 600; font-size: 1rem; list-style: none; display: flex; align-items: center; }
details.manim-collapse summary::-webkit-details-marker { display: none; }
details.manim-collapse summary::before { content: "\25B6"; margin-right: 0.6rem; transition: transform 0.2s; font-size: 0.85em; }
details.manim-collapse[open] summary::before { transform: rotate(90deg); }
details.manim-collapse[open] summary { border-bottom: 1px solid var(--border-color); }
details.manim-collapse > figure.manim-figure { margin: 1rem 1.5rem 1.25rem; }

section.appendix { margin-top: 3rem; padding: 1.5rem; background: var(--appendix-bg, #fafafa); border-left: 4px solid var(--appendix-accent, #c0c0c0); border-radius: 0.5rem; }
section.appendix > details.appendix-toggle > summary { cursor: pointer; list-style: none; }
section.appendix > details.appendix-toggle > summary h3 { display: inline; margin: 0; font-size: 1.15rem; color: var(--appendix-heading, #555); }
section.appendix .appendix-blurb { font-style: italic; color: var(--text-secondary, #666); margin: 0.5rem 0 1rem 0; }
section.appendix details.solution { background: rgba(0,0,0,0.02); }
@media (prefers-color-scheme: dark) {
  section.appendix { --appendix-bg: rgba(255,255,255,0.03); --appendix-accent: #555; --appendix-heading: #aaa; }
}
[data-theme="dark"] section.appendix { --appendix-bg: rgba(255,255,255,0.03); --appendix-accent: #555; --appendix-heading: #aaa; }
.nav-appendix-group > details > summary { cursor: pointer; font-style: italic; color: var(--text-muted, #888); list-style: none; padding: 0.25rem 0.5rem; }
.nav-appendix-group > details > summary::-webkit-details-marker { display: none; }
.nav-appendix-group > details > summary::before { content: "\25B8 "; display: inline-block; transition: transform 0.2s; }
.nav-appendix-group > details[open] > summary::before { content: "\25BE "; }
.nav-appendix-group > details > ul.nav-appendix-list { list-style: none; padding-left: 1rem; border-left: 2px solid var(--appendix-accent, #c0c0c0); margin: 0.25rem 0 0.5rem 0.5rem; }
.nav-appendix-group > details > ul.nav-appendix-list .nav-link { color: var(--text-secondary, #666); }
@media (prefers-color-scheme: dark) {
  .nav-appendix-group > details > summary { color: #888; }
  .nav-appendix-group > details > ul.nav-appendix-list { border-left-color: #555; }
  .nav-appendix-group > details > ul.nav-appendix-list .nav-link { color: #aaa; }
}
[data-theme="dark"] .nav-appendix-group > details > summary { color: #888; }
[data-theme="dark"] .nav-appendix-group > details > ul.nav-appendix-list { border-left-color: #555; }
[data-theme="dark"] .nav-appendix-group > details > ul.nav-appendix-list .nav-link { color: #aaa; }

table { border-collapse: collapse; width: 100%; margin: 1.5rem 0; font-size: 1.15rem; }
th, td { border: 1px solid var(--border-color); padding: 0.75rem 1.25rem; text-align: center; }
th { background-color: var(--bg-light); font-weight: bold; }

.important-rule { background-color: #f8d7da; border: 2px solid #f5c6cb; padding: 1.5rem 2rem; margin: 2rem 0; border-radius: 8px; color: #721c24; }
.problem-set { background-color: #f0f0f0; padding: 2rem; margin: 2.5rem 0; border-radius: 8px; scroll-margin-top: 80px; }
.problem { scroll-margin-top: 80px; margin-bottom: 1rem; }
hr { border: none; border-top: 1px solid var(--border-color); margin: 2rem 0; }

/* Drawing Canvas */
.draw-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 998;
    pointer-events: none;
    cursor: crosshair;
}
.draw-canvas.active { pointer-events: auto; }

.draw-toolbar {
    position: fixed;
    right: calc(2rem + 50px + 0.75rem);
    bottom: 2rem;
    display: flex;
    gap: 0.75rem;
    align-items: center;
    background: white;
    padding: 0.5rem 1rem;
    border-radius: 25px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.2);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transform: translateX(10px);
    transition: opacity 0.2s, visibility 0.2s, transform 0.2s;
}
.draw-toolbar.show { opacity: 1; visibility: visible; transform: translateX(0); }
.draw-toolbar button {
    background: none;
    border: 1px solid var(--border-color);
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
}
.draw-toolbar button:hover { background-color: var(--bg-light); }
.draw-toolbar button.active { background-color: var(--secondary-color); color: white; border-color: var(--secondary-color); }
.draw-toolbar input[type="color"] { width: 32px; height: 32px; border: none; border-radius: 50%; cursor: pointer; padding: 0; }
.draw-toolbar input[type="range"] { width: 80px; cursor: pointer; }
.draw-toolbar .size-preview { width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; }
.draw-toolbar .size-dot { background-color: #333; border-radius: 50%; }

/* Laser Pointer */
.laser-dot {
    position: fixed;
    width: 12px;
    height: 12px;
    background: #ff0000;
    border-radius: 50%;
    pointer-events: none;
    z-index: 1002;
    display: none;
    box-shadow: 0 0 10px 5px rgba(255, 0, 0, 0.5), 0 0 20px 10px rgba(255, 0, 0, 0.2);
    transform: translate(-50%, -50%);
}
.laser-dot.show { display: block; }
.laser-trail {
    position: fixed;
    width: 8px;
    height: 8px;
    background: #ff0000;
    border-radius: 50%;
    pointer-events: none;
    z-index: 997;
    opacity: 0.5;
    animation: laser-fade 0.4s ease-out forwards;
    transform: translate(-50%, -50%);
}
@keyframes laser-fade {
    to { opacity: 0; transform: translate(-50%, -50%) scale(0.3); }
}

/* Dark Mode — neutral gray palette */
[data-theme="dark"] {
    --primary-color: #e0e0e0;
    --secondary-color: #6cb4ee;
    --accent-color: #e74c3c;
    --bg-light: #2a2a2a;
    --bg-highlight: #3a3528;
    --bg-insight: #2a3538;
    --border-color: #484848;
}
[data-theme="dark"] body { background-color: #1e1e1e; color: #d4d4d4; }
[data-theme="dark"] .navbar { background-color: #252525; }
[data-theme="dark"] .nav-dropdown-menu { background: #2a2a2a; border-color: #484848; }
[data-theme="dark"] .nav-dropdown-menu .nav-link { color: #d4d4d4; }
[data-theme="dark"] .nav-dropdown-menu .nav-link:hover,
[data-theme="dark"] .nav-dropdown-menu .nav-link.active { background-color: #333; }
/* Dark-mode coloured callouts — 50% transparent tinted-dark bg so the
 * page's dark canvas shows through, matching the light-mode treatment.
 * Each strip uses a lighter shade of the same hue for visibility. */
[data-theme="dark"] .learning-objectives { background-color: rgba(55, 45, 32, 0.3); border-left-color: #e09a55; }
[data-theme="dark"] .context-pause { background-color: rgba(58, 53, 40, 0.3); }
[data-theme="dark"] .insight-note { background-color: rgba(42, 53, 56, 0.3); }
[data-theme="dark"] .definition { background-color: rgba(42, 47, 51, 0.3); border-left-color: #6a96bf; }
[data-theme="dark"] .example { background-color: #232323; }
[data-theme="dark"] details.solution { background-color: #303030; }
[data-theme="dark"] details.solution summary { background-color: #5a5a5a; }
[data-theme="dark"] details.manim-collapse { background-color: #2a2a2a; border-color: #444; }
[data-theme="dark"] details.manim-collapse summary { background-color: #3a3a3a; }
[data-theme="dark"] .context-pause::before { color: #ffc107; }
[data-theme="dark"] .insight-note::before { color: #6cb4ee; }
[data-theme="dark"] .important-rule { background-color: #352222; border-color: #5a3333; color: #ff9a9a; }
[data-theme="dark"] .problem-set { background-color: #2a2a2a; }
[data-theme="dark"] .float-nav-btn { background-color: #333; }
[data-theme="dark"] .float-nav-btn:hover { background-color: var(--secondary-color); }
[data-theme="dark"] .float-nav-btn:disabled:hover { background-color: #333; }
[data-theme="dark"] .draw-toolbar { background: #2a2a2a; }
[data-theme="dark"] .draw-toolbar button { border-color: #484848; color: #d4d4d4; }
[data-theme="dark"] .draw-toolbar button:hover { background-color: #333; }
[data-theme="dark"] .draw-toolbar .size-dot { background-color: #d4d4d4; }

@media (max-width: 768px) {
    .navbar { flex-direction: column; gap: 0.75rem; padding: 0.75rem 1rem; }
    .container { padding: 1rem; }
    .float-nav { right: 1rem; bottom: 1rem; }
    .float-nav-btn { width: 45px; height: 45px; }
    .nav-dropdown-menu { right: auto; left: 0; min-width: 250px; }
    .draw-toolbar { right: calc(1rem + 45px + 0.75rem); }
    .main-content img { margin: 1rem auto; }
    .main-content .figure-row { flex-direction: column; gap: 0.75rem; }
    .main-content .figure-row > * { flex: 1 1 auto; }
}

/* ── Teacher edition subtitle ──────────────────────────────────────────────
   Rendered immediately after the page <h1> by the pipeline (pipeline.py
   step_html) when teach_mode is on. */
.teacher-edition-subtitle {
    display: block;
    margin: -0.75rem 0 1.5rem;
    font-style: italic;
    font-weight: 600;
    font-size: 0.95rem;
    color: #b91c1c;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
[data-theme="dark"] .teacher-edition-subtitle { color: #f87171; }

/* ── Reading-font picker (Font dropdown in navbar) ──────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Atkinson+Hyperlegible:wght@400;700&family=Lexend:wght@400;700&display=swap');

@font-face {
    font-family: 'OpenDyslexic';
    src: url('https://cdn.jsdelivr.net/npm/open-dyslexic@1.0.3/woff/OpenDyslexic-Regular.woff') format('woff');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'OpenDyslexic';
    src: url('https://cdn.jsdelivr.net/npm/open-dyslexic@1.0.3/woff/OpenDyslexic-Bold.woff') format('woff');
    font-weight: bold;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'OpenDyslexic';
    src: url('https://cdn.jsdelivr.net/npm/open-dyslexic@1.0.3/woff/OpenDyslexic-Italic.woff') format('woff');
    font-weight: normal;
    font-style: italic;
    font-display: swap;
}
@font-face {
    font-family: 'OpenDyslexic';
    src: url('https://cdn.jsdelivr.net/npm/open-dyslexic@1.0.3/woff/OpenDyslexic-BoldItalic.woff') format('woff');
    font-weight: bold;
    font-style: italic;
    font-display: swap;
}

body.font-opendyslexic {
    font-family: 'OpenDyslexic', 'Comic Sans MS', cursive;
    --font-body: 'OpenDyslexic', 'Comic Sans MS', cursive;
    letter-spacing: 0.05em;
    word-spacing: 0.12em;
    line-height: 1.8;
}
body.font-lexend {
    font-family: 'Lexend', sans-serif;
    --font-body: 'Lexend', sans-serif;
    letter-spacing: 0.02em;
    line-height: 1.75;
}
body.font-atkinson {
    font-family: 'Atkinson Hyperlegible', sans-serif;
    --font-body: 'Atkinson Hyperlegible', sans-serif;
    line-height: 1.7;
}
body.font-comic {
    font-family: 'Comic Sans MS', 'Comic Sans', cursive;
    --font-body: 'Comic Sans MS', 'Comic Sans', cursive;
    letter-spacing: 0.02em;
    line-height: 1.7;
}

/* Keep navbar / code / math in their original fonts regardless of pick. */
body.font-opendyslexic .navbar,
body.font-opendyslexic .nav-dropdown-btn,
body.font-opendyslexic .theme-toggle,
body.font-opendyslexic code,
body.font-opendyslexic pre,
body.font-opendyslexic kbd,
body.font-opendyslexic .mjx-container,
body.font-lexend .navbar,
body.font-lexend .nav-dropdown-btn,
body.font-lexend .theme-toggle,
body.font-lexend code,
body.font-lexend pre,
body.font-lexend kbd,
body.font-lexend .mjx-container,
body.font-atkinson .navbar,
body.font-atkinson .nav-dropdown-btn,
body.font-atkinson .theme-toggle,
body.font-atkinson code,
body.font-atkinson pre,
body.font-atkinson kbd,
body.font-atkinson .mjx-container,
body.font-comic .navbar,
body.font-comic .nav-dropdown-btn,
body.font-comic .theme-toggle,
body.font-comic code,
body.font-comic pre,
body.font-comic kbd,
body.font-comic .mjx-container {
    font-family: var(--font-heading);
    letter-spacing: normal;
    word-spacing: normal;
}

/* Google Translate widget host (sits in the navbar) */
.nav-translate-widget { display: inline-flex; align-items: center; }
.nav-translate-widget .goog-te-gadget { font-size: 0.85rem; }
.nav-translate-widget .goog-te-gadget-icon { display: none; }


/* ── Settings cog + squircle controls ────────────────────────────────── */
/* Used by the consolidated settings dropdown in the navbar partial.
 * Same block lives in both style.css and style-bookshelf.css so all
 * theme variants render the cog identically.
 */

.nav-settings {
    position: relative;
    display: inline-flex;
    align-items: center;
    margin-left: 0.25rem;
}
.nav-settings-btn {
    background: transparent;
    border: 1px solid transparent;
    color: inherit;
    padding: 0.3rem;
    border-radius: 8px;
    cursor: pointer;
    line-height: 0;
    transition: background 0.15s, border-color 0.15s, transform 0.2s;
}
.nav-settings-btn:hover,
.nav-settings-btn[aria-expanded="true"] {
    background: rgba(120, 120, 140, 0.12);
    border-color: rgba(120, 120, 140, 0.25);
}
.nav-settings-btn .settings-cog {
    display: block;
    transition: transform 0.4s ease;
}
.nav-settings-btn[aria-expanded="true"] .settings-cog {
    transform: rotate(60deg);
}

.nav-settings-menu {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 0.4rem);
    min-width: 320px;
    max-width: 92vw;
    z-index: 110;
    background: var(--card-bg, #fff);
    color: var(--ink, #1c1c1e);
    border: 1px solid var(--card-border, rgba(60, 60, 67, 0.18));
    border-radius: 14px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.16);
    padding: 0.85rem 1rem 1rem;
}
.nav-settings-menu.open {
    display: block;
}

.settings-heading {
    margin: 0 0 0.6rem;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted, #6b6b73);
}

.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.85rem;
    padding: 0.55rem 0;
    border-top: 1px solid var(--divider, rgba(60, 60, 67, 0.12));
}
.settings-row:first-of-type {
    border-top: none;
}
.settings-label {
    flex: 1 1 auto;
    font-size: 0.95rem;
    color: var(--ink, #1c1c1e);
}

/* Squircle switch — used for binary toggles (Dark Mode, Dyslexic Font) */
.squircle-switch {
    position: relative;
    display: inline-block;
    width: 46px;
    height: 26px;
    flex: 0 0 auto;
    cursor: pointer;
}
.squircle-switch input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}
.squircle-slider {
    position: absolute;
    inset: 0;
    background: var(--switch-off, #cbd5e0);
    /* Squircle = pill outline + slightly-rounded inner knob */
    border-radius: 6px;
    transition: background 0.18s;
}
.squircle-slider::before {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    /* Squircle knob — not a full circle, not a square; ~40% radius */
    border-radius: 4px;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    transition: transform 0.18s, border-radius 0.18s;
}
.squircle-switch input:checked + .squircle-slider {
    background: var(--wedgwood, #4a7ba6);
}
.squircle-switch input:checked + .squircle-slider::before {
    transform: translateX(20px);
}
.squircle-switch input:focus-visible + .squircle-slider {
    outline: 2px solid var(--wedgwood-light, #6a96bf);
    outline-offset: 2px;
}

/* Squircle action button — used for Save Offline. Squircle silhouette,
 * single-press action (not stateful). */
.squircle-action {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.8rem;
    background: var(--wedgwood, #4a7ba6);
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1;
    transition: transform 0.12s, box-shadow 0.12s, background 0.15s;
    flex: 0 0 auto;
}
.squircle-action:hover {
    background: var(--wedgwood-dark, #3a6892);
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15);
}
.squircle-action:active {
    transform: translateY(0);
}
.squircle-action svg {
    display: block;
}
.squircle-action-label {
    display: inline-block;
}

/* Slides "Present" link, injected by publish.py survival guard before
 * the saveOfflineBtn. Render as a squircle-action so it visually
 * matches the rest of the dropdown. publish.py emits the link with
 * classes `theme-toggle slides-link`; the settings-row scope keeps
 * old un-themed instances looking sane. */
.nav-settings-menu .slides-link {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.8rem;
    background: var(--wedgwood, #4a7ba6);
    color: #fff;
    border-radius: 6px;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1;
    transition: background 0.15s, transform 0.12s;
}
.nav-settings-menu .slides-link:hover {
    background: var(--wedgwood-dark, #3a6892);
    transform: translateY(-1px);
}

/* Dark-theme variant — recolor switch off-state + cog hover */
[data-theme="dark"] .squircle-slider {
    background: #4a4a52;
}
[data-theme="dark"] .nav-settings-menu {
    background: var(--dark-surface, #2a2a30);
    color: var(--ivory, #f3efe6);
    border-color: rgba(255, 255, 255, 0.08);
}
[data-theme="dark"] .settings-label {
    color: var(--ivory, #f3efe6);
}
[data-theme="dark"] .nav-settings-btn:hover,
[data-theme="dark"] .nav-settings-btn[aria-expanded="true"] {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.18);
}

/* Hide the old Light/Dark text button if the new checkbox swap is in
 * place but a stale page snapshot still has both. Defensive only. */
button.theme-toggle#themeToggle { display: none; }

/* Heading font swap when dyslexic font is on. The default theme styles
 * H1-H4 via var(--font-serif) which overrides the body font, so toggling
 * font-opendyslexic on the body alone leaves headings in their serif. */
body.font-opendyslexic h1,
body.font-opendyslexic h2,
body.font-opendyslexic h3,
body.font-opendyslexic h4,
body.font-opendyslexic .definition-title,
body.font-opendyslexic .example-title,
body.font-opendyslexic .navbar-brand,
body.font-opendyslexic summary {
    font-family: 'OpenDyslexic', 'Comic Sans MS', cursive !important;
    letter-spacing: 0.03em;
}
body.font-lexend h1,
body.font-lexend h2,
body.font-lexend h3,
body.font-lexend h4,
body.font-lexend .definition-title,
body.font-lexend .example-title,
body.font-lexend .navbar-brand,
body.font-lexend summary {
    font-family: 'Lexend', sans-serif !important;
}
body.font-atkinson h1,
body.font-atkinson h2,
body.font-atkinson h3,
body.font-atkinson h4,
body.font-atkinson .definition-title,
body.font-atkinson .example-title,
body.font-atkinson .navbar-brand,
body.font-atkinson summary {
    font-family: 'Atkinson Hyperlegible', sans-serif !important;
}
body.font-comic h1,
body.font-comic h2,
body.font-comic h3,
body.font-comic h4,
body.font-comic .definition-title,
body.font-comic .example-title,
body.font-comic .navbar-brand,
body.font-comic summary {
    font-family: 'Comic Sans MS', 'Comic Sans', cursive !important;
}

/* ── Static manim figures (theme-aware light/dark PNG pair) ─────────── */
/* Used by figure_animate when mode: static. Two `<img>` tags inside
 * a single wrapper; CSS shows the light variant by default and swaps
 * to dark on `[data-theme="dark"]`. The dark img carries
 * aria-hidden="true" so screen readers only see the light variant's
 * alt text. */
.figure-static-wrap {
    display: block;
    margin: var(--xl, 2rem) 0;
    text-align: center;
}
.figure-static-wrap .figure-static {
    max-width: 100%;
    /* Cap solo figures at viewport height; aspect ratio preserved via
     * `height: auto` + `width: auto`. In-row figures override below. */
    max-height: 80vh;
    height: auto;
    width: auto;
    display: inline-block;
}
.figure-static-wrap .figure-dark {
    display: none;
}
[data-theme="dark"] .figure-static-wrap .figure-light {
    display: none;
}
[data-theme="dark"] .figure-static-wrap .figure-dark {
    display: inline-block;
}

/* Multi-figure row grouping. Adjacent figure cells fold into a grid.
   Each cell pairs the figure wrap with its caption paragraph.
   Mobile (narrow viewport) collapses back to single-column stacking. */
.figure-row {
    display: grid;
    gap: 1.25rem;
    /* Full-bleed: break out of .container max-width to span viewport. */
    margin: var(--xl, 2rem) calc(50% - 50vw);
    width: 100vw;
    max-width: 100vw;
    align-items: start;
    padding: 0 30px;
    box-sizing: border-box;
}
.figure-row-2col { grid-template-columns: 1fr 1fr; }
.figure-row-3col { grid-template-columns: 1fr 1fr 1fr; }
.figure-row .figure-row-cell {
    display: flex;
    flex-direction: column;
    align-items: stretch;     /* fill cell width — was `center` */
}
.figure-row .figure-row-cell .figure-static-wrap,
.figure-row .figure-row-cell .figure-anim-wrap {
    margin: 0 0 0.4rem 0;
    width: 100%;
}
/* Force in-row figure media to fill the cell width (overrides default
 * inline-block + max-width). Also unsets the solo `max-height: 80vh`
 * cap — the grid cell already constrains the figure. */
.figure-row .figure-row-cell .figure-static,
.figure-row .figure-row-cell .figure-anim {
    display: block;
    width: 100%;
    height: auto;
    max-height: none;
}
/* Theme toggle at in-row scope — the `display: block` rule above is
 * more specific than the default `.figure-static-wrap .figure-dark`
 * hide rule, so without these overrides BOTH light + dark variants
 * would render simultaneously inside a row cell. */
.figure-row .figure-row-cell .figure-static.figure-dark,
.figure-row .figure-row-cell .figure-anim.figure-dark { display: none; }
[data-theme="dark"] .figure-row .figure-row-cell .figure-static.figure-light,
[data-theme="dark"] .figure-row .figure-row-cell .figure-anim.figure-light { display: none; }
[data-theme="dark"] .figure-row .figure-row-cell .figure-static.figure-dark,
[data-theme="dark"] .figure-row .figure-row-cell .figure-anim.figure-dark { display: block; }
.figure-row .figure-row-cell p {
    margin: 0;
    text-align: center;
    font-size: 0.9em;
}
@media (max-width: 1399px) {
    /* Laptop / small-desktop: 3-col rows reflow to 2-col. Grid auto-flow
     * handles odd counts — overflow cells land in the left column of
     * the next row. */
    .figure-row-3col { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 768px) {
    /* Mobile / tablet: every row collapses to single-column stacking. */
    .figure-row-2col,
    .figure-row-3col { grid-template-columns: 1fr; }
}
