/* dCREST, step by step — course stylesheet.
   Layout: a session rail on the left, one reading column (44rem) that lets figures,
   widgets and code cells widen to 62rem. Colours follow the model's stores:
   snow / canopy / soil / aquifer / fast flow / evaporation, so a colour means the
   same store on every page. */
:root {
  --paper: #F4F6F5; --surface: #FFFFFF; --sunk: #EBEFEE; --ink: #16232B; --muted: #56656D; --faint: #8A979E;
  --rule: #D6DDDF; --accent: #1C5A86; --accent-soft: #E1ECF4;
  --snow: #3D8FCB; --canopy: #3B8A4C; --soil: #8B5A3A; --aquifer: #14806C; --fast: #B4382C;
  --inter: #7B3D98; --et: #C9621A; --obs: #1E1E1E; --sim: #1C5A86;
  --ok: #1E7B4C; --warn: #A15C07; --bad: #B4382C;
  --f-display: "Newsreader", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --f-body: "Source Sans 3", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --f-mono: "JetBrains Mono", "SFMono-Regular", Menlo, Consolas, monospace;
  --text: 44rem; --wide: 62rem; --rail: 17rem; --radius: 8px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0F161B; --surface: #151F26; --sunk: #1B2730; --ink: #E2E9EC; --muted: #9BAAB2; --faint: #6F7F88;
    --rule: #26343D; --accent: #7DB8E6; --accent-soft: #17293A;
    --snow: #7CC0F0; --canopy: #6CC07E; --soil: #D19A73; --aquifer: #4CC9AE; --fast: #EE8676;
    --inter: #C597E0; --et: #F0A35C; --obs: #E2E9EC; --sim: #7DB8E6;
    --ok: #5BC48C; --warn: #E3A64A; --bad: #EE8676;
    color-scheme: dark;
  }
}
*, *::before, *::after { box-sizing: border-box; }
html { scroll-padding-top: 4.5rem; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--f-body); font-size: 17px; line-height: 1.7;
       -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
a { color: var(--accent); text-underline-offset: 2px; }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- top bar and rail ---------- */
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 1rem; padding: 0.55rem 1.2rem;
          background: color-mix(in srgb, var(--paper) 92%, transparent); backdrop-filter: blur(6px); border-bottom: 1px solid var(--rule); }
.topbar .brand { font-family: var(--f-display); font-weight: 600; font-size: 1.15rem; color: var(--ink); text-decoration: none; letter-spacing: 0.01em; }
.topbar .brand b { color: var(--accent); }
.topbar .where { color: var(--muted); font-size: 0.88rem; }
.topbar .spacer { flex: 1; }
.topbar a.ext { font-size: 0.85rem; color: var(--muted); text-decoration: none; }
.topbar button.menu { display: none; background: none; border: 1px solid var(--rule); border-radius: 6px; color: var(--ink); padding: 0.2rem 0.6rem; font: inherit; font-size: 0.85rem; cursor: pointer; }
.layout { display: grid; grid-template-columns: var(--rail) minmax(0, 1fr); }
nav.rail { position: sticky; top: 3.1rem; align-self: start; height: calc(100vh - 3.1rem); overflow-y: auto; padding: 1.4rem 1rem 2rem 1.2rem;
           border-right: 1px solid var(--rule); font-size: 0.9rem; }
nav.rail .part { margin: 1.1rem 0 0.35rem; font-size: 0.72rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--faint); }
nav.rail ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.1rem; }
nav.rail a { display: grid; grid-template-columns: 1.7rem 1fr; gap: 0.2rem; padding: 0.3rem 0.45rem; border-radius: 6px; color: var(--ink); text-decoration: none; line-height: 1.35; }
nav.rail a .n { font-family: var(--f-mono); font-size: 0.78rem; color: var(--faint); padding-top: 0.12rem; }
nav.rail a:hover { background: var(--sunk); }
nav.rail a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
nav.rail a[aria-current="page"] .n { color: var(--accent); }
@media (max-width: 980px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  nav.rail { display: none; position: fixed; inset: 3.1rem 0 0 0; height: auto; z-index: 25; background: var(--paper); border-right: none; }
  body.rail-open nav.rail { display: block; }
  .topbar button.menu { display: inline-block; }
}

