/* Inference Engineering course: shared stylesheet.
   Tufte-inspired: one readable column, sidenotes in the margin, quiet rules.
   Every lesson and reference page links this file. */
@import url("https://fonts.googleapis.com/css2?family=Source+Serif+4:ital,opsz,wght@0,8..60,300..700;1,8..60,300..700&family=JetBrains+Mono:wght@400;600&family=Inter:wght@400;500;600&display=swap");

:root {
  --paper: #fffff8;
  --ink: #1d1d1b;
  --muted: #5f5d57;
  --faint: #8a877f;
  --rule: #dedbd0;
  --accent: #9b2915;          /* deep brick: links, markers */
  --accent-soft: #f4e4dc;
  --key-bg: #fbf3dc;  --key-rule: #c9971c;
  --lab-bg: #eef3f7;  --lab-rule: #3d6b8f;
  --ok: #1e7a3c;      --ok-bg: #e6f3ea;
  --bad: #b3261e;     --bad-bg: #fbe9e7;
  --code-bg: #f3f1e8;
  --card: #ffffff;
  --shadow: 0 1px 2px rgba(0,0,0,.05);
  --serif: "Source Serif 4", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --sans: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #161614; --ink: #e9e6df; --muted: #aaa69c; --faint: #7d7a72; --rule: #34332f;
    --accent: #e0835f; --accent-soft: #3a2a22;
    --key-bg: #2b2616; --key-rule: #b8902e; --lab-bg: #1b2530; --lab-rule: #6b9cc2;
    --ok: #6fcf8e; --ok-bg: #19301f; --bad: #f08a80; --bad-bg: #3a1d1a;
    --code-bg: #212120; --card: #1d1d1b; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #161614; --ink: #e9e6df; --muted: #aaa69c; --faint: #7d7a72; --rule: #34332f;
  --accent: #e0835f; --accent-soft: #3a2a22;
  --key-bg: #2b2616; --key-rule: #b8902e; --lab-bg: #1b2530; --lab-rule: #6b9cc2;
  --ok: #6fcf8e; --ok-bg: #19301f; --bad: #f08a80; --bad-bg: #3a1d1a;
  --code-bg: #212120; --card: #1d1d1b; --shadow: none; color-scheme: dark;
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html { font-size: 17px; -webkit-text-size-adjust: 100%; }
@media (min-width: 1100px) { html { font-size: 18px; } }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--serif); font-size: 1rem; line-height: 1.6;
  font-optical-sizing: auto; text-rendering: optimizeLegibility;
}
.page { max-width: 1120px; margin: 0 auto; padding: 1.25rem 16px 6rem; }
article { width: 100%; counter-reset: sn; }
@media (min-width: 1000px) { article { width: 64%; } .fullwidth { width: 156%; } }

