/* ---------- palette & chrome (light default, dark via media query) ---------- */
: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);

  --speed: #2a78d6;      /* series 1 blue — speed line */
  --hr: #e34948;         /* series 8 red — heart-rate line */
  --halftime-wash: rgba(137, 135, 129, 0.14);
  --half-wash: rgba(42, 120, 214, 0.07);

  /* ordinal blue ramp — speed zones (walk → sprint) */
  --zone-1: #86b6ef;
  --zone-2: #5598e7;
  --zone-3: #2a78d6;
  --zone-4: #1c5cab;
  --zone-5: #0d366b;

  /* ordinal orange ramp — HR zones (z1 → z5) */
  --hrz-1: #f0a05e;
  --hrz-2: #eb7f3a;
  --hrz-3: #d55e1f;
  --hrz-4: #a8461a;
  --hrz-5: #7d3410;
}
@media (prefers-color-scheme: dark) {
  :root {
    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);

    --speed: #3987e5;
    --hr: #e66767;
    --halftime-wash: rgba(137, 135, 129, 0.18);
    --half-wash: rgba(57, 135, 229, 0.09);

    --zone-1: #cde2fb;
    --zone-2: #86b6ef;
    --zone-3: #5598e7;
    --zone-4: #2a78d6;
    --zone-5: #184f95;

    --hrz-1: #fbe3cc;
    --hrz-2: #f4b27a;
    --hrz-3: #ed7f45;
    --hrz-4: #d95926;
    --hrz-5: #a33f11;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.45;
}

.page { max-width: 960px; margin: 0 auto; padding: 24px 16px 48px; }

.page-header h1 { margin: 0 0 4px; font-size: 1.7rem; }
.subtitle { margin: 0 0 20px; color: var(--ink-2); max-width: 60ch; }

.muted { color: var(--muted); }
.small { font-size: 0.82rem; }

/* ---------- drop zone ---------- */
.drop-zone {
  border: 2px dashed var(--axis);
  border-radius: 12px;
  background: var(--surface);
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.drop-zone:hover, .drop-zone:focus-visible, .drop-zone.drag-over {
  border-color: var(--speed);
  outline: none;
}
.drop-zone.drag-over { background: var(--half-wash); }
.drop-icon { font-size: 2rem; color: var(--muted); }
.drop-zone p { margin: 6px 0; }
.drop-hint { color: var(--muted); font-size: 0.82rem; }

.error-box {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: #d03b3b;
}

/* ---------- report layout ---------- */
.report-header {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; margin: 24px 0 12px; flex-wrap: wrap;
}
.report-header h2 { margin: 0; font-size: 1.25rem; }
.report-header p { margin: 2px 0 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin: 16px 0;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 4px;
}
.card-head h3 { margin: 0; font-size: 1.05rem; }
.card-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.chart-title { margin: 14px 0 4px; font-size: 0.88rem; color: var(--ink-2); font-weight: 600; }

.ghost-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--ink-2);
  padding: 6px 12px;
  font: inherit;
  cursor: pointer;
}
.ghost-btn:hover { border-color: var(--axis); color: var(--ink); }
.ghost-btn.small { padding: 3px 9px; font-size: 0.8rem; }

/* ---------- stat tiles ---------- */
.tile-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin: 12px 0;
}
.tile-row.compact { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}
.tile .t-label { font-size: 0.78rem; color: var(--muted); margin-bottom: 2px; }
.tile .t-value { font-size: 1.45rem; font-weight: 600; }
.tile .t-value.hero { font-size: 2rem; }
.tile .t-sub { font-size: 0.78rem; color: var(--ink-2); margin-top: 2px; }
.tile-row.compact .t-value { font-size: 1.2rem; }

/* ---------- settings ---------- */
.settings-row {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 8px 0 4px;
}
.settings-row label, .settings-inline {
  font-size: 0.82rem; color: var(--ink-2);
  display: inline-flex; align-items: center; gap: 5px;
}
.settings-row input, .settings-inline input {
  width: 62px;
  padding: 3px 6px;
  font: inherit;
  color: var(--ink);
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: 6px;
}

/* ---------- legend ---------- */
.legend-row {
  display: flex; gap: 14px; flex-wrap: wrap;
  margin: 8px 0 2px;
  font-size: 0.8rem; color: var(--ink-2);
}
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.legend-line { width: 16px; height: 2px; border-radius: 1px; display: inline-block; }

/* ---------- charts ---------- */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; }
.chart text { font-family: inherit; }

.marker-handle { cursor: ew-resize; }
.marker-line { cursor: ew-resize; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; margin-top: 8px; }
table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.85rem;
}
th, td {
  text-align: right;
  padding: 6px 10px;
  border-bottom: 1px solid var(--grid);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--axis); }

/* ---------- tooltip ---------- */
.tooltip {
  position: fixed;
  z-index: 10;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  padding: 8px 10px;
  font-size: 0.8rem;
  color: var(--ink-2);
  min-width: 120px;
}
.tooltip .tt-title { color: var(--muted); margin-bottom: 4px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 6px; margin: 2px 0; }
.tooltip .tt-key { width: 12px; height: 2px; border-radius: 1px; flex: none; }
.tooltip .tt-key.box { height: 10px; border-radius: 3px; }
.tooltip .tt-value { font-weight: 600; color: var(--ink); margin-left: auto; font-variant-numeric: tabular-nums; }

.page-footer { margin-top: 28px; text-align: center; }
