/* Layout: an airfield operations manual. Sticky masthead, a rail of taxiway-sign
   module markers, one lesson on stage at a time with sign-style wayfinding. */
:root {
  --bg: #eceff2;
  --surface: #fbfcfd;
  --tint: #e1e7ed;
  --zebra: #f2f5f7;
  --ink: #15202a;
  --muted: #46525d;
  --rule: #cdd5dc;
  --accent: #8a5d00;
  --accent-fill: #ffc629;
  --ok: #1d7a44;
  --warn: #9c5c00;
  --bad: #b3261e;

  /* Fixed-colour worlds: airfield signs and the night scene look the same in both themes */
  --sign-black: #111417;
  --sign-yellow: #ffcc00;
  --sign-red: #c8102e;
  --sign-white: #ffffff;
  --night: #09121a;
  --night-2: #142231;
  --night-line: #2a3b4c;
  --night-ink: #d5dee6;
  --night-muted: #93a3b1;
  --pavement: #26323d;
  --grass: #0d1a15;
  --l-white: #fff6dc;
  --l-yellow: #ffd23f;
  --l-red: #ff4b4b;
  --l-green: #3ddc84;
  --l-blue: #4f8dff;
  --c-a: #ffae00;
  --c-b: #2fc6f0;
  --c-s: #c99bff;

  --f-display: "Barlow Condensed", "Heebo", "Arial Narrow", "Roboto Condensed", sans-serif;
  --f-body: "IBM Plex Sans", "IBM Plex Sans Hebrew", "Segoe UI", system-ui, sans-serif;
  --f-mono: "IBM Plex Mono", "IBM Plex Sans Hebrew", ui-monospace, "SFMono-Regular", Menlo, monospace;

  /* Type scale: 15 / 17 / 20 / 26 / 36 / 44 px. Nothing on the page is set below 14px. */
  --step--2: 0.875rem;
  --step--1: 0.9375rem;
  --step-0: 1.0625rem;
  --step-1: 1.25rem;
  --step-2: 1.625rem;
  --step-3: 2.25rem;
  --step-4: 2.75rem;
  --lh: 1.65;

  /* Spacing scale */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 40px;
  --sp-7: 64px;

  --measure: 66ch;
  --radius: 6px;
  --tap: 44px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b131a;
    --surface: #111c26;
    --tint: #1a2836;
    --zebra: #142130;
    --ink: #e6ecf1;
    --muted: #a7b5c2;
    --rule: #2a3a48;
    --accent: #ffc629;
    --ok: #4cc47d;
    --warn: #f2a93b;
    --bad: #ff6b5e;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b131a;
  --surface: #111c26;
  --tint: #1a2836;
  --zebra: #142130;
  --ink: #e6ecf1;
  --muted: #a7b5c2;
  --rule: #2a3a48;
  --accent: #ffc629;
  --ok: #4cc47d;
  --warn: #f2a93b;
  --bad: #ff6b5e;
  color-scheme: dark;
}
/* Hebrew reads smaller than Latin at the same size, so it gets a larger scale and looser lines */
:root[dir="rtl"] {
  --step--2: 0.9375rem;
  --step--1: 1rem;
  --step-0: 1.125rem;
  --step-1: 1.3125rem;
  --lh: 1.75;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 150px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: var(--step-0);
  line-height: var(--lh);
}
body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto;
  height: env(safe-area-inset-top, 0px);
  z-index: 10;
  background: var(--sign-black);
}
a { color: var(--accent); text-underline-offset: 3px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.masthead :focus-visible, .scene :focus-visible, .sim-wrap :focus-visible { outline-color: var(--sign-yellow); }
h1, h2, h3, h4 { font-family: var(--f-display); text-wrap: balance; margin: 0; }
h2 { font-size: var(--step-4); font-weight: 700; line-height: 1.05; letter-spacing: 0.005em; }
h3 { font-size: var(--step-2); font-weight: 700; line-height: 1.15; letter-spacing: 0.01em; }
h4 { font-size: var(--step-1); font-weight: 600; line-height: 1.25; letter-spacing: 0.01em; }
:root[dir="rtl"] h2, :root[dir="rtl"] h3, :root[dir="rtl"] h4 { letter-spacing: 0; line-height: 1.25; font-weight: 700; }
p { margin: 0; }
code, .mono { font-family: var(--f-mono); font-size: 0.92em; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: var(--step--1); }

.skip {
  position: absolute;
  inset-inline-start: 12px;
  top: -60px;
  z-index: 50;
  background: var(--sign-yellow);
  color: var(--sign-black);
  font-weight: 600;
  padding: 10px 16px;
  border-radius: var(--radius);
}
.skip:focus { top: calc(env(safe-area-inset-top, 0px) + 12px); }

/* Masthead */
.masthead {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 20;
  background: var(--sign-black);
  color: var(--sign-yellow);
  border-bottom: 3px solid var(--sign-yellow);
}
.masthead-inner {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding-block: 10px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.brand {
  min-width: 0;
  font-family: var(--f-display);
  font-weight: 700;
  font-size: 1.625rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  line-height: 1;
}
.brand small {
  display: block;
  font-family: var(--f-body);
  font-weight: 400;
  font-size: var(--step--2);
  letter-spacing: 0.02em;
  color: var(--sign-white);
  margin-top: 5px;
  text-transform: none;
}
.masthead .spacer { flex: 1; }
.masthead .std {
  font-family: var(--f-mono);
  font-size: var(--step--2);
  line-height: 1.4;
  color: #c9d1d8;
  text-align: end;
}

/* Shell */
.shell {
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr);
  gap: var(--sp-6);
  max-width: 1360px;
  margin: 0 auto;
  padding-block: var(--sp-6) var(--sp-7);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

/* Rail: module signs, with the active module's lessons opened beneath it */
.rail {
  position: sticky;
  top: calc(env(safe-area-inset-top, 0px) + 84px);
  align-self: start;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.rail-label {
  font-size: var(--step--2);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: var(--sp-2);
}
.rail a {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: 48px;
  padding: 4px 8px;
  border-radius: var(--radius);
  color: var(--ink);
  text-decoration: none;
  font-weight: 500;
  line-height: 1.25;
}
.rail a:hover { background: var(--tint); }
.rail .chip {
  flex: none;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  font-family: var(--f-display);
  font-weight: 700;
  font-size: 1.375rem;
  background: var(--sign-yellow);
  color: var(--sign-black);
  border-radius: 3px;
}
.rail > a[aria-current] { background: var(--tint); font-weight: 600; }
.rail > a[aria-current] .chip {
  background: var(--sign-black);
  color: var(--sign-yellow);
  box-shadow: inset 0 0 0 2px var(--sign-black), inset 0 0 0 4px var(--sign-yellow);
}
.sublessons {
  list-style: none;
  margin: 2px 0 8px;
  padding: 0;
  padding-inline-start: 22px;
  border-inline-start: 2px dashed var(--rule);
  margin-inline-start: 25px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sublessons a { min-height: 44px; font-weight: 400; font-size: var(--step--1); }
.subchip {
  flex: none;
  min-width: 34px;
  padding: 2px 5px;
  text-align: center;
  font-family: var(--f-display);
  font-weight: 700;
  font-size: 1rem;
  line-height: 1.3;
  border-radius: 2px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: inset 0 0 0 1.5px var(--rule);
}
.sublessons a.seen .subchip { background: var(--tint); }
.sublessons a.seen .subchip::after { content: " ✓"; font-size: 0.8em; color: var(--ok); }
.sublessons a[aria-current] { background: var(--tint); font-weight: 600; }
.sublessons a[aria-current] .subchip { background: var(--sign-yellow); color: var(--sign-black); box-shadow: none; }
.sublessons a[aria-current] .subchip::after { content: ""; }
.rail-note { margin-top: var(--sp-4); font-size: var(--step--2); color: var(--muted); line-height: 1.5; }

/* Lesson stage */
main { min-width: 0; outline: none; }
.module { display: flex; flex-direction: column; gap: var(--sp-5); }
.lesson { display: flex; flex-direction: column; gap: var(--sp-5); min-width: 0; }
.lesson > h3 { font-size: var(--step-3); }
.lesson > .module-head + h3 { margin-top: var(--sp-4); font-size: var(--step-2); }
.module-head { display: flex; flex-direction: column; gap: var(--sp-4); }
.lede { font-size: var(--step-1); line-height: 1.55; max-width: var(--measure); }
.lede-small { max-width: var(--measure); }
.prose { display: flex; flex-direction: column; gap: var(--sp-4); max-width: var(--measure); }
.prose ul, .prose ol, ol.prose { margin: 0; padding-inline-start: 1.3em; display: flex; flex-direction: column; gap: var(--sp-3); }
.narrow { max-width: 640px; display: flex; flex-direction: column; gap: var(--sp-3); }
.section { display: flex; flex-direction: column; gap: var(--sp-3); min-width: 0; }

/* Numbered steps read like a checklist */
ol.steps { list-style: none; padding: 0; counter-reset: step; gap: var(--sp-4); }
ol.steps li { counter-increment: step; position: relative; padding-inline-start: 52px; min-height: 38px; }
ol.steps li::before {
  content: counter(step);
  position: absolute;
  inset-inline-start: 0;
  top: 0;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  font-family: var(--f-display);
  font-weight: 700;
  font-size: 1.25rem;
  background: var(--sign-black);
  color: var(--sign-yellow);
  border-radius: 3px;
  margin-top: 1px;
}

/* Wayfinding: sign breadcrumb, progress line, direction-sign pager */
.crumb { display: flex; align-items: center; gap: var(--sp-4); flex-wrap: wrap; }
.sign {
  display: inline-flex;
  align-items: stretch;
  font-family: var(--f-display);
  font-weight: 700;
  font-size: 1.125rem;
  letter-spacing: 0.04em;
  line-height: 1;
  border-radius: 2px;
  overflow: hidden;
  text-decoration: none;
}
.sign span { padding: 6px 10px; display: grid; place-items: center; }
.sign .loc { background: var(--sign-black); color: var(--sign-yellow); box-shadow: inset 0 0 0 2px var(--sign-yellow); }
.sign .dir { background: var(--sign-yellow); color: var(--sign-black); }
.sign .mand { background: var(--sign-red); color: var(--sign-white); }
.crumb-sign { font-size: 1.375rem; }
.crumb-sign span { min-width: 40px; padding: 8px 12px; }
.crumb-text { display: flex; flex-direction: column; line-height: 1.3; }
.crumb-module { font-weight: 600; }
.crumb-count { font-size: var(--step--1); color: var(--muted); }
.crumb-bar { height: 4px; background: var(--tint); border-radius: 2px; overflow: hidden; margin-top: calc(-1 * var(--sp-2)); }
.crumb-bar i { display: block; height: 100%; background: var(--accent-fill); }

.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-4);
  margin-top: var(--sp-5);
  padding-top: var(--sp-5);
  border-top: 1px solid var(--rule);
}
.pg {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: 64px;
  padding: 10px 16px;
  border-radius: 4px;
  background: var(--sign-yellow);
  color: var(--sign-black);
  text-decoration: none;
  min-width: 0;
}
.pg:hover { filter: brightness(1.05); }
.pg.next { justify-content: flex-end; text-align: end; grid-column: 2; }
.pg.next .arr { order: 2; }
.pg .arr { font-family: var(--f-display); font-weight: 700; font-size: 2rem; line-height: 1; }
:root[dir="rtl"] .pg .arr { transform: scaleX(-1); }
.pg-text { display: flex; flex-direction: column; min-width: 0; }
.pg-label { font-size: var(--step--2); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
:root[dir="rtl"] .pg-label { text-transform: none; letter-spacing: 0; }
.pg-title { font-family: var(--f-display); font-weight: 600; font-size: 1.3rem; line-height: 1.2; }
.pg-title b { font-weight: 700; margin-inline-end: 4px; }
.resume { max-width: 460px; justify-content: flex-start; text-align: start; }
.resume .arr { order: 2; margin-inline-start: auto; }

/* Panels and grids */
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-5); }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--sp-5); }
.panel {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  min-width: 0;
}
.panel.narrow { max-width: 760px; }
.panel h4 { font-size: 1.375rem; }
.panel .small { font-size: var(--step-0); }
.track { gap: var(--sp-3); }
.track .who, .tag {
  font-size: var(--step--2);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
}
:root[dir="rtl"] .track .who, :root[dir="rtl"] .tag { text-transform: none; letter-spacing: 0; }
.track ol { margin: 0; padding-inline-start: 1.2em; display: flex; flex-direction: column; gap: var(--sp-2); }
.try { border-inline-start: 6px solid var(--accent-fill); max-width: 820px; }
.try ol { margin: 0; padding-inline-start: 1.3em; display: flex; flex-direction: column; gap: var(--sp-2); }

