/* ──────────────────────────────────────────────────────────────────────────
   THE WAY THE MOTOR WORKS — stylesheet
   A parchment-and-ink homage to the great illustrated explainer books.
   Plain CSS, no build step.
   ────────────────────────────────────────────────────────────────────────── */

:root {
  --paper:        #e9dec4;   /* page background */
  --paper-plate:  #f3ead4;   /* plate panel paper, a touch brighter */
  --ink:          #44321f;   /* warm dark brown ink */
  --ink-faded:    #6e5a40;
  --ink-faint:    #93805f;
  --brick:        #b65c38;   /* terracotta / copper */
  --brick-deep:   #94472a;
  --steel:        #6e8896;   /* cool slate for iron & S poles */
  --iron:         #7d8a8f;
  --mustard:      #c9a04e;   /* energized / highlight */
  --sage:         #8a9471;
  --cream:        #f6efdd;
  --magnet-n:     #c46a4a;
  --magnet-s:     #6e8896;
  --serif: "Alegreya", "Iowan Old Style", Georgia, serif;
  --smallcaps: "Alegreya SC", "Alegreya", Georgia, serif;
  --hand: "Caveat", "Bradley Hand", cursive;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  background-color: var(--paper);
  /* layered paper: soft vignette + fine grain (inline SVG noise) */
  background-image:
    radial-gradient(ellipse 120% 90% at 50% 0%, rgba(255, 250, 235, 0.55), transparent 60%),
    radial-gradient(ellipse 140% 120% at 50% 110%, rgba(94, 72, 40, 0.18), transparent 65%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3CfeComponentTransfer%3E%3CfeFuncA type='linear' slope='0.05'/%3E%3C/feComponentTransfer%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.62;
  overflow-x: hidden;
}

/* ── Book front matter ──────────────────────────────────────────────────── */

.bookplate {
  max-width: 1080px;
  margin: 0 auto;
  padding: 64px 28px 8px;
  text-align: center;
}

.bookplate .over-title {
  font-family: var(--smallcaps);
  letter-spacing: 0.32em;
  font-size: 14px;
  color: var(--ink-faded);
  text-transform: uppercase;
}

.bookplate h1 {
  font-size: clamp(46px, 7.5vw, 96px);
  line-height: 1.02;
  font-weight: 700;
  letter-spacing: 0.01em;
  margin: 18px 0 10px;
  text-wrap: balance;
}

.bookplate .being {
  font-style: italic;
  font-size: clamp(17px, 2.2vw, 22px);
  color: var(--ink-faded);
  max-width: 640px;
  margin: 0 auto;
  text-wrap: balance;
}

.bookplate .being .sc { font-family: var(--smallcaps); font-style: normal; font-size: 0.92em; }

.rule-ornament {
  display: flex; align-items: center; justify-content: center;
  gap: 14px; margin: 26px auto 0; color: var(--ink-faded);
}
.rule-ornament::before, .rule-ornament::after {
  content: ""; height: 1px; width: min(220px, 26vw);
  background: linear-gradient(90deg, transparent, var(--ink-faded));
}
.rule-ornament::after { background: linear-gradient(90deg, var(--ink-faded), transparent); }
.rule-ornament svg { display: block; }

.hand-note {
  font-family: var(--hand);
  font-size: 21px;
  color: var(--ink-faded);
  transform: rotate(-1.6deg);
  margin: 18px auto 0;
  max-width: 480px;
}

.scroll-hint {
  margin: 28px auto 0;
  font-family: var(--smallcaps);
  letter-spacing: 0.22em;
  font-size: 13px;
  color: var(--ink-faded);
}
.scroll-hint .arr { display: block; font-size: 20px; margin-top: 4px; animation: bob 2.2s ease-in-out infinite; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(7px); } }

/* hero figure sits free on the paper, no panel */
.hero-fig { max-width: 1080px; margin: 8px auto 0; padding: 0 16px; }
.hero-fig svg { width: 100%; height: auto; display: block; }

