/* ------------------------------------------------------------------
   IEEE Learn — design language from kakageldi.com (paper, dot grid,
   oversized uppercase display type, ruled rows), recoloured with
   Louisiana Tech's official palette (brand.latech.edu):
     Tech Blue  PMS 287   #003087
     Tech Red   PMS 1797  #CB333B
     Neutrals   Warm Gray 2c #CBC4BC, PMS 2135c #758CC0, PMS 540c #0A3254
   ------------------------------------------------------------------ */

:root {
  --tech-blue: #003087;
  --tech-red: #cb333b;

  --paper: #f3efe6;
  --panel: #e9e3d6;
  --ink: #111827;
  --ink-soft: rgba(17, 24, 39, 0.68);
  --ink-faint: rgba(17, 24, 39, 0.45);
  --line: #cbc4bc;
  --brand: #003087;          /* headings, primary actions */
  --accent: #cb333b;         /* highlights, active states */
  --accent-text: #b0262e;    /* red used as text: AA on paper */
  --band: #003087;           /* solid blue bands */
  --band-ink: #f3efe6;
  --dot: rgba(0, 48, 135, 0.16);
  --math: #0a3254;

  /* figure colours */
  --fig-ink: #111827;
  --fig-field: #003087;
  --fig-core: #cb333b;
  --fig-section: #69b3e7;
  --fig-flux-a: #003087;
  --fig-flux-b: #cb333b;
  --fig-flux-c: #4d5f80;
  --fig-current: #cb333b;

  --font-display: "Space Grotesk", system-ui, sans-serif;
  --font-body: "Inter", system-ui, sans-serif;
  --font-script: "Caveat", cursive;

  --rail: 88px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #000000;
    --panel: #111114;
    --ink: #ece7dc;
    --ink-soft: rgba(236, 231, 220, 0.72);
    --ink-faint: rgba(236, 231, 220, 0.48);
    --line: #2a2a30;
    --brand: #8aa0d0;
    --accent: #cb333b;
    --accent-text: #ec7479;
    --band: #003087;
    --band-ink: #f3efe6;
    --dot: rgba(138, 160, 208, 0.14);
    --math: #dfe6f5;
    --fig-ink: #ece7dc;
    --fig-field: #8aa0d0;
    --fig-core: #e2575e;
    --fig-section: #69b3e7;
    --fig-flux-a: #8aa0d0;
    --fig-flux-b: #ec7479;
    --fig-flux-c: #c6dae7;
    --fig-current: #ec7479;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #000000;
  --panel: #111114;
  --ink: #ece7dc;
  --ink-soft: rgba(236, 231, 220, 0.72);
  --ink-faint: rgba(236, 231, 220, 0.48);
  --line: #2a2a30;
  --brand: #8aa0d0;
  --accent: #cb333b;
  --accent-text: #ec7479;
  --band: #003087;
  --band-ink: #f3efe6;
  --dot: rgba(138, 160, 208, 0.14);
  --math: #dfe6f5;
  --fig-ink: #ece7dc;
  --fig-field: #8aa0d0;
  --fig-core: #e2575e;
  --fig-section: #69b3e7;
  --fig-flux-a: #8aa0d0;
  --fig-flux-b: #ec7479;
  --fig-flux-c: #c6dae7;
  --fig-current: #ec7479;
  color-scheme: dark;
}

/* ---------- base ---------- */
*,
*::before,
*::after { box-sizing: border-box; }

html { scroll-behavior: smooth; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.25s ease, color 0.25s ease;
}

