/* ═══════════════════════ Python Code Visualiser ═══════════════════════ */

:root {
  --bg: #f3f4f6;
  --panel: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --accent: #2563eb;
  --green: #059669;
  --green-bg: #d1fae5;
  --orange: #d97706;
  --orange-bg: #fef3c7;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --gutter: #9ca3af;      /* editor line numbers (former .mirror .ln literal) */
  --text-body: #374151;   /* vars-panel values (former #varsBody td.v literal) */
  --mono: Consolas, "SF Mono", Menlo, monospace;
  /* Themed vertical scrollbars (2026-11-19, grilled Q1–Q5): rest = gutter,
     hover/drag = accent; the 10px trough holds a 6px pill after the inset. */
  --sb-size: 10px;
  --sb-thumb: var(--gutter);
  --sb-thumb-hover: var(--accent);
}
:root[data-theme="dark"] {
  /* Chrome-only override (2026-11-05-dark-mode-design.md Q1): the dark
     visualisation panes (#outputBody/#treeBody/#stackBody/… — #111827
     terminals) are untouched; only the surrounding chrome re-themes.
     Highlight bgs go translucent so the editor hl rows work on dark panels. */
  --bg: #0f172a;
  --panel: #1e293b;
  --border: #334155;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --green: #34d399;
  --green-bg: rgba(52, 211, 153, 0.16);
  --orange: #fbbf24;
  --orange-bg: rgba(251, 191, 36, 0.14);
  --red: #f87171;
  --red-bg: rgba(248, 113, 113, 0.14);
  --gutter: #64748b;
  --text-body: #d1d5db;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
header h1 { font-size: 18px; margin: 0; font-weight: 600; }
#status {
  font-size: 13px;
  color: var(--muted);
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--bg);
}
#status.ready { color: var(--green); }
/* Dark-mode toggle: right corner of the top bar,
same row as the title. Glyphs match the app's emoji language. */
#themeToggle {
  margin-left: auto;
  padding: 5px 10px;
  font-size: 15px;
  line-height: 1;
}
/* The toggle is inert while a reveal owns the screen (theme.js). Keep its
   appearance identical to the normal state so the clone and the live button
   match at handoff. */
#themeToggle:disabled {
  opacity: 1;
  cursor: default;
}

/* Theme transition (2026-11-20): the dark-mode reveal is a fixed layer holding
   a clone of the page in the INCOMING theme, clipped by a circle that expands
   from the toggle (src/theme.js). Because the layer contains real content
   rather than a flat colour, text, panels and borders stay visible inside the
   circle; outside it the outgoing theme is still visible. Deliberately
   snapshot-free: the View Transition API's full-page captures stalled the
   compositor on slower GPUs and froze the circle mid-spread. */
#themeWave {
  position: fixed;
  inset: 0;
  z-index: 99;   /* above menus so the reveal covers them too */
  pointer-events: none;      /* display-only; never intercepts interaction */
  display: none;
  flex-direction: column;
  overflow: hidden;
  will-change: clip-path;
}

main {
  flex: 1;
  display: flex;
  min-height: 0;
  padding: 12px;
  gap: 6px;
}

/* ---------- left: editor ---------- */
/* #left must NOT clip: the hierarchical DSA menus are absolutely positioned
   inside the editor column and have to escape it to the right when the editor
   is narrow (2026-11-20). The rounded bottom corners are preserved by
   #controlsPanel below instead of the column's overflow clip. */
#left {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: visible;
}
#toolbar {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  /* The DSA trigger is nowrap and has a wide min-content floor; below ~560px
     the controls wrap onto additional rows rather than being cut off. */
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
/* Execution-steps panel lives inside #left, below the editor: it blends
   into the editor column (no double border) and keeps its natural height so
   the editor above it absorbs any shrinkage. It owns the column's rounded
   bottom because #left no longer clips (see above). */
#controlsPanel {
  border: 0;
  border-radius: 0 0 9px 9px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ---------- draggable divider between editor and output ---------- */
#divider {
  flex: 0 0 8px;
  position: relative;
  cursor: col-resize;
  touch-action: none;   /* so touch dragging isn't hijacked by scrolling */
}
#divider::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 4px;
  transform: translateX(-50%);
  border-radius: 2px;
  background: var(--border);
}
#divider:hover::before,
#divider.dragging::before { background: var(--accent); }
body.resizing {
  cursor: col-resize;
  user-select: none;
  -webkit-user-select: none;
}

/* ---------- draggable divider between variables and output ---------- */
#vdivider {
  flex: 0 0 2px;
  position: relative;
  cursor: row-resize;
  touch-action: none;   /* so touch dragging isn't hijacked by scrolling */
}

#vdivider::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 4px;
  transform: translateY(-50%);
  border-radius: 2px;
  background: var(--border);
}

#vdivider:hover::before,
#vdivider.dragging::before { background: var(--accent); }
body.resizing-v {
  cursor: row-resize;
  user-select: none;
  -webkit-user-select: none;
}

button {
  font: inherit;
  font-size: 14px;
  padding: 7px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  cursor: pointer;
}
#btnFirst, #btnPrev, #btnNext, #btnLast, #btnPlay {
  color: var(--muted);    /* match step label visibility in both themes */
}
button:hover:not(:disabled) { background: var(--bg); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
#btnVisualize {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
#btnVisualize:hover:not(:disabled) { background: #1d4ed8; }
/* The hint takes a real flex basis instead of shrinking word-by-word into a
   tall column; when the row runs out of room it wraps to its own full-width
   row and stays right-aligned (2026-11-20). */
.hint { font-size: 12px; color: var(--muted); margin-left: auto; flex: 1 1 120px; text-align: right; }

/* ═══════════════ DSA dropdown (hierarchical, hover-driven) ═══════════════
   The trigger is a quiet context control matching the toolbar's secondary
   buttons. Open/close is pure CSS: :hover for the pointer, :focus-within for
   the keyboard. JS never touches visibility — it selects, persists and
   re-renders only (2026-11-04 dropdown grill, Q3). */
.dsa-dropdown {
  position: relative;
  display: inline-flex;
}
/* Hover bridge: the panel sits 4px below the trigger (visual offset), but an
   absolute element lives OUT of flow — that 4px band belongs to no box, so a
   slow pointer crossing it loses :hover and the menu snaps shut mid-journey
   (fast flicks skip the band entirely, hence the flaky "closes before I can
   choose" report). This invisible strip extends the wrapper's hover area over
   the gap: same 4px look, unbroken pointer path — the same fix the submenu
   got (internal offset, grill requirement 5), expressed as a bridge because
   the panel's background must start 4px down. */
.dsa-dropdown::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  height: 4px;
}
.dsa-trigger {
  display: flex;
  align-items: center;
  gap: 6px;
  font: 12px/1 system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px 4px 6px;
  max-width: 220px;
  cursor: pointer;
  white-space: nowrap;
}
.dsa-trigger:hover:not(:disabled) { border-color: var(--accent); }
.dsa-trigger:disabled { opacity: 0.5; cursor: not-allowed; }
.dsa-trigger:focus { outline: none; border-color: var(--accent); }
.dsa-caret {
  font-size: 10px;
  color: var(--muted);
  transition: transform 0.15s ease;
}
.dsa-dropdown:hover .dsa-caret,
.dsa-dropdown:focus-within .dsa-caret {
  transform: rotate(180deg);
}

