/* interval-arithmetic — SICP 2.1.4 trace explorer.
   Palette mirrors the ported vanilla-JS/HTML reference's :root tokens,
   scoped under #tool-root so it doesn't leak into the rest of the page. */
#tool-root {
  --ia-bg: #EAEEF1; --ia-surface: #FFFFFF; --ia-ink: #1D2B36; --ia-muted: #5B6873; --ia-rule: #C6CFD6;
  --ia-cur: #2B59C3; --ia-cur-soft: #D9E3F7; --ia-hit: #178577; --ia-one: #C27D0E; --ia-zero: #9AA5AE;
  --ia-bad: #C2413B; --ia-vio: #7A5AB8;
  font-family: 'IBM Plex Sans', system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ia-ink);
}
@media (prefers-color-scheme: dark) {
  #tool-root:not([data-ia-theme="light"]) {
    --ia-bg: #141A20; --ia-surface: #1C242C; --ia-ink: #E2E7EB; --ia-muted: #95A2AC; --ia-rule: #35414C;
    --ia-cur: #7FA3FF; --ia-cur-soft: #26324D; --ia-hit: #45BFAE; --ia-one: #E5A845; --ia-zero: #5E6B76;
    --ia-bad: #F07167; --ia-vio: #B49AF0;
  }
}
#tool-root code, #tool-root .ia-mono { font-family: 'IBM Plex Mono', ui-monospace, Menlo, Consolas, monospace; }
#tool-root button, #tool-root input, #tool-root select { font: inherit; color: inherit; }

#tool-root .ia-lede { color: var(--ia-muted); max-width: 74ch; margin-bottom: 16px; }

#tool-root .ia-controls {
  display: grid; grid-template-columns: 1.25fr 1fr; gap: 28px;
  padding: 18px 0; border-top: 1px solid var(--ia-rule); border-bottom: 1px solid var(--ia-rule);
}
#tool-root .ia-lbl { display: block; font-weight: 500; margin-bottom: 6px; }
#tool-root #ia-var-cv {
  display: block; width: 100%; height: 118px; touch-action: none;
  background: var(--ia-surface); border: 1px solid var(--ia-rule); border-radius: 4px;
}
#tool-root table.ia-vars { border-collapse: collapse; margin-top: 10px; font-size: 13px; }
#tool-root table.ia-vars th { font-weight: 500; color: var(--ia-muted); text-align: left; padding: 0 8px 4px 0; }
#tool-root table.ia-vars td { padding: 2px 8px 2px 0; }
#tool-root table.ia-vars input {
  width: 9ch; font-family: 'IBM Plex Mono', monospace; font-size: 13px; padding: 3px 6px;
  border: 1px solid var(--ia-rule); border-radius: 3px; background: var(--ia-surface); color: inherit;
}
#tool-root .ia-vname { font: 500 14px 'IBM Plex Mono', monospace; display: inline-flex; align-items: center; gap: 6px; }
#tool-root .ia-vdot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
#tool-root .ia-presets { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
#tool-root .ia-presets button {
  border: 1px solid var(--ia-rule); background: transparent; border-radius: 14px; padding: 2px 10px;
  font-size: 13px; cursor: pointer; color: inherit;
}
#tool-root .ia-presets button:hover { border-color: var(--ia-muted); }
#tool-root .ia-hint { color: var(--ia-muted); font-size: 13px; margin-top: 6px; }
#tool-root .ia-exprrow { display: grid; grid-template-columns: 1.4em 1fr; align-items: center; gap: 8px; margin-bottom: 8px; }
#tool-root .ia-exprrow b { font: 500 14px 'IBM Plex Mono', monospace; color: var(--ia-muted); }
#tool-root .ia-exprrow input {
  width: 100%; font: 14px 'IBM Plex Mono', monospace; padding: 6px 9px;
  border: 1px solid var(--ia-rule); border-radius: 4px; background: var(--ia-surface); color: inherit;
}
#tool-root .ia-err { color: var(--ia-bad); font-size: 13px; margin: -4px 0 8px 2.2em; }
#tool-root .ia-err[hidden] { display: none; }
#tool-root .ia-seg { display: inline-flex; border: 1px solid var(--ia-rule); border-radius: 5px; overflow: hidden; background: var(--ia-surface); }
#tool-root .ia-seg label { position: relative; }
#tool-root .ia-seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
#tool-root .ia-seg span { display: block; padding: 4px 12px; font-size: 13px; border-right: 1px solid var(--ia-rule); cursor: pointer; }
#tool-root .ia-seg label:last-child span { border-right: 0; }
#tool-root .ia-seg input:checked + span { background: var(--ia-cur); color: var(--ia-surface); }
#tool-root .ia-opts { display: grid; gap: 10px; margin-top: 14px; font-size: 14px; }
#tool-root .ia-opt { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
#tool-root .ia-chk { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
#tool-root .ia-chk input { accent-color: var(--ia-cur); width: 16px; height: 16px; margin: 0; }

