/* "How trains work" (set PHY): the page's own styles. The site's site.css comes first, so these only add what the
   figures need. Figure colours are tokens with a dark set, as the site's are. */
:root {
  --sky: #F2F4F6; --fumes: #3A3530; --fumes2: #6A625A; --ground: #E9E4DA; --ballast: #CFC8BA; --sleeper: #A8957A; --rail: #6E737C;
  --shell: #3B4048; --dark: #23262C; --metal: #8A909A; --metal2: #B9BEC6; --wheel: #2A2D33; --spoke: #9AA0AA;
  --water: #8FC1DE; --steam: #E3EAEF; --fire: #E8792B; --fire2: #F6C445; --live: #D9472B; --exh: #9AA3AE;
  --amp: #A87400; --regen: #1F9D55; --glass: #A9C0D0; --body: #E5E8EC; --body-line: #3B4048; --wire: #2E3238; --blue: #1D5FBF;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --sky: #151A20; --fumes: #8C8278; --fumes2: #5E5750; --ground: #1D2026; --ballast: #34373D; --sleeper: #5E503F; --rail: #9AA0AA;
  --shell: #59606B; --dark: #30343B; --metal: #7C838E; --metal2: #5A606A; --wheel: #3A3F47; --spoke: #A4AAB5;
  --water: #2F6A8C; --steam: #232B33; --glass: #3E5566; --body: #262B32; --body-line: #A4AAB5; --wire: #C9CDD3;
  --amp: #F2B829; --regen: #3CC47A; --blue: #6E9EF0; } }
/* set HTW2 (P1): the charts' own colours, one job each, so the figures' fire and current keep theirs. Steam a coal-fire
   red, diesel a deep teal, electric the current's amber; speed is --blue on every meter. design/htw2/palette.py checks
   them: 4:1 or more against the bar's track in both themes, and apart for each kind of colour vision */
:root { --k-steam: #A3360F; --k-diesel: #0E7C7B; --k-electric: var(--amp); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --k-steam: #E0603A; --k-diesel: #4CC9C0; } }
:root[data-theme="dark"] { --k-steam: #E0603A; --k-diesel: #4CC9C0; }
:root[data-theme="dark"] {
  --sky: #151A20; --fumes: #8C8278; --fumes2: #5E5750; --ground: #1D2026; --ballast: #34373D; --sleeper: #5E503F; --rail: #9AA0AA;
  --shell: #59606B; --dark: #30343B; --metal: #7C838E; --metal2: #5A606A; --wheel: #3A3F47; --spoke: #A4AAB5;
  --water: #2F6A8C; --steam: #232B33; --glass: #3E5566; --body: #262B32; --body-line: #A4AAB5; --wire: #C9CDD3;
  --amp: #F2B829; --regen: #3CC47A; --blue: #6E9EF0;
}

.hw .lede { font-size: 1.12rem; color: var(--muted); max-width: 62ch; }
.hw p { max-width: 72ch; }

/* The colour key (PHY6): each colour has one job in every figure */
.hw-key { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center; font-size: .9rem; color: var(--muted); margin: 14px 0 0; max-width: none; }
.hw-key i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; background: var(--k); margin-right: 5px; vertical-align: -1px; }
.hw-key i.k-steam-used { opacity: .6; }

/* What's on this page: ten cards, the first fold's picture of the page. Each shows a still crop of its own section's
   drawing (made by the script from the live figure), its title and a question. */
.hw-cards ol { list-style: none; margin: 18px 0 8px; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.hw-cards a { display: flex; flex-direction: column; height: 100%; box-sizing: border-box; padding: 10px 12px 12px;
  border: 1px solid var(--rule); border-radius: var(--radius); background: var(--surface); color: var(--fg); text-decoration: none; }
.hw-cards a:hover { border-color: var(--muted); }
.hw-thumb { display: flex; gap: 3px; aspect-ratio: 2.4; margin: 0 0 8px; border-radius: 6px; overflow: hidden; background: var(--sky); }
.hw-thumb svg { flex: 1; min-width: 0; width: 100%; height: 100%; display: block; }
.hw-cards b { font-weight: 700; line-height: 1.25; }
.hw-cn { display: none; }
.hw-hook { color: var(--muted); font-size: .86rem; line-height: 1.35; margin-top: 3px; }
@media (max-width: 560px) {
  .hw-cards ol { grid-template-columns: 1fr 1fr; gap: 8px; }
  .hw-cards a { padding: 8px 10px 10px; }
  .hw-hook { font-size: .8rem; }
}

/* Sections: each starts on its heading, clear of the masthead and (on narrow screens) the jump row */
.hw section { padding-top: 28px; margin-top: 28px; border-top: 1px solid var(--rule); scroll-margin-top: calc(var(--mast-h) + 12px); }
.hw .line-main > section:first-child { border-top: 0; margin-top: 0; }
/* Under 960 px the jump row (about 48 px) pins under the masthead. The section lands with its top 28 px under the
   masthead and its heading clear of the row, and the section before ends above line.js's 80 px line, so the row marks
   the section you jumped to rather than the one before it. */
@media (max-width: 960px) { .hw .line-layout section[id] { scroll-margin-top: calc(var(--mast-h) + 28px); padding-top: 34px; } }
.hw section h2 { margin-top: 0; }
.section-num { color: var(--muted); font-weight: 600; font-size: .85rem; margin: 0 0 2px; }
.hw-next { margin: 18px 0 0; font-size: .92rem; }
.hw-next a { font-weight: 650; text-decoration: none; }
.hw-next a:hover { text-decoration: underline; }

.hw figure { margin: 16px 0 20px; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 12px; }
.hw figure svg { display: block; width: 100%; height: auto; }
.hw figcaption { font-size: .85rem; color: var(--muted); margin-top: 8px; }
.fig-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 8px; }
.fig-title { font-weight: 700; font-size: .98rem; margin-right: auto; }
.btn { font: inherit; font-size: .85rem; padding: 6px 14px; min-height: 40px; border-radius: 999px; border: 1px solid var(--rule); background: var(--bg); color: var(--fg); cursor: pointer; }
.btn:hover { border-color: var(--fg); }
.btn[aria-pressed="true"].toggle { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.hw-seg { display: inline-flex; border: 1px solid var(--rule); border-radius: 999px; overflow: hidden; max-width: 100%; }
.hw-seg button { font: inherit; font-size: .85rem; padding: 6px 12px; min-height: 40px; border: 0; background: var(--bg); color: var(--fg); cursor: pointer; }
.hw-seg button + button { border-left: 1px solid var(--rule); }
.hw-seg button[aria-pressed="true"] { background: var(--fg); color: var(--bg); }
.ctrl { display: flex; flex-wrap: wrap; gap: 10px 22px; align-items: center; font-size: .9rem; margin: 6px 0 4px; }
.ctrl label { display: inline-flex; align-items: center; gap: 8px; }
.ctrl input[type=range] { width: 180px; accent-color: var(--fg); }
.ctrl output { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 4.5em; display: inline-block; }
.hw-approx { font-size: .82rem; color: var(--muted); margin: 4px 0 0; max-width: none; }   /* set HTW2 (NOTE): simplified and approximate, said under each cut-away */
.readout { font-size: .95rem; background: var(--bg); border-radius: 8px; padding: 10px 12px; margin-top: 8px; }
.readout p { margin: .15em 0; max-width: none; }
.readout b { font-variant-numeric: tabular-nums; }
.ok { color: var(--regen); font-weight: 700; } .bad { color: var(--warn-fg); font-weight: 700; } .meh { color: var(--warn-fg); font-weight: 700; }

ol.steps { margin: 6px 0 0; padding-left: 0; list-style: none; counter-reset: s; font-size: .93rem; display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 6px 22px; }
ol.steps li { counter-increment: s; position: relative; padding-left: 30px; }
ol.steps li::before { content: counter(s); position: absolute; left: 0; top: 1px; width: 21px; height: 21px; border-radius: 50%; background: var(--fg); color: var(--bg); font-size: .75rem; font-weight: 700; display: grid; place-items: center; }

.two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.two figure { margin: 0; }
#fig-cant svg { max-width: 520px; margin: 0 auto; }
@media (max-width: 760px) { .two { grid-template-columns: 1fr; } .ctrl input[type=range] { width: 140px; } }

.hw-timeline { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin: 16px 0 0; padding: 0; list-style: none; }
.hw-timeline li { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 10px 12px; font-size: .9rem; border-top: 4px solid var(--c, var(--fg)); }
.hw-timeline .yr { font-weight: 800; font-size: 1.15rem; display: block; font-variant-numeric: tabular-nums; }
.hw-timeline .k { font-size: .72rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 600; }

.bars { display: grid; gap: 10px; margin: 10px 0; }
.bar-row { display: grid; grid-template-columns: 150px 1fr minmax(60px, auto); gap: 10px; align-items: center; font-size: .92rem; }
.bar-track { background: var(--bg); border-radius: 6px; height: 22px; overflow: hidden; border: 1px solid var(--rule); }
.bar-fill { height: 100%; border-radius: 5px 0 0 5px; transition: width .35s ease; }
.bar-val { font-variant-numeric: tabular-nums; font-weight: 700; text-align: right; white-space: nowrap; }
@media (max-width: 560px) { .bar-row { grid-template-columns: 96px 1fr minmax(52px, auto); font-size: .85rem; } }
/* The efficiency chart (set REVB, question 6; Kyle, 8 November 2026: "Fix how diesel-electric goes over 2 lines"): its
   labels share one column as wide as the longest and never wrap; on a phone the bars shrink instead. */
#eff-bars { grid-template-columns: max-content minmax(48px, 1fr) auto; column-gap: 10px; align-items: center; font-size: .92rem; }
#eff-bars .bar-row { display: contents; }
#eff-bars .bar-row > span:first-child { white-space: nowrap; }
@media (max-width: 560px) { #eff-bars { font-size: .85rem; column-gap: 8px; } }
@media (max-width: 359px) { #eff-bars { font-size: .8rem; column-gap: 6px; } }

.hw .table-scroll { overflow-x: auto; }
.hw table { font-size: .92rem; margin: 12px 0; }
.hw table td { white-space: normal; min-width: 11em; }   /* set HTW2 (F3): sentences wrap, rather than run off the side */
#fig-sig svg .lbl, #fig-stop svg .lbl { paint-order: stroke; stroke: var(--surface); stroke-width: 3px; stroke-linejoin: round; }   /* set HTW2 (F1) */
.hw th, .hw td { text-align: left; vertical-align: top; padding: 8px 10px; border-bottom: 1px solid var(--rule); }
.callout { border-left: 4px solid var(--fg); padding: 4px 0 4px 14px; margin: 14px 0; }
.check { font-size: .9rem; }
.check li { margin-bottom: 4px; }

/* On a phone a wide drawing (760 units across) would shrink to under half size, too small to read. Like the strip maps
   (set SB), it keeps a readable size and scrolls sideways, with the thin bar the strip maps fall back to and a hint. */
.fig-hint { display: none; }
@media (max-width: 600px) {
  .fig-scroll { overflow-x: auto; margin: 0 -12px; padding: 0 12px 4px; scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--fg) 34%, transparent) transparent; }
  .hw figure .fig-scroll > svg { width: 680px; max-width: none; }
  .fig-scroll::-webkit-scrollbar { height: 8px; }
  .fig-scroll::-webkit-scrollbar-track { background: color-mix(in srgb, var(--fg) 8%, transparent); border-radius: 99px; }
  .fig-scroll::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--fg) 34%, transparent); border-radius: 99px; }
  .fig-hint { display: block; font-size: .8rem; color: var(--muted); margin: 2px 0 0; }
}

