/* ===== Reset & base ===== */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Charter", "Georgia", "Iowan Old Style", "Times New Roman", serif;
  background: #fbfbf9;
  color: #1f2330;
  line-height: 1.65;
  font-size: 17px;
  -webkit-font-smoothing: antialiased;
}
a { color: #1b66cc; text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; cursor: pointer; }

/* ===== Accessibility helpers ===== */
.skip-link {
  position: absolute; left: 8px; top: -60px; z-index: 100000;
  background: #14376b; color: #fff; padding: 10px 16px;
  border-radius: 0 0 8px 8px; font-weight: 700; text-decoration: none;
  transition: top .15s;
}
.skip-link:focus { top: 0; outline: 3px solid #f3b700; outline-offset: 2px; }
/* Heading / main focused programmatically for screen-reader landing — no visible ring */
main:focus, .page-title:focus { outline: none; }
/* Respect users who prefer reduced motion (WCAG 2.3.3) */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

:root {
  --brand: #14376b;
  --brand-2: #285aab;
  --accent: #f3b700;
  --bg: #fbfbf9;
  --panel: #ffffff;
  --line: #e6e6dd;
  --muted: #6f6f6a;
  --good: #117a3f;
  --warn: #b3261e;
  --code-bg: #f4f4ee;
  --shadow: 0 1px 2px rgba(15,23,42,.05), 0 4px 14px rgba(15,23,42,.04);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

/* ===== Header ===== */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: var(--brand);
  color: #fff;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px;
  font-family: var(--sans);
  box-shadow: 0 2px 12px rgba(0,0,0,.10);
}
.brand { display: flex; align-items: center; gap: 12px; }
.menu-toggle {
  background: transparent; border: 1px solid rgba(255,255,255,.3);
  color: #fff; width: 36px; height: 36px; border-radius: 8px; font-size: 18px;
  display: none;
}
.brand-link { color: #fff; display: flex; align-items: baseline; gap: 12px; }
.brand-link:hover { text-decoration: none; }
.brand-code { font-weight: 800; letter-spacing: .5px; font-size: 18px; }
.brand-title { font-size: 14px; opacity: .9; }
.header-right { display: flex; align-items: center; gap: 14px; }
.instructor { font-size: 13px; opacity: .9; }
#searchBox {
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.25);
  color: #fff;
  padding: 7px 12px; border-radius: 8px;
  width: 260px; font-size: 14px;
  font-family: var(--sans);
}
#searchBox::placeholder { color: rgba(255,255,255,.75); }
#searchBox:focus { outline: 2px solid var(--accent); background: rgba(255,255,255,.25); }

/* ===== Layout ===== */
.layout { display: grid; grid-template-columns: 300px 1fr; min-height: calc(100vh - 56px - 36px); }
.sidebar {
  background: #fbfbf6;
  border-right: 1px solid var(--line);
  padding: 20px 8px 30px;
  overflow-y: auto;
  max-height: calc(100vh - 56px);
  position: sticky;
  top: 56px;
  font-family: var(--sans);
}
.main { padding: 30px 48px 80px; max-width: 800px; width: 100%; margin: 0 auto; min-width: 0; }

/* ===== Sidebar nav ===== */
.chapter-nav { display: flex; flex-direction: column; gap: 2px; }
.chap { border-radius: 10px; margin-bottom: 2px; }
.chap-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px;
  cursor: pointer;
  border-radius: 8px;
  color: #1f2330;
  font-size: 14px;
}
button.chap-header { width: 100%; background: none; border: 0; font: inherit; text-align: left; }
.chap-header:hover { background: #efeee5; }
/* In-prose links must be distinguishable without color (WCAG 1.4.1): underline them */
.intro-body a, .example-body a, .qprompt a, .explanation a, .ebody a, .page-subtitle a { text-decoration: underline; }
.chap-header.active { background: #e6e8f1; color: var(--brand); font-weight: 600; }
.chap-title { font-weight: 600; line-height: 1.3; }
.chap-caret { transition: transform .15s; opacity: .55; font-size: 11px; }
.chap.open > .chap-header .chap-caret { transform: rotate(90deg); }
.chap-body { display: none; padding: 2px 6px 10px; }
.chap.open > .chap-body { display: block; }

.topic-link {
  display: block;
  padding: 6px 10px 6px 22px;
  font-size: 13.5px;
  color: #2c3548;
  border-radius: 6px;
  border-left: 2px solid transparent;
  line-height: 1.35;
  margin: 1px 0;
}
.topic-link:hover { background: #f0f0e7; text-decoration: none; }
.topic-link.active { background: #e6e8f1; color: var(--brand); border-left-color: var(--accent); font-weight: 600; }

/* ===== Main content ===== */
.crumbs {
  font-size: 13px; color: var(--muted); margin-bottom: 16px;
  font-family: var(--sans);
}
.crumbs a { color: var(--muted); }
.crumbs .sep { margin: 0 6px; }

.page-title { font-size: 30px; margin: 0 0 8px; color: #1f2330; font-weight: 700; line-height: 1.2; }
.page-subtitle { color: var(--muted); margin: 0 0 28px; font-size: 16px; }

/* Hero on home */
.hero {
  background: linear-gradient(135deg, #14376b 0%, #285aab 100%);
  color: #fff;
  padding: 36px 32px;
  border-radius: 14px;
  margin-bottom: 30px;
  font-family: var(--sans);
}
.hero h1 { margin: 0 0 8px; font-size: 28px; }
.hero p { margin: 0; opacity: .92; max-width: 70ch; font-size: 15px; line-height: 1.6; }

/* Chapter cards on home */
.chapter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  font-family: var(--sans);
}
.chapter-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px 18px 14px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  transition: transform .12s ease, box-shadow .12s ease;
  color: inherit;
}
.chapter-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 22px rgba(15,23,42,.08);
  text-decoration: none;
}
.chapter-card h3, .chapter-card h2 {
  margin: 0 0 8px;
  color: var(--brand);
  font-size: 17px;
  font-family: var(--sans);
  font-weight: 700;
}
.chapter-card .desc {
  color: var(--muted); font-size: 13.5px; flex: 1; line-height: 1.5;
}
.chapter-card .meta {
  margin-top: 14px; display: flex; gap: 8px; flex-wrap: wrap;
  font-size: 11.5px; color: var(--muted);
}
.chapter-card .meta span {
  background: #f3f3eb; color: #555; padding: 3px 8px; border-radius: 999px; font-weight: 600;
}

/* ===== Topic page ===== */
.topic-page { font-size: 17px; line-height: 1.7; }
.topic-page p { margin: 0 0 14px; }
.topic-page ul, .topic-page ol { padding-left: 24px; margin: 0 0 14px; }
.topic-page li { margin-bottom: 6px; }
.topic-page strong { color: #111; }

/* Section block (intro / example / practice) */
.section-block { margin-bottom: 34px; }

.section-h {
  display: flex; align-items: center; justify-content: space-between;
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: .6px;
  text-transform: uppercase;
  color: #4c5366;
  margin: 0 0 14px;
  padding-bottom: 0;
}
.section-h .help {
  font-size: 14px; color: var(--muted); cursor: help;
  border: 1px solid var(--line); border-radius: 50%;
  width: 22px; height: 22px; display: inline-flex;
  align-items: center; justify-content: center; font-weight: 600;
  text-transform: none; letter-spacing: 0;
}

.section-rule { border: none; border-top: 1px solid var(--line); margin: 22px 0 18px; }

.intro-body, .example-body { font-size: 17px; }
.intro-body p, .example-body p { margin: 0 0 14px; }

/* Tables */
.data-table {
  margin: 16px auto;
  border-collapse: separate;
  border-spacing: 0;
  font-family: var(--sans);
  font-size: 14.5px;
  display: inline-table;
}
.data-table th, .data-table td {
  padding: 8px 16px;
  border: 1px solid #c8d4ee;
  text-align: center;
  background: #fff;
}
.data-table th {
  background: #e3edff;
  color: #14376b;
  font-weight: 700;
}
.data-table.compact th, .data-table.compact td { padding: 6px 12px; font-size: 14px; }
.table-wrap { text-align: center; margin: 16px 0 20px; }
/* Horizontal scroll container for wide tables on narrow screens */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
  margin: 16px 0;
  text-align: center;
}
.table-scroll .data-table { margin: 0 auto; }
/* Let wide display equations scroll instead of overflowing the page on mobile */
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 2px 0 4px; }
/* Contain KaTeX's absolutely-positioned (hidden) MathML so it can't inflate
   page width on narrow screens, while keeping it for accessibility. */
.katex { position: relative; }

/* Math blocks */
.math-block {
  margin: 14px 0;
  text-align: center;
  font-size: 18px;
}
.math-inline { font-size: 1em; }

/* Example block */
.example-card {
  background: #fffdf6;
  border: 1px solid #f0e2a3;
  border-left: 4px solid var(--accent);
  padding: 22px 26px;
  border-radius: 0 10px 10px 0;
  margin-bottom: 28px;
}
.example-card > .label {
  font-family: var(--sans);
  font-size: 13px; letter-spacing: .6px; text-transform: uppercase;
  color: #8a6b00; font-weight: 700; margin-bottom: 8px;
}
.example-card h3 {
  font-size: 19px; margin: 0 0 12px;
  color: #1f2330;
  font-family: var(--sans);
  font-weight: 700;
}

/* Solution divider */
.solution-divider {
  font-family: var(--sans);
  font-size: 13px; letter-spacing: .6px; text-transform: uppercase;
  color: #5e6577; font-weight: 700;
  margin: 18px 0 10px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

/* Practice question (multiple choice) */
.practice-q {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 22px 24px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.practice-q .qnum {
  font-family: var(--sans);
  font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .8px;
  color: var(--muted);
  margin-bottom: 8px;
}
.practice-q .qprompt { margin-bottom: 14px; }
.practice-q .qprompt p { margin: 0 0 8px; }
.practice-q .qprompt > *:last-child { margin-bottom: 0; }

.choices {
  list-style: none; padding: 0; margin: 0;
  display: grid; gap: 8px;
  font-family: var(--sans);
}
.choice {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px 10px 44px;
  background: #fff;
  cursor: pointer;
  font-size: 15.5px;
  line-height: 1.5;
  transition: background .12s, border-color .12s, transform .04s;
}
.choice:hover { background: #f7f7ef; border-color: #cdcdb8; }
.choice:active { transform: scale(.997); }
.choice::before {
  content: attr(data-letter);
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 22px; height: 22px; border-radius: 50%;
  border: 1.5px solid #c0c0a8;
  display: flex; align-items: center; justify-content: center;
  font-size: 12.5px; font-weight: 700;
  color: #6f6f6a;
  background: #fff;
}
.choice.correct {
  background: #ecf6ee; border-color: #6cb87e;
}
.choice.correct::before {
  background: var(--good); border-color: var(--good); color: #fff;
  content: '✓';
}
.choice.incorrect {
  background: #fdecea; border-color: #e0a8a3;
}
.choice.incorrect::before {
  background: var(--warn); border-color: var(--warn); color: #fff;
  content: '✗';
}
.choice.disabled { pointer-events: none; }
.choice.fade { opacity: .6; }
/* Keyboard-accessible answer choices (buttons in practice, radios in quizzes) */
button.choice { font: inherit; text-align: left; width: 100%; color: inherit; -webkit-appearance: none; appearance: none; }
button.choice:disabled:not(.fade) { opacity: 1; cursor: default; }
.choice:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.explanation {
  display: none;
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}
.explanation.show { display: block; }
.explanation .elabel {
  font-family: var(--sans);
  font-size: 12.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .8px;
  color: #4c5366; margin-bottom: 8px;
}
.explanation .ebody p:first-child { margin-top: 0; }
.explanation .ebody p:last-child { margin-bottom: 0; }

.q-actions {
  margin-top: 12px; display: flex; gap: 10px;
  font-family: var(--sans); font-size: 13px;
}
.q-actions button {
  background: transparent; border: 1px solid var(--line);
  padding: 5px 10px; border-radius: 6px; color: var(--muted);
}
.q-actions button:hover { background: #f0f0e7; }

/* Topic-level navigation */
.topic-nav {
  display: flex; justify-content: space-between; gap: 12px;
  margin-top: 40px; padding-top: 22px; border-top: 1px solid var(--line);
  font-family: var(--sans);
}
.topic-nav a {
  flex: 1; padding: 14px 16px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: #1f2330;
  display: block;
}
.topic-nav a:hover { background: #f0f0e7; text-decoration: none; }
.topic-nav .nav-label { font-size: 11px; text-transform: uppercase; color: var(--muted); letter-spacing: .6px; }
.topic-nav .nav-title { display: block; font-weight: 600; margin-top: 3px; font-size: 14.5px; }
.topic-nav a.next { text-align: right; }
.topic-nav a.disabled { opacity: .35; pointer-events: none; }

/* Chapter overview list */
.topic-list {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 6px 0; box-shadow: var(--shadow);
  font-family: var(--sans);
}
.topic-list a {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 22px;
  border-bottom: 1px solid #f1f1e8;
  color: #1f2330;
}
.topic-list a:last-child { border-bottom: none; }
.topic-list a:hover { background: #f7f7ef; text-decoration: none; }
.topic-list .num {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 38px; height: 28px; padding: 0 9px;
  background: #e3edff; color: var(--brand);
  border-radius: 14px;
  font-size: 13px; font-weight: 700;
}
.topic-list .tcol { flex: 1; }
.topic-list .ttitle { font-weight: 600; font-size: 15.5px; }
.topic-list .tdesc { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* Footer */
.site-footer {
  background: #fff; border-top: 1px solid var(--line);
  padding: 12px 24px; color: var(--muted); font-size: 12.5px; text-align: center;
  font-family: var(--sans);
}

/* Search results */
.search-results h2 { color: var(--brand); font-family: var(--sans); }
.search-hit {
  background: var(--panel); padding: 12px 16px; border: 1px solid var(--line);
  border-radius: 10px; margin-bottom: 10px;
  font-family: var(--sans); font-size: 14px;
}
.search-hit .hit-path { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.search-hit mark { background: #fff3a8; padding: 0 2px; border-radius: 3px; }

/* Empty / fallback */
.empty {
  border: 1px dashed var(--line); padding: 24px; border-radius: 12px;
  color: var(--muted); text-align: center; font-family: var(--sans);
}

/* KaTeX tweak — match body color */
.katex { color: #1f2330; font-size: 1.02em; }
.katex-display { margin: 16px 0; }
.katex-display > .katex { font-size: 1.18em; }

/* Pretty inline code/formula text */
code, .formula-inline {
  background: var(--code-bg);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.92em;
}

/* Excel hint */
.excel-tip {
  background: #f3f8f5;
  border: 1px solid #c9e6d5;
  border-left: 4px solid var(--good);
  padding: 12px 16px;
  border-radius: 0 8px 8px 0;
  margin: 14px 0;
  font-family: var(--sans);
  font-size: 14px;
}
.excel-tip strong { color: #0f5c2f; }

/* ===== Whiteboard ===== */
.wb-fab {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  border: none;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 14px rgba(0,0,0,.25), 0 1px 3px rgba(0,0,0,.18);
  cursor: pointer;
  z-index: 9000;
  transition: transform .12s, background .12s, box-shadow .12s;
}
.wb-fab:hover { background: var(--brand-2); transform: translateY(-1px); box-shadow: 0 6px 18px rgba(0,0,0,.30); }
.wb-fab:active { transform: translateY(0); }
.wb-fab.active { background: var(--accent); color: #1a1a1a; }

.wb-overlay {
  position: fixed; inset: 0;
  z-index: 8999;
  pointer-events: none;
}
.wb-overlay[hidden] { display: none; }
.wb-overlay.bg-white::before {
  content: '';
  position: absolute; inset: 0;
  background: #ffffff;
  pointer-events: none;
}
.wb-canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  cursor: crosshair;
  pointer-events: auto;
  touch-action: none;
}
.wb-overlay.erasing .wb-canvas { cursor: cell; }
.wb-overlay.texting .wb-canvas { cursor: text; }
/* In-place text entry box for the whiteboard text tool */
.wb-textinput {
  position: absolute;
  z-index: 45;
  margin: 0;
  padding: 0;
  border: 0;
  outline: 1px dashed rgba(20,55,107,.6);
  background: rgba(255,255,255,.5);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  line-height: 1.1;
  white-space: pre;
  overflow: hidden;
  resize: none;
}

.wb-toolbar {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 8px; padding: 6px 10px;
  background: #ffffff;
  border: 1px solid #d8d8cc;
  border-radius: 12px;
  box-shadow: 0 6px 22px rgba(0,0,0,.18), 0 1px 3px rgba(0,0,0,.10);
  font-family: var(--sans);
  pointer-events: auto;
  z-index: 1;
}
.wb-group {
  display: flex; gap: 4px; align-items: center;
  padding: 0 6px;
  border-right: 1px solid #ecece2;
}
.wb-group:last-child { border-right: none; }

.wb-color {
  width: 26px; height: 26px;
  border: 2px solid transparent;
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  outline: 1px solid #c8c8b8;
  outline-offset: 1px;
  transition: transform .08s;
}
.wb-color:hover { transform: scale(1.08); }
.wb-color.active { border-color: #14376b; outline-color: #14376b; }

.wb-size {
  width: 30px; height: 30px;
  background: #fff;
  border: 1px solid #d8d8cc;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.wb-size:hover { background: #f4f4ec; }
.wb-size.active { background: #e3edff; border-color: var(--brand-2); }
.wb-dot { display: inline-block; background: #1a1a1a; border-radius: 50%; }

.wb-tool {
  height: 30px; min-width: 30px;
  padding: 0 8px;
  background: #fff;
  border: 1px solid #d8d8cc;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  color: #1f2330;
  display: inline-flex; align-items: center; justify-content: center;
}
.wb-tool:hover { background: #f4f4ec; }
.wb-tool.active { background: #fff4d0; border-color: var(--accent); }
.wb-close { color: #b3261e; font-weight: 700; }
.wb-close:hover { background: #fdecea; }

@media (max-width: 600px) {
  .wb-fab { width: 50px; height: 50px; right: 14px; bottom: 14px; }
  .wb-toolbar { gap: 4px; padding: 4px 6px; top: 8px; }
  .wb-group { padding: 0 4px; }
  .wb-color { width: 22px; height: 22px; }
  .wb-size, .wb-tool { height: 28px; min-width: 28px; }
}

/* Responsive */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 56px; left: 0; bottom: 0; z-index: 40;
    width: 280px; transform: translateX(-100%); transition: transform .2s;
    box-shadow: 2px 0 16px rgba(0,0,0,.10);
  }
  .sidebar.open { transform: translateX(0); }
  .menu-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .brand-title { display: none; }
  .header-right #searchBox { width: 150px; }
  .main { padding: 22px 18px 60px; }
  .example-card { padding: 16px 18px; }
  .practice-q { padding: 16px 18px; }
}

/* Narrow phones: keep the header within the viewport (no horizontal page scroll) */
@media (max-width: 520px) {
  .instructor { display: none; }
  .header-right #searchBox { width: 120px; }
  .site-header { padding: 10px 14px; }
}

/* ===== Embedded explainer videos ===== */
.video-figure {
  margin: 24px 0 8px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.video-figure video {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
  background: #fff;
}
.video-figure figcaption {
  margin-top: 10px;
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
  text-align: center;
}
.video-figure figcaption .vlabel {
  display: inline-block;
  font-weight: 600;
  color: var(--brand);
  text-transform: uppercase;
  letter-spacing: .5px;
  font-size: 11px;
  margin-right: 6px;
}

/* ===== DF-WELCH APPROX embedded calculator ===== */
.df-app {
  margin: 18px 0;
  padding: 14px 16px;
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.df-app-title {
  font-family: var(--sans);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: .5px;
  color: var(--brand);
  margin-bottom: 10px;
}
.df-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px 14px;
}
.df-grid label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--sans);
  font-size: 13.5px;
  color: #1a2233;
}
.df-grid input {
  flex: 1;
  width: 100%;
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 14px;
  font-family: var(--sans);
}
.df-grid input:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand); }
.df-out {
  margin-top: 12px;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-family: var(--sans);
  font-size: 14px;
  color: #1a2233;
}
@media (max-width: 560px) { .df-grid { grid-template-columns: repeat(2, 1fr); } }

/* ===== Interval Estimation - Regression embedded calculator ===== */
.reg-app {
  margin: 18px 0;
  padding: 14px 16px;
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.reg-app-title {
  font-family: var(--sans);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: .5px;
  color: var(--brand);
  margin-bottom: 10px;
}
.reg-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px 14px;
}
.reg-grid label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-family: var(--sans);
  font-size: 12px;
  color: #5b6478;
}
.reg-grid input {
  width: 100%;
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 14px;
  font-family: var(--sans);
  color: #1a2233;
}
.reg-grid input:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand); }
.reg-out {
  margin-top: 12px;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-family: var(--sans);
  font-size: 14px;
  color: #1a2233;
}
@media (max-width: 560px) { .reg-grid { grid-template-columns: repeat(2, 1fr); } }

/* ===== Practice Quizzes ===== */
.quiz-intro {
  font-family: var(--sans);
  font-size: 14.5px;
  color: #3a4156;
  background: #f7f7ef;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 22px;
}
.quiz-intro p { margin: 0; }

/* a chosen-but-not-yet-graded answer */
.choice.selected {
  background: #fff8e1;
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.choice.selected::before {
  background: var(--accent); border-color: var(--accent); color: #3a2f00;
}

/* graded-question accent stripe */
.quiz-q.q-right { border-left: 4px solid var(--good); }
.quiz-q.q-wrong { border-left: 4px solid var(--warn); }

/* score banner shown after submitting */
.quiz-scorebar {
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 4px solid var(--accent);
  border-radius: 12px;
  padding: 18px 22px;
  margin-bottom: 22px;
  box-shadow: var(--shadow);
  font-family: var(--sans);
  text-align: center;
}
.quiz-scorebar .score-head {
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .8px;
  color: var(--muted); margin-bottom: 4px;
}
.quiz-scorebar .score-num { font-size: 34px; font-weight: 800; color: var(--brand); line-height: 1.1; }
.quiz-scorebar .score-num span { font-size: 20px; font-weight: 600; color: var(--muted); }
.quiz-scorebar .score-pct { font-size: 16px; font-weight: 700; color: var(--good); margin-top: 2px; }
.quiz-scorebar .score-msg { font-size: 13.5px; color: var(--muted); margin-top: 6px; }

/* quiz action buttons */
.quiz-actions {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  margin: 6px 0 30px; font-family: var(--sans);
}
.quiz-submit, .quiz-retake {
  background: var(--brand); color: #fff; border: none;
  padding: 11px 22px; border-radius: 8px; font-size: 15px; font-weight: 700;
  cursor: pointer; font-family: var(--sans);
}
.quiz-submit:hover, .quiz-retake:hover { filter: brightness(1.12); }
.quiz-retake { background: #6b7280; }
.quiz-progress { font-size: 13px; color: var(--muted); font-weight: 600; }

/* business scenario blocks in quizzes */
.quiz-scenario-group {
  border-left: 4px solid var(--brand-2);
  padding-left: 16px;
  margin-bottom: 24px;
}
.quiz-scenario {
  background: #eef2fb;
  border: 1px solid #d3ddf0;
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 16px;
  font-family: var(--sans);
}
.quiz-scenario .scenario-label {
  font-size: 12px; font-weight: 800; letter-spacing: .8px; text-transform: uppercase;
  color: var(--brand-2); margin-bottom: 8px;
}
.quiz-scenario .scenario-body { font-size: 15.5px; line-height: 1.6; color: #1f2a44; }
.quiz-scenario .scenario-body p:first-child { margin-top: 0; }
.quiz-scenario .scenario-body p:last-child { margin-bottom: 0; }
.quiz-scenario-group .quiz-q { margin-bottom: 14px; }
.quiz-scenario-group .quiz-q:last-child { margin-bottom: 0; }

/* ===== Presentation mode (lecture slides) ===== */
.present-toggle {
  font-family: var(--sans); font-size: 13px; font-weight: 700;
  background: var(--brand); color: #fff; border: none;
  border-radius: 8px; padding: 7px 12px; cursor: pointer; white-space: nowrap;
}
.present-toggle:hover { background: var(--brand-2); }

body.presenting { overflow: hidden; }

.present-overlay {
  position: fixed; inset: 0; z-index: 8000;
  background: #0f1320; color: #f5f6fa;
  display: flex; flex-direction: column;
}
.present-overlay[hidden] { display: none; }

.present-stage {
  flex: 1 1 auto; overflow: auto;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 4vh 5vw;
}
.slide {
  width: 100%; max-width: 1040px;
  background: #fff; color: #1a2233;
  border-radius: 16px;
  padding: 44px 52px;
  box-shadow: 0 12px 48px rgba(0,0,0,.45);
  font-size: 21px; line-height: 1.6;
  min-height: 62vh;
}
.slide p { margin: 0 0 14px; }
.slide ul, .slide ol { padding-left: 26px; margin: 0 0 14px; }
.slide li { margin-bottom: 8px; }
.slide strong { color: #111; }
.slide .table-scroll, .slide table.data-table { font-size: 16px; }
.slide figure { margin: 8px auto; }
.slide video { max-width: 100%; border-radius: 10px; }

.slide-title { display: flex; flex-direction: column; justify-content: center; text-align: center; }
.slide-chapter {
  font-family: var(--sans); font-size: 15px; font-weight: 700;
  letter-spacing: .8px; text-transform: uppercase; color: var(--brand-2); margin-bottom: 20px;
}
.slide-h1 { font-family: var(--sans); font-size: 42px; font-weight: 800; color: var(--brand); margin: 0 0 18px; line-height: 1.15; }
.slide-summary { font-size: 22px; color: var(--muted); }

.slide-eyebrow {
  font-family: var(--sans); font-size: 13.5px; font-weight: 700;
  letter-spacing: .6px; text-transform: uppercase; color: var(--brand-2); margin-bottom: 18px;
}
.slide-prompt > *:first-child, .slide-body > *:first-child { margin-top: 0; }

.slide .frag { display: none; }
.slide .frag.revealed { display: block; animation: fragIn .16s ease; }
@keyframes fragIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.slide-solution, .slide-answer {
  margin-top: 24px; background: #f3f8f4; border: 1px solid #cfe6d6;
  border-radius: 12px; padding: 16px 20px;
}
.soln-label {
  font-family: var(--sans); font-size: 12.5px; font-weight: 800;
  letter-spacing: .6px; text-transform: uppercase; color: var(--good); margin-bottom: 8px;
}
.slide-choices { font-family: var(--sans); list-style: upper-alpha; }
.slide-choice { margin: 8px 0; }

.present-bar {
  flex: 0 0 auto; display: flex; align-items: center; gap: 14px;
  padding: 10px 18px; background: #0b0e18; color: #cfd3e0;
  font-family: var(--sans); font-size: 14px; border-top: 1px solid #1d2333;
}
.present-bar button {
  background: #222840; color: #e8eaf2; border: 1px solid #333a55;
  border-radius: 8px; padding: 8px 14px; font-size: 15px; cursor: pointer;
}
.present-bar button:hover { background: #2c3350; }
.present-arrow { font-size: 20px; line-height: 1; padding: 6px 18px; }
.present-counter { font-variant-numeric: tabular-nums; min-width: 60px; text-align: center; }
.present-topicname { color: #9aa0b6; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 38vw; }
.present-hint { margin-left: auto; color: #67708c; font-size: 12.5px; }
.present-exit { background: #3a2230 !important; border-color: #5a3346 !important; color: #f3c8d2 !important; }

@media (max-width: 700px) {
  .slide { padding: 28px 22px; font-size: 18px; min-height: 70vh; }
  .slide-h1 { font-size: 30px; }
  .present-hint { display: none; }
  .present-topicname { display: none; }
  .present-toggle { padding: 6px 9px; }
}

/* ===== Predict-then-reveal / faded example solutions ===== */
.example-attempt {
  margin-top: 16px;
  border-top: 1px dashed #e0d49a;
  padding-top: 14px;
}
.attempt-nudge {
  font-family: var(--sans);
  font-size: 14px; color: #7a5d00; margin-bottom: 10px;
}
.attempt-actions { display: flex; flex-wrap: wrap; gap: 10px; font-family: var(--sans); }
.reveal-btn {
  background: var(--brand); color: #fff; border: none;
  border-radius: 8px; padding: 8px 14px; font-size: 14px; font-weight: 700; cursor: pointer;
}
.reveal-btn:hover { background: var(--brand-2); }
.reveal-btn:disabled { background: #9aa3b2; cursor: default; }
.reveal-all { background: #6b7280; }
.reveal-all:hover { background: #565d6b; }
.reveal-hide { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.reveal-hide:hover { background: #f0f0e7; }

.solution-wrap { font-size: 17px; }
.soln-step { display: none; }
.soln-step.revealed { display: block; animation: fragIn .16s ease; }
.soln-step p { margin: 0 0 14px; }
.soln-step > *:last-child { margin-bottom: 0; }

/* Fading-sequence mode badges (worked → faded → solo) */
.ex-mode-badge {
  font-family: var(--sans);
  font-size: 11px; font-weight: 800; letter-spacing: .5px; text-transform: uppercase;
  padding: 2px 10px; border-radius: 999px;
}
.ex-worked     { background: #e6edfb; color: #1f4ba8; border: 1px solid #b9ccf0; }
.ex-faded      { background: #fdf0d2; color: #8a5a00; border: 1px solid #f0d79a; }
.ex-completion { background: #fdf0d2; color: #8a5a00; border: 1px solid #f0d79a; }
.ex-solo       { background: #e6f5ec; color: #1a7d44; border: 1px solid #b6e0c6; }
.attempt-nudge.worked-note { color: #1f4ba8; }

/* Tools page cards */
.chapter-card.tool-card { border-color: #cdbce8; }
.chapter-card.tool-card:hover { border-color: #7c6bb0; }
.chapter-card.tool-card h3, .chapter-card.tool-card h2 { color: #5b4b8a; }

/* Completion-problem "your turn" blanks */
.soln-blank {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  margin: 0 0 14px; padding: 11px 14px;
  border: 1.5px dashed #c9b36b; border-radius: 8px; background: #fffdf5;
  font-family: var(--sans);
}
.soln-blank.done { display: none; }
.soln-blank-label { font-size: 14px; font-weight: 600; color: #7a5d00; flex: 1 1 200px; }
.soln-blank .reveal-step { background: #b8860b; }
.soln-blank .reveal-step:hover { background: #9a7209; }

/* Numeric-entry (generative-retrieval) practice items */
.numeric-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 12px 0 0; font-family: var(--sans); }
.numeric-input {
  font-family: var(--sans); font-size: 15px; padding: 8px 11px;
  border: 1.5px solid var(--line); border-radius: 8px; width: 170px; max-width: 60vw;
}
.numeric-input:focus { outline: 3px solid var(--brand); outline-offset: 1px; border-color: var(--brand); }
.numeric-input.correct   { border-color: #1a7d44; background: #eef9f1; color: #14532d; font-weight: 700; }
.numeric-input.incorrect { border-color: #b3261e; background: #fdeceb; color: #7f1d1d; font-weight: 700; }
.numeric-input:disabled  { opacity: 1; }
.numeric-unit { font-size: 14px; color: var(--muted); }
.numeric-check { background: var(--brand); }
.numeric-feedback { margin-top: 10px; font-family: var(--sans); font-size: 14.5px; font-weight: 600; }
.numeric-feedback.correct   { color: #1a7d44; }
.numeric-feedback.incorrect { color: #b3261e; }

/* ---- Stat joke of the day (home page) ---- */
.joke-card {
  margin: 40px 0 8px;
  background: linear-gradient(180deg, #f7f4fc 0%, var(--panel) 100%);
  border: 1px solid #cdbce8;
  border-radius: 12px;
  padding: 20px 22px;
  box-shadow: var(--shadow);
}
.joke-card h2 { color: #5b4b8a; font-size: 18px; }
.joke-text { margin: 0 0 6px; font-size: 16.5px; line-height: 1.55; }
.joke-tag { margin: 0; font-size: 13px; color: var(--muted); font-style: italic; }
.joke-btn {
  margin-top: 14px;
  font-family: var(--sans); font-size: 14px; font-weight: 600;
  color: #fff; background: #5b4b8a;
  border: 0; border-radius: 8px; padding: 9px 16px; cursor: pointer;
  transition: background .12s ease;
}
.joke-btn:hover { background: #4a3d73; }
.joke-btn:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .joke-btn { transition: none; } }