/* ---------- reading column ---------- */
main { padding: 2.2rem 1.4rem 5rem; min-width: 0; }
main > * { max-width: var(--text); margin-left: auto; margin-right: auto; }
main > .wide, main > figure, main > .widget, main > .pycell, main > .tablewrap.wide, main > .grid2 { max-width: var(--wide); }
.kicker { font-family: var(--f-mono); font-size: 0.78rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent); margin-bottom: 0.4rem; }
h1, h2, h3, h4 { font-family: var(--f-display); font-weight: 600; line-height: 1.25; text-wrap: balance; color: var(--ink); }
h1 { font-size: clamp(2.1rem, 4.2vw, 2.9rem); margin: 0 auto 0.8rem; letter-spacing: -0.005em; }
h2 { font-size: 1.65rem; margin: 3rem auto 0.7rem; padding-top: 1.2rem; border-top: 1px solid var(--rule); }
h3 { font-size: 1.25rem; margin: 2rem auto 0.4rem; }
h4 { font-size: 1.05rem; margin: 1.4rem auto 0.3rem; font-family: var(--f-body); font-weight: 700; }
p, ul, ol { margin-top: 0; margin-bottom: 1rem; }
li + li { margin-top: 0.3rem; }
.lede { font-size: 1.16rem; color: var(--ink); }
.meta { display: flex; flex-wrap: wrap; gap: 0.5rem 1.4rem; color: var(--muted); font-size: 0.9rem; margin-bottom: 1.4rem; }
.meta b { color: var(--ink); font-weight: 600; }
.goals { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 1rem 1.3rem 0.4rem; margin-bottom: 1.6rem; }
.goals h4 { margin: 0 0 0.4rem; font-size: 0.8rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.goals ul { padding-left: 1.2rem; }
strong { font-weight: 700; }
code { font-family: var(--f-mono); font-size: 0.86em; background: var(--sunk); padding: 0.08em 0.36em; border-radius: 4px; }
var, .v { font-family: var(--f-display); font-style: italic; font-size: 1.04em; }
var[data-v] { border-bottom: 1px dotted var(--faint); cursor: help; }
kbd { font-family: var(--f-mono); font-size: 0.8em; border: 1px solid var(--rule); border-bottom-width: 2px; border-radius: 4px; padding: 0 0.3em; }
hr { border: none; border-top: 1px solid var(--rule); margin: 2rem auto; }

/* ---------- callouts ---------- */
.callout { position: relative; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 0.95rem 1.2rem 0.2rem; margin: 1.3rem auto 1.5rem; }
.callout > .label { display: inline-block; font-family: var(--f-mono); font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase; padding: 0.1rem 0.5rem; border-radius: 4px; margin-bottom: 0.5rem; }
.callout.idea > .label { background: var(--accent-soft); color: var(--accent); }
.callout.case > .label { background: color-mix(in srgb, var(--aquifer) 16%, transparent); color: var(--aquifer); }
.callout.code > .label { background: var(--sunk); color: var(--muted); }
.callout.warn > .label { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.callout.try > .label { background: color-mix(in srgb, var(--et) 16%, transparent); color: var(--et); }
.callout p:last-child, .callout ul:last-child { margin-bottom: 0.8rem; }

/* ---------- equations ---------- */
.eq { overflow-x: auto; margin: 0.8rem auto 1.2rem; padding: 0.35rem 0; }
.eqnote { color: var(--muted); font-size: 0.9rem; margin-top: -0.6rem; }
.katex { font-size: 1.06em; }
.katex-display { margin: 0.6rem 0 !important; }

/* ---------- tables ---------- */
.tablewrap { overflow-x: auto; margin: 1rem auto 1.5rem; }
table { border-collapse: collapse; width: 100%; font-size: 0.92rem; line-height: 1.45; }
th, td { padding: 0.45rem 0.65rem; border-bottom: 1px solid var(--rule); text-align: left; vertical-align: top; }
thead th { font-size: 0.76rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); font-weight: 600; border-bottom: 1.5px solid var(--ink); }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--f-mono); font-size: 0.82rem; white-space: nowrap; }
tr.group td { background: var(--sunk); font-weight: 700; font-size: 0.8rem; letter-spacing: 0.04em; color: var(--muted); }
td.sym { font-family: var(--f-display); font-style: italic; font-size: 1.02rem; white-space: nowrap; }

