/* Shared theme for the whole site: colour tokens (light and dark), base typography, top bar, buttons, focus.
   Every class folder links this file first and adds its own stylesheet after it.
   Dark mode: follows the visitor's system setting, and the toggle in the top bar overrides it (see theme.js).
   The two dark blocks below must stay identical: one is used when JavaScript chooses the theme (data-theme="dark"),
   the other when JavaScript is off and only the system setting is available. */

:root {
  color-scheme: light;
  --ink: #1d2433;
  --muted: #4f576b;
  --line: #d9dde6;          /* decorative dividers */
  --ctl-border: #6b7488;    /* borders of inputs and controls (needs 3:1) */
  --paper: #ffffff;
  --wash: #f5f7fb;
  --link: #1f4e9c;          /* link and accent text */
  --accent: #1f4e9c;        /* filled buttons */
  --on-accent: #ffffff;
  --accent-hover: #173d7b;
  --accent-2: #e7eefb;      /* hover and selected backgrounds */
  --bar-bg: #1f4e9c;
  --bar-ink: #ffffff;
  --good: #17693a;
  --good-bg: #e6f5ec;
  --good-line: #6dac85;
  --bad: #b3261e;
  --bad-bg: #fdeceb;
  --bad-line: #d98780;
  --warn: #7a4e00;
  --warn-bg: #fff4dc;
  --code-bg: #eef0f5;
  --key-bg: #fbfcfe;
  --sol-bg: #fffdf3;
  --sol-line: #b9a24a;
  --focus: #1a47a3;
  --shadow: rgba(20, 30, 60, .08);
  --svg-ink: #1d2433;
  --svg-grid: #b9c1d3;
  --svg-line: #1f5bc4;
  --svg-red: #b32d20;
  --svg-label: #8a1f17;
  --svg-shade: #3f74cf;
  --svg-gb-fill: #eaf0fb;
  --svg-gb-line: #8fa6d2;
  --svg-peg: #5e6679;
  --svg-band: #b35900;
  --fig-filter: none;
  --radius: 10px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #e6e9f0;
  --muted: #aab3c5;
  --line: #2e3647;
  --ctl-border: #8c96ab;
  --paper: #12151c;
  --wash: #1a1f2a;
  --link: #8db4ff;
  --accent: #2f66c4;
  --on-accent: #ffffff;
  --accent-hover: #3a73d6;
  --accent-2: #222d47;
  --bar-bg: #1b2a4a;
  --bar-ink: #ffffff;
  --good: #6fd39a;
  --good-bg: #14301f;
  --good-line: #3d8a5c;
  --bad: #ff9a90;
  --bad-bg: #3a1a1a;
  --bad-line: #a8504a;
  --warn: #f2c35f;
  --warn-bg: #33280f;
  --code-bg: #252c3a;
  --key-bg: #171c27;
  --sol-bg: #211e12;
  --sol-line: #8a7a35;
  --focus: #8db4ff;
  --shadow: rgba(0, 0, 0, .4);
  --svg-ink: #e6e9f0;
  --svg-grid: #3a4258;
  --svg-line: #7fa8ff;
  --svg-red: #ff8f84;
  --svg-label: #ffaaa1;
  --svg-shade: #7fa8ff;
  --svg-gb-fill: #1c2436;
  --svg-gb-line: #4a5f8a;
  --svg-peg: #9aa3b8;
  --svg-band: #ffa94d;
  --fig-filter: invert(1) hue-rotate(180deg);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --ink: #e6e9f0;
    --muted: #aab3c5;
    --line: #2e3647;
    --ctl-border: #8c96ab;
    --paper: #12151c;
    --wash: #1a1f2a;
    --link: #8db4ff;
    --accent: #2f66c4;
    --on-accent: #ffffff;
    --accent-hover: #3a73d6;
    --accent-2: #222d47;
    --bar-bg: #1b2a4a;
    --bar-ink: #ffffff;
    --good: #6fd39a;
    --good-bg: #14301f;
    --good-line: #3d8a5c;
    --bad: #ff9a90;
    --bad-bg: #3a1a1a;
    --bad-line: #a8504a;
    --warn: #f2c35f;
    --warn-bg: #33280f;
    --code-bg: #252c3a;
    --key-bg: #171c27;
    --sol-bg: #211e12;
    --sol-line: #8a7a35;
    --focus: #8db4ff;
    --shadow: rgba(0, 0, 0, .4);
    --svg-ink: #e6e9f0;
    --svg-grid: #3a4258;
    --svg-line: #7fa8ff;
    --svg-red: #ff8f84;
    --svg-label: #ffaaa1;
    --svg-shade: #7fa8ff;
    --svg-gb-fill: #1c2436;
    --svg-gb-line: #4a5f8a;
    --svg-peg: #9aa3b8;
    --svg-band: #ffa94d;
    --fig-filter: invert(1) hue-rotate(180deg);
  }
}

