/* === RESET & BASE === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: #333;
  background: #fff;
  line-height: 1.7;
  display: flex;
  min-height: 100vh;
}

/* === SIDEBAR === */
.sidebar {
  width: 260px;
  min-width: 260px;
  background: #f8f9fa;
  border-right: 1px solid #e0e0e0;
  padding: 20px 16px;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  overflow-y: auto;
  transition: transform 0.25s ease, width 0.25s ease, min-width 0.25s ease;
  z-index: 100;
}

.sidebar.collapsed {
  transform: translateX(-260px);
  width: 0;
  min-width: 0;
  padding: 0;
  overflow: hidden;
}

.sidebar-title {
  font-weight: 700;
  font-size: 15px;
  color: #1a1a1a;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid #ddd;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sidebar-toggle {
  background: none;
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 2px 8px;
  cursor: pointer;
  font-size: 12px;
  color: #666;
}

.sidebar-toggle:hover { background: #eee; }

.sidebar-cluster {
  color: #888;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 14px 0 4px;
}

.sidebar-link {
  display: block;
  padding: 3px 0 3px 10px;
  color: #555;
  text-decoration: none;
  font-size: 13px;
  border-left: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}

.sidebar-link:hover { color: #1565c0; }

.sidebar-link.active {
  color: #1565c0;
  font-weight: 600;
  border-left-color: #1565c0;
}

.sidebar-subsection {
  display: block;
  padding: 1px 0 1px 22px;
  color: #888;
  text-decoration: none;
  font-size: 11.5px;
}

.sidebar-subsection:hover { color: #1565c0; }

/* Floating open button when sidebar is collapsed */
.sidebar-open {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 99;
  background: #f8f9fa;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 16px;
  display: none;
  color: #555;
}

.sidebar-open:hover { background: #eee; }

.sidebar.collapsed ~ .sidebar-open { display: block; }
.sidebar.collapsed ~ .main-content { margin-left: 0; }

/* === MAIN CONTENT === */
.main-content {
  margin-left: 260px;
  padding: 32px 40px 60px;
  max-width: 780px;
  width: 100%;
  min-width: 0; /* let the column shrink beside the fixed sidebar on 769-1039px screens instead of overflowing the page */
  transition: margin-left 0.25s ease;
}

.page-title {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 26px;
  font-weight: 700;
  color: #1a1a1a;
  margin-bottom: 4px;
}

.page-subtitle {
  font-size: 13px;
  color: #888;
  margin-bottom: 24px;
}

/* === IN-PAGE TOC === */
.page-toc {
  background: #f5f7fa;
  border: 1px solid #e8ecf0;
  border-radius: 4px;
  padding: 14px 18px;
  margin-bottom: 28px;
}

.page-toc-title {
  font-weight: 600;
  font-size: 13px;
  color: #333;
  margin-bottom: 6px;
}

.page-toc a {
  display: block;
  padding: 2px 0;
  color: #1565c0;
  text-decoration: none;
  font-size: 13px;
}

.page-toc a:hover { text-decoration: underline; }

.page-toc .toc-interactive {
  margin-top: 6px;
  font-style: italic;
}

/* === SECTION HEADINGS === */
h2.section-heading {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 20px;
  font-weight: 600;
  color: #1a1a1a;
  margin: 36px 0 12px;
  padding-top: 12px;
  border-top: 1px solid #eee;
}

h3.subsection-heading {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 16px;
  font-weight: 600;
  color: #333;
  margin: 24px 0 8px;
}

/* === CONTENT BOXES === */
.definition-box {
  border-left: 3px solid #1565c0;
  background: #f5f8ff;
  padding: 14px 18px;
  margin: 16px 0;
  border-radius: 0 4px 4px 0;
}

.definition-box .box-label {
  font-size: 11px;
  font-weight: 600;
  color: #1565c0;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 4px;
}

.insight-box {
  border-left: 3px solid #e67e22;
  background: #fff8f0;
  padding: 14px 18px;
  margin: 16px 0;
  border-radius: 0 4px 4px 0;
}

.insight-box .box-label {
  font-size: 11px;
  font-weight: 600;
  color: #e67e22;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 4px;
}

/* === COLLAPSIBLE SECTIONS === */
.collapsible {
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  margin: 16px 0;
  overflow: hidden;
}

.collapsible-header {
  background: #f8f9fa;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  color: #555;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
}

.collapsible-header:hover { background: #f0f1f3; }

.collapsible-header::after {
  content: '\25B8';
  font-size: 12px;
  color: #999;
  transition: transform 0.2s;
}

.collapsible.open > .collapsible-header::after {
  transform: rotate(90deg);
}

.collapsible-body {
  display: none;
  padding: 14px 18px;
  font-size: 14px;
  line-height: 1.7;
  border-top: 1px solid #e0e0e0;
}

.collapsible.open > .collapsible-body { display: block; }

/* === INTERACTIVE CONTAINER === */
.interactive-container {
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  padding: 18px;
  margin: 20px 0;
  background: #fafafa;
}

.interactive-label {
  font-size: 11px;
  font-weight: 600;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 12px;
}

/* === STEP-BY-STEP WALKTHROUGH === */
.walkthrough-steps {
  display: flex;
  gap: 0;
  margin-bottom: 16px;
}

.walkthrough-step-tab {
  flex: 1;
  text-align: center;
  padding: 8px 4px;
  font-size: 12px;
  background: #e8ecf0;
  color: #888;
  cursor: pointer;
  border: 1px solid #ddd;
  border-right: none;
  transition: background 0.15s, color 0.15s;
}

.walkthrough-step-tab:first-child { border-radius: 4px 0 0 4px; }
.walkthrough-step-tab:last-child { border-radius: 0 4px 4px 0; border-right: 1px solid #ddd; }

.walkthrough-step-tab.active {
  background: #1565c0;
  color: #fff;
  font-weight: 600;
  border-color: #1565c0;
}

.walkthrough-content {
  margin-bottom: 14px;
}

.walkthrough-nav {
  display: flex;
  justify-content: space-between;
  padding-top: 12px;
  border-top: 1px solid #eee;
  font-size: 13px;
}

.walkthrough-nav button {
  background: none;
  border: none;
  color: #1565c0;
  cursor: pointer;
  font-size: 13px;
  padding: 4px 0;
}

.walkthrough-nav button:disabled { color: #ccc; cursor: default; }
.walkthrough-nav button:hover:not(:disabled) { text-decoration: underline; }

/* === FLASHCARDS === */
.flashcard-container {
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  padding: 18px;
  margin: 20px 0;
  background: #fff;
}

.flashcard-counter {
  font-size: 11px;
  color: #999;
  text-align: center;
  margin-bottom: 8px;
}

.flashcard {
  background: #f5f7fa;
  border-radius: 6px;
  padding: 24px;
  text-align: center;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.flashcard-question {
  font-size: 15px;
  font-weight: 500;
  color: #1a1a1a;
  line-height: 1.5;
}

.flashcard-answer {
  display: none;
  font-size: 14px;
  color: #444;
  line-height: 1.6;
  margin-top: 12px;
  text-align: left;
  width: 100%;
}

.flashcard-answer.visible { display: block; }

.flashcard-reveal {
  margin-top: 14px;
  font-size: 12px;
  color: #1565c0;
  cursor: pointer;
  border: 1px solid #1565c0;
  padding: 5px 20px;
  border-radius: 3px;
  background: none;
}

.flashcard-reveal:hover { background: #f0f4ff; }

.flashcard-buttons {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 14px;
}

.flashcard-btn {
  font-size: 12px;
  padding: 5px 16px;
  border-radius: 4px;
  cursor: pointer;
  border: 1px solid;
  background: none;
}

.flashcard-btn.again { color: #c62828; border-color: #c62828; }
.flashcard-btn.again:hover { background: #fef0f0; }
.flashcard-btn.got-it { color: #2e7d32; border-color: #2e7d32; }
.flashcard-btn.got-it:hover { background: #f0fef0; }

.flashcard-progress {
  text-align: center;
  margin-top: 12px;
  font-size: 11px;
  color: #888;
}

/* === FIGURES === */
.figure-container {
  margin: 20px 0;
  text-align: center;
}

.figure-container img {
  max-width: 100%;
  border: 1px solid #eee;
  border-radius: 4px;
}

.figure-caption {
  font-size: 12px;
  color: #888;
  margin-top: 6px;
  font-style: italic;
}

/* === TABLES === */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 13.5px;
}

th {
  background: #f5f7fa;
  font-weight: 600;
  text-align: left;
  padding: 8px 12px;
  border-bottom: 2px solid #ddd;
}

td {
  padding: 8px 12px;
  border-bottom: 1px solid #eee;
}

/* === MATH === */
.math-block {
  overflow-x: auto;
  margin: 12px 0;
  padding: 8px;
  background: #fafafa;
  border-radius: 4px;
  text-align: center;
}

/* KaTeX inline math inside headings and flex containers */
.collapsible-header .katex,
.section-heading .katex,
.subsection-heading .katex {
  display: inline;
  vertical-align: baseline;
  line-height: inherit;
  font-size: inherit;
}

.collapsible-header .katex .katex-html {
  display: inline;
  vertical-align: baseline;
}

.collapsible-header .katex .base {
  vertical-align: baseline;
}

/* === PREV/NEXT NAVIGATION === */
.page-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 36px;
  padding-top: 20px;
  border-top: 1px solid #e0e0e0;
  font-size: 13px;
}

.page-nav a {
  color: #1565c0;
  text-decoration: none;
}

.page-nav a:hover { text-decoration: underline; }

/* === SLIDER CONTROLS === */
.slider-group {
  display: flex;
  gap: 20px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.slider-control {
  flex: 1;
  min-width: 150px;
}

.slider-control label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: #555;
  margin-bottom: 4px;
}

.slider-control label span { font-weight: 600; color: #333; }

.slider-control input[type="range"] {
  width: 100%;
  accent-color: #1565c0;
}

/* === RESPONSIVE === */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-260px); }
  .sidebar.open-mobile { transform: translateX(0); }
  .sidebar-open { display: block; }
  .main-content { margin-left: 0; padding: 64px 20px 20px; }
}

/* === LANDING PAGE SPECIFIC === */
.landing-header {
  text-align: center;
  padding: 40px 0 30px;
}

.landing-title {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 28px;
  font-weight: 700;
  color: #1a1a1a;
  margin-bottom: 6px;
}

.landing-subtitle {
  font-size: 14px;
  color: #888;
}

.concept-map-container {
  margin: 20px 0 40px;
  background: #fafafa;
  border: 1px solid #e8ecf0;
  border-radius: 6px;
  padding: 20px;
}

.module-list {
  margin: 30px 0;
}

.module-list h3 {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 16px;
  color: #1a1a1a;
  margin: 20px 0 8px;
}

.module-list a {
  display: block;
  padding: 4px 0 4px 12px;
  color: #1565c0;
  text-decoration: none;
  font-size: 14px;
}

.module-list a:hover { text-decoration: underline; }

.module-list .module-desc {
  color: #888;
  font-size: 12px;
  margin-left: 4px;
}

.back-link {
  font-size: 13px;
  color: #1565c0;
  text-decoration: none;
  display: inline-block;
  margin-bottom: 10px;
}

.back-link:hover { text-decoration: underline; }

/* === WARNING BOX (from 2IX30) === */
.warning-box {
  border-left: 3px solid #c62828;
  background: #fff5f5;
  padding: 14px 18px;
  margin: 16px 0;
  border-radius: 0 4px 4px 0;
}

.warning-box .box-label {
  font-size: 11px;
  font-weight: 600;
  color: #c62828;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 4px;
}

/* === RESEARCH-NOTES ADDITIONS === */
/* Lists: the global reset strips list indentation */
.main-content ul, .main-content ol { margin: 8px 0 8px 22px; }
.main-content li { margin: 2px 0; }

/* Paper citations */
a.cite { color: #1565c0; text-decoration: none; }
a.cite:hover { text-decoration: underline; }

/* Pseudocode (a div, not <pre>, so KaTeX still renders inside) */
.algorithm {
  border-top: 2px solid #1a1a1a;
  border-bottom: 2px solid #1a1a1a;
  background: #fcfcfc;
  padding: 8px 16px 10px;
  margin: 18px 0;
  font-size: 13.5px;
  line-height: 1.8;
}

.algorithm-title {
  font-weight: 600;
  font-size: 13px;
  border-bottom: 1px solid #ccc;
  padding-bottom: 4px;
  margin-bottom: 6px;
}

.algorithm ol { margin: 0 0 0 24px; }
.algorithm .indent { padding-left: 20px; }
.algorithm .comment { color: #888; font-style: italic; }

/* Wide tables (papers, comparison tables with math) scroll instead of widening the page on phones and on
   tablet/narrow-window widths, where the column is narrower than 780px beside the sidebar */
@media (max-width: 1039px) {
  .main-content table { display: block; overflow-x: auto; position: relative; }
}

/* Display math scrolls horizontally when wider than the column (also outside .math-block wrappers) */
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; position: relative; }
/* KaTeX's hidden MathML copy is position:absolute; scroll containers must be positioned to clip it */
.math-block { position: relative; }

/* === SMALL SCREENS: no state of any page may be wider than the viewport === */
/* Phones: a formula that cannot wrap (one wide KaTeX box: a matrix, a long tuple) scrolls inside its own box instead of
   widening the page. Wrap it as <span class="math-scroll">$...$</span> (kept on one line; screens up to 500px) or, when
   KaTeX's own line breaks suffice on all but the smallest phones, as <span class="math-scroll-xs">$...$</span> (up to 360px).
   Works in static text and in the strings of walkthrough steps and flashcards alike. */
@media (max-width: 500px) {
  .math-scroll { display: inline-block; max-width: 100%; overflow-x: auto; overflow-y: hidden; vertical-align: middle; position: relative; padding: 4px 0; white-space: nowrap; }
}
@media (max-width: 360px) {
  .math-scroll-xs { display: inline-block; max-width: 100%; overflow-x: auto; overflow-y: hidden; vertical-align: middle; position: relative; padding: 4px 0; }
}
/* a select with long option text must be able to shrink below its intrinsic width inside a wrapping flex row */
@media (max-width: 600px) {
  .interactive-container label { min-width: 0; max-width: 100%; }
  .interactive-container select { max-width: 100%; }
}
/* Walkthrough step tabs (up to 7) wrap onto a second row instead of overflowing the panel */
@media (max-width: 480px) {
  .walkthrough-steps { flex-wrap: wrap; gap: 4px; }
  .walkthrough-step-tab, .walkthrough-step-tab:first-child, .walkthrough-step-tab:last-child { flex: 1 1 auto; border: 1px solid #ddd; border-radius: 4px; }
  .walkthrough-step-tab.active { border-color: #1565c0; }
}

/* === "Before you start" prerequisite box (top of each module) === */
.prereq-box {
  background: #f6f8f9;
  border: 1px solid #e0e6ea;
  border-left: 3px solid #455a64;
  border-radius: 0 4px 4px 0;
  padding: 12px 18px;
  margin: 0 0 24px;
  font-size: 13.5px;
  line-height: 1.6;
}

.prereq-box .prereq-title {
  font-size: 11px;
  font-weight: 600;
  color: #455a64;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 4px;
}

.prereq-box ul { margin: 4px 0 0 20px; }
.prereq-box li { margin: 1px 0; }
.prereq-box a { color: #1565c0; text-decoration: none; }
.prereq-box a:hover { text-decoration: underline; }
.prereq-box .prereq-src { color: #888; font-size: 12px; }

/* Collapsible headers often contain inline math; the flex layout spread words and formulas apart.
   Lay the header out as ordinary text and pin the arrow to the right instead. */
.collapsible-header { display: block; position: relative; padding-right: 34px; }
.collapsible-header::after { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); }
.collapsible.open > .collapsible-header::after { transform: translateY(-50%) rotate(90deg); }

/* === READABILITY (2026-10-01) ===
   The global reset removes every margin, so consecutive paragraphs used to run together with no gap.
   Space paragraphs and list items, and give lines a little more height so inline math (fractions, subscripts) does not crowd them. */
.main-content { line-height: 1.8; }
.main-content h1, .main-content h2, .main-content h3, .main-content h4 { line-height: 1.35; }
.main-content p { margin-bottom: 14px; }
.main-content p:last-child { margin-bottom: 0; }
.main-content li { margin: 6px 0; }
.main-content table { line-height: 1.6; }
.collapsible-body { font-size: 15px; line-height: 1.8; }
.prereq-box { font-size: 14px; line-height: 1.7; }

/* === EXPLANATION AIDS (2026-10-01) ===
   "In plain words." run-in labels and "Symbols" boxes that define every symbol a section uses. */
.lead-label { font-weight: 600; color: #1a1a1a; }
.symbols-box { background: #f8f9fb; border: 1px solid #e3e8ee; border-radius: 4px; padding: 10px 16px; margin: 16px 0; font-size: 15px; line-height: 1.75; }
.symbols-box .symbols-title { font-size: 11px; font-weight: 600; color: #455a64; text-transform: uppercase; letter-spacing: 0.3px; }
.symbols-box ul { margin: 4px 0 0 18px; }
.symbols-box li { margin: 4px 0; }

/* Reading and practice: visible keyboard focus and room around linked headings. */
[id] { scroll-margin-top: 56px; }
a:focus-visible, button:focus-visible, summary:focus-visible,
[role="button"]:focus-visible, [tabindex="0"]:focus-visible {
  outline: 3px solid #1565c0;
  outline-offset: 3px;
}
.skip-link {
  position: fixed; top: 8px; left: 8px; z-index: 200;
  transform: translateY(-150%); padding: 8px 14px;
  color: #1565c0; background: #fff; border: 2px solid #1565c0;
}
.skip-link:focus { transform: translateY(0); }
.walkthrough-step-tab { font-family: inherit; line-height: 1.5; }
.main-content details > summary { line-height: 1.55; }
.main-content details > summary:hover { color: #1565c0; }
.reading-route { border-left-color: #455a64; background: #f6f8f9; }
.topic-map-scroll { overflow-x: auto; max-width: 100%; }
.topic-map-scroll svg { display: block; min-width: 760px; }
.landing-content { max-width: 900px; margin: 0 auto; padding: 32px 40px 60px; }
.landing-content p { margin-bottom: 14px; }
.landing-content li { margin: 6px 0; }
@media (max-width: 768px) {
  .landing-content { padding: 20px; }
  .landing-header { padding-top: 20px; }
}
@media print {
  .sidebar, .sidebar-open, .skip-link, .page-nav { display: none !important; }
  .main-content { margin: 0; padding: 0; max-width: none; }
  .collapsible-body { display: block !important; }
  details, .definition-box, .insight-box { break-inside: avoid; }
  a { color: inherit; }
}

/* Book application chapters and reference pages. */
.book-entry { font-size: 13px; color: #555; margin: 14px 0; }
.book-chapter { margin: 28px 0; padding-top: 8px; border-top: 2px solid #d0d8ea; }
.book-chapter details, .book-content details { border: 1px solid #d0d8ea; border-radius: 6px; margin: 14px 0; overflow: hidden; }
.book-chapter details > summary, .book-content details > summary { padding: 12px 16px; cursor: pointer; font-weight: 600; background: #f0f4fb; }
.book-chapter details > p, .book-content details > p { margin: 12px 16px; }
.book-chapter details > details, .book-content details > details { margin: 10px 14px; }
.book-chapter details > div, .book-content details > div { padding: 10px 16px; }
.book-chapter details details > summary, .book-content details details > summary { background: #f7f9fc; color: #2d5fa6; }
.book-contents { padding-left: 22px; }
.book-contents li { margin: 10px 0; }
.book-glossary dt { margin-top: 20px; color: #1a1a1a; font-weight: 700; }
.book-glossary dd { margin: 4px 0 0; }
.book-chapter li, .book-content li { margin-bottom: 6px; }
@media print {
  .book-entry, .page-toc { display: none !important; }
  .book-chapter details, .book-content details, .collapsible { break-inside: auto; }
  .book-chapter summary, .book-content summary, h2, h3 { break-after: avoid; }
  .book-glossary dt { break-after: avoid; }
  .book-glossary dd { break-inside: avoid; }
  details::details-content { content-visibility: visible !important; display: block !important; }
  .math-block, .math-scroll { overflow: visible; }
  .book-chapter details > div, .book-content details > div { padding: 6px 12px; }
}
