/* ══════════════════════════════════════════════════════════════════════════
   paragraph — app.css : THE FRAME.

   The plate: a top bar, a five-column workspace (rail / splitter / stage /
   splitter / rail) and a status bar. Everything is bounded by hairlines and
   crop marks; nothing is bounded by a box with a radius.

   The viewport is a cold void. The sheet of paper drawn inside it is the only
   lit object on screen — no other surface in this UI is allowed to be warm.

   JS-owned custom properties (set inline by src/app.js / ui):
     #workspace  --rail-left, --rail-right    px widths of the two rails
     #app        --code-h                     px height of the code pane
     #pr-bar-fill --p                         0..1 fraction of the plot meter
   State classes:
     #workspace.no-left / .no-right           rail hidden (width collapses to 0)
     #code-pane.is-collapsed                  editor hidden, header stays
     #viewport-wrap.no-rulers                 ruler strips hidden
   ══════════════════════════════════════════════════════════════════════════ */

/* ══════════════════════════════ 1. SHELL ══════════════════════════════ */

#app {
  height: 100%;
  display: grid;
  grid-template-rows: var(--bar) minmax(0, 1fr) var(--bar);
  background: var(--ink-000);
  isolation: isolate;
}

/* ══════════════════════════════ 2. TOP BAR ════════════════════════════ */

#topbar {
  display: flex;
  align-items: stretch;
  gap: 0;
  min-width: 0;
  background: var(--ink-100);
  border-bottom: 1px solid var(--line);
  user-select: none;
}

/* ── brand ── */
#brand {
  display: flex;
  align-items: center;
  gap: var(--u2);
  padding: 0 var(--u3) 0 var(--u3);
  border-right: 1px solid var(--line);
  flex: none;
}
#brand-mark {
  width: 17px; height: 17px;
  color: var(--pen-1);
  display: block;
  flex: none;
}
#brand-name {
  font-family: var(--f-display);
  font-size: var(--fs-head);
  font-weight: 700;
  font-stretch: condensed;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--txt);
  line-height: 1;
}
#brand-ver {
  font-size: var(--fs-micro);
  font-variant-numeric: tabular-nums;
  align-self: flex-start;
  margin-top: 9px;
}

/* ── document name ── */
#doc-bar {
  display: flex;
  align-items: center;
  gap: var(--u);
  padding: 0 var(--u3);
  border-right: 1px solid var(--line);
  flex: none;
  min-width: 0;
}
#doc-name {
  width: 12ch;
  min-width: 6ch;
  max-width: 26ch;
  padding: 3px var(--u);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  color: var(--txt-mid);
  font-size: var(--fs-ui);
  letter-spacing: 0.02em;
  text-overflow: ellipsis;
}
#doc-name:hover { background: var(--ink-200); border-color: var(--line); }
#doc-name:focus {
  background: var(--ink-300);
  border-color: var(--line-hot);
  color: var(--txt);
}
#doc-name:focus-visible { outline: 1px solid var(--accent); outline-offset: 0; }
/* src/app.js shows/hides the dot with .is-hidden (tokens.css), so it must be
   visible by default — do not park it at opacity 0 here. */
#doc-dirty {
  font-size: 14px;
  line-height: 1;
  color: var(--pen-3);
  transition: color var(--dur) var(--ease);
}
#doc-bar.clean #doc-dirty { color: var(--txt-faint); }

/* ── render mode switches (filled by ui/toolbar.js) ── */
#mode-bar {
  display: flex;
  align-items: center;
  gap: var(--u2);
  padding: 0 var(--u3);
  border-right: 1px solid var(--line);
  flex: none;
  min-width: 0;
  overflow: hidden;
}

/* ── the plot readout: what this drawing costs a real plotter ── */
#plot-readout {
  display: flex;
  align-items: stretch;
  margin: 0 auto;
  padding: 0 var(--u3);
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  background: var(--ink-050);
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
}
#plot-readout::before, #plot-readout::after { opacity: 0.7; }

.pr-cell {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-end;
  gap: 1px;
  padding: 0 var(--u3);
  min-width: 0;
  border-right: 1px solid var(--line-soft);
}
/* #pr-bar is the last child, so the last *cell* is nth-last-child(2). */
.pr-cell:last-child, .pr-cell:nth-last-child(2) { border-right: 0; }
.pr-cell .t-label {
  font-size: var(--fs-micro);
  letter-spacing: 0.16em;
  color: var(--txt-faint);
  line-height: 1;
}
.pr-cell .t-val {
  font-size: var(--fs-val);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  color: var(--txt);
  white-space: nowrap;
}
.pr-cell.pr-time .t-val { color: var(--pen-3); }
.pr-cell.stale .t-val { color: var(--txt-dim); }

