:root {
  --bg: transparent;
  --panel: #ffffff;
  --panel-border: #d7dbe2;
  --text: #22252b;
  --muted: #5b6472;
  --accent: #8a5a12;
  --accent-soft: #efe3c9;
  --active: #b43c2f;
  --shadow: rgba(25, 35, 52, 0.04);
  --code-bg: #fbfcfd;
  --stack-active: #fff2df;
  --sidebar-width: 625px;
  --source-panel-height: 260px;
  --workspace-height: 42rem;
  --ui-font: "Helvetica Neue", Helvetica, Arial, sans-serif;
  --code-font: ui-monospace, "SFMono-Regular", "Cascadia Mono", "DejaVu Sans Mono", monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--ui-font);
  background: transparent;
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  max-width: none;
  margin: 1.5rem auto 2rem;
  padding: 0 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  color: var(--text);
}

.hero {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(860px, 1040px);
  gap: 1rem;
  align-items: start;
}

.hero-side {
  display: grid;
  grid-template-columns: 220px 240px minmax(320px, 1fr);
  gap: 14px;
  align-items: start;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.68rem;
  font-weight: 700;
}

.hero h1 {
  margin: 0 0 6px;
  font-family: var(--ui-font);
  font-size: clamp(1.35rem, 1.7vw, 1.7rem);
  line-height: 1.18;
}

.lede {
  margin: 0;
  max-width: 58ch;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.45;
}

.summary-card,
.panel,
.controls-panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  box-shadow: 0 1px 2px var(--shadow);
}

.summary-card {
  padding: 10px 12px;
}

.example-picker-card {
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  box-shadow: 0 1px 2px var(--shadow);
}

.example-picker-card select {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
}

.summary-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 6px;
}

.summary-value {
  font-size: 1.08rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.summary-meta {
  color: var(--muted);
  margin-top: 2px;
  font-size: 0.92rem;
}

.controls-panel {
  display: grid;
  grid-template-columns: auto minmax(280px, 1fr) minmax(260px, 420px);
  gap: 16px;
  align-items: center;
  padding: 10px 14px;
  position: static;
}

.controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.controls button {
  border: 1px solid #cbd2dc;
  border-radius: 6px;
  padding: 7px 12px;
  background: #f7f9fb;
  color: var(--text);
  cursor: pointer;
}

.controls button:hover {
  background: #eef2f6;
}

.step-range {
  display: grid;
  gap: 6px;
  color: var(--muted);
  min-width: 0;
}

.step-range input {
  width: 100%;
}

.step-readout {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.step-readout span:first-child {
  font-weight: 700;
}

.step-readout span:last-child {
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, var(--sidebar-width)) 12px minmax(0, 1fr);
  gap: 0;
  min-height: var(--workspace-height);
  height: var(--workspace-height);
  overflow: hidden;
  align-items: stretch;
}

.workspace-height-splitter {
  position: relative;
  height: 12px;
  cursor: row-resize;
  touch-action: none;
}

.workspace-height-splitter::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 84px;
  height: 2px;
  transform: translate(-50%, -50%);
  border-radius: 999px;
  background: rgba(119, 131, 148, 0.35);
  transition: background 120ms ease;
}

.workspace-height-splitter:hover::before,
.app-shell.is-resizing-height .workspace-height-splitter::before {
  background: rgba(138, 90, 18, 0.75);
}

.sidebar {
  display: grid;
  grid-template-rows: minmax(180px, var(--source-panel-height)) 12px minmax(180px, 1fr);
  gap: 0;
  min-height: 0;
  overflow: hidden;
  padding-right: 12px;
}

.sidebar-splitter {
  position: relative;
  min-width: 0;
  cursor: row-resize;
  touch-action: none;
}

.sidebar-splitter::before {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  top: 50%;
  height: 2px;
  transform: translateY(-50%);
  border-radius: 999px;
  background: rgba(119, 131, 148, 0.35);
  transition: background 120ms ease;
}

