/* Sillboard design tokens: warm stone, ink, amber. Dark mode re-steps the same hues. */
:root {
  color-scheme: light;
  --stone-50: #fbf8f3; --stone-100: #f3eee6; --stone-200: #e7dfd3; --stone-300: #d3c8b8;
  --stone-400: #a89d8d; --stone-500: #7c7265;
  --ink: #1c1917; --ink-secondary: #4a443f; --ink-muted: #7c7265;
  --amber: #d97706; --amber-deep: #b45309; --amber-soft: #fdecc8; --amber-ink: #7a3f03;
  --surface: #fffdf9; --page: var(--stone-50); --card-border: rgba(28, 25, 23, 0.10);
  --grid: #e9e3d8; --axis: #cfc5b5;
  --series-1: #c2410c; --series-2: #2a66a8; --series-3: #0f8a6e; --series-4: #8a4bb3; --series-5: #b8860b;
  --good: #0ca30c; --warn: #fab219; --bad: #d03b3b;
  --radius: 14px; --shadow: 0 1px 2px rgba(28, 25, 23, 0.06), 0 6px 20px -12px rgba(28, 25, 23, 0.25);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --ink: #f3eee6; --ink-secondary: #cdc4b7; --ink-muted: #9c9185;
    --amber: #f59e0b; --amber-deep: #fbbf24; --amber-soft: #3b2a10; --amber-ink: #fcd38a;
    --surface: #262220; --page: #1c1917; --card-border: rgba(255, 255, 255, 0.10);
    --grid: #342f2b; --axis: #4a443f;
    --series-1: #d9782f; --series-2: #4f8fd4; --series-3: #22a383; --series-4: #a97bd8; --series-5: #b58a14;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px -12px rgba(0, 0, 0, 0.6);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #f3eee6; --ink-secondary: #cdc4b7; --ink-muted: #9c9185;
  --amber: #f59e0b; --amber-deep: #fbbf24; --amber-soft: #3b2a10; --amber-ink: #fcd38a;
  --surface: #262220; --page: #1c1917; --card-border: rgba(255, 255, 255, 0.10);
  --grid: #342f2b; --axis: #4a443f;
  --series-1: #d9782f; --series-2: #4f8fd4; --series-3: #22a383; --series-4: #a97bd8; --series-5: #b58a14;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px -12px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); color: var(--ink); background: var(--page);
  line-height: 1.45; font-size: 15px;
}
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -0.01em; }
p { margin: 0; }
a { color: var(--amber-deep); }
button, input, select { font: inherit; color: inherit; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--amber); color: #1c1917; padding: 8px 12px; border-radius: 8px; z-index: 50; }
.skip:focus { left: 8px; }

/* ---- top bar ---- */
.topbar { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: center; justify-content: space-between; padding: 20px 16px 8px; max-width: 1200px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 14px; }
.logo { width: 44px; height: 44px; flex: none; }
.logo-frame { fill: var(--ink); }
.logo-glow { fill: var(--amber); }
.logo-sill { fill: var(--stone-400); }
.topbar h1 { font-size: 1.45rem; font-weight: 700; }
.tagline { color: var(--ink-muted); font-size: 0.9rem; }
.status { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; font-size: 0.85rem; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--card-border); background: var(--surface); }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--stone-400); }
.pill-live::before { background: var(--good); }
.pill-snapshot::before { background: var(--warn); }
.pill-builtin::before { background: var(--bad); }
.pill-muted::before { background: var(--stone-400); }