/* ------------------------------------------------------------------ base */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 76px; -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 17px/1.6 "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif; color: var(--ink); background: var(--paper); }
a { color: var(--link); }
a:hover { text-decoration-thickness: 2px; }
h1, h2, h3 { overflow-wrap: anywhere; }
kbd { background: var(--code-bg); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; font-size: .85em; }
code { background: var(--code-bg); border-radius: 4px; padding: 0 4px; font-size: .92em; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* keyboard focus: always visible, never hidden under the sticky bar (scroll-padding above) */
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.topbar :focus-visible { outline-color: #ffffff; }

.skip { position: absolute; left: 8px; top: -60px; z-index: 100; background: var(--paper); color: var(--link); padding: 10px 16px; border-radius: 0 0 8px 8px; border: 2px solid var(--focus); font-weight: 600; }
.skip:focus { top: 0; }

/* ------------------------------------------------------------------ top bar */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 14px; min-height: 54px; padding: 0 18px; background: var(--bar-bg); color: var(--bar-ink); box-shadow: 0 1px 4px rgba(0,0,0,.25); }
.topbar a { color: var(--bar-ink); }
.topbar .brand { text-decoration: none; font-weight: 700; letter-spacing: .02em; }
.topbar .brand span { font-weight: 400; }
.topbar .top-link { font-size: .92rem; padding: 6px 4px; }
.topbar .spacer { margin-left: auto; }
/* Site-wide navigation (home page, Teaching, Research, ...): in the bar on wide screens, on its own row on narrow ones.
   Not sticky, so the extra row can never cover the thing that has keyboard focus. */
.topbar.site { position: relative; flex-wrap: wrap; row-gap: 0; }
.sitenav { margin-left: 14px; }
.sitenav ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0 4px; }
.sitenav a { display: inline-block; padding: 14px 10px 11px; border-bottom: 3px solid transparent; text-decoration: none; font-size: .95rem; }
.sitenav a:hover { background: rgba(255,255,255,.16); }
.sitenav a[aria-current] { font-weight: 700; border-bottom-color: currentColor; }
@media (max-width: 760px) {
  .topbar.site { padding-bottom: 0; }
  .topbar.site .brand { padding: 14px 0; }
  .sitenav { order: 3; flex: 1 0 100%; margin: 0 -8px; }
  .sitenav a { padding: 10px 10px 8px; }
}
.theme-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-width: 38px; height: 38px; padding: 0 10px; background: transparent; color: var(--bar-ink); border: 1px solid rgba(255,255,255,.7); border-radius: 8px; font: inherit; font-size: .9rem; cursor: pointer; }
.theme-btn:hover { background: rgba(255,255,255,.16); }
.theme-btn[hidden] { display: none; }
.theme-btn svg { width: 18px; height: 18px; flex: none; fill: currentColor; }
.theme-btn .switch { position: relative; width: 36px; height: 20px; flex: none; border: 2px solid currentColor; border-radius: 999px; box-sizing: border-box; }
.theme-btn .switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: 50%; background: currentColor; transition: transform .15s; }
.theme-btn[aria-checked="true"] .switch { background: currentColor; }
.theme-btn[aria-checked="true"] .switch::after { background: var(--bar-bg); transform: translateX(16px); }

/* ------------------------------------------------------------------ buttons */
.btn { font: inherit; font-size: .95rem; min-height: 38px; padding: 7px 14px; border-radius: 8px; border: 1.5px solid var(--link); background: var(--paper); color: var(--link); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.btn:hover { background: var(--accent-2); }
.btn.small { font-size: .88rem; min-height: 32px; padding: 3px 11px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { border-color: var(--ctl-border); color: var(--muted); }

@media (max-width: 600px) {
  .topbar { gap: 10px; padding: 0 12px; }
  .topbar .brand span { display: none; }
  .theme-btn .label { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }   /* icon only, still named for screen readers */
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
@media (forced-colors: active) {
  .btn, .theme-btn, input.answer { border: 2px solid ButtonText; }
  .btn.primary { background: ButtonFace; color: ButtonText; }
  .theme-btn .switch, .theme-btn .switch::after { forced-color-adjust: none; }
  .theme-btn .switch::after { background: ButtonText; }
  .theme-btn[aria-checked="true"] .switch { background: ButtonText; }
  .theme-btn[aria-checked="true"] .switch::after { background: ButtonFace; }
}
@media print { .topbar, .skip { display: none !important; } body { background: #fff; color: #000; } }
