/* ==========================================================================
   The Model Railway Handbook — site styles
   A workshop ground: warm cream paper, ink-black lettering, and a palette
   borrowed from signal lamps and railway liveries. Each page, card and
   diagram takes its own livery colour.
   ========================================================================== */

:root {
  /* --- the livery board ---------------------------------------------- */
  --c-signal:  #c0392b;  --c-signal-w:  #fbe9e6;   /* signal red         */
  --c-orange:  #a65410;  --c-orange-w:  #fbeddc;   /* warning orange     */
  --c-brass:   #866614;  --c-brass-w:   #f8f0d6;   /* polished brass     */
  --c-olive:   #597319;  --c-olive-w:   #f0f5dc;   /* lineside green     */
  --c-green:   #29784e;  --c-green-w:   #e0f2e7;   /* clear-signal green */
  --c-teal:    #13767c;  --c-teal-w:    #ddf0f1;   /* Southern malachite */
  --c-steel:   #2d6cae;  --c-steel-w:   #e4eef9;   /* steel blue         */
  --c-indigo:  #4f4bb4;  --c-indigo-w:  #e9e8fa;   /* night blue         */
  --c-plum:    #863f96;  --c-plum-w:    #f3e7f6;   /* plum coach         */
  --c-maroon:  #a63a52;  --c-maroon-w:  #fae9ed;   /* crimson lake       */

  --liveries: linear-gradient(90deg,
    var(--c-signal) 0%, var(--c-orange) 12%, var(--c-brass) 24%, var(--c-olive) 36%,
    var(--c-green) 48%, var(--c-teal) 60%, var(--c-steel) 72%, var(--c-indigo) 82%,
    var(--c-plum) 91%, var(--c-maroon) 100%);

  /* --- paper, ink, metal --------------------------------------------- */
  --paper:   #fbf7ef;
  --paper-2: #f2ebdd;
  --card:    #ffffff;
  --ink:     #23201c;
  --ink-2:   #56504a;
  --ink-3:   #706961;
  --rule:    #e6ddcc;
  --rule-2:  #d3c7b2;

  /* the page's default livery — overridden per page and per card */
  --accent:   var(--c-teal);
  --accent-w: var(--c-teal-w);

  /* --- materials used by the diagrams -------------------------------- */
  --rail:      #8c8378;   /* rail head, viewed from the side */
  --rail-hi:   #cfc7bb;   /* polished railhead               */
  --sleeper:   #7a6650;   /* timber sleeper / tie            */
  --ballast:   #cbc3b6;
  --ground:    #d8d2c2;
  --sky:       #dceaf2;
  --hill:      #b9cfae;
  --hill-2:    #9dba93;
  --metal:     #b9b3a8;

  --shadow:    0 1px 2px rgba(35,32,28,.05), 0 8px 24px -12px rgba(35,32,28,.22);
  --shadow-lg: 0 2px 4px rgba(35,32,28,.06), 0 24px 48px -20px rgba(35,32,28,.3);

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans:  ui-sans-serif, -apple-system, "Segoe UI", Inter, Roboto, "Helvetica Neue", sans-serif;
  --mono:  ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --wrap: 1150px;
  --radius: 13px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --c-signal: #f5766a;  --c-signal-w: #3a1d1a;
    --c-orange: #f09443;  --c-orange-w: #3a2716;
    --c-brass:  #d9b342;  --c-brass-w:  #362c12;
    --c-olive:  #a8c552;  --c-olive-w:  #2b3315;
    --c-green:  #5cc48a;  --c-green-w:  #16341f;
    --c-teal:   #47c2c9;  --c-teal-w:   #103033;
    --c-steel:  #6da6ee;  --c-steel-w:  #17263a;
    --c-indigo: #9791f5;  --c-indigo-w: #211f42;
    --c-plum:   #c586d6;  --c-plum-w:   #2f1f36;
    --c-maroon: #ec7f96;  --c-maroon-w: #3a1c25;

    --paper:   #16140f;
    --paper-2: #1f1c17;
    --card:    #262219;
    --ink:     #f2ece0;
    --ink-2:   #c5bcae;
    --ink-3:   #948b7d;
    --rule:    #3a352c;
    --rule-2:  #4e4739;

    --rail:    #7d7568;
    --rail-hi: #b6ada0;
    --sleeper: #5b4c3b;
    --ballast: #4a443b;
    --ground:  #3c382f;
    --sky:     #1e2a33;
    --hill:    #35452f;
    --hill-2:  #2a3826;
    --metal:   #6d675c;

    --shadow:    0 1px 2px rgba(0,0,0,.35), 0 8px 24px -12px rgba(0,0,0,.65);
    --shadow-lg: 0 2px 4px rgba(0,0,0,.4), 0 24px 48px -20px rgba(0,0,0,.75);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 96px; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

img, svg { max-width: 100%; }
a { color: var(--accent); text-underline-offset: 3px; }
a:hover { filter: brightness(.88); }

h1, h2, h3, h4 { font-family: var(--serif); line-height: 1.14; margin: 0 0 .5em; font-weight: 600; letter-spacing: -.012em; }
h1 { font-size: clamp(2.05rem, 5vw, 3.1rem); }
h2 { font-size: clamp(1.55rem, 3.4vw, 2.15rem); }
h3 { font-size: 1.28rem; }
h4 { font-size: 1.02rem; font-family: var(--sans); font-weight: 700; }
h5 { font-family: var(--sans); }
p  { margin: 0 0 1.1em; }

.wrap { max-width: var(--wrap); margin: 0 auto; padding: 0 24px; }
.narrow { max-width: 810px; }

/* ---------- Livery classes -------------------------------------------- */

.a-signal { --accent: var(--c-signal); --accent-w: var(--c-signal-w); }
.a-orange { --accent: var(--c-orange); --accent-w: var(--c-orange-w); }
.a-brass  { --accent: var(--c-brass);  --accent-w: var(--c-brass-w); }
.a-olive  { --accent: var(--c-olive);  --accent-w: var(--c-olive-w); }
.a-green  { --accent: var(--c-green);  --accent-w: var(--c-green-w); }
.a-teal   { --accent: var(--c-teal);   --accent-w: var(--c-teal-w); }
.a-steel  { --accent: var(--c-steel);  --accent-w: var(--c-steel-w); }
.a-indigo { --accent: var(--c-indigo); --accent-w: var(--c-indigo-w); }
.a-plum   { --accent: var(--c-plum);   --accent-w: var(--c-plum-w); }
.a-maroon { --accent: var(--c-maroon); --accent-w: var(--c-maroon-w); }

/* ---------- Header ----------------------------------------------------
   The strip across the top is a length of track seen from above: two rails
   with sleepers running between them.                                    */

.track-top {
  height: 9px;
  background:
    repeating-linear-gradient(90deg, var(--sleeper) 0 3px, transparent 3px 11px),
    var(--ballast);
  border-top: 2px solid var(--rail);
  border-bottom: 2px solid var(--rail);
}

.site-head {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--paper) 90%, transparent);
  backdrop-filter: saturate(1.5) blur(12px);
  border-bottom: 1px solid var(--rule);
}
.head-inner {
  max-width: var(--wrap); margin: 0 auto; padding: 11px 24px;
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--serif); font-size: 1.2rem; font-weight: 600;
  color: var(--ink); text-decoration: none; letter-spacing: -.015em;
}
.brand svg { width: 34px; height: 34px; flex: none; border-radius: 9px; }
.brand b { font-weight: 600; color: var(--c-signal); }

