:root {
  --bg: #0d1117; --bg2: #11161d; --panel: #161b22; --panel2: #1f2630; --line: #2a3340;
  --text: #e6edf3; --muted: #9aa7b4; --dim: #6b7785;
  --accent: #58a6ff; --accent2: #79c0ff; --accent-soft: rgba(88, 166, 255, .14);
  --warm: #f0b35a; --ok: #56d364; --bad: #ff7b72;
  --paper: #f6f8fa; --paper-text: #1f2328;
  --radius: 10px; --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --serif: "Fraunces", Georgia, serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 var(--sans); }
a { color: var(--accent2); text-decoration: none; }
a:hover { text-decoration: underline; }
button, select, input, textarea { font: inherit; color: inherit; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }

/* ---------- top bar ---------- */
.topbar { height: 52px; display: flex; align-items: center; gap: 16px; padding: 0 16px;
  background: rgba(13, 17, 23, .92); border-bottom: 1px solid var(--line); position: relative; z-index: 5; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: .2px; color: var(--text); }
.brand svg { width: 26px; height: 26px; }
.brand small { color: var(--muted); font-weight: 400; }
.topbar nav { margin-left: auto; display: flex; gap: 14px; }
.topbar nav a { color: var(--muted); }
.topbar nav a.on, .topbar nav a:hover { color: var(--text); text-decoration: none; }

