/* Shared stylesheet for every lesson and reference page in this course.
   Tufte-inspired: a narrow reading column, margin notes for citations, quiet colour. */

:root {
  --bg: #fffff8;
  --fg: #1d1d1b;
  --muted: #6b6a63;
  --rule: #dcd9cc;
  --panel: #f5f3e8;
  --accent: #a3412b;       /* rust: headings, links */
  --branch: #2f6f9f;       /* blue: local branch labels */
  --remote: #7a5ea8;       /* violet: remote-tracking refs */
  --head: #b5651d;         /* amber: HEAD */
  --good: #2e7d4f;
  --bad: #b23a3a;
  --code-bg: #f0eee2;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --mono: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1a17; --fg: #e9e6da; --muted: #9c998d; --rule: #3a3833; --panel: #24231f;
    --accent: #e08b6f; --branch: #7fb2dc; --remote: #b59ae0; --head: #e0a35f;
    --good: #6cc391; --bad: #e57d7d; --code-bg: #26251f;
  }
}
:root[data-theme="dark"] {
  --bg: #1b1a17; --fg: #e9e6da; --muted: #9c998d; --rule: #3a3833; --panel: #24231f;
  --accent: #e08b6f; --branch: #7fb2dc; --remote: #b59ae0; --head: #e0a35f;
  --good: #6cc391; --bad: #e57d7d; --code-bg: #26251f;
}

* { box-sizing: border-box; }
html { font-size: 18px; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font-family: var(--serif); line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
main { max-width: 1060px; margin: 0 auto; padding: 3rem 16px 5rem; }
/* Reading column on the left, margin-note column on the right */
main > * { max-width: 640px; }
main > figure.wide, main > .wide { max-width: 1000px; }

/* ---------- Type ---------- */
.kicker { font-family: var(--sans); font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin: 0 0 .4rem; }
h1 { font-weight: 400; font-size: 2.3rem; line-height: 1.15; margin: 0 0 .6rem; }
h1 + .subtitle { font-style: italic; color: var(--muted); font-size: 1.15rem; margin-top: 0; }
h2 { font-weight: 400; font-style: italic; font-size: 1.5rem; margin: 2.8rem 0 .6rem; color: var(--accent); }
h3 { font-weight: 600; font-size: 1.05rem; margin: 1.8rem 0 .4rem; }
p, li { font-size: 1rem; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
strong { font-weight: 600; }
hr { border: 0; border-top: 1px solid var(--rule); margin: 2.5rem 0; }

code, kbd, pre { font-family: var(--mono); font-size: .82em; }
code { background: var(--code-bg); padding: .08em .3em; border-radius: 3px; }
pre {
  background: var(--code-bg); padding: .9rem 1rem; border-radius: 4px;
  overflow-x: auto; line-height: 1.5; border-left: 3px solid var(--rule);
}
pre code { background: none; padding: 0; font-size: 1em; }
pre .c { color: var(--muted); }          /* comment in a shell snippet */
pre .o { color: var(--muted); font-style: italic; } /* expected output */

/* ---------- Margin notes (citations, asides) ---------- */
.sidenote {
  float: right; clear: right; width: 300px; margin-right: -340px;
  font-family: var(--sans); font-size: .74rem; line-height: 1.45; color: var(--muted);
  margin-top: .25rem; position: relative;
}
.sidenote a { color: var(--muted); }
@media (max-width: 1060px) {
  .sidenote {
    float: none; display: block; width: auto; margin: .5rem 0 1rem;
    padding-left: .8rem; border-left: 2px solid var(--rule);
  }
}

/* ---------- Callouts ---------- */
.idea {
  font-size: 1.2rem; font-style: italic; border-left: 3px solid var(--accent);
  padding: .2rem 0 .2rem 1.1rem; margin: 1.5rem 0;
}
.box { background: var(--panel); border-radius: 6px; padding: 1rem 1.2rem; margin: 1.5rem 0; }
.box > :first-child { margin-top: 0; } .box > :last-child { margin-bottom: 0; }
.box.agent::before {
  content: "In the age of agents"; display: block; font-family: var(--sans);
  font-size: .7rem; letter-spacing: .1em; text-transform: uppercase; color: var(--accent); margin-bottom: .4rem;
}
.box.warn { border-left: 3px solid var(--head); }
.misconception { border-left: 3px solid var(--bad); }
.misconception::before {
  content: "Common misconception"; display: block; font-family: var(--sans);
  font-size: .7rem; letter-spacing: .1em; text-transform: uppercase; color: var(--bad); margin-bottom: .4rem;
}

/* ---------- Figures ---------- */
figure { margin: 1.8rem 0; }
figcaption { font-family: var(--sans); font-size: .76rem; color: var(--muted); margin-top: .4rem; }
.graph svg { max-width: 100%; height: auto; display: block; }
.graph-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; }
.graph-row figure { margin: 0; }

/* ---------- Checklist (assets/checklist.js) ---------- */
ol.steps { list-style: none; padding: 0; counter-reset: step; }
ol.steps > li { counter-increment: step; position: relative; padding: .2rem 0 .8rem 2.6rem; border-bottom: 1px dotted var(--rule); margin-bottom: .8rem; }
ol.steps > li::before {
  content: counter(step); position: absolute; left: 0; top: .15rem; width: 1.7rem; height: 1.7rem;
  border-radius: 50%; border: 1px solid var(--rule); font-family: var(--sans); font-size: .8rem;
  display: flex; align-items: center; justify-content: center; color: var(--muted);
}
ol.steps > li.done::before { content: "✓"; background: var(--good); border-color: var(--good); color: var(--bg); }
ol.steps > li.done > .step-title { color: var(--muted); }
.step-title { font-weight: 600; display: flex; align-items: baseline; gap: .6rem; justify-content: space-between; }
.step-toggle {
  font-family: var(--sans); font-size: .7rem; border: 1px solid var(--rule); background: transparent;
  color: var(--muted); border-radius: 999px; padding: .15rem .6rem; cursor: pointer; white-space: nowrap;
}
.step-toggle:hover { border-color: var(--good); color: var(--good); }
.progress { font-family: var(--sans); font-size: .78rem; color: var(--muted); }

/* ---------- Quiz (assets/quiz.js) ---------- */
.quiz { margin: 1.5rem 0; }
.q { margin: 0 0 1.6rem; }
.q-prompt { margin-bottom: .5rem; }
.q-options { display: grid; gap: .45rem; }
.q-option {
  text-align: left; font-family: var(--sans); font-size: .86rem; line-height: 1.4;
  background: transparent; color: var(--fg); border: 1px solid var(--rule); border-radius: 6px;
  padding: .55rem .8rem; cursor: pointer;
}
.q-option:hover:not(:disabled) { border-color: var(--accent); }
.q-option:disabled { cursor: default; }
.q-option.correct { border-color: var(--good); background: color-mix(in srgb, var(--good) 12%, transparent); }
.q-option.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 10%, transparent); }
.q-feedback { font-family: var(--sans); font-size: .82rem; margin-top: .5rem; color: var(--muted); }
.q-feedback strong.ok { color: var(--good); } .q-feedback strong.no { color: var(--bad); }
.q-score { font-family: var(--sans); font-size: .85rem; padding: .7rem 1rem; background: var(--panel); border-radius: 6px; }
.q-retry { margin-left: .6rem; }