/* ---------- figures and widgets ---------- */
figure { margin: 1.6rem auto 2rem; }
figure > .plate, .widget { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); }
figure > .plate { padding: 0.8rem; overflow-x: auto; }
figure img, figure svg { display: block; max-width: 100%; height: auto; margin: 0 auto; }
figcaption { color: var(--muted); font-size: 0.9rem; margin-top: 0.55rem; line-height: 1.55; }
figcaption b { color: var(--ink); }
figure.video video { display: block; width: 100%; height: auto; aspect-ratio: 16 / 9; background: #0E1013; border-radius: var(--radius); border: 1px solid var(--rule); }
.widget { margin: 1.6rem auto 2rem; padding: 1rem 1.1rem 1.1rem; }
.widget > .whead { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.3rem 0.8rem; margin-bottom: 0.7rem; }
.widget > .whead .wtitle { font-family: var(--f-display); font-weight: 600; font-size: 1.12rem; }
.widget > .whead .wtag { font-family: var(--f-mono); font-size: 0.7rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--et); }
.widget .note { color: var(--muted); font-size: 0.88rem; }
.controls { display: grid; grid-template-columns: repeat(auto-fill, minmax(13.5rem, 1fr)); gap: 0.55rem 1.3rem; margin: 0.6rem 0 0.8rem; }
.ctl { display: grid; gap: 0.1rem; font-size: 0.86rem; }
.ctl .top { display: flex; justify-content: space-between; gap: 0.5rem; }
.ctl .top span:first-child { color: var(--ink); }
.ctl output, .ctl .val { font-family: var(--f-mono); font-size: 0.8rem; color: var(--accent); font-variant-numeric: tabular-nums; }
.ctl input[type=range] { width: 100%; accent-color: var(--accent); }
.ctl select, .ctl input[type=date], .ctl input[type=number] { font: inherit; font-size: 0.86rem; padding: 0.2rem 0.4rem; border: 1px solid var(--rule); border-radius: 6px; background: var(--surface); color: var(--ink); }
.btnrow { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin: 0.5rem 0; }
button.btn { font: inherit; font-size: 0.86rem; padding: 0.32rem 0.85rem; border-radius: 6px; border: 1px solid var(--accent); background: var(--accent); color: var(--surface); cursor: pointer; }
button.btn.ghost { background: transparent; color: var(--accent); }
button.btn:disabled { opacity: 0.45; cursor: default; }
.stats { display: flex; flex-wrap: wrap; gap: 0.4rem 1.5rem; font-size: 0.88rem; margin: 0.4rem 0; }
.stats .s { display: grid; }
.stats .s .k { color: var(--muted); font-size: 0.74rem; letter-spacing: 0.06em; text-transform: uppercase; }
.stats .s .v2 { font-family: var(--f-mono); font-size: 1rem; font-variant-numeric: tabular-nums; }
.chart { width: 100%; min-height: 60px; }
.uplot { font-family: var(--f-body); }
.u-legend { font-size: 0.8rem; }
.u-legend .u-marker { border-radius: 2px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(19rem, 1fr)); gap: 1.2rem; margin: 1.4rem auto; align-items: start; }
.grid2 > figure, .grid2 > .widget { margin: 0; }
.legend-inline { display: inline-flex; align-items: center; gap: 0.3rem; margin-right: 0.9rem; font-size: 0.85rem; color: var(--muted); }
.sw { display: inline-block; width: 0.8em; height: 0.8em; border-radius: 2px; }
svg text { font-family: var(--f-body); }
svg text:not([fill]) { fill: var(--ink); }
svg .muted { fill: var(--muted); }
svg .mono { font-family: var(--f-mono); }