details.more { border: 1px solid var(--rule); border-radius: var(--radius); background: var(--surface); max-width: 820px; }
details.more summary {
  cursor: pointer;
  min-height: 52px;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  font-weight: 600;
  list-style: none;
}
details.more summary::-webkit-details-marker { display: none; }
details.more summary::before { content: "▸"; color: var(--accent); transition: transform 0.15s; }
:root[dir="rtl"] details.more summary::before { transform: scaleX(-1); }
details.more[open] summary::before { transform: rotate(90deg); }
details.more > div { padding: 0 18px 18px; }

/* Callouts */
.callout {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: var(--sp-4);
  align-items: start;
  padding: 18px 20px;
  border: 2px solid color-mix(in srgb, var(--bad) 55%, var(--rule));
  border-radius: var(--radius);
  background: var(--surface);
  max-width: 820px;
}
.callout .sign { margin-top: 3px; }
.callout p + p { margin-top: var(--sp-3); }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: var(--step-0); line-height: 1.5; }
th, td { text-align: start; padding: 10px 14px; border-bottom: 1px solid var(--rule); vertical-align: top; }
th { font-weight: 600; background: var(--tint); }
thead th { white-space: nowrap; }
tbody tr:nth-child(even) td { background: var(--zebra); }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; }
.panel table th { white-space: normal; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-inline-end: 8px; vertical-align: -1px; box-shadow: 0 0 0 1px var(--muted); }