/* the thin segmented meter along the bottom edge of the readout */
#pr-bar {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 2px;
  background:
    repeating-linear-gradient(90deg,
      var(--line) 0 3px, transparent 3px 4px);
  overflow: hidden;
}
#pr-bar-fill {
  height: 100%;
  width: calc(var(--p, 0) * 100%);
  background:
    repeating-linear-gradient(90deg,
      var(--pen-1) 0 3px, transparent 3px 4px);
  transition: width 160ms var(--ease);
}
#plot-readout.over #pr-bar-fill {
  background: repeating-linear-gradient(90deg, var(--pen-4) 0 3px, transparent 3px 4px);
}

/* ── actions (filled by ui/toolbar.js) ── */
#actions {
  display: flex;
  align-items: center;
  gap: var(--u);
  padding: 0 var(--u2) 0 var(--u3);
  border-left: 1px solid var(--line);
  flex: none;
}

/* ══════════════════════════════ 3. WORKSPACE ══════════════════════════ */

#workspace {
  --rail-left: 268px;
  --rail-right: 300px;
  display: grid;
  grid-template-columns:
    minmax(0, var(--rail-left)) 3px minmax(0, 1fr) 3px minmax(0, var(--rail-right));
  min-height: 0;
  background: var(--ink-000);
}
/* !important because JS keeps the dragged width as an inline custom property
   on #workspace, and an inline declaration would otherwise beat this class. */
#workspace.no-left { --rail-left: 0px !important; }
#workspace.no-right { --rail-right: 0px !important; }
#workspace.no-left > #split-left,
#workspace.no-right > #split-right { pointer-events: none; opacity: 0.4; }
#workspace.no-left > #rail-left { border-right: 0; }
#workspace.no-right > #rail-right { border-left: 0; }

/* ── rails ── */
.rail {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--ink-100);
}
#rail-left { border-right: 1px solid var(--line); }
#rail-right { border-left: 1px solid var(--line); }

.rail-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
#panel-tree { flex: 1 1 55%; }
#panel-library { flex: 1 1 45%; }

.rail-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding-bottom: var(--u2);
}

/* section headers inside the rails carry a count / a search box */
#tree-count {
  font-variant-numeric: tabular-nums;
  font-size: var(--fs-micro);
}
#lib-search {
  width: 11ch;
  flex: 1 1 auto;
  min-width: 0;
  max-width: 15ch;
  padding: 2px var(--u);
  background: var(--ink-050);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--txt);
  font-size: var(--fs-ui);
}
#lib-search::placeholder { color: var(--txt-faint); }
#lib-search:focus { background: var(--ink-300); border-color: var(--line-hot); }
#lib-search:focus-visible { outline: 1px solid var(--accent); outline-offset: 0; }

/* inspector tab strip */
#insp-tabs {
  display: flex;
  align-items: stretch;
  height: var(--hdr);
  flex: none;
  background: var(--ink-050);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}
#insp-tabs::-webkit-scrollbar { height: 0; }
#insp-body { padding-bottom: var(--u4); }

/* ══════════════════════════════ 4. SPLITTERS ══════════════════════════ */

.vsplit, .hsplit {
  position: relative;
  background: transparent;
  flex: none;
  z-index: 2;
  touch-action: none;
}
.vsplit { cursor: col-resize; width: 3px; }
.hsplit { cursor: row-resize; height: 3px; }

/* the hairline itself, centred in the 3px hit area */
.vsplit::before, .hsplit::before {
  content: '';
  position: absolute;
  background: var(--line);
  transition: background var(--dur) var(--ease);
}
.vsplit::before { top: 0; bottom: 0; left: 1px; width: 1px; }
.hsplit::before { left: 0; right: 0; top: 1px; height: 1px; }

.vsplit:hover::before, .hsplit:hover::before,
.vsplit.dragging::before, .hsplit.dragging::before { background: var(--accent); }