.nav { display: flex; gap: 2px; margin-left: auto; flex-wrap: wrap; }
.nav a {
  padding: 7px 12px; border-radius: 999px; text-decoration: none;
  color: var(--ink-2); font-size: .92rem; font-weight: 500; white-space: nowrap;
  border: 1px solid transparent;
}
.nav a:nth-child(1) { --nc: var(--c-signal); }
.nav a:nth-child(2) { --nc: var(--c-orange); }
.nav a:nth-child(3) { --nc: var(--c-brass); }
.nav a:nth-child(4) { --nc: var(--c-olive); }
.nav a:nth-child(5) { --nc: var(--c-green); }
.nav a:nth-child(6) { --nc: var(--c-teal); }
.nav a:nth-child(7) { --nc: var(--c-steel); }
.nav a:nth-child(8) { --nc: var(--c-plum); }
.nav a:nth-child(9) { --nc: var(--c-maroon); }
.nav a:nth-child(10) { --nc: var(--c-olive); }
.nav a:nth-child(11) { --nc: var(--c-green); }
.nav a:hover { color: var(--nc); border-color: var(--nc); filter: none; }
.nav a[aria-current="page"] { background: var(--nc); color: #fff; border-color: var(--nc); }
@media (prefers-color-scheme: dark) { .nav a[aria-current="page"] { color: #17130f; } }

/* ---------- Links out to the other handbooks --------------------------
   They sit in the main nav, after a divider, so they read as somewhere
   else rather than another chapter of this site.                        */

.nav-sep {
  width: 1px; height: 22px; background: var(--rule-2);
  margin: 0 6px; align-self: center; flex: none;
}
.nav a.nav-out {
  color: var(--ink-3); font-weight: 600;
  display: inline-flex; align-items: center; gap: 7px;
}
.nav a.nav-out::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: var(--nc); flex: none;
}
.nav a.nav-out.o1 { --nc: var(--c-maroon); }
.nav a.nav-out.o2 { --nc: var(--c-indigo); }
.nav a.nav-out.o3 { --nc: var(--c-orange); }
.nav a.nav-out:hover { color: var(--nc); border-color: var(--nc); }

@media (max-width: 640px) { .nav-sep { display: none; } }

/* ---------- Hero ------------------------------------------------------ */

.hero {
  position: relative; overflow: hidden;
  background:
    linear-gradient(transparent 0 100%),
    radial-gradient(900px 420px at 14% -10%, var(--c-brass-w), transparent 64%),
    radial-gradient(780px 400px at 86% 4%, var(--c-steel-w), transparent 62%),
    radial-gradient(700px 420px at 52% 112%, var(--c-green-w), transparent 60%),
    var(--paper);
  border-bottom: 1px solid var(--rule);
  padding: clamp(46px, 8vw, 84px) 0 clamp(40px, 6vw, 68px);
}
/* faint drafting grid, like a sheet of layout-planning paper */
.hero::before {
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .5;
  background:
    repeating-linear-gradient(0deg, color-mix(in srgb, var(--rule) 70%, transparent) 0 1px, transparent 1px 32px),
    repeating-linear-gradient(90deg, color-mix(in srgb, var(--rule) 70%, transparent) 0 1px, transparent 1px 32px);
  mask-image: radial-gradient(circle at 50% 40%, #000, transparent 78%);
}
.hero > * { position: relative; }
.hero-grid { display: grid; grid-template-columns: 1.02fr .98fr; gap: 46px; align-items: center; }
.hero h1 { margin-bottom: .35em; }
.hero h1 em { font-style: normal; color: var(--c-signal); }
.hero .lede { font-size: 1.15rem; color: var(--ink-2); max-width: 48ch; }

.eyebrow {
  font-family: var(--sans); font-size: .75rem; font-weight: 700;
  letter-spacing: .15em; text-transform: uppercase; color: var(--accent);
  margin: 0 0 14px; display: flex; align-items: center; gap: 10px;
}
.eyebrow::after { content: ""; flex: 1; max-width: 90px; height: 3px; border-radius: 2px; background: var(--liveries); }

.hero-art { background: var(--card); border: 1px solid var(--rule); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow-lg); }
.hero-art::before { content: ""; display: block; height: 4px; border-radius: 3px; background: var(--liveries); margin: -4px 0 15px; }

.btn-row { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 26px; }
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 22px; border-radius: 999px; text-decoration: none;
  font-weight: 600; font-size: .95rem; border: 1px solid transparent; cursor: pointer;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(.9); color: #fff; }
.btn-ghost { border-color: var(--rule-2); color: var(--ink); background: var(--card); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); filter: none; }
@media (prefers-color-scheme: dark) { .btn-primary, .btn-primary:hover { color: #17130f; } }

/* ---------- Sections -------------------------------------------------- */

section { padding: clamp(44px, 6vw, 72px) 0; position: relative; }
section + section::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: var(--liveries); opacity: .45;
}
.section-head { max-width: 65ch; margin-bottom: 32px; }
.section-head p { color: var(--ink-2); margin-bottom: 0; }

.page-head { padding: clamp(38px, 5vw, 58px) 0 8px; }
.page-head .lede { font-size: 1.13rem; color: var(--ink-2); max-width: 64ch; }

/* ---------- Cards ----------------------------------------------------- */

.grid { display: grid; gap: 22px; }
.g2 { grid-template-columns: repeat(2, 1fr); }
.g3 { grid-template-columns: repeat(3, 1fr); }
.g4 { grid-template-columns: repeat(4, 1fr); }

.card {
  background: var(--card); border: 1px solid var(--rule);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius); padding: 21px; box-shadow: var(--shadow);
}
.card h3, .card h4 { margin-bottom: .35em; }
.card p:last-child { margin-bottom: 0; }
.card .meta { font-size: .84rem; color: var(--ink-3); }

a.card { text-decoration: none; color: inherit; display: block; transition: transform .15s ease, box-shadow .15s ease; }
a.card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); color: inherit; filter: none; }

