/* SPDX-License-Identifier: Apache-2.0 */
/* The simulator's page (docs/ui-design.md). A fixed frame: the top bar, the stage (its band,
   then the machine in 3D or in 2D), the handle, the dock below, the status line. The page never
   scrolls. Every colour, corner and state is a token (css/theme.css, P11). */

@import url("theme.css?v=1.0.0");
@import url("fonts.css?v=1.0.0");

:root {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--md-on-surface);
  background: var(--md-surface);
  font-variant-numeric: tabular-nums;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--md-surface); }
body {
  display: grid;
  grid-template-rows: var(--bar-h) minmax(0, 1fr) auto auto var(--status-h);
  /* one column, never wider than the window: without this it grows to the widest thing in it
     (the Video RAM tab's 64 columns), and the whole page stops narrowing with the window */
  grid-template-columns: minmax(0, 1fr);
  height: 100dvh;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
.lesson, .dialog-body, #status, .vram-inspector, .tape-tool .tool-side, .tool-note, .cpu-state { user-select: text; -webkit-user-select: text; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--link); }
:focus-visible { outline: 2px solid var(--md-primary); outline-offset: 2px; }
.icon { width: 20px; height: 20px; fill: currentColor; flex: none; display: block; }
code, pre, .mono, kbd { font-family: var(--mono); }
.dim { color: var(--md-on-surface-variant); }
.spacer { flex: 1; }
.empty { color: var(--md-on-surface-variant); margin: 8px 0; }

/* ---- buttons (Material 3: filled, tonal, text, icon; state layers) ---- */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--md-primary-text);
  font-weight: 560;
  cursor: pointer;
  white-space: nowrap;
  isolation: isolate;
}
.btn::before, .chip::before, .dock-tab::before, .segmented button::before, .menu button::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: currentColor;
  opacity: 0;
  transition: opacity 120ms var(--ease);
  z-index: -1;
  pointer-events: none;
}
.btn:hover::before, .chip:hover::before, .dock-tab:hover::before, .segmented button:hover::before, .menu button:hover::before { opacity: var(--state-hover); }
.btn:active::before, .chip:active::before, .segmented button:active::before { opacity: var(--state-press); }
.btn.filled { background: var(--md-primary); color: var(--md-on-primary); }
.btn.tonal { background: var(--md-secondary-container); color: var(--md-on-secondary-container); }
.btn.has-icon { padding-left: 12px; }
.btn.small { height: 32px; padding: 0 12px; font-size: 13px; }
.btn.small.has-icon { padding-left: 8px; }
.btn.small .icon { width: 18px; height: 18px; }
.btn[aria-disabled="true"] { cursor: default; color: color-mix(in srgb, var(--md-on-surface) 38%, transparent); }
.btn.tonal[aria-disabled="true"], .btn.filled[aria-disabled="true"] { background: color-mix(in srgb, var(--md-on-surface) 12%, transparent); }
.btn[aria-disabled="true"]::before { display: none; }
/* an icon alone: in the text's colour, as the 8800 simulator's icon buttons are */
.btn.icon-only { width: 40px; padding: 0; color: var(--md-on-surface); }
/* a tool button: the top bar's and the band's menus, flat until pointed at; tinted while its menu is open */
.btn.tool-btn { height: 36px; padding: 0 8px 0 10px; gap: 6px; color: var(--md-on-surface); font-weight: 500; }
.btn.tool-btn > .icon:last-child, .menu-btn > .icon:last-child { width: 18px; height: 18px; margin-left: -2px; color: var(--md-on-surface-variant); }
.btn[aria-expanded="true"]::before { opacity: var(--state-press); }
.btn.lit { background: var(--on-container); color: var(--on); }

/* a segmented button (2D | 3D, the clock's speed) */
.segmented { display: inline-flex; border: 1px solid var(--md-outline); border-radius: var(--radius-full); overflow: hidden; height: 32px; }
.segmented button { position: relative; isolation: isolate; display: inline-flex; align-items: center; gap: 6px; padding: 0 12px; border: 0; background: none; color: var(--md-on-surface); font-size: 13px; font-weight: 560; cursor: pointer; }
.segmented button + button { border-left: 1px solid var(--md-outline); }
.segmented button[aria-checked="true"] { background: var(--md-primary-container); color: var(--md-on-primary-container); }
.segmented .icon { width: 18px; height: 18px; }

/* a chip: Type it, Show me */
.chip { position: relative; isolation: isolate; display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px 0 8px; border: 1px solid var(--md-outline); border-radius: var(--radius-s); background: none; color: var(--md-on-surface); font-size: 13px; font-weight: 560; cursor: pointer; }
.chip .icon { width: 18px; height: 18px; color: var(--md-primary-text); }

/* a switch (Material 3) */
.switch { display: inline-flex; align-items: center; gap: 10px; height: 32px; padding: 0 12px 0 4px; border: 0; border-radius: var(--radius-full); background: none; color: var(--md-on-surface); cursor: pointer; font-weight: 560; }
.switch:hover { background: color-mix(in srgb, var(--md-on-surface) 8%, transparent); }
.switch-track { position: relative; width: 44px; height: 24px; border-radius: 12px; border: 2px solid var(--md-outline); background: var(--md-surface-highest); transition: background 120ms var(--ease), border-color 120ms var(--ease); flex: none; }
.switch-thumb { position: absolute; top: 4px; left: 4px; width: 12px; height: 12px; border-radius: 50%; background: var(--md-outline); transition: all 120ms var(--ease); }
.switch[aria-checked="true"] .switch-track { background: var(--md-primary); border-color: var(--md-primary); }
.switch[aria-checked="true"] .switch-thumb { left: 22px; top: 2px; width: 16px; height: 16px; background: var(--md-on-primary); }

