/* Stapelwerk interface. Panels are separated by line weights, not boxes:
   --w3 ink for major divisions, --w2 ink between stacked panes, --w1 mid
   for columns, faint hairlines for rows. */

*, *::before, *::after { box-sizing: border-box; }

html {
  font-family: var(--font-ui);
  font-size: 100%;
  line-height: 1.45;
  color: var(--ink);
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  font-kerning: normal;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font-size: var(--fs-m);
}

::selection { background: var(--blue-wash); color: var(--ink); }
:focus-visible { outline: var(--w3) solid var(--blue); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }

h1, h2, h3, h4 { margin: 0; line-height: 1.2; font-weight: 650; letter-spacing: -0.005em; text-wrap: balance; }
p { margin: 0; }
a { color: var(--blue); text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
a:hover { color: var(--blue-strong); text-decoration-thickness: 2px; }
code, kbd, pre, .mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums slashed-zero; }
kbd {
  font-size: 0.72rem;
  padding: 0 0.35em;
  border: var(--w1) solid var(--rule-mid);
  border-bottom-width: var(--w3);
  border-radius: var(--radius);
  color: var(--ink-2);
  background: var(--paper-3);
  line-height: 1.5;
  white-space: nowrap;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
img, svg, canvas { display: block; }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

.muted { color: var(--ink-2); }
.ok { color: var(--stamp); }
.bad { color: var(--pencil); }

.skip {
  position: absolute; left: var(--s2); top: -40px; z-index: 50;
  background: var(--paper-3); color: var(--ink); padding: var(--s2) var(--s3);
  border: var(--w2) solid var(--rule);
}
.skip:focus { top: var(--s2); }

/* ------------------------------------------------------------ icons */
.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: square; stroke-linejoin: miter; }
.icon-run path { fill: currentColor; stroke-linejoin: round; }

/* ------------------------------------------------------------ app bar */
.appbar {
  position: sticky; top: 0; z-index: 20;
  height: var(--appbar-h);
  display: flex; align-items: center; gap: var(--s5);
  padding: 0 var(--s4);
  background: var(--head-bg);
  color: var(--head-ink);
  border-bottom: var(--w1) solid var(--head-rule);
}
.brand {
  display: inline-flex; align-items: center; gap: var(--s2);
  color: var(--head-ink); text-decoration: none;
  font-weight: 750; font-size: var(--fs-l); letter-spacing: 0.01em;
}
.brand:hover { color: var(--head-ink); }
.logo { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.5; }
.logo .logo-top { fill: currentColor; }
.logo .logo-dim { stroke-width: 1.2; }
.mainnav { display: flex; gap: var(--s1); height: 100%; }
.mainnav a {
  display: inline-flex; align-items: center;
  padding: 0 var(--s3);
  color: var(--head-ink-2); text-decoration: none; font-weight: 550;
  border-bottom: var(--w4) solid transparent; border-top: var(--w4) solid transparent;
}
.mainnav a:hover { color: var(--head-ink); }
.mainnav a[aria-current='page'] { color: var(--head-ink); border-bottom-color: var(--head-ink); }
/* five links (with Setzwerk) must fit next to brand and tools down to 760px */
@media (min-width: 760px) and (max-width: 1023px) {
  .appbar { gap: var(--s3); }
  .mainnav a { padding: 0 var(--s2); }
}
.appbar-tools { margin-left: auto; display: flex; align-items: center; gap: var(--s2); }
.lang-link { color: var(--head-ink-2); text-decoration: none; font-weight: 550; padding: var(--s2); }
.lang-link:hover { color: var(--head-ink); text-decoration: underline; }
.appbar .icon-btn { color: var(--head-ink); }
.appbar .icon-btn:hover { background: color-mix(in srgb, var(--head-ink) 12%, transparent); }
.appbar :focus-visible { outline-color: var(--head-ink); }

/* ------------------------------------------------------------ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 36px; padding: 0 var(--s3);
  background: transparent; color: var(--ink);
  border: var(--w1) solid var(--rule-mid); border-radius: var(--radius);
  font-weight: 600; font-size: var(--fs-m); line-height: 1.1;
  text-decoration: none; white-space: nowrap;
  transition: background-color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.btn:hover { background: var(--paper-3); border-color: var(--rule); color: var(--ink); }
.btn:active { background: var(--ink); color: var(--paper); }
.btn[aria-disabled='true'], .btn:disabled { color: var(--ink-3); border-style: dashed; cursor: default; background: transparent; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: var(--blue-on); }
.btn-primary:hover { background: var(--blue-strong); border-color: var(--blue-strong); color: var(--blue-on); }
.btn-primary kbd { background: transparent; color: inherit; border-color: color-mix(in srgb, var(--blue-on) 55%, transparent); opacity: 0.85; }
.btn-quiet { border-color: transparent; color: var(--blue); }
.btn-quiet:hover { border-color: var(--rule-mid); color: var(--blue-strong); }
.btn-small { min-height: 28px; padding: 0 var(--s2); font-size: var(--fs-s); }
.btn-danger { background: var(--pencil); border-color: var(--pencil); color: var(--paper-3); }
.btn-danger-quiet { color: var(--pencil); border-color: color-mix(in srgb, var(--pencil) 50%, transparent); }
.btn-danger-quiet:hover { color: var(--pencil); border-color: var(--pencil); }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px; padding: 0;
  background: transparent; border: 0; border-radius: var(--radius); color: var(--ink-2);
}
.icon-btn:hover { background: var(--paper-2); color: var(--ink); }
.icon-btn:disabled { color: var(--rule-mid); cursor: default; background: transparent; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 28px; padding: 0 var(--s2);
  background: transparent; border: var(--w1) solid var(--rule-faint); border-radius: var(--radius);
  color: var(--ink-2); font-size: var(--fs-s);
}
.chip:hover { border-color: var(--rule-mid); color: var(--ink); }
.chip[aria-pressed='true'] { border-color: var(--ink); color: var(--ink); background: var(--paper-3); font-weight: 600; }

.seg { display: inline-flex; border: var(--w1) solid var(--rule-mid); border-radius: var(--radius); }
.seg-btn {
  min-height: 26px; padding: 0 var(--s2);
  background: transparent; border: 0; border-left: var(--w1) solid var(--rule-faint);
  color: var(--ink-2); font-size: var(--fs-s); font-weight: 550;
}
.seg-btn:first-child { border-left: 0; }
.seg-btn[aria-pressed='true'] { background: var(--ink); color: var(--paper); }
.seg-btn:disabled { color: var(--rule-mid); cursor: default; }

input[type='text'], select {
  min-height: 32px; padding: 0 var(--s2);
  background: var(--paper-3); border: var(--w1) solid var(--rule-mid); border-radius: var(--radius);
}
input[type='text']:focus-visible, select:focus-visible { outline-offset: 0; }
input[aria-invalid='true'] { border-color: var(--pencil); box-shadow: inset 0 -2px 0 var(--pencil); }

/* switch */
.switch { display: inline-flex; align-items: center; gap: var(--s2); cursor: pointer; font-size: var(--fs-s); color: var(--ink-2); }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track { width: 34px; height: 18px; border: var(--w2) solid var(--ink-2); border-radius: var(--radius); position: relative; transition: background-color var(--t-fast); }
.switch-track::after { content: ''; position: absolute; top: 2px; left: 2px; width: 11px; height: 11px; border-radius: 1px; background: var(--ink-2); transition: transform var(--t-fast) var(--ease); }
.switch input:checked + .switch-track { background: var(--blue); border-color: var(--blue); }
.switch input:checked + .switch-track::after { transform: translateX(16px); background: var(--blue-on); }
.switch input:focus-visible + .switch-track { outline: var(--w3) solid var(--blue); outline-offset: 2px; }