/* a two-tick grip at the middle, only visible on hover */
.vsplit::after, .hsplit::after {
  content: '';
  position: absolute;
  opacity: 0;
  background: var(--line-hot);
  transition: opacity var(--dur) var(--ease);
}
.vsplit::after { left: 1px; width: 1px; top: 50%; height: 18px; margin-top: -9px; }
.hsplit::after { top: 1px; height: 1px; left: 50%; width: 18px; margin-left: -9px; }
.vsplit:hover::after, .hsplit:hover::after { opacity: 1; }

.vsplit:focus-visible, .hsplit:focus-visible { outline: 1px solid var(--accent); outline-offset: 0; }

/* while dragging a splitter the whole app stops selecting text */
body.resizing { user-select: none; cursor: col-resize; }
body.resizing-v { cursor: row-resize; }
body.resizing * { pointer-events: none; }

/* ══════════════════════════════ 5. STAGE ═════════════════════════════ */

/* --code-h is set by src/app.js on #app, so it arrives here by inheritance:
   never re-declare it on #stage or the inline value would be shadowed. */
#stage {
  display: grid;
  grid-template-rows: minmax(0, 1fr) 3px minmax(0, var(--code-h, 260px));
  min-width: 0;
  min-height: 0;
  background: var(--ink-050);
}
#code-pane.is-collapsed #editor-wrap,
#code-pane.is-collapsed #console { display: none; }
#stage:has(#code-pane.is-collapsed) > #split-code { pointer-events: none; }
#code-pane.is-collapsed #code-collapse { transform: rotate(180deg); }

/* ── the void ── */
#viewport-wrap {
  --ruler: 15px;
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--ink-000);
  /* a very faint cold vignette so the paper reads as lit from within */
  background-image:
    radial-gradient(120% 100% at 50% 45%, var(--ink-050) 0%, var(--ink-000) 70%);
}

#gl-preview, #viewport {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
#gl-preview { z-index: 0; opacity: 0.9; pointer-events: none; }
#viewport { z-index: 1; cursor: crosshair; }
#viewport:focus-visible { outline: 1px solid var(--accent); outline-offset: -1px; }

/* tool cursors, set by ui/viewport.js on #viewport-wrap */
#viewport-wrap.tool-pan #viewport { cursor: grab; }
#viewport-wrap.tool-pan.dragging #viewport { cursor: grabbing; }
#viewport-wrap.tool-orbit #viewport { cursor: move; }
#viewport-wrap.tool-select #viewport { cursor: default; }
#viewport-wrap.tool-measure #viewport { cursor: crosshair; }
#viewport-wrap.dragging-node #viewport { cursor: move; }

/* ── rulers: opaque strips laid over the top and left edges of the void ── */
.ruler {
  position: absolute;
  z-index: 3;
  display: block;
  background: var(--ink-050);
  pointer-events: none;
}
#ruler-h {
  top: 0; left: var(--ruler); right: 0;
  height: var(--ruler);
  border-bottom: 1px solid var(--line);
}
#ruler-v {
  left: 0; top: var(--ruler); bottom: 0;
  width: var(--ruler);
  border-right: 1px solid var(--line);
}
#ruler-corner {
  position: absolute;
  z-index: 4;
  top: 0; left: 0;
  width: var(--ruler); height: var(--ruler);
  display: flex; align-items: center; justify-content: center;
  background: var(--ink-050);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  font-size: var(--fs-micro);
  color: var(--txt-faint);
  letter-spacing: 0.04em;
  user-select: none;
  pointer-events: none;
}
#viewport-wrap.no-rulers .ruler,
#viewport-wrap.no-rulers #ruler-corner { display: none; }

/* ── overlay: DOM-level gizmo labels, marquee, path handles ── */
#overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  overflow: hidden;
}
#overlay > * { pointer-events: auto; }

/* marquee rectangle drawn by the selection drag */
.marquee {
  position: absolute;
  border: 1px dashed var(--accent);
  background: color-mix(in srgb, var(--pen-1) 8%, transparent);
  pointer-events: none;
}
/* the hover label chip that follows the cursor */
.hover-chip {
  position: absolute;
  transform: translate(8px, 8px);
  padding: 1px var(--u);
  background: var(--ink-000);
  border: 1px solid var(--line-hi);
  border-radius: var(--r-sm);
  color: var(--txt-mid);
  font-size: var(--fs-micro);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  pointer-events: none;
}