/* First level: closed by default, opened by pointer hover or keyboard focus.
   NO max-height/overflow here: the submenu is a descendant of the list's
   rows, so any overflow clipping would trap it inside the list box (it would
   scroll the first level instead of popping out beside it). Six categories
   never need scrolling anyway; if the registry grows tall enough to matter,
   the fix is JS-placed positioning, not clipping (2026-11-04 layout fix). */
.dsa-options {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 200px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  padding: 4px 0;
  margin: 0;
  list-style: none;
  /* #left no longer clips, so these positioned menus paint in the root
     stacking context. They must beat the Variables display menu (100) and its
     panel content when they extend over the output column (2026-11-20). */
  z-index: 1000;
  display: none;
}
.dsa-dropdown:hover .dsa-options,
.dsa-dropdown:focus-within .dsa-options {
  display: block;
}
.dsa-options li {
  position: relative;
}
.dsa-options button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 12px;
  font: 12px/1 system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text);
  background: transparent;
  border: none;
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
}
.dsa-options button:hover,
.dsa-options button:focus {
  background: var(--bg);
  outline: none;
}
/* A pure folder row (grilled 2026-11-05 Q3) expands on hover/focus but has
   nothing to select: no pointer cursor. */
.dsa-options li.dsa-folder > button { cursor: default; }
/* The currently selected id is highlighted (generic parent and sub-modes are
   distinct selections — picking 'Two Sum' does not light up 'Two Pointers'). */
.dsa-options button.active {
  background: var(--accent);
  color: #fff;
}
/* A parent row carrying a submenu gets the ▸ affordance. */
.dsa-options li.has-submenu > button::after {
  content: '▸';
  margin-left: auto;
  font-size: 10px;
  color: var(--muted);
}

/* Second level: opens to the RIGHT of the parent row, beside it — never
   overlapping or replacing the first-level list. Positioned with zero
   lateral gap (li spans the full option width, so left:100% touches the
   parent row's edge); the 4px visual offset is internal padding, so the
   hover path from ▸ into the submenu is unbroken (grill requirement 5). */
.dsa-submenu {
  position: absolute;
  top: -5px;
  left: 100%;
  min-width: 190px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  padding: 4px 0 4px 6px;
  margin: 0;
  list-style: none;
  z-index: 1001;   /* above its parent list (1000) and the Variables menu */
  display: none;
  /* Long sub-mode registries scroll inside the flyout instead of stretching
     the page (2026-11-23). CSS caps the height at the smaller of a compact
     menu height and a share of the viewport; dsa.js tightens it further on
     open when a lower parent row would cross the bottom edge. Only level two
     may clip: it has no nested flyouts, unlike .dsa-options, which must stay
     unclipped for this menu to pop out beside its row (see the note above
     .dsa-options). Vertical only — a horizontally scrolling hover menu would
     be hostile. */
  max-height: min(360px, 60vh);
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
}
.dsa-options li:hover > .dsa-submenu,
.dsa-options li:focus-within > .dsa-submenu {
  display: block;
}
.dsa-submenu button {
  padding: 6px 12px;
}
.dsa-submenu button:hover,
.dsa-submenu button:focus {
  background: var(--bg);
  outline: none;
}
.dsa-submenu button.active {
  background: var(--accent);
  color: #fff;
}

.editor {
  flex: 1;
  display: flex;
  min-height: 0;
  background: var(--panel);
  position: relative;
}
.code-area {
  position: relative;
  flex: 1;
  min-width: 0;
}
.mirror, textarea {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 8px 8px 24px 0;
  font-family: var(--mono);
  font-size: 14px;
  line-height: 22px;
  white-space: pre;
  word-break: normal;
  overflow-wrap: normal;
  tab-size: 4;
  overflow: hidden;
}
.mirror {
  z-index: 1;
  pointer-events: none;
  /* The mirror owns the VISIBLE text. It used to duplicate it (#374151)
     under the textarea's opaque #111827 text — two identical glyph layers.
     The textarea is compositor-scrolled (async scroll thread) while the
     mirror only follows via the main-thread scroll handler, so during fast
     scrolling the two opaque layers printed at different offsets: doubled,
     overlapping text that reduced readability (user report 2026-11-05).
     One glyph layer can never ghost against itself.
     Colour = the theme text (2026-11-05 dark mode Q2): light computes the
     exact former #111827; dark mode re-inks both layers together. */
  color: var(--text);
}
.mirror .spacer {
  position: absolute;
  top: 0;
  left: 0;
  visibility: hidden;   /* occupies scroll range only; invisible */
}
.mirror .row { height: 22px; white-space: pre; }
/* No green/orange row bands (2026-11-24 user request): the gutter arrows and
   coloured line numbers mark the just-executed / next lines on their own.
   The red band stays — it marks the line where the program failed. */
.mirror .row.hl-error { background: var(--red-bg); }
.mirror .ln {
  display: inline-block;
  width: 46px;
  position: sticky;
  left: 0;
  text-align: right;
  padding-right: 10px;
  color: var(--gutter);
  user-select: none;
}
.mirror .arrow {
  display: inline-block;
  width: 22px;
  position: sticky;
  left: 46px;
  font-size: 13px;
  user-select: none;
}
.mirror .row.hl-current .ln { color: var(--green); font-weight: bold; }
.mirror .row.hl-next .ln { color: var(--orange); font-weight: bold; }
.mirror .row.hl-error .ln { color: var(--red); font-weight: bold; }
.arrow-prev { color: var(--green); }
.arrow-next { color: var(--orange); }
.arrow-error { color: var(--red); }
textarea {
  z-index: 2;
  width: 100%;
  height: 100%;
  resize: none;
  outline: none;
  border: 0;
  background: transparent;
  /* The mirror underneath paints the visible text (one glyph layer only —
     see .mirror above). The textarea stays the input surface: transparent
     text over the mirror, with the caret and selection still drawn. */
  color: transparent;
  overflow: auto;
  padding-left: 68px;          /* must equal gutter width: 46px line numbers (border-box) + 22px arrow */
  caret-color: var(--text);    /* theme text: re-inks with the mirror (dark mode Q2) */
}
/* Selection: the textarea paints above the mirror, so the highlight must
   stay translucent — the mirror's glyphs show through it (a solid default
   blue would erase the text under the selection). */
textarea::selection {
  background: rgba(37, 99, 235, 0.30);
}
/* Locked editor: a faint wash (must stay semi-transparent — the highlight
   mirror renders underneath the textarea). */
textarea[readonly] {
  background: rgba(37, 99, 235, 0.05);
}
#btnEdit {
  color: var(--muted);     /* match step label visibility in both themes */
}
#btnEdit:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

/* ---------- right: variables & output ---------- */
#right {
  width: calc(50% - 10px);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.panel h2 {
  font-size: 13px;
  font-weight: 600;
  margin: 0;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}
#controls, #controlsPanel .body { padding: 10px 12px; }
#controlsPanel .body {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
#stepLabel {
  margin-left: auto;
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
#stepSlider {
  flex-basis: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}
