/* Shared design system for the homework site.
   Light/dark tokens follow the OS setting; the toggle stamps data-theme on <html>. */

:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f2f1ed;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --border-strong: rgba(11, 11, 11, 0.18);

  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --accent-wash: rgba(42, 120, 214, 0.1);

  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;

  --good: #0ca30c;
  --good-ink: #006300;
  --warning: #fab219;
  --critical: #d03b3b;
  --critical-ink: #b02a2a;

  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.04);
  --wide: 1120px;
  --prose: 760px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --border-strong: rgba(255, 255, 255, 0.18);
    --accent: #3987e5;
    --accent-ink: #86b6ef;
    --accent-wash: rgba(57, 135, 229, 0.16);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
    --good-ink: #0ca30c;
    --critical-ink: #e66767;
    --shadow: none;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.18);
  --accent: #3987e5;
  --accent-ink: #86b6ef;
  --accent-wash: rgba(57, 135, 229, 0.16);
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
  --good-ink: #0ca30c;
  --critical-ink: #e66767;
  --shadow: none;
}

/* ---------- base ---------- */

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

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: 72px; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 16px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-ink); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

h1, h2, h3, h4 { line-height: 1.2; margin: 0 0 0.5em; letter-spacing: -0.01em; }
h1 { font-size: clamp(2rem, 4.5vw, 3rem); letter-spacing: -0.025em; }
h2 { font-size: clamp(1.45rem, 2.6vw, 1.9rem); margin-top: 0; }
h3 { font-size: 1.15rem; }
h4 { font-size: 1rem; }
p { margin: 0 0 1em; }
ul, ol { padding-left: 1.3em; margin: 0 0 1em; }
li + li { margin-top: 0.25em; }
strong { font-weight: 650; }
hr { border: 0; border-top: 1px solid var(--border); margin: 2rem 0; }

code, kbd, pre, .mono { font-family: var(--mono); font-size: 0.9em; }
:not(pre) > code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.05em 0.35em;
  overflow-wrap: anywhere;
}
pre {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  overflow-x: auto;
  line-height: 1.5;
  margin: 0 0 1em;
}

var { font-style: italic; font-family: Georgia, "Times New Roman", serif; }
.math { font-family: Georgia, "Times New Roman", serif; font-size: 1.05em; white-space: nowrap; }
@media (max-width: 480px) { .math { white-space: normal; } }  /* long formulas would push the page sideways on phones */
.math-block {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.08em;
  text-align: center;
  padding: 0.8em 1em;
  margin: 0 0 1em;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  overflow-x: auto;
}

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

.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;
}

/* ---------- layout ---------- */

.wrap { width: min(var(--wide), 100% - 32px); margin-inline: auto; }
.prose { max-width: var(--prose); }
.prose p, .prose li { color: var(--ink); }

.site-header {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--page) 85%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.site-header .wrap { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 16px; height: 56px; }
.site-header .brand { justify-self: start; }
.header-title { grid-column: 2; display: flex; align-items: center; gap: 6px; font-weight: 600; color: var(--ink); white-space: nowrap; }
.hw-arrow { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; color: var(--ink-2); }
a.hw-arrow:hover { background: var(--surface-2); color: var(--ink); }
.hw-arrow svg { width: 16px; height: 16px; }
.header-author { color: var(--ink-2); font-size: 0.9rem; white-space: nowrap; margin-right: 4px; }
@media (max-width: 900px) { .header-author { display: none; } }   /* still in the footer */
@media (max-width: 420px) { .header-title { display: none; } }
.brand { font-weight: 650; color: var(--ink); text-decoration: none; white-space: nowrap; }
.nav { grid-column: 3; justify-self: end; display: flex; gap: 8px; align-items: center; }
.nav a {
  color: var(--ink-2); text-decoration: none; padding: 6px 10px; border-radius: 8px; font-size: 0.93rem;
}
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a[aria-current="page"] { color: var(--ink); background: var(--surface-2); }
.theme-toggle, .nav a.icon-btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--ink-2);
  width: 34px; height: 34px; padding: 0; border-radius: 9px; cursor: pointer; display: grid; place-items: center;
}
.theme-toggle:hover, .nav a.icon-btn:hover { color: var(--ink); border-color: var(--border-strong); background: var(--surface); }
.theme-toggle svg, .icon-btn svg { width: 17px; height: 17px; }