/* Controls */
.controls { display: flex; flex-wrap: wrap; gap: var(--sp-3) var(--sp-5); align-items: center; }
.ctl-label { max-width: 100%; min-width: 0; font-size: var(--step--1); color: var(--muted); display: inline-flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-3); }
.seg { display: inline-flex; min-width: 0; max-width: 100%; overflow-x: auto; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--surface); }
.seg button {
  font: inherit;
  font-size: var(--step--1);
  font-weight: 500;
  min-height: var(--tap);
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 8px 16px;
  cursor: pointer;
  white-space: nowrap;
}
.seg button + button { border-inline-start: 1px solid var(--rule); }
.seg button[aria-pressed="true"] { background: var(--sign-black); color: var(--sign-yellow); }
.btn {
  font: inherit;
  font-size: var(--step--1);
  font-weight: 500;
  min-height: var(--tap);
  border: 1px solid var(--rule);
  background: var(--surface);
  color: var(--ink);
  padding: 8px 16px;
  border-radius: var(--radius);
  cursor: pointer;
}
.btn:hover { background: var(--tint); }
.btn.primary { background: var(--accent-fill); color: var(--sign-black); border-color: var(--accent-fill); font-weight: 600; }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, var(--rule)); }
.btn[aria-pressed="true"] { background: var(--sign-black); color: var(--sign-yellow); border-color: var(--sign-black); }
label.field { display: flex; flex-direction: column; gap: 6px; font-size: var(--step--1); font-weight: 500; color: var(--ink); min-width: 0; }
label.field.search { max-width: 460px; }
input[type="number"], input[type="text"], input[type="date"], input[type="search"], select {
  font: inherit;
  font-size: max(16px, var(--step-0));
  font-weight: 400;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--muted) 55%, var(--rule));
  border-radius: 4px;
  padding: 9px 12px;
  min-height: var(--tap);
  min-width: 0;
  width: 100%;
}
input[type="number"] { font-variant-numeric: tabular-nums; }
input[type="range"] { accent-color: var(--accent-fill); min-height: var(--tap); }