a { color: inherit; text-decoration-color: var(--accent); text-decoration-thickness: 1.5px; text-underline-offset: 2px; }
a:hover { color: var(--accent); }
h1, h2, h3, h4 { font-weight: 600; line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: 2.25rem; margin: .4rem 0 .6rem; font-weight: 650; }
h2 { font-size: 1.45rem; margin: 2.6rem 0 .7rem; padding-top: .9rem; border-top: 1px solid var(--rule); }
h3 { font-size: 1.12rem; margin: 1.8rem 0 .4rem; }
p, ul, ol { margin: 0 0 1rem; }
li { margin-bottom: .3rem; }
strong { font-weight: 650; }
hr { border: 0; border-top: 1px solid var(--rule); margin: 2.5rem 0; }
.subtitle { font-size: 1.2rem; font-style: italic; color: var(--muted); margin: 0 0 1.4rem; line-height: 1.45; }
.smallcaps, .eyebrow { font-family: var(--sans); font-size: .7rem; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
.muted { color: var(--muted); }
kbd { font-family: var(--mono); font-size: .78em; padding: .05em .4em; border: 1px solid var(--rule); border-bottom-width: 2px; border-radius: 4px; background: var(--card); }

/* ---------- top nav ---------- */
.topnav {
  display: flex; flex-wrap: wrap; gap: .4rem 1.1rem; align-items: center;
  font-family: var(--sans); font-size: .78rem; color: var(--muted);
  padding-bottom: .9rem; border-bottom: 1px solid var(--rule); margin-bottom: 1.6rem;
}
.topnav a { text-decoration: none; color: var(--muted); }
.topnav a:hover { color: var(--accent); }
.topnav .brand { font-weight: 600; color: var(--ink); margin-right: auto; }
.theme-toggle { background: none; border: 1px solid var(--rule); color: var(--muted); border-radius: 999px; padding: .15rem .6rem; font: inherit; cursor: pointer; }

/* lesson meta strip */
.meta { display: flex; flex-wrap: wrap; gap: .3rem .9rem; font-family: var(--sans); font-size: .78rem; color: var(--muted); margin: 0 0 1.6rem; }
.meta span::before { content: "·"; margin-right: .9rem; color: var(--faint); }
.meta span:first-child::before { content: none; margin: 0; }
.covers { font-family: var(--sans); font-size: .78rem; color: var(--muted); margin: -0.8rem 0 1.6rem; }
.covers .tag { display: inline-block; border: 1px solid var(--rule); border-radius: 999px; padding: .05rem .55rem; margin: .15rem .2rem .15rem 0; background: var(--card); }

/* ---------- sidenotes (Tufte) ---------- */
.sn-ref { counter-increment: sn; }
.sn-ref::after { content: counter(sn); font-family: var(--sans); font-size: .62rem; font-weight: 600; vertical-align: super; color: var(--accent); margin-left: 1px; }
.sidenote, .marginnote {
  display: block; font-size: .8rem; line-height: 1.45; color: var(--muted);
  margin: .5rem 0 .9rem; padding-left: .8rem; border-left: 2px solid var(--rule);
}
.sidenote::before { content: counter(sn) ". "; font-family: var(--sans); font-weight: 600; color: var(--accent); font-size: .7rem; }
@media (min-width: 1000px) {
  .sidenote, .marginnote {
    float: right; clear: right; width: 46%; margin: .25rem -54% .8rem 0;
    padding-left: 0; border-left: 0; position: relative;
  }
}

/* ---------- code ---------- */
code { font-family: var(--mono); font-size: .82em; background: var(--code-bg); padding: .08em .35em; border-radius: 4px; }
pre { position: relative; font-family: var(--mono); font-size: .76rem; line-height: 1.55; background: var(--code-bg); border: 1px solid var(--rule); border-radius: 8px; padding: .9rem 4.2rem .9rem 1rem; margin: 0 0 1.1rem; white-space: pre-wrap; overflow-wrap: anywhere; }
pre.no-copy { padding-right: 1rem; }
pre code { background: none; padding: 0; font-size: inherit; }
pre .c { color: var(--faint); }                 /* comment */
pre .out { color: var(--muted); }               /* sample output */
.copy-btn { position: absolute; top: .45rem; right: .45rem; font-family: var(--sans); font-size: .68rem; border: 1px solid var(--rule); background: var(--card); color: var(--muted); border-radius: 6px; padding: .15rem .5rem; cursor: pointer; opacity: .75; }
.copy-btn:hover { opacity: 1; color: var(--accent); }

/* ---------- tables (booktabs) ---------- */
table { border-collapse: collapse; width: 100%; font-size: .88rem; margin: .4rem 0 1.4rem; font-variant-numeric: tabular-nums; }
thead th { border-top: 2px solid var(--ink); border-bottom: 1px solid var(--ink); }
tbody tr:last-child td { border-bottom: 2px solid var(--ink); }
th, td { text-align: left; padding: .4rem .6rem .4rem 0; vertical-align: top; }
th { font-family: var(--sans); font-size: .72rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
td.num, th.num { text-align: right; }
.table-wrap { overflow-x: auto; }
caption { caption-side: bottom; text-align: left; font-size: .78rem; color: var(--muted); padding-top: .4rem; font-style: italic; }

/* ---------- callouts ---------- */
.key, .lab, .predict, .source, .ask, .mission-link, .warn {
  border-radius: 10px; padding: 1rem 1.2rem; margin: 1.4rem 0; box-shadow: var(--shadow);
}
.key { background: var(--key-bg); border-left: 4px solid var(--key-rule); }
.key > :last-child, .lab > :last-child, .predict > :last-child, .source > :last-child, .ask > :last-child, .mission-link > :last-child, .warn > :last-child { margin-bottom: 0; }
.box-label { display: block; font-family: var(--sans); font-size: .68rem; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; margin-bottom: .45rem; }
.key .box-label { color: var(--key-rule); }
.lab { background: var(--lab-bg); border: 1px solid color-mix(in srgb, var(--lab-rule) 30%, transparent); }
.lab .box-label { color: var(--lab-rule); }
.predict { border: 1.5px dashed var(--accent); background: transparent; box-shadow: none; }
.predict .box-label { color: var(--accent); }
.source { border: 1px solid var(--rule); background: var(--card); }
.source .box-label { color: var(--muted); }
.ask { background: var(--accent-soft); }
.ask .box-label { color: var(--accent); }
.mission-link { border: 1px solid var(--rule); background: transparent; box-shadow: none; font-style: italic; color: var(--muted); }
.warn { background: var(--bad-bg); }
.warn .box-label { color: var(--bad); }

/* formula display */
.formula { font-family: var(--mono); font-size: .9rem; background: var(--card); border: 1px solid var(--rule); border-radius: 8px; padding: .7rem 1rem; margin: .8rem 0 1.2rem; overflow-x: auto; white-space: nowrap; }

/* ---------- figures ---------- */
figure { margin: 1.4rem 0; }
/* inline-SVG diagram palette: follows the theme */
svg text { font-family: var(--sans); fill: var(--ink); }
svg .t-muted { fill: var(--muted); } svg .t-accent { fill: var(--accent); } svg .t-lab { fill: var(--lab-rule); }
svg .f-ink { fill: var(--ink); } svg .f-accent { fill: var(--accent); } svg .f-lab { fill: var(--lab-rule); }
svg .f-key { fill: var(--key-bg); } svg .f-labbg { fill: var(--lab-bg); } svg .f-card { fill: var(--card); } svg .f-soft { fill: var(--accent-soft); }
svg .s-ink { stroke: var(--ink); fill: none; } svg .s-muted { stroke: var(--faint); fill: none; } svg .s-accent { stroke: var(--accent); fill: none; }
svg .s-lab { stroke: var(--lab-rule); fill: none; } svg .s-rule { stroke: var(--rule); }
.prediction { border: 1.5px dashed var(--accent); border-radius: 12px; padding: 1rem 1.2rem; margin: 1rem 0; }
.prediction .prompt { margin-bottom: .2rem; }
figure svg { width: 100%; height: auto; display: block; }
figcaption { font-size: .8rem; color: var(--muted); font-style: italic; margin-top: .4rem; line-height: 1.45; }

/* ---------- exercises (components.js) ---------- */
.exercise-set { counter-reset: ex; }
.mcq, .numeric, .explain {
  counter-increment: ex; background: var(--card); border: 1px solid var(--rule); border-radius: 12px;
  padding: 1rem 1.2rem 1.1rem; margin: 1.1rem 0; box-shadow: var(--shadow);
}
.mcq > .prompt::before, .numeric > .prompt::before, .explain > .prompt::before {
  content: counter(ex); display: inline-grid; place-items: center; width: 1.45rem; height: 1.45rem; margin-right: .5rem;
  border-radius: 50%; background: var(--ink); color: var(--paper); font-family: var(--sans); font-size: .72rem; font-weight: 600; vertical-align: .1rem;
}
.prompt { margin-bottom: .75rem; }
.mcq ul { list-style: none; padding: 0; margin: 0; display: grid; gap: .45rem; }
.mcq li { margin: 0; }
.opt {
  width: 100%; text-align: left; font: inherit; font-size: .95rem; line-height: 1.4; color: var(--ink);
  background: var(--paper); border: 1px solid var(--rule); border-radius: 8px; padding: .55rem .8rem; cursor: pointer;
  transition: border-color .12s, background .12s;
}
.opt:hover:not(:disabled) { border-color: var(--accent); }
.opt:disabled { cursor: default; }
.opt.correct { border-color: var(--ok); background: var(--ok-bg); }
.opt.wrong { border-color: var(--bad); background: var(--bad-bg); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--bad) 60%, transparent); }
.feedback { font-family: var(--sans); font-size: .82rem; margin-top: .6rem; min-height: 1.1rem; }
.feedback.ok { color: var(--ok); } .feedback.bad { color: var(--bad); }
.explanation, .model-answer, .solution { display: none; margin-top: .8rem; padding-top: .8rem; border-top: 1px dashed var(--rule); font-size: .92rem; }
.revealed > .explanation, .revealed > .model-answer, .revealed > .solution { display: block; }
.btn {
  font-family: var(--sans); font-size: .8rem; font-weight: 500; border-radius: 8px; padding: .42rem .9rem; cursor: pointer;
  border: 1px solid var(--ink); background: var(--ink); color: var(--paper);
}
.btn.secondary { background: transparent; color: var(--ink); border-color: var(--rule); }
.btn:hover { opacity: .88; }
.btn-row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: .6rem; }
.numeric input, .lab-results input {
  font-family: var(--mono); font-size: .9rem; width: 9.5rem; padding: .4rem .6rem; border-radius: 8px;
  border: 1px solid var(--rule); background: var(--paper); color: var(--ink);
}
.unit { font-family: var(--sans); font-size: .82rem; color: var(--muted); }
.explain textarea {
  width: 100%; min-height: 5.5rem; font: inherit; font-size: .95rem; padding: .6rem .75rem; border-radius: 8px;
  border: 1px solid var(--rule); background: var(--paper); color: var(--ink); resize: vertical;
}
.self-grade { display: none; gap: .4rem; flex-wrap: wrap; margin-top: .7rem; font-family: var(--sans); font-size: .8rem; color: var(--muted); align-items: center; }
.revealed > .self-grade { display: flex; }
.self-grade button { font: inherit; border: 1px solid var(--rule); background: var(--paper); color: var(--ink); border-radius: 999px; padding: .2rem .7rem; cursor: pointer; }
.self-grade button.picked { border-color: var(--accent); background: var(--accent-soft); }