::selection { background: var(--accent); color: #fff; }

h1, h2, h3 { font-family: var(--font-display); text-wrap: balance; margin: 0; }
p { margin: 0 0 1rem; }
a { color: inherit; }
button { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- shared type ---------- */
.display {
  font-family: var(--font-display);
  font-weight: 700;
  text-transform: uppercase;
  line-height: 0.92;
  letter-spacing: -0.03em;
}
.display-hero { font-size: clamp(2.4rem, 8vw, 5.5rem); letter-spacing: -0.04em; }
.display-lg { font-size: clamp(2rem, 6vw, 4.2rem); }
.display-md { font-size: clamp(1.5rem, 3.4vw, 2.4rem); }

.eyebrow {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.25em;
  color: var(--ink-faint);
}
.script-tag {
  font-family: var(--font-script);
  font-size: 1.9rem;
  color: var(--accent-text);
  line-height: 1.1;
}

.dot-grid {
  background-size: 26px 26px;
  background-position: -13px -13px;
}

/* ---------- shell: Canvas-style global rail ---------- */
.rail {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--rail);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 18px 0;
  background: var(--band);
  color: var(--band-ink);
  border-right: 4px solid var(--tech-red);
  z-index: 30;
}
.rail__logo {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  text-decoration: none;
  text-align: center;
  line-height: 1;
  padding: 10px 6px 18px;
}
.rail__mark { display: block; width: 56px; height: auto; margin: 0 auto 8px; }
.rail__logo span { display: block; font-size: 0.62rem; letter-spacing: 0.2em; opacity: 0.75; margin-top: 4px; }
.rail__link,
.rail__btn {
  width: 78px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 4px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-decoration: none;
  font-size: 0.62rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background-color 0.2s ease;
}
.rail__link:hover,
.rail__btn:hover { background: rgba(255, 255, 255, 0.1); }
.rail__link[aria-current="page"] { background: var(--paper); color: var(--tech-blue); }
:root[data-theme="dark"] .rail__link[aria-current="page"] { color: var(--ink); background: rgba(255,255,255,0.14); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .rail__link[aria-current="page"] { color: var(--ink); background: rgba(255,255,255,0.14); }
}
.rail svg { width: 22px; height: 22px; }
.rail__spacer { flex: 1; }

.main { margin-left: var(--rail); min-height: 100vh; }

@media (max-width: 760px) {
  :root { --rail: 0px; }
  .rail {
    inset: auto 0 0 0;
    width: 100%;
    height: 64px;
    flex-direction: row;
    justify-content: space-around;
    padding: 0 8px;
    border-right: 0;
    border-top: 4px solid var(--tech-red);
  }
  .rail__logo { display: none; }
  .rail__spacer { display: none; }
  .rail__link, .rail__btn { width: auto; flex: 1; padding: 8px 2px; }
  .main { padding-bottom: 72px; }
}

/* ---------- layout helpers ---------- */
.container { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 761px) { .container { padding: 0 40px; } }

.hero {
  position: relative;
  overflow: hidden;
  padding: 72px 0 56px;
  border-bottom: 1px solid var(--line);
}
.hero .container { position: relative; }
.hero__lead { max-width: 38rem; color: var(--ink-soft); margin-top: 20px; }

.band {
  position: relative;
  overflow: hidden;
  background: var(--band);
  color: var(--band-ink);
  border-bottom: 4px solid var(--tech-red);
  padding: 56px 0 44px;
}
.band .eyebrow { color: rgba(243, 239, 230, 0.66); }
.band .script-tag { color: #f2a3a7; }
.band .dot-grid-layer {
  position: absolute; inset: 0;
  background-size: 26px 26px;
  background-position: -13px -13px;
}
.band .container { position: relative; }

.crumbs {
  display: flex; flex-wrap: wrap; gap: 6px;
  font-size: 0.8rem; letter-spacing: 0.08em; text-transform: uppercase;
  margin-bottom: 22px;
}
.crumbs a { text-decoration: none; opacity: 0.75; }
.crumbs a:hover { opacity: 1; text-decoration: underline; }
.crumbs span[aria-hidden] { opacity: 0.45; }

.section { padding: 56px 0; }
.section-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px;
  margin-bottom: 28px;
}
.section-head .meta { font-size: 0.9rem; color: var(--ink-faint); }

/* ---------- dashboard course cards ---------- */
.cards { display: grid; gap: 20px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.card {
  position: relative;
  display: flex; flex-direction: column;
  min-height: 220px;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: var(--paper);
  text-decoration: none;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}
.card:hover { transform: translateY(-3px); box-shadow: 0 14px 30px -18px rgba(0, 0, 0, 0.45); }
.card__top {
  position: relative;
  height: 110px;
  background: var(--band);
  color: var(--band-ink);
  border-bottom: 4px solid var(--tech-red);
  padding: 18px 20px;
}
.card__top .dot-grid-layer {
  position: absolute; inset: 0;
  background-size: 18px 18px;
}
.card__code { position: relative; font-size: 2.2rem; }
.card__body { padding: 16px 20px 20px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.card__title { font-family: var(--font-display); font-weight: 500; font-size: 1.1rem; }
.card__meta { font-size: 0.85rem; color: var(--ink-soft); }
.progress { height: 6px; border-radius: 99px; background: var(--panel); overflow: hidden; margin-top: auto; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: inherit; transition: width 0.5s ease; }
.progress-label { font-size: 0.78rem; color: var(--ink-faint); }

/* ---------- course page ---------- */
.course-layout { display: grid; gap: 40px; grid-template-columns: 1fr; }
@media (min-width: 961px) { .course-layout { grid-template-columns: 200px 1fr; } }
.course-nav { display: flex; flex-direction: column; gap: 2px; position: sticky; top: 24px; align-self: start; }
.course-nav a {
  padding: 8px 12px;
  border-left: 3px solid transparent;
  text-decoration: none;
  font-size: 0.95rem;
  color: var(--ink-soft);
}
.course-nav a[aria-current="page"] { border-left-color: var(--accent); color: var(--ink); font-weight: 500; }
@media (max-width: 960px) {
  .course-nav { position: static; flex-direction: row; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
  .course-nav a { border-left: 0; border-bottom: 3px solid transparent; }
  .course-nav a[aria-current="page"] { border-bottom-color: var(--accent); }
}

.module-title { margin-bottom: 8px; }
.rows { border-bottom: 1px solid var(--line); }
.row {
  position: relative;
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px 28px;
  padding: 26px 16px;
  border-top: 1px solid var(--line);
  text-decoration: none;
}
@media (min-width: 761px) { .row { grid-template-columns: 5.5rem 1fr auto; align-items: baseline; } }
.row::before {
  content: "";
  position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--accent);
  transform: scaleY(0); transform-origin: top;
  transition: transform 0.35s ease;
  pointer-events: none;
}
.row { transition: background-color 0.3s ease; }
.row:hover { background: color-mix(in srgb, var(--ink) 4%, transparent); }
.row:hover::before { transform: scaleY(1); }
.row:hover .row__num { color: var(--accent-text); }
.row__num { font-size: 0.85rem; color: var(--ink-faint); position: relative; transition: color 0.3s ease; }
.row__main { position: relative; transition: transform 0.3s ease; }
.row__title { font-size: clamp(1.35rem, 3vw, 2rem); display: inline-block; }
.row:hover .row__main { transform: translateX(6px); }
.row__desc { color: var(--ink-soft); margin: 6px 0 0; }
.pill {
  position: relative;
  display: inline-flex; align-items: center; gap: 6px;
  width: fit-content; height: fit-content;
  padding: 4px 12px;
  border: 1px solid var(--line);
  border-radius: 99px;
  font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--ink-soft);
}
.pill--done { border-color: var(--accent); color: var(--accent-text); }
.pill--done::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }

/* ---------- lecture page ---------- */
.lecture-meta { display: flex; flex-wrap: wrap; gap: 10px 18px; margin-top: 26px; align-items: center; }
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 18px;
  border-radius: 99px;
  border: 1px solid currentColor;
  background: transparent;
  text-decoration: none;
  font-family: var(--font-display);
  font-size: 0.85rem; letter-spacing: 0.08em; text-transform: uppercase;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}