/* ── viewport tool rack ── */
#viewport-tools {
  position: absolute;
  z-index: 6;
  left: calc(var(--ruler) + var(--u2));
  top: calc(var(--ruler) + var(--u2));
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 1px;
  background: var(--ink-100);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  user-select: none;
}
#viewport-wrap.no-rulers #viewport-tools { left: var(--u2); top: var(--u2); }

/* ── HUD corners ── */
.hud {
  position: absolute;
  z-index: 6;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--u) var(--u2);
  font-size: var(--fs-micro);
  font-variant-numeric: tabular-nums;
  color: var(--txt-dim);
  line-height: 1.4;
  white-space: nowrap;
  pointer-events: none;
  user-select: none;
  text-shadow: 0 0 2px var(--ink-000);
}
.hud:empty { display: none; }
.hud b {
  font-weight: 400;
  color: var(--txt-mid);
  font-family: var(--f-display);
  font-stretch: condensed;
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
}
.hud .k { color: var(--txt-faint); }
.hud .v { color: var(--txt); }
.hud .hot { color: var(--accent); }

#hud-tl { top: calc(var(--ruler) + var(--u2)); left: calc(var(--ruler) + 34px); }
#hud-tr { top: calc(var(--ruler) + var(--u2)); right: var(--u2); align-items: flex-end; }
#hud-bl { bottom: var(--u2); left: calc(var(--ruler) + var(--u2)); }
#hud-br { bottom: var(--u2); right: var(--u2); align-items: flex-end; }
#viewport-wrap.no-rulers #hud-tl { left: 34px; top: var(--u2); }
#viewport-wrap.no-rulers #hud-tr { top: var(--u2); }
#viewport-wrap.no-rulers #hud-bl { left: var(--u2); }

/* the scale bar lives in #hud-br */
.scalebar {
  display: flex;
  align-items: center;
  gap: var(--u);
}
.scalebar i {
  display: block;
  height: 5px;
  border: 1px solid var(--txt-dim);
  border-top: 0;
}

/* ── render flag ── */
#render-flag {
  position: absolute;
  z-index: 7;
  top: calc(var(--ruler) + var(--u2));
  left: 50%;
  transform: translateX(-50%);
  padding: 2px var(--u2);
  background: var(--ink-000);
  border: 1px solid var(--pen-3);
  border-radius: var(--r-sm);
  color: var(--pen-3);
  font-family: var(--f-display);
  font-stretch: condensed;
  font-weight: 700;
  font-size: var(--fs-micro);
  letter-spacing: var(--ls-label);
  animation: pg-pulse 700ms var(--ease) infinite;
  pointer-events: none;
}

/* ══════════════════════════════ 6. CODE PANE ══════════════════════════ */

#code-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background: var(--ink-100);
  border-top: 1px solid var(--line);
}
#code-head { background: var(--ink-100); }
#code-pos {
  font-variant-numeric: tabular-nums;
  font-size: var(--fs-micro);
  min-width: 6ch;
  text-align: right;
}

/* The three layers of the editor. Gutter | (highlight ⧉ textarea).
   --ed-pad, --ed-lh and --ed-fs are shared by all three: change them here and
   nowhere else, or the caret drifts off the glyphs. */
#editor-wrap {
  --ed-pad: 6px;
  --ed-lh: 17px;
  --ed-fs: var(--fs-code);
  --ed-gutter: 42px;
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: var(--ink-050);
}

#editor-gutter {
  flex: none;
  width: var(--ed-gutter);
  padding: var(--ed-pad) var(--u) var(--ed-pad) 0;
  overflow: hidden;
  background: var(--ink-100);
  border-right: 1px solid var(--line);
  font-family: var(--f-mono);
  font-size: var(--ed-fs);
  line-height: var(--ed-lh);
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: var(--txt-faint);
  user-select: none;
  white-space: pre;
}
#editor-gutter .gl { display: block; height: var(--ed-lh); position: relative; }
#editor-gutter .gl.cur { color: var(--txt-mid); background: var(--ink-200); }
#editor-gutter .gl.err { color: var(--pen-2); }
#editor-gutter .gl.warn { color: var(--pen-4); }
#editor-gutter .gl.err::before,
#editor-gutter .gl.warn::before {
  content: '';
  position: absolute;
  left: 2px; top: 50%;
  width: 3px; height: 3px;
  margin-top: -1.5px;
  background: currentColor;
}

#editor-scroll {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
}

