/* app.css — TopicLLM. Soft, modern shell over a code-forward terminal core.
 * Chart color roles follow the validated reference palette (light + dark
 * selected separately). Terminal panels are always dark, in both themes. */

/* Tokens follow the site design system (site.css): warm paper and ink, an
 * ember-gold ornament, selected light and dark modes. Chart roles use a
 * validated categorical palette. Terminal panels stay dark in both themes. */
:root {
  color-scheme: light;
  --surface-1: #fbf9f4;
  --page: #f6f2e9;
  --ink: #1c1a16;
  --ink-2: #4d473d;
  --muted: #6e675a;
  --grid: #e4dccd;
  --axis: #b9ad97;
  --border: #d9cfbd;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --good: #2f7a3b;
  --bad: #b8402f;
  --accent: #7a5a0f;
  --ornament: #c9a227;
  --accent-soft: rgba(201, 162, 39, 0.12);
  --accent-ink: #fbf9f4;
  --shadow: 0 1px 0 rgba(28, 26, 22, 0.04), 0 14px 32px -24px rgba(28, 26, 22, 0.35);
  --term-bg: #12110e;
  --term-bar: #1a1814;
  --term-border: #2c2820;
  --term-ink: #e4dccb;
  --term-dim: #9b927f;
  --term-ok: #7fbf6a;
  --term-warn: #e0b14a;
  --term-cmd: #d4b048;
  --term-accent: #d4b048;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: "Cormorant Garamond", Garamond, "Times New Roman", serif;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #16140f; --page: #0d0c0a; --ink: #ece5d6; --ink-2: #bdb3a1; --muted: #8f8676;
    --grid: #26221b; --axis: #4a4235; --border: #2f2a22;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
    --good: #6fb35f; --bad: #e0705c; --accent: #d4b048; --accent-soft: rgba(201, 162, 39, 0.10);
    --accent-ink: #0d0c0a;
    --shadow: 0 1px 0 rgba(0, 0, 0, 0.4), 0 14px 32px -24px rgba(0, 0, 0, 0.8);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #16140f; --page: #0d0c0a; --ink: #ece5d6; --ink-2: #bdb3a1; --muted: #8f8676;
  --grid: #26221b; --axis: #4a4235; --border: #2f2a22;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
  --good: #6fb35f; --bad: #e0705c; --accent: #d4b048; --accent-soft: rgba(201, 162, 39, 0.10);
  --accent-ink: #0d0c0a;
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.4), 0 14px 32px -24px rgba(0, 0, 0, 0.8);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--sans);
  background: var(--page);
  color: var(--ink);
  line-height: 1.55;
  font-size: 15px;
}
a { color: var(--accent); text-underline-offset: 3px; }
.wrap { max-width: 1080px; margin: 0 auto; padding: 0 20px; }

/* ------------------------------ header ----------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
.topbar .wrap { display: flex; align-items: center; gap: 20px; height: 58px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand svg { width: 26px; height: 26px; color: var(--ornament); }
.brand b { font-family: var(--display); font-size: 24px; font-weight: 700; }
.topnav { display: flex; gap: 2px; margin-left: auto; overflow-x: auto; scrollbar-width: none; }
.topnav a { font-size: 14px; color: var(--ink-2); text-decoration: none; padding: 7px 10px; border-radius: 6px; white-space: nowrap; }
.topnav a:hover, .topnav a[aria-current="page"] { color: var(--ink); background: var(--accent-soft); }
.theme-toggle { flex: none; appearance: none; border: 1px solid var(--border); background: var(--surface-1);
  color: var(--ink-2); width: 34px; height: 34px; border-radius: 50%; cursor: pointer; display: grid; place-items: center; }
.theme-toggle svg { width: 16px; height: 16px; }
@media (max-width: 560px) { .topnav { display: none; } .topbar .wrap { justify-content: space-between; } }
.page-head { border-bottom: 1px solid var(--border); padding-top: 34px; }
.eyebrow { font-family: var(--mono); font-size: 11.5px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent); margin: 0; }
.page-head h1 { font-family: var(--display); font-weight: 600; font-size: clamp(2rem, 4vw, 2.9rem); line-height: 1.05; margin: 8px 0 10px; letter-spacing: -0.005em; }
.tagline { margin: 0 0 18px; color: var(--ink-2); max-width: 70ch; }
.mono-chip { font-family: var(--mono); font-size: 12.5px; background: var(--term-bg); color: var(--term-ok);
  border: 1px solid var(--term-border); border-radius: 999px; padding: 3px 12px; }
.blink { animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
nav.tabs { display: flex; gap: 4px; }
nav.tabs button {
  appearance: none; border: none; background: none; color: var(--ink-2);
  font: inherit; padding: 9px 14px; cursor: pointer;
  border-bottom: 2px solid transparent; transition: color .15s;
}
nav.tabs button.active { color: var(--ink); border-bottom-color: var(--ornament); font-weight: 600; }
nav.tabs button:hover { color: var(--ink); }

/* ------------------------------ layout ------------------------------------ */
main { padding: 24px 0 48px; }
main.wrap { padding-top: 26px; padding-bottom: 48px; }
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px 22px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 4px; font-size: 22px; font-family: var(--display); font-weight: 600; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.card h3 { margin: 0 0 6px; font-size: 15px; }
.idx { font-family: var(--mono); color: var(--accent); font-weight: 600; margin-right: 2px; }
.stage-sub { margin: 2px 0 12px; color: var(--ink-2); font-size: 14px; max-width: 72ch; }
.intro p { margin: 0 0 12px; }
.stage-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; }
.stage-grid .card { margin: 0; }
.stage-grid p { margin: 0; color: var(--ink-2); font-size: 14px; }

