:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --text: #1d2330;
  --muted: #5c6577;
  --border: #dde1e8;
  --accent: #2f6fde;
  --sim-bg: #ffffff;
  --sim-fg: #1d2330;
  --grid: #e8ebf0;
  /* Series colours for plots and diagrams */
  --c1: #2f6fde;  /* blue   */
  --c2: #e0662b;  /* orange */
  --c3: #1f9d6b;  /* green  */
  --c4: #c2398f;  /* magenta*/
  --c5: #c99a06;  /* amber  */
  --c6: #7a52d1;  /* violet */
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --surface: #1b1f27;
    --text: #e6e9ef;
    --muted: #9aa3b2;
    --border: #2c323d;
    --accent: #6c9cf0;
    --sim-bg: #0e1116;
    --sim-fg: #e6e9ef;
    --grid: #1f252f;
    --c1: #6c9cf0;
    --c2: #f08a52;
    --c3: #3cc48d;
    --c4: #e46bb7;
    --c5: #e8c040;
    --c6: #a586ef;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}
a { color: var(--accent); }

.site-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.brand { font-weight: 700; text-decoration: none; color: var(--text); }
.site-footer { padding: 24px 16px; color: var(--muted); text-align: center; font-size: .9rem; }

.container { max-width: 1100px; margin: 0 auto; padding: 24px 16px; }
.lead { color: var(--muted); font-size: 1.1rem; }

/* Catalog */
.filter { display: inline-block; margin: 8px 0 20px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.card {
  display: block; padding: 16px; text-decoration: none; color: inherit;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.card:hover { border-color: var(--accent); }
.card img { width: 100%; border-radius: 6px; margin-bottom: 8px; }
.card h2 { font-size: 1.15rem; margin: 6px 0; }
.card p { margin: 0; color: var(--muted); }
.tag { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--accent); }

/* Simulation page */
.sim-layout { display: grid; gap: 24px; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
@media (max-width: 800px) { .sim-layout { grid-template-columns: 1fr; } }
.sim-panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px;
}
.sim-canvas { width: 100%; aspect-ratio: 4 / 3; display: block; background: var(--sim-bg); border-radius: 6px; }
.controls { display: grid; gap: 10px; margin-top: 14px; }
.controls label { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; font-size: .95rem; }
.controls input[type=range] { grid-column: 1 / -1; width: 100%; }
.buttons { display: flex; gap: 8px; }
button {
  font: inherit; padding: 6px 14px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
button:hover { border-color: var(--accent); }
.content h2 { margin-top: 1.6em; }
.content .equation { font-family: Georgia, serif; font-size: 1.1rem; text-align: center; margin: 12px 0; }

/* ---------- Course index (home page) ---------- */
.section-title { margin-top: 2em; }
.course { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin: 16px 0; }
.course-head h2 { margin: 2px 0 4px; }
.course-head p { margin: 0; color: var(--muted); }
.course-meta { font-size: .85rem; color: var(--muted); }
.unit { border-top: 1px solid var(--border); padding: 4px 0; }
.unit:first-of-type { margin-top: 12px; }
.unit summary { cursor: pointer; padding: 10px 0; font-weight: 600; list-style: none; display: flex; gap: 10px; align-items: baseline; }
.unit summary::-webkit-details-marker { display: none; }
.unit summary::before { content: "▸"; color: var(--accent); transition: transform .15s; display: inline-block; }
.unit[open] summary::before { transform: rotate(90deg); }
.unit-num { color: var(--accent); min-width: 4.5em; }
.unit-lec { margin-left: auto; font-weight: 400; font-size: .85rem; color: var(--muted); white-space: nowrap; }
.topic-list { list-style: none; margin: 0 0 12px; padding: 0 0 0 1.4em; counter-reset: topic; }
.topic-list li { counter-increment: topic; display: flex; gap: 10px; padding: 3px 0; align-items: baseline; flex-wrap: wrap; }
.topic-list li::before { content: counter(topic) "."; color: var(--muted); min-width: 1.6em; font-variant-numeric: tabular-nums; }
.topic-list .sim-name { color: var(--muted); font-size: .85rem; }
.readings { margin-top: 8px; font-size: .9rem; color: var(--muted); }
.readings summary { cursor: pointer; }

/* ---------- Simulation pages ---------- */
.breadcrumb { font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.breadcrumb a { color: var(--muted); }
.breadcrumb a:hover { color: var(--accent); }
.on-this-page { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 16px; margin: 12px 0 8px; font-size: .95rem; }
.on-this-page strong { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.on-this-page ol { margin: 4px 0 0; padding-left: 1.4em; }
.page-nav { display: flex; justify-content: space-between; gap: 12px; margin-top: 32px; flex-wrap: wrap; }
.page-nav a { display: block; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); text-decoration: none; max-width: 48%; }
.page-nav a:hover { border-color: var(--accent); }
.page-nav small { display: block; color: var(--muted); }
.page-nav .next { margin-left: auto; text-align: right; }

.topic { margin-top: 36px; scroll-margin-top: 16px; }
.topic > h2 { margin-bottom: 4px; }
.topic > .intro { color: var(--muted); margin-top: 0; }
.sim-canvas.wide { aspect-ratio: 16 / 9; }
.sim-layout.full { grid-template-columns: 1fr; }
.sim-layout.full > .content { columns: 2 320px; column-gap: 32px; }
.sim-layout.full > .content > * { break-inside: avoid; }
.sim-layout.full > .content > h3:first-child { margin-top: 0; }
.sim-canvas.tall { aspect-ratio: 1 / 1; }
.seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; border-right: 1px solid var(--border); }
.seg button:last-child { border-right: 0; }
.seg button.active { background: var(--accent); color: #fff; }
.control-row { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; }
.readout { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .85rem; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; display: grid; grid-template-columns: auto auto; gap: 2px 12px; justify-content: start; }
.readout b { font-weight: 600; color: var(--accent); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .85rem; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }
.note { border-left: 3px solid var(--accent); padding: 4px 12px; color: var(--muted); background: var(--bg); border-radius: 0 6px 6px 0; }
.content table { border-collapse: collapse; width: 100%; font-size: .9rem; }
.content th, .content td { border-bottom: 1px solid var(--border); padding: 5px 6px; text-align: left; vertical-align: top; }
.content .equation sub, .content .equation sup { font-size: .7em; }