/* ------------------------------------------------------------ pages */
#main { display: block; }
#main:focus { outline: none; }
.page { max-width: 1200px; margin: 0 auto; padding: var(--s6) var(--s5) var(--s8); }
.lede { font-size: var(--fs-l); color: var(--ink-2); max-width: 62ch; line-height: 1.45; }

.prose { max-width: 70ch; }
.prose > * + * { margin-top: var(--s3); }
.prose h2 { font-size: var(--fs-xl); margin-top: var(--s6); }
.prose h3 { font-size: var(--fs-l); margin-top: var(--s5); }
.prose h4 { font-size: var(--fs-m); margin-top: var(--s4); }
.prose ul { padding-left: 1.2em; margin-bottom: 0; }
.prose li + li { margin-top: var(--s1); }
.prose li::marker { color: var(--ink-3); }
.prose code { font-size: 0.88em; padding: 0 0.2em; background: var(--paper-2); border-radius: var(--radius); }
.prose pre {
  margin: var(--s3) 0 0; padding: var(--s3);
  background: var(--paper-3); border-left: var(--w1) solid var(--rule-mid);
  overflow-x: auto; font-size: var(--fs-s); line-height: 1.55;
}
.prose pre code { background: none; padding: 0; font-size: inherit; }
.prose a.term { font-weight: 600; }
.prose strong { font-weight: 700; }

/* ------------------------------------------------------------ chapter plan */
.page-plan { max-width: 1240px; }
.plan-head {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s6); align-items: end;
  padding-bottom: var(--s5); border-bottom: var(--w3) solid var(--rule);
}
.plan-head h1 { font-size: var(--fs-3xl); font-weight: 750; letter-spacing: -0.015em; margin-bottom: var(--s3); }
.plan-side { display: grid; justify-items: end; gap: var(--s3); }
.plan-count { color: var(--ink-2); font-size: var(--fs-s); }
.chapters { list-style: none; margin: 0; padding: 0; }
.chapter {
  display: grid; grid-template-columns: 56px minmax(0, 1fr); column-gap: var(--s4);
  padding: var(--s5) 0 var(--s6);
  border-bottom: var(--w1) solid var(--rule-faint);
}
.chapter-head { display: contents; }
.chapter-no {
  grid-row: 1 / span 2; align-self: start;
  width: 40px; height: 40px; display: grid; place-items: center;
  border: var(--w2) solid var(--ink); border-radius: 50%;
  font-size: var(--fs-l); font-weight: 600;
}
.chapter.is-complete .chapter-no { background: var(--ink); color: var(--paper); }
.chapter.is-locked .chapter-no { border-style: dashed; color: var(--ink-3); border-color: var(--ink-3); }
.chapter h2 { grid-column: 2; font-size: var(--fs-xl); display: flex; align-items: baseline; gap: var(--s3); }
.chapter-progress { grid-column: 2; justify-self: start; font-size: var(--fs-s); color: var(--ink-3); margin-top: 2px; }
.chapter.is-locked h2 { color: var(--ink-2); }