.hero { padding: clamp(40px, 8vw, 88px) 0 clamp(28px, 5vw, 48px); }
.kicker {
  display: inline-flex; align-items: center; gap: 8px;
  font: 600 0.78rem/1 var(--mono); letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--accent-ink); margin-bottom: 16px;
}
.lede { font-size: clamp(1.05rem, 1.8vw, 1.22rem); color: var(--ink-2); max-width: 720px; }
.hero .meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px; }

section.block { padding: clamp(32px, 6vw, 56px) 0; border-top: 1px solid var(--border); }
.section-head { display: flex; align-items: baseline; gap: 14px; margin-bottom: 18px; }
.section-num { font: 600 0.85rem/1 var(--mono); color: var(--muted); min-width: 2.2em; }
.section-head h2 { margin: 0; }
.section-sub { color: var(--ink-2); margin-top: -6px; max-width: var(--prose); }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.split { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 860px) {
  .grid-2, .grid-3, .split { grid-template-columns: minmax(0, 1fr); }
}


.site-footer { border-top: 1px solid var(--border); padding: 32px 0 48px; color: var(--ink-2); font-size: 0.9rem; }
.site-footer .wrap { display: flex; flex-wrap: wrap; gap: 8px 24px; justify-content: space-between; }

/* ---------- components ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.card > :last-child { margin-bottom: 0; }
.card h3 { margin-bottom: 0.4em; }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-title h3 { margin: 0; }
.card.inset { background: var(--surface-2); box-shadow: none; }

a.card-link { display: block; color: inherit; text-decoration: none; transition: border-color .15s, transform .15s; }
a.card-link:hover { border-color: var(--border-strong); transform: translateY(-2px); }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface);
  font-size: 0.8rem; color: var(--ink-2); white-space: nowrap;
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--accent)); flex: none; }
.chip.mono { font-family: var(--mono); }

.callout {
  display: grid; grid-template-columns: 22px 1fr; gap: 10px;
  border: 1px solid var(--border); border-left: 3px solid var(--accent);
  background: var(--surface); border-radius: var(--radius-sm);
  padding: 12px 14px; margin: 0 0 1em; font-size: 0.95rem;
}
.callout > svg { width: 20px; height: 20px; color: var(--accent); margin-top: 2px; }
.callout p:last-child { margin-bottom: 0; }
.callout.warn { border-left-color: var(--critical); }
.callout.warn > svg { color: var(--critical); }
.callout.insight { border-left-color: var(--series-3); }
.callout.insight > svg { color: var(--series-3); }

/* forms */
.controls { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: flex-end; margin-bottom: 16px; }
.field { display: grid; gap: 4px; min-width: 0; }
.field > span, .field-label { font-size: 0.78rem; font-weight: 600; color: var(--ink-2); letter-spacing: 0.01em; }
input[type="text"], input[type="number"], input[type="search"], select, textarea {
  font: inherit; font-size: 0.95rem; color: var(--ink);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px;
  padding: 7px 10px; min-height: 36px; max-width: 100%;
}
input.mono, textarea.mono { font-family: var(--mono); font-size: 0.88rem; }
input[type="range"] { accent-color: var(--accent); width: 140px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-wash); border-color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: 600 0.9rem/1 var(--sans); padding: 0 14px; height: 36px; border-radius: 8px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--ink); cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

.segmented { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 9px; padding: 2px; background: var(--surface); }
.segmented button {
  font: 600 0.85rem/1 var(--sans); border: 0; background: transparent; color: var(--ink-2);
  padding: 0 12px; height: 30px; border-radius: 7px; cursor: pointer;
}
.segmented button[aria-pressed="true"] { background: var(--ink); color: var(--page); }