.step-num {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent-w); color: var(--accent);
  border: 1.5px solid var(--accent);
  display: grid; place-items: center; font-weight: 700; font-size: .95rem;
  font-family: var(--mono); margin-bottom: 12px;
}

/* ---------- Badges ---------------------------------------------------- */

.badge {
  display: inline-block; padding: 3px 11px; border-radius: 999px;
  font-size: .71rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  background: var(--accent-w); color: var(--accent);
}
.b-easy  { background: var(--c-green-w);  color: var(--c-green); }
.b-mid   { background: var(--c-orange-w); color: var(--c-orange); }
.b-hard  { background: var(--c-signal-w); color: var(--c-signal); }
.b-info  { background: var(--c-steel-w);  color: var(--c-steel); }
.tags { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 14px; align-items: center; }

/* ---------- Lesson blocks --------------------------------------------- */

.lesson {
  background: var(--card); border: 1px solid var(--rule);
  border-left: 5px solid var(--accent);
  border-radius: var(--radius);
  padding: clamp(20px, 3vw, 32px); box-shadow: var(--shadow); margin-bottom: 28px;
  scroll-margin-top: 100px;
}
.lesson-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 8px; }
.lesson-head h2, .lesson-head h3 { margin-bottom: 0; }
.lesson-split { display: grid; grid-template-columns: 1fr 1fr; gap: 30px; align-items: start; margin-top: 20px; }
.lesson-split.wide-left { grid-template-columns: 1.35fr 1fr; }

