/* Run Tracker. One stylesheet, light and dark. Chart colours follow the
   dataviz reference palette (validated): series blue, a 5-step blue ramp for
   heart-rate zones, hairline grids. */

:root {
  color-scheme: light;
  --page: #f4f5f2;
  --card: #ffffff;
  --ink: #191919;
  --ink-2: #666666;
  --line: #e7e7e7;
  --axis: #c2c2c2;
  --ring: rgba(11, 11, 11, 0.08);
  --accent: #257de0;
  --accent-ink: #1757ac;
  --series: #257de0;
  --series-wash: rgba(37, 125, 224, 0.12);
  --muted-mark: #b6d5f8;
  --z1: #84b9f3;
  --z2: #519ced;
  --z3: #257de0;
  --z4: #1b64be;
  --z5: #0f4a96;
  --good: #006c10;
  --warn-bg: #fff4dc;
  --warn-ink: #7a4a00;
  --radius: 16px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0b0b0b;
    --card: #191919;
    --ink: #efefef;
    --ink-2: #9c9c9c;
    --line: #303030;
    --axis: #474747;
    --ring: rgba(255, 255, 255, 0.08);
    --accent: #338ced;
    --accent-ink: #84b9f3;
    --series: #338ced;
    --series-wash: rgba(51, 140, 237, 0.16);
    --muted-mark: #1757ac;
    --z1: #9dc8f7;
    --z2: #6aabf1;
    --z3: #338ced;
    --z4: #2370cd;
    --z5: #1757ac;
    --good: #53c556;
    --warn-bg: #3a2a08;
    --warn-ink: #ffd27a;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.45;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
a { color: var(--accent-ink); }
button, input, textarea { font: inherit; color: inherit; }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 18px 10px;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.brand { font-weight: 750; font-size: 1.1rem; letter-spacing: -0.01em; color: var(--ink); text-decoration: none; }
.sync {
  border: 0; background: var(--card); box-shadow: 0 0 0 1px var(--ring);
  border-radius: 999px; padding: 6px 12px; font-size: 0.85rem; color: var(--ink-2);
}
.sync.busy::before {
  content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 7px;
  border-radius: 50%; background: var(--accent); animation: pulse 1s infinite alternate;
}
@keyframes pulse { from { opacity: 0.25; } to { opacity: 1; } }

main { max-width: 760px; margin: 0 auto; padding: 4px 14px 24px; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; justify-content: space-around;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: var(--card); box-shadow: 0 -1px 0 var(--line);
}
.tabs a {
  flex: 1; text-align: center; padding: 8px 0; border-radius: 10px;
  color: var(--ink-2); text-decoration: none; font-weight: 600; font-size: 0.95rem;
}
.tabs a.on { color: var(--ink); background: var(--page); }

h1 { font-size: 1.6rem; letter-spacing: -0.02em; margin: 14px 4px 4px; line-height: 1.15; }
h2 { font-size: 1.05rem; margin: 0 0 2px; letter-spacing: -0.01em; }
.sub { color: var(--ink-2); font-size: 0.9rem; margin: 0 0 12px; }
.lede { color: var(--ink-2); margin: 0 4px 14px; }

.card {
  background: var(--card); border-radius: var(--radius); padding: 16px;
  box-shadow: 0 0 0 1px var(--ring); margin-bottom: 12px;
}
.card.flat { box-shadow: none; }

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 12px; }
.tile { background: var(--card); border-radius: var(--radius); padding: 12px 14px; box-shadow: 0 0 0 1px var(--ring); }
.tile .label { color: var(--ink-2); font-size: 0.8rem; }
.tile .value { font-size: 1.55rem; font-weight: 650; letter-spacing: -0.02em; line-height: 1.2; margin-top: 2px; }
.tile .value small { font-size: 0.85rem; font-weight: 500; color: var(--ink-2); margin-left: 2px; }
.tile .delta { font-size: 0.8rem; color: var(--ink-2); }
.tile .delta.up { color: var(--good); }
@media (max-width: 420px) { .tile .value { font-size: 1.3rem; } }

.warn {
  background: var(--warn-bg); color: var(--warn-ink); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 12px; font-size: 0.95rem;
}
.warn strong { display: block; }

.plan { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0 12px; }
.plan div { background: var(--page); border-radius: 12px; padding: 10px; }
.plan b { display: block; font-size: 1.3rem; letter-spacing: -0.02em; }
.plan span { color: var(--ink-2); font-size: 0.8rem; }
.why { margin: 0; padding-left: 18px; color: var(--ink-2); font-size: 0.92rem; }
.why li + li { margin-top: 4px; }

/* ---- charts */
.chart { width: 100%; height: auto; display: block; touch-action: pan-y; }
.chart text { fill: var(--ink-2); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .base { stroke: var(--axis); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--series); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--series-wash); }
.chart .dot { fill: var(--muted-mark); stroke: var(--card); stroke-width: 2; }
.chart .bar { fill: var(--series); }
.chart .bar.partial { fill: var(--muted-mark); }
.chart .bar.hot { opacity: 0.8; }
.chart .cross { stroke: var(--axis); stroke-width: 1; }
.chart .focus { fill: var(--series); stroke: var(--card); stroke-width: 2; }
.chart .end-label { fill: var(--ink); font-weight: 600; font-size: 12px; }
.chart .route { fill: none; stroke: var(--series); stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; }
.chart .route-start { fill: var(--good); stroke: var(--card); stroke-width: 2; }
.chart .route-end { fill: var(--ink); stroke: var(--card); stroke-width: 2; }