.btn svg { width: 16px; height: 16px; }
.band .btn:hover { background: var(--band-ink); color: var(--tech-blue); }
.btn--solid { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--solid:hover { background: transparent; color: var(--accent-text); }
.btn--ghost { border-color: var(--line); }
.btn--ghost:hover { border-color: var(--accent); color: var(--accent-text); }

.lecture-layout { display: grid; gap: 48px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1100px) { .lecture-layout { grid-template-columns: minmax(0, 1fr) 220px; } }

.toc { display: none; }
@media (min-width: 1100px) {
  .toc { display: block; position: sticky; top: 28px; align-self: start; font-size: 0.88rem; }
  .toc ol { list-style: none; margin: 12px 0 0; padding: 0; border-left: 1px solid var(--line); }
  .toc a {
    display: block; padding: 6px 0 6px 14px; margin-left: -1px;
    border-left: 2px solid transparent;
    text-decoration: none; color: var(--ink-soft);
  }
  .toc a.is-active { border-left-color: var(--accent); color: var(--ink); }
}

.lsec { padding: 40px 0 8px; border-top: 1px solid var(--line); scroll-margin-top: 20px; }
.lsec:first-child { border-top: 0; padding-top: 8px; }
.lsec__head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px 16px; margin-bottom: 22px; }
.lsec__num { display: block; margin-bottom: 8px; }
.lsec__title { font-size: clamp(1.5rem, 3.4vw, 2.3rem); }
.video-jump {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.8rem; color: var(--ink-soft); text-decoration: none;
  border-bottom: 1px dashed var(--line);
}
.video-jump:hover { color: var(--accent-text); border-bottom-color: var(--accent); }
.video-jump svg { width: 13px; height: 13px; }