ol.steps { counter-reset: s; list-style: none; padding: 0; margin: 0; }
ol.steps li { counter-increment: s; position: relative; padding-left: 46px; margin-bottom: 16px; }
ol.steps li::before {
  content: counter(s); position: absolute; left: 0; top: -1px;
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent-w); border: 1.5px solid var(--accent); color: var(--accent);
  display: grid; place-items: center; font-family: var(--mono); font-size: .85rem; font-weight: 700;
}
ol.steps li b { color: var(--ink); }

.callout {
  border-left: 4px solid var(--c-brass); background: var(--c-brass-w);
  padding: 14px 18px; border-radius: 0 10px 10px 0; margin: 20px 0; font-size: .95rem;
}
.callout.tip   { border-color: var(--c-green);  background: var(--c-green-w); }
.callout.watch { border-color: var(--c-signal); background: var(--c-signal-w); }
.callout.note  { border-color: var(--c-steel);  background: var(--c-steel-w); }
.callout.deep  { border-color: var(--c-plum);   background: var(--c-plum-w); }
.callout strong { display: block; font-size: .77rem; letter-spacing: .1em; text-transform: uppercase; margin-bottom: 4px; }
.callout p:last-child { margin-bottom: 0; }

/* ---------- Diagram frames -------------------------------------------- */

.diagram {
  background: var(--paper-2); border: 1px solid var(--rule);
  border-radius: 12px; padding: 16px; margin: 0 0 12px; overflow-x: auto;
}
.diagram.plain { background: var(--card); }
.diagram.blueprint {
  background:
    repeating-linear-gradient(0deg, color-mix(in srgb, var(--rule-2) 55%, transparent) 0 1px, transparent 1px 24px),
    repeating-linear-gradient(90deg, color-mix(in srgb, var(--rule-2) 55%, transparent) 0 1px, transparent 1px 24px),
    var(--paper-2);
}
.diagram svg { display: block; margin: 0 auto; height: auto; }
.diagram-cap { font-size: .87rem; color: var(--ink-3); text-align: center; margin: 10px 0 0; }
.diagram-cap b { color: var(--ink-2); }
figure { margin: 0 0 22px; }

.d-label { font-family: var(--sans); font-size: 10px; font-weight: 700; fill: var(--ink-2); letter-spacing: .04em; }
.d-note  { font-family: var(--sans); font-size: 9.5px; fill: var(--ink-3); }
.d-lead  { stroke: var(--ink-3); stroke-width: .8; fill: none; }
.d-dim   { stroke: var(--accent); stroke-width: 1; fill: none; }
.d-dimtx { font-family: var(--mono); font-size: 9.5px; fill: var(--accent); font-weight: 700; }

/* ---------- Legend / key ---------------------------------------------- */

.legend { display: flex; gap: 18px; flex-wrap: wrap; justify-content: center; font-size: .85rem; color: var(--ink-2); margin-top: 14px; }
.legend span { display: inline-flex; align-items: center; gap: 8px; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; flex: none; }
.chip { width: 22px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }

/* ---------- Tables ---------------------------------------------------- */

.table-scroll { overflow-x: auto; border: 1px solid var(--rule); border-radius: 12px; background: var(--card); }
table { border-collapse: collapse; width: 100%; font-size: .93rem; }
th, td { text-align: left; padding: 11px 15px; border-bottom: 1px solid var(--rule); vertical-align: top; }
thead th { background: var(--accent-w); color: var(--accent); font-size: .73rem; letter-spacing: .09em; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--paper); }
td code, p code, li code, th code, dd code {
  font-family: var(--mono); font-size: .88em; background: var(--accent-w);
  color: var(--accent); padding: 1px 6px; border-radius: 5px;
}
td.num, th.num { font-family: var(--mono); white-space: nowrap; }

