:root {
  color-scheme: dark;
  --bg: #0a0d14;
  --slate: #0f141c;
  --elev: #151c27;
  --text: #e1e2ec;
  --parchment: #f1f5f9;
  --muted: #94a3b8;
  --faint: #64748b;
  --line: #1e293b;
  --line-2: #334155;
  --emerald: #4edea3;
  --emerald-deep: #10b981;
  --cyan: #4cd7f6;
  --amber: #ffb95f;
  --danger: #ffb4ab;
  --violet: #d6bcfa;
  --sans: "Segoe UI", system-ui, sans-serif;
  --serif: Palatino, "Palatino Linotype", "Iowan Old Style", Georgia, serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body { margin: 0; background: var(--bg); }

body {
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  background:
    radial-gradient(circle at 8% 0%, rgba(16, 185, 129, 0.08), transparent 28%),
    radial-gradient(circle at 92% 4%, rgba(6, 182, 212, 0.07), transparent 26%),
    var(--bg);
}

button, input { font: inherit; color: inherit; }

button { cursor: pointer; }

.app {
  width: min(1080px, 100%);
  margin: 0 auto;
  padding: 18px 16px 28px;
}

.eyebrow, .kicker {
  margin: 0 0 6px;
  color: var(--cyan);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.top h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(1.7rem, 3vw, 2.3rem);
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--parchment);
  line-height: 1.15;
}

.lede {
  margin: 8px 0 0;
  max-width: 68ch;
  color: var(--muted);
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0 12px;
}

.tabs button, .transport button, .btn {
  min-height: 44px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid var(--line-2);
  background: var(--slate);
  color: var(--parchment);
}

.tabs button[aria-selected="true"] {
  border-color: var(--emerald-deep);
  color: var(--emerald);
  box-shadow: inset 0 0 0 1px rgba(16, 185, 129, 0.35);
}

.btn.primary, .transport button.primary {
  background: var(--emerald-deep);
  border-color: var(--emerald);
  color: #052117;
  font-weight: 650;
}

button:hover { border-color: var(--cyan); }

button:disabled { opacity: 0.4; cursor: not-allowed; }

button:focus-visible, input:focus-visible, .node:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.narration {
  min-height: 4.8em;
  margin: 0 0 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--slate);
  color: var(--parchment);
}

.app button {
  min-height: 44px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--line-2);
  background: var(--slate);
  color: var(--parchment);
}

.stage {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(15, 20, 28, 0.92);
  padding: 8px;
  overflow-x: auto;
}

.stage-scroll { overflow-x: auto; }

.tree-frame { width: 100%; min-width: 640px; }

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

.node rect {
  fill: var(--elev);
  stroke: var(--line-2);
  stroke-width: 1.5;
}

.node text { text-anchor: middle; }

.node-label {
  fill: var(--faint);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.08em;
}

.node-hash {
  fill: var(--parchment);
  font-family: var(--mono);
  font-size: 13px;
}

.node.is-leaf rect { stroke: #1c4550; }
.node.is-root rect { stroke: var(--amber); }
.node.is-selected rect { fill: #10261c; stroke: var(--emerald); stroke-width: 2; }
.node.is-sibling rect { fill: #0d2430; stroke: var(--cyan); stroke-width: 2; }
.node.is-path rect { fill: #10261c; stroke: var(--emerald-deep); stroke-width: 2; }
.node.is-dirty rect { fill: #2a1c0c; stroke: var(--amber); stroke-width: 2; }
.node.is-fresh rect { fill: #10261c; stroke: var(--emerald); stroke-width: 2; }
.node.is-tampered rect { fill: #2a1214; stroke: var(--danger); stroke-width: 2; }
.node.is-dim { opacity: 0.34; }
.node.is-kept { opacity: 0.8; }
.node.is-reused rect { fill: #0d2430; stroke: var(--cyan); stroke-width: 2; }
.node.is-ghost rect { fill: transparent; stroke: #243044; stroke-dasharray: 4 3; }
.append-tag { fill: var(--cyan); font-family: var(--mono); font-size: 11px; letter-spacing: 0.08em; text-anchor: middle; }
.append-caption { margin: 8px 4px 0; color: var(--muted); font-size: 13px; }
.node.is-ghost .node-hash, .node.is-ghost .node-label { fill: #3d4c63; }
.node.is-pulse rect { filter: drop-shadow(0 0 8px rgba(78, 222, 163, 0.55)); }

.edge { stroke: #2a3a4e; stroke-width: 1.6; }
.edge.is-ghost { stroke: #1a2433; stroke-dasharray: 3 4; }
.edge.is-hot { stroke: var(--emerald); stroke-width: 2.2; }
.travel-dot { fill: var(--emerald); }

.transport {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
}

.step-count {
  margin-left: auto;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
}

.panel { margin-top: 12px; }

.editors {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.editors label, .sib-row label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
}

input[type="text"] {
  min-height: 40px;
  width: 100%;
  padding: 0 8px;
  border-radius: 8px;
  border: 1px solid var(--line-2);
  background: #0b1018;
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0;
  text-transform: none;
}

input.bad { border-color: var(--amber); }

.root-readout, .hint, .fineprint, .assume, .lit {
  color: var(--muted);
  font-size: 13px;
}

.root-readout {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: baseline;
  margin: 10px 0;
}

.root-readout code, .mono {
  font-family: var(--mono);
  color: var(--amber);
  font-size: 14px;
}

.root-full { color: var(--faint); word-break: break-all; font-family: var(--mono); font-size: 12px; }

.row-actions, .picker, .seg {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.picker button[aria-pressed="true"], .seg button[aria-pressed="true"] {
  border-color: var(--emerald);
  color: var(--emerald);
}

.sib-list { display: grid; gap: 8px; margin: 10px 0; }

.sib-row {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(120px, 0.7fr) auto;
  gap: 8px;
  align-items: end;
}

.folds { list-style: none; padding: 0; margin: 8px 0; display: grid; gap: 4px; }
.folds li { font-family: var(--mono); font-size: 12.5px; color: var(--parchment); }
.folds li.done { color: var(--emerald); }

.verdict {
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line-2);
  background: #0b1018;
}

.verdict.pass { border-color: var(--emerald-deep); color: var(--emerald); }
.verdict.fail { border-color: #7f1d1d; color: var(--danger); }

.seal {
  display: grid;
  justify-items: center;
  gap: 2px;
  margin: 4px auto 10px;
  min-height: 72px;
}

.seal strong {
  font-family: var(--mono);
  font-size: 1.25rem;
  color: var(--amber);
  letter-spacing: 0.04em;
}

.seal.is-waiting strong { color: var(--faint); }

.wide-row {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 6px;
}

button.cell {
  min-height: 64px;
  padding: 6px 4px;
  border-radius: 8px;
  border: 1px solid var(--line-2);
  background: var(--elev);
  color: var(--text);
  text-align: center;
}

.cell small, .cell em {
  display: block;
  color: var(--faint);
  font-style: normal;
  font-family: var(--mono);
  font-size: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cell b {
  display: block;
  margin-top: 4px;
  font-weight: 500;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--parchment);
}

.cell.is-on {
  border-color: var(--emerald);
  background: #10261c;
  box-shadow: inset 0 0 0 1px rgba(78, 222, 163, 0.35);
}

.trays {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.tray {
  min-height: 148px;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0b1018;
}

.tray h3 {
  margin: 0 0 8px;
  font-family: var(--serif);
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--parchment);
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  display: inline-flex;
  flex-direction: column;
  gap: 1px;
  padding: 5px 7px;
  border-radius: 7px;
  border: 1px solid #245468;
  background: #0d2430;
  animation: pop 280ms ease;
}

.chip-hash { font-family: var(--mono); font-size: 12px; color: var(--cyan); }
.chip-sub { font-family: var(--mono); font-size: 10px; color: var(--faint); }

.opening {
  padding: 10px;
  border-radius: 10px;
  border: 1px solid rgba(78, 222, 163, 0.55);
  background: #10261c;
  animation: pop 320ms ease;
}

.opening p { margin: 0 0 4px; }
.opening .bytes, .stat-bytes {
  font-family: var(--mono);
  font-size: 1.6rem;
  color: var(--emerald);
  letter-spacing: -0.03em;
}

.compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.compare-grid[data-mode="merkle"],
.compare-grid[data-mode="verkle"] { grid-template-columns: 1fr; }
.compare-grid[data-mode="merkle"] .col-verkle,
.compare-grid[data-mode="verkle"] .col-merkle { display: none; }

.stat-kicker { margin: 0; color: var(--muted); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; font-family: var(--mono); }
.stat-detail { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.tray .waiting { color: var(--faint); margin: 0; }

.controls { display: grid; gap: 10px; margin-bottom: 10px; }
.control-line { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.control-line span.label { color: var(--muted); font-size: 12px; font-family: var(--mono); letter-spacing: 0.08em; text-transform: uppercase; }

details.assume { margin-top: 8px; }
details.assume summary { cursor: pointer; color: var(--cyan); }
.lit { margin: 8px 0 0; }

.scroll-hint { display: none; margin: 0 0 6px; color: var(--faint); font-size: 12px; }

.fineprint {
  margin: 14px 0 0;
  font-size: 12px;
  max-width: 85ch;
}

@keyframes pop {
  from { transform: translateY(4px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

@media (max-width: 640px) {
  .editors { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .trays, .compare-grid { grid-template-columns: 1fr; }
  .compare-grid[data-mode="split"] .col-verkle,
  .compare-grid[data-mode="split"] .col-merkle { display: block; }
  .wide-row { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .sib-row { grid-template-columns: 1fr; }
  .scroll-hint { display: block; }
  .step-count { margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .chip, .opening, .node.is-pulse rect { animation: none; filter: none; }
}
