:root {
  --n-pool: #4d7656;
  --n-concat: #7a6250;
  --edge: #a39b90;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --n-pool: #355239;
    --n-concat: #5b4939;
    --edge: #6f6a63;
  }
}

:root[data-theme="dark"] {
  --n-pool: #355239;
  --n-concat: #5b4939;
  --edge: #6f6a63;
}

.viewer-page { max-width: 1100px; margin: 0 auto; padding: 32px 16px 64px; }

.muted { color: var(--muted); }
.small { font-size: 0.88em; }
.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }

/* empty state */

.viewer-intro { max-width: 680px; margin: 0 auto; text-align: center; }
.viewer-intro h1 { margin-top: 16px; }

.dropzone {
  display: block;
  margin: 24px 0 12px;
  padding: 40px 16px;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
}

.dropzone:hover, .dropzone:focus-visible, .dropzone.hover {
  border-color: var(--accent-text);
  outline: none;
}

.dropzone strong { color: var(--text); font-weight: 600; }
.dropzone u { color: var(--accent-text); text-underline-offset: 2px; }

.link-btn {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--accent-text);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.viewer-error { color: #d93f3f; }

/* loaded */

.viewer-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.viewer-head h1 { margin: 0; font-size: 1.5rem; overflow-wrap: anywhere; }
.viewer-summary { margin: 6px 0 20px; color: var(--muted); font-size: 0.92em; }
.viewer-summary b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.graph {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 28px 16px;
  background:
    radial-gradient(circle, color-mix(in srgb, var(--muted) 22%, transparent) 1px, transparent 1px) 0 0 / 18px 18px,
    var(--bg-alt);
  min-height: 480px;
}

/* nodes */

.node {
  position: relative;
  display: block;
  width: 200px;
  max-width: 100%;
  padding: 0;
  font: inherit;
  font-size: 13px;
  line-height: 1.35;
  text-align: left;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 2px 6px rgba(0, 0, 0, 0.04);
}

.node::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--strip, var(--border));
}

.node-head { padding: 9px 12px 2px; font-weight: 600; }
.node-body { padding: 0 12px 9px; font-size: 12px; color: var(--muted); }
.node-body div { white-space: nowrap; }
.node-body b { color: var(--text); font-weight: 600; margin-right: 4px; }

.node-linear { --strip: var(--accent); }
.node-pool { --strip: var(--n-pool); }
.node-op { --strip: var(--n-concat); }
.node-io { --strip: var(--muted); }

.tags { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 12px 10px; }

.tag {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 4px;
  border: 1px solid var(--border);
  color: var(--muted);
  background: var(--bg-alt);
}

.tag:hover { color: var(--text); border-color: var(--accent-text); }

.node:hover { border-color: color-mix(in srgb, var(--accent-text) 50%, var(--border)); }

.node.selected { border-color: var(--accent-text); }

.edge {
  position: relative;
  width: 1px;
  height: 26px;
  background: var(--edge);
}

.edge-label {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.edge::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: -3px;
  border: 3.5px solid transparent;
  border-top: 5px solid var(--edge);
  border-bottom: 0;
}

.group {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 24px 18px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: color-mix(in srgb, var(--surface) 50%, transparent);
}

.group-title {
  align-self: flex-start;
  margin: 0 0 12px -12px;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

/* side panel */

.inspector {
  position: sticky;
  top: 57px;
  max-height: calc(100vh - 57px);
  overflow-y: auto;
  border-left: 1px solid var(--border);
  background: var(--bg);
  font-size: 0.92em;
}

.side { padding: 16px 20px; border-bottom: 1px solid var(--border); }
.side:last-child { border-bottom: none; }

.side-label {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.side h3 { margin: 0 0 6px; font-size: 1.05rem; }
.side h4 { margin: 18px 0 6px; font-size: 0.92rem; font-weight: 600; }
.side p { margin: 0 0 8px; color: var(--muted); }

.type {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.85em;
  font-weight: 400;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--code-bg);
  color: var(--text);
}

.kv { display: table; width: 100%; margin: 6px 0; border-collapse: collapse; font-size: 0.92em; }
.kv td { border: none; padding: 2px 0; }
.kv td:first-child { color: var(--muted); }
.kv td:last-child { text-align: right; font-variant-numeric: tabular-nums; }

.hist, .heat { display: block; width: 100%; margin-top: 6px; }
.heat { border: 1px solid var(--border); image-rendering: pixelated; }

.try-row { display: flex; gap: 8px; margin: 8px 0; }

.try-row select, #custom {
  font: inherit;
  padding: 5px 8px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.try-row select { flex: 1; }

.try-row button {
  font: inherit;
  padding: 5px 14px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.try-row button:hover { border-color: var(--accent-text); }

#custom {
  width: 100%;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.85em;
  resize: vertical;
}

.prob { display: grid; grid-template-columns: 40px 1fr 48px; align-items: center; gap: 8px; margin: 3px 0; font-size: 0.9em; }
.prob-idx { color: var(--muted); font-variant-numeric: tabular-nums; }
.prob-bar { height: 6px; border-radius: 3px; background: var(--code-bg); overflow: hidden; }
.prob-bar span { display: block; height: 100%; background: var(--accent); }
.prob-val { text-align: right; font-variant-numeric: tabular-nums; }

details.side summary { cursor: pointer; list-style: none; }
details.side summary::-webkit-details-marker { display: none; }
details.side summary .side-label { display: inline; margin: 0; }
details.side summary::after { content: " +"; color: var(--muted); font-size: 12px; }
details.side[open] summary::after { content: " \2212"; }
details.side pre {
  margin: 12px 0 0;
  max-height: 320px;
  padding: 12px 14px;
  font-family: Consolas, "Cascadia Mono", ui-monospace, monospace;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.55;
  color: var(--muted);
}

.j-key { color: var(--text); }
.j-str { color: var(--accent-text); }
.j-val { color: #4f8fd6; }

@media (max-width: 900px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .inspector { position: static; max-height: none; border-left: none; border-top: 1px solid var(--border); }
}