/* ---- scenario bar ---- */
.scenario-bar { max-width: 1200px; margin: 8px auto 0; padding: 12px 16px; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.scenario-pick { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.scenario-pick select { min-width: 180px; }
.scenario-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.scenario-note { width: 100%; color: var(--ink-muted); font-size: 0.85rem; min-height: 1.2em; }
.divider { width: 1px; height: 22px; background: var(--card-border); margin: 0 4px; }

.btn { border: 1px solid var(--card-border); background: var(--surface); border-radius: 10px; padding: 7px 12px; cursor: pointer; font-size: 0.9rem; transition: transform 0.08s ease, background 0.15s ease; }
.btn:hover { background: var(--stone-100); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--amber); border-color: var(--amber-deep); color: #1c1917; font-weight: 600; }
.btn-primary:hover { background: var(--amber-deep); color: #1c1917; }
.btn-danger:hover { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--stone-100); }
:root[data-theme="dark"] .btn:hover, :root[data-theme="dark"] .btn-ghost:hover { background: #332e2a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn:hover, :root:not([data-theme="light"]) .btn-ghost:hover { background: #332e2a; } }
.file-btn { display: inline-block; }
input[type="number"], input[type="text"], select {
  background: var(--surface); border: 1px solid var(--card-border); border-radius: 8px; padding: 6px 8px; min-width: 0;
}
input[type="number"]:focus, select:focus, .btn:focus-visible, .hit:focus { outline: 2px solid var(--amber); outline-offset: 2px; }

/* ---- tabs ---- */
.tabs { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--page) 88%, transparent); backdrop-filter: blur(8px);
  display: flex; gap: 4px; overflow-x: auto; padding: 8px 16px; max-width: 1200px; margin: 0 auto; border-bottom: 1px solid var(--card-border); scrollbar-width: none; }
.tabs a { white-space: nowrap; text-decoration: none; color: var(--ink-secondary); padding: 8px 12px; border-radius: 999px; font-weight: 600; font-size: 0.92rem; }
.tabs a:hover { background: var(--stone-100); }
.tabs a[aria-current="page"] { background: var(--ink); color: var(--page); }
:root[data-theme="dark"] .tabs a:hover { background: #332e2a; }

/* ---- views ---- */
main { max-width: 1200px; margin: 0 auto; padding: 8px 16px 48px; }
.view { display: none; padding-top: 20px; }
.view.active { display: block; }
.view-head { margin-bottom: 16px; }
.view-head h2 { font-size: 1.5rem; }
.lede { color: var(--ink-secondary); max-width: 70ch; margin-top: 6px; }
.layout { display: grid; grid-template-columns: 300px 1fr; gap: 16px; align-items: start; }
.charts { display: grid; gap: 16px; min-width: 0; }
@media (max-width: 860px) { .layout { grid-template-columns: 1fr; } }

.card { background: var(--surface); border: 1px solid var(--card-border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px 12px; margin: 0; min-width: 0; position: relative; }
.card::after { content: ""; position: absolute; left: 14px; right: 14px; bottom: 0; height: 3px; border-radius: 3px 3px 0 0; background: var(--stone-300); opacity: 0.6; }
figure.card figcaption { font-weight: 600; margin-bottom: 8px; }
.note { color: var(--ink-secondary); font-size: 0.92rem; max-width: 75ch; padding: 0 4px; }
.note b { color: var(--ink); }

/* ---- KPI tiles ---- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--card-border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); min-width: 0; }
.tile .label { color: var(--ink-muted); font-size: 0.8rem; }
.tile .value { font-size: 1.5rem; font-weight: 600; margin-top: 2px; overflow-wrap: anywhere; }
.tile .sub { color: var(--ink-secondary); font-size: 0.8rem; margin-top: 2px; }
.tile.hero { grid-column: span 2; background: var(--amber-soft); border-color: transparent; }
.tile.hero .value { font-size: 2.6rem; color: var(--amber-ink); }
.tile.hero .label { color: var(--amber-ink); }
.tile.bad .value { color: var(--bad); }
@media (max-width: 480px) { .tile.hero { grid-column: 1 / -1; } }

/* ---- knobs ---- */
.knobs { background: var(--surface); border: 1px solid var(--card-border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.knobs h3 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-muted); margin-bottom: 8px; }
.knobs h3[role="button"] { cursor: default; }
@media (max-width: 860px) {
  .knobs h3[role="button"] { cursor: pointer; display: flex; justify-content: space-between; align-items: center; margin-bottom: 0; }
  .knobs h3[role="button"]::after { content: "Show"; font-size: 0.72rem; color: var(--amber-deep); letter-spacing: 0; text-transform: none; font-weight: 600; }
  .knobs.open h3[role="button"]::after { content: "Hide"; }
  .knobs.open h3 { margin-bottom: 8px; }
  .knobs[data-knobs]:not(.open) .field, .knobs[data-knobs]:not(.open) h4 { display: none; }
}
.knobs h4 { font-size: 0.8rem; margin: 10px 0 4px; color: var(--ink-secondary); }
.field { display: grid; grid-template-columns: 1fr 112px; align-items: center; gap: 8px; padding: 4px 0; border-bottom: 1px solid var(--grid); }
.field:last-child { border-bottom: 0; }
.field label { font-size: 0.88rem; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.field .control { display: flex; align-items: center; gap: 4px; justify-content: flex-end; }
.field input[type="number"] { width: 84px; text-align: right; font-variant-numeric: tabular-nums; }
.field select { width: 100%; }
.field .unit { color: var(--ink-muted); font-size: 0.8rem; width: 20px; }
.badge-live { display: inline-block; font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.05em; background: var(--amber-soft); color: var(--amber-ink); border-radius: 6px; padding: 1px 5px; font-weight: 700; }
.sliders .field { grid-template-columns: 1fr; }
.sliders .field .control { justify-content: space-between; width: 100%; }
.sliders input[type="range"] { flex: 1; accent-color: var(--amber); }
.inputs-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; margin-bottom: 16px; }

/* ---- charts ---- */
.chart { position: relative; }
.chart-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 0.82rem; color: var(--ink-secondary); }
.legend li { display: flex; align-items: center; gap: 6px; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex: none; }
.chart-table-toggle { font-size: 0.78rem; padding: 3px 8px; border: 1px solid var(--card-border); border-radius: 8px; cursor: pointer; margin-left: auto; }
.chart-table-toggle[aria-pressed="true"] { background: var(--ink); color: var(--page); }
.chart-plot { width: 100%; min-height: 60px; }
.chart-plot svg { display: block; width: 100%; height: auto; overflow: visible; }
.hit { cursor: crosshair; outline: none; }
.tooltip { position: absolute; z-index: 5; pointer-events: none; background: var(--ink); color: var(--page); border-radius: 8px; padding: 8px 10px; font-size: 0.8rem; min-width: 160px; box-shadow: var(--shadow); }
.tip-title { font-weight: 600; margin-bottom: 4px; }
.tip-row { display: grid; grid-template-columns: auto 1fr auto; gap: 6px; align-items: center; }
.tip-row b { font-variant-numeric: tabular-nums; }

table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { text-align: right; padding: 6px 8px; border-bottom: 1px solid var(--grid); font-variant-numeric: tabular-nums; }
th:first-child, td:first-child { text-align: left; }
thead th { color: var(--ink-muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }
tbody th { font-weight: 500; }
.chart-table { overflow-x: auto; }
.table-card { overflow-x: auto; }
.table-card h3 { font-size: 1rem; margin-bottom: 8px; }
.neg { color: var(--bad); }

.controls { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: center; }
.controls label { display: flex; gap: 8px; align-items: center; font-weight: 600; font-size: 0.9rem; }
.controls input[type="number"] { width: 72px; }

/* ---- live config card ---- */
#live-config-card h3 { font-size: 1rem; margin-bottom: 6px; }
#live-config-card p { color: var(--ink-secondary); font-size: 0.9rem; margin-bottom: 8px; }
#live-config-card .actions { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; }
.diff { color: var(--amber-deep); font-weight: 600; }

.foot { text-align: center; color: var(--ink-muted); font-size: 0.8rem; padding: 16px; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--ink); color: var(--page); padding: 10px 16px; border-radius: 999px; font-size: 0.9rem; box-shadow: var(--shadow); z-index: 30; max-width: calc(100vw - 32px); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media print { .tabs, .scenario-bar, .knobs { display: none; } .view { display: block !important; } }