.stations {
  grid-column: 2; list-style: none; margin: var(--s4) 0 0; padding: 0;
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); column-gap: var(--s4);
  position: relative;
}
.station { position: relative; padding-top: 26px; min-width: 0; }
/* the dimension line runs through every node; the first segment starts at the node */
.station::before {
  content: ''; position: absolute; top: 8px; left: 0; right: calc(-1 * var(--s4));
  border-top: var(--w2) solid var(--ink);
}
.station:first-child::before { left: 8px; }
.station:last-child::before { right: auto; width: 0; }
.station::after { /* tick mark like a dimension chain */
  content: ''; position: absolute; top: 2px; left: 7px; height: 13px;
  border-left: var(--w1) solid var(--ink); transform: skewX(-40deg);
}
.station.is-locked::before { border-top-style: dashed; border-top-color: var(--rule-mid); }
.station.is-locked::after { border-left-color: var(--rule-mid); }
.st-link { display: grid; gap: 3px; text-decoration: none; color: var(--ink); padding: var(--s2) var(--s2) var(--s2) 0; border-radius: var(--radius); }
a.st-link:hover .st-title { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
.st-node {
  position: absolute; top: 0; left: 0; width: 18px; height: 18px;
  display: grid; place-items: center;
  background: var(--paper); border: var(--w2) solid var(--ink); border-radius: 50%;
  z-index: 1;
}
.st-node .icon { width: 12px; height: 12px; stroke-width: 2.4; }
.station.is-solved .st-node { background: var(--stamp); border-color: var(--stamp); color: var(--paper-3); }
.station.is-locked .st-node { border-style: dashed; border-color: var(--rule-mid); color: var(--ink-3); }
.station.is-locked .st-node .icon { width: 11px; height: 11px; stroke-width: 1.6; }
.station.is-next .st-node { border-color: var(--blue); box-shadow: 0 0 0 3px var(--paper), 0 0 0 5px var(--blue); }
.st-num { font-size: var(--fs-s); color: var(--ink-3); }
.st-title { font-weight: 650; font-size: var(--fs-m); line-height: 1.25; }
.st-card { font-size: var(--fs-s); color: var(--ink-2); line-height: 1.4; }
.st-tags { font-size: var(--fs-xs); color: var(--ink-3); letter-spacing: 0.01em; }
.st-badges { display: flex; gap: var(--s1); flex-wrap: wrap; }
.mini-badge { font-size: var(--fs-xs); font-weight: 650; color: var(--stamp); border: var(--w1) solid var(--stamp); border-radius: var(--radius); padding: 0 5px; }
.station.is-locked .st-title, .station.is-locked .st-card { color: var(--ink-3); }
.station.is-locked .st-link { cursor: not-allowed; }
.station.is-bonus .st-title::after { content: ' *'; color: var(--ink-3); font-weight: 400; }

/* ------------------------------------------------------------ site footer (legal notice, privacy) */
.sitefoot {
  max-width: 1200px; margin: 0 auto; padding: var(--s4) var(--s5) var(--s6);
  display: flex; flex-wrap: wrap; gap: var(--s2) var(--s5);
  font-size: var(--fs-s); border-top: var(--w1) solid var(--rule-faint);
}
.sitefoot a { color: var(--ink-3); }
.sitefoot a:hover { color: var(--ink); }
/* The workspace fills the viewport; the links stay one click away on every other page. */
html[data-view='level'] .sitefoot, html[data-view='sandbox'] .sitefoot { display: none; }

/* ------------------------------------------------------------ workspace */
html[data-view='level'] body, html[data-view='sandbox'] body { overflow: hidden; }
.ws {
  overflow-x: clip;
  grid-template-columns: minmax(0, 1fr);
  height: calc(100dvh - var(--appbar-h));
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  background: var(--paper);
}
.ws-head {
  display: flex; align-items: center; gap: var(--s4);
  padding: var(--s2) var(--s4) var(--s2);
  min-height: 44px;
}
.crumbs { display: flex; gap: var(--s2); font-size: var(--fs-s); color: var(--ink-3); white-space: nowrap; }
.crumbs a { color: var(--ink-2); }
.ws-title { font-size: var(--fs-l); font-weight: 700; display: flex; gap: var(--s2); align-items: baseline; min-width: 0; }
.ws-title:focus { outline: none; }
.ws-num { font-size: var(--fs-m); font-weight: 500; color: var(--ink-3); }
.status-chip {
  margin-left: auto; display: inline-flex; align-items: center; gap: 6px;
  font-size: var(--fs-s); color: var(--ink-2); white-space: nowrap;
}
.status-dot { width: 9px; height: 9px; border-radius: 50%; border: var(--w2) solid var(--ink-3); flex: none; }
.status-chip[data-kind='paused'] .status-dot, .status-chip[data-kind='running'] .status-dot { background: var(--blue); border-color: var(--blue); }
.status-chip[data-kind='halted'] .status-dot { background: var(--ink); border-color: var(--ink); }
.status-chip[data-kind='fault'] .status-dot, .status-chip[data-kind='budget'] .status-dot, .status-chip[data-kind='breakpoint'] .status-dot { background: var(--pencil); border-color: var(--pencil); }
.status-chip[data-kind='waiting'] .status-dot { border-color: var(--blue); }
.status-chip[data-kind='fault'], .status-chip[data-kind='budget'] { color: var(--pencil); font-weight: 600; }
.status-dirty { color: var(--ochre); }
.status-ok { color: var(--stamp); font-weight: 600; }
.status-bad { color: var(--pencil); font-weight: 600; }

.dbg {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s2) var(--s4);
  background: var(--paper-2);
  border-top: var(--w1) solid var(--rule-faint);
  border-bottom: var(--w3) solid var(--rule);
}
.dbg-group { display: flex; gap: var(--s1); }
.lbl-short { display: none; }
.dbg-btn { min-width: 0; }
.dbg-btn kbd, .dbg-primary kbd { margin-left: 2px; }
.dbg-btn[aria-pressed='true'] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.dbg-btn[aria-pressed='true'] kbd { background: transparent; color: inherit; }
.timeline { flex: 1; display: grid; grid-template-columns: auto minmax(120px, 1fr) minmax(0, auto); align-items: center; gap: var(--s3); min-width: 0; }
.timeline-label { font-size: var(--fs-s); color: var(--ink-2); font-weight: 600; }
.timeline-out { font-size: var(--fs-s); color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.timeline-out .tl-step { color: var(--ink); }
@media (max-width: 1599px) { .dbg-btn kbd { display: none; } }
@media (max-width: 1599px) { .timeline-out .tl-cyc { display: none; } }
.test-pick { display: inline-flex; align-items: center; gap: var(--s2); font-size: var(--fs-s); color: var(--ink-2); font-weight: 600; }
.test-select { font-family: var(--font-mono); font-size: var(--fs-s); min-height: 32px; max-width: 22ch; text-overflow: ellipsis; }

/* the timeline as a ruler */
.timeline-range { -webkit-appearance: none; appearance: none; width: 100%; height: 28px; background: transparent; cursor: pointer; }
.timeline-range::-webkit-slider-runnable-track {
  height: 12px;
  background:
    linear-gradient(var(--ink), var(--ink)) 0 100% / 100% var(--w2) no-repeat,
    repeating-linear-gradient(90deg, var(--rule-mid) 0 1px, transparent 1px 10%) 0 100% / 100% 7px no-repeat;
}
.timeline-range::-moz-range-track {
  height: 12px;
  background:
    linear-gradient(var(--ink), var(--ink)) 0 100% / 100% var(--w2) no-repeat,
    repeating-linear-gradient(90deg, var(--rule-mid) 0 1px, transparent 1px 10%) 0 100% / 100% 7px no-repeat;
}
.timeline-range::-webkit-slider-thumb { -webkit-appearance: none; width: 4px; height: 20px; margin-top: -4px; background: var(--blue); border: 0; border-radius: 1px; }
.timeline-range::-moz-range-thumb { width: 4px; height: 20px; background: var(--blue); border: 0; border-radius: 1px; }
.timeline-range:disabled { cursor: default; opacity: 0.45; }

.ws-mobile-tabs { display: none; }

.ws-grid {
  grid-row: 4;
  display: grid;
  grid-template-columns: minmax(0, 38fr) minmax(0, 25fr) minmax(0, 37fr);
  min-height: 0;
}
.ws-col { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.ws-col + .ws-col { border-left: var(--w1) solid var(--rule-mid); }
.pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.ws-col > .pane + .pane { border-top: var(--w2) solid var(--rule); }
.pane-head {
  display: flex; align-items: center; gap: var(--s3); justify-content: space-between;
  min-height: 36px; padding: var(--s1) var(--s4);
  border-bottom: var(--w1) solid var(--rule-faint);
}
.pane-head h2 { font-size: var(--fs-m); font-weight: 700; letter-spacing: 0.005em; }
.pane-note { font-size: var(--fs-xs); color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub-head { font-size: var(--fs-xs); font-weight: 650; color: var(--ink-2); letter-spacing: 0.02em; margin-bottom: var(--s1); }
.empty { padding: var(--s4); font-size: var(--fs-s); color: var(--ink-2); max-width: 46ch; }

/* column A: task above, code below */
.pane-task { flex: 0 1 40%; min-height: 140px; }
.pane-code { flex: 1 1 60%; min-height: 200px; }
.ws[data-mode='sandbox'] .pane-task { flex-basis: 34%; }
/* the result is the moment of the level: it gets the larger share of the column */
.pane-task:has(.tabpanel:not([hidden]) > .result-wrap) { flex-basis: 62%; }
.ws-col-a:has(.tabpanel:not([hidden]) > .result-wrap) .pane-code { flex-basis: 38%; }
.pane-task .tabs { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.pane-task .tabpanels { flex: 1; min-height: 0; overflow: auto; }
.pane-task .tabpanel { padding: var(--s3) var(--s4) var(--s4); }
.sandbox-panel { padding: var(--s3) var(--s4) var(--s4); overflow: auto; }
.sandbox-panel h2 { font-size: var(--fs-l); margin-top: 0; }

.tablist {
  display: flex; gap: var(--s1); padding: 0 var(--s3);
  border-bottom: var(--w1) solid var(--rule-faint);
  overflow-x: auto; scrollbar-width: none; flex: none;
}
.tab {
  position: relative; min-height: 36px; padding: 0 var(--s2);
  background: transparent; border: 0; color: var(--ink-2); font-weight: 600; font-size: var(--fs-s);
  white-space: nowrap;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected='true'] { color: var(--ink); }
.tab[aria-selected='true']::after { content: ''; position: absolute; left: var(--s2); right: var(--s2); bottom: -1px; border-bottom: var(--w4) solid var(--blue); }
.tabpanel:focus-visible { outline-offset: -3px; }

.task { font-size: var(--fs-m); }
.task p { line-height: 1.5; }
.checklist {
  margin-top: var(--s4); padding: var(--s2) 0 var(--s1); border-top: var(--w2) solid var(--ink);
  /* stays in view at the foot of the task pane while the text scrolls above it */
  position: sticky; bottom: 0; background: var(--paper);
}
.checklist h3 { font-size: var(--fs-s); margin: 0 0 var(--s2); color: var(--ink-2); }
.checklist ul { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(2, minmax(0, max-content)); gap: var(--s1) var(--s5); }
.checklist li { display: flex; align-items: center; gap: var(--s2); font-size: var(--fs-s); color: var(--ink-2); }
.checklist li.is-done { color: var(--ink); }
.check-box { width: 16px; height: 16px; border: var(--w2) solid var(--ink-3); display: grid; place-items: center; flex: none; }
.is-done .check-box { border-color: var(--stamp); background: var(--stamp); color: var(--paper-3); }
.check-box .icon { width: 12px; height: 12px; stroke-width: 2.6; }
.hints .hint { padding-top: var(--s3); border-top: var(--w1) solid var(--rule-faint); }
.hints .hint h3 { font-size: var(--fs-s); color: var(--ink-2); margin: 0 0 var(--s2); }
.hints .btn { margin-top: var(--s3); }

/* tests */
.tests-summary { font-size: var(--fs-s); margin-bottom: var(--s2); color: var(--ink-2); }
.tests { list-style: none; margin: 0; padding: 0; }
.test {
  display: grid; grid-template-columns: 22px minmax(0, auto) minmax(0, 1fr) auto auto; align-items: center; column-gap: var(--s2);
  padding: 6px 0; border-bottom: var(--w1) solid var(--rule-faint); font-size: var(--fs-s);
}
.test-mark { display: grid; place-items: center; width: 20px; height: 20px; }
.test-mark .icon { width: 16px; height: 16px; stroke-width: 2.2; }
.test.is-passed .test-mark { color: var(--stamp); }
.test.is-failed .test-mark { color: var(--pencil); }
.test.is-pending .test-mark::before { content: ''; width: 10px; height: 10px; border: var(--w1) dashed var(--ink-3); border-radius: 50%; }
.test-name { font-weight: 500; white-space: nowrap; }
.test-io { color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: var(--fs-xs); }
.test-cyc { color: var(--ink-3); font-size: var(--fs-xs); white-space: nowrap; }
.test.is-current .test-name { text-decoration: underline; text-decoration-color: var(--blue); text-decoration-thickness: 2px; text-underline-offset: 4px; }
.test-why { grid-column: 2 / -1; color: var(--pencil); font-size: var(--fs-s); padding: 2px 0 2px; }
.test-hidden { grid-template-columns: 22px auto minmax(0, 1fr); }
.test-hidden .test-name { font-family: var(--font-ui); }

/* notices */
.notice {
  display: flex; gap: var(--s2); align-items: flex-start;
  padding: var(--s2) var(--s4); font-size: var(--fs-s); line-height: 1.4;
  border-bottom: var(--w1) solid currentColor;
}
.notice .icon { width: 16px; height: 16px; margin-top: 1px; stroke-width: 2.2; }
.notice-error { color: var(--pencil); background: var(--pencil-wash); }
.notice-error span, .notice-warn span, .notice-ok span { color: var(--ink); }
.notice-warn { color: var(--ochre); background: var(--ochre-wash); }
.notice-ok { color: var(--stamp); background: var(--stamp-wash); }

/* ------------------------------------------------------------ editor */
.editor { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.ed-frame { position: relative; display: grid; grid-template-columns: auto minmax(0, 1fr); flex: 1; min-height: 0; background: var(--paper-3); }
.ed-gutter {
  position: relative; overflow: hidden;
  background: var(--paper); border-right: var(--w1) solid var(--rule-faint);
  font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--ink-3);
  user-select: none; cursor: default;
}
.ed-gutter-inner { padding: var(--s2) 0; will-change: transform; }
.gl {
  height: var(--lh-code); display: grid; grid-template-columns: 3.4ch 14px 3ch 12px; align-items: center; column-gap: 2px;
  padding-left: var(--s2);
}
.gl.is-code { cursor: pointer; }
@media (hover: hover) { .gl.is-code:hover .gl-bp { background: radial-gradient(circle, var(--rule-mid) 0 3px, transparent 3.5px); } }
.gl-count { text-align: right; color: var(--blue); opacity: 0.85; font-size: 0.68rem; }
.gl-no { text-align: right; }
.gl-bp { display: grid; place-items: center; height: 100%; }
.bp-mark { width: 10px; height: 10px; fill: var(--pencil); }
.gl.is-current .gl-no { color: var(--ink); font-weight: 600; }
.gl.is-current .gl-pc::before {
  content: ''; display: block; width: 7px; height: 10px; margin-left: 2px;
  background: var(--blue); clip-path: polygon(0 0, 100% 50%, 0 100%);
}
.gl.has-error .gl-no { color: var(--pencil); font-weight: 600; }
.ed-body { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
.ed-back, .ed-text {
  font-family: var(--font-mono); font-size: var(--fs-code); line-height: var(--lh-code);
  tab-size: 8; -moz-tab-size: 8; white-space: pre; letter-spacing: 0;
  font-variant-ligatures: none;
}
.ed-back { position: absolute; inset: 0; overflow: hidden; pointer-events: none; color: transparent; }
.ed-back-inner {
  position: relative;
  padding: var(--s2) var(--s3);
  min-height: 100%;
  width: max-content; min-width: 100%;
  will-change: transform;
}
/* column rules (coding-sheet discipline): label | instruction from col 9 | comment from col 28 */
.ed-back-inner::before, .ed-back-inner::after {
  content: ''; position: absolute; top: 0; bottom: 0; width: 0;
  border-left: var(--w1) dashed var(--rule-faint);
}
.ed-back-inner::before { left: calc(var(--s3) + 8ch - 3px); }
.ed-back-inner::after { left: calc(var(--s3) + 27ch - 3px); }
.bl { height: var(--lh-code); }
.bl.is-current { background: var(--blue-wash); box-shadow: inset 3px 0 0 var(--blue); margin: 0 calc(-1 * var(--s3)); padding: 0 var(--s3); }
.bl.has-error { background: var(--pencil-wash); margin: 0 calc(-1 * var(--s3)); padding: 0 var(--s3); }
.bl.is-hot { background: var(--ochre-wash); margin: 0 calc(-1 * var(--s3)); padding: 0 var(--s3); box-shadow: inset 3px 0 0 var(--ochre); }
.gl.is-hot .gl-count { color: var(--ochre); font-weight: 600; opacity: 1; }
.bl .err { text-decoration: underline wavy var(--pencil); text-decoration-thickness: 1.5px; text-underline-offset: 3px; }
.ed-text {
  position: absolute; inset: 0; width: 100%; height: 100%;
  margin: 0; padding: var(--s2) var(--s3);
  background: transparent; color: var(--ink); caret-color: var(--blue);
  border: 0; resize: none; overflow: auto;
}
.ed-text:focus-visible { outline: var(--w3) solid var(--blue); outline-offset: -2px; }
.ed-text::selection { background: color-mix(in srgb, var(--blue) 26%, transparent); }
.ed-palette { display: none; }
.ed-errors { list-style: none; margin: 0; padding: var(--s1) 0; max-height: 30%; overflow: auto; border-top: var(--w2) solid var(--pencil); background: var(--paper); flex: none; }
.ed-error {
  display: block; width: 100%; text-align: left; padding: 4px var(--s4);
  background: transparent; border: 0; color: var(--ink); font-size: var(--fs-s); line-height: 1.4;
}
.ed-error:hover { background: var(--pencil-wash); }
.ed-error-pos { color: var(--pencil); font-size: var(--fs-xs); font-weight: 600; margin-right: var(--s1); }

/* ------------------------------------------------------------ registers */
.pane-regs { flex: none; }
.regs { padding: var(--s1) var(--s4) 0; }
.reg-group + .reg-group { margin-top: var(--s2); }
.reg-group-head { font-size: var(--fs-xs); color: var(--ink-3); padding: 2px 0; border-bottom: var(--w1) solid var(--rule-faint); }
.reg-group dl { margin: 0; }
.reg {
  display: grid; grid-template-columns: 3ch minmax(0, 1fr); align-items: center; column-gap: var(--s2);
  height: 26px; border-bottom: var(--w1) solid var(--rule-faint);
}
.reg dt { font-weight: 600; font-size: var(--fs-s); }
.reg dd { margin: 0; display: flex; align-items: center; justify-content: flex-end; gap: var(--s1); min-width: 0; }
.reg-val {
  display: inline-flex; align-items: baseline; justify-content: flex-start; gap: var(--s2);
  flex: 1; min-width: 0; height: 22px; padding: 0 var(--s1);
  background: transparent; border: 0; border-radius: var(--radius); text-align: right;
}
.reg-val .hex { font-size: var(--fs-s); color: var(--ink-3); letter-spacing: 0.02em; }
.reg-val .dec { font-size: var(--fs-s); font-weight: 500; color: var(--ink); min-width: 8ch; text-align: right; }
.reg-val:not([aria-disabled='true']):hover { background: var(--paper-3); box-shadow: inset 0 -1px 0 var(--blue); }
.reg-val[aria-disabled='true'] { cursor: default; }
.reg.is-changed .reg-val { background: var(--hatch); }
.reg.is-changed .reg-val .dec { color: var(--pencil); text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; }
.reg-old { margin-left: auto; font-size: var(--fs-xs); color: var(--pencil); text-decoration-thickness: 1.5px; opacity: 0.9; white-space: nowrap; }
/* after a run: the same quiet rule as for memory bytes (thin underline, old value in grey) */
.reg.is-touched .reg-val .dec { text-decoration: underline; text-decoration-color: var(--ink-3); text-decoration-thickness: 1px; text-underline-offset: 3px; }
input.reg-input { width: 100%; height: 22px; min-height: 22px; text-align: right; font-size: var(--fs-s); border-color: var(--blue); }
.reg-back { width: 24px; height: 24px; color: var(--ink-3); }
.reg-back .icon { width: 15px; height: 15px; }
.reg.is-sp dt, .reg.is-fp dt { color: var(--blue); }
.flags-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s2) var(--s4) var(--s3); }
.flags-row .sub-head { margin: 0; }
.flags { display: flex; gap: var(--s1); }
.flag {
  display: inline-flex; align-items: center; gap: 4px; height: 26px; padding: 0 var(--s2);
  background: transparent; border: var(--w1) solid var(--rule-mid); border-radius: var(--radius);
  font-size: var(--fs-s);
}
.flag .flag-name { font-weight: 600; }
.flag .flag-bit { color: var(--ink-3); }
.flag.is-on { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.flag.is-on .flag-bit { color: var(--paper); opacity: 0.75; }
.flag.is-changed { box-shadow: 0 2px 0 var(--pencil); }
.flag.is-changed:not(.is-on) { background: var(--hatch); }
.flag.is-touched { box-shadow: 0 1px 0 var(--ink-3); }
.flag[aria-disabled='true'] { cursor: default; }

/* ------------------------------------------------------------ stack */
.pane-stack { flex: 1; }
.stack-scroll { flex: 1; min-height: 0; overflow: auto; }
.stack-wrap { display: grid; grid-template-columns: 56px minmax(0, 1fr); padding: 0 var(--s4) 28px 0; } /* room below sp for the whole-row scroll */
.dims { width: 56px; overflow: visible; }
.dim { stroke: var(--ink); stroke-width: 1.25; fill: none; }
.dim-ext { stroke: var(--rule-mid); stroke-width: 0.8; }
.dim-tick { stroke-width: 1.4; }
.dim-ret.dim-current:not(.dim-label) { stroke: var(--blue); }
.dim-label { fill: var(--ink); stroke: none; font-family: var(--font-mono); font-size: 11.5px; font-weight: 600; }
.dim-ret.dim-current.dim-label { fill: var(--blue); }
.stack { width: 100%; border-collapse: collapse; font-size: var(--fs-s); }
.stack th, .stack td { text-align: left; padding: 0 var(--s2) 0 0; height: 24px; border-bottom: var(--w1) solid var(--rule-faint); white-space: nowrap; }
.stack thead th { font-size: var(--fs-xs); font-weight: 650; color: var(--ink-3); height: 26px; position: sticky; top: 0; background-color: var(--paper); background-image: none; z-index: 3; box-shadow: 0 1px 0 var(--rule-faint); }
.stack-scroll { background: var(--paper); }
/* the sticky head also covers the dimension column, so chains slide under it */
.stack thead th.c-ptr::before { content: ''; position: absolute; top: 0; bottom: 0; right: 100%; width: 56px; background: var(--paper); box-shadow: 0 1px 0 var(--rule-faint); }
.stack .c-ptr { width: 4ch; color: var(--blue); font-size: var(--fs-xs); font-weight: 600; text-align: right; padding-right: var(--s2); }
.stack .c-addr { font-weight: 400; color: var(--ink-3); width: 6ch; }
.stack .c-val { font-weight: 500; }
.stack .c-val .dec { color: var(--ink-3); font-weight: 400; }
.stack .c-mean { color: var(--ink-2); white-space: nowrap; max-width: 0; width: 100%; overflow: hidden; text-overflow: ellipsis; }
.stack tr.k-ret .c-mean, .stack tr.k-oldfp .c-mean { color: var(--ink); }
.stack tr.k-ret .c-val .dec, .stack tr.k-oldfp .c-val .dec { display: none; }
.stack tr.is-sp td, .stack tr.is-sp th { border-bottom: var(--w3) solid var(--blue); }
.stack tr.is-changed .c-val { background: var(--hatch); color: var(--pencil); }
.stack tr.is-touched .c-val { box-shadow: inset 0 -1px 0 var(--ink-3); }
.stack tr.frame-head th {
  height: 26px; padding-top: 6px; vertical-align: bottom;
  border-bottom: var(--w1) solid var(--rule-faint); border-top: var(--w2) solid var(--ink);
  font-weight: 500; font-size: var(--fs-xs); color: var(--ink-2);
}
.stack tr.frame-head .frame-name { font-weight: 600; color: var(--ink); font-size: var(--fs-s); }
.stack tr.more td { color: var(--ink-3); font-size: var(--fs-xs); }

/* ------------------------------------------------------------ screen */
.pane-screen { flex: none; }
.screen-body { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--s4); align-items: start; padding: var(--s4) var(--s4) var(--s3) calc(var(--s4) + 18px); }
.screen-frame {
  position: relative; width: clamp(160px, 17vw, 256px); aspect-ratio: 1; margin-top: 14px;
  outline: var(--w1) solid var(--ink); outline-offset: 0;
  touch-action: none; cursor: crosshair;
}
.screen-canvas, .screen-overlay { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; image-rendering: crisp-edges; }
.screen-overlay { pointer-events: none; image-rendering: auto; }
.screen-ticks { position: absolute; inset: 0; pointer-events: none; font-family: var(--font-mono); font-size: 9.5px; color: var(--ink-3); }
.tick-x, .tick-y { position: absolute; line-height: 1; }
.tick-x { top: -13px; transform: translateX(-50%); }
.tick-y { left: -6px; transform: translate(-100%, -50%); }
.tick-x[data-v='0'] { left: 0; transform: none; }
.tick-x[data-v='16'] { left: 25%; }
.tick-x[data-v='32'] { left: 50%; }
.tick-x[data-v='48'] { left: 75%; }
.tick-x[data-v='64'] { left: 100%; transform: translateX(-100%); }
.tick-y[data-v='16'] { top: 25%; }
.tick-y[data-v='32'] { top: 50%; }
.tick-y[data-v='48'] { top: 75%; }
.tick-y[data-v='64'] { top: 100%; transform: translate(-100%, -100%); }
.screen-side { padding-top: 14px; min-width: 0; }
.screen-info { display: grid; gap: 3px; font-size: var(--fs-xs); color: var(--ink); }
.screen-info span { display: flex; align-items: center; gap: 6px; }
.screen-info b { color: var(--ink-3); font-weight: 400; }
.screen-info .muted, .tape .muted { font-family: var(--font-ui); font-size: var(--fs-s); }
.screen-info .is-wrong { color: var(--pencil); font-weight: 600; }
.swatch { display: inline-block; width: 12px; height: 12px; outline: var(--w1) solid var(--rule-mid); flex: none; }

/* ------------------------------------------------------------ console */
.pane-console { flex: 0 1 auto; min-height: 120px; max-height: 32%; }
.console-in { padding: var(--s2) var(--s4) 0; }
.console-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 0.6fr); gap: var(--s4); padding: var(--s2) var(--s4) var(--s3); min-height: 0; flex: 1; overflow: auto; }
.console-grid:has(.console-col:nth-child(2)[hidden]) { grid-template-columns: minmax(0, 1fr); }
.tape { font-size: var(--fs-s); line-height: 1.55; white-space: pre-wrap; word-break: break-all; }
.tape-in { display: flex; flex-wrap: wrap; gap: 2px var(--s2); }
.i-int { padding: 0 2px; border-bottom: var(--w2) solid transparent; }
.i-int.is-read { color: var(--ink-3); }
.i-int.is-next { border-bottom-color: var(--blue); color: var(--ink); font-weight: 600; }
.tape-out, .tape-exp { display: flex; flex-direction: column; align-items: flex-start; }
.tape-out { max-height: 120px; overflow: auto; }
.o-int { min-width: 4ch; }
.o-int.is-wrong { color: var(--pencil); text-decoration: line-through; }
.o-int.is-right { color: var(--stamp); }
.o-chr { white-space: pre-wrap; }
.console-form { display: flex; gap: var(--s2); padding: var(--s2) var(--s4) var(--s3); border-top: var(--w1) solid var(--rule-faint); flex-wrap: wrap; }
.console-form input { flex: 1; min-width: 8ch; }
.console-form.is-waiting input { border-color: var(--blue); box-shadow: inset 0 -2px 0 var(--blue); }

/* ------------------------------------------------------------ memory tabs */
.pane-mem { flex: 1 1 0; min-height: 160px; }
.pane-mem .tabs { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.pane-mem .tabpanels { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.pane-mem .tabpanel { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.pane-mem .tabpanel > * { flex: 1; min-height: 0; }

.hexdump { display: flex; flex-direction: column; min-height: 0; }
.hex-tools { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); padding: var(--s2) var(--s4) 0; flex-wrap: wrap; }
.chips { display: flex; gap: var(--s1); flex-wrap: wrap; }
.seg-swatch { width: 8px; height: 8px; display: inline-block; }
.seg-text .seg-swatch { background: var(--seg-text); }
.seg-data .seg-swatch { background: var(--seg-data); }
.seg-input .seg-swatch { background: var(--seg-input); }
.seg-heap .seg-swatch { background: var(--seg-heap); }
.seg-stack .seg-swatch { background: var(--seg-stack); }
.seg-screen .seg-swatch { background: var(--seg-screen); }
.hex-range { font-size: var(--fs-xs); color: var(--ink-3); padding: var(--s2) var(--s4) var(--s1); }
.hex-scroll { flex: 1; min-height: 0; overflow: auto; padding: 0 var(--s4) var(--s2); }
.hex-spacer { position: relative; }
.hex-rows { will-change: transform; }
.hexdump { container-type: inline-size; }
.hex-row { display: grid; grid-template-columns: 5ch auto 16ch minmax(0, 1fr); column-gap: var(--s3); height: 20px; align-items: center; font-family: var(--font-mono); font-size: 12px; }
.hex-addr { color: var(--ink-3); }
.hex-cells { display: flex; gap: 0.5ch; }
.hex-cells.is-word { gap: 1ch; }
.hx { padding: 0 1px; }
.hx.is-zero { color: var(--ink-3); opacity: 0.75; }
.hx.is-changed { background: var(--hatch-strong); color: var(--pencil); font-weight: 600; opacity: 1; }
.hx.is-touched { box-shadow: inset 0 -1px 0 var(--ink-3); color: var(--ink); }
.hx.is-pc { box-shadow: inset 0 -2px 0 var(--blue); }
.hx.is-sp { box-shadow: inset 0 -2px 0 var(--seg-stack); }
.hex-ascii { color: var(--ink-2); white-space: pre; letter-spacing: 0.02em; }
 @container (max-width: 560px) { .hex-row { grid-template-columns: 5ch auto minmax(0, 1fr); } .hex-ascii { display: none; } }
.hex-label { color: var(--blue); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--font-mono); }

.heapmap { padding: var(--s3) var(--s4); overflow: auto; display: block; }
.heap-sheet { border: var(--w1) solid var(--rule-mid); background: var(--paper-3); }
.heap-canvas { width: 100%; height: auto; image-rendering: pixelated; }
.legend { list-style: none; display: flex; flex-wrap: wrap; gap: var(--s1) var(--s4); padding: 0; margin: var(--s2) 0; font-size: var(--fs-xs); color: var(--ink-2); }
.legend li { display: flex; align-items: center; gap: 6px; }
.lg { width: 12px; height: 12px; display: inline-block; border: var(--w1) solid var(--rule-mid); background: var(--paper-3); }
.lg-live { background: var(--blue); border-color: var(--blue); }
.lg-freed { background: repeating-linear-gradient(135deg, var(--pencil) 0 1.5px, transparent 1.5px 4px); }
.lg-red { background: var(--ink); box-shadow: inset 0 0 0 2px var(--paper-3); }
.heap-table { width: 100%; border-collapse: collapse; font-size: var(--fs-s); }
.heap-table th, .heap-table td { text-align: left; padding: 3px var(--s2) 3px 0; border-bottom: var(--w1) solid var(--rule-faint); }
.heap-table th { font-size: var(--fs-xs); color: var(--ink-3); font-weight: 650; }
.heap-table .is-freed td { color: var(--ink-3); }

.manual-tab { padding: var(--s3) var(--s4); overflow: auto; display: block; }
.field-inline { display: flex; align-items: center; gap: var(--s2); font-size: var(--fs-s); color: var(--ink-2); font-weight: 600; margin-bottom: var(--s2); }
.manual-tab .prose h3 { font-size: var(--fs-l); margin-top: var(--s2); }
.manual-tab .prose { font-size: var(--fs-s); }

/* ------------------------------------------------------------ result */
.result { display: grid; gap: var(--s4); }
.result-head { display: flex; gap: var(--s4); align-items: center; }
.result-head h2 { font-size: var(--fs-xl); }
.result-head h2:focus { outline: none; }
.stamp {
  flex: none; display: grid; place-items: center;
  padding: 6px 12px; transform: rotate(-4deg);
  border: var(--w3) solid var(--stamp); outline: var(--w1) solid var(--stamp); outline-offset: 2px;
  color: var(--stamp); font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; font-size: var(--fs-s);
}
.metrics { width: 100%; border-collapse: collapse; font-size: var(--fs-s); }
.metrics th, .metrics td { padding: 6px var(--s2) 6px 0; border-bottom: var(--w1) solid var(--rule-faint); text-align: left; }
.metrics thead th { font-size: var(--fs-xs); color: var(--ink-3); font-weight: 650; border-bottom: var(--w2) solid var(--ink); }
.metrics tbody th { font-weight: 500; }
.metrics .num { text-align: right; font-size: var(--fs-m); font-weight: 600; }
.metrics .delta { font-size: var(--fs-xs); font-weight: 650; }
.metrics .delta.ok { color: var(--stamp); }
.metrics .delta.over { color: var(--ochre); }
.badges { list-style: none; display: grid; gap: var(--s2); padding: 0; margin: 0; }
.badge { display: flex; align-items: center; gap: var(--s2); font-size: var(--fs-s); color: var(--ink-2); }
.badge-mark { width: 22px; height: 22px; display: grid; place-items: center; border: var(--w2) dashed var(--rule-mid); border-radius: 50%; flex: none; }
.badge.is-earned .badge-mark { border-style: solid; border-color: var(--stamp); background: var(--stamp); color: var(--paper-3); }
.badge-mark .icon { width: 14px; height: 14px; stroke-width: 2.4; }
.badge.is-earned strong { color: var(--ink); }
.learned { padding-top: var(--s3); border-top: var(--w2) solid var(--ink); max-width: none; }
.learned h3 { font-size: var(--fs-l); margin-top: 0; }
.slot-row { display: flex; gap: var(--s2); flex-wrap: wrap; margin-top: var(--s2); }
.slots .muted { font-size: var(--fs-s); }
.btn-next { justify-self: start; }

/* ------------------------------------------------------------ sandbox */
.examples { list-style: none; padding: 0; margin: 0; display: grid; gap: 0; }
.example {
  width: 100%; display: grid; gap: 1px; text-align: left; padding: 6px var(--s2) 6px 0;
  background: transparent; border: 0; border-bottom: var(--w1) solid var(--rule-faint);
}
.example strong { color: var(--blue); font-size: var(--fs-m); }
.example .muted { font-size: var(--fs-s); }
.example:hover strong { text-decoration: underline; text-underline-offset: 0.18em; }
.share-out { width: 100%; margin-top: var(--s2); font-size: var(--fs-xs); }
.share-note { font-size: var(--fs-s); }

/* ------------------------------------------------------------ manual + about pages */
.page-manual { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: var(--s7); }
.toc { position: sticky; top: calc(var(--appbar-h) + var(--s5)); align-self: start; }
.toc-title { font-size: var(--fs-2xl); margin-bottom: var(--s4); }
.toc ol { list-style: none; padding: 0; margin: 0; border-left: var(--w1) solid var(--rule-mid); }
.toc a { display: block; padding: 5px var(--s3); color: var(--ink-2); text-decoration: none; margin-left: -1px; border-left: var(--w3) solid transparent; }
.toc a:hover { color: var(--ink); }
.toc a[aria-current='page'] { color: var(--ink); font-weight: 650; border-left-color: var(--blue); }
.manual-article h2 { font-size: var(--fs-2xl); margin-top: 0; padding-bottom: var(--s3); border-bottom: var(--w3) solid var(--rule); }
.page-about h1, .page-notfound h1 { font-size: var(--fs-3xl); margin-bottom: var(--s3); }
.page-about { max-width: 820px; }
.about-section { padding-top: var(--s3); }
.about-section h2 { padding-top: var(--s3); border-top: var(--w2) solid var(--rule); }
.button-row { display: flex; gap: var(--s2); flex-wrap: wrap; margin-top: var(--s3); }
.keys-table { border-collapse: collapse; font-size: var(--fs-s); width: 100%; max-width: 560px; }
.keys-table th, .keys-table td { padding: 6px var(--s3) 6px 0; text-align: left; border-bottom: var(--w1) solid var(--rule-faint); }
.keys-table thead th { font-size: var(--fs-xs); color: var(--ink-3); border-bottom: var(--w2) solid var(--ink); }
.page-notfound .btn { margin-top: var(--s5); }

/* dialogs */
.sheet {
  max-width: min(560px, calc(100vw - 32px)); width: 100%;
  padding: var(--s5); color: var(--ink); background: var(--paper-3);
  border: var(--w3) solid var(--ink); border-radius: var(--radius);
}
.sheet::backdrop { background: rgba(14, 26, 40, 0.42); }
.sheet h2 { font-size: var(--fs-xl); margin-bottom: var(--s3); }
.sheet p { margin-top: var(--s3); font-size: var(--fs-s); }
.sheet-actions { display: flex; gap: var(--s2); justify-content: flex-end; margin-top: var(--s5); }

/* ------------------------------------------------------------ tablet: two columns */
@media (max-width: 1199px) {
  .ws-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); overflow: hidden; }
  .ws-col-a { grid-row: 1 / span 2; }
  .ws-col-b { grid-column: 2; grid-row: 1; border-bottom: var(--w2) solid var(--rule); max-height: 50vh; overflow: auto; }
  .ws-col-c { grid-column: 2; grid-row: 2; border-left: var(--w1) solid var(--rule-mid); overflow: auto; }
  .ws-col-b .pane-stack { min-height: 200px; }
  .pane-console { max-height: none; }
  .pane-mem { min-height: 320px; }
  .timeline-label { display: none; }
  /* The select keeps its aria-label; the visible "Test case" label and the shortcut hint go. */
  .test-pick > span, .dbg-primary kbd { display: none; }
  .test-select { max-width: 18ch; }
  /* Label hidden: the ruler gives way to the step readout, which keeps its full text. */
  .timeline { grid-template-columns: minmax(40px, 1fr) minmax(0, max-content); }
  .timeline-out { min-width: min-content; max-width: 22ch; }
  .dbg-btn .btn-label { display: none; }
  .dbg-btn { padding: 0 var(--s2); }
  .stations { grid-template-columns: repeat(3, minmax(0, 1fr)); row-gap: var(--s4); }
  .station::before { right: calc(-1 * var(--s4)); }
  .station:nth-child(3n)::before { right: 0; }
}