/* Night scene (airfield map) */
.scene {
  background: var(--night);
  border-radius: var(--radius);
  overflow: hidden;
  color: var(--night-ink);
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.scene-bar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3) var(--sp-5);
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--night-2);
}
.scene-bar .ctl-label { color: var(--night-muted); }
.scene .seg { background: var(--night-2); border-color: var(--night-line); }
.scene .seg button { color: var(--night-ink); }
.scene .seg button + button { border-inline-start-color: var(--night-line); }
.scene .seg button[aria-pressed="true"] { background: var(--sign-yellow); color: var(--sign-black); }
.scene .btn { background: var(--night-2); color: var(--night-ink); border-color: var(--night-line); }
.scene .btn[aria-pressed="true"] { background: var(--sign-yellow); color: var(--sign-black); border-color: var(--sign-yellow); }
.scene-svg { overflow-x: auto; direction: ltr; }
.scene-svg svg { display: block; width: 100%; min-width: 760px; height: auto; }
.scene-legend { display: flex; flex-wrap: wrap; gap: var(--sp-2); padding: 14px 16px; border-top: 1px solid var(--night-2); }
.scene-legend button, .scene-legend .pill {
  font: inherit;
  font-size: var(--step--1);
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: var(--tap);
  border: 1px solid var(--night-line);
  background: var(--night-2);
  color: var(--night-ink);
  border-radius: 999px;
  padding: 6px 14px 6px 10px;
  cursor: pointer;
}
.scene-legend .pill { cursor: default; background: transparent; }
.scene-legend button[aria-pressed="true"] { border-color: var(--sign-yellow); color: var(--sign-yellow); }
.scene-legend .dot { width: 11px; height: 11px; border-radius: 50%; flex: none; }
.scroll-hint { display: none; font-size: var(--step--2); color: var(--muted); }
.scene .scroll-hint { color: var(--night-muted); padding: 8px 16px 0; }
.light { cursor: pointer; }
.light-group.dim { opacity: 0.18; }
.rgl-a { animation: rgl 1.4s steps(1) infinite; }
.rgl-b { animation: rgl 1.4s steps(1) infinite 0.7s; }
@keyframes rgl { 0% { opacity: 1; } 50% { opacity: 0.08; } }