/* lab checklist */
.checklist { list-style: none; padding-left: 0; counter-reset: step; }
.checklist > li { counter-increment: step; position: relative; padding: .55rem 0 .55rem 2.6rem; border-bottom: 1px solid color-mix(in srgb, var(--lab-rule) 18%, transparent); margin: 0; }
.checklist > li:last-child { border-bottom: 0; }
.checklist > li > input[type=checkbox] { position: absolute; left: .2rem; top: .78rem; width: 1.1rem; height: 1.1rem; accent-color: var(--lab-rule); cursor: pointer; }
.checklist > li::before { content: counter(step); position: absolute; left: 1.65rem; top: .62rem; font-family: var(--sans); font-size: .68rem; font-weight: 600; color: var(--lab-rule); }
.checklist > li.done > *:not(input):not(pre) { opacity: .6; }
.checklist pre { margin-top: .5rem; }

/* lab results checker */
.lab-results { background: var(--card); border: 1px solid var(--rule); border-radius: 12px; padding: 1rem 1.2rem; margin: 1.2rem 0; }
.lab-results .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: .7rem 1.2rem; margin-bottom: .6rem; }
.lab-results label { display: grid; gap: .25rem; font-family: var(--sans); font-size: .78rem; color: var(--muted); }
.check-list { list-style: none; padding: 0; margin: .8rem 0 0; font-size: .92rem; }
.check-list li { padding: .45rem .7rem; border-radius: 8px; margin-bottom: .4rem; }
.check-list li.ok { background: var(--ok-bg); } .check-list li.bad { background: var(--bad-bg); } .check-list li.info { background: var(--lab-bg); }

