/* Tokens and base rules from lab/index.html, so the module pages look like the lab. */
:root {
  --bg: #e8edf0;
  --panel: #f7f9fa;
  --panel-2: #dde5ea;
  --ink: #12202a;
  --muted: #546778;
  --line: #c2cdd5;
  --copper: #b0521c;
  --copper-ink: #8c3d0f;
  --copper-soft: #f3dccc;
  --teal: #0b7a74;
  --amber: #a87200;
  --magenta: #a52b70;
  --good: #2c8439;
  --bad: #be3a2c;
  --code-bg: #dfe7ec;
  --scope: #0f1a20;
  --scope-ink: #cfe3e0;
  /* instrument screens are dark in both themes: their traces never change */
  --tr-grid: #1e3039;
  --tr-dim: #6f8a93;
  --tr-1: #4fd6c9;
  --tr-2: #f2bd45;
  --tr-3: #ee6fac;
  --tr-4: #f08d50;
  --tr-5: #9fb7ff;
  /* schematic sheets (Logisim-style benches) */
  --sheet: #fbfcfc; --sheet-grid: #d9e1e6; --sheet-ink: #18252e; --sheet-mute: #66808f; --sheet-hi: #fff4ea;
  --w1: #18b418; --w0: #0f5d14; --wbus: #2b3c47; --wact: #d0661b; --wval-bg: #18252e; --wval-ink: #ffffff;
  --led-on: #e8322a; --led-off: #5d2420;
  --f-display: "Archivo", "Arial Narrow", system-ui, sans-serif;
  --f-body: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
  --f-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --f-pixel: "Silkscreen", "JetBrains Mono", ui-monospace, monospace;
  --radius: 6px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c141a; --panel: #121d25; --panel-2: #1a2a35; --ink: #d8e2e9; --muted: #8ea1b0;
    --line: #283d4a; --copper: #e2834a; --copper-ink: #f2a77a; --copper-soft: #3a2518;
    --teal: #3fc3ba; --amber: #e9b23c; --magenta: #e463a1; --good: #5cc26b; --bad: #ef6c5f;
    --code-bg: #091015; --scope: #070d11; --scope-ink: #cfe3e0; color-scheme: dark;
    --sheet: #0f181e; --sheet-grid: #1f2f38; --sheet-ink: #d6e0e7; --sheet-mute: #8aa0ae; --sheet-hi: #2a1d14;
    --w1: #4be04b; --w0: #22702a; --wbus: #8ca2b0; --wact: #f3974f; --wval-bg: #e6edf1; --wval-ink: #0d151b;
    --led-on: #ff5a4f; --led-off: #4a1f1c;
  }
}
:root[data-theme="dark"] {
  --bg: #0c141a; --panel: #121d25; --panel-2: #1a2a35; --ink: #d8e2e9; --muted: #8ea1b0;
  --line: #283d4a; --copper: #e2834a; --copper-ink: #f2a77a; --copper-soft: #3a2518;
  --teal: #3fc3ba; --amber: #e9b23c; --magenta: #e463a1; --good: #5cc26b; --bad: #ef6c5f;
  --code-bg: #091015; --scope: #070d11; --scope-ink: #cfe3e0; color-scheme: dark;
  --sheet: #0f181e; --sheet-grid: #1f2f38; --sheet-ink: #d6e0e7; --sheet-mute: #8aa0ae; --sheet-hi: #2a1d14;
  --w1: #4be04b; --w0: #22702a; --wbus: #8ca2b0; --wact: #f3974f; --wval-bg: #e6edf1; --wval-ink: #0d151b;
  --led-on: #ff5a4f; --led-off: #4a1f1c;
}