/* The leaves figure's readings, above its drawing */
.lf-meter { display: grid; gap: 6px; margin: 4px 0 10px; }
.lf-meter .bar-row { grid-template-columns: 64px 1fr minmax(64px, auto); }
.lf-meter .bar-fill { transition: none; }
.lf-state { justify-self: start; font-weight: 700; font-size: .85rem; padding: 3px 12px; border-radius: 999px; }
.lf-state.rolling { background: color-mix(in srgb, var(--regen) 16%, transparent); color: var(--regen); }
.lf-state.sliding { background: var(--warn-bg); color: var(--warn-fg); }
.lf-state.stopped { background: color-mix(in srgb, var(--muted) 16%, transparent); color: var(--muted); }

/* set HTW2: the figures' texture layer (.tx, hidden by Shading off): the haze, the rails' bright edge */
:root { --tx-haze: #FFFFFF; --tx-sky: #7FA3C8; --tx-edge: rgba(255, 255, 255, .55); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --tx-haze: #2B3440; --tx-sky: #000000; --tx-edge: rgba(255, 255, 255, .28); } }
:root[data-theme="dark"] { --tx-haze: #2B3440; --tx-sky: #000000; --tx-edge: rgba(255, 255, 255, .28); }
.hw figure svg .tx { pointer-events: none; }
/* SVG parts */
.ws-wheel { fill: var(--metal2); stroke: var(--shell); stroke-width: 1.5; }
.hw-credit { font-size: 11px; fill: var(--muted); opacity: .8; }
svg text { font-family: var(--font); }
.sky { fill: var(--sky); }
.ground { fill: var(--ground); }
.ballast { fill: var(--ballast); }
.sleeper { fill: var(--sleeper); }
.rail { stroke: var(--rail); stroke-width: 4; }
.railhead { fill: var(--rail); }
.shell { fill: var(--shell); }
.dark { fill: var(--dark); }
.metal { fill: var(--metal); }
.metal2 { fill: var(--metal2); }
.wheel { fill: var(--wheel); stroke: var(--spoke); stroke-width: 1.5; }
.spoke { stroke: var(--spoke); stroke-width: 2; }
.hub { fill: var(--spoke); }
.h2o { fill: var(--water); }
.steamspace { fill: var(--steam); }
.firebox { fill: #2A1408; }
.fire { fill: var(--fire); }
.fire2 { fill: var(--fire2); }
.tube { stroke: var(--metal); stroke-width: 5; stroke-linecap: round; opacity: 0.7; }
.gas { fill: var(--fire); }
.bubble { fill: none; stroke: #fff; stroke-width: 1.2; opacity: 0.8; }
.pipe-live { fill: none; stroke: var(--live); stroke-width: 5; stroke-dasharray: 8 6; stroke-linecap: round; }
.pipe-exh { fill: none; stroke: var(--exh); stroke-width: 5; stroke-dasharray: 8 6; stroke-linecap: round; }
.cyl { fill: var(--metal2); stroke: var(--shell); stroke-width: 2; }
.ch-live { fill: var(--live); opacity: 0.85; }
.ch-exh { fill: var(--exh); opacity: 0.6; }
.piston { fill: var(--dark); }
.rod { stroke: var(--metal); stroke-width: 6; stroke-linecap: round; }
.rod-thin { stroke: var(--metal); stroke-width: 3; }
.pin { fill: var(--fire2); stroke: var(--dark); stroke-width: 1; }
.puff { fill: var(--exh); }
.puff-steam { fill: #E9EDF1; stroke: var(--exh); stroke-width: 0.6; }
.badge circle { fill: var(--fg); }
.badge text { fill: var(--bg); font-size: 12px; font-weight: 700; text-anchor: middle; dominant-baseline: central; }
.glass { fill: var(--glass); }
.body { fill: var(--body); stroke: var(--body-line); stroke-width: 2; }
.engine { fill: var(--metal2); stroke: var(--shell); stroke-width: 2; }
.bore { fill: var(--surface); stroke: var(--shell); stroke-width: 1.5; }
.alt { fill: var(--metal2); stroke: var(--shell); stroke-width: 2; }
.eqbox { fill: var(--metal2); stroke: var(--shell); stroke-width: 2; }
.tank { fill: var(--metal); stroke: var(--shell); stroke-width: 1.5; }
.cable { fill: none; stroke: var(--amp); stroke-width: 2.5; opacity: 0.55; }
.cable-fuel { fill: none; stroke: #8A6A2A; stroke-width: 3; opacity: 0.6; }
.amp { fill: var(--amp); }
.amp.regen { fill: var(--regen); }
.fuel { fill: #B5862E; }
.wire { stroke: var(--wire); stroke-width: 2; fill: none; }
.wire-thin { stroke: var(--wire); stroke-width: 1; fill: none; opacity: 0.7; }
.mast { stroke: var(--metal); stroke-width: 6; }
.lbl { font-size: 12px; fill: var(--muted); }
.lbl-b { font-size: 13px; fill: var(--fg); font-weight: 700; }
.motor { fill: var(--metal2); stroke: var(--shell); stroke-width: 1.5; }
.flash { fill: var(--fire2); }
.contact { fill: var(--fg); }
.trace { fill: none; stroke: var(--blue); stroke-width: 2.5; }
.centre { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 4; }
.strap { stroke: var(--fg); stroke-width: 2; }
.plumb { stroke: var(--muted); stroke-width: 1.2; stroke-dasharray: 3 3; }
.arrow { stroke: var(--blue); stroke-width: 2.5; fill: none; marker-end: url(#arrowhead); }
.lane { stroke: var(--rule); stroke-width: 6; stroke-linecap: round; }
.axtick { stroke: var(--muted); stroke-width: 1; }
.stopline { stroke: var(--fg); stroke-width: 2; stroke-dasharray: 4 3; }
.veh-car { fill: var(--blue); }
.veh-pax { fill: var(--fg); }
.veh-frt { fill: var(--metal); stroke: var(--shell); stroke-width: 1; }
.veh-wagon { fill: none; stroke: var(--metal); stroke-width: 1.2; }
.veh-wheel { fill: var(--fg); }
.rail-run { stroke: var(--rail); stroke-width: 2; }
.sigline { stroke: var(--blue); stroke-width: 1.5; stroke-dasharray: 2 3; }

/* Set HTW (Kyle, 22 November 2026) ------------------------------------------------------------------------------------- */
/* HTW7: the cards in three chapters */
.hw-chap + .hw-chap { margin-top: 14px; }
.hw-chap-h { font-weight: 700; margin: 0 0 6px; max-width: none; }
.hw-chap-h small { font-weight: 500; color: var(--muted); font-size: .85rem; margin-left: 6px; }
.hw-cards .hw-chap ol { margin: 0; }
.hw-new { font-size: .68rem; font-weight: 800; letter-spacing: .05em; color: var(--regen); text-transform: uppercase; }
.eyebrow a { color: inherit; font-weight: 700; }
/* HTW6: the trains on this site that work each way, at one scale */
.hw-fleet { margin: 18px 0 4px; }
.hw-fleet h3 { font-size: 1rem; margin: 0 0 4px; }
.hw-fleet .fleet-h { font-size: .88rem; color: var(--muted); font-weight: 600; margin: 10px 0 4px; }
.hw-fleet ul { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.hw-fleet a { display: flex; flex-direction: column; gap: 3px; height: 100%; box-sizing: border-box; padding: 9px 11px; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--surface); color: var(--fg); text-decoration: none; }
.hw-fleet a:hover { border-color: var(--muted); }
.hw-fleet .pic { height: 30px; display: flex; align-items: flex-end; overflow: hidden; }
.hw-fleet img { display: block; width: var(--w); height: auto; max-width: none; }
.hw-fleet b { font-size: .92rem; }
.hw-fleet small { color: var(--muted); font-size: .8rem; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.hw-fleet .scale-bar { display: flex; align-items: center; gap: 8px; font-size: .78rem; color: var(--muted); margin: 6px 0 0; }
.hw-fleet .scale-bar i { display: inline-block; width: var(--w); height: 6px; border: 1px solid var(--muted); border-top: 0; }
@media (max-width: 560px) {
  .hw-fleet ul { grid-template-columns: 1fr 1fr; }
  .hw-fleet img, .hw-fleet .scale-bar i { width: calc(var(--w) * .67); }
}
/* HTW3: the signals' colours (the real ones, outside the page's colour roles), dimensions and curve */
:root { --sig-r: #D62B1E; --sig-y: #F2B200; --sig-g: #13A452; --sig-off: #3A3E45; }
/* set HTW2: the signal head's own colours, the home page scene's (set HSR), so both pages draw one signal */
:root { --sig-head: #1E2023; --sig-side: #3B3F45; --sig-lit: #6A7078; --sig-hood: #4A4E55; --sig-edge: #E9E9E6; --sig-post: #8C9097; --sig-post-lt: #B3B7BD; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --sig-head: #0B0C0E; --sig-side: #26292E; --sig-lit: #43474E; --sig-hood: #33363C; --sig-edge: #4A4E55; --sig-post: #5E636B; --sig-post-lt: #767B83; } }
:root[data-theme="dark"] { --sig-head: #0B0C0E; --sig-side: #26292E; --sig-lit: #43474E; --sig-hood: #33363C; --sig-edge: #4A4E55; --sig-post: #5E636B; --sig-post-lt: #767B83; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --sig-r: #FF4A3D; --sig-y: #FFC83A; --sig-g: #2FD07A; --sig-off: #262A30; } }
:root[data-theme="dark"] { --sig-r: #FF4A3D; --sig-y: #FFC83A; --sig-g: #2FD07A; --sig-off: #262A30; }
.dim { stroke: var(--muted); stroke-width: 1; }
.grid { stroke: var(--rule); stroke-width: 1; }
.curve { fill: none; stroke: var(--blue); stroke-width: 3; }
.curve-ghost { fill: none; stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 5 4; }
.hw-status { font-size: .9rem; font-weight: 650; min-height: 1.5em; margin: 6px 0 0; max-width: none; }
/* HTW5 D1: the diesel's engine and train bars */
.lf-meter.htw-ds .bar-row { grid-template-columns: 64px 1fr minmax(110px, auto); }
