/* Palette roles: light is the default, dark is a selected set of steps for the
   dark surface (not an automatic inversion). Both the OS setting and the manual
   toggle resolve to the same tokens. */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --hover: rgba(11, 11, 11, 0.04);
  --series-1: #2a78d6;   /* speed */
  --series-2: #eb6834;   /* work intervals */
  --good: #006300;
  --critical: #d03b3b;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --hover: rgba(255, 255, 255, 0.06);
    --series-1: #3987e5;
    --series-2: #d95926;
    --good: #0ca30c;
    --critical: #d03b3b;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --hover: rgba(255, 255, 255, 0.06);
  --series-1: #3987e5;
  --series-2: #d95926;
  --good: #0ca30c;
  --critical: #d03b3b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
}

h1, h2 { font-weight: 600; }

/* ---------- chrome ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 17px; margin: 0; letter-spacing: -0.01em; }

.logo {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: linear-gradient(135deg, var(--series-1), var(--series-2));
}

.topbar-actions { display: flex; align-items: center; gap: 10px; }

.engine {
  font-size: 12px;
  color: var(--ink-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px;
  white-space: nowrap;
}

button.ghost {
  font: inherit;
  font-size: 13px;
  color: var(--ink-2);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 12px;
  cursor: pointer;
}
button.ghost:hover { background: var(--hover); color: var(--ink); }

main {
  max-width: 1080px;
  margin: 0 auto;
  padding-block: 28px 64px;
  padding-inline: 20px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 18px;
}

/* ---------- upload ---------- */

.dropzone {
  border: 1.5px dashed var(--axis);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 56px 24px;
  text-align: center;
  transition: border-color .15s, background .15s;
}
.dropzone.over { border-color: var(--series-1); background: var(--hover); }

.dz-title { margin: 0 0 6px; font-size: 19px; font-weight: 600; }
.dz-sub { margin: 0; color: var(--ink-2); font-size: 14px; }
.dz-hint { margin: 14px 2px 0; color: var(--muted); font-size: 13px; }

.link {
  color: var(--series-1);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.error {
  margin-top: 16px;
  padding: 12px 14px;
  border: 1px solid var(--critical);
  border-radius: 8px;
  color: var(--ink);
  font-size: 14px;
}
.error::before { content: "⚠ "; color: var(--critical); }

/* ---------- hero & tiles ---------- */

.hero { padding-block: 22px; }
.hero-label { margin: 0; color: var(--ink-2); font-size: 14px; }
.hero-figure {
  margin: 4px 0 2px;
  font-size: 48px;
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: -0.02em;
}
.hero-sub { margin: 0; color: var(--ink-2); font-size: 14px; }

.notice {
  margin: 14px 0 0;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--hover);
  color: var(--ink-2);
  font-size: 13px;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.tile-label { margin: 0; font-size: 12.5px; color: var(--ink-2); }
.tile-value { margin: 2px 0 0; font-size: 26px; font-weight: 600; letter-spacing: -0.01em; }
.tile-note { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }
.tile-note.up { color: var(--good); }
.tile-note.down { color: var(--critical); }

/* ---------- controls ---------- */

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 18px;
}
.control { display: flex; flex-direction: column; gap: 5px; min-width: 160px; flex: 1 1 160px; }
.control label { font-size: 12.5px; color: var(--ink-2); display: flex; gap: 6px; }
.control output { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.control input[type="range"] { width: 100%; accent-color: var(--series-1); }
.control select {
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
}

/* ---------- charts ---------- */

.chart-card .chart-caption { margin-bottom: 10px; }
.chart-card h2 { margin: 0; font-size: 15px; }
.chart-card .chart-caption p { margin: 2px 0 0; font-size: 13px; color: var(--ink-2); }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; touch-action: pan-y; }

.controls-collapsible summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  list-style: none;
}
.controls-collapsible summary::-webkit-details-marker { display: none; }
.controls-collapsible summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 6px;
  transition: transform .15s;
}
.controls-collapsible[open] summary::before { transform: rotate(90deg); }
.controls-collapsible .controls { margin-top: 14px; }

.tooltip {
  position: absolute;
  pointer-events: none;
  z-index: 2;
  min-width: 132px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .16);
  font-size: 12.5px;
  color: var(--ink-2);
  opacity: 0;
  transition: opacity .1s;
}
.tooltip.show { opacity: 1; }
.tt-head { color: var(--ink); font-weight: 600; margin-bottom: 4px; }
.tt-row { display: flex; align-items: center; gap: 7px; white-space: nowrap; }
.tt-row + .tt-row { margin-top: 2px; }
.tt-key { width: 12px; height: 2px; border-radius: 1px; flex: none; }
.tt-val { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- table ---------- */

.table-card h2 { margin: 0 0 12px; font-size: 15px; }
.table-scroll { overflow-x: auto; }

table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { text-align: right; padding: 7px 10px; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
thead th {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
  border-bottom: 1px solid var(--axis);
}
tbody td { border-bottom: 1px solid var(--grid); font-variant-numeric: tabular-nums; }
tbody tr:hover td { background: var(--hover); }
tbody tr.is-work td:first-child { font-weight: 600; color: var(--ink); }
td:first-child { color: var(--ink-2); }

.swatch {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  margin-right: 7px;
  vertical-align: middle;
  background: var(--axis);
}
.swatch.work { background: var(--series-2); }

.table-note { margin: 12px 0 0; font-size: 12.5px; color: var(--muted); }

@media (max-width: 620px) {
  .hero-figure { font-size: 36px; }
  main { padding-block: 20px 48px; }
  .card { padding: 15px 16px; }
}

/* ---------- chart marks ----------
   Presentation attributes cannot read CSS custom properties, so every mark is
   styled here by class and both themes swap for free. */
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .band { fill: var(--series-2); fill-opacity: .13; }
.chart .band-label { fill: var(--muted); font-size: 10px; font-weight: 600; }
.chart .area { fill: var(--series-1); fill-opacity: .10; }
.chart .line {
  fill: none;
  stroke: var(--series-1);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.chart .ref { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 4; }
.chart .ref-label { fill: var(--muted); font-size: 11px; }
.chart .dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.chart .crosshair { stroke: var(--axis); stroke-width: 1; }
.chart .value-label { fill: var(--ink-2); font-size: 11px; font-weight: 600; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .hit:focus-visible { outline: 2px solid var(--series-1); outline-offset: -2px; }
.chart .label-bg { fill: var(--surface); fill-opacity: .88; }