#stepSlider:disabled { cursor: default; }
/* Playback-speed select (2026-11-15 auto-play design, grilled Q3/Q8): styled
   to match the neighbouring step buttons — panel bg, 1px border, 8px radius,
   muted text — with the native arrow replaced by a chevron drawn in the
   muted colour so it re-themes with dark mode (per-theme data URI below).
   appearance:none + custom padding leaves room for it. */
#playSpeed {
  appearance: none;
  -webkit-appearance: none;
  font: inherit;
  font-size: 14px;
  color: var(--muted);
  background-color: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 26px 7px 10px;
  cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' fill='none' stroke='%236b7280' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 9px center;
  background-size: 10px 6px;
}
:root[data-theme="dark"] #playSpeed {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' fill='none' stroke='%2394a3b8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/></svg>");
}
/* Same dark chevron for the transition clone (theme.js), which carries the
   incoming palette on #themeWave instead of on :root. Kept as a separate rule
   so the :root override above stays the canonical theme declaration. */
#themeWave[data-theme="dark"] #playSpeed {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' fill='none' stroke='%2394a3b8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/></svg>");
}
#playSpeed:hover:not(:disabled) { background-color: var(--bg); }   /* matches button:hover */
#playSpeed:focus { outline: none; border-color: var(--accent); }   /* matches .dsa-trigger:focus */
.legend {
  display: flex;
  gap: 14px;
  padding: 0 12px 10px;
  font-size: 12px;
  color: var(--muted);
}
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend .dot { font-size: 13px; user-select: none; }
.legend .g { color: var(--green); }
.legend .o { color: var(--orange); }

#outputPanel { flex: 1; }
#outputBody {
  flex: 1;
  min-height: 80px;
  overflow: auto;
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 18px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: #111827;
  color: #f9fafb;
}
#outputBody .err { color: #fca5a5; }

/* Output panel tabs — only shown for runs where user code recursed. */
.outtabs {
  display: flex;
  gap: 6px;
  padding: 4px 8px 0;
}
.outtabs button {
  border: 1px solid transparent;
  border-bottom: none;
  background: #1f2937;
  color: #9ca3af;
  font: inherit;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 6px 6px 0 0;
  cursor: pointer;
}
.outtabs button.active {
  background: #111827;
  color: #f9fafb;
  border-color: #374151;
}
#treeBody {
  flex: 1;
  min-height: 80px;
  overflow: hidden;
  padding: 6px 8px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 18px;
  background: #111827;
  color: #f9fafb;
  /* toolbar · (tree | stack) · legend (2026-11-24 graphical tree) */
  display: flex;
  flex-direction: column;
  gap: 6px;
  container-type: inline-size;
}
/* [hidden] ALWAYS wins, even over per-pane display/flex rules (2026-11-06
   user report: the container animation stayed visible on the Output tab —
   #containerBody { display:flex } beat the browser's default
   [hidden] → display:none, and wasn't in the old per-pane escape list).
   One generic rule covers every current and FUTURE algorithm body/tab —
   no per-pane list to maintain. */
[hidden] { display: none !important; }
.tn-active { color: var(--orange); font-weight: 600; }
.tn-done { color: #6ee7a0; }
.tn-error { color: #fca5a5; font-weight: 600; }
.tn-more { color: #9ca3af; font-style: italic; }
#outputBody .info { color: #9ca3af; }

/* Stack visualiser panel (2026-11-03-stack-visualiser-design.md): cells
   bottom→top with the top of the stack at the TOP of the list, like a
   restaurant plate stack drawn downwards. The top cell carries an orange
   border; peek outlines it; a cell born on the current step rises in. */
#stackBody {
  flex: 1;
  min-height: 80px;
  overflow: auto;
  padding: 10px 12px;
  background: #111827;
  color: #f9fafb;
}
.sstrip { font-family: var(--mono); font-size: 12px; color: #9ca3af; }

/* Visual stack: fixed slots, bottom-up. Each slot is a box.
   Empty = hollow with subtle border; Filled = solid with content.
   Enter = fade+scale in; Leave = fade+scale out (rendered one extra frame).
   Peek = amber outline on the top filled box. */
.sstack {
  display: flex;
  flex-direction: column-reverse;   /* bottom row first visually */
  align-items: center;
  gap: 4px;
  margin-top: 8px;
}
/* Multi-instance figures (grilled 2026-11-05 Q3/Q6; unbounded figures
   2026-11-05-stack-unbounded-figures-design.md): one complete figure per
   instance at ANY count — the old 4-cap collapsed the rest into a chip
   the user asked away; the nowrap row + overflow-x scrolls instead.
   Each figure keeps its own slot stack and strip. */
.sfigures {
  display: flex;
  flex-wrap: nowrap;   /* side by side, ALWAYS — a narrow pane scrolls
                          horizontally instead of stacking figures
                          top-and-bottom (user report 2026-11-05) */
  overflow-x: auto;
  gap: 18px;
  align-items: flex-end;
  margin-top: 8px;
}
.sfig {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;      /* a fixed-width figure never gets squeezed */
}
.sfig-label {
  font-family: var(--mono);
  font-size: 12px;
  color: #e5e7eb;
  margin-bottom: 2px;
}
.sbox {
  width: 180px;
  height: 36px;
  box-sizing: border-box;
  border: 2px solid #374151;
  border-radius: 6px;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 18px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: #f9fafb;
  transition: transform 0.2s ease, opacity 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}
.sbox-empty {
  border-style: dashed;
  border-color: #4b5563;
  background: transparent;
}
.sbox-filled {
  background: #1f2937;
  border-color: #374151;
}
.sbox-top { border-color: var(--orange); }
.sbox-peek { box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.45); }
.sbox-cap {
  width: 180px;
  box-sizing: border-box;
  padding: 4px 6px;
  border: 2px dashed rgba(245, 158, 11, 0.55);
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 16px;
  color: #fbbf24;
  text-align: center;
}
.sbox-enter {
  animation: sboxEnter 0.25s ease-out;
}
.sbox-leave {
  animation: sboxLeave 0.25s ease-in forwards;
}
@keyframes sboxEnter {
  from { opacity: 0; transform: scale(0.85) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes sboxLeave {
  from { opacity: 1; transform: scale(1) translateY(0); }
  to { opacity: 0; transform: scale(0.85) translateY(-8px); }
}

/* Default vertical split (2026-11-20): 40/60 Variables/Output of
   the right column — column chrome = gap 12 + #vdivider 2 + gap 12 = 26px,
   Variables gets 40% - 13px, Output's flex:1 fills the rest (60% + 13px).
   Plain height, NOT flex-basis: a flex-basis would outrank the JS drag's
   inline height override (browser probe caught exactly that — drag applied
   474px while the panel sat frozen at its half-height), and dblclick clears
   the inline so this default re-takes over. */
#varsPanel {
  flex-grow: 0;
  flex-shrink: 0;
  height: calc(40% - 13px);
}

/* Display-options dropdown (2026-11-16, grilled Q1–Q6): the header row keeps
   the Variables title and the "Display ▾" trigger on one line — the panel's
   border moves to the row (the generic .panel h2 border is dropped here) and
   the checkbox menu hangs below the trigger, right-aligned. Rows come from
   the displayOptions registry (label + checkbox pairs); new options are one
   registry entry, no CSS changes. */
.vars-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.vars-head h2 { border-bottom: none; flex-shrink: 0; }
.vars-display { position: relative; margin-right: 6px; }
#varsDisplayBtn {
  font: 12px/1 system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 8px;
  cursor: pointer;
  white-space: nowrap;
}
#varsDisplayBtn:hover, #varsDisplayBtn:focus { outline: none; border-color: var(--accent); }
.vars-display-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 100;
  min-width: 220px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  padding: 4px 0;
}
.vars-display-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  font: 12px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text-body);
  cursor: pointer;
  white-space: nowrap;
}
.vars-display-row:hover { background: var(--bg); }
.vars-display-row input { margin: 0; cursor: pointer; }