/* Setzwerk: the code pane holds the source and the generated assembly side by side */
.ws[data-setz='1'] .ws-grid { grid-template-columns: minmax(0, 50fr) minmax(0, 20fr) minmax(0, 30fr); }
.setz-split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); flex: 1; min-height: 0; }
.setz-side { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.setz-side + .setz-side { border-left: var(--w1) solid var(--rule-mid); }
.setz-head {
  font-size: var(--fs-xs); font-weight: 650; color: var(--ink-2); letter-spacing: 0.02em;
  padding: var(--s1) var(--s4); border-bottom: var(--w1) solid var(--rule-faint); flex: none;
}
.setz-asm .ed-frame { background: var(--paper-2); }
@media (max-width: 1199px) {
  .ws[data-setz='1'] .ws-grid { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
}

/* compact heights (1366×768, 1280×720) */
@media (min-width: 1200px) and (max-height: 820px) {
  :root { --fs-code: 0.8125rem; --lh-code: 1.25rem; }
  .ws-head { min-height: 38px; padding-top: 4px; padding-bottom: 4px; }
  .dbg { padding-top: 6px; padding-bottom: 6px; }
  .pane-head { min-height: 32px; }
  .reg { height: 23px; }
  .reg-group + .reg-group { margin-top: 4px; }
  .flags-row { padding-top: 6px; padding-bottom: 8px; }
  .screen-body { padding-top: var(--s2); padding-bottom: var(--s2); }
  .screen-frame { width: clamp(150px, 13vw, 192px); }
  .pane-task { flex-basis: 38%; }
}

/* ------------------------------------------------------------ phone: one column with tabs */
@media (max-width: 759px) {
  :root { --appbar-h: 92px; }
  .appbar { height: auto; flex-wrap: wrap; row-gap: 0; padding: 0 var(--s3); gap: var(--s2); }
  .brand { height: 48px; }
  .mainnav { order: 3; width: calc(100% + 2 * var(--s3)); margin: 0 calc(-1 * var(--s3)); padding: 0 var(--s1); height: 44px; overflow-x: auto; border-top: var(--w1) solid var(--head-rule); }
  .mainnav a { padding: 0 var(--s2); white-space: nowrap; }
  .page { padding: var(--s5) var(--s4) var(--s7); }
  .plan-head { grid-template-columns: 1fr; gap: var(--s4); }
  .plan-head h1 { font-size: var(--fs-2xl); }
  .plan-side { justify-items: start; }
  .chapter { grid-template-columns: 40px minmax(0, 1fr); column-gap: var(--s3); }
  .chapter-no { width: 32px; height: 32px; font-size: var(--fs-m); }
  .chapter h2 { font-size: var(--fs-l); }
  .stations { grid-template-columns: 1fr; row-gap: 0; margin-top: var(--s3); }
  .station { padding: 0 0 var(--s3) 30px; }
  .station::before { top: 0; bottom: 0; left: 8px; right: auto; border-top: 0; border-left: var(--w2) solid var(--ink); }
  .station:first-child::before { top: 9px; left: 8px; }
  .station:last-child::before { bottom: auto; height: 9px; width: auto; }
  .station.is-locked::before { border-left-style: dashed; border-left-color: var(--rule-mid); }
  .station::after { display: none; }
  .st-node { top: 0; }
  .st-link { padding-top: 0; }
  .page-manual { grid-template-columns: minmax(0, 1fr); gap: var(--s4); }
  .page-manual > * { min-width: 0; }
  html[data-view='level'], html[data-view='sandbox'] { --appbar-h: 48px; }
  html[data-view='level'] .mainnav, html[data-view='sandbox'] .mainnav, html[data-view='setzwerk'] .mainnav { display: none; }
  .toc { position: static; }
  .toc ol { display: flex; flex-wrap: wrap; border-left: 0; gap: var(--s1); }
  .toc a { border: var(--w1) solid var(--rule-faint); border-radius: var(--radius); margin: 0; padding: 4px var(--s2); font-size: var(--fs-s); }
  .toc a[aria-current='page'] { border-color: var(--blue); }

  html[data-view='level'] body, html[data-view='sandbox'] body { overflow: auto; }
  .ws { height: auto; min-height: calc(100dvh - var(--appbar-h)); display: block; padding-bottom: 104px; }
  .ws-head { flex-wrap: wrap; padding: var(--s2) var(--s3); row-gap: 2px; }
  .crumbs { width: 100%; }
  .status-chip { margin-left: 0; width: 100%; }
  .dbg {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
    flex-wrap: wrap; gap: var(--s1) var(--s2); padding: 6px var(--s2) calc(6px + env(safe-area-inset-bottom));
    border-top: var(--w3) solid var(--rule); border-bottom: 0;
  }
  .dbg .timeline { order: -1; flex: 1 1 100%; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s2); }
  .dbg .timeline-range { height: 22px; }
  .test-pick { display: none; }
  .dbg-primary kbd, .dbg-btn kbd { display: none; }
  .dbg-btn, .dbg-primary { flex-direction: column; gap: 1px; min-height: 48px; padding: 2px 0; }
  .dbg-btn .btn-label, .dbg-primary .btn-label { display: block; font-size: 0.6875rem; font-weight: 600; }
  .dbg-primary { flex: none; width: 76px; }
  .dbg-primary .lbl-long { display: none; }
  .dbg-primary .lbl-short { display: inline; }
  .dbg-group { flex: 1; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .ws-mobile-tabs {
    display: flex; position: sticky; top: var(--appbar-h); z-index: 10;
    overflow-x: auto; scrollbar-width: none; background: var(--paper);
    border-bottom: var(--w2) solid var(--rule); padding: 0 var(--s1);
    justify-content: space-between;
  }
  .mtab { flex: none; min-height: 44px; padding: 0 6px; background: transparent; border: 0; color: var(--ink-2); font-weight: 600; font-size: var(--fs-xs); position: relative; }
  .mtab[aria-selected='true'] { color: var(--ink); }
  .mtab[aria-selected='true']::after { content: ''; position: absolute; left: var(--s2); right: var(--s2); bottom: -2px; border-bottom: var(--w4) solid var(--blue); }
  .ws-grid { display: block; }
  .ws-col { display: contents; }
  .pane { display: none; border: 0 !important; }
  .ws[data-mtab='task'] .pane-task,
  .ws[data-mtab='code'] .pane-code,
  .ws[data-mtab='regs'] .pane-regs,
  .ws[data-mtab='stack'] .pane-stack,
  .ws[data-mtab='screen'] .pane-screen,
  .ws[data-mtab='console'] .pane-console,
  .ws[data-mtab='mem'] .pane-mem { display: flex; }
  .pane-task .tabpanels, .stack-scroll, .hex-scroll { overflow: visible; }
  .checklist { position: static; }
  .pane-code { min-height: calc(100dvh - var(--appbar-h) - 220px); }
  .setz-split { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(12rem, 1fr) minmax(12rem, 1fr); }
  .setz-side + .setz-side { border-left: 0; border-top: var(--w2) solid var(--rule); }
  .ed-palette { display: flex; gap: var(--s1); overflow-x: auto; padding: var(--s2); border-top: var(--w1) solid var(--rule-faint); background: var(--paper-2); scrollbar-width: none; flex: none; }
  .ed-palette .chip { min-height: 40px; min-width: 40px; justify-content: center; font-family: var(--font-mono); background: var(--paper-3); }
  .pane-console { max-height: none; }
  .pane-mem { min-height: 70dvh; }
  .hex-scroll { max-height: 60dvh; overflow: auto; }
  .screen-body { grid-template-columns: 1fr; padding-left: calc(var(--s4) + 18px); }
  .screen-frame { width: min(100%, 320px); }
  .test { grid-template-columns: 22px minmax(0, 1fr) auto; }
  .test-io { grid-column: 2 / -1; grid-row: 2; }
  .test-cyc { display: none; }
}

/* touch: 44 px targets */
@media (pointer: coarse) {
  .btn, .icon-btn, .tab, .seg-btn, .chip, .flag, .reg-val, .ed-error, .example { min-height: 44px; }
  .icon-btn { width: 44px; height: 44px; }
  .reg { height: 44px; }
  .reg-back { width: 44px; height: 44px; }
  .gl { height: var(--lh-code); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0ms !important; animation-duration: 0ms !important; scroll-behavior: auto !important; }
}

@media (forced-colors: active) {
  .reg.is-changed .reg-val, .stack tr.is-changed .c-val, .hx.is-changed { forced-color-adjust: none; background: Mark; color: MarkText; }
  .bl.is-current { forced-color-adjust: none; background: Highlight; color: HighlightText; }
  .bp-mark { fill: CanvasText; }
  .station::before, .station::after { border-color: CanvasText; }
  .tab[aria-selected='true']::after, .mtab[aria-selected='true']::after { border-color: Highlight; }
  .btn-primary { border: var(--w2) solid ButtonText; }
  .status-dot { forced-color-adjust: none; border-color: CanvasText; }
}