.map-below { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: var(--sp-5); align-items: start; }
.info-card h4 { font-size: var(--step-2); }
.info-card dl { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--sp-2) var(--sp-4); margin: 0; }
.info-card dt { color: var(--muted); font-weight: 500; }
.info-card dd { margin: 0; }
.info-card .ref { font-family: var(--f-mono); font-size: var(--step--2); color: var(--muted); }

.papi { display: flex; gap: 12px; padding: 14px; background: var(--night); border-radius: var(--radius); justify-content: center; direction: ltr; }
.papi i { width: 30px; height: 30px; border-radius: 50%; display: block; }

/* Readouts */
.readouts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--sp-3); }
.readout {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.readout .k { font-size: var(--step--2); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
:root[dir="rtl"] .readout .k { text-transform: none; letter-spacing: 0; }
.readout .v { font-family: var(--f-mono); font-size: 1.5rem; font-weight: 500; font-variant-numeric: tabular-nums; line-height: 1.25; }
.readout .v small { font-size: 0.9rem; color: var(--muted); margin-inline-start: 4px; }
.alarms { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--step--1);
  font-weight: 500;
  border-radius: 999px;
  padding: 4px 12px;
  border: 1px solid var(--rule);
  color: var(--muted);
  background: var(--surface);
}
.pill::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--rule); }
.scene-legend .pill::before { display: none; }
.pill.on-ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 50%, var(--rule)); }
.pill.on-ok::before { background: var(--ok); }
.pill.on-warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 50%, var(--rule)); }
.pill.on-warn::before { background: var(--warn); }
.pill.on-bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 50%, var(--rule)); }
.pill.on-bad::before { background: var(--bad); }

