/* Engineer's Notebook — tabbed handbook */

:root {
  --ground: #e8ebea;
  --sheet: #f6f7f6;
  --ink: #16181a;
  --ink-2: #4c5351;
  --rule: #16181a;
  --hair: #c3c9c7;
  --tab: #d2d8d6;
  --tab-hover: #c3cbc8;
  --ox: #b3261e;
  --ox-tint: #ecd8d4;
  --on-ox: #f6f7f6;

  --serif: "Source Serif 4", Georgia, serif;
  --label: "Archivo Narrow", "Arial Narrow", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;

  --gutter: clamp(16px, 5vw, 80px);
  --tabs-w: 72px;
  --measure: 40rem;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);

  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='320' height='320'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .09 0 0 0 0 .11 0 0 0 0 .11 0 0 0 .10 0'/%3E%3C/filter%3E%3Crect width='320' height='320' filter='url(%23g)'/%3E%3C/svg%3E");
  --fibre: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='640' height='640'%3E%3Cfilter id='f'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.012 .09' numOctaves='2' seed='7' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .1 0 0 0 0 .12 0 0 0 0 .12 0 0 0 .07 -.01'/%3E%3C/filter%3E%3Crect width='640' height='640' filter='url(%23f)'/%3E%3C/svg%3E");
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scrollbar-color: var(--ink-2) var(--ground); }
body {
  margin: 0;
  background: var(--ground) var(--grain);
  color: var(--ink);
  font: 400 1.125rem/1.6 var(--serif);
  font-optical-sizing: auto;
  caret-color: var(--ox);
  position: relative;
}
/* Paper fibres: a faint layer fixed to the page, so it scrolls with the sheet, drifting slowly under the grain. */
body::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--fibre);
  pointer-events: none;
  animation: drift 90s steps(90) infinite alternate;
}
/* Background-position keeps the layer inside the page; steps() repaints about once a second. */
@keyframes drift { to { background-position: -40px 24px; } }

::selection { background: var(--ox); color: var(--on-ox); }
h1, h2, h3, p, ol, ul, dl, figure, table { margin: 0; }
a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
a:hover { color: var(--ox); }
:focus-visible { outline: 2px solid var(--ox); outline-offset: 3px; }

.skip { position: absolute; left: -9999px; }
.skip:focus { left: var(--gutter); top: 8px; background: var(--sheet); padding: 8px 12px; z-index: 10; }