/* ------------------------------ stepper ----------------------------------- */
.stepper {
  list-style: none; display: flex; gap: 8px; flex-wrap: wrap;
  margin: 0 0 20px; padding: 0;
}
.stepper li {
  font-family: var(--mono); font-size: 12.5px; color: var(--ink-2);
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface-1);
  padding: 6px 14px; cursor: pointer; user-select: none;
  transition: border-color .15s, color .15s, transform .1s;
}
.stepper li:hover { border-color: var(--accent); color: var(--ink); transform: translateY(-1px); }
.stepper li b { font-weight: 600; color: var(--muted); margin-right: 6px; }
.stepper li.done { border-color: var(--good); }
.stepper li.done b { color: var(--good); }
.stepper li.done::after { content: " ✓"; color: var(--good); }
.stepper li.running { border-color: var(--accent); color: var(--ink); }
.stepper li.running b { color: var(--accent); }
.stepper li.running::after { content: " …"; color: var(--accent); }
.stepper li.blocked { border-color: var(--bad); }
.stepper li.blocked::after { content: " !"; color: var(--bad); }

/* ------------------------------ controls ---------------------------------- */
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 10px 0; }
.row.dl { margin-top: 14px; align-items: baseline; }
.dl-label { font-family: var(--mono); font-size: 12px; color: var(--muted); cursor: help; }
.btn {
  appearance: none; font: inherit; cursor: pointer;
  background: var(--surface-1); color: var(--ink);
  border: 1px solid var(--axis); border-radius: 9px; padding: 8px 15px;
  text-decoration: none; display: inline-block;
  transition: border-color .15s, transform .12s, box-shadow .15s, opacity .15s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); transform: translateY(-1px); box-shadow: var(--shadow); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.sm { padding: 5px 11px; font-size: 12.5px; font-family: var(--mono); }
.btn.file { position: relative; overflow: hidden; }

.note { color: var(--ink-2); font-size: 13.5px; margin: 8px 0; }
.live { color: var(--ink-2); font-size: 13.5px; font-family: var(--mono); font-variant-numeric: tabular-nums; }

.badge {
  font-size: 11.5px; font-weight: 600; font-family: var(--mono);
  border-radius: 999px; padding: 3px 11px;
  border: 1px solid var(--border); color: var(--ink-2); background: var(--page);
}
.badge.running { color: var(--accent); border-color: var(--accent); }
.badge.done { color: var(--good); border-color: var(--good); }
.badge.blocked, .badge.error { color: var(--bad); border-color: var(--bad); }

label { display: flex; flex-direction: column; gap: 4px; font-size: 13.5px; color: var(--ink-2); }
label .lbl { display: inline-flex; align-items: center; gap: 6px; }
label.check { flex-direction: row; align-items: center; gap: 8px; }
label.wide { margin-top: 10px; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--page);
  border: 1px solid var(--axis); border-radius: 8px; padding: 7px 10px;
  transition: border-color .15s, outline-color .15s;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.grid-4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; margin: 10px 0; }
details.settings { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 10px; }
details.settings summary { cursor: pointer; font-weight: 600; color: var(--ink-2); }
details.settings summary::marker { color: var(--accent); }

/* ------------------------------ tooltips ---------------------------------- */
.info-chip {
  display: inline-flex; align-items: center; justify-content: center;
  width: 17px; height: 17px; border-radius: 50%;
  border: 1px solid var(--axis); color: var(--muted);
  font: 600 11px/1 var(--mono); cursor: help; flex: none;
  transition: border-color .15s, color .15s;
}
.info-chip:hover, .info-chip:focus-visible { border-color: var(--accent); color: var(--accent); }

[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute; z-index: 60;
  bottom: calc(100% + 9px); left: 50%;
  transform: translateX(-50%) translateY(3px);
  width: max-content; max-width: 300px;
  background: var(--term-bg); color: var(--term-ink);
  border: 1px solid var(--term-border); border-radius: 9px;
  padding: 9px 12px;
  font: 400 12.5px/1.55 var(--mono);
  text-align: left; white-space: normal; letter-spacing: 0;
  opacity: 0; pointer-events: none;
  transition: opacity .15s, transform .15s;
  box-shadow: 0 8px 24px -8px rgba(0, 0, 0, 0.5);
}
[data-tip]::before {
  content: "";
  position: absolute; z-index: 61;
  bottom: calc(100% + 4px); left: 50%;
  transform: translateX(-50%) translateY(3px) rotate(45deg);
  width: 9px; height: 9px;
  background: var(--term-bg);
  border-right: 1px solid var(--term-border); border-bottom: 1px solid var(--term-border);
  opacity: 0; pointer-events: none;
  transition: opacity .15s, transform .15s;
}
[data-tip]:hover::after, [data-tip]:focus-visible::after,
[data-tip]:hover::before, [data-tip]:focus-visible::before {
  opacity: 1; transform: translateX(-50%) translateY(0);
}
[data-tip]:hover::before, [data-tip]:focus-visible::before {
  transform: translateX(-50%) translateY(0) rotate(45deg);
}