/* ── Contents ribbon ────────────────────────────────────────────────────── */

.contents {
  max-width: 760px;
  margin: 40px auto 12px;
  padding: 22px 30px 26px;
  border-top: 1px solid var(--ink-faded);
  border-bottom: 1px solid var(--ink-faded);
  position: relative;
}
.contents h2 {
  font-family: var(--smallcaps); text-align: center; letter-spacing: 0.3em;
  font-size: 15px; font-weight: 500; margin-bottom: 14px; color: var(--ink-faded);
}
.contents ol { list-style: none; columns: 2; column-gap: 48px; }
.contents li { margin: 3px 0; break-inside: avoid; }
.contents a {
  color: var(--ink); text-decoration: none; display: flex; align-items: baseline; gap: 8px;
}
.contents a:hover .toc-title { color: var(--brick-deep); }
.contents .toc-no { font-family: var(--smallcaps); font-size: 13px; color: var(--brick-deep); min-width: 2.4em; }
.contents .toc-dots { flex: 1; border-bottom: 1px dotted var(--ink-faint); transform: translateY(-4px); }
@media (max-width: 640px) { .contents ol { columns: 1; } }

/* ── Plates ─────────────────────────────────────────────────────────────── */

.plate {
  max-width: 1080px;
  margin: 56px auto;
  padding: 0 16px;
}

.plate-inner {
  background: var(--paper-plate);
  border: 1.5px solid var(--ink);
  outline: 1px solid var(--ink-faint);
  outline-offset: 5px;
  box-shadow: 0 2px 0 rgba(68, 50, 31, 0.18), 0 14px 36px -18px rgba(68, 50, 31, 0.45);
  padding: 36px 44px 40px;
  position: relative;
}

.plate-head {
  text-align: center;
  margin-bottom: 26px;
}
.plate-no {
  font-family: var(--smallcaps);
  letter-spacing: 0.34em;
  font-size: 13px;
  color: var(--brick-deep);
}
.plate-head h2 {
  font-size: clamp(28px, 4vw, 40px);
  font-weight: 700;
  line-height: 1.1;
  margin-top: 6px;
  text-wrap: balance;
}
.plate-head .dek {
  font-style: italic; color: var(--ink-faded); margin-top: 8px; font-size: 19px;
  max-width: 620px; margin-left: auto; margin-right: auto; text-wrap: balance;
}

.plate-body { display: grid; gap: 28px; }
.plate-body.cols { grid-template-columns: 3fr 2fr; align-items: center; }
.plate-body.cols.flip { grid-template-columns: 2fr 3fr; }
@media (max-width: 880px) {
  .plate-inner { padding: 26px 20px 30px; }
  .plate-body.cols, .plate-body.cols.flip { grid-template-columns: 1fr; }
}

.prose p { margin-bottom: 12px; text-wrap: pretty; }
.prose p:last-child { margin-bottom: 0; }
.prose em { font-style: italic; }
.prose strong { color: var(--brick-deep); font-weight: 600; }

/* book-style drop cap on designated paragraphs */
.prose .dropcap::first-letter {
  font-size: 3.4em; float: left; line-height: 0.82;
  padding: 4px 8px 0 0; font-weight: 700; color: var(--brick-deep);
}

.fig { margin: 0; }
.fig svg { width: 100%; height: auto; display: block; }
figcaption, .figcaption {
  margin-top: 10px;
  font-size: 15px;
  font-style: italic;
  color: var(--ink-faded);
  text-align: center;
  line-height: 1.45;
}
figcaption .figno, .figcaption .figno {
  font-family: var(--smallcaps); font-style: normal; letter-spacing: 0.14em;
  color: var(--brick-deep); margin-right: 6px;
}

.margin-note {
  font-family: var(--hand);
  font-size: 20px;
  line-height: 1.3;
  color: var(--ink-faded);
  transform: rotate(-1.2deg);
  border-left: 2px solid var(--ink-faint);
  padding-left: 14px;
  margin-top: 16px;
}