.prose { max-width: 44rem; color: var(--ink-soft); }
.prose strong { color: var(--ink); font-weight: 500; }

.quote-board {
  font-family: var(--font-script);
  font-size: 1.6rem;
  color: var(--ink);
  margin: 0 0 12px;
}

/* math */
.math-block {
  position: relative;
  margin: 18px 0;
  padding: 20px 22px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--panel) 45%, transparent);
  color: var(--math);
  overflow-x: auto;
  overflow-y: hidden;
}
.math-block:has(.math-block__label) { padding-top: 32px; }
.math-block .katex-display { margin: 0; }
.math-block .katex { font-size: 1.22em; }
.math-block__label {
  position: absolute; top: 8px; right: 12px;
  font-size: 0.65rem; letter-spacing: 0.2em; text-transform: uppercase; color: var(--ink-faint);
}
.katex { color: inherit; }

/* derivation stepper */
.stepper { margin: 18px 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.stepper__lines { padding: 16px 22px 8px; overflow-x: auto; color: var(--math); }
.stepper__line {
  display: grid;
  grid-template-columns: 2.2rem 1fr;
  align-items: center;
  padding: 8px 0;
  transition: opacity 0.35s ease, transform 0.35s ease;
}
.stepper__line[hidden] { display: none; }
.stepper__line.is-new { animation: stepIn 0.4s ease both; }
@keyframes stepIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.stepper__idx { font-size: 0.72rem; color: var(--ink-faint); font-family: var(--font-display); }
.stepper__line .katex { font-size: 1.18em; }
.stepper__line .katex-display { margin: 0; text-align: left; }
.stepper__line .katex-display > .katex { text-align: left; }
.stepper__bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 50%, transparent);
}
.stepper__count { font-size: 0.8rem; color: var(--ink-faint); margin-right: auto; }
.chip-btn {
  padding: 6px 14px;
  border-radius: 99px;
  border: 1px solid var(--line);
  background: var(--paper);
  font-size: 0.8rem;
  cursor: pointer;
  transition: border-color 0.2s ease, color 0.2s ease, background-color 0.2s ease;
}
.chip-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent-text); }
.chip-btn:disabled { opacity: 0.4; cursor: default; }
.chip-btn--primary { background: var(--brand); border-color: var(--brand); color: var(--paper); }
.chip-btn--primary:hover:not(:disabled) { background: transparent; color: var(--brand); border-color: var(--brand); }

/* correction callout */
.callout {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 14px;
  margin: 18px 0;
  padding: 16px 18px;
  border-left: 4px solid var(--accent);
  border-radius: 0 10px 10px 0;
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  max-width: 48rem;
}
.callout__tag {
  grid-row: span 2;
  font-family: var(--font-script);
  font-size: 1.5rem;
  color: var(--accent-text);
  line-height: 1;
  padding-top: 2px;
}
.callout__title { font-family: var(--font-display); font-weight: 500; }
.callout__body { color: var(--ink-soft); font-size: 0.97rem; }
.callout__body p:last-child { margin: 0; }
@media (max-width: 520px) { .callout { grid-template-columns: 1fr; } .callout__tag { grid-row: auto; } }

/* figures */
.figure {
  margin: 20px 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}
.figure__canvas { position: relative; padding: 12px; }
.figure svg { display: block; width: 100%; height: auto; max-height: 440px; }
.figure figcaption {
  padding: 12px 18px;
  border-top: 1px solid var(--line);
  font-size: 0.88rem;
  color: var(--ink-soft);
}
.fig-text { font-family: var(--font-body); fill: var(--fig-ink); }
.fig-script { font-family: var(--font-script); }

/* case switcher (two-coil system) */
.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 4px; }
.tab {
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: transparent;
  cursor: pointer;
  font-size: 0.88rem;
  transition: all 0.2s ease;
}
.tab:hover { border-color: var(--accent); }
.tab[aria-selected="true"] { background: var(--brand); border-color: var(--brand); color: var(--paper); }
.case-panel[hidden] { display: none; }
.case-panel.is-in { animation: stepIn 0.35s ease both; }

/* calculators */
.calc {
  margin: 20px 0;
  border: 1px dashed color-mix(in srgb, var(--brand) 55%, var(--line));
  border-radius: 12px;
  padding: 18px 20px 20px;
}
.calc__head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.calc__title { font-family: var(--font-display); font-weight: 500; }
.calc__grid { display: grid; gap: 12px 16px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--ink-soft); }
.field input, .field select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  font: 500 1rem var(--font-body);
}
.field input:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 22%, transparent); }
.calc__out {
  margin-top: 16px;
  padding: 12px 16px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--panel) 60%, transparent);
  color: var(--math);
  overflow-x: auto;
}
.calc__out .katex { font-size: 1.12em; }
.calc__err { color: var(--accent-text); font-size: 0.9rem; }