/* ---------- running head ---------- */
.head {
  display: flex;
  align-items: baseline;
  gap: 1.5rem;
  margin: 0 calc(var(--gutter) + var(--tabs-w)) 0 var(--gutter);
  padding: 28px 0 10px;
  border-bottom: 4px double var(--rule);
  font: 700 0.8125rem/1.2 var(--label);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
/* Baseline-aligned so the name lines up with the crumbs and ref; the icon centres on it. */
.head .site { display: inline-flex; align-items: baseline; gap: 0.55em; text-decoration: none; }
.head .site img { display: block; flex: none; align-self: center; }
.head .crumbs { display: flex; gap: 0.6em; flex-wrap: wrap; flex: 1; justify-content: center; }
.head .crumbs a { text-decoration: none; color: var(--ox); }
.head .crumbs span[aria-hidden] { color: var(--ink-2); }
.head .ref { font-family: var(--mono); font-weight: 500; letter-spacing: 0.04em; }

/* ---------- discipline tabs ---------- */
.tabs {
  position: fixed;
  top: 88px;
  right: 0;
  width: var(--tabs-w);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
  z-index: 5;
}
.tabs a {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  min-height: 92px;
  padding: 12px 0;
  border-radius: 10px 0 0 10px;
  background: var(--tab);
  color: var(--ink);
  text-decoration: none;
  font: 700 0.8125rem/1 var(--label);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  transition: width 0.25s var(--ease), background-color 0.2s;
}
.tabs a.soon { color: var(--ink-2); }
.tabs a:hover { background: var(--tab-hover); color: var(--ink); width: 58px; }
.tabs a[aria-current] { width: var(--tabs-w); background: var(--ox); color: var(--on-ox); }
.tabs a:focus-visible { outline-offset: -4px; outline-color: var(--ink); }

/* ---------- page frame ---------- */
main {
  margin: 0 calc(var(--gutter) + var(--tabs-w)) 0 var(--gutter);
  padding: 48px 0 0;
}
.title {
  font: 700 clamp(2.5rem, 5vw, 3.5rem)/1.04 var(--serif);
  letter-spacing: -0.02em;
  text-wrap: balance;
}
.lede { margin-top: 0.9rem; max-width: var(--measure); font-size: 1.1875rem; }
.prose { max-width: var(--measure); }
.prose p + p { margin-top: 0.9em; }
.muted { color: var(--ink-2); }

h2 {
  margin: 3.5rem 0 1rem;
  padding-top: 10px;
  border-top: 1px solid var(--rule);
  font: 700 0.875rem/1.2 var(--label);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
h3 { margin: 0; font: 600 1.25rem/1.3 var(--serif); }
.legend { margin-top: 0.9rem; font: 500 0.875rem/1.4 var(--label); letter-spacing: 0.02em; color: var(--ink-2); }

/* ---------- maths ---------- */
.v { font-family: var(--serif); font-style: italic; font-weight: 500; font-size: 1.12em; letter-spacing: 0; }
sub { font-family: var(--serif); font-style: normal; font-size: 0.6em; }
.frac { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; }
.frac > span { padding: 0 0.2em; }
.frac > span:first-child { border-bottom: 2px solid currentColor; padding-bottom: 0.12em; }
.frac > span:last-child { padding-top: 0.14em; }
.eq {
  margin-top: 1.75rem;
  padding: 1.25rem 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  font: 500 clamp(1.75rem, 3.2vw, 2.25rem)/1 var(--mono);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4em;
  flex-wrap: wrap;
}
.eq .frac { font-size: 0.82em; }
.inline-eq, .derive code { font: 500 0.9375rem var(--mono); white-space: nowrap; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; margin-top: 1rem; }
table {
  width: 100%;
  border-collapse: collapse;
  font: 400 0.9375rem/1.4 var(--mono);
  font-variant-numeric: tabular-nums;
}
th {
  text-align: left;
  padding: 7px 10px;
  border-top: 2px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  font: 700 0.8125rem/1.2 var(--label);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  white-space: nowrap;
}
td { padding: 11px 10px; border-bottom: 1px solid var(--hair); vertical-align: middle; }
td:first-child, th:first-child { padding-left: 0; }
tbody th { border-top: 0; border-bottom: 1px solid var(--hair); font: 400 1rem/1.4 var(--serif); letter-spacing: 0; text-transform: none; white-space: normal; }
td a, tbody th a { font-family: var(--serif); text-decoration: none; border-bottom: 1px solid var(--hair); }
td a:hover, tbody th a:hover { border-color: var(--ox); }
td .frac { font-size: 0.86em; line-height: 1.15; }
td .frac > span:first-child { border-bottom-width: 1px; }
.planned th, .planned td { color: var(--ink-2); }
.prep { font: 500 0.75rem/1 var(--label); letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-2); white-space: nowrap; }
.prep.live { color: var(--ox); }
th .prep.live { margin-left: 0.6em; }

/* ---------- symbols ---------- */
.symbols { display: grid; grid-template-columns: 2.25rem 1fr auto 4.25rem 1fr auto; margin-top: 1.25rem; }
.symbols dt, .symbols dd { padding: 7px 0; border-bottom: 1px solid var(--hair); margin: 0; }
.symbols dt { font: italic 500 1.0625rem var(--serif); }
.symbols dt:nth-of-type(even) { padding-left: 2rem; grid-column-start: 4; }
.symbols dd { font-size: 1rem; }
.symbols dd.u { font: 400 0.875rem var(--mono); color: var(--ink-2); text-align: right; padding-left: 12px; }

/* ---------- topic layout ---------- */
.topic {
  display: grid;
  grid-template-columns: minmax(0, var(--measure)) minmax(340px, 1fr);
  column-gap: clamp(32px, 5vw, 72px);
  align-items: start;
  /* The demo spans every row; the last, flexible row absorbs its extra height so collapsed sections don't stretch. */
  grid-template-rows: auto auto auto 1fr;
}
.topic > .col { grid-column: 1; }
.topic > .demo-col { grid-column: 2; grid-row: 1 / span 4; }
@media (min-width: 961px) and (min-height: 720px) { .topic > .demo-col { position: sticky; top: 24px; } }

/* ---------- worked example ---------- */
.step {
  display: grid;
  grid-template-columns: 7rem minmax(0, 1fr);
  column-gap: 1rem;
  padding: 14px 0;
  border-bottom: 1px solid var(--hair);
}
.step > .lbl { font: 700 0.8125rem/1.6 var(--label); letter-spacing: 0.14em; text-transform: uppercase; padding-top: 2px; }
.given { list-style: none; padding: 0; display: grid; gap: 4px; font: 500 0.9375rem/1.5 var(--mono); }
.given li { display: grid; grid-template-columns: 2.5rem 1fr auto; gap: 8px; align-items: baseline; }
.given .what { font: 400 1rem var(--serif); color: var(--ink-2); }
.calc { display: grid; gap: 6px; font: 500 0.9375rem/1.5 var(--mono); }
.calc .sub-line { color: var(--ink-2); }
.answer {
  display: inline-flex;
  align-items: baseline;
  gap: 0.4em;
  border: 2px solid var(--ox);
  padding: 8px 16px;
  font: 500 1.625rem/1.2 var(--mono);
  color: var(--ox);
}
.live { border-radius: 2px; }
.live.flash { animation: live-flash 0.9s var(--ease); }
@keyframes live-flash { from { background-color: var(--ox-tint); } to { background-color: transparent; } }
.answer.live { border-radius: 0; }
.answer-note { margin-top: 8px; font-size: 1rem; color: var(--ink-2); }

/* ---------- demo box ---------- */
.demo {
  background: var(--sheet);
  border: 1px solid var(--rule);
  padding: 18px 20px 20px;
}
.demo svg { display: block; width: 100%; height: auto; }
.demo figcaption {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--hair);
  font: 500 0.8125rem/1.45 var(--label);
  letter-spacing: 0.02em;
  color: var(--ink-2);
}
.demo figcaption b { color: var(--ink); letter-spacing: 0.08em; text-transform: uppercase; margin-right: 0.4em; }
.controls { margin-top: 12px; display: grid; }
.ctl {
  display: grid;
  grid-template-columns: 7.5rem 1fr 6rem;
  align-items: center;
  gap: 12px;
  padding: 5px 0;
  border-bottom: 1px solid var(--hair);
}
.ctl label { font: 600 0.875rem/1.2 var(--label); letter-spacing: 0.04em; }
.ctl label i { font: italic 500 1rem var(--serif); letter-spacing: 0; margin-right: 0.25em; }
.unit { font: 400 0.75rem var(--mono); color: var(--ink-2); }
.ctl input[type="number"], .ctl select {
  width: 100%;
  font: 500 0.875rem/1 var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: var(--ground);
  border: 1px solid var(--ink-2);
  border-radius: 0;
  padding: 7px 8px;
}
.ctl select { grid-column: 2 / 4; }
.ctl input[aria-invalid="true"] { border-color: var(--ox); background: var(--ox-tint); }
input[type="range"] { width: 100%; accent-color: var(--ox); }
.err { grid-column: 1 / -1; font: 500 0.8125rem/1.3 var(--label); color: var(--ox); }
.err:empty { display: none; }
.results { margin-top: 14px; }
.results td { white-space: nowrap; padding-top: 8px; padding-bottom: 8px; }
.results td:last-child { text-align: right; font-weight: 500; }
.results tr.key td { font-size: 1.0625rem; border-bottom: 2px solid var(--rule); }
.results tr.key td:last-child { color: var(--ox); }
.readout { margin-top: 12px; font: 400 0.9375rem/1.5 var(--serif); }