/* ---------- code ---------- */
pre { background: var(--sunk); border-radius: var(--radius); padding: 0.85rem 1rem; overflow-x: auto; font-family: var(--f-mono); font-size: 0.82rem; line-height: 1.55; margin: 0.8rem auto 1.3rem; }
pre code { background: none; padding: 0; font-size: inherit; }
pre .c, .cm-comment { color: var(--faint); }
.pycell { margin: 1.6rem auto 2rem; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.pycell .bar { display: flex; align-items: center; gap: 0.6rem; padding: 0.45rem 0.8rem; background: var(--sunk); border-bottom: 1px solid var(--rule); font-size: 0.82rem; }
.pycell .bar .tag { font-family: var(--f-mono); font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.pycell .bar .title { color: var(--ink); font-weight: 600; }
.pycell .bar .spacer { flex: 1; }
.pycell .bar .status { color: var(--muted); font-size: 0.78rem; }
.pycell .CodeMirror { height: auto; font-family: var(--f-mono); font-size: 0.82rem; line-height: 1.55; background: var(--surface); color: var(--ink); }
.pycell .CodeMirror-scroll { max-height: 34rem; }
.pycell .CodeMirror-gutters { background: var(--surface); border-right: 1px solid var(--rule); }
.pycell .CodeMirror-linenumber { color: var(--faint); }
.pycell .CodeMirror-cursor { border-left-color: var(--ink); }
.pycell textarea.src { width: 100%; min-height: 10rem; font-family: var(--f-mono); font-size: 0.82rem; border: none; padding: 0.8rem; background: var(--surface); color: var(--ink); }
.pycell .out { margin: 0; border-radius: 0; border-top: 1px solid var(--rule); max-height: 28rem; overflow: auto; background: var(--paper); white-space: pre; display: none; }
.pycell .out.err { color: var(--bad); }
.pycell .plots { padding: 0 0.6rem; }
.pycell .plots:empty { display: none; }
.cm-s-course .cm-keyword { color: #8A3FB0; } .cm-s-course .cm-def { color: #1C5A86; font-weight: 600; }
.cm-s-course .cm-number { color: #B4382C; } .cm-s-course .cm-string { color: #1E7B4C; } .cm-s-course .cm-builtin { color: #A15C07; }
.cm-s-course .cm-comment { color: #8A979E; font-style: italic; } .cm-s-course .cm-operator { color: var(--muted); }
@media (prefers-color-scheme: dark) {
  .cm-s-course .cm-keyword { color: #CDA0EA; } .cm-s-course .cm-def { color: #8FC6F0; }
  .cm-s-course .cm-number { color: #F09A8C; } .cm-s-course .cm-string { color: #7FD3A2; } .cm-s-course .cm-builtin { color: #F0BA6C; }
}

/* ---------- quiz ---------- */
.quiz { margin: 1.4rem auto; display: grid; gap: 0.6rem; }
.quiz details { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 0.7rem 1rem; }
.quiz summary { cursor: pointer; font-weight: 600; }
.quiz summary::marker { color: var(--accent); }
.quiz details[open] summary { margin-bottom: 0.5rem; }
.quiz .ans { color: var(--ink); }
.quiz .ans p:last-child { margin-bottom: 0.2rem; }

/* ---------- summary and pager ---------- */
.remember { background: var(--accent-soft); border-radius: var(--radius); padding: 1rem 1.3rem 0.3rem; margin: 2rem auto; }
.remember h4 { margin-top: 0; color: var(--accent); }
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin: 3rem auto 0; }
.pager a { display: block; padding: 0.8rem 1rem; border: 1px solid var(--rule); border-radius: var(--radius); text-decoration: none; background: var(--surface); }
.pager a .d { display: block; font-size: 0.75rem; color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; }
.pager a .t { font-family: var(--f-display); font-size: 1.05rem; color: var(--ink); }
.pager a.next { text-align: right; grid-column: 2; }
.tip { position: absolute; z-index: 50; max-width: 19rem; background: var(--ink); color: var(--paper); font-size: 0.82rem; line-height: 1.45; padding: 0.5rem 0.7rem; border-radius: 6px; pointer-events: none; box-shadow: 0 6px 18px rgba(0,0,0,0.18); }
.tip b { font-family: var(--f-display); font-style: italic; font-size: 0.95rem; }
.tip .c { display: block; font-family: var(--f-mono); font-size: 0.72rem; opacity: 0.75; margin-top: 0.2rem; }
footer.site { max-width: var(--wide); margin: 4rem auto 0; padding: 1.2rem 0 0; border-top: 1px solid var(--rule); color: var(--muted); font-size: 0.82rem; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
code, pre, kbd, .mono, .CodeMirror, svg .mono, .ctl output, .stats .v2, td.n { font-variant-ligatures: none; font-feature-settings: "liga" 0, "calt" 0; }

/* parameter groups (Session 11) */
.pgroup { margin: 0.3rem 0 0.2rem; }
.pgroup > h5 { margin: 0.7rem 0 0; font-size: 0.74rem; letter-spacing: 0.1em; text-transform: uppercase; font-weight: 700; }
.pgroup .controls { margin-top: 0.3rem; }
canvas.land { display: block; max-width: 100%; touch-action: none; cursor: crosshair; }
.chk { display: inline-flex; gap: 0.4rem; align-items: center; font-size: 0.86rem; }
/* never upper-case maths or symbols inside upper-cased labels */
.katex, .nc, var { text-transform: none; }
/* reference list */
.refs p { font-size: 0.86rem; padding-left: 1.6rem; text-indent: -1.6rem; margin: 0.35rem 0; overflow-wrap: anywhere; }
/* let grid items shrink so wide tables scroll inside their own box */
.grid2 > * { min-width: 0; }
.grid2 > .tablewrap { margin: 0; }
/* a control never grows past its grid column (long <select> options used to spill into the next column) */
.controls > * { min-width: 0; }
.ctl select { width: 100%; max-width: 100%; min-width: 0; text-overflow: ellipsis; }
.ctl input[type=search], .ctl input[type=number], .ctl input[type=date] { max-width: 100%; box-sizing: border-box; }
.btnrow .lbl { font-size: 0.86rem; color: var(--muted); margin-right: 0.2rem; }