/* symbols panel */
.symbols { margin: 8px 0 0; }
.symbols summary {
  cursor: pointer;
  list-style: none;
  display: inline-flex; align-items: center; gap: 10px;
  font-family: var(--font-display); font-size: 0.85rem; letter-spacing: 0.1em; text-transform: uppercase;
}
.symbols summary::-webkit-details-marker { display: none; }
.symbols summary::before { content: "+"; font-size: 1.1rem; width: 1rem; color: var(--accent-text); }
.symbols[open] summary::before { content: "−"; }
.symbol-grid { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); margin-top: 16px; }
.symbol {
  display: grid; grid-template-columns: 3.2rem 1fr; align-items: center; gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  font-size: 0.88rem;
  color: var(--ink-soft);
  transition: border-color 0.2s ease, transform 0.2s ease;
}
.symbol:hover { border-color: var(--accent); transform: translateY(-1px); }
.symbol .katex { font-size: 1.15em; color: var(--math); }
.flash { animation: flash 1.4s ease; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 45%, transparent); } 100% { box-shadow: 0 0 0 0 transparent; } }

/* complete + pager */
.finish {
  margin: 48px 0 0;
  padding: 28px 24px;
  border-radius: 14px;
  background: var(--band);
  color: var(--band-ink);
  border-bottom: 4px solid var(--tech-red);
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px;
}
.finish .btn:hover { background: var(--band-ink); color: var(--tech-blue); }
.finish .btn[aria-pressed="true"] { background: var(--tech-red); border-color: var(--tech-red); color: #fff; }
.pager { display: flex; justify-content: space-between; gap: 16px; margin: 28px 0 72px; }

.empty {
  padding: 40px 24px;
  border: 1px dashed var(--line);
  border-radius: 14px;
  text-align: center;
  color: var(--ink-soft);
}

/* reveal on scroll */
.reveal { opacity: 0; transform: translateY(20px); transition: opacity 0.6s cubic-bezier(0.22, 1, 0.36, 1), transform 0.6s cubic-bezier(0.22, 1, 0.36, 1); }
.reveal.is-in { opacity: 1; transform: none; }

/* theme icon swap */
.icon-sun, .icon-moon { display: none; }
:root[data-theme="dark"] .icon-sun { display: block; }
:root[data-theme="light"] .icon-moon { display: block; }

footer.site-foot {
  border-top: 1px solid var(--line);
  padding: 28px 0 40px;
  font-size: 0.8rem;
  color: var(--ink-faint);
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
  .reveal { opacity: 1; transform: none; }
}

/* ================= animation ================= */

/* flowing charges / field in diagrams (direction = path drawing direction) */
.flow { pointer-events: none; stroke-linecap: round; }
.flow--current { stroke-width: 3.4; stroke-dasharray: 0.1 16; animation: flow-c 0.9s linear infinite; }
.flow--field { stroke-width: 3; stroke-dasharray: 0.1 14; opacity: 0.95; animation: flow-f 1.3s linear infinite; }
.flow--rev { animation-direction: reverse; }
@keyframes flow-c { to { stroke-dashoffset: -16.1; } }
@keyframes flow-f { to { stroke-dashoffset: -14.1; } }
.figure.is-paused .flow { animation-play-state: paused; }

.fig-toggle {
  position: absolute; top: 10px; right: 10px; z-index: 2;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px;
  border-radius: 99px;
  border: 1px solid var(--line);
  background: var(--paper);
  font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--ink-soft);
  cursor: pointer;
}
.fig-toggle:hover { border-color: var(--accent); color: var(--accent-text); }
.fig-toggle svg { width: 12px; height: 12px; }
.fig-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 0.8rem; }
.fig-legend span { display: inline-flex; align-items: center; gap: 6px; }
.fig-legend i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