.sidebar-splitter:hover::before,
.sidebar.is-resizing .sidebar-splitter::before {
  background: rgba(138, 90, 18, 0.75);
}

.workspace-splitter {
  position: relative;
  min-height: 0;
  cursor: col-resize;
  touch-action: none;
}

.workspace-splitter::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 8px;
  bottom: 8px;
  width: 2px;
  transform: translateX(-50%);
  border-radius: 999px;
  background: rgba(119, 131, 148, 0.35);
  transition: background 120ms ease;
}

.workspace-splitter:hover::before,
.workspace.is-resizing .workspace-splitter::before {
  background: rgba(138, 90, 18, 0.75);
}

.source-panel {
  min-height: 0;
}

.stack-panel {
  min-height: 0;
}

.tree-panel {
  min-height: 0;
  height: 100%;
  margin-left: 12px;
}

.panel {
  overflow: hidden;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.panel-header {
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--panel-border);
}

.panel-header h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.source-code {
  padding: 10px 12px 6px;
  background: var(--code-bg);
  overflow: auto;
  flex: 1;
}

.tree-canvas {
  padding: 12px 12px 6px;
  overflow: auto;
  flex: 1;
  background:
    linear-gradient(180deg, rgba(248, 250, 252, 0.86), rgba(248, 250, 252, 0.86)),
    linear-gradient(90deg, rgba(210, 216, 226, 0.28) 1px, transparent 1px),
    linear-gradient(rgba(210, 216, 226, 0.28) 1px, transparent 1px);
  background-size: auto, 24px 24px, 24px 24px;
}

.tree-stage {
  min-width: 100%;
  min-height: 100%;
  width: max-content;
  height: max-content;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.tree-shared-state {
  display: none;
  padding: 10px 14px;
  border-bottom: 1px solid var(--panel-border);
  background: #f8fafc;
}

.tree-shared-state.is-visible {
  display: grid;
  gap: 8px;
}

.tree-shared-title {
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.tree-shared-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 12px;
}

.tree-shared-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  align-items: start;
  padding: 8px 10px;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.88);
}

.tree-shared-name {
  font-family: var(--code-font);
  color: var(--muted);
}

.tree-shared-value {
  font-family: var(--code-font);
  color: var(--text);
  word-break: break-word;
}

.tree-shared-legend {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.75rem;
  padding-top: 0.2rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.tree-shared-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.tree-shared-legend-marker-grid {
  display: inline-grid;
  grid-template-columns: auto auto;
  column-gap: 0.35rem;
  align-items: start;
}

.tree-shared-legend-marker-label {
  white-space: nowrap;
}

.tree-shared-legend-marker-values {
  display: flex;
  flex-direction: column;
  gap: 0.06rem;
}

.tree-shared-legend-swatch {
  width: 0.72rem;
  height: 0.72rem;
  border-radius: 999px;
  flex: 0 0 auto;
}

.tree-shared-cell {
  display: inline-block;
  padding: 0 0.16rem;
  border-radius: 0.2rem;
}

.tree-shared-cell.is-highlighted.tone-0,
.tree-shared-legend-swatch.tone-0 {
  background: rgba(245, 208, 54, 0.34);
}

.tree-shared-cell.is-highlighted.tone-1,
.tree-shared-legend-swatch.tone-1 {
  background: rgba(147, 197, 253, 0.34);
}

.tree-shared-cell.is-highlighted.tone-2,
.tree-shared-legend-swatch.tone-2 {
  background: rgba(167, 243, 208, 0.4);
}

.tree-shared-cell.is-highlighted.tone-3,
.tree-shared-legend-swatch.tone-3 {
  background: rgba(253, 186, 116, 0.34);
}

.tree-shared-cell.is-highlighted.tone-4,
.tree-shared-legend-swatch.tone-4 {
  background: rgba(216, 180, 254, 0.34);
}

.tree-shared-cell.is-highlighted.tone-5,
.tree-shared-legend-swatch.tone-5 {
  background: rgba(244, 173, 196, 0.34);
}

.tree-shared-cell.is-marker,
.tree-shared-legend-swatch.is-marker {
  background: rgba(37, 99, 235, 0.12);
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.48);
}