/* an outlined text field, and a select */
.field { height: 32px; padding: 0 8px; border: 1px solid var(--md-outline); border-radius: var(--radius-xs); background: var(--md-well); color: var(--md-on-surface); font-size: 13px; }
.field:focus { outline: 2px solid var(--md-primary); outline-offset: -1px; }

/* ---- the top bar (U8) ---- */
#topbar { display: flex; align-items: center; gap: 6px; padding: 0 8px 0 14px; background: var(--md-surface-low); border-bottom: 1px solid var(--md-outline-variant); min-width: 0; }
.brand { display: flex; align-items: center; gap: 10px; margin-right: 12px; min-width: 0; }
.brand-mark { width: 30px; height: 30px; }
.brand-name { font-size: 17px; font-weight: 650; letter-spacing: 0.01em; white-space: nowrap; }

/* ---- the stage ---- */
/* the stage: its band, a row of its own, then the machine in a card under it (U1) */
#stage { display: flex; flex-direction: column; overflow: hidden; min-height: 0; padding: 0 12px 10px; background: var(--md-surface); }
#stage-view { position: relative; flex: 1 1 0; min-height: 0; overflow: hidden; border-radius: var(--radius-m); background: var(--md-surface-low); }
/* both views on one dark blue glow: the 3D view draws on a clear canvas over it, with no floor,
   so nothing is brighter than the machine; the 2D view's drawings sit on the same */
#view3d, #view2d { background: var(--stage-glow); }
#view3d, #view2d { position: absolute; inset: 0; }
#view3d canvas { display: block; width: 100%; height: 100%; touch-action: none; outline: none; }
#view3d canvas:focus-visible { outline: 2px solid var(--md-primary); outline-offset: -3px; }
#view2d { opacity: 0; transition: opacity 260ms var(--ease); }
#view2d.shown { opacity: 1; }
@media (prefers-reduced-motion: reduce) { #view2d { transition: none; } }

/* the band (U1, U4): a row of its own over the machine, not laid on it */
#band { flex: none; display: flex; align-items: center; gap: 8px; height: 48px; min-width: 0; overflow-x: auto; scrollbar-width: none; }
#band::-webkit-scrollbar { display: none; }
.band-group { flex: none; display: flex; align-items: center; gap: 4px; }
.band-group .btn.icon-only { width: 34px; height: 34px; }
.joined { display: inline-flex; }
.menu-btn { color: var(--md-on-surface); padding: 0 6px 0 12px; }
.menu-btn.active { color: var(--md-primary-text); }
.segmented.mode { flex: none; height: 32px; }
#stage[data-mode="3d"] .drawers, #stage[data-mode="2d"] .tools3d { display: none; }
/* a drawer's toggle: filled while its drawer is open */
.drawers .btn[aria-pressed="true"] { background: var(--md-primary-container); color: var(--md-on-primary-container); }

/* the helper strip (U4): the controls that are hard to reach on the machine, in a strip at the
   stage's foot, centred; a tab on its top edge folds it away, leaving the tab */
#helper-strip { flex: none; display: flex; flex-direction: column; align-items: center; max-width: 100%; margin-top: 6px; }
.strip-tab { display: flex; align-items: center; justify-content: center; width: 44px; height: 14px; padding: 0; border: 1px solid var(--md-outline-variant); border-bottom: 0; border-radius: var(--radius-s) var(--radius-s) 0 0; background: var(--md-surface-mid); color: var(--md-on-surface-variant); cursor: pointer; }
.strip-tab:hover { background: var(--md-surface-high); color: var(--md-on-surface); }
.strip-tab .icon { width: 18px; height: 18px; transition: transform 150ms var(--ease); }
#helper-strip.folded .strip-tab { border-bottom: 1px solid var(--md-outline-variant); border-radius: var(--radius-s); }
#helper-strip.folded .strip-tab .icon { transform: rotate(180deg); }
#helper-strip.folded .strip-body { display: none; }
.strip-body { display: flex; align-items: center; gap: 12px; max-width: 100%; padding: 6px 10px; overflow-x: auto; scrollbar-width: none; border: 1px solid var(--md-outline-variant); border-radius: var(--radius-l); background: var(--md-surface-mid); }
.strip-body::-webkit-scrollbar { display: none; }
/* a group: Material's connected buttons, round at the ends, nearly square where they meet */
.strip-group { flex: none; display: flex; gap: 2px; }
.strip-group .btn:not(:first-child) { border-top-left-radius: var(--radius-xs); border-bottom-left-radius: var(--radius-xs); }
.strip-group .btn:not(:last-child) { border-top-right-radius: var(--radius-xs); border-bottom-right-radius: var(--radius-xs); }
.strip-divider { flex: none; align-self: stretch; width: 1px; background: var(--md-outline-variant); }
.deck-key { letter-spacing: 0.02em; }
.deck-key.rec .icon { color: #ff5a46; }
.deck-key[aria-pressed="true"] { background: var(--md-primary-container); color: var(--md-on-primary-container); box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.35); }

/* a part's label (U2) */
.part-label { position: absolute; z-index: 6; max-width: 320px; padding: 8px 12px; border-radius: var(--radius-s); background: var(--md-surface-highest); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45); pointer-events: none; display: flex; flex-direction: column; gap: 2px; }
.part-label strong { font-weight: 640; }
.part-label span { color: var(--md-on-surface-variant); font-size: 13px; }
.part-label em { color: var(--md-primary-text); font-style: normal; font-size: 12px; }
.put-back { position: absolute; right: 12px; bottom: 12px; z-index: 5; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4); height: 48px; border-radius: var(--radius-l); }
.loading { position: absolute; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 5; width: min(320px, 80%); text-align: center; color: var(--md-on-surface-variant); font-size: 13px; }
.loading-bar { height: 4px; border-radius: 2px; background: var(--md-surface-highest); overflow: hidden; }
.loading-bar span { display: block; height: 100%; width: 0; background: var(--md-primary); transition: width 120ms linear; }