#tool-root .ia-result { padding: 18px 0 6px; }
#tool-root .ia-answer { font-size: 20px; line-height: 1.4; max-width: 70ch; }
#tool-root .ia-answer code { font: 500 18px 'IBM Plex Mono', monospace; }
#tool-root .ia-compare { color: var(--ia-muted); margin-top: 6px; max-width: 95ch; }

#tool-root .ia-transport { padding: 12px 0 10px; border-bottom: 1px solid var(--ia-rule); }
#tool-root .ia-tbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
#tool-root .ia-tbar button {
  height: 32px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--ia-rule); background: var(--ia-surface); border-radius: 4px; cursor: pointer; padding: 0 10px;
  color: inherit;
}
#tool-root .ia-tbar button:hover { border-color: var(--ia-muted); }
#tool-root .ia-tbar button.ia-play { background: var(--ia-cur); border-color: var(--ia-cur); color: var(--ia-surface); font-weight: 500; }
#tool-root #ia-step-range { flex: 1; min-width: 160px; accent-color: var(--ia-cur); }
#tool-root .ia-steplabel { font: 13px 'IBM Plex Mono', monospace; color: var(--ia-muted); min-width: 12ch; text-align: right; }
#tool-root .ia-speed { font-size: 13px; color: var(--ia-muted); display: inline-flex; align-items: center; gap: 6px; }
#tool-root .ia-speed select { border: 1px solid var(--ia-rule); background: var(--ia-surface); border-radius: 4px; padding: 3px 4px; }
#tool-root #ia-strip { display: block; width: 100%; height: 44px; margin-top: 10px; cursor: crosshair; touch-action: none; border-radius: 3px; }
#tool-root .ia-caption { color: var(--ia-muted); font-size: 13px; margin-top: 4px; }

#tool-root .ia-work { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px; margin-top: 16px; }
#tool-root .ia-panel { background: var(--ia-surface); border: 1px solid var(--ia-rule); border-radius: 6px; padding: 14px 16px; min-width: 0; }
#tool-root .ia-side { display: grid; gap: 16px; align-content: start; min-width: 0; }
#tool-root .ia-treewrap { overflow: auto; border-top: 1px solid var(--ia-rule); margin: 0 -16px; max-height: 420px; }
#tool-root .ia-treewrap svg { display: block; }
#tool-root .ia-tree .e { stroke: var(--ia-rule); }
#tool-root .ia-tree .e.r { stroke: var(--ia-muted); }
#tool-root .ia-tree .n circle { fill: var(--ia-surface); stroke: var(--ia-rule); stroke-width: 1.5; }
#tool-root .ia-tree .n.u { opacity: .5; }
#tool-root .ia-tree .n.d circle { fill: var(--ia-ink); stroke: var(--ia-ink); }
#tool-root .ia-tree .n.x circle { fill: var(--ia-bad); stroke: var(--ia-bad); }
#tool-root .ia-tree .n.cur circle { stroke: var(--ia-cur); stroke-width: 4; }
#tool-root .ia-tree .op { font: 500 13px 'IBM Plex Mono', monospace; text-anchor: middle; fill: var(--ia-ink); pointer-events: none; }
#tool-root .ia-tree .n.d .op, #tool-root .ia-tree .n.x .op { fill: var(--ia-surface); }
#tool-root .ia-tree .iv { font: 10.5px 'IBM Plex Mono', monospace; text-anchor: middle; fill: var(--ia-muted); }
#tool-root .ia-tree .n.cur .iv { fill: var(--ia-cur); font-weight: 500; }
#tool-root .ia-tree .n.x .iv { fill: var(--ia-bad); }
#tool-root .ia-tree .ttl { font: 500 13px inherit; fill: var(--ia-muted); }
#tool-root .ia-tree .n { cursor: pointer; }