* { box-sizing: border-box; }
body { background: var(--bg); color: var(--ink); font: 16px/1.6 var(--f-body); }
code, pre, kbd { font-family: var(--f-mono); font-size: 0.86em; }
code { background: var(--code-bg); padding: 0.05em 0.35em; border-radius: 3px; }
pre { background: var(--code-bg); padding: 12px 14px; border-radius: var(--radius); overflow-x: auto; line-height: 1.5; margin: 0; }
pre code { background: none; padding: 0; }
h1, h2, h3, h4 { font-family: var(--f-display); text-wrap: balance; line-height: 1.12; margin: 0; }
[hidden] { display: none !important; }
.btn { font: 700 14px/1 var(--f-body); padding: 11px 16px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--panel); color: var(--ink); cursor: pointer; text-decoration: none; display: inline-flex; gap: 8px; align-items: center; }
.btn:hover { border-color: var(--copper); }
.btn.primary { background: var(--copper); border-color: var(--copper); color: #fff; }
:root[data-theme="dark"] .btn.primary { color: #1a0c04; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.primary { color: #1a0c04; } }
.prose { max-width: 66ch; display: flex; flex-direction: column; gap: 14px; }
.module { display: flex; flex-direction: column; gap: 16px; }
.module > header { display: flex; gap: 14px; align-items: baseline; }
.module > header .no { font: 14px/1 var(--f-pixel); color: var(--copper-ink); flex: none; }
.module > header h2 { font-size: 27px; font-weight: 800; font-stretch: 108%; }
.module .prose ul, .module .prose ol { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; }
table.t { border-collapse: collapse; font-size: 14px; width: 100%; }
.tw { overflow-x: auto; max-width: 100%; }
table.t th, table.t td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t th { font: 10px/1.2 var(--f-pixel); letter-spacing: .05em; color: var(--muted); font-weight: 400; }
table.t td code { white-space: nowrap; }
.bench { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.bench > .bh { display: flex; align-items: center; gap: 10px; padding: 9px 14px; border-bottom: 1px solid var(--line); background: var(--panel-2); }
.bench > .bh b { font: 11px/1 var(--f-pixel); letter-spacing: .06em; color: var(--ink); font-weight: 400; }
.bench > .bh span { font-size: 13px; color: var(--muted); }
.bench > .bh .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--teal); box-shadow: 0 0 0 3px color-mix(in srgb, var(--teal) 25%, transparent); flex: none; }
.q { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.q > p { font-weight: 700; }
.q .opts { display: flex; flex-direction: column; gap: 6px; }
.q .opts button { text-align: left; font: 15px/1.4 var(--f-body); padding: 9px 12px; border-radius: 4px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); cursor: pointer; }
.q .opts button:hover:not([disabled]) { border-color: var(--copper); }
.q .opts button.right { border-color: var(--good); background: color-mix(in srgb, var(--good) 14%, var(--bg)); }
.q .opts button.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, var(--bg)); }
.q .why { font-size: 14.5px; color: var(--muted); }
.q .why[hidden] { display: none; }
.mpage { max-width: 1040px; margin: 0 auto; padding: 22px 24px 70px; display: flex; flex-direction: column; gap: 18px; }
.mback { font-size: 14px; color: var(--copper-ink); text-decoration: none; font-weight: 700; }
.mnavs { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 18px; }
.mnavs span { display: inline-flex; gap: 18px; flex-wrap: wrap; }
@media (max-width: 600px) { .mpage { padding: 16px 16px 60px; } }

/* Gates to Games: module labs inside a tier page. Uses the lab's tokens from lab/index.html. */
.mlabs { display: flex; flex-direction: column; gap: 28px; border-top: 1px solid var(--line); padding-top: 28px; }
.mlabs > .sec-h p { margin: 6px 0 0; color: var(--muted); max-width: 66ch; }
.mstrip { display: flex; flex-direction: column; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; }
.mstrip > b { font: 11px/1 var(--f-pixel); letter-spacing: .06em; font-weight: 400; color: var(--muted); }
.mstrip .row { display: flex; flex-wrap: wrap; gap: 6px; }
.mpill { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; line-height: 1.2; padding: 6px 9px; border: 1px solid var(--line); border-radius: 4px; background: var(--bg); color: var(--ink); text-decoration: none; }
a.mpill:hover { border-color: var(--copper); }
.mpill .n { font: 10px/1 var(--f-pixel); color: var(--copper-ink); }
.mpill .st { font: 9px/1 var(--f-pixel); letter-spacing: .03em; padding: 3px 4px; border-radius: 3px; border: 1px solid currentColor; }
.st.ready { color: var(--good); } .st.next { color: var(--copper-ink); } .st.planned { color: var(--muted); }
.mpill.planned { color: var(--muted); }

.mlab { scroll-margin-top: 70px; }
/* code must show != and == as typed, so JetBrains Mono's ligatures stay off */
.mlab, .mlab * { font-variant-ligatures: none !important; font-feature-settings: "liga" 0, "calt" 0 !important; }
.mlab > header { flex-wrap: wrap; }
.mlab > header .st { font: 10px/1 var(--f-pixel); padding: 4px 5px; border: 1px solid currentColor; border-radius: 3px; align-self: center; }
.mlab .mmeta { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; font-size: 13.5px; color: var(--muted); }
.mlab .mmeta code { color: var(--ink); overflow-wrap: anywhere; }
.mlab .mmeter { display: inline-flex; align-items: center; gap: 8px; margin-left: auto; font: 11px/1 var(--f-pixel); color: var(--ink); }
.mlab .mmeter i { display: block; width: 84px; height: 6px; border-radius: 3px; background: var(--panel-2); overflow: hidden; }
.mlab .mmeter i::after { content: ""; display: block; height: 100%; width: var(--p, 0%); background: var(--copper); }