/* ---------- Footer nav ---------- */
.lesson-nav { display: flex; justify-content: space-between; gap: 1rem; font-family: var(--sans); font-size: .82rem; border-top: 1px solid var(--rule); padding-top: 1rem; margin-top: 3rem; }
.ask { font-family: var(--sans); font-size: .85rem; }

/* ---------- Reference pages ---------- */
.ref main > * { max-width: 1000px; }
.ref table { border-collapse: collapse; width: 100%; font-size: .85rem; margin: .5rem 0 1.5rem; }
.ref th, .ref td { text-align: left; vertical-align: top; padding: .45rem .6rem; border-bottom: 1px solid var(--rule); }
.ref th { font-family: var(--sans); font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 500; }
.ref td code { white-space: nowrap; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 0 2rem; }

/* ---------- Print ---------- */
@media print {
  :root { --bg: #fff; --fg: #000; --panel: #f4f4f4; --code-bg: #f4f4f4; }
  html { font-size: 11pt; }
  main { padding: 0; max-width: none; }
  main > * { max-width: none; }
  .sidenote { float: none; width: auto; margin: .3rem 0 .8rem; display: block; }
  .step-toggle, .q-retry, .lesson-nav, .no-print { display: none !important; }
  .quiz .q-option { break-inside: avoid; }
  pre, figure, .box, table { break-inside: avoid; }
  a { color: inherit; }
}

/* ---------- Remote simulator (assets/remote-sim.js) ---------- */
.remote-sim { max-width: 1000px !important; margin: 1.5rem 0; font-family: var(--sans); }
.sim-boxes { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .8rem; }
.sim-box { border: 1px solid var(--rule); border-radius: 6px; padding: .7rem .8rem; background: var(--bg); }
.sim-box.remote { border-color: var(--remote); border-style: dashed; }
.sim-box.tracking .sim-name code { color: var(--remote); }
.sim-box.local .sim-name code { color: var(--branch); }
.sim-where { font-size: .66rem; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.sim-name { font-weight: 600; margin: .1rem 0 .5rem; }
.sim-chain { display: flex; flex-wrap: wrap; align-items: center; gap: .15rem; min-height: 1.8rem; }
.sim-note { font-size: .72rem; color: var(--muted); margin-top: .5rem; line-height: 1.4; }
.chip { display: inline-flex; align-items: center; justify-content: center; width: 1.6rem; height: 1.6rem; border-radius: 50%;
  border: 1.5px solid var(--fg); font-family: var(--mono); font-size: .72rem; }
.chip.theirs { border-color: var(--remote); color: var(--remote); }
.chip.mine { border-color: var(--branch); color: var(--branch); }
.chip.merge { border-radius: 4px; }
.chip.new { box-shadow: 0 0 0 3px color-mix(in srgb, var(--head) 45%, transparent); }
.link { color: var(--muted); }
.sim-buttons { display: flex; flex-wrap: wrap; gap: .4rem; margin: .9rem 0 .6rem; }
.sim-btn { font-family: var(--mono); font-size: .74rem; padding: .3rem .75rem; color: var(--fg); }
.sim-btn.theirs { color: var(--remote); font-family: var(--sans); }
.sim-term { font-size: .74rem; min-height: 6rem; max-height: 16rem; overflow-y: auto; white-space: pre-wrap; margin: 0; }
.sim-ch-title { font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-top: 1rem; }
.sim-challenges { font-size: .86rem; padding-left: 1.3rem; margin: .4rem 0 0; }
.sim-challenges li { margin: .25rem 0; }
.sim-challenges li.done { color: var(--good); }
.sim-challenges li.done::after { content: "  ✓"; font-weight: 700; }
@media print { .sim-buttons, .sim-term { display: none; } }

/* ---------- Small table inside a lesson ---------- */
table.ref-inline { border-collapse: collapse; width: 100%; font-family: var(--sans); font-size: .8rem; margin: .8rem 0 1.2rem; }
table.ref-inline th, table.ref-inline td { text-align: left; vertical-align: top; padding: .4rem .5rem; border-bottom: 1px solid var(--rule); }
table.ref-inline th { font-size: .68rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 500; }

/* ---------- Conflict drills (assets/conflict-drill.js) ---------- */
.conflict-drill { margin: 1.5rem 0; }
.cd { border: 1px solid var(--rule); border-radius: 6px; padding: .9rem 1rem; margin: 0 0 1.2rem; }
.cd.solved { border-color: var(--good); }
.cd-title { margin-bottom: .3rem; }
.cd-intent { font-family: var(--sans); font-size: .82rem; color: var(--muted); margin-bottom: .6rem; line-height: 1.45; }
.cd-text { width: 100%; font-family: var(--mono); font-size: .8rem; line-height: 1.5; background: var(--code-bg); color: var(--fg);
  border: 1px solid var(--rule); border-radius: 4px; padding: .6rem .7rem; resize: vertical; tab-size: 4; }
.cd-text:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); }
.cd-bar { display: flex; flex-wrap: wrap; gap: .4rem; margin: .5rem 0; }
.cd-btn { color: var(--fg); }
.cd-feedback { font-family: var(--sans); font-size: .82rem; color: var(--muted); }
.cd-feedback strong.ok { color: var(--good); } .cd-feedback strong.no { color: var(--bad); }
pre .add { color: var(--good); } pre .del { color: var(--bad); } pre .mk { color: var(--head); font-weight: 600; }
@media print { .cd-bar { display: none; } }