#tool-root pre.ia-code { font: 12.5px/1.65 'IBM Plex Mono', monospace; margin: 0; overflow-x: auto; }
#tool-root pre.ia-code .ia-ln { display: block; padding: 0 8px; border-left: 3px solid transparent; white-space: pre; }
#tool-root pre.ia-code .ia-ln.ia-off { color: var(--ia-zero); }
#tool-root pre.ia-code .ia-ln.ia-hl { background: var(--ia-cur-soft); border-left-color: var(--ia-cur); }
#tool-root .ia-event { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--ia-rule); min-height: 4.5em; }
#tool-root table.ia-det { border-collapse: collapse; font: 12.5px/1.6 'IBM Plex Mono', monospace; width: 100%; }
#tool-root table.ia-det th { font: 500 12.5px inherit; color: var(--ia-muted); text-align: left; padding: 3px 8px; }
#tool-root table.ia-det td { padding: 3px 8px; border-top: 1px solid var(--ia-rule); }
#tool-root table.ia-det td.ia-min { box-shadow: inset 0 0 0 2px var(--ia-cur); }
#tool-root table.ia-det td.ia-max { box-shadow: inset 0 0 0 2px var(--ia-one); }
#tool-root table.ia-det td.ia-skip { color: var(--ia-zero); }
#tool-root .ia-detnote { font-size: 13px; color: var(--ia-muted); margin-top: 8px; }
#tool-root .ia-detnote.ia-bad { color: var(--ia-bad); }

#tool-root .ia-rowspanel { margin-top: 16px; }
#tool-root .ia-rows { display: flex; flex-direction: column; }
#tool-root .ia-row-head {
  font: 500 12.5px inherit; color: var(--ia-muted); padding: 10px 0 4px;
  border-top: 1px solid var(--ia-rule); margin-top: 6px;
}
#tool-root .ia-row-head:first-child { border-top: 0; margin-top: 0; }
#tool-root .ia-row {
  display: grid; grid-template-columns: minmax(0, 220px) 1fr auto; align-items: center; gap: 10px;
  padding: 5px 6px; border-radius: 3px;
}
#tool-root .ia-row.ia-row-cur { background: var(--ia-cur-soft); }
#tool-root .ia-row-label {
  font: 12.5px 'IBM Plex Mono', monospace; color: var(--ia-ink); overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
#tool-root .ia-row-track { position: relative; height: 16px; background: var(--ia-bg); border-radius: 2px; }
#tool-root .ia-row-sample { position: absolute; top: 3px; height: 10px; background: var(--ia-hit); opacity: 0.35; border-radius: 2px; }
#tool-root .ia-row-bar { position: absolute; top: 5px; height: 6px; border-radius: 2px; min-width: 2px; }
#tool-root .ia-row-val {
  font: 11.5px 'IBM Plex Mono', monospace; color: var(--ia-muted); white-space: nowrap;
  text-align: right; min-width: 8ch;
}
#tool-root .ia-legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--ia-muted); margin-top: 8px; }
#tool-root .ia-legend span { display: inline-flex; align-items: center; gap: 6px; }
#tool-root .ia-sw { width: 14px; height: 8px; display: inline-block; border-radius: 1px; }

@media (max-width: 920px) {
  #tool-root .ia-controls { grid-template-columns: 1fr; }
  #tool-root .ia-work { grid-template-columns: 1fr; }
}