/* letter-by-letter headline (kakageldi.com hero) */
.split .w { display: inline-block; white-space: nowrap; }
.split .ch {
  display: inline-block;
  opacity: 0;
  transform: translateY(0.5em);
  animation: ch-in 0.6s cubic-bezier(0.22, 1, 0.36, 1) forwards;
  animation-delay: calc(var(--i) * 28ms + 120ms);
}
@keyframes ch-in { to { opacity: 1; transform: none; } }
.anim-slide { animation: slide-in 0.5s 0.1s cubic-bezier(0.22, 1, 0.36, 1) both; }
@keyframes slide-in { from { opacity: 0; transform: translateX(-12px); } to { opacity: 1; transform: none; } }
.anim-up { animation: up-in 0.6s 0.55s cubic-bezier(0.22, 1, 0.36, 1) both; }
@keyframes up-in { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }

/* page change */
.page-in { animation: page-in 0.45s cubic-bezier(0.22, 1, 0.36, 1) both; }
@keyframes page-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* progress bars fill on load */
.progress > span { transition: width 1.2s cubic-bezier(0.22, 1, 0.36, 1); }

/* complete button pop */
.pop { animation: pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes pop { 50% { transform: scale(1.08); } }

/* stepper: new line slides in, previous result glows briefly */
.stepper__line.is-new { animation: step-in 0.5s cubic-bezier(0.22, 1, 0.36, 1) both; }
@keyframes step-in { from { opacity: 0; transform: translateX(-14px); } to { opacity: 1; transform: none; } }

/* ================= 3D scenes ================= */
.scene { position: relative; height: 380px; touch-action: none; cursor: grab; }
.scene:active { cursor: grabbing; }
.scene canvas { display: block; width: 100% !important; height: 100% !important; }
.scene__status {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-size: 0.85rem; color: var(--ink-faint);
}
.scene__bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
}
.scene__bar .fig-legend { margin-right: auto; color: var(--ink-soft); }
.scene__hint {
  position: absolute; left: 12px; bottom: 10px;
  font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--ink-faint); pointer-events: none;
}
@media (max-width: 560px) { .scene { height: 300px; } }

@media (prefers-reduced-motion: reduce) {
  .flow { display: none; }
  .split .ch { opacity: 1; transform: none; animation: none; }
}

.field__label { display: block; white-space: nowrap; }
.calc__grid { align-items: end; }

/* step-function figures: waveform sweeps in left to right (in time); switch figures loop over 6 s (t = 0..6 s on the plot) */
.sweep { transform-box: view-box; transform-origin: 36px 0; animation: sweep 4s linear infinite; }
@keyframes sweep { 0% { transform: scaleX(0); } 70%, 100% { transform: scaleX(1); } }
.figure.is-paused .sweep { animation: none; }
.sw-arm { transform-box: view-box; transform-origin: 160px 70px; }
.sw-arm--close { animation: sw-close 6s linear infinite; }
.sw-arm--open { animation: sw-open 6s linear infinite; }
@keyframes sw-close { 0%, 49.5% { transform: rotate(-35deg); } 50.5%, 100% { transform: rotate(0deg); } }
@keyframes sw-open { 0%, 49.5% { transform: rotate(0deg); } 50.5%, 100% { transform: rotate(-35deg); } }
.cur-x { animation: cur-x 6s linear infinite; }
@keyframes cur-x { from { transform: translateX(0); } to { transform: translateX(210px); } }
.cur-y--close { animation: cur-up 6s linear infinite; }
.cur-y--open { animation: cur-down 6s linear infinite; }
@keyframes cur-up { 0%, 49.99% { transform: translateY(0); } 50%, 100% { transform: translateY(-90px); } }
@keyframes cur-down { 0%, 49.99% { transform: translateY(0); } 50%, 100% { transform: translateY(90px); } }
.figure.is-paused :is(.sw-arm, .cur-x, .cur-y) { animation-play-state: paused; }
.callout--key { border-left-color: var(--brand); background: color-mix(in srgb, var(--brand) 8%, transparent); }
.callout--key .callout__tag { color: var(--brand); }
.step-plot { display: block; width: 100%; max-width: 460px; margin: 4px 0 8px; }