.footnote {
  margin-top: 22px;
  padding-top: 12px;
  border-top: 1px solid var(--ink-faint);
  font-size: 14.5px;
  color: var(--ink-faded);
  line-height: 1.5;
}
.footnote a { color: var(--brick-deep); }

/* keyed parts list, as in the book's numbered callouts */
.parts-list {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 6px 22px;
  font-size: 16px;
  margin-top: 4px;
}
.parts-list li { display: flex; gap: 10px; align-items: baseline; }
.parts-list .key {
  flex: none;
  font-family: var(--smallcaps);
  width: 24px; height: 24px; border-radius: 50%;
  border: 1.5px solid var(--ink);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px; transform: translateY(4px);
  background: var(--cream);
}

/* ── Instruments: sliders, levers, dials ────────────────────────────────── */

.instrument {
  margin-top: 18px;
  padding: 14px 18px 16px;
  border: 1.5px solid var(--ink);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.35), rgba(120,90,50,0.07)),
    var(--cream);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.6), 0 2px 0 rgba(68,50,31,0.25);
  border-radius: 3px;
}
.instrument .inst-label {
  font-family: var(--smallcaps);
  letter-spacing: 0.18em;
  font-size: 12.5px;
  color: var(--ink-faded);
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 8px;
}
.instrument .inst-value {
  font-family: var(--smallcaps); font-size: 15px; color: var(--brick-deep);
  font-variant-numeric: tabular-nums; letter-spacing: 0.06em;
}