/* ---------- Spec plate (mono block) ----------------------------------- */

.spec {
  font-family: var(--mono); font-size: .88rem; line-height: 1.9;
  background: var(--paper-2); border: 1px solid var(--rule);
  border-left: 4px solid var(--accent); border-radius: 0 10px 10px 0;
  padding: 14px 18px; margin: 0 0 18px; overflow-x: auto;
}
.spec div { white-space: nowrap; }
.spec .key { color: var(--accent); font-weight: 700; }

/* ---------- Filters --------------------------------------------------- */

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 26px; align-items: center; }
.filters button {
  font: inherit; font-size: .89rem; font-weight: 600;
  padding: 8px 15px; border-radius: 999px; cursor: pointer;
  border: 1.5px solid var(--fc, var(--rule-2)); background: var(--card); color: var(--fc, var(--ink-2));
}
.filters button:hover { filter: brightness(.95); }
.filters button[aria-pressed="true"] { background: var(--fc, var(--ink)); color: #fff; }
@media (prefers-color-scheme: dark) { .filters button[aria-pressed="true"] { color: #17130f; } }
.filters button:nth-child(10n+1) { --fc: var(--c-signal); }
.filters button:nth-child(10n+2) { --fc: var(--c-orange); }
.filters button:nth-child(10n+3) { --fc: var(--c-brass); }
.filters button:nth-child(10n+4) { --fc: var(--c-olive); }
.filters button:nth-child(10n+5) { --fc: var(--c-green); }
.filters button:nth-child(10n+6) { --fc: var(--c-teal); }
.filters button:nth-child(10n+7) { --fc: var(--c-steel); }
.filters button:nth-child(10n+8) { --fc: var(--c-indigo); }
.filters button:nth-child(10n+9) { --fc: var(--c-plum); }
.filters button:nth-child(10n)   { --fc: var(--c-maroon); }

.search {
  font: inherit; font-size: .93rem; padding: 9px 15px; border-radius: 999px;
  border: 1.5px solid var(--rule-2); background: var(--card); color: var(--ink);
  min-width: 250px; flex: 1;
}
.search:focus { outline: 2px solid var(--c-teal); outline-offset: 1px; border-color: transparent; }

/* ---------- Glossary -------------------------------------------------- */

.gloss { margin: 0; }
.gloss > div {
  border-bottom: 1px solid var(--rule); padding: 15px 0;
  display: grid; grid-template-columns: 240px 1fr; gap: 24px;
}
.gloss > div:nth-child(10n+1) { --accent: var(--c-signal); }
.gloss > div:nth-child(10n+2) { --accent: var(--c-orange); }
.gloss > div:nth-child(10n+3) { --accent: var(--c-brass); }
.gloss > div:nth-child(10n+4) { --accent: var(--c-olive); }
.gloss > div:nth-child(10n+5) { --accent: var(--c-green); }
.gloss > div:nth-child(10n+6) { --accent: var(--c-teal); }
.gloss > div:nth-child(10n+7) { --accent: var(--c-steel); }
.gloss > div:nth-child(10n+8) { --accent: var(--c-indigo); }
.gloss > div:nth-child(10n+9) { --accent: var(--c-plum); }
.gloss > div:nth-child(10n)   { --accent: var(--c-maroon); }
.gloss dt { font-weight: 700; color: var(--accent); font-size: 1.02rem; }
.gloss dt small { display: block; font-weight: 500; color: var(--ink-3); font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; margin-top: 3px; }
.gloss dd { margin: 0; color: var(--ink-2); font-size: .96rem; }
.gloss dd b { color: var(--ink); }
.no-hits { padding: 30px 0; color: var(--ink-3); }

/* ---------- Checklist ------------------------------------------------- */

.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li { border-bottom: 1px solid var(--rule); }
.checklist li:last-child { border-bottom: 0; }
.checklist li:nth-child(10n+1) { --accent: var(--c-signal); }
.checklist li:nth-child(10n+2) { --accent: var(--c-orange); }
.checklist li:nth-child(10n+3) { --accent: var(--c-brass); }
.checklist li:nth-child(10n+4) { --accent: var(--c-olive); }
.checklist li:nth-child(10n+5) { --accent: var(--c-green); }
.checklist li:nth-child(10n+6) { --accent: var(--c-teal); }
.checklist li:nth-child(10n+7) { --accent: var(--c-steel); }
.checklist li:nth-child(10n+8) { --accent: var(--c-indigo); }
.checklist li:nth-child(10n+9) { --accent: var(--c-plum); }
.checklist li:nth-child(10n)   { --accent: var(--c-maroon); }
.checklist label { display: flex; gap: 12px; align-items: flex-start; padding: 12px 2px; cursor: pointer; }
.checklist input { margin-top: 5px; width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.checklist span { font-size: .96rem; }
.checklist small { display: block; color: var(--ink-3); font-size: .84rem; }
.checklist input:checked + span { color: var(--ink-3); text-decoration: line-through; }
.progress-note { font-size: .86rem; color: var(--ink-3); margin: 14px 0 0; }

/* ---------- TOC ------------------------------------------------------- */

.toc { position: sticky; top: 100px; align-self: start; padding-left: 16px;
       background: linear-gradient(var(--liveries)) left/3px 100% no-repeat; }
.toc h4 { font-size: .71rem; letter-spacing: .13em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 12px; }
.toc a { display: block; padding: 4px 0; font-size: .91rem; text-decoration: none; color: var(--ink-2); }
.toc a:hover { color: var(--c-teal); filter: none; }
.with-toc { display: grid; grid-template-columns: 220px 1fr; gap: 42px; align-items: start; }

/* ---------- Footer ---------------------------------------------------- */

.site-foot { border-top: 1px solid var(--rule); background: var(--paper-2); padding: 0 0 34px; margin-top: 40px; font-size: .92rem; color: var(--ink-2); }
.site-foot .track-top { margin-bottom: 42px; }
.foot-grid { display: grid; grid-template-columns: 1.4fr 1fr 1fr 1fr; gap: 30px; }
.foot-grid h5 { font-size: .73rem; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); margin: 0 0 12px; }
.foot-grid ul { list-style: none; padding: 0; margin: 0; }
.foot-grid li { margin-bottom: 7px; }
.foot-grid a { text-decoration: none; color: var(--ink-2); }
.foot-grid a:hover { color: var(--c-teal); filter: none; }
.foot-bottom { border-top: 1px solid var(--rule); margin-top: 32px; padding-top: 20px; font-size: .85rem; color: var(--ink-3); }

/* Grid children default to min-width:auto, which lets a wide table or SVG
   push the whole column past the viewport. Pin them to zero instead. */
.with-toc > *, .grid > *, .lesson-split > *, .hero-grid > *, .foot-grid > *, .gloss > div > * { min-width: 0; }

/* ---------- Running train --------------------------------------------- */

.runner { overflow: hidden; }
.runner .train { animation: run 22s linear infinite; }
.puff { animation: puff 2.6s ease-out infinite; transform-origin: center; }
.puff:nth-of-type(2) { animation-delay: .5s; }
.puff:nth-of-type(3) { animation-delay: 1s; }
.puff:nth-of-type(4) { animation-delay: 1.5s; }
.wheelspin { animation: spin 1.4s linear infinite; transform-box: fill-box; transform-origin: center; }

@keyframes run  { from { transform: translateX(-430px); } to { transform: translateX(660px); } }
@keyframes puff { 0% { opacity: .55; transform: translate(0,0) scale(.5); } 100% { opacity: 0; transform: translate(-26px,-30px) scale(1.7); } }
@keyframes spin { to { transform: rotate(-360deg); } }

@media (prefers-reduced-motion: reduce) {
  .runner .train, .puff, .wheelspin { animation: none; }
  html { scroll-behavior: auto; }
}

/* ---------- Utility --------------------------------------------------- */

.mt0 { margin-top: 0; } .mb0 { margin-bottom: 0; } .mt24 { margin-top: 24px; }
.center { text-align: center; }
.muted { color: var(--ink-2); }
.small { font-size: .9rem; }
.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.lead-in { font-size: 1.06rem; color: var(--ink-2); }

/* ---------- Responsive ------------------------------------------------ */

@media (max-width: 960px) {
  .hero-grid, .lesson-split, .lesson-split.wide-left { grid-template-columns: 1fr; }
  .g4, .g3 { grid-template-columns: 1fr 1fr; }
  .with-toc { grid-template-columns: 1fr; }
  .toc { position: static; padding: 16px 0 0; background: linear-gradient(var(--liveries)) top/100% 3px no-repeat; padding-left: 0; }
  .foot-grid { grid-template-columns: 1fr 1fr; }
  .gloss > div { grid-template-columns: 1fr; gap: 6px; }
}
@media (max-width: 640px) {
  body { font-size: 16px; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .foot-grid { grid-template-columns: 1fr; }
  .head-inner { padding: 10px 16px; gap: 10px; }
  .nav { margin-left: 0; width: 100%; overflow-x: auto; }
  .wrap { padding: 0 16px; }
}

/* ---------- Track drawn in SVG ----------------------------------------
   Any <path> or <rect> can be turned into a length of track by drawing it
   four times, back to front: ballast bed, sleepers, rail pair, then the
   gap between the rails. Add .tk-sm on the wrapping <g> for tight plans.  */

.t-bed  { fill: none; stroke: var(--ballast); stroke-width: 12;  stroke-linecap: round; }
.t-tie  { fill: none; stroke: var(--sleeper); stroke-width: 11;  stroke-dasharray: 1.7 5.3; }
.t-rail { fill: none; stroke: var(--rail);    stroke-width: 7.4; }
.t-gap  { fill: none; stroke: var(--ballast); stroke-width: 4.6; }

.tk-sm .t-bed  { stroke-width: 8; }
.tk-sm .t-tie  { stroke-width: 7.4; stroke-dasharray: 1.2 3.6; }
.tk-sm .t-rail { stroke-width: 5; }
.tk-sm .t-gap  { stroke-width: 3; }

.board { fill: var(--paper); stroke: var(--rule-2); stroke-width: 2; }
.board-2 { fill: var(--paper-2); stroke: var(--rule-2); stroke-width: 1.5; }

/* ---------- Repair bay -------------------------------------------------
   A described symptom, matched against a list of faults. Everything works
   without JavaScript: the faults are plain <details> that open on click.  */

.ask { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 0 0 12px; }
.ask input {
  flex: 1; min-width: 260px; font: inherit; font-size: 1.02rem;
  padding: 13px 18px; border-radius: 999px;
  border: 2px solid var(--rule-2); background: var(--card); color: var(--ink);
}
.ask input:focus { outline: none; border-color: var(--c-teal); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 20px; }
.chips button {
  font: inherit; font-size: .89rem; padding: 7px 14px; border-radius: 999px;
  border: 1.5px solid var(--rule-2); background: var(--card); color: var(--ink-2); cursor: pointer;
}
.chips button:hover { border-color: var(--accent); color: var(--accent); }
.hit-count { font-size: .88rem; color: var(--ink-3); margin: 0 0 22px; }

.fault {
  background: var(--card); border: 1px solid var(--rule); border-left: 5px solid var(--accent);
  border-radius: var(--radius); margin-bottom: 12px; box-shadow: var(--shadow);
  scroll-margin-top: 100px;
}
.fault:nth-of-type(10n+1) { --accent: var(--c-signal); --accent-w: var(--c-signal-w); }
.fault:nth-of-type(10n+2) { --accent: var(--c-orange); --accent-w: var(--c-orange-w); }
.fault:nth-of-type(10n+3) { --accent: var(--c-brass);  --accent-w: var(--c-brass-w); }
.fault:nth-of-type(10n+4) { --accent: var(--c-olive);  --accent-w: var(--c-olive-w); }
.fault:nth-of-type(10n+5) { --accent: var(--c-green);  --accent-w: var(--c-green-w); }
.fault:nth-of-type(10n+6) { --accent: var(--c-teal);   --accent-w: var(--c-teal-w); }
.fault:nth-of-type(10n+7) { --accent: var(--c-steel);  --accent-w: var(--c-steel-w); }
.fault:nth-of-type(10n+8) { --accent: var(--c-indigo); --accent-w: var(--c-indigo-w); }
.fault:nth-of-type(10n+9) { --accent: var(--c-plum);   --accent-w: var(--c-plum-w); }
.fault:nth-of-type(10n)   { --accent: var(--c-maroon); --accent-w: var(--c-maroon-w); }

.fault > summary {
  cursor: pointer; padding: 15px 20px; list-style: none;
  font-family: var(--serif); font-size: 1.09rem; font-weight: 600; color: var(--ink);
  display: flex; gap: 12px; align-items: center; border-radius: 9px;
}
.fault > summary::-webkit-details-marker { display: none; }
.fault > summary::after {
  content: "+"; margin-left: auto; font-family: var(--mono); font-size: 1.25rem;
  color: var(--accent); line-height: 1;
}
.fault[open] > summary::after { content: "\2212"; }
.fault > summary:hover { background: var(--accent-w); }
.fault > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.fault .fault-body { padding: 2px 20px 18px; }
.fault .fault-body h4 { margin: 16px 0 6px; color: var(--accent); font-size: .78rem; letter-spacing: .1em; text-transform: uppercase; }
.fault .fault-body h4:first-child { margin-top: 4px; }
.fault .fault-body p, .fault .fault-body li { font-size: .96rem; }
.fault .fault-body ul { margin: 0; padding-left: 20px; }
.fault .fault-body ul li { margin-bottom: 5px; }
.fault .fault-body ol.steps li { margin-bottom: 12px; }

/* ---------- Fault report form ----------------------------------------- */

.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.field.wide { grid-column: 1 / -1; }
.field label {
  display: block; font-size: .74rem; font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase; color: var(--ink-3); margin-bottom: 6px;
}
.field input, .field select, .field textarea {
  width: 100%; font: inherit; font-size: .96rem; padding: 10px 13px;
  border-radius: 10px; border: 1.5px solid var(--rule-2);
  background: var(--card); color: var(--ink);
}
.field textarea { min-height: 86px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--c-teal); }

.report-out {
  white-space: pre-wrap; font-family: var(--mono); font-size: .87rem; line-height: 1.75;
  background: var(--paper-2); border: 1px solid var(--rule); border-left: 4px solid var(--c-green);
  border-radius: 0 10px 10px 0; padding: 15px 18px; margin: 18px 0 0; overflow-x: auto;
}
.report-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 14px; }
.copied { font-size: .87rem; color: var(--c-green); font-weight: 600; }

@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }

/* ---------- The drawing bench ------------------------------------------
   A transparent canvas over a squared-paper frame, so the eraser can cut
   holes in the drawing without touching the grid or a traced photo.      */

.bench-grid { display: grid; grid-template-columns: 1.25fr 1fr; gap: 22px; align-items: start; }
.bench-grid > * { min-width: 0; }

.panel {
  background: var(--card); border: 1px solid var(--rule); border-top: 3px solid var(--accent);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
}
.panel > h3 { margin-bottom: .2em; }
.panel > .panel-note { font-size: .89rem; color: var(--ink-3); margin: 0 0 16px; }

.toolbar { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar .sep { width: 1px; height: 24px; background: var(--rule); }
.swatches { display: flex; gap: 6px; }
.swatch {
  width: 27px; height: 27px; border-radius: 50%; border: 2px solid var(--rule-2);
  cursor: pointer; padding: 0; transition: transform .12s ease;
}
.swatch[aria-pressed="true"] { border-color: var(--ink); transform: scale(1.14); }
.tool-btn {
  font: inherit; font-size: .85rem; font-weight: 600; padding: 7px 13px; border-radius: 999px;
  border: 1.5px solid var(--rule-2); background: var(--card); color: var(--ink-2); cursor: pointer;
}
.tool-btn:hover { border-color: var(--accent); color: var(--accent); }
.tool-btn[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }
@media (prefers-color-scheme: dark) { .tool-btn[aria-pressed="true"] { color: #17130f; } }
.tool-btn.file { position: relative; overflow: hidden; }
.tool-btn.file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.canvas-frame {
  position: relative; border: 1px solid var(--rule-2); border-radius: 10px; overflow: hidden;
  background-color: var(--paper-2);
  background-image:
    repeating-linear-gradient(0deg, color-mix(in srgb, var(--rule-2) 60%, transparent) 0 1px, transparent 1px 24px),
    repeating-linear-gradient(90deg, color-mix(in srgb, var(--rule-2) 60%, transparent) 0 1px, transparent 1px 24px);
}
#underlay {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain;
  opacity: .32; pointer-events: none;
}
#sketch { position: relative; display: block; width: 100%; height: auto; touch-action: none; cursor: crosshair; }
.ruler { display: block; width: 100%; margin-top: 6px; }
.hintline { font-size: .85rem; color: var(--ink-3); margin: 10px 0 0; }

/* ---------- The build sheet -------------------------------------------- */

.sheet {
  background: var(--paper-2); border: 1px solid var(--rule); border-left: 4px solid var(--c-green);
  border-radius: 0 10px 10px 0; padding: 16px 20px; margin-top: 18px;
}
.sheet h4 {
  font-size: .74rem; letter-spacing: .1em; text-transform: uppercase;
  color: var(--c-green); margin: 18px 0 7px;
}
.sheet h4:first-child { margin-top: 0; }
.sheet p, .sheet li { font-size: .94rem; }
.sheet ul, .sheet ol { margin: 0; padding-left: 20px; }
.sheet li { margin-bottom: 5px; }
.sheet .headline { font-family: var(--serif); font-size: 1.2rem; font-weight: 600; color: var(--ink); margin: 0 0 4px; }
.sheet .sub { font-size: .88rem; color: var(--ink-3); margin: 0 0 4px; }
.sheet-empty { color: var(--ink-3); font-size: .93rem; }

@media (max-width: 960px) { .bench-grid { grid-template-columns: 1fr; } }