.mtabs { display: flex; flex-wrap: wrap; gap: 6px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.mtabs button { font: 11px/1 var(--f-pixel); letter-spacing: .03em; padding: 8px 10px; border: 1px solid var(--line); border-radius: 4px; background: var(--panel); color: var(--ink); cursor: pointer; }
.mtabs button:hover { border-color: var(--copper); }
.mtabs button[aria-selected="true"] { background: var(--copper); border-color: var(--copper); color: #fff; }
:root[data-theme="dark"] .mtabs button[aria-selected="true"] { color: #1a0c04; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .mtabs button[aria-selected="true"] { color: #1a0c04; } }
.mtabs button .tick { margin-left: 6px; color: var(--good); }
.mtabs button[aria-selected="true"] .tick { color: inherit; }

.mpanel { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.mpanel:focus { outline: none; }
.mpanel h3 { font-size: 19px; font-weight: 800; font-stretch: 106%; }
.mpanel .prose { max-width: 70ch; }
.mpanel .prose p, .mpanel .prose ul { margin: 0; }
.mpanel .prose ul { padding-left: 20px; display: flex; flex-direction: column; gap: 4px; }
.mfoot { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; padding-top: 14px; border-top: 1px solid var(--line); }
.mscen { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.mfoot label { display: inline-flex; gap: 8px; align-items: center; font-size: 14px; cursor: pointer; }
.mfoot input { accent-color: var(--copper); width: 16px; height: 16px; }
.btn.msmall { padding: 7px 10px; font-size: 13px; }
.btn.msmall[disabled] { opacity: .5; cursor: default; }

.mnote { border-left: 3px solid var(--teal); background: var(--panel); padding: 10px 14px; font-size: 14.5px; border-radius: 0 4px 4px 0; }
.mnote.warn { border-left-color: var(--amber); }
.mnote.find { border-left-color: var(--bad); }
.mnote b.k { display: block; font: 10px/1 var(--f-pixel); letter-spacing: .06em; font-weight: 400; color: var(--muted); margin-bottom: 7px; }
.mstats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; }
.mstats > div { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; }
.mstats b { display: block; font: 800 21px/1.1 var(--f-display); font-stretch: 106%; }
.mstats span { font-size: 12.5px; color: var(--muted); }
.mpath { font: 13px/1.5 var(--f-mono); background: var(--code-bg); padding: 10px 12px; border-radius: 6px; overflow-wrap: anywhere; }
.mpath .here { color: var(--copper-ink); font-weight: 700; }

/* block diagrams: dark labels on the sheet in both themes follow the page tokens */
.mdiag { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.mdiag svg { display: block; width: 100%; min-width: 760px; height: auto; }
.mdiag .w { fill: none; stroke: var(--ink); stroke-width: 1.4; }
.mdiag .dot { fill: var(--ink); }
.mdiag .ar { fill: var(--ink); }
.mdiag .bd { fill: none; stroke: var(--muted); stroke-width: 1.2; stroke-dasharray: 5 4; }
.mdiag text { fill: var(--ink); font: 11.5px var(--f-mono); white-space: pre; }
.mdiag text.m { fill: var(--muted); font-size: 10.5px; }
.mdiag text.t { font: 700 12.5px var(--f-body); }
.mdiag g[data-blk] { cursor: pointer; }
.mdiag g[data-blk] rect, .mdiag g[data-blk] polygon { fill: var(--bg); stroke: var(--ink); stroke-width: 1.3; transition: fill .12s; }
.mdiag g[data-blk]:hover rect, .mdiag g[data-blk]:hover polygon { fill: var(--panel-2); }
.mdiag g[data-blk]:focus { outline: none; }
.mdiag g[data-blk]:focus-visible rect, .mdiag g[data-blk].on rect, .mdiag g[data-blk].on polygon { fill: var(--copper-soft); stroke: var(--copper); stroke-width: 2; }
.mhint { font-size: 13px; color: var(--muted); margin: 0; }
@media (min-width: 800px) { .mhint.phone { display: none; } }

/* code pane */
.mcode { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--code-bg); min-width: 0; }
.mcode .f { display: flex; gap: 8px; align-items: center; font: 12px/1.2 var(--f-mono); padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line); color: var(--muted); overflow-wrap: anywhere; }
.mcode pre { margin: 0; padding: 8px 0; max-height: 440px; overflow: auto; font: 12.5px/1.55 var(--f-mono); tab-size: 4; position: relative; }
.mcode .l { display: block; min-width: max-content; padding-right: 14px; white-space: pre; border-left: 3px solid transparent; }
.mcode .l i { display: inline-block; width: 3.4em; padding-right: 1em; text-align: right; color: var(--muted); font-style: normal; user-select: none; -webkit-user-select: none; }
.mcode .l.on { background: var(--copper-soft); border-left-color: var(--copper); }
.mcode .c { color: var(--muted); font-style: italic; } .mcode .k { color: var(--magenta); font-weight: 600; }
.mcode .n { color: var(--teal); } .mcode .y { color: var(--copper-ink); }

/* steps beside code */
.msplit { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 16px; align-items: start; }
.msplit .side { position: sticky; top: 64px; min-width: 0; }
@media (max-width: 860px) { .msplit { grid-template-columns: minmax(0, 1fr); } .msplit .side { position: static; } }
.msteps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.msteps button { display: grid; grid-template-columns: 24px minmax(0, 1fr); gap: 10px; width: 100%; text-align: left; font: 14.5px/1.45 var(--f-body); color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; cursor: pointer; }
.msteps button:hover { border-color: var(--copper); }
.msteps .on button { border-color: var(--copper); box-shadow: inset 3px 0 0 var(--copper); }
.msteps .num { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font: 700 12px/1 var(--f-mono); border: 1.5px solid var(--copper-ink); color: var(--copper-ink); }
.msteps .on .num { background: var(--copper); border-color: var(--copper); color: #fff; }
.msteps .tm { font: 12px var(--f-mono); color: var(--muted); margin-right: 5px; }
.msteps code { overflow-wrap: anywhere; }

/* waveform: an instrument screen, dark in both themes like the lab's other benches */
.mwv .tools { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.mwv .tools .span { font: 12px var(--f-mono); color: var(--muted); margin-left: 4px; }
.mwv .box { background: var(--scope); touch-action: pan-y; }
.mwv svg { display: block; width: 100%; user-select: none; -webkit-user-select: none; cursor: crosshair; }
.mwv .nm { fill: var(--scope-ink); font: 12px var(--f-mono); }
.mwv .val { fill: var(--tr-2); font: 11px var(--f-mono); }
.mwv .axis { fill: var(--tr-dim); font: 10.5px var(--f-mono); }
.mwv .grid { stroke: var(--tr-grid); stroke-width: 1; }
.mwv .bit { fill: none; stroke: var(--tr-1); stroke-width: 1.5; }
.mwv .bus { fill: color-mix(in srgb, var(--tr-5) 14%, transparent); stroke: var(--tr-5); stroke-width: 1.1; }
.mwv .bus.out { fill: color-mix(in srgb, var(--tr-4) 20%, transparent); stroke: var(--tr-4); }
.mwv .btx { fill: var(--scope-ink); font: 10px var(--f-mono); text-anchor: middle; }
.mwv .cur { stroke: var(--tr-3); stroke-width: 1.5; }
.mwv .curt { fill: var(--tr-3); font: 700 11px var(--f-mono); text-anchor: middle; }
.mwv .mk { cursor: pointer; }
.mwv .mk circle { fill: var(--scope); stroke: var(--tr-3); stroke-width: 1.4; }
.mwv .mk text { fill: var(--tr-3); font: 700 10px var(--f-mono); text-anchor: middle; }
.mwv .mk.on circle { fill: var(--tr-3); } .mwv .mk.on text { fill: var(--scope); }
.mwv .bar { stroke-width: 3; }
.mlegend { display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 9px 12px; font-size: 13px; color: var(--muted); border-top: 1px solid var(--line); }
.mlegend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

.mlabx { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.mlabx h4 { font-size: 16px; font-weight: 800; }
.mlabx p { margin: 0; }
.mlabx pre, .mpanel > pre, .mnote pre, .mterm { margin: 0; font: 12.5px/1.5 var(--f-mono); background: var(--scope); color: var(--scope-ink); padding: 10px 12px; border-radius: 6px; overflow-x: auto; white-space: pre; }
.mlabx details, .miq { border: 1px solid var(--line); border-radius: 6px; background: var(--bg); padding: 8px 12px; }
.mlabx summary, .miq summary { cursor: pointer; font-weight: 700; font-size: 14.5px; }
.mlabx details > *:not(summary), .miq > *:not(summary) { margin: 8px 0 0; }
.miq { background: var(--panel); }
.miq .fu { color: var(--muted); font-size: 14.5px; }
.mquiz { display: flex; flex-direction: column; gap: 10px; }
.mquiz .opts button[disabled] { cursor: default; }