#varsBody {
  flex: 1;         /* fill the panel's (now fixed 50/50) height… */
  min-height: 0;   /* …and scroll instead of pushing past its clip */
  overflow: auto;
  padding: 8px 0;
  font-family: var(--mono);
  font-size: 13px;
}
#varsBody table { width: 100%; display: grid; grid-template-columns: max-content minmax(0, 1fr); }
/* Every row's cells flow into ONE shared grid (2026-11-17, grilled Q1–Q3):
   column 1 fits the widest name, so all values align at one x; column 2 can
   shrink without bound (minmax(0,1fr)), so long nowrap value strips scroll
   INSIDE the cell instead of widening the panel. Recomputed per render —
   same behaviour as the pre-30cd482 auto table. */
#varsBody tbody, #varsBody tr { display: contents; }
#varsBody td { padding: 3px 12px; vertical-align: top; }
#varsBody td.k { color: var(--accent); white-space: nowrap; }
#varsBody td.v { color: var(--text-body); word-break: break-all; white-space: pre-wrap; min-width: 0; }
#varsBody .empty { color: var(--muted); padding: 4px 12px; font-size: 13px; }
#varsBody tr.sub td.k { padding-left: 30px; }

/* ── Boxes-and-arrows memory diagram (2026-11-15, grilled Q1–Q9) ──
   Container/instance values in the variables panel render as boxes instead
   of formatted strings: one box per object (its canonical first appearance
   carries the owner's name in the cap), later names holding the SAME object
   render `──▶ <label>` (the alias arrow), nested containers draw nested
   boxes, back-edges draw `↺`. Pure flow HTML — the td's own word-break
   handles wrapping, so no positioning math and no SVG. The old formatted
   string rides along as the row's hover tooltip (.mem-wrap[title]). */
#varsBody .mem-wrap { cursor: help; }
#varsBody .mem-box {
  display: inline-block;
  margin: 2px 6px 2px 0;
  padding: 4px 6px 5px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  vertical-align: top;
}
#varsBody .mem-cap {
  display: block;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 3px;
}
#varsBody .mem-cap i { font-style: normal; font-weight: 400; color: var(--muted); font-size: 11px; }
#varsBody .mem-slots { display: flex; flex-wrap: wrap; gap: 3px; }
#varsBody .mem-slot {
  display: inline-block;
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  white-space: nowrap;
}
#varsBody .mem-slot i { font-style: normal; color: var(--muted); margin-right: 4px; font-size: 11px; }
#varsBody .mem-empty, #varsBody .mem-more, #varsBody .mem-deep { color: var(--muted); }
#varsBody .mem-ref { color: var(--accent); font-weight: 600; }
#varsBody .mem-cycle { color: var(--orange); }

/* A root-level list/tuple of all-scalar elements renders as an index-row
× value-row grid instead of boxes: row 1 literal `index` + positions
(muted, dashed cells), row 2 the owner name (+ muted type chip) +
values. Same caps (8 shown, `+N more` cell) and cell formatting as the
boxes; the formatted string stays the hover tooltip (.mem-wrap). */
#varsBody .mem-grid {
  display: inline-grid;
  gap: 3px;
  margin: 2px 6px 2px 0;
  padding: 4px 6px 5px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  vertical-align: top;
}
/* Horizontal scroll for flat list grids (all emitted cells, nowrap): the
   strip never widens the panel or its siblings — a scrollbar appears only
   when the cells overflow the wrapper (2026-11-17, grilled Q1–Q8). */
#varsBody .mem-scroll {
  display: inline-block;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  vertical-align: top;
  scrollbar-width: thin;
  /* The standard scrollbar properties inherit, so reset the colour here:
     otherwise the themed #varsBody skin tints this strip. `auto` keeps its
     pre-existing native paint (the strip was already UA-coloured). */
  scrollbar-color: auto;
}
#varsBody .mem-scroll::-webkit-scrollbar { height: 6px; }
#varsBody .mem-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
#varsBody .mem-glabel { align-self: center; padding: 1px 6px 1px 2px; white-space: nowrap; }
#varsBody .mem-ghead { color: var(--muted); font-size: 11px; text-align: right; }
#varsBody .mem-gname { color: var(--accent); font-weight: 600; }
#varsBody .mem-gcell {
  min-width: 1.6em;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  text-align: center;
  white-space: nowrap;
}
#varsBody .mem-gidx { color: var(--muted); background: transparent; border-style: dashed; }
#varsBody .mem-gmore { color: var(--muted); }
/* Invisible filler that keeps ragged matrix rows aligned to the column count. */
#varsBody .mem-gpad { border: none; background: transparent; min-width: 0; padding: 1px 0; }

/* ── Themed scrollbars: code editor + Variables box + sub-mode menu (2026-11-19, grilled Q1–Q5) ──
   The rest colour is the theme gutter, hover/drag is the theme accent, and both
   resolve through the tokens above, so light and dark need no separate rules.
   Firefox takes the coarse standard properties (thin width, matched colours,
   square thumb). They sit behind a support query on purpose: in Chromium those
   properties disable the custom pseudo-element skin (verified headed — the
   standard thin width beside a 20px WebKit rule renders the native 10px bar).
   Chromium also ignores per-axis selectors, so the WebKit skin covers both axes
   of these two containers: a 10px trough with a transparent track and a 6px
   floating pill after the 2px inset. The 28px minimum keeps the thumb grabbable
   in very long files. */
@supports not selector(::-webkit-scrollbar) {
  #codeInput,
  #varsBody,
  .dsa-submenu {
    scrollbar-width: thin;
    scrollbar-color: var(--sb-thumb) transparent;
  }
}
#codeInput::-webkit-scrollbar,
#varsBody::-webkit-scrollbar,
.dsa-submenu::-webkit-scrollbar {
  width: var(--sb-size);
  height: var(--sb-size);
}
#codeInput::-webkit-scrollbar-track,
#varsBody::-webkit-scrollbar-track,
.dsa-submenu::-webkit-scrollbar-track {
  background: transparent;
}
#codeInput::-webkit-scrollbar-thumb,
#varsBody::-webkit-scrollbar-thumb,
.dsa-submenu::-webkit-scrollbar-thumb {
  min-height: 28px;
  min-width: 28px;
  background-color: var(--sb-thumb);
  background-clip: padding-box;
  border: 2px solid transparent;
  border-radius: 999px;
}
#codeInput::-webkit-scrollbar-thumb:hover,
#varsBody::-webkit-scrollbar-thumb:hover,
.dsa-submenu::-webkit-scrollbar-thumb:hover,
#codeInput::-webkit-scrollbar-thumb:active,
#varsBody::-webkit-scrollbar-thumb:active,
.dsa-submenu::-webkit-scrollbar-thumb:active {
  background-color: var(--sb-thumb-hover);
}
#codeInput::-webkit-scrollbar-corner,
#varsBody::-webkit-scrollbar-corner,
.dsa-submenu::-webkit-scrollbar-corner {
  background: transparent;
}