/* console-like printed output */
.console {
  font: 0.86rem/1.65 var(--mono);
  background: #111110; color: #e9e8e2;
  border-radius: var(--radius-sm); padding: 14px 16px; margin: 0;
  overflow: auto; max-height: 420px; white-space: pre;
  border: 1px solid var(--border);
}
.console.console-wrap { white-space: pre-wrap; max-height: none; }   /* step-by-step output: wrap long lines, show everything */
.console .c-dim { color: #8f8e87; }
.console .c-hi { color: #86b6ef; }
.console .c-ok { color: #57c96b; font-weight: 700; }
.console .c-warn { color: #f0a868; }

/* key output */
.keyout {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px;
  border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px;
  background: var(--surface); box-shadow: var(--shadow);
}
.keyout .label { font: 600 0.75rem/1 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-2); width: 100%; }
.keyout .value { font: 650 clamp(1.6rem, 4vw, 2.4rem)/1.1 var(--mono); letter-spacing: -0.02em; }
.keyout .sub { color: var(--ink-2); font-size: 0.92rem; }

/* tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 0.78rem; font-weight: 650; color: var(--ink-2); background: var(--surface-2); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.mono { font-family: var(--mono); font-size: 0.85rem; }
.yes { color: var(--good-ink); font-weight: 650; }
.no { color: var(--critical-ink); font-weight: 650; }
.partial { color: var(--ink-2); font-weight: 650; }

/* stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.tile { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; background: var(--surface); min-width: 0; }
.tile .t-label { font-size: 0.78rem; color: var(--ink-2); }
.tile .t-value { font-size: 1.35rem; font-weight: 650; margin-top: 2px; overflow-wrap: anywhere; }
.tile .t-sub { font-size: 0.78rem; color: var(--muted); margin-top: 2px; }

/* charts */
.chart { position: relative; width: 100%; min-width: 0; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { font-family: var(--sans); fill: var(--muted); font-size: 11px; }
.chart .axis-title { fill: var(--ink-2); font-size: 11.5px; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .bar { transition: opacity .1s; }
.chart .bar.dim { opacity: 0.45; }
.chart-title { font-size: 0.9rem; font-weight: 650; margin: 0 0 2px; }
.chart-sub { font-size: 0.8rem; color: var(--ink-2); margin: 0 0 8px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 0.8rem; color: var(--ink-2); margin: 4px 0 6px; }
.legend .key { display: inline-flex; align-items: center; gap: 6px; }
.legend .swatch { width: 10px; height: 10px; border-radius: 3px; background: var(--c); }
.legend .linekey { width: 16px; height: 2px; border-radius: 2px; background: var(--c); }
.tooltip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px;
  padding: 6px 9px; font-size: 0.8rem; box-shadow: 0 6px 20px rgba(0,0,0,.12);
  white-space: nowrap; opacity: 0; transition: opacity .08s; color: var(--ink-2);
}
.tooltip strong { color: var(--ink); font-weight: 650; display: block; font-variant-numeric: tabular-nums; }
.tooltip.show { opacity: 1; }
details.data-table { margin-top: 6px; font-size: 0.82rem; }
details.data-table summary { cursor: pointer; color: var(--ink-2); }
details.data-table .table-wrap { margin-top: 6px; max-height: 260px; overflow: auto; }

/* status badges */
.badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: 0.8rem; font-weight: 600;
  padding: 3px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
}
.badge svg { width: 14px; height: 14px; }
.badge.ok { color: var(--good-ink); }
.badge.ok svg { color: var(--good); }
.badge.fail { color: var(--critical-ink); }
.badge.fail svg { color: var(--critical); }
.badge.pending { color: var(--ink-2); }

.muted { color: var(--ink-2); }
.small { font-size: 0.85rem; }
.nowrap { white-space: nowrap; }
.break { overflow-wrap: anywhere; word-break: break-all; }
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; }
.mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.stack > * + * { margin-top: 16px; }

/* ---------- section rail, Notion-style (built by layout.js from main > section[id] h2) ---------- */

.rail { display: none; }
@media (min-width: 720px) {
  /* every page leaves room for the rail and the assignment tab, set in CSS so the first paint is already right */
  .wrap { width: min(var(--wide), 100% - 200px); }
  .rail {
    display: block; position: fixed; left: 14px; top: 50%; z-index: 25; transform: translateY(-50%);
    padding: 8px; border: 1px solid transparent; border-radius: var(--radius-sm);
    transition: background .15s, border-color .15s, box-shadow .15s;
  }
  .rail ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
  .rail a {
    display: flex; align-items: center; gap: 10px; min-height: 14px; padding: 2px 4px; border-radius: 6px;
    color: var(--muted); text-decoration: none; font-size: 0.86rem; line-height: 1.3;
  }
  /* width and opacity are set per frame by layout.js: a bump centred on the scroll position */
  .rail-dash { flex: none; width: 8px; height: 2px; border-radius: 2px; background: var(--ink); opacity: .2; transition: width .12s linear, opacity .12s linear; }
  .rail ol { justify-items: start; }
  .rail-label { display: none; white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
  .rail:hover, .rail:focus-within { background: var(--surface); border-color: var(--border); box-shadow: var(--shadow); }
  .rail:hover .rail-label, .rail:focus-within .rail-label { display: block; }
  .rail:hover a, .rail:focus-within a { padding: 4px 8px 4px 4px; }
  .rail a:hover { background: var(--surface-2); color: var(--ink); }
  .rail a.active { color: var(--ink); font-weight: 600; }
}

/* ---------- assignment drawer (built by layout.js from <template id="assignment">) ---------- */

.drawer-tab {
  position: fixed; right: 0; top: 50%; z-index: 30;
  transform: translateY(-50%);
  writing-mode: vertical-rl;
  padding: 14px 7px; border: 1px solid var(--border-strong); border-right: 0;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  background: var(--surface); color: var(--ink-2); box-shadow: var(--shadow);
  font: 600 0.78rem/1 var(--sans); letter-spacing: 0.08em; text-transform: uppercase;
  cursor: pointer; transition: padding .15s, color .15s;
}
.drawer-tab:hover, .drawer-tab:focus-visible { color: var(--ink); padding-right: 11px; }
.drawer-backdrop {
  position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, 0.28);
  opacity: 0; pointer-events: none; transition: opacity .25s;
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 50;
  width: min(560px, 100vw); display: flex; flex-direction: column;
  background: var(--surface); border-left: 1px solid var(--border-strong);
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.12);
  transform: translateX(100%); visibility: hidden;
  transition: transform .3s cubic-bezier(.2, .8, .2, 1), visibility 0s linear .3s;
}
.drawer-open .drawer { transform: none; visibility: visible; transition: transform .3s cubic-bezier(.2, .8, .2, 1); }
.drawer-open .drawer-backdrop { opacity: 1; pointer-events: auto; }
.drawer-open { overflow: hidden; }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 16px 0 24px; height: 56px; border-bottom: 1px solid var(--border); flex: none;
}
.drawer-head h2 { font-size: 0.82rem; margin: 0; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-2); }
.drawer-close {
  width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface);
  color: var(--ink-2); cursor: pointer; font-size: 1.2rem; line-height: 1;
}
.drawer-close:hover { color: var(--ink); border-color: var(--border-strong); }
.drawer-body { padding: 24px; overflow-y: auto; font-size: 0.95rem; line-height: 1.6; }
.drawer-body h3 { font-size: 1.1rem; margin: 0 0 16px; line-height: 1.35; }
.drawer-body h4 { font-size: 0.78rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin: 24px 0 8px; }
.drawer-body p { margin: 0 0 12px; color: var(--ink-2); }
.drawer-body ul { margin: 0 0 12px; padding-left: 20px; color: var(--ink-2); }
.drawer-body li { margin: 2px 0; }
.drawer-body pre { font: 0.85rem/1.5 var(--mono); background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px 14px; margin: 0 0 12px; overflow-x: auto; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