/* the highlight layer and the textarea must be pixel-identical */
#editor-hl, #editor {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: var(--ed-pad) var(--u3) var(--ed-pad) var(--u2);
  border: 0;
  font-family: var(--f-mono);
  font-size: var(--ed-fs);
  line-height: var(--ed-lh);
  font-variant-ligatures: none;
  tab-size: 2;
  white-space: pre;
  word-wrap: normal;
  overflow-wrap: normal;
  letter-spacing: 0;
  text-align: left;
  background: transparent;
}
#editor-hl {
  z-index: 0;
  overflow: hidden;
  color: var(--txt-mid);
  pointer-events: none;
}
#editor {
  z-index: 1;
  overflow: auto;
  resize: none;
  color: transparent;
  caret-color: var(--pen-1);
  -webkit-text-fill-color: transparent;
}
#editor::selection { background: color-mix(in srgb, var(--pen-1) 30%, transparent); }
#editor:focus-visible { outline: 1px solid var(--line-hot); outline-offset: -1px; }

/* editor token colours — set by ui/editor.js from lang/lexer.js */
.tk-num   { color: var(--pen-3); }
.tk-str   { color: var(--pen-4); }
.tk-com   { color: var(--txt-faint); font-style: italic; }
.tk-kw    { color: var(--pen-5); }
.tk-op    { color: var(--txt-dim); }
.tk-punct { color: var(--txt-dim); }
.tk-id    { color: var(--txt); }
.tk-var   { color: var(--txt-mid); }
.tk-shape { color: var(--pen-1); }
.tk-bool  { color: var(--pen-2); }
.tk-warp  { color: var(--pen-4); }
.tk-fill  { color: var(--pen-3); }
.tk-set   { color: var(--txt-mid); }
.tk-xform { color: var(--txt); }
.tk-err   { text-decoration: underline wavy var(--pen-2); text-underline-offset: 3px; }
.tk-warn  { text-decoration: underline wavy var(--pen-4); text-underline-offset: 3px; }
/* the span of the selected node, mirrored from the tree/viewport */
.tk-sel   { background: color-mix(in srgb, var(--pen-1) 16%, transparent); }
.tk-live  { background: color-mix(in srgb, var(--pen-3) 14%, transparent); }

/* ── console ── */
#console {
  flex: none;
  max-height: 92px;
  overflow: auto;
  padding: 0;
  background: var(--ink-050);
  border-top: 1px solid var(--line);
  font-size: var(--fs-ui);
}
#console:empty { display: none; }
.diag {
  display: flex;
  align-items: baseline;
  gap: var(--u2);
  padding: 2px var(--u2);
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
  color: var(--txt-mid);
}
.diag:last-child { border-bottom: 0; }
.diag:hover { background: var(--ink-200); color: var(--txt); }
.diag .loc {
  flex: none;
  min-width: 6ch;
  color: var(--txt-faint);
  font-variant-numeric: tabular-nums;
}
.diag .sev {
  flex: none;
  font-family: var(--f-display);
  font-stretch: condensed;
  font-weight: 700;
  font-size: var(--fs-micro);
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
}
.diag.error .sev { color: var(--pen-2); }
.diag.warn  .sev { color: var(--pen-4); }
.diag.info  .sev { color: var(--txt-dim); }
.diag .msg { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.diag:focus-visible { outline: 1px solid var(--accent); outline-offset: -1px; }

/* ══════════════════════════════ 7. STATUS BAR ═════════════════════════ */

#statusbar {
  display: flex;
  align-items: center;
  gap: var(--u2);
  padding: 0 var(--u2) 0 var(--u2);
  background: var(--ink-100);
  border-top: 1px solid var(--line);
  font-size: var(--fs-ui);
  color: var(--txt-dim);
  user-select: none;
  overflow: hidden;
  white-space: nowrap;
}
#statusbar .fill-rule { flex: 1 1 auto; height: 1px; background: var(--line-soft); }
#statusbar .rule-v { height: 14px; flex: none; }
#statusbar .t-val { font-size: var(--fs-ui); color: var(--txt-mid); }

#status-engine { flex: none; }
/* ui/toolbar.js flags the raymarch engine with .is-rm */
#status-engine.is-rm, #status-engine.raymarch { --accent: var(--pen-5); }
#status-msg {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--txt-mid);
}
#status-msg.error { color: var(--pen-2); }
#status-msg.warn  { color: var(--pen-4); }
#status-msg.ok    { color: var(--pen-3); }
#status-sel { flex: none; max-width: 32ch; overflow: hidden; text-overflow: ellipsis; }
#status-coords { flex: none; font-variant-numeric: tabular-nums; }
#status-perf { flex: none; font-variant-numeric: tabular-nums; }