/* ---------- demo figures (svg.fig: styled from the tokens, drawn by each topic script) ---------- */
svg.fig text { font: 400 13px var(--mono); fill: var(--ink-2); }
svg.fig text.lbl { font: 600 12px var(--label); letter-spacing: 0.04em; }
svg.fig text.t-ink { fill: var(--ink); }
svg.fig text.t-ox { fill: var(--ox); }
svg.fig .s-ink { stroke: var(--ink); fill: none; }
svg.fig .s-ink2 { stroke: var(--ink-2); fill: none; }
svg.fig .s-hair { stroke: var(--hair); fill: none; }
svg.fig .s-ox { stroke: var(--ox); fill: none; }
svg.fig .f-ink { fill: var(--ink); }
svg.fig .f-ox { fill: var(--ox); }
svg.fig .f-tab { fill: var(--tab); }
svg.fig .f-tint { fill: var(--ox-tint); }
svg.fig .f-sheet { fill: var(--sheet); }
svg.fig .dash { stroke-dasharray: 4 4; }

/* ---------- other load cases ---------- */
.cases { list-style: none; padding: 0; }
.cases li {
  display: grid;
  grid-template-columns: 7rem minmax(0, 1fr);
  column-gap: 1.25rem;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--hair);
}
.cases svg { width: 7rem; height: auto; display: block; }
.cases h3 { font-size: 1.0625rem; }
.cases .f { display: flex; gap: 1.75rem; flex-wrap: wrap; margin-top: 6px; font: 500 0.9375rem var(--mono); }
.cases .f > span { display: inline-flex; align-items: center; gap: 0.35em; }
.cases .f .frac { font-size: 0.9em; line-height: 1.15; }
.cases .f .frac > span:first-child { border-bottom-width: 1px; }