/* ---------- Diff review drill (assets/diff-review.js) ---------- */
.diff-review { margin: 1.5rem 0; font-family: var(--sans); }
.dr-title { font-weight: 600; font-size: .9rem; margin-bottom: .5rem; }
.dr-diff { border: 1px solid var(--rule); border-radius: 6px; overflow: hidden; font-family: var(--mono); font-size: .76rem; }
.dr-file { background: var(--panel); padding: .4rem .7rem; font-weight: 600; border-bottom: 1px solid var(--rule); border-top: 1px solid var(--rule); margin-top: -1px; }
.dr-line { display: flex; width: 100%; text-align: left; border: 0; border-left: 4px solid transparent; background: transparent; color: var(--fg);
  font: inherit; padding: .08rem .5rem; cursor: pointer; white-space: pre; overflow-x: auto; }
.dr-line:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.dr-line.add { background: color-mix(in srgb, var(--good) 10%, transparent); }
.dr-line.del { background: color-mix(in srgb, var(--bad) 9%, transparent); }
.dr-sign { width: 1.2rem; flex: none; color: var(--muted); }
.dr-line.flagged { border-left-color: var(--head); outline: 1px dashed var(--head); outline-offset: -1px; }
.dr-line.hit { border-left-color: var(--good); }
.dr-line.miss { border-left-color: var(--bad); }
.dr-result { font-size: .84rem; }
.dr-result li { margin: .35rem 0; } .dr-result li.ok strong { color: var(--good); } .dr-result li.no strong { color: var(--bad); }
.dr-score { margin: .4rem 0; }

/* ---------- Guardrail prediction drill (assets/rules-drill.js) ---------- */
.rules-drill { margin: 1.5rem 0; font-family: var(--sans); }
.rd-rules { background: var(--panel); border: 1px solid var(--rule); border-radius: 6px; padding: .6rem .9rem; font-size: .85rem; margin-bottom: 1rem; }
.rd-rules ul { margin: .3rem 0 0; padding-left: 1.2rem; }
.rd-title { font-weight: 600; }
.rd-case { border-top: 1px solid var(--rule); padding: .7rem 0; }
.rd-action { font-size: .92rem; margin-bottom: .4rem; }
.rd-bar { display: flex; gap: .5rem; }
.rd-bar .q-option { flex: 1; max-width: 10rem; }