/* ══════════════════════════ 8. FLOATING LAYERS ════════════════════════ */

#modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--ink-000) 78%, transparent);
}
#modal-box {
  min-width: 320px;
  max-width: min(680px, 88vw);
  max-height: 80vh;
  overflow: auto;
  padding: var(--u4);
  background: var(--ink-100);
  border: 1px solid var(--line-hi);
  border-radius: var(--r-sm);
}
#modal-box h2 {
  margin: 0 0 var(--u3);
  font-family: var(--f-display);
  font-stretch: condensed;
  font-size: var(--fs-big);
  font-weight: 700;
  letter-spacing: var(--ls-head);
  text-transform: uppercase;
  color: var(--txt);
}
#modal-box p { margin: 0 0 var(--u2); color: var(--txt-mid); }
#modal-box kbd {
  display: inline-block;
  min-width: 16px;
  padding: 0 3px;
  background: var(--ink-300);
  border: 1px solid var(--line-hi);
  border-radius: var(--r-sm);
  font-size: var(--fs-micro);
  color: var(--txt-mid);
  text-align: center;
}
#modal-box table { width: 100%; border-collapse: collapse; font-size: var(--fs-ui); }
#modal-box td { padding: 2px var(--u2); border-bottom: 1px solid var(--line-soft); }
#modal-box td:first-child { color: var(--txt-dim); white-space: nowrap; }

/* the help sheet: two columns of shortcut definition lists, then prose */
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--u3); margin: calc(var(--u4) * -1) calc(var(--u4) * -1) var(--u3);
  padding: 0 var(--u3); height: var(--hdr);
  border-bottom: 1px solid var(--line);
  background: var(--ink-200);
}
.modal-body { display: grid; grid-template-columns: 1fr 1fr; gap: var(--u3) var(--u4); }
.modal-body > section:last-child { grid-column: 1 / -1; }
.modal-body h4 { margin: 0 0 var(--u) ; padding-bottom: 3px; border-bottom: 1px solid var(--line); }
.modal-body dl {
  display: grid; grid-template-columns: auto 1fr;
  gap: 1px var(--u2); margin: 0; font-size: var(--fs-ui);
}
.modal-body dt {
  color: var(--pen-1); white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.modal-body dd { margin: 0; color: var(--txt-mid); }
.modal-body p { margin: 0 0 var(--u2); line-height: 1.5; }
.modal-body code {
  padding: 0 3px; background: var(--ink-300);
  border: 1px solid var(--line); color: var(--pen-3);
  font-size: var(--fs-ui);
}
@media (max-width: 620px) { .modal-body { grid-template-columns: 1fr; } }

/* ══════════════════════════ 9. NARROW LAYOUT ══════════════════════════ */

/* Below 1100px the rails stop being columns and become overlays that float
   over the stage. The stage keeps the full width so the paper stays big. */
@media (max-width: 1100px) {
  #workspace {
    grid-template-columns: 0 0 minmax(0, 1fr) 0 0;
    position: relative;
  }

  .rail {
    position: absolute;
    z-index: var(--z-overlay);
    top: 0;
    bottom: 0;
    width: min(300px, 78vw);
    background: var(--ink-100);
    transition: transform var(--dur) var(--ease);
  }
  #rail-left {
    left: 0;
    border-right: 1px solid var(--line-hi);
    transform: translateX(-101%);
  }
  #rail-right {
    right: 0;
    border-left: 1px solid var(--line-hi);
    transform: translateX(101%);
  }
  /* JS adds .open to reveal an overlay rail */
  #rail-left.open, #rail-right.open { transform: none; }

  .vsplit { display: none; }

  #plot-readout { display: none; }
  #brand-ver, #doc-bar { display: none; }
  #stage { grid-column: 1 / -1; }

  #status-paper, #status-coords, #status-perf { display: none; }
}

@media (max-width: 720px) {
  #mode-bar { display: none; }
  #status-sel { display: none; }
  .rail { width: 88vw; }
}

/* print is meaningless here — but do not let it look broken */
@media print {
  #topbar, #statusbar, .rail, .vsplit, .hsplit, #code-pane { display: none; }
}