/* charts (charts.js): latency/throughput plots and the CSV paste box */
.chart-grid { display: grid; gap: 1rem; margin: .8rem 0; }
.chart-panel { background: var(--card); border: 1px solid var(--rule); border-radius: 10px; padding: .6rem .7rem .3rem; }
.chart-panel svg { width: 100%; height: auto; display: block; }
.csv-plot { background: var(--card); border: 1px solid var(--rule); border-radius: 12px; padding: 1rem 1.2rem; margin: 1.2rem 0; }
.csv-plot .chart-panel { background: var(--paper); }
.csv-input {
  width: 100%; min-height: 8rem; font-family: var(--mono); font-size: .74rem; line-height: 1.5; padding: .6rem .75rem;
  border-radius: 8px; border: 1px solid var(--rule); background: var(--paper); color: var(--ink); resize: vertical;
}

/* learner notes (components.js initNotes) */
.my-notes { border: 1px solid var(--rule); border-left: 4px solid var(--lab-rule); border-radius: 10px; padding: 1rem 1.2rem; margin: 2rem 0 1.4rem; background: var(--card); }
.my-notes .box-label { color: var(--lab-rule); }
.my-notes .notes-body { font-size: .95rem; }
.my-notes .notes-body h3, .my-notes .notes-body h4, .my-notes .notes-body h5 { margin: 1rem 0 .3rem; font-size: 1rem; }
.my-notes .notes-body > :first-child { margin-top: 0; }
.my-notes .btn-row a.btn { text-decoration: none; }
.my-notes .notes-meta { font-family: var(--sans); font-size: .78rem; color: var(--muted); margin-left: auto; }