/* circuit-board traces on the blue header bands (drawn through a mask) */
:root { --circuit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200' fill='none' stroke='%23000' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M0 40H50L70 60H130L150 40H200'/%3E%3Cpath d='M40 200V160L60 140H96M40 0V9'/%3E%3Cpath d='M170 200V124L150 104H124M170 0V17'/%3E%3Cpath d='M0 110H20L40 90H66M200 110H189'/%3E%3Cpath d='M100 60V78M110 150V128M130 150V128M110 174V190M130 174V190'/%3E%3Crect x='102' y='150' width='36' height='24' rx='2'/%3E%3Cg fill='%23000'%3E%3Ccircle cx='100' cy='140' r='3.5'/%3E%3Ccircle cx='40' cy='12' r='3.5'/%3E%3Ccircle cx='120' cy='104' r='3.5'/%3E%3Ccircle cx='170' cy='20' r='3.5'/%3E%3Ccircle cx='70' cy='90' r='3.5'/%3E%3Ccircle cx='185' cy='110' r='3.5'/%3E%3Ccircle cx='100' cy='82' r='3.5'/%3E%3Ccircle cx='110' cy='124' r='3'/%3E%3Ccircle cx='130' cy='124' r='3'/%3E%3C/g%3E%3C/svg%3E"); }
.band .dot-grid-layer {
  background: rgba(243, 239, 230, 0.13);
  -webkit-mask: var(--circuit-mask) 0 0 / 200px 200px repeat; mask: var(--circuit-mask) 0 0 / 200px 200px repeat;
}

/* signal pulses travelling along the header traces */
:root { --circuit-pulse: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200' fill='none' stroke='%23000' stroke-width='3.2' stroke-linecap='round'%3E%3Cstyle%3Epath%7Bstroke-dasharray:9 91%3Banimation:p linear infinite%7D%40keyframes p%7Bfrom%7Bstroke-dashoffset:100%7Dto%7Bstroke-dashoffset:0%7D%7D%40media %28prefers-reduced-motion:reduce%29%7Bpath%7Banimation:none%3Bstroke-dasharray:none%3Bopacity:0%7D%7D%3C/style%3E%3Cpath pathLength='100' style='animation-duration:4.2s%3Banimation-delay:0s' d='M0 40H50L70 60H130L150 40H200'/%3E%3Cpath pathLength='100' style='animation-duration:3.1s%3Banimation-delay:-1.2s' d='M40 200V160L60 140H96'/%3E%3Cpath pathLength='100' style='animation-duration:3.7s%3Banimation-delay:-2.3s' d='M170 200V124L150 104H124'/%3E%3Cpath pathLength='100' style='animation-duration:2.9s%3Banimation-delay:-0.6s' d='M0 110H20L40 90H66'/%3E%3Cpath pathLength='100' style='animation-duration:1.6s%3Banimation-delay:-0.9s' d='M100 60V78'/%3E%3Cpath pathLength='100' style='animation-duration:1.8s%3Banimation-delay:-0.3s' d='M110 150V128'/%3E%3Cpath pathLength='100' style='animation-duration:1.7s%3Banimation-delay:-1.1s' d='M130 174V190'/%3E%3C/svg%3E"); }
.band .dot-grid-layer::after {
  content: ""; position: absolute; inset: 0;
  background: rgba(243, 239, 230, 0.75);
  -webkit-mask: var(--circuit-pulse) 0 0 / 200px 200px repeat; mask: var(--circuit-pulse) 0 0 / 200px 200px repeat;
}
@media (prefers-reduced-motion: reduce) { .band .dot-grid-layer::after { display: none; } }

/* same circuit traces and pulses on the dashboard hero, in the theme's brand colour */
.hero .dot-grid-layer {
  position: absolute; inset: 0;
  background: color-mix(in srgb, var(--brand) 22%, transparent);
  -webkit-mask: var(--circuit-mask) 0 0 / 200px 200px repeat; mask: var(--circuit-mask) 0 0 / 200px 200px repeat;
}
.hero .dot-grid-layer::after {
  content: ""; position: absolute; inset: 0;
  background: color-mix(in srgb, var(--brand) 85%, transparent);
  -webkit-mask: var(--circuit-pulse) 0 0 / 200px 200px repeat; mask: var(--circuit-pulse) 0 0 / 200px 200px repeat;
}
@media (prefers-reduced-motion: reduce) { .hero .dot-grid-layer::after { display: none; } }

/* course page: modules with lecture cards */
.mod + .mod { margin-top: 56px; }
.mod__head { display: flex; align-items: baseline; gap: 14px; margin-bottom: 20px; }
.mod__head::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.mod__title { margin: 0; font-size: clamp(1.15rem, 2.4vw, 1.5rem); }
.lcards { display: grid; gap: 18px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.lcard {
  position: relative; display: flex; flex-direction: column; gap: 8px; min-height: 210px;
  padding: 22px 22px 18px; border: 1px solid var(--line); border-radius: 14px;
  background: var(--panel); color: var(--ink); text-decoration: none; overflow: hidden;
  transition: transform 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}
.lcard::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 3px; background: var(--accent); transform: scaleX(0); transform-origin: left; transition: transform 0.35s ease; }
.lcard:hover { transform: translateY(-4px); border-color: color-mix(in srgb, var(--brand) 55%, var(--line)); box-shadow: 0 14px 30px -18px color-mix(in srgb, var(--brand) 60%, transparent); }
.lcard:hover::before { transform: scaleX(1); }
.lcard__num { font-size: 2.6rem; line-height: 1; color: var(--brand); }
.lcard__title { font-size: 1.3rem; line-height: 1.15; }
.lcard__desc { color: var(--ink-soft); font-size: 0.9rem; }
.lcard__foot { margin-top: auto; padding-top: 14px; display: flex; justify-content: space-between; align-items: center; font-size: 0.78rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-faint); border-top: 1px solid var(--line); }
.lcard__go { display: inline-flex; transition: transform 0.25s ease; color: var(--brand); }
.lcard:hover .lcard__go { transform: translateX(4px); }
.lcard--done .lcard__foot { color: var(--accent-text); }
.lcard__go svg { width: 18px; height: 18px; }

/* ---------- custom form controls (no native look) ---------- */
.field input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
.field input[type="number"]::-webkit-inner-spin-button,
.field input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

.field select {
  -webkit-appearance: none; appearance: none; cursor: pointer;
  padding-right: 38px;
  background: var(--paper) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none' stroke='%238aa0d0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1 1.5l5 5 5-5'/%3E%3C/svg%3E") no-repeat right 14px center;
}
.field select:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 22%, transparent); }
.field select option { background: var(--panel); color: var(--ink); }