.tree-shared-cell.is-marker {
  font-weight: 700;
}

.tree-svg {
  display: block;
  min-width: 100%;
}

.tree-edge {
  stroke: #8a97a9;
  stroke-width: 2.2;
  fill: none;
  opacity: 0.42;
}

.tree-edge.is-active-path {
  opacity: 1;
  stroke: #b43c2f;
}

.tree-node-circle {
  fill: #ffffff;
  stroke: #8f9bad;
  stroke-width: 2.2;
  opacity: 0.68;
}

.tree-node.is-active-path .tree-node-circle {
  opacity: 1;
}

.tree-node.is-active .tree-node-circle {
  fill: #fff2df;
  stroke: #b43c2f;
  stroke-width: 3.2;
}

.tree-node.is-returned .tree-node-circle {
  fill: #f4f6f9;
}

.tree-node-label {
  font-family: var(--ui-font);
  font-size: 14px;
  fill: var(--text);
}

.tree-node-label-highlight {
  fill: var(--active);
  font-weight: 700;
}

.tree-node-label-marker {
  text-decoration: underline;
  text-decoration-thickness: 1.5px;
}

.tree-node-value {
  font-family: var(--code-font);
  font-size: 13px;
  fill: var(--muted);
}

.tree-node-value-bg {
  fill: rgba(255, 255, 255, 0.94);
  stroke: rgba(205, 212, 222, 0.95);
  stroke-width: 0.8;
}

.tree-node-value.is-persistent-leaf {
  fill: #8a7869;
  opacity: 0.9;
}

.tree-node-value.is-persistent-return {
  fill: #8a7869;
  opacity: 0.82;
}

.tree-edge-label {
  font-family: var(--code-font);
  font-size: 12px;
  fill: var(--active);
  text-anchor: start;
}

.source-line {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 6px;
  align-items: start;
  padding: 4px 8px;
  border-radius: 8px;
  white-space: pre;
  font-family: var(--code-font);
  font-size: 0.95rem;
  line-height: 1.38;
}

.source-line.is-active {
  background: linear-gradient(90deg, rgba(214, 163, 54, 0.18), rgba(214, 163, 54, 0));
  outline: 1px solid rgba(214, 163, 54, 0.22);
}

.source-line.is-condition-true {
  background: linear-gradient(90deg, rgba(74, 124, 89, 0.18), rgba(74, 124, 89, 0));
}

.source-line.is-condition-false {
  background: linear-gradient(90deg, rgba(192, 57, 43, 0.18), rgba(192, 57, 43, 0));
}

.source-line-number {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  color: var(--muted);
  text-align: right;
  user-select: none;
}