/* scoreboard + completion */
.scoreboard { font-family: var(--sans); font-size: .82rem; color: var(--muted); border: 1px solid var(--rule); border-radius: 10px; padding: .7rem 1rem; margin: 1.6rem 0; display: flex; flex-wrap: wrap; gap: .4rem 1.5rem; align-items: center; }
.scoreboard strong { color: var(--ink); }
.complete-btn.done { background: var(--ok); border-color: var(--ok); }

/* prev / next */
.pager { display: flex; justify-content: space-between; gap: 1rem; margin-top: 3rem; padding-top: 1rem; border-top: 1px solid var(--rule); font-family: var(--sans); font-size: .85rem; }
.pager a { text-decoration: none; color: var(--muted); }
.pager a:hover { color: var(--accent); }
.pager .disabled { color: var(--faint); }

/* details */
details { border: 1px solid var(--rule); border-radius: 10px; padding: .6rem 1rem; margin: 1rem 0; background: var(--card); }
details > summary { cursor: pointer; font-family: var(--sans); font-size: .85rem; font-weight: 500; color: var(--muted); }
details[open] > summary { margin-bottom: .6rem; }

/* ---------- reference-page helpers ---------- */
.ref-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: 1rem; margin: 1rem 0 1.5rem; }
.ref-card { border: 1px solid var(--rule); border-radius: 10px; padding: .9rem 1rem; background: var(--card); break-inside: avoid; }
.ref-card h3 { margin: 0 0 .35rem; font-size: 1rem; }
.ref-card p { font-size: .88rem; margin-bottom: .5rem; }
.pill { display: inline-block; font-family: var(--sans); font-size: .66rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; border-radius: 999px; padding: .08rem .5rem; border: 1px solid var(--rule); color: var(--muted); }
.pill.core { border-color: var(--accent); color: var(--accent); }
.pill.light { color: var(--faint); }
.pill.mac { border-color: var(--lab-rule); color: var(--lab-rule); }
.pill.gpu { border-color: var(--key-rule); color: var(--key-rule); }

/* ---------- print ---------- */
@media print {
  :root { --paper: #fff; --ink: #000; --card: #fff; --shadow: none; }
  html { font-size: 11pt; }
  .page { max-width: none; padding: 0; }
  article { width: 100% !important; }
  .topnav, .copy-btn, .theme-toggle, .btn, .btn-row, .self-grade, .pager, .scoreboard, .no-print { display: none !important; }
  .explanation, .model-answer, .solution { display: block !important; }
  .sidenote, .marginnote { float: none; width: auto; margin: .3rem 0 .6rem; border-left: 2px solid #ccc; padding-left: .6rem; }
  a { text-decoration: none; }
  h2 { break-after: avoid; } pre, .mcq, .numeric, .explain, .key, .lab, table, .ref-card { break-inside: avoid; }
}