/* ---------- app layout ---------- */
.app { display: grid; grid-template-columns: 360px 1fr; height: calc(100vh - 52px); }
.side { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.stage { position: relative; min-width: 0; background: radial-gradient(1200px 700px at 60% 30%, #172130 0%, #0d1117 70%); }
.stage canvas { width: 100%; height: 100%; display: block; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; background: none; border: 0; padding: 11px 6px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }
.tabpane { overflow: auto; padding: 14px 16px 30px; flex: 1; display: none; }
.tabpane.on { display: block; }
h3.sec { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--dim); margin: 18px 0 8px; font-weight: 600; }
h3.sec:first-child { margin-top: 2px; }

.field { margin: 8px 0; }
.field label { display: block; color: var(--muted); font-size: 12.5px; margin-bottom: 4px; }
select, input[type=text], textarea { width: 100%; background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; }
textarea { min-height: 150px; resize: vertical; font-family: var(--mono); font-size: 12px; line-height: 1.45; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.btn { white-space: nowrap; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; cursor: pointer; }
.btn:hover { border-color: #3a4656; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #0b1320; font-weight: 600; }
.btn.primary:hover { background: var(--accent2); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { flex: 1; }
.seg { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.seg button { background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 8px; cursor: pointer; text-align: left; font-size: 13px; }
.seg button.on { border-color: var(--accent); background: var(--accent-soft); }
.seg button small { display: block; color: var(--dim); font-size: 11px; }
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.small { font-size: 12px; }
.hint { color: var(--dim); font-size: 12px; margin: 4px 0 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 11.5px; padding: 2px 8px; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.chip.on { color: #0b1320; background: var(--accent); border-color: var(--accent); }
.chip.warm { color: #1d1405; background: var(--warm); border-color: var(--warm); }

.card { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.card h4 { margin: 0 0 2px; font-size: 15px; }
.card p { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.showme { list-style: none; padding: 0; margin: 8px 0 0; }
.showme li { margin: 0 0 6px; }
.showme button { width: 100%; text-align: left; background: none; border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; cursor: pointer; color: var(--text); font-size: 12.5px; display: flex; gap: 8px; }
.showme button:hover { border-color: var(--accent); background: var(--accent-soft); }
.showme button::before { content: "▸"; color: var(--accent); }

.slider-label { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.slider-label b { color: var(--text); font-weight: 600; }

.tree { font-size: 12.5px; max-height: 300px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; background: var(--bg2); }
.tree ul { list-style: none; padding-left: 14px; margin: 0; }
.tree > ul { padding-left: 0; }
.tree label { display: flex; gap: 6px; align-items: center; cursor: pointer; padding: 1px 0; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }

/* overlays on the stage */
.overlay { position: absolute; background: rgba(22, 27, 34, .88); border: 1px solid var(--line); border-radius: var(--radius); backdrop-filter: blur(6px); box-shadow: var(--shadow); }
.legend { left: 14px; bottom: 14px; min-width: 190px; max-width: 300px; max-height: 45%; overflow: auto; padding: 10px 12px; font-size: 12px; }
.legend .it { display: flex; align-items: center; gap: 8px; padding: 1px 0; cursor: default; }
.legend .it span.c { margin-left: auto; color: var(--dim); font-variant-numeric: tabular-nums; }
.ramp { height: 10px; border-radius: 4px; margin: 6px 0 2px; background: linear-gradient(90deg, #30123b, #4686fb, #1be5b5, #a4fc3c, #fbb938, #e4460a, #7a0403); }
.viewbar { right: 14px; top: 14px; display: flex; gap: 2px; padding: 4px; }
.viewbar button { background: none; border: 0; color: var(--muted); padding: 5px 8px; border-radius: 6px; cursor: pointer; font-size: 12px; }
.viewbar button:hover { background: var(--panel2); color: var(--text); }
.status { right: 14px; bottom: 14px; padding: 7px 11px; font-size: 12px; color: var(--muted); max-width: 46%; }
.loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 12px; color: var(--muted); }
.bar { width: 260px; height: 4px; background: var(--panel2); border-radius: 4px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }

/* results */
.result { margin-top: 10px; font-size: 12.5px; }
.result .sum { padding: 8px 10px; border-radius: 8px; background: var(--accent-soft); border: 1px solid rgba(88, 166, 255, .35); }
.result .err { padding: 8px 10px; border-radius: 8px; background: rgba(255, 123, 114, .1); border: 1px solid rgba(255, 123, 114, .4); color: #ffb3ad; }
table.tbl { border-collapse: collapse; width: 100%; font-size: 12px; margin-top: 8px; }
table.tbl th, table.tbl td { border-bottom: 1px solid var(--line); padding: 4px 6px; text-align: left; vertical-align: top; }
table.tbl th { color: var(--dim); font-weight: 600; }
table.tbl td a { cursor: pointer; }
details summary { cursor: pointer; color: var(--muted); font-size: 12px; margin-top: 8px; }
details pre { white-space: pre-wrap; background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 8px; max-height: 240px; overflow: auto; }

.slot { border: 1px dashed #3a4656; border-radius: 8px; padding: 10px; color: var(--dim); font-size: 12.5px; }
.slot ul { list-style: none; margin: 0; padding: 0; }
.slot li button { background: none; border: 0; color: var(--accent2); padding: 3px 0; cursor: pointer; text-align: left; }

.chain { list-style: none; padding: 0; margin: 6px 0; }
.chain li { position: relative; padding: 6px 8px 6px 26px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 6px; background: var(--bg2); cursor: pointer; }
.chain li:hover, .chain li.on { border-color: var(--accent); }
.chain li::before { content: ""; position: absolute; left: 10px; top: 0; bottom: 0; width: 2px; background: var(--line); }
.chain li .k { color: var(--dim); font-size: 11.5px; }
.props { font-size: 12px; width: 100%; border-collapse: collapse; }
.props td { padding: 3px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.props td:first-child { color: var(--muted); width: 45%; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 55vh auto; height: auto; }
  .stage { height: 55vh; order: -1; }
  .side { border-right: 0; border-top: 1px solid var(--line); }
  .topbar { gap: 10px; padding: 0 10px; }
  .topbar nav { gap: 10px; }
  .topbar nav a:not(:last-child) { display: none; }
  .topbar #project { min-width: 0 !important; flex: 1; max-width: 220px; }
  .brand small { display: none; }
  .legend { max-width: 55%; max-height: 38%; font-size: 11px; left: 8px; bottom: 8px; padding: 6px 8px; min-width: 0; }
  .status { display: none; }
  .viewbar { right: 8px; top: 8px; }
}