.sim-wrap { overflow-x: auto; background: var(--night); border-radius: var(--radius); direction: ltr; }
.sim-wrap svg { display: block; width: 100%; min-width: 680px; height: auto; }
.log {
  font-family: var(--f-mono);
  font-size: var(--step--2);
  line-height: 1.6;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 14px 16px;
  max-height: 240px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  max-width: 900px;
}
:root[dir="rtl"] .log { font-family: var(--f-body); font-size: var(--step--1); }
.log p { white-space: pre-wrap; }
.log p:first-child { color: var(--ink); }
.log p:not(:first-child) { color: var(--muted); }

/* Calculators */
.calc-layout { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(300px, 1fr); gap: var(--sp-5); align-items: start; }
.calc-rows { display: flex; flex-direction: column; gap: var(--sp-3); }
.calc-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--sp-3);
  align-items: end;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}
.calc-row .desc { grid-column: 1 / -1; }
.calc-row .x { grid-column: 1 / -1; justify-self: start; color: var(--bad); }
.result { position: sticky; top: 100px; }
.result-table td { padding: 8px 10px; }
.result-table td:first-child { color: var(--muted); }
.result-big { font-family: var(--f-display); font-size: var(--step-4); font-weight: 700; line-height: 1; }
.note-list { margin: 0; padding-inline-start: 1.2em; display: flex; flex-direction: column; gap: var(--sp-2); }
.note-list .bad { color: var(--bad); }
.note-list .warn { color: var(--warn); }
.chart { direction: ltr; }
.chart svg { display: block; width: 100%; height: auto; }
.entry { max-width: 560px; }

/* Scenarios, quiz, glossary */
.scenario-pick { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.step-card { display: flex; flex-direction: column; gap: var(--sp-4); max-width: 820px; }
.step-card h4 { font-size: var(--step-2); }
.choices { display: flex; flex-direction: column; gap: var(--sp-3); }
.choice {
  font: inherit;
  text-align: start;
  border: 1px solid var(--rule);
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--radius);
  min-height: 56px;
  padding: 12px 14px;
  cursor: pointer;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: var(--sp-3);
  align-items: center;
}
.choice:hover:not([disabled]) { background: var(--tint); }
.choice .letter {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 3px;
  font-family: var(--f-display);
  font-weight: 700;
  font-size: 1.125rem;
  background: var(--tint);
}
.choice.right { border-color: var(--ok); border-width: 2px; }
.choice.right .letter { background: var(--ok); color: var(--surface); }
.choice.wrong { border-color: var(--bad); border-width: 2px; }
.choice.wrong .letter { background: var(--bad); color: var(--surface); }
.choice[disabled] { cursor: default; }
.feedback { padding: 14px 16px; border-radius: var(--radius); background: var(--tint); }
.feedback strong { display: block; margin-bottom: 4px; }
.progress { height: 6px; background: var(--tint); border-radius: 3px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--accent-fill); }