input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 26px; background: transparent; cursor: pointer; display: block;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px; border-radius: 3px;
  background: linear-gradient(180deg, #9c8155, #c2a878);
  border: 1px solid var(--ink);
  box-shadow: inset 0 1px 2px rgba(60,40,20,0.5);
}
input[type="range"]::-moz-range-track {
  height: 6px; border-radius: 3px;
  background: linear-gradient(180deg, #9c8155, #c2a878);
  border: 1px solid var(--ink);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 22px; height: 22px; margin-top: -9px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #e9cf96, #b68c46 60%, #7d5c28);
  border: 1.5px solid var(--ink);
  box-shadow: 0 2px 3px rgba(60,40,20,0.45);
}
input[type="range"]::-moz-range-thumb {
  width: 20px; height: 20px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #e9cf96, #b68c46 60%, #7d5c28);
  border: 1.5px solid var(--ink);
  box-shadow: 0 2px 3px rgba(60,40,20,0.45);
}
input[type="range"]:focus-visible { outline: 2px dashed var(--brick-deep); outline-offset: 4px; }

/* knife-switch lever toggle */
.lever {
  display: inline-flex; align-items: center; gap: 12px;
  font-family: var(--smallcaps); font-size: 13px; letter-spacing: 0.14em;
  color: var(--ink-faded);
  cursor: pointer; user-select: none;
  background: none; border: none; padding: 4px 2px;
}
.lever .blade {
  width: 58px; height: 26px; position: relative; flex: none;
}
.lever .blade::before { /* base plate */
  content: ""; position: absolute; inset: 9px 0;
  background: linear-gradient(180deg, #c2a878, #9c8155);
  border: 1px solid var(--ink); border-radius: 3px;
}
.lever .blade::after { /* the blade itself */
  content: ""; position: absolute; left: 4px; top: 11px;
  width: 36px; height: 5px; border-radius: 2px;
  background: var(--brick-deep);
  border: 1px solid var(--ink);
  transform-origin: 3px 50%;
  transform: rotate(-26deg);
  transition: transform 0.18s ease;
  box-shadow: 0 1px 2px rgba(60,40,20,0.5);
}
.lever[aria-pressed="true"] .blade::after { transform: rotate(26deg); }
.lever .side { transition: color 0.15s; }
.lever[aria-pressed="false"] .side.off,
.lever[aria-pressed="true"] .side.on { color: var(--brick-deep); font-weight: 700; }
.lever:focus-visible { outline: 2px dashed var(--brick-deep); outline-offset: 3px; }

button.lever:hover .blade::before { filter: brightness(1.06); }

/* ── Stats, in the manner of a specimen table ───────────────────────────── */

.stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  border: 1.5px solid var(--ink);
  background: var(--cream);
  margin-top: 18px;
}
.stats > div {
  padding: 12px 14px 10px;
  border-right: 1px solid var(--ink-faint);
}
.stats > div:last-child { border-right: none; }
.stats b {
  display: block; font-size: 26px; font-weight: 700; color: var(--brick-deep);
  font-variant-numeric: tabular-nums; line-height: 1.1;
}
.stats span {
  display: block; font-family: var(--smallcaps); font-size: 11.5px;
  letter-spacing: 0.08em; color: var(--ink-faded); margin-top: 4px; line-height: 1.4;
}
@media (max-width: 560px) {
  .stats { grid-template-columns: 1fr; }
  .stats > div { border-right: none; border-bottom: 1px solid var(--ink-faint); }
  .stats > div:last-child { border-bottom: none; }
}

.readout-table { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 16px; }
.readout-table td { padding: 5px 8px; border-bottom: 1px dotted var(--ink-faint); }
.readout-table td:last-child {
  text-align: right; font-family: var(--smallcaps);
  color: var(--brick-deep); font-variant-numeric: tabular-nums;
}

/* mammoth-pull gauge */
.mammoth-gauge { margin-top: 16px; }
.mammoth-gauge .gauge-label {
  font-family: var(--smallcaps); font-size: 12.5px; letter-spacing: 0.18em;
  color: var(--ink-faded); margin-bottom: 6px;
}
.mammoth-row { display: flex; flex-wrap: wrap; gap: 2px; min-height: 36px; align-items: flex-end; }
.mammoth-row svg { width: 54px; height: 41px; display: block; }
.mammoth-row .half { opacity: 0.45; }

/* ── In-figure SVG conventions ──────────────────────────────────────────── */

svg text { font-family: var(--serif); fill: var(--ink); }
svg .lbl   { font-size: 15px; font-style: italic; fill: var(--ink-faded); }
svg .lbl-sc { font-family: var(--smallcaps); font-size: 13px; letter-spacing: 0.12em; fill: var(--ink); }
svg .lbl-hand { font-family: var(--hand); font-size: 21px; fill: var(--ink-faded); }
svg .leader { stroke: var(--ink-faded); stroke-width: 1; fill: none; }
svg .keynum circle { fill: var(--cream); stroke: var(--ink); stroke-width: 1.5; }
svg .keynum text {
  font-family: var(--smallcaps); font-size: 13px; font-style: normal;
  text-anchor: middle; fill: var(--ink);
}

/* gentle shimmer for flux arrows */
.flux-arrow { animation: shimmer 1.8s ease-in-out infinite; }
@keyframes shimmer { 0%, 100% { opacity: 0.35; } 50% { opacity: 1; } }

/* plates ease in as they enter the page (only when JS is present to un-hide them) */
.js .plate .plate-inner { opacity: 0; transform: translateY(14px); transition: opacity 0.7s ease, transform 0.7s ease; }
.js .plate.inview .plate-inner { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  .plate .plate-inner { opacity: 1; transform: none; transition: none; }
  .flux-arrow { animation: none; opacity: 0.9; }
  .scroll-hint .arr { animation: none; }
  html { scroll-behavior: auto; }
}

/* ── Colophon ───────────────────────────────────────────────────────────── */

.colophon {
  max-width: 760px;
  margin: 70px auto 60px;
  padding: 26px 30px 30px;
  border-top: 1px solid var(--ink-faded);
  text-align: center;
  font-size: 15px;
  color: var(--ink-faded);
  line-height: 1.8;
}
.colophon a { color: var(--brick-deep); }
.colophon .mammoth-bow { margin: 6px auto 14px; width: 96px; }
.colophon .mammoth-bow svg { width: 100%; height: auto; }