/* ---------- collapsible ---------- */
details.more > summary { list-style: none; cursor: pointer; }
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary h2 { display: flex; justify-content: space-between; align-items: center; margin: 2.25rem 0 0; padding-bottom: 10px; }
details.more[open] > summary h2 { margin-bottom: 1rem; }
.worked-live > details.more > summary h2 { margin-top: 3.5rem; }
details.more > summary h2::after {
  content: "";
  width: 8px; height: 8px;
  border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: translateY(-3px) rotate(45deg);
  transition: transform 0.25s var(--ease);
}
details.more[open] > summary h2::after { transform: translateY(2px) rotate(-135deg); }
details.more > summary:hover h2 { color: var(--ox); }
details.more > summary:focus-visible { outline: none; }
details.more > summary:focus-visible h2 { outline: 2px solid var(--ox); outline-offset: 4px; }
ol.derive { padding-left: 1.4rem; display: grid; gap: 0.6rem; }
details.more > .prose + .derive, details.more > .derive + .prose { margin-top: 0.9rem; }
ol.derive li::marker { font: 700 0.875rem var(--label); color: var(--ox); }
ul.plain { padding-left: 1.1rem; display: grid; gap: 0.4rem; }
ul.plain li::marker { color: var(--ox); }

.pager { display: flex; justify-content: space-between; gap: 1rem; margin-top: 3.5rem; padding: 12px 0; border-top: 4px double var(--rule); font: 600 0.875rem/1.3 var(--label); letter-spacing: 0.02em; }

/* ---------- home ---------- */
.home-intro { display: flex; justify-content: space-between; align-items: end; gap: 1.5rem 3rem; flex-wrap: wrap; }
.home-title { margin: 0; line-height: 0; }
.home-title img { display: block; width: clamp(17rem, 40vw, 34rem); height: auto; }
.home-intro .lede { max-width: 28rem; margin-top: 0; }
.shelf {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  column-gap: clamp(24px, 3vw, 48px);
  row-gap: 2.75rem;
  margin-top: 2.75rem;
}
.disc { border-top: 2px solid var(--rule); padding-top: 12px; }
.disc header { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.disc h2 { margin: 0; padding: 0; border: 0; font: 700 1.5rem/1.2 var(--serif); letter-spacing: -0.01em; text-transform: none; }
.disc h2 a { text-decoration: none; }
.disc .count { font: 500 0.75rem var(--label); letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-2); white-space: nowrap; }
.disc .count.live { color: var(--ox); }
.disc p { margin-top: 6px; font-size: 1rem; color: var(--ink-2); }
.disc ol { list-style: none; padding: 0; margin-top: 12px; }
.disc li { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: baseline; padding: 7px 0; border-bottom: 1px solid var(--hair); font-size: 1rem; color: var(--ink-2); }
.disc li .k { font: 500 0.8125rem var(--mono); white-space: nowrap; }
.disc li.live { color: var(--ink); }
.disc li.live a { font-weight: 600; }
.disc.soon h2 { color: var(--ink-2); }