.gloss { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 var(--sp-6); margin: 0; }
.gloss div { padding: 14px 0; border-bottom: 1px solid var(--rule); min-width: 0; }
.gloss dt { font-weight: 600; font-size: var(--step-1); font-family: var(--f-display); }
.gloss dd { margin: 4px 0 0; color: var(--ink); }

.foot { font-size: var(--step--1); color: var(--muted); max-width: var(--measure); border-top: 1px solid var(--rule); padding-top: var(--sp-4); margin-top: var(--sp-6); }

.flow { animation: flow 1.6s linear infinite; }
@keyframes flow { to { stroke-dashoffset: -40; } }
@media (prefers-reduced-motion: reduce) {
  .rgl-a, .rgl-b, .flow { animation: none; }
  details.more summary::before { transition: none; }
}

/* Language switch on the black masthead */
.masthead .lang { flex: none; background: transparent; border-color: #3a3f44; }
.masthead .lang button { color: var(--sign-white); font-size: var(--step--2); min-height: 40px; padding: 6px 14px; }
.masthead .lang button + button { border-inline-start-color: #3a3f44; }
.masthead .lang button[aria-pressed="true"] { background: var(--sign-yellow); color: var(--sign-black); }

:root[dir="rtl"] .brand { letter-spacing: 0; }

@media (max-width: 1240px) {
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .map-below { grid-template-columns: minmax(0, 1fr); }
  .calc-layout { grid-template-columns: minmax(0, 1fr); }
  .result { position: static; }
}
@media (max-width: 860px) {
  :root { --step-3: 1.875rem; --step-4: 2.125rem; }
  html { scroll-padding-top: 170px; }
  .shell { grid-template-columns: minmax(0, 1fr); gap: var(--sp-5); padding-top: 0; }
  .rail {
    position: sticky;
    top: calc(env(safe-area-inset-top, 0px) + 56px);
    z-index: 15;
    max-height: none;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x proximity;
    background: var(--bg);
    padding-block: 10px;
    border-bottom: 1px solid var(--rule);
    -webkit-mask-image: linear-gradient(to right, transparent, #000 12px, #000 calc(100% - 28px), transparent);
            mask-image: linear-gradient(to right, transparent, #000 12px, #000 calc(100% - 28px), transparent);
  }
  .rail a { flex: none; scroll-snap-align: center; padding: 4px; }
  .rail-label, .rail-note, .sublessons { display: none; }
  .rail .label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .rail > a[aria-current] { padding-inline-end: 12px; }
  .rail > a[aria-current] .label { position: static; width: auto; height: auto; clip-path: none; }
  .masthead .std, .brand small { display: none; }
  .brand { font-size: 1.375rem; }
  .grid-2, .grid-3, .gloss { grid-template-columns: minmax(0, 1fr); }
  .pager { grid-template-columns: minmax(0, 1fr); }
  .pg.next { grid-column: auto; }
  .pg.prev { order: 2; }
  .scroll-hint { display: block; }
  .scene-svg svg { min-width: 900px; }
  .readouts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .calc-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .callout { grid-template-columns: minmax(0, 1fr); }

  /* Wide tables become stacked cards */
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack th, table.stack td { display: block; width: 100%; }
  table.stack tr { padding: 12px 14px; border-bottom: 1px solid var(--rule); }
  table.stack tbody tr:nth-child(even) td { background: transparent; }
  table.stack th, table.stack td { padding: 2px 0; border: 0; background: transparent; }
  table.stack td:first-child, table.stack th { font-weight: 600; font-size: var(--step-1); font-family: var(--f-display); }
  table.stack td[data-label]::before { content: attr(data-label); display: block; font-size: var(--step--2); font-weight: 600; color: var(--muted); margin-top: 6px; }
}