.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 0.82rem; color: var(--ink-2); margin-top: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.legend .ln { width: 14px; height: 2px; border-radius: 1px; vertical-align: 3px; }
.legend .dt { width: 8px; height: 8px; border-radius: 50%; }
.z1 { background: var(--z1); } .z2 { background: var(--z2); } .z3 { background: var(--z3); }
.z4 { background: var(--z4); } .z5 { background: var(--z5); }
.ln-series { background: var(--series); } .dt-muted { background: var(--muted-mark); }

.segbar { display: flex; gap: 2px; height: 14px; border-radius: 7px; overflow: hidden; background: var(--page); }
.segbar span { display: block; height: 100%; min-width: 0; }

.tip {
  position: fixed; z-index: 20; pointer-events: none;
  background: var(--card); color: var(--ink); border-radius: 10px; padding: 7px 10px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.16), 0 0 0 1px var(--ring); font-size: 0.82rem;
  max-width: 220px;
}
.tip b { display: block; font-size: 0.95rem; }
.tip span { color: var(--ink-2); }

details.table { margin-top: 8px; font-size: 0.85rem; color: var(--ink-2); }
details.table summary { cursor: pointer; }

/* ---- lists */
.runs { list-style: none; margin: 0; padding: 0; }
.runs li + li { border-top: 1px solid var(--line); }
.runs a {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 11px 2px;
  color: inherit; text-decoration: none;
}
.runs .when { font-weight: 600; }
.runs .what { color: var(--ink-2); font-size: 0.88rem; }
.runs .km { font-weight: 650; text-align: right; font-variant-numeric: tabular-nums; }
.runs .pace { color: var(--ink-2); font-size: 0.88rem; text-align: right; font-variant-numeric: tabular-nums; }
.week-head { display: flex; justify-content: space-between; color: var(--ink-2); font-size: 0.85rem; margin: 16px 4px 6px; }

.bests { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.bests a { background: var(--page); border-radius: 12px; padding: 10px 12px; color: inherit; text-decoration: none; }
.bests span { color: var(--ink-2); font-size: 0.8rem; display: block; }
.bests b { font-size: 1.2rem; font-variant-numeric: tabular-nums; }

/* ---- run page */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px 10px; }
@media (max-width: 520px) { .stats { grid-template-columns: repeat(3, 1fr); } }
.stats div span { display: block; color: var(--ink-2); font-size: 0.78rem; }
.stats div b { font-size: 1.2rem; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 2px 4px 12px; }
.chip { background: var(--card); box-shadow: 0 0 0 1px var(--ring); border-radius: 999px; padding: 4px 10px; font-size: 0.85rem; color: var(--ink-2); }

table.splits { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 0.92rem; }
table.splits th { text-align: left; color: var(--ink-2); font-weight: 500; font-size: 0.8rem; padding: 0 4px 6px; }
table.splits td { padding: 7px 4px; border-top: 1px solid var(--line); }
table.splits td.barcell { width: 38%; }
.pacebar { height: 8px; border-radius: 0 4px 4px 0; background: var(--series); }
.pacebar.fast { background: var(--z5); }

.feel { display: flex; gap: 6px; margin: 6px 0 10px; }
.feel button {
  flex: 1; border: 0; border-radius: 10px; padding: 9px 0; background: var(--page);
  font-size: 0.85rem; color: var(--ink-2);
}
.feel button.on { background: var(--accent); color: #fff; }
textarea {
  width: 100%; min-height: 80px; border-radius: 12px; border: 0; padding: 10px 12px;
  background: var(--page); resize: vertical;
}
.row { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.btn {
  border: 0; border-radius: 12px; padding: 11px 16px; font-weight: 600;
  background: var(--accent); color: #fff;
}
.btn.ghost { background: var(--page); color: var(--ink); }
.btn.quiet { background: none; color: var(--ink-2); padding: 8px 0; font-weight: 500; }
.btn:disabled { opacity: 0.5; }
.saved { color: var(--good); font-size: 0.85rem; }

label.field { display: block; margin-bottom: 12px; }
label.field span { display: block; font-size: 0.85rem; color: var(--ink-2); margin-bottom: 4px; }
input[type="email"], input[type="password"], input[type="number"] {
  width: 100%; border: 0; border-radius: 12px; padding: 11px 12px; background: var(--page);
}
.zones-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; font-variant-numeric: tabular-nums; }
.zones-table td { padding: 6px 4px; border-top: 1px solid var(--line); }
.zones-table td:first-child { width: 22px; }
.zones-table i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; }

.empty { text-align: center; padding: 34px 18px; }
.empty .big { font-size: 2.4rem; }
.error { color: #c0392b; font-size: 0.9rem; }
.login { max-width: 380px; margin: 9vh auto 0; }
