@font-face {
  font-family: "Inter";
  src: url("../fonts/inter-latin.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: "Newsreader";
  src: url("../fonts/newsreader-display-latin.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Newsreader";
  src: url("../fonts/newsreader-display-italic-latin.woff2") format("woff2");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("../fonts/jetbrains-mono-latin.woff2") format("woff2");
  font-weight: 100 800;
  font-display: swap;
}

/* Paper and ink, with forest green and amber doing the talking. */
:root {
  --paper: #f4f1ea;
  --panel: #faf8f3;
  --ink: #1b211d;
  --muted: #6c7169;
  --line: rgb(27 33 29 / 0.16);
  --hair: rgb(27 33 29 / 0.09);
  --soft: rgb(27 33 29 / 0.045);
  --accent: #2f6b4f;
  --accent-soft: rgb(47 107 79 / 0.12);
  --amber: #c58a2d;
  --bad: #b4563c;
  --sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Newsreader", "Iowan Old Style", Georgia, serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #121715;
    --panel: #171d1a;
    --ink: #e9e5dc;
    --muted: #9aa097;
    --line: rgb(233 229 220 / 0.18);
    --hair: rgb(233 229 220 / 0.1);
    --soft: rgb(233 229 220 / 0.05);
    --accent: #7fb79a;
    --accent-soft: rgb(127 183 154 / 0.14);
    --amber: #e0a84f;
    --bad: #e08366;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 13.5px/1.5 var(--sans);
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
}
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.i { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; flex: none; vertical-align: -2px; }
.wrap { width: 100%; max-width: 1360px; margin: 0 auto; padding-left: 24px; padding-right: 24px; }
a { color: inherit; text-decoration: none; }
h2 { margin: 0; display: flex; align-items: center; gap: 7px; font-size: 0.7rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
h2 .i { width: 13px; height: 13px; }
.muted { color: var(--muted); }
.hint { margin: 8px 0 0; font-size: 0.74rem; color: var(--muted); }
.num { font: 500 0.66rem var(--mono); color: var(--muted); letter-spacing: 0.06em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

/* The page is one screen tall; everything inside scrolls in its own panel. */
.shell { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
@media (min-width: 1101px) and (min-height: 700px) {
  .shell { height: 100vh; height: 100dvh; }
  main { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
  .work { flex: 1 1 auto; min-height: 0; }
  .ask { overflow-y: auto; }
  .tree-scroll { flex: 1 1 0; min-height: 0; }
  .pane { flex: 1 1 0; min-height: 0; overflow: auto; }
}

/* ---------------------------------------------------------------- header */

nav { display: flex; justify-content: space-between; align-items: baseline; padding: 16px 0 0; font-size: 0.82rem; }
.word { font: 400 1.2rem var(--serif); letter-spacing: -0.005em; }
.nav-link { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); }
.nav-link .i { width: 12px; height: 12px; transition: transform 0.25s var(--ease); }
.nav-link:hover { color: var(--ink); }
.nav-link:hover .i { transform: translate(1px, -1px); }

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  gap: 16px 56px;
  align-items: end;
  padding: 26px 24px 18px;
  border-bottom: 1px solid var(--line);
}
.hero-text { animation: rise 0.7s var(--ease) both; }
h1 {
  margin: 0 0 8px;
  font: 400 clamp(1.9rem, 2.9vw, 2.6rem) / 1.08 var(--serif);
  letter-spacing: -0.01em;
}
h1 em { font-style: italic; color: var(--accent); }
.lede { margin: 0; max-width: 58ch; font-size: 0.92rem; color: var(--muted); }

.figures { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin: 0; animation: rise 0.7s 0.12s var(--ease) both; }
.figures > div { min-width: 0; padding: 2px 14px 0 14px; border-left: 1px solid var(--line); }
.figures dt { display: flex; align-items: center; gap: 5px; font-size: 0.66rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.figures dt .i { width: 12px; height: 12px; }
.figures dd { margin: 3px 0 0; font: 400 1.85rem/1.05 var(--serif); letter-spacing: -0.01em; font-variant-numeric: tabular-nums; white-space: nowrap; }
.figures small { display: block; margin-top: 3px; font-size: 0.7rem; line-height: 1.3; color: var(--muted); }
.figures .flash dd { animation: flash 0.9s ease; }
@keyframes flash { from { color: var(--accent); } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.wait { color: var(--muted); }

.go {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer; border: 1px solid var(--ink); background: var(--ink); color: var(--paper);
  font: 600 0.76rem var(--sans); padding: 5px 10px; border-radius: 3px; letter-spacing: 0.01em; transition: background 0.2s, border-color 0.2s, transform 0.2s var(--ease);
}
.go:hover { background: var(--accent); border-color: var(--accent); }
.go:active { transform: scale(0.98); }
.go:disabled { opacity: 0.4; cursor: default; }
.go.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.go.ghost:hover { border-color: var(--ink); background: transparent; }
.figures .go { margin: 7px 0 5px; }

/* ---------------------------------------------------------------- data sources */

.sources { display: flex; align-items: center; gap: 8px 14px; flex-wrap: wrap; padding: 12px 0 10px; }
.tabs { display: flex; gap: 2px; max-width: 100%; overflow-x: auto; }
.tab {
  display: inline-flex; align-items: center; gap: 6px;
  border: 0; border-bottom: 2px solid transparent; background: none; color: var(--muted); font: 500 0.84rem var(--sans);
  padding: 4px 2px 5px; margin-right: 16px; cursor: pointer; white-space: nowrap; transition: color 0.2s, border-color 0.2s;
}
.tab .i { width: 13px; height: 13px; opacity: 0.8; }
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }
.blurb { margin: 0; color: var(--muted); font-size: 0.84rem; }
.sources .link { margin-left: auto; }

/* ---------------------------------------------------------------- workspace */

.work { display: grid; grid-template-columns: 330px minmax(0, 1fr) 296px; border: 1px solid var(--line); background: var(--panel); }
.ask { padding: 14px 18px 16px; border-right: 1px solid var(--line); min-width: 0; }
.viz { display: flex; flex-direction: column; padding: 14px 18px 12px; min-width: 0; }
.insight { display: flex; flex-direction: column; border-left: 1px solid var(--line); min-width: 0; }

.target-row { display: flex; align-items: center; gap: 6px 9px; flex-wrap: wrap; }
.label { font-size: 0.7rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.chips { display: contents; }
.chip {
  border: 1px solid var(--line); background: transparent; color: var(--ink);
  font: 500 0.76rem var(--sans); padding: 2px 9px; border-radius: 3px; cursor: pointer; transition: border-color 0.2s, background 0.2s, color 0.2s;
}
.chip:hover { border-color: var(--ink); }
.chip[aria-checked="true"] { background: var(--ink); border-color: var(--ink); color: var(--paper); }

.answer { margin: 12px 0; padding: 12px 0; border-top: 1px solid var(--hair); border-bottom: 1px solid var(--hair); }
.answer .top { display: flex; align-items: baseline; gap: 9px; flex-wrap: wrap; }
.answer .big { font: 400 2rem/1 var(--serif); letter-spacing: -0.01em; overflow-wrap: anywhere; color: var(--c, var(--ink)); }
.answer .big.pop { animation: pop 0.45s var(--ease); }
@keyframes pop { from { opacity: 0; transform: translateY(4px); } }
.answer .chance { font-size: 0.9rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.answer .time { margin-left: auto; font: 500 0.66rem var(--mono); color: var(--muted); }
.answer .why { margin: 7px 0 9px; font-size: 0.8rem; color: var(--muted); line-height: 1.7; }
.answer .why code { font: 500 0.7rem var(--mono); color: var(--ink); background: var(--soft); padding: 2px 5px; border-radius: 3px; white-space: nowrap; }
.mix { display: flex; height: 6px; overflow: hidden; gap: 2px; border-radius: 2px; }
.mix i { display: block; height: 100%; transition: flex-grow 0.35s var(--ease); }
.legend { display: flex; flex-wrap: wrap; gap: 2px 12px; margin-top: 6px; font-size: 0.74rem; color: var(--muted); }
.legend span::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 2px; background: var(--c); margin-right: 5px; }
.legend b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }

.ask-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 9px; }
.link { display: inline-flex; align-items: center; gap: 5px; border: 0; background: none; color: var(--muted); font: 500 0.74rem var(--sans); cursor: pointer; padding: 0; transition: color 0.2s; }
.link:hover { color: var(--ink); }
.link .i { width: 12px; height: 12px; }
.fields { display: grid; gap: 8px; }
.field { display: grid; grid-template-columns: 104px minmax(0, 1fr); align-items: center; gap: 10px; min-height: 24px; }
.field .name { font-size: 0.78rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.field .ctl { display: grid; grid-template-columns: minmax(0, 1fr) 3.4em 12px; align-items: center; gap: 8px; }
.field output { font: 500 0.72rem var(--mono); color: var(--accent); text-align: right; transition: color 0.2s; }
.field.unset output { color: var(--muted); }
.field .x { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0; font-size: 0.9rem; line-height: 1; }
.seg { display: flex; gap: 3px; }
.seg button {
  flex: 1 1 auto; min-width: 0; border: 1px solid var(--line); background: transparent; color: var(--muted);
  font: 500 0.74rem var(--sans); padding: 2px 6px; border-radius: 3px; cursor: pointer; transition: border-color 0.2s, background 0.2s, color 0.2s;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.seg button:hover { border-color: var(--ink); color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); }
select {
  width: 100%; font: 500 0.78rem var(--sans); color: var(--ink); background: transparent;
  border: 1px solid var(--line); border-radius: 3px; padding: 2px 6px;
}
input[type="range"] { width: 100%; accent-color: var(--accent); margin: 0; height: 18px; }
.field.unset input[type="range"] { opacity: 0.4; }

/* tree */
.viz-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 6px; flex-wrap: wrap; }
.viz-head h2 .muted { font-weight: 500; letter-spacing: 0; text-transform: none; margin-left: 2px; }
.knobs { display: flex; gap: 14px; flex-wrap: wrap; }
.knobs label { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 0 5px; font-size: 0.7rem; color: var(--muted); width: 112px; cursor: pointer; }
.knobs label .i { width: 12px; height: 12px; }
.knobs output { font: 500 0.7rem var(--mono); color: var(--ink); }
.knobs input { grid-column: 1 / -1; height: 16px; }
.tree-scroll { overflow: auto; margin: 0 -18px; padding: 4px 18px; }
#tree svg { display: block; }
.too-big { padding: 40px 0; text-align: center; color: var(--muted); }

.flow { fill: none; opacity: 0.38; stroke-linecap: round; transition: opacity 0.25s, stroke 0.25s; }
.node { cursor: pointer; transition: opacity 0.25s; }
.node .hit { fill: transparent; transition: fill 0.15s; }
.node:hover .hit { fill: var(--soft); }
.node .test { font: 500 11px var(--mono); fill: var(--muted); }
.node .pred { font: 600 11.5px var(--sans); fill: var(--ink); }
svg.focus .node:not(.on) { opacity: 0.32; }
svg.focus .flow:not(.on) { opacity: 0.14; }
.flow.on { opacity: 0.95; }
.node.on .test { fill: var(--ink); }
.node.on .hit { fill: var(--soft); }
/* A fresh tree grows from the root outward. */
svg.grow .flow { stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 0.7s var(--ease) forwards; animation-delay: calc(var(--d) * 110ms); }
svg.grow .node { animation: fade 0.4s ease both; animation-delay: calc(var(--d) * 110ms + 80ms); }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes fade { from { opacity: 0; } }

/* insight */
.seg-tabs { display: flex; border-bottom: 1px solid var(--line); padding: 0 6px; }
.seg-tabs button {
  display: inline-flex; align-items: center; gap: 5px; flex: 1 1 auto; justify-content: center;
  border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; background: none; color: var(--muted);
  font: 500 0.72rem var(--sans); padding: 11px 4px 9px; cursor: pointer; white-space: nowrap; transition: color 0.2s, border-color 0.2s;
}
.seg-tabs button .i { width: 12px; height: 12px; }
.seg-tabs button:hover { color: var(--ink); }
.seg-tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }
.pane { padding: 12px 16px 14px; animation: fade 0.3s ease; }
.pane-lede { margin: 0 0 12px; font-size: 0.76rem; color: var(--muted); }
.bars { display: grid; grid-template-columns: minmax(0, max-content) 1fr 3.2ch; gap: 8px 10px; align-items: center; font-size: 0.78rem; }
.bars > span:nth-child(3n + 1) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bars .pct { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.meter { height: 5px; background: var(--soft); overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--accent); transition: width 0.4s var(--ease); }
.rules { margin: 0; padding: 0; list-style: none; display: grid; gap: 10px; font-size: 0.76rem; }
.rules li { display: grid; gap: 2px; }
.rules .if { font: 500 0.68rem var(--mono); color: var(--muted); }
.rules .then { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.rules .then i { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.rules .then small { font-weight: 400; color: var(--muted); }
pre {
  margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font: 0.68rem/1.65 var(--mono); color: var(--ink);
  background: var(--soft); padding: 10px 12px; border-radius: 3px;
}
.tk-k { color: var(--accent); }
.tk-s { color: var(--amber); }
.tk-n { color: var(--bad); }
.tk-c { color: var(--muted); }
.table-scroll { overflow: auto; }
table { border-collapse: collapse; font-size: 0.72rem; width: 100%; }
th, td { text-align: left; padding: 4px 8px; border-bottom: 1px solid var(--hair); white-space: nowrap; }
th { font-weight: 600; color: var(--muted); }
td.na { color: var(--muted); font-style: italic; }

/* custom data */
.custom { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; border: 1px solid var(--line); background: var(--panel); padding: 14px 16px; }
.custom.drop { border-color: var(--accent); background: var(--accent-soft); }
.custom textarea {
  display: block; flex: 1 1 auto; width: 100%; min-height: 220px; resize: none; border: 0; background: transparent;
  color: var(--ink); font: 0.78rem/1.55 var(--mono); padding: 0;
}
.custom textarea:focus-visible { outline: none; }
.custom-bar { display: flex; gap: 12px; align-items: center; border-top: 1px solid var(--hair); padding-top: 10px; margin-top: 8px; font-size: 0.8rem; }
.custom-bar .error { color: var(--bad); }
.custom-bar #show-tree { margin-left: auto; }

footer.wrap { display: flex; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap; padding-top: 10px; padding-bottom: 12px; font-size: 0.72rem; color: var(--muted); }

/* ---------------------------------------------------------------- smaller screens scroll normally */

@media (max-width: 1100px), (max-height: 699px) {
  .work { grid-template-columns: 330px minmax(0, 1fr); }
  .insight { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); }
  .tree-scroll { height: 460px; }
  .pane { max-height: 360px; overflow: auto; }
  footer.wrap { padding-top: 20px; padding-bottom: 24px; }
}
@media (max-width: 860px) {
  .hero { grid-template-columns: 1fr; align-items: start; }
  .figures > div:first-child { border-left: 0; padding-left: 0; }
  .work { grid-template-columns: 1fr; }
  .ask { border-right: 0; border-bottom: 1px solid var(--line); }
  .tree-scroll { height: 420px; }
  .figures { grid-template-columns: 1fr 1fr; gap: 12px 0; }
  .figures > div:nth-child(3) { border-left: 0; padding-left: 0; }
}
@media (max-width: 600px) {
  .wrap { padding-left: 16px; padding-right: 16px; }
  .hero { padding-left: 16px; padding-right: 16px; }
  .knobs label { width: calc(50% - 7px); }
  .field { grid-template-columns: 92px minmax(0, 1fr); }
  .seg-tabs button span { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