/* ---- the 2D view: the machine's faces, flat (D10) ---- */
/* the drawn keyboard is a drawer, at any width, shown only while open; closed, the screen gets
   the stage's whole height (docs/ui-design.md, U10) */
/* the drawings' widths are set by script, all at one scale (js/flat/layout.js, fitFlat) */
.flat { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 12px 16px; }
.flat:not([data-kbd="open"]) .flat-kbd { display: none; }
/* each row is a container: a drawing takes the largest size its shape allows in it */
.flat-top { flex: none; display: flex; align-items: center; justify-content: center; }
.flat-kbd { flex: none; display: flex; align-items: center; justify-content: center; }
.flat-box { position: relative; aspect-ratio: var(--ar); container-type: inline-size; flex: none; }
.flat-box > svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
/* the recorder a drawer too: closed, the display has the row */
.flat:not([data-rec="open"]) .flat-recorder { display: none; }
.flat-screen { position: absolute; display: block; cursor: crosshair; image-rendering: auto; }
.flat-dpower { position: absolute; border: 0; border-radius: 50%; background: radial-gradient(circle at 40% 35%, #ff6a4d, #c8301c 70%); box-shadow: 0 2px 0 #5a1208, inset 0 -2px 3px rgba(0, 0, 0, 0.3); cursor: pointer; padding: 0; }
/* the display's POWER is a push button, not a lamp: the same red in or out, as on the machine.
   Pushed in (on), it sits lower in its ring, its drop shadow gone and shaded from above; only the
   keyboard's LED lights for on, and the screen says the display is on */
.flat-dpower { transition: transform 80ms var(--ease), box-shadow 80ms var(--ease); }
.flat-dpower[aria-pressed="true"] { transform: scale(0.9); box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.45); }
.flat-recled.on { filter: drop-shadow(0 0 1.2px var(--led-on, #ff3b24)); }
.flat-knob { position: absolute; border: 0; border-radius: 50%; background: transparent; cursor: ew-resize; padding: 0; touch-action: none; }
.flat-knob:hover { background: color-mix(in srgb, var(--md-primary) 18%, transparent); }
.flat-deckkey { position: absolute; padding: 0; border: 1px solid #000; border-radius: 2px; background: linear-gradient(#3b3b3b, #262626); cursor: pointer; box-shadow: 0 2px 0 #090909; }
.flat-deckkey.rec { background: linear-gradient(#f2604a, #d8422d); }
/* STOP and EJECT spring back: pressed, every key goes down while it is held */
.flat-deckkey { transition: transform 60ms var(--ease), box-shadow 60ms var(--ease); }
.flat-deckkey:active, .flat-deckkey.latched { transform: translateY(2px); box-shadow: none; background: linear-gradient(#2a2a2a, #1a1a1a); }
.flat-deckkey.rec:active, .flat-deckkey.rec.latched { background: linear-gradient(#c8432f, #a8301f); }
.flat-key { position: absolute; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0; padding: 0; border: 0; border-radius: 3px; background: linear-gradient(#2a2a2a, var(--key-black)); color: var(--key-legend); font-family: var(--font); font-weight: 600; font-size: min(1.55cqw, var(--fit, 1.55cqw)); overflow: hidden; white-space: nowrap; line-height: 1.05; cursor: pointer; box-shadow: 0 0.2cqw 0 #050505, inset 0 1px 0 rgba(255, 255, 255, 0.07); touch-action: none; }
.flat-key small { font-size: 0.72em; opacity: 0.85; }
.flat-key.enter { background: linear-gradient(#e6dcbe, var(--key-cream)); color: #1d1a14; }
/* the key's edge and its travel scale with the drawing: a fixed 2px filled the gaps between
   the keys on a phone, where the keys are about 2px apart, and they seemed to run together */
.flat-key.down { transform: translateY(0.2cqw); box-shadow: none; filter: brightness(0.82); }
.flat-rear { position: absolute; display: inline-flex; align-items: center; justify-content: center; gap: 4px; padding: 0 4px; border: 0; border-radius: var(--radius-xs); background: #2a2a2a; color: #dcdcd6; font-size: 1.15cqw; font-weight: 650; cursor: pointer; }
.flat-rear .icon { width: 1.4em; height: 1.4em; }
.flat-rear.on .icon { color: var(--on); }

/* ---- the dock (P3, U6) ---- */
#dock { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--md-surface-low); }
/* the handle between the stage and the dock: a row of its own, lit while pointed at or dragged */
#dock-handle { position: relative; height: 6px; cursor: ns-resize; touch-action: none; background: var(--md-well); }
#dock-handle::after { content: ""; position: absolute; left: 50%; top: 2px; width: 40px; height: 2px; transform: translateX(-50%); border-radius: 1px; background: var(--md-outline-variant); }
#dock-handle:hover, #dock-handle:focus-visible, #dock-handle.dragging { background: var(--md-primary); outline: none; }
#dock-handle:hover::after, #dock-handle:focus-visible::after, #dock-handle.dragging::after { background: var(--md-on-primary); }
.dock-bar { display: flex; align-items: stretch; gap: 2px; padding: 0 4px 0 8px; height: 40px; flex: none; min-width: 0; background: var(--md-surface-mid); border-bottom: 1px solid var(--md-well); }
#dock.folded .dock-bar { border-bottom: 0; }
#dock-fold { align-self: center; width: 36px; height: 36px; }
#dock-tabs { display: flex; gap: 2px; min-width: 0; overflow-x: auto; scrollbar-width: none; }
/* Material's primary tabs, dense: the open one amber, over an indicator with rounded ends */
.dock-tab { position: relative; isolation: isolate; display: inline-flex; align-items: center; gap: 6px; height: 100%; padding: 0 14px; border: 0; background: none; color: var(--md-on-surface-variant); font-weight: 560; cursor: pointer; border-radius: 0; white-space: nowrap; }
.dock-tab .icon { width: 18px; height: 18px; }
.dock-tab:focus-visible { outline-offset: -2px; }
.dock-tab[aria-selected="true"] { color: var(--md-primary-text); }
.dock-tab[aria-selected="true"]::after { content: ""; position: absolute; left: 8px; right: 8px; bottom: 0; height: 3px; border-radius: 3px 3px 0 0; background: var(--md-primary); }
/* room below a pane's end for a status message risen over the dock's foot (P7) */
.dock-pane { flex: 1; min-height: 0; overflow: auto; padding: 8px 16px calc(16px + var(--status-rise, 0px)); }
#dock.folded .dock-pane { display: none; }

/* a tool's layout: its main part, and a side */
/* an instrument is one block, centred in its tab as a lesson is: its cards side by side at
   their own widths, not spread to the tab's edges */
.tool { display: flex; gap: 20px; align-items: flex-start; justify-content: center; min-width: 0; max-width: 1400px; margin: 0 auto; }
.tool-main { min-width: 0; flex: 0 1 auto; }
.tool-side { flex: 0 1 340px; min-width: 240px; }
.tool-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 8px 0; }
.tool h3, .cpu-box h3 { margin: 4px 0 8px; font-size: 13px; font-weight: 640; color: var(--md-on-surface-variant); }
.tool-note { margin: 4px 0 8px; }

/* the Video RAM tool */
.vram-grid { display: inline-grid; gap: 1px; font-family: var(--mono); font-size: 11px; background: var(--md-well); padding: 6px; border-radius: var(--radius-m); max-width: 100%; overflow-x: auto; }
.vram-tool { flex-wrap: wrap; gap: 12px; }
.vram-row { display: grid; grid-template-columns: 34px repeat(64, 14px); gap: 1px; }
.vram-head { grid-template-columns: 34px repeat(8, calc(14px * 8 + 7px)); color: var(--md-outline); }
.vram-addr { color: var(--md-outline); }
.vram-cell { width: 14px; height: 15px; letter-spacing: -0.04em; padding: 0; border: 0; border-radius: 2px; background: transparent; color: var(--md-on-surface-variant); font: inherit; font-size: 10px; cursor: pointer; transition: background 300ms; }
.vram-cell.gfx { color: var(--story); }
.vram-cell.hot { background: color-mix(in srgb, var(--md-primary) 35%, transparent); transition: none; }
.vram-cell.picked { outline: 2px solid var(--md-primary); outline-offset: -1px; color: var(--md-on-surface); }
.vram-inspector { flex: 1 1 250px; min-width: 240px; max-width: 360px; }
.insp-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.insp-head strong { font-size: 16px; color: var(--md-primary-text); }
.insp-value { margin: 4px 0; }
.bits { display: flex; gap: 3px; margin: 6px 0 10px; }
.bit { display: flex; flex-direction: column; align-items: center; width: 28px; padding: 2px 0; border-radius: var(--radius-xs); background: var(--md-surface-high); font-family: var(--mono); }
.bit small { color: var(--md-outline); font-size: 10px; }
.bit.on { background: var(--md-secondary-container); }
.bit.rebuilt { outline: 1px dashed var(--md-primary); }
.glyph { display: flex; gap: 12px; align-items: flex-start; }
.dots { display: grid; grid-template-columns: repeat(var(--w), 12px); gap: 2px; padding: 6px; background: #0c0d0d; border-radius: var(--radius-xs); }
.dot { width: 12px; height: 12px; border-radius: 2px; background: #1b201f; }
.dot.on { background: var(--phosphor); box-shadow: 0 0 4px rgba(228, 236, 255, 0.6); }
.dot-rows { display: grid; grid-auto-rows: 14px; font-size: 11px; color: var(--md-outline); padding-top: 6px; }
.blocks { display: grid; grid-template-columns: repeat(2, 40px); grid-auto-rows: 36px; gap: 3px; padding: 6px; background: #0c0d0d; border-radius: var(--radius-xs); }
.block { display: flex; align-items: flex-end; justify-content: center; border-radius: 2px; background: #1b201f; font-size: 10px; color: var(--md-outline); }
.block.on { background: var(--phosphor); color: #2a2f38; }

/* the Keyboard tool */
.matrix { display: inline-grid; gap: 2px; padding: 6px; background: var(--md-well); border-radius: var(--radius-m); font-size: 12px; max-width: 100%; overflow-x: auto; }
.matrix-row { display: grid; grid-template-columns: 64px repeat(8, 54px) 64px 96px; gap: 2px; align-items: center; border-radius: var(--radius-xs); }
.matrix-head { color: var(--md-outline); font-size: 11px; }
.matrix-row.read .mx-addr { color: var(--md-primary-text); }
.matrix-row.read { background: color-mix(in srgb, var(--md-primary) 10%, transparent); }
.mx-addr { padding-left: 4px; color: var(--md-on-surface-variant); }
.mx-key { height: 26px; display: flex; align-items: center; justify-content: center; border-radius: var(--radius-xs); background: var(--md-surface-high); font-weight: 560; }
.mx-key.none { background: transparent; }
.mx-key.down { background: var(--md-primary); color: var(--md-on-primary); }
.mx-byte, .mx-rate { text-align: right; padding-right: 6px; color: var(--md-on-surface-variant); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* the Cassette tool */
.tape-name { display: block; font-size: 15px; margin: 4px 0; }
.tape-what { margin: 4px 0; }
.tape-where { margin: 4px 0 8px; color: var(--md-on-surface-variant); font-size: 12px; }
.tape-strip { width: 100%; max-width: 960px; height: auto; aspect-ratio: 960 / 150; display: block; background: var(--md-well); border-radius: var(--radius-m); }
.tape-now { min-height: 2.9em; margin: 6px 0; }

/* the CPU & Memory tool */
.cpu-tool { flex-direction: column; gap: 8px; }
.cpu-top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.cpu-controls { margin: 0; }
.cpu-controls .group { display: inline-flex; gap: 4px; align-items: center; }
.cpu-state { margin: 0; color: var(--md-on-surface-variant); }
/* the registers at their own width, the next instructions as wide as a listing needs, side by
   side down to a phone; the memory under both, the whole width, or beside them on a wide window */
.cpu-tool { width: fit-content; max-width: 100%; }
.cpu-grid { display: grid; grid-template-columns: max-content minmax(320px, 520px); gap: 12px; }
@media (min-width: 1440px) {
  .cpu-grid { grid-template-columns: max-content minmax(320px, 520px) minmax(560px, 640px); }
  .cpu-grid .cpu-box.wide { grid-column: 3; grid-row: 1 / span 2; align-self: start; }
}
.cpu-box { padding: 8px 12px 10px; border-radius: var(--radius-m); background: var(--md-surface-mid); min-width: 0; }
.cpu-box.wide { grid-column: 1 / -1; }
.box-head { display: flex; align-items: center; gap: 6px; }
.box-head h3 { margin: 0; }
.regs { display: grid; gap: 4px; }
.reg-row { display: flex; gap: 6px; flex-wrap: wrap; }
.reg { display: inline-flex; flex-direction: column; min-width: 54px; padding: 2px 6px; border-radius: var(--radius-xs); background: var(--md-well); }
.reg small { font-size: 10px; color: var(--md-outline); }
.reg b { font-weight: 500; font-size: 13px; }
.reg.changed b { color: var(--md-primary-text); }
.flags { display: flex; gap: 4px; margin-top: 8px; }
.flag { min-width: 32px; padding: 2px 6px; text-align: center; border-radius: var(--radius-xs); background: var(--md-well); color: var(--md-outline); font-family: var(--mono); font-size: 12px; }
.flag.on { background: var(--md-secondary-container); color: var(--md-on-secondary-container); }
.code { margin: 0; padding: 0; list-style: none; font-size: 12.5px; }
.code li { display: grid; grid-template-columns: 44px 98px 1fr; gap: 8px; padding: 1px 6px; border-radius: var(--radius-xs); }
.code li.at-pc { background: color-mix(in srgb, var(--md-primary) 18%, transparent); color: var(--md-primary-text); }
.code li.undoc .c-text::after { content: " *"; color: var(--md-outline); }
.c-addr, .c-bytes { color: var(--md-outline); }
.code li.at-pc .c-addr { color: var(--md-primary-text); }
.memmap { display: flex; height: 26px; margin: 8px 0; border-radius: var(--radius-xs); overflow: hidden; gap: 1px; background: var(--md-outline-variant); }
.region { --lit: 0; position: relative; display: flex; align-items: center; justify-content: center; min-width: 0; background: color-mix(in srgb, var(--md-primary) calc(var(--lit) * 70%), var(--md-surface-high)); font-size: 10px; color: var(--md-on-surface-variant); cursor: pointer; overflow: hidden; }
button.region { padding: 0; border: 0; border-radius: 0; font: inherit; font-size: 10px; }
button.region:focus-visible { outline: 2px solid var(--md-primary); outline-offset: -2px; }
.region span { white-space: nowrap; overflow: hidden; text-overflow: clip; padding: 0 2px; }
.region.none, .region.high, .region.ei { background: var(--md-well); color: var(--md-outline); }
.dump { font-size: 12px; overflow-x: auto; }
.dump-row { display: flex; gap: 12px; white-space: nowrap; }
.d-addr { color: var(--md-outline); }
.d-bytes { display: inline-flex; gap: 0.6ch; }
.d-bytes span { border-radius: 2px; }
.d-bytes .at-pc { background: color-mix(in srgb, var(--md-primary) 30%, transparent); color: var(--md-primary-text); }
.d-bytes .at-sp { outline: 1px solid var(--story); }
.d-ascii { color: var(--md-outline); letter-spacing: 0.05em; }

/* the lessons (U7): a bar of numbered lessons across the top, full width and in sight as a
   lesson scrolls, its tabs centred; then one lesson down the middle */
#pane-lessons { padding-top: 0; container-type: inline-size; }
.lessons { --reading: 780px; display: flex; flex-direction: column; min-height: 100%; line-height: 1.6; }
.lesson-bar { position: sticky; top: 0; z-index: 2; display: flex; gap: 4px; margin: 0 -16px; padding: 6px 16px 0; background: var(--md-surface-low); border-bottom: 1px solid var(--md-outline-variant); overflow-x: auto; scrollbar-width: none; }
.lesson-bar::-webkit-scrollbar { display: none; }
/* the tabs centred in the bar; where they overflow, the auto margins give way and they start at its left */
.lesson-bar > .lesson-tab:first-child { margin-left: auto; }
.lesson-bar > .lesson-tab:last-child { margin-right: auto; }
.lesson-tab { flex: none; display: inline-flex; align-items: center; gap: 8px; margin-bottom: -1px; padding: 6px 10px 8px 4px; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--md-on-surface-variant); cursor: pointer; white-space: nowrap; font-size: 13px; font-weight: 560; line-height: 1.45; }
.lesson-tab:hover { color: var(--md-on-surface); }
.lesson-tab:focus-visible { outline: none; }
.lesson-tab:focus-visible b { box-shadow: 0 0 0 2px var(--md-primary); }
.lesson-tab b { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; border: 1.5px solid currentColor; border-radius: 50%; font-size: 12px; }
.lesson-tab[aria-selected="true"] { color: var(--md-on-surface); border-bottom-color: var(--md-primary); }
.lesson-tab[aria-selected="true"] b { background: var(--md-primary); border-color: var(--md-primary); color: var(--md-on-primary); }
.lesson-tab.complete:not([aria-selected="true"]) b { background: var(--on-container); border-color: var(--on); color: var(--on); }
/* narrow, the other lessons are their numbers alone; their names are their tooltips */
@container (max-width: 600px) {
  .lesson-tab:not([aria-selected="true"]) span { display: none; }
}
.lesson-bar.compact .lesson-tab:not([aria-selected="true"]) span { display: none; }
.lesson-body { display: flex; gap: 16px; align-items: flex-start; padding-top: 14px; }
.lesson { flex: 1 1 auto; max-width: var(--reading); margin: 0 auto; min-width: 0; }
.lesson-of { margin: 0; color: var(--md-outline); font-size: 11px; font-weight: 650; letter-spacing: 0.08em; text-transform: uppercase; }
.lesson h3 { margin: 2px 0 4px; font-size: 20px; font-weight: 650; line-height: 1.3; color: var(--md-on-surface); }
.lesson .lead { margin: 0 0 18px; color: var(--md-on-surface-variant); }
/* the steps: numbered down a thin line */
.steps { list-style: none; margin: 0; padding: 0; }
.step { position: relative; display: grid; grid-template-columns: 24px minmax(0, 1fr) 24px; gap: 14px; padding: 0 0 18px; }
.step:not(:last-child)::after { content: ""; position: absolute; left: 11px; top: 30px; bottom: 6px; width: 2px; border-radius: 1px; background: var(--md-outline-variant); }
.step-n { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; border-radius: 50%; border: 1.5px solid var(--md-outline); color: var(--md-on-surface-variant); font-size: 12px; font-weight: 650; }
.step-body { min-width: 0; }
.step h4 { margin: 0 0 2px; font-size: 15px; font-weight: 620; line-height: 24px; }
.step-text { color: var(--md-on-surface); }
.step-text code, .more code { padding: 0 4px; border-radius: var(--radius-xs); background: var(--md-well); font-size: 0.95em; }
.step-body { display: flow-root; }
.photo { float: right; width: min(42%, 300px); margin: 4px 0 8px 18px; }
.photo img { display: block; width: 100%; border-radius: var(--radius-s); box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4); }
@container (max-width: 560px) {
  .photo { float: none; width: auto; max-width: 420px; margin: 10px 0 4px; }
}
.photo figcaption { margin-top: 6px; font-size: 12px; color: var(--md-outline); }
.photo figcaption a { color: inherit; }
.listing { margin: 8px 0; padding: 10px 14px; border: 1px solid var(--md-outline-variant); border-radius: var(--radius-s); background: var(--md-well); color: var(--phosphor); font-size: 13px; line-height: 1.5; overflow-x: auto; }
/* a step's chips: what to press, in amber (Material's assist chip) */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip { border-color: var(--md-primary); background: color-mix(in srgb, var(--md-primary) 12%, transparent); color: var(--md-primary-text); }
.chip .icon { color: inherit; }
/* Going further: the story and the asides, in blue */
.more { margin-top: 10px; padding: 4px 14px; border-left: 3px solid var(--story); border-radius: var(--radius-s); background: color-mix(in srgb, var(--story) 10%, transparent); }
.more summary { cursor: pointer; color: var(--story); font-weight: 600; font-size: 13px; padding: 2px 0; }
.more > div { padding: 4px 0 6px; color: var(--md-on-surface-variant); }
.tick { color: var(--md-outline-variant); padding-top: 2px; }
.step.done .tick { color: var(--on); }
.step.done .step-n { background: var(--on); border-color: var(--on); color: var(--on-container); }
/* on to the next lesson: Material's outlined button, at the right */
.btn.next-lesson { display: flex; margin: 8px 0 8px auto; background: none; border: 1px solid var(--md-outline); color: var(--md-on-surface); }
.btn.next-lesson:hover { border-color: var(--md-primary); color: var(--md-primary-text); }
.lessons .dim:last-child { margin-top: 8px; }
/* the tool Show me opened, beside the lesson: the grids keep their size and scroll */
/* Show me's answer on the stage: its edge glows once, so a press is seen even when the view is already there */
#stage-view.pointed::after { content: ""; position: absolute; inset: 0; z-index: 30; border-radius: inherit; pointer-events: none; animation: pointed 900ms var(--ease) forwards; }
@keyframes pointed { 0%, 100% { box-shadow: inset 0 0 0 3px transparent; } 25%, 45% { box-shadow: inset 0 0 0 3px var(--md-primary); } }
.lesson-companion { position: sticky; top: 56px; flex: 0 1 560px; min-width: 0; max-height: calc(100% - 8px); overflow: auto; padding: 8px 12px; border-radius: var(--radius-l); background: var(--md-surface-mid); border: 1px solid var(--md-outline-variant); line-height: 1.45; }
.companion-close { display: flex; margin: -2px -6px 4px auto; }
.companion-tool .tool { flex-direction: column; }
.companion-tool .vram-grid, .companion-tool .matrix { max-width: 100%; overflow-x: auto; }
.companion-tool .tool-side, .companion-tool .vram-inspector { flex: none; min-width: 0; max-width: none; }
/* beside a lesson there is room for one card across: the CPU tool's cards one under another */
.companion-tool .cpu-tool { width: auto; }
.companion-tool .cpu-grid { grid-template-columns: minmax(0, 1fr); width: 100%; }
.companion-tool .cpu-grid .cpu-box.wide { grid-column: 1; grid-row: auto; }

/* ---- the status line (P7) ---- */
/* one line's height in the page: a longer message rises over the foot of the dock (P7), which
   gains as much room below its end (--status-rise); a refusal is amber, a fault red */
#status { position: relative; z-index: 7; min-width: 0; font-size: 13px; color: var(--md-on-surface); background: var(--md-surface-mid); }
#status-text { position: absolute; left: 0; right: 0; bottom: 0; min-height: var(--status-h); padding: 5px 16px 6px; line-height: 18px; background: inherit; color: inherit; border-top: 1px solid var(--md-well); }
#status[data-level="warn"] { background: var(--warn-container); color: var(--on-warn-container); }
#status[data-level="error"] { background: var(--md-error-container); color: var(--md-error); }
#status:has(.rom-pick) #status-text { padding-right: 200px; }
.rom-pick { position: absolute; right: 8px; bottom: 0; top: 0; margin: auto 0; z-index: 1; }

/* ---- menus, tooltips, dialogs (P10) ---- */
.menu { position: fixed; z-index: 50; width: max-content; min-width: 180px; max-width: calc(100vw - 16px); padding: 6px 0; border-radius: var(--radius-xs); background: var(--md-surface-highest); box-shadow: 0 8px 28px rgba(0, 0, 0, 0.5); }
.menu button { position: relative; isolation: isolate; display: flex; align-items: center; gap: 10px; width: 100%; height: 40px; padding: 0 16px 0 12px; border: 0; background: none; text-align: left; cursor: pointer; }
.menu button:focus-visible { outline: none; background: color-mix(in srgb, var(--md-on-surface) 12%, transparent); }
.menu button[aria-disabled="true"] > span { color: color-mix(in srgb, var(--md-on-surface) 38%, transparent); }
.menu .why { margin-left: auto; padding-left: 16px; color: var(--md-outline); font-size: 12px; }
.menu .check { width: 20px; }
.menu button.has-sub > .icon:last-child { margin-left: auto; color: var(--md-outline); }
.menu button.has-sub[aria-expanded="true"] { background: color-mix(in srgb, var(--md-on-surface) 8%, transparent); }
.menu .menu-back { font-weight: 640; border-bottom: 1px solid var(--md-outline-variant); margin-bottom: 4px; }
.menu-divider { margin: 6px 0; border-top: 1px solid var(--md-outline-variant); }
.menu-divider span { display: block; padding: 8px 16px 2px; font-size: 12px; color: var(--md-outline); }
.tooltip { position: fixed; z-index: 60; max-width: 320px; padding: 6px 10px; border-radius: var(--radius-xs); background: var(--md-on-surface); color: var(--md-surface); font-size: 12px; pointer-events: none; }
/* Material's dialog, as the 8800 simulator's: a title band with its close button, the body,
   the actions at the bottom right, the one it is for filled */
.dialog { width: min(480px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 0; border: 0; border-radius: var(--radius-xl); background: var(--md-surface-high); color: var(--md-on-surface); box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55); overflow: hidden; }
.dialog[open] { display: flex; flex-direction: column; }
.dialog::backdrop { background: var(--md-scrim); }
.dialog-head { flex: none; display: flex; align-items: center; justify-content: space-between; padding: 18px 14px 6px 24px; }
.dialog-head h2 { margin: 0; font-size: 22px; font-weight: 400; line-height: 28px; }
.dialog-body { min-height: 0; overflow-y: auto; padding: 8px 24px 20px; }
.dialog-body h3 { margin: 16px 0 6px; font-size: 14px; font-weight: 500; color: var(--md-on-surface-variant); }
.dialog-text { margin: 0 0 12px; font-size: 14px; line-height: 1.5; color: var(--md-on-surface-variant); }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.dialog-actions .btn { line-height: 1.15; }
.dialog-actions .choice-label { display: inline-flex; flex-direction: column; align-items: flex-start; }
.dialog-actions .btn .why { font-size: 11px; font-weight: 400; opacity: 0.8; }
.dialog-actions .btn[aria-disabled="true"] { opacity: 0.55; }
.program-listing { margin: 10px 0 4px; padding: 8px 10px; max-height: 11.5em; overflow: auto; border-radius: var(--radius-xs); background: var(--md-well); font-family: var(--mono); font-size: 12px; line-height: 1.45; white-space: pre; user-select: text; -webkit-user-select: text; }
.program-ways { margin: 10px 0 0; padding-left: 18px; font-size: 13px; line-height: 1.5; }
.program-faster { margin: 8px 0 0 -4px; }
.dialog-subhead { margin: 16px 0 2px; font-size: 14px; font-weight: 640; color: var(--md-on-surface); }
.originals-links { margin: 0 0 12px; padding-left: 18px; font-size: 14px; line-height: 1.5; color: var(--md-on-surface-variant); }
.originals-links li { margin: 0 0 6px; }
.originals-links a { color: var(--md-primary); font-weight: 560; }
.dialog-actions .btn:not(.filled) { color: var(--md-primary-text); }
.about-band { display: flex; gap: 16px; align-items: center; margin: 4px 0 14px; }
.about-band img { width: 56px; height: 56px; }
.about-band strong { font-size: 18px; font-weight: 600; }
.about-band .version { color: var(--md-on-surface-variant); font-size: 13px; }
.about-links { margin: 0; padding: 0; list-style: none; font-size: 14px; line-height: 1.5; }
.about-links li { padding: 2px 0; }
/* what, then whose: a label column as wide as the longest label */
.about-licences { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; font-size: 13px; line-height: 1.5; }
.about-licences dt { color: var(--md-on-surface-variant); }
.about-licences dd { margin: 0; }
.about-trademark { margin: 16px 0 0; font-size: 12px; }
/* the References tab: one column down the middle of the dock, as a lesson is */
.references { max-width: 780px; margin: 0 auto; padding: 4px 0 8px; line-height: 1.5; }
.references h3 { margin: 16px 0 6px; font-size: 14px; font-weight: 600; color: var(--md-on-surface-variant); }
.references h3:first-child { margin-top: 6px; }
.plain-list, .link-list { margin: 0; padding: 0 0 0 18px; }
.plain-list li, .link-list li { margin: 3px 0; }
.link-list a { text-decoration: none; }
.refs-more { margin-top: 20px; }
.refs-more .plain-list { margin: 4px 0 6px; color: var(--md-on-surface-variant); }
.link-list a:hover, .link-list a:focus-visible { text-decoration: underline; }
.selftest { position: fixed; right: 12px; bottom: 40px; z-index: 40; width: 440px; max-height: 60vh; overflow: auto; padding: 10px 14px; border-radius: var(--radius-m); background: var(--md-surface-highest); font-size: 12px; }
.selftest .pass { color: var(--on); }
.selftest .fail { color: var(--md-error); }

/* ---- narrower windows ---- */
/* the tape beside its card while both fit (it scales), under it when not */
.tape-tool { flex-wrap: wrap; }
.tape-tool .tool-main { flex: 1 1 420px; }
@media (max-width: 660px) {
  .cpu-tool { width: auto; }
  .cpu-grid { grid-template-columns: minmax(0, 1fr); width: 100%; }
}
@media (max-width: 1100px) {
  .tool:not(.tape-tool) { flex-wrap: wrap; }
  .lesson-companion { flex-basis: 420px; }
}
@media (max-width: 860px) {
  .strip-label { display: none; }
  .strip-body { gap: 6px; padding: 4px 6px; }
  .strip-body .btn.small.has-icon { padding: 0 9px; }
  .lesson-body { flex-direction: column-reverse; }
  .lesson-companion { position: static; width: 100%; flex: none; max-height: none; }
  .dock-tab span { display: none; }
  .dock-tab { padding: 0 12px; }
}
/* a phone, upright (P9): the display, then the main keys; the recorder in a drawer */
@media (max-width: 700px) {
  .program-listing { font-size: 10.5px; }
  :root { --bar-h: 48px; }
  #topbar .label, .brand-name { display: none; }
  #topbar { padding: 0 4px 0 10px; }
  #stage { padding: 0 6px 6px; }
  #band { height: 44px; gap: 4px; }
  .tools3d .joined, .tools3d .home-btn { display: none; }
  .segmented.mode .icon { display: none; }
  .segmented.mode button { padding: 0 10px; }
  .drawers .btn span { display: none; }
  .drawers .btn.small.has-icon { padding: 0 10px; }
  .flat { padding: 8px 6px; gap: 8px; }
  .flat-key { font-size: min(2.6cqw, var(--fit, 2.6cqw)); }
  .tool-side, .vram-inspector { min-width: 0; flex-basis: 100%; }
  .dock-pane { padding: 4px 10px calc(12px + var(--status-rise, 0px)); }
  #pane-lessons { padding-top: 0; }
  .lesson-bar { margin: 0 -10px; padding-left: 10px; padding-right: 10px; }
  .put-back span { display: none; }
  .put-back { width: 48px; padding: 0; }
}
/* a phone on its side: the display and the recorder; the keyboard in a drawer */
@media (max-height: 520px) and (orientation: landscape) {
  .flat { padding-top: 8px; }
  .flat .flat-kbd, .flat:not([data-kbd="open"]) .flat-kbd { display: none; }
  .flat[data-kbd="open"] .flat-kbd { display: flex; position: absolute; left: 8px; right: 8px; bottom: 8px; height: 55%; z-index: 3; container-type: size; filter: drop-shadow(0 -6px 20px rgba(0, 0, 0, 0.6)); }
  .flat-keyboard { width: min(100cqw, 100cqh * var(--ar)); }
}