/* ------------------------------ terminal ---------------------------------- */
.term {
  border: 1px solid var(--term-border); border-radius: 12px;
  overflow: hidden; margin: 12px 0;
  background: var(--term-bg);
  box-shadow: var(--shadow);
}
.term-bar {
  display: flex; align-items: center; gap: 10px;
  background: var(--term-bar); border-bottom: 1px solid var(--term-border);
  padding: 7px 12px;
}
.dots { display: inline-flex; gap: 6px; }
.dots i { width: 10px; height: 10px; border-radius: 50%; background: #3a4048; }
.dots i:nth-child(1) { background: #b3444a; }
.dots i:nth-child(2) { background: #b08a2e; }
.dots i:nth-child(3) { background: #3d8b46; }
.term-title { font: 500 12px var(--mono); color: var(--term-dim); }
.term-status { margin-left: auto; font: 600 11.5px var(--mono); color: var(--term-dim); }
.term.running .term-status { color: var(--term-accent); }
.term.running .term-status::before { content: "● "; animation: blink 1.1s steps(1) infinite; }

.log {
  font-family: var(--mono); font-size: 12.5px; line-height: 1.7;
  color: var(--term-ink);
  max-height: 280px; overflow-y: auto;
  padding: 10px 14px 12px;
}
.log:empty::before {
  content: "· idle — output streams here when this stage runs";
  color: var(--term-dim); font-style: italic;
}
.term.running .log::after {
  content: "▊"; color: var(--term-accent);
  animation: blink 1.1s steps(1) infinite;
}
.log-line { white-space: pre-wrap; word-break: break-word; }
.log-line .t { color: #444d56; margin-right: 8px; font-size: 11px; }
.log-line .g { margin-right: 8px; color: var(--term-dim); }
.log-line.info .tx { color: var(--term-ink); }
.log-line.meta .tx, .log-line.meta .g { color: var(--term-dim); }
.log-line.ok .tx, .log-line.ok .g, .log-line.best .tx, .log-line.best .g { color: var(--term-ok); }
.log-line.warn .tx, .log-line.warn .g { color: var(--term-warn); }
.log-line.cmd .tx { color: var(--term-cmd); font-weight: 600; }
.log-line.cmd .g { color: var(--term-ok); }
.log-line.log-progress .tx, .log-line.log-progress .g { color: var(--term-accent); }

/* ------------------------------ content ----------------------------------- */
.table-box { overflow-x: auto; margin: 12px 0; }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--grid); vertical-align: top; }
th { color: var(--ink-2); font-weight: 600; white-space: nowrap; }
td { font-variant-numeric: tabular-nums; }

.topic-card {
  border: 1px solid var(--border); border-radius: 10px;
  padding: 13px 15px; margin: 10px 0;
  transition: border-color .15s;
}
.topic-card:hover { border-color: var(--axis); }
.topic-card h4 { margin: 0 0 4px; }
.topic-card .meta { margin: 2px 0; color: var(--ink-2); font-size: 13px; }
.topic-card code { font-family: var(--mono); font-size: 12.5px; }
.topic-card details { margin: 8px 0; font-size: 13.5px; }
.topic-card summary { cursor: pointer; color: var(--ink-2); }
.topic-card ul { margin: 6px 0; padding-left: 20px; }
.topic-card label { margin-top: 8px; }
.ok { color: var(--good); font-weight: 700; }
.fail { color: var(--bad); font-weight: 700; }

/* --------------------------- charts -------------------------------------- */
.chart-box { margin: 14px 0; }
svg.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.chart .axis-label { fill: var(--ink-2); font-size: 12.5px; }
.chart .direct-label { fill: var(--ink-2); font-size: 12px; font-variant-numeric: tabular-nums; }
.chart .series-line { stroke: var(--series-1); stroke-width: 2; }
.chart .dot { fill: var(--series-1); }
.chart .dot-hi { stroke: var(--surface-1); stroke-width: 2; }
.chart .bar.s1 { fill: var(--series-1); }
.chart .bar.s2 { fill: var(--series-2); }
.chart .bar.s3 { fill: var(--series-3); }
.chart-tooltip {
  position: fixed; z-index: 50; pointer-events: none;
  background: var(--surface-1); color: var(--ink); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; font-size: 12.5px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18); max-width: 300px;
}

#paper-frame { width: 100%; height: 78vh; border: 1px solid var(--border); border-radius: 14px; background: var(--surface-1); box-shadow: var(--shadow); }

footer { border-top: 1px solid var(--border); padding: 14px 0 30px; color: var(--muted); font-size: 13px; }
footer a { color: inherit; }