.field input[type="range"] {
  -webkit-appearance: none; appearance: none; cursor: pointer;
  height: 44px; padding: 0; border: 0; background: transparent; box-shadow: none;
}
.field input[type="range"]:focus { outline: none; box-shadow: none; }
.field input[type="range"]::-webkit-slider-runnable-track { height: 6px; border-radius: 99px; background: var(--line); }
.field input[type="range"]::-moz-range-track { height: 6px; border-radius: 99px; background: var(--line); }
.field input[type="range"]::-moz-range-progress { height: 6px; border-radius: 99px; background: var(--brand); }
.field input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 20px; height: 20px; margin-top: -7px; border-radius: 50%;
  background: var(--accent); border: 3px solid var(--paper); box-shadow: 0 0 0 1px var(--accent);
  transition: transform 0.15s ease;
}
.field input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); border: 3px solid var(--paper); box-shadow: 0 0 0 1px var(--accent);
}
.field input[type="range"]:hover::-webkit-slider-thumb { transform: scale(1.12); }
.field input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 1px var(--accent), 0 0 0 6px color-mix(in srgb, var(--accent) 30%, transparent); }
.field input[type="range"]:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 1px var(--accent), 0 0 0 6px color-mix(in srgb, var(--accent) 30%, transparent); }

/* scrollbars and focus rings in the site's colours */
html { scrollbar-color: color-mix(in srgb, var(--brand) 55%, transparent) var(--paper); scrollbar-width: thin; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--paper); }
::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--brand) 45%, transparent); border-radius: 99px; border: 2px solid var(--paper); }
::-webkit-scrollbar-thumb:hover { background: color-mix(in srgb, var(--brand) 70%, transparent); }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 3px; }

/* convolution window: blue edge at τ = t slides right; shaded overlap 0 < τ < t grows in step */
.cw-move { animation: cw-move 5s ease-in-out infinite alternate; }
@keyframes cw-move { from { transform: translateX(0); } to { transform: translateX(210px); } }
.cw-fill { transform-box: view-box; transform-origin: 150px 0; animation: cw-fill 5s ease-in-out infinite alternate; }
@keyframes cw-fill { from { transform: scaleX(0.0869565); } to { transform: scaleX(1); } }
.figure.is-paused :is(.cw-move, .cw-fill) { animation-play-state: paused; }

/* segmented toggle (replaces native select) */
.seg { display: flex; padding: 4px; gap: 4px; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); }
.seg [role=radio] { flex: 1; padding: 7px 8px; border: 0; border-radius: 7px; background: transparent; color: var(--ink-soft); cursor: pointer; font: inherit; transition: background-color .2s ease, color .2s ease; white-space: nowrap; }
.seg [role=radio]:hover { color: var(--ink); background: color-mix(in srgb, var(--brand) 12%, transparent); }
.seg [role=radio][aria-checked="true"] { background: var(--brand); color: var(--paper); }
.field--wide { grid-column: span 2; } @media (max-width: 520px) { .field--wide { grid-column: 1 / -1; } }