/* Two Pointers visualiser panel */
/* Every two-pointers body: the same black terminal chrome as #outputBody /
   #treeBody / #stackBody, laid out as a column (head, caption, track,
   legend) by the shared kit (panels/pointerKit.js). */
#twoPtrsBody,
#reverseBody,
#palindromeBody,
#containerBody {
  flex: 1 1 auto;       /* grow to fill available space */
  min-height: 0;        /* allow shrinking below min-height */
  overflow-x: auto;     /* horizontal scroll for many bars */
  overflow-y: hidden;
  padding: 4px 8px;     /* reduced padding to maximize vertical space */
  background: #111827;
  color: #f9fafb;
  display: flex;        /* flex container for strip + array */
  flex-direction: column;
}
.tp-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 8px;
  font-family: var(--mono);
  font-size: 12px;
  color: #9ca3af;
}
.tp-arr { color: var(--accent); }
.tp-ptr { font-weight: 600; }
.tp-ptr-val { font-weight: 400; opacity: 0.8; }
.tp-left-label { color: #60a5fa; }   /* blue for left */
.tp-right-label { color: #f87171; }  /* red for right */
.tp-empty {
  margin-top: 16px;
  color: #6b7280;
  font-style: italic;
}
.tp-array {
  display: flex;
  gap: 2px;
  overflow-x: visible;
  padding: 4px 0;
}
.tp-cell {
  flex: 1 1 36px;
  min-width: 36px;
  max-width: 80px;
  height: 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 2px solid #374151;
  border-radius: 6px;
  background: #1f2937;
  font-family: var(--mono);
  font-size: 13px;
  position: relative;
  transition: background 0.2s, border-color 0.2s, transform 0.15s;
}
.tp-cell::before {
  content: attr(data-idx);
  position: absolute;
  bottom: -16px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  color: #6b7280;
  white-space: nowrap;
}
/* Pointer roles (2026-11-24): converging pairs read left/right (blue/red),
   same-direction pairs slow/fast (amber/green). Markers below the array
   (.tp-marker) replace the old per-cell ::after triangles so they can slide. */
.tp-at-left  { border-color: #60a5fa; background: #1e3a5f; }
.tp-at-right { border-color: #f87171; background: #5f1e1e; }
.tp-at-slow  { border-color: #fbbf24; background: #4a3710; }
.tp-at-fast  { border-color: #34d399; background: #0f3f30; }
.tp-both     { border-color: #a78bfa; background: #3b1e5f; }
/* Swap pulse (Reverse tab): the cell whose value just changed vs. the
   previous recorded step — ground truth, detected in panels/reverse.js. */
.tp-swap {
  animation: tpSwap 0.45s ease;
}
@keyframes tpSwap {
  0%   { background: #fbbf24; color: #111; transform: scale(1); }
  40%  { transform: scale(1.12); }
  100% { transform: scale(1); }
}
/* Valid Palindrome tab additions (2026-11-05-valid-palindrome-submode-design.md).
   Cells reuse .tp-*; only the palindrome-specific presentation is new. */
.pal-array { flex-wrap: nowrap; align-items: center; }
.pal-dim { opacity: 0.35; }
.pal-gap {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  padding: 0 6px;
}
.pal-badge {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
  color: var(--muted);
}
.pal-match { color: #4ade80; border-color: #4ade80; }
.pal-diff { color: #fbbf24; border-color: #fbbf24; }
.pal-chip {
  font-size: 11px;
  padding: 1px 8px;
  border-radius: 4px;
}
.pal-chip-true { color: #4ade80; background: rgba(74, 222, 128, 0.12); }
.pal-chip-false { color: #fbbf24; background: rgba(251, 191, 36, 0.12); }
.tp-enter {
  animation: tpEnter 0.2s ease-out;
}
@keyframes tpEnter {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

/* Container With Most Water tab (2026-11-05-container-with-most-water-design.md) */
.tp-area { font-weight: 600; color: var(--accent); }
.tp-pulse {
  animation: tpPulse 0.5s ease;
}
@keyframes tpPulse {
  0%   { background: rgba(59, 130, 246, 0.35); transform: scale(1); }
  50%  { background: rgba(59, 130, 246, 0.55); transform: scale(1.05); }
  100% { transform: scale(1); }
}
.tp-cell {
  position: relative;
  overflow: visible;
}
.tp-water {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(59, 130, 246, 0.18);
  border-radius: 4px 4px 0 0;
  pointer-events: none;
  transition: height 0.15s ease;
}
.tp-pulse .tp-water {
  animation: tpWaterPulse 0.5s ease;
  background: rgba(59, 130, 246, 0.35);
}
@keyframes tpWaterPulse {
  0%   { background: rgba(59, 130, 246, 0.35); }
  50%  { background: rgba(59, 130, 246, 0.55); }
  100% { background: rgba(59, 130, 246, 0.35); }
}

/* Container With Most Water: finalized bars + thin bars (2026-11-06-container-finalized-bars-design.md) */
.tp-array[data-container] {
  position: relative;
  align-items: flex-end;      /* bottom-aligned baseline */
  gap: var(--gap, 12px);      /* R2: responsive gap set by JS (--gap); fills the tab width */
  justify-content: safe center; /* R2/Q3: centered when clamped, left + scroll when not */
  flex: 1;                    /* fill all available vertical space */
  min-height: 0;              /* allow flex to determine height */
  overflow: visible;          /* water container positioned absolutely */
  padding-top: 24px;          /* Q2 top band: value label (top:-16 tp-val) */
  padding-bottom: 18px;       /* Q2 bottom band: index label (::before bottom:-14) */
}

.tp-array[data-container] .tp-cell {
  flex: 0 0 auto;             /* Q3: neutralise base flex:1 1 36px growth */
  min-width: 0;               /* Q3: override base min-width:36px */
  max-width: none;            /* Q3: override base max-width:80px */
  width: 10px;                /* Q3: fixed thin bar */
  height: auto;               /* proportional height set by JS */
  min-height: 4px;            /* minimum visible height */
  /* labels are absolutely positioned relative to the cell — no cell padding
     (Q2: the array's 24/18px bands are the ONE reservation) */
  justify-content: flex-end;  /* value label at top */
}

.tp-array[data-container] .tp-cell::before {
  bottom: -14px;              /* index label below bar */
}

.tp-array[data-container] .tp-val {
  position: absolute;
  top: -16px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  /* The pane is always dark (#111827): a fixed light ink, not var(--text),
     which is near-black in light mode and hid every bar's value label. */
  color: #e5e7eb;
  white-space: nowrap;
  pointer-events: none;
}

/* Water container: single rectangle spanning between pointer bars */
.tp-water-container {
  position: absolute;
  bottom: 18px;               /* Q2: aligned with bar bottoms (array bottom−BOTTOM_BAND) */
  background: rgba(59, 130, 246, 0.35);  /* blue water */
  border-radius: 2px;
  pointer-events: none;
  transition: left 150ms ease, width 150ms ease, height 150ms ease;  /* Q5 */
  z-index: 1;  /* above bars, below labels */
}

.tp-water-container.hidden {
  display: none;
}

/* Pulse on max_area update: highlight the water container */
.tp-pulse .tp-water-container {
  animation: tpWaterPulse 0.5s ease;
  background: rgba(59, 130, 246, 0.55);
}
@keyframes tpWaterPulse {
  0%   { background: rgba(59, 130, 246, 0.35); }
  50%  { background: rgba(59, 130, 246, 0.55); }
  100% { background: rgba(59, 130, 246, 0.35); }
}

/* ═══════════════ 2026-11-24 visualisation upgrade ═══════════════ */

/* ---- two-pointers kit (panels/pointerKit.js) ---- */
.tp-head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 4px;
}
.tp-head .tp-strip { flex: 1; margin-bottom: 0; align-items: center; }
.tp-caption {
  min-height: 18px;
  margin: 2px 0 6px;
  font-family: var(--mono);
  font-size: 12px;
  color: #e5e7eb;
}
.tp-caption b { color: #fde68a; }
.tp-cap-muted { color: #9ca3af; font-style: italic; }
.tp-cap-good { color: #4ade80; font-weight: 600; }
.tp-cap-warn { color: #fbbf24; font-weight: 600; }
.tp-track {
  position: relative;
  padding-top: 34px;          /* room for a swap value arcing upward */
}
.tp-track-bars {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding-top: 0;
}
.tp-markers {
  position: relative;
  height: 36px;
  margin-top: 16px;           /* below the cells' index labels */
}
.tp-track-bars .tp-markers { margin-top: 0; flex: 0 0 auto; }
.tp-marker {
  position: absolute;
  left: 0;
  top: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  line-height: 12px;
  white-space: nowrap;
  pointer-events: none;
  transition: transform var(--tp-anim, 320ms) cubic-bezier(.3, .7, .4, 1);
}
.tp-marker-arrow { font-size: 10px; height: 12px; }
.tp-marker-stacked .tp-marker-arrow { display: none; }
.tp-role-left,  .tp-role-text-left  { color: #60a5fa; }
.tp-role-right, .tp-role-text-right { color: #f87171; }
.tp-role-slow,  .tp-role-text-slow  { color: #fbbf24; }
.tp-role-fast,  .tp-role-text-fast  { color: #34d399; }
.tp-cell {
  transition: background var(--tp-anim, 320ms), border-color var(--tp-anim, 320ms),
              opacity var(--tp-anim, 320ms), height var(--tp-anim, 320ms) ease,
              transform 0.15s;
}
/* Settled regions */
.tp-done { background: rgba(52, 211, 153, 0.10); border-color: rgba(52, 211, 153, 0.45); color: #a7f3d0; }
.tp-kept { background: rgba(52, 211, 153, 0.16); border-color: rgba(52, 211, 153, 0.6); color: #d1fae5; }
.tp-out { opacity: 0.32; }
.tp-stale { opacity: 0.45; border-style: dashed; }
/* Ghost slot: one past either end, where a finished loop leaves a pointer */
.tp-ghost {
  border-style: dashed;
  border-color: #4b5563;
  background: transparent;
  opacity: 0.8;
}
.tp-ghost.tp-at-left, .tp-ghost.tp-at-right, .tp-ghost.tp-at-slow, .tp-ghost.tp-at-fast { background: transparent; }
/* Swap arc */
.tp-fly {
  position: absolute;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fbbf24;
  border-radius: 6px;
  background: #3a2c0b;
  color: #fde68a;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  pointer-events: none;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
}
.tp-landing { color: transparent !important; }
/* One-shot flashes on persistent cells */
.tp-found { animation: tpFound 0.7s ease; }
@keyframes tpFound {
  0% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.9); background: #14532d; }
  100% { box-shadow: 0 0 0 10px rgba(74, 222, 128, 0); }
}
.tp-write { animation: tpWrite 0.6s ease; }
@keyframes tpWrite {
  0% { background: #fbbf24; color: #111; transform: translateY(-6px); }
  100% { transform: translateY(0); }
}
/* Badges in the header strip */
.tp-badge {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 4px;
  border: 1px solid #374151;
  color: #d1d5db;
}
.tp-badge-good { color: #4ade80; border-color: #4ade80; background: rgba(74, 222, 128, 0.08); }
.tp-badge-warn { color: #fbbf24; border-color: #fbbf24; background: rgba(251, 191, 36, 0.08); }
/* Legend */
.tp-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 4px;
  font-size: 11px;
  color: #9ca3af;
}
.tp-legend:empty { display: none; }
.tp-legend-item { display: inline-flex; align-items: center; gap: 5px; }
.tp-swatch {
  width: 12px;
  height: 10px;
  border-radius: 2px;
  border: 1px solid #4b5563;
  background: #1f2937;
}
.tp-sw-done  { background: rgba(52, 211, 153, 0.2); border-color: rgba(52, 211, 153, 0.6); }
.tp-sw-kept  { background: rgba(52, 211, 153, 0.3); border-color: rgba(52, 211, 153, 0.8); }
.tp-sw-out   { opacity: 0.35; }
.tp-sw-stale { opacity: 0.5; border-style: dashed; }
.tp-sw-dim   { opacity: 0.35; }
.tp-sw-water { background: rgba(59, 130, 246, 0.45); border-color: #3b82f6; }
.tp-sw-best  { background: transparent; border: 1px dashed #fbbf24; }
/* Pin control */
.tp-pin { flex: 0 0 auto; }
.tp-pin-box { font-size: 11px; color: #9ca3af; position: relative; }
.tp-pin-box summary {
  cursor: pointer;
  list-style: none;
  padding: 1px 7px;
  border: 1px solid #374151;
  border-radius: 4px;
  user-select: none;
}
.tp-pin-box summary::-webkit-details-marker { display: none; }
.tp-pin-box[open] summary { color: #e5e7eb; border-color: #6b7280; }
.tp-pin-form {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 6px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
  white-space: nowrap;
}
.tp-pin-form label { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.tp-pin-form select, .tp-pin-form button {
  font: inherit;
  background: #111827;
  color: #e5e7eb;
  border: 1px solid #374151;
  border-radius: 4px;
  padding: 1px 4px;
}
.tp-pin-form button:disabled { opacity: 0.5; }
/* Container: best-so-far outline + water pulse on the persistent water */
.tp-best {
  position: absolute;
  bottom: 18px;
  border: 2px dashed #fbbf24;
  border-bottom: none;
  border-radius: 2px 2px 0 0;
  pointer-events: none;
  z-index: 2;
  transition: left var(--tp-anim, 320ms) ease, width var(--tp-anim, 320ms) ease, height var(--tp-anim, 320ms) ease;
}
.tp-best.hidden { display: none; }
.tp-best-tag {
  position: absolute;
  top: -15px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--mono);
  font-size: 10px;
  color: #fbbf24;
  white-space: nowrap;
}
.tp-water-container {
  transition: left var(--tp-anim, 320ms) ease, width var(--tp-anim, 320ms) ease, height var(--tp-anim, 320ms) ease;
}
.tp-water-container.tp-pulse { animation: tpWaterPulse 0.6s ease; }
.tp-array[data-container] .tp-cell.tp-out { opacity: 0.3; }

/* ---- recursion tree (panels/recursion.js) ---- */
.rt-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 12px;
}
.rt-toggle { display: inline-flex; border: 1px solid #374151; border-radius: 5px; overflow: hidden; }
.rt-toggle button {
  font: inherit;
  font-size: 11px;
  padding: 1px 9px;
  background: transparent;
  color: #9ca3af;
  border: none;
  cursor: pointer;
}
.rt-toggle button.active { background: #374151; color: #f9fafb; }
.rt-toggle button:disabled { opacity: 0.4; cursor: not-allowed; }
.rt-stats { color: #9ca3af; }
.rt-stats b { color: #e5e7eb; }
.rt-stat-rep b { color: #f472b6; }
.rt-dot { margin: 0 6px; color: #4b5563; }
.rt-main { flex: 1; min-height: 0; display: flex; gap: 8px; }
.rt-scroll {
  flex: 1;
  min-width: 0;
  overflow: auto;
  position: relative;
  scrollbar-width: thin;                 /* dark pane: dark, thin scrollbars */
  scrollbar-color: #4b5563 transparent;
}
.rt-svg { display: block; margin: 0 auto; overflow: visible; }
.rt-text {
  margin: 0;
  font: inherit;
  white-space: pre;
}
.rt-text [data-step] { cursor: pointer; }
.rt-stack {
  flex: 0 0 auto;
  width: 170px;
  overflow: auto;
  border-left: 1px solid #1f2937;
  padding-left: 8px;
  font-size: 11px;
}
@container (max-width: 460px) { .rt-stack { display: none; } }
.rt-stack-title { color: #6b7280; text-transform: uppercase; letter-spacing: 0.06em; font-size: 10px; margin-bottom: 4px; }
.rt-fr {
  padding: 3px 6px;
  margin-bottom: 3px;
  border: 1px solid #374151;
  border-radius: 4px;
  background: #1f2937;
  color: #d1d5db;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.rt-fr-active { border-color: #fbbf24; color: #fde68a; }
.rt-fr-ret { border-color: #34d399; color: #a7f3d0; }
.rt-fr-val { margin-left: 6px; color: #6ee7a0; }
.rt-legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 11px; color: #9ca3af; }
.rt-sw { display: inline-block; width: 12px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; border: 1.5px solid; }
.rt-sw-active { border-color: #fbbf24; background: rgba(251, 191, 36, 0.25); }
.rt-sw-stack { border-color: #fbbf24; border-style: dashed; }
.rt-sw-done { border-color: #34d399; background: rgba(52, 211, 153, 0.15); }
.rt-sw-base { border-color: #2dd4bf; background: rgba(45, 212, 191, 0.3); }
.rt-sw-rep { border-color: #f472b6; background: #f472b6; border-radius: 6px; }
/* nodes */
.rt-node {
  cursor: pointer;
  transition: transform var(--rt-anim, 320ms) cubic-bezier(.3, .7, .4, 1), opacity var(--rt-anim, 320ms);
}
.rt-box { fill: #1f2937; stroke: #4b5563; stroke-width: 1.5; transition: fill 0.2s, stroke 0.2s; }
.rt-label { fill: #e5e7eb; font-family: var(--mono); font-size: 12px; }
.rt-sub { fill: #9ca3af; font-family: var(--mono); font-size: 10.5px; }
.rt-sub-ret { fill: #6ee7a0; font-weight: 700; }
.rt-root .rt-box { fill: #111827; stroke: #374151; stroke-dasharray: 3 3; }
.rt-root .rt-label { fill: #9ca3af; }
.rt-onstack .rt-box { stroke: #fbbf24; stroke-dasharray: 4 3; }
.rt-onstack .rt-label { fill: #fde68a; }
.rt-active .rt-box { fill: rgba(251, 191, 36, 0.2); stroke: #fbbf24; stroke-width: 2.5; filter: drop-shadow(0 0 6px rgba(251, 191, 36, 0.55)); }
.rt-active .rt-label { fill: #fde68a; font-weight: 700; }
.rt-done .rt-box { fill: rgba(52, 211, 153, 0.12); stroke: #34d399; }
.rt-done .rt-label { fill: #a7f3d0; }
.rt-base .rt-box { fill: rgba(45, 212, 191, 0.22); stroke: #2dd4bf; }
.rt-error .rt-box { fill: rgba(248, 113, 113, 0.2); stroke: #f87171; stroke-width: 2.5; }
.rt-error .rt-label { fill: #fca5a5; }
.rt-rep .rt-box { stroke-width: 2.2; }
.rt-badge text { fill: #111827; font-family: var(--mono); font-size: 9.5px; font-weight: 700; }
.rt-hovering .rt-node:not(.rt-same) { opacity: 0.25 !important; }
.rt-hovering .rt-edge { opacity: 0.25; }
/* edges */
.rt-edge {
  fill: none;
  stroke: #374151;
  stroke-width: 1.5;
  transition: d var(--rt-anim, 320ms) cubic-bezier(.3, .7, .4, 1), stroke 0.2s;
}
.rt-edge-done { stroke: rgba(52, 211, 153, 0.45); }
.rt-edge-active { stroke: #fbbf24; stroke-width: 2.5; }
/* value travelling up to the caller */
.rt-flyval rect { fill: #14532d; stroke: #4ade80; stroke-width: 1.5; }
.rt-flyval text { fill: #bbf7d0; font-family: var(--mono); font-size: 11px; font-weight: 700; }
/* text view extras */
.tn-stack { color: #fde68a; opacity: 0.85; }
.tn-base { color: #2dd4bf; font-size: 11px; }
.tn-rep { font-size: 11px; font-weight: 700; }

@media (prefers-reduced-motion: reduce) {
  .tp-marker, .tp-cell, .rt-node, .rt-edge, .tp-water-container, .tp-best { transition: none !important; }
}

/* ═══════════════ 2026-11-24 viewport detection (src/viewport.js) ═══════════════
   html[data-viewport] = phone | tablet | laptop | monitor
   html[data-layout]   = split | stacked      html[data-short] / [data-touch]
   Laptop is the baseline: every rule below adapts FROM it. */

/* ---- visualiser cell sizing: one set of variables per device class ----
   panels/pointerKit.js fitCells() reads --tp-cell-min to decide how many
   cells fit, so CSS stays the single source of sizing truth. */
:root {
  --tp-cell-min: 36px;
  --tp-cell-max: 80px;
  --tp-cell-h: 44px;
  --tp-cell-font: 13px;
  --tp-bar-w: 10px;        /* container bars (container.js reads it) */
}
:root[data-viewport="phone"] {
  --tp-cell-min: 30px;
  --tp-cell-max: 56px;
  --tp-cell-h: 38px;
  --tp-cell-font: 12px;
  --tp-bar-w: 8px;
}
:root[data-viewport="monitor"] {
  --tp-cell-min: 44px;
  --tp-cell-max: 96px;
  --tp-cell-h: 52px;
  --tp-cell-font: 15px;
  --tp-bar-w: 16px;
}
.tp-cell {
  flex: 1 1 var(--tp-cell-min);
  min-width: var(--tp-cell-min);
  max-width: var(--tp-cell-max);
  height: var(--tp-cell-h);
  font-size: var(--tp-cell-font);
}
/* Gap between two pointer windows: "…12…" */
.tp-gap {
  flex: 0 0 auto;
  align-self: center;
  padding: 0 4px;
  font-family: var(--mono);
  font-size: 10px;
  color: #6b7280;
  white-space: nowrap;
}
/* Container on narrow panes: only the pointer bars keep their value label */
.tp-array.tp-tight .tp-cell:not(.tp-at-left):not(.tp-at-right):not(.tp-at-slow):not(.tp-at-fast) .tp-val {
  display: none;
}

/* ---- monitor: more room → larger type in the visualisers ---- */
:root[data-viewport="monitor"] #outputBody,
:root[data-viewport="monitor"] #treeBody { font-size: 14px; line-height: 20px; }
:root[data-viewport="monitor"] .tp-strip,
:root[data-viewport="monitor"] .tp-caption { font-size: 13.5px; }
:root[data-viewport="monitor"] .tp-marker { font-size: 12.5px; }
:root[data-viewport="monitor"] header h1 { font-size: 20px; }
:root[data-viewport="monitor"] .mirror,
:root[data-viewport="monitor"] textarea { font-size: 15px; line-height: 24px; }
:root[data-viewport="monitor"] .mirror .row { height: 24px; }
:root[data-viewport="monitor"] .tp-legend,
:root[data-viewport="monitor"] .rt-legend { font-size: 12px; }

/* ---- short windows (e.g. 1366×768 laptops): trim chrome, keep the visual ---- */
:root[data-short] header { padding: 6px 14px; }
:root[data-short] header h1 { font-size: 16px; }
:root[data-short] main { padding: 8px; }
:root[data-short] #toolbar { padding: 6px 10px; }
:root[data-short] .legend { display: none; }
:root[data-short] .tp-track { padding-top: 24px; }
:root[data-short] .tp-caption { margin-bottom: 2px; }

/* ---- stacked layout (phones, upright tablets): one scrolling column ----
   Order: editor → visualisation → variables; the step controls dock at the
   bottom of the screen (viewport.js moves #controlsPanel into <body>). */
:root[data-layout="stacked"],
:root[data-layout="stacked"] body { height: auto; min-height: 100%; }
:root[data-layout="stacked"] body {
  padding-bottom: calc(var(--dock-h, 0px) + 8px);
}
:root[data-layout="stacked"] main {
  flex: none;
  flex-direction: column;
  padding: 8px;
  gap: 10px;
}
:root[data-layout="stacked"] #divider,
:root[data-layout="stacked"] #vdivider { display: none; }
:root[data-layout="stacked"] #left { flex: none; }
:root[data-layout="stacked"] .editor {
  flex: none;
  height: clamp(200px, 40vh, 520px);
  height: clamp(200px, 40svh, 520px);
  border-radius: 0 0 9px 9px;
  overflow: hidden;
}
:root[data-layout="stacked"] #right {
  width: auto !important;          /* beats a split-layout splitter drag */
  flex: none;
  gap: 10px;
}
:root[data-layout="stacked"] #outputPanel {
  order: -1;                       /* the visualisation right under the code */
  flex: none;
  height: clamp(340px, 68vh, 760px);
  height: clamp(340px, 68svh, 760px);
}
:root[data-layout="stacked"] #varsPanel {
  height: auto !important;
  max-height: 45vh !important;
  max-height: 45svh !important;
  min-height: 110px;
}

/* Bottom dock for the step controls */
#controlsPanel.dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 12px 12px 0 0;
  background: var(--panel);
  box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.18);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
#controlsPanel.dock h2,
#controlsPanel.dock .legend { display: none; }
#controlsPanel.dock .body { padding: 8px 10px 4px; gap: 6px; }
#controlsPanel.dock #stepSlider { margin: 2px 0 4px; }

/* ---- phone ---- */
:root[data-viewport="phone"] header { padding: 8px 10px; gap: 8px; }
:root[data-viewport="phone"] header h1 { font-size: 15px; }
:root[data-viewport="phone"] #status { font-size: 11px; padding: 2px 8px; }
:root[data-viewport="phone"] .hint { display: none; }
:root[data-viewport="phone"] #toolbar { padding: 8px; gap: 8px; }
:root[data-viewport="phone"] #btnVisualize,
:root[data-viewport="phone"] #btnEdit { padding: 7px 12px; }
/* Dock: icons only (aria-labels keep the names), one compact row + slider */
:root[data-viewport="phone"] #controlsPanel.dock .bt { display: none; }
:root[data-viewport="phone"] #controlsPanel.dock button {
  padding: 7px 0;
  min-width: 40px;
  font-size: 15px;
}
:root[data-viewport="phone"] #controlsPanel.dock #playSpeed {
  padding: 7px 22px 7px 8px;
  font-size: 13px;
  background-position: right 7px center;
}
:root[data-viewport="phone"] #controlsPanel.dock #stepLabel { font-size: 12px; }
/* Smaller type inside the visualisers */
:root[data-viewport="phone"] .tp-strip { font-size: 11px; gap: 8px; }
:root[data-viewport="phone"] .tp-caption { font-size: 11px; }
:root[data-viewport="phone"] .tp-marker { font-size: 10px; }
:root[data-viewport="phone"] .tp-legend,
:root[data-viewport="phone"] .rt-legend { font-size: 10px; gap: 8px; }
:root[data-viewport="phone"] .tp-track { padding-top: 26px; }
:root[data-viewport="phone"] #outputBody,
:root[data-viewport="phone"] #treeBody { font-size: 12px; line-height: 17px; }
/* DSA menu: no side flyouts on a phone — sub-menus open inline below */
:root[data-viewport="phone"] .dsa-options {
  max-width: calc(100vw - 24px);
  max-height: 70vh;
  max-height: 70svh;
  overflow-y: auto;
}
:root[data-viewport="phone"] .dsa-submenu {
  position: static;
  min-width: 0;
  max-height: none !important;
  margin: 2px 0 4px 14px;
  padding: 0;
  border: none;
  border-left: 2px solid var(--border);
  border-radius: 0;
  box-shadow: none;
}
:root[data-viewport="phone"] .dsa-options li.has-submenu > button::after { content: '▾'; }
:root[data-viewport="phone"] .dsa-options button { padding: 10px 12px; font-size: 14px; }

/* ---- touch screens: finger-sized targets, no iOS zoom-on-focus ---- */
:root[data-touch] #stepSlider { height: 28px; }
:root[data-touch][data-viewport="phone"] .mirror,
:root[data-touch][data-viewport="phone"] textarea { font-size: 16px; line-height: 24px; }
:root[data-touch][data-viewport="phone"] .mirror .row { height: 24px; }
:root[data-touch] .rt-toggle button { padding: 5px 12px; }
:root[data-touch] .tp-pin-box summary { padding: 4px 9px; }