.source-fold-toggle,
.source-fold-spacer {
  width: 14px;
  height: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.source-fold-toggle {
  border: 1px solid var(--panel-border);
  border-radius: 3px;
  background: #fff;
  color: var(--muted);
  font: inherit;
  font-size: 0.78rem;
  line-height: 1;
  padding: 0;
  cursor: pointer;
}

.source-fold-toggle:hover {
  color: var(--active);
  border-color: #d7b48c;
}

.source-line-marker {
  display: inline-block;
  width: 14px;
  color: #9b6a18;
  font-weight: 700;
}

.source-fold-ellipsis {
  color: var(--muted);
}

.source-token-keyword {
  font-weight: 700;
  color: #5c4b32;
}

.source-token-type {
  font-weight: 700;
  color: #79540e;
}

.source-token-number {
  color: #7a5a22;
}

.source-line.is-condition-true .source-line-marker {
  color: #2f7d4a;
}

.source-line.is-condition-false .source-line-marker {
  color: #b43c2f;
}

.source-expression-highlight {
  background: rgba(138, 90, 18, 0.14);
  color: #6e531d;
  border-radius: 4px;
  padding: 0 2px;
  box-shadow: inset 0 -1px 0 rgba(138, 90, 18, 0.24);
}

.stack-list {
  padding: 16px;
  overflow: auto;
  flex: 1;
}

.stack-item {
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
  background: #fff;
  display: grid;
  grid-template-rows: auto auto;
  grid-template-columns: minmax(0, 1fr) minmax(150px, 0.95fr);
  gap: 14px;
}

.stack-item.is-active {
  background: var(--stack-active);
  border-color: #d98d3a;
}

.stack-item.is-entering {
  animation: stack-frame-enter 420ms ease-out;
}

@keyframes stack-frame-enter {
  0% {
    background: #fff;
    border-color: #efe2cf;
    box-shadow: 0 0 0 0 rgba(217, 141, 58, 0);
    opacity: 0.65;
    transform: translateY(-6px);
  }

  55% {
    background: #fff7eb;
    border-color: #e4b16d;
    box-shadow: 0 0 0 4px rgba(217, 141, 58, 0.12);
    opacity: 1;
    transform: translateY(0);
  }

  100% {
    background: var(--stack-active);
    border-color: #d98d3a;
    box-shadow: 0 0 0 0 rgba(217, 141, 58, 0);
    opacity: 1;
    transform: translateY(0);
  }
}

.stack-info,
.stack-locals {
  min-width: 0;
}

.stack-heading {
  grid-column: 1 / -1;
  font-weight: 700;
  margin-bottom: -2px;
}

.stack-meta {
  color: var(--muted);
  font-size: 0.95rem;
  margin-top: 4px;
}

.stack-ref-toggle {
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  padding: 0;
  border: 1px solid var(--panel-border);
  border-radius: 3px;
  background: #fff;
  color: var(--muted);
  font: inherit;
  font-size: 0.78rem;
  line-height: 1;
  text-align: center;
  cursor: pointer;
}

.stack-ref-toggle:hover {
  color: var(--active);
  border-color: #d7b48c;
}

.stack-ref-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.85rem;
}

.stack-ref-section {
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr);
  gap: 6px;
  align-items: start;
  margin-bottom: 8px;
}

.stack-ref-toggle-column {
  display: flex;
  align-items: start;
  justify-content: center;
  padding-top: 7px;
}

.stack-ref-rows > .local-row {
  margin-bottom: 8px;
}

.stack-ref-rows > .local-row:last-child {
  margin-bottom: 0;
}

.empty-state {
  color: var(--muted);
  font-style: italic;
}

.local-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 7px 9px;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  background: #fff;
  margin-bottom: 8px;
}

.local-row.is-reference {
  cursor: help;
  border-style: dashed;
}


.local-name {
  font-family: var(--code-font);
  font-size: 0.9rem;
}

.local-value {
  font-weight: 700;
  font-size: 0.9rem;
}

@media (max-width: 1040px) {
  .hero,
  .controls-panel,
  .workspace {
    grid-template-columns: 1fr;
  }

  .hero-side {
    grid-template-columns: 1fr;
  }

  .app-shell {
    height: auto;
    overflow: visible;
    margin: 1rem 0 1.5rem;
    padding: 0 0.75rem;
  }

  .workspace {
    height: auto;
    min-height: 0;
    overflow: visible;
  }

  .sidebar {
    display: grid;
    grid-template-rows: none;
    gap: 14px;
    overflow: visible;
    padding-right: 0;
  }

  .sidebar-splitter,
  .workspace-splitter,
  .workspace-height-splitter {
    display: none;
  }

  .tree-panel {
    margin-left: 0;
  }

  .step-readout {
    min-width: 0;
  }
}

@media (min-width: 1680px) {
  .workspace {
    grid-template-columns: minmax(380px, var(--sidebar-width)) 12px minmax(0, 1fr);
  }

  .tree-canvas {
    padding-left: 20px;
    padding-right: 20px;
  }
}