.example {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 26rem);
  column-gap: clamp(32px, 5vw, 72px);
  align-items: center;
}
.example .eq { justify-content: flex-start; margin-top: 1rem; }
.example .go { display: inline-block; margin-top: 1rem; font-weight: 600; }
.example .demo { padding: 14px 16px; }

/* ---------- mechanics index ---------- */
.toc { display: flex; flex-wrap: wrap; gap: 0.4rem 1.5rem; margin-top: 1.25rem; padding: 0; list-style: none; font: 700 0.8125rem var(--label); letter-spacing: 0.12em; text-transform: uppercase; }
.toc a { text-decoration: none; color: var(--ox); }
.topics-page h2 { max-width: 52rem; }
table.topics { table-layout: fixed; width: 52rem; max-width: 100%; }
table.topics col.c-n { width: 4rem; }
table.topics col.c-t { width: 26rem; }
table.topics col.c-f { width: 22rem; }
table.topics td:nth-child(3) { white-space: nowrap; }
tr.current td, tr.current th { background: var(--ox-tint); }
tr.current th { font-weight: 600; }

/* ---------- footer ---------- */
.foot {
  margin: 4.5rem calc(var(--gutter) + var(--tabs-w)) 0 var(--gutter);
  padding: 14px 0 36px;
  border-top: 1px solid var(--rule);
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  font: 500 0.8125rem/1.4 var(--label);
  letter-spacing: 0.02em;
  color: var(--ink-2);
}

/* ---------- narrower screens ---------- */
@media (max-width: 1180px) {
  .shelf { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 960px) {
  .topic, .example { grid-template-columns: minmax(0, 1fr); }
  .topic { grid-template-rows: none; }
  .topic > .demo-col { grid-column: 1; grid-row: auto; margin-top: 2rem; }
  .example .demo { margin-top: 1.5rem; }
}
@media (max-width: 760px) {
  :root { --tabs-w: 0px; }
  body { font-size: 1.0625rem; }
  .head { padding-top: 18px; flex-wrap: wrap; gap: 0.4rem 1rem; }
  .head .crumbs { order: 3; flex-basis: 100%; justify-content: flex-start; }
  .head .ref { margin-left: auto; }
  .tabs {
    position: sticky;
    top: 0;
    width: auto;
    flex-direction: row;
    align-items: stretch;
    gap: 4px;
    padding: 8px var(--gutter) 0;
    background: var(--ground) var(--grain);
    border-bottom: 2px solid var(--rule);
    overflow-x: auto;
    scrollbar-width: none;
    mask-image: linear-gradient(to right, #000 calc(100% - 40px), transparent);
  }
  .tabs a, .tabs a:hover, .tabs a[aria-current] {
    writing-mode: horizontal-tb;
    transform: none;
    width: auto;
    min-height: 0;
    padding: 10px 12px 8px;
    border-radius: 8px 8px 0 0;
    white-space: nowrap;
  }
  main { padding-top: 28px; }
  .shelf { grid-template-columns: minmax(0, 1fr); }
  .symbols { grid-template-columns: 2.25rem 1fr auto; }
  .symbols dt:nth-of-type(even) { padding-left: 0; grid-column-start: auto; }
  .step { grid-template-columns: minmax(0, 1fr); row-gap: 6px; }
  .ctl { grid-template-columns: 6rem 1fr 5.5rem; gap: 8px; }
  .demo { padding: 14px; }
  .cases li { grid-template-columns: 5rem minmax(0, 1fr); }
  .cases svg { width: 5rem; }
  table.topics colgroup { display: none; }
  table.topics tr { display: grid; grid-template-columns: 2.5rem 1fr auto; gap: 4px 12px; padding: 10px; border-bottom: 1px solid var(--hair); align-items: baseline; }
  table.topics th, table.topics td { border: 0; padding: 0; background: none; }
  tr.current { background: var(--ox-tint); }
}

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