:root {
  color-scheme: dark;
  --bg: #0c0c0f;
  --panel: rgba(21, 21, 26, 0.96);
  --card: rgba(20, 20, 24, 0.97);
  --ink: #dddde2;
  --muted: #aaaab3;
  --faint: #90909c;
  --gold: #e1b96c;
  --gold-2: #c89355;
  --amber: #ffb442;
  --line: #3b3b43;
  --line-soft: #303038;
  --field: #111113;
  --button: #202025;
  --in: #7dbf9d;
  --out: #a1a5ee;
  --danger: #60342c;
  font-family: Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
}

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

button {
  padding: 7px 10px;
  border: 1px solid #45454c;
  border-radius: 5px;
  background: var(--button);
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
}

button:hover:not(:disabled) { border-color: var(--gold-2); color: var(--amber); }
button:disabled { opacity: 0.4; cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid #b7c7f9;
  outline-offset: 2px;
}

input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #424246;
  border-radius: 5px;
  background: var(--field);
  font-size: 13px;
}

textarea { resize: vertical; }

label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 12px; }

.app { height: 100dvh; }
.layout { position: relative; height: 100%; overflow: hidden; background: var(--bg); }
.layout:fullscreen { width: 100%; height: 100%; background: var(--bg); }

.canvas {
  position: absolute;
  inset: 0;
  overflow: auto;
  cursor: grab;
  background:
    radial-gradient(ellipse at center, rgba(232, 196, 122, 0.05), transparent 58%),
    var(--bg);
}

.canvas.is-panning, .layout.is-dragging .canvas { cursor: grabbing; }

.graph {
  min-width: 100%;
  min-height: 100%;
  padding: 108px 24px 72px;
}

.graph svg { display: block; }
.graph .node { cursor: grab; }
.graph .node rect { fill: #15151a; stroke: #4c402d; stroke-width: 1; }
.graph .node.is-selected rect { stroke: #f4a54d; stroke-width: 2; }
.graph .node.is-match rect { stroke: #f5d24c; stroke-width: 3; fill: #332b18; }
.graph text { font-family: Arial, sans-serif; fill: var(--ink); }
.graph .txid { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.graph .sub { fill: var(--muted); font-size: 11px; }
.graph .edge { fill: none; stroke: #66512b; stroke-width: 1.4; }
.graph .edge-label { fill: #c9b58f; font-size: 10px; font-family: ui-monospace, Consolas, monospace; }

.empty-graph {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  color: var(--faint);
  font-size: 14px;
}

.floatbar {
  position: absolute;
  top: 14px;
  left: 16px;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  max-width: calc(100% - 120px);
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 28px #0008;
}

.tabs { display: flex; gap: 6px; padding-right: 8px; border-right: 1px solid var(--line); }
.tab[aria-expanded="true"] { color: var(--amber); border-color: #9c7741; background: #30261a; }

.bar-form { display: flex; gap: 6px; align-items: center; }
.bar-form input { width: 240px; padding: 6px 8px; font-size: 12px; }

.zoom, .find { flex-direction: row; align-items: center; gap: 4px; margin: 0; }
.zoom { border: 1px solid #424246; border-radius: 4px; padding: 2px; }
.zoom input { width: 3.2ch; border: 0; background: transparent; text-align: right; padding: 4px 0; }
.find input { width: 200px; padding: 6px 8px; font-size: 12px; }
#find-count { color: var(--gold-2); font-size: 11px; }

.pill {
  padding: 5px 8px;
  border: 1px solid #66512b;
  border-radius: 4px;
  color: var(--gold);
  font-size: 11px;
}
.pill.is-down { color: #e1c697; border-color: #60342c; }

.collapse {
  position: absolute;
  top: 14px;
  right: 16px;
  z-index: 6;
  padding: 10px 12px;
  box-shadow: 0 8px 25px #0005;
}

.panel {
  position: absolute;
  top: 70px;
  bottom: 56px;
  z-index: 4;
  width: 350px;
  max-width: calc(100% - 32px);
  overflow: auto;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 32px #000a;
}
.panel.left { left: 16px; }
.panel.right { right: 16px; }
.panel h2 { margin: 0 0 12px; font-size: 16px; font-weight: 600; }
.panel h3 { margin: 18px 0 8px; color: var(--gold-2); font-size: 13px; }
.panel-close { float: right; padding: 4px 8px; font-size: 11px; }
.lead { color: var(--muted); font-size: 12px; line-height: 1.5; }

.trace-options { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.trace-options label { margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 7px; margin: 12px 0; }
.save-state { color: var(--gold-2); font-size: 11px; }
.file { width: auto; }
.file input { display: none; }

.branch-list { display: grid; gap: 6px; margin-top: 8px; }
.branch-row {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 8px;
  border: 1px solid var(--line-soft);
  border-radius: 4px;
  background: #111113;
  color: var(--ink);
  font-size: 12px;
}
.branch-row small { display: block; color: var(--muted); margin-top: 3px; font-family: ui-monospace, Consolas, monospace; }
.is-in { color: var(--in); }
.is-out { color: var(--out); }
.is-both { color: var(--gold); }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 12px 0; }
.stats div { padding: 8px; background: #111113; border: 1px solid var(--line-soft); border-radius: 4px; }
.stats strong, .stats span { display: block; font-size: 11px; overflow-wrap: anywhere; }
.stats strong { color: var(--gold-2); margin-bottom: 3px; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 11px; line-height: 1.6; overflow-wrap: anywhere; color: var(--muted); }
.io { margin: 8px 0; padding: 0; list-style: none; }
.io li { padding: 7px 0; border-bottom: 1px solid var(--line-soft); font-size: 12px; }
.io button { margin-top: 6px; }

.library-row, .welcome-row { display: flex; gap: 6px; margin: 6px 0; }
.library-row button:first-child, .welcome-row button {
  flex: 1;
  text-align: left;
  white-space: normal;
}

.welcome {
  position: absolute;
  inset: 0;
  overflow: auto;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 12px;
  padding: 24px;
}
.card {
  width: min(660px, 100%);
  padding: 20px;
  border: 1px solid #4c402d;
  border-radius: 10px;
  background: var(--card);
  box-shadow: 0 16px 55px #0009;
}
.library { border-color: var(--line); }
.eyebrow { margin: 0 0 6px; color: var(--gold); letter-spacing: 0.08em; text-transform: uppercase; font-size: 11px; }
.card h1 { margin: 0 0 8px; font-size: 26px; font-weight: 600; color: #f3ead6; }
.card h2 { margin: 0 0 10px; font-size: 14px; color: #d9c39b; }
.lede { margin: 0 0 16px; color: var(--muted); font-size: 14px; line-height: 1.5; }
.target-label { color: #e1c697; font-size: 14px; }
.target-row { display: flex; gap: 8px; }
.target-row input { flex: 1; padding: 12px; }
.node-line { min-height: 1.4em; margin: 12px 0 0; color: #c9b58f; font-size: 12px; }

.status {
  position: absolute;
  bottom: 52px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
  max-width: calc(100% - 32px);
  margin: 0;
  padding: 7px 12px;
  border: 1px solid #33333c;
  border-radius: 6px;
  background: rgba(21, 21, 26, 0.92);
  color: #c9b58f;
  font-size: 12px;
}
.status:empty { display: none; }

.foot {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-top: 1px solid #25252d;
  background: rgba(17, 17, 19, 0.92);
  color: var(--muted);
  font-size: 11px;
  pointer-events: none;
}

.app.is-empty .floatbar,
.app.is-empty .panel,
.app.is-empty .collapse,
.app.is-empty .foot,
.app.is-empty .empty-graph { display: none; }
.app:not(.is-empty) .welcome { display: none; }
.app.is-collapsed .floatbar,
.app.is-collapsed .panel { display: none; }

@media (max-width: 800px) {
  .floatbar { left: 10px; right: 10px; max-width: none; }
  .collapse { top: auto; bottom: 58px; right: 10px; }
  .panel { left: 10px; right: 10px; width: auto; top: 120px; bottom: 108px; }
  .bar-form input, .find input { width: 140px; }
  .foot span:nth-child(2) { display: none; }
  .card h1 { font-size: 22px; }
}
