/* Bike Training dashboard — light/dark via tokens (palette: dataviz reference) */
: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.1);
  --s-blue: #2a78d6;
  --s-orange: #eb6834;
  --s-aqua: #1baf7a;
  --s-violet: #4a3aa7;
  --s-red: #e34948;
  --bar: #256abf;
  --wash: rgba(11, 11, 11, 0.04);
  --track: rgba(11, 11, 11, 0.09);    /* comparison bar track, 2px tall */
  --chip-bg: rgba(11, 11, 11, 0.045); /* chip fill, only if chips are ever used */
  --peak: #52514e;                    /* peak dot and label on elevation, = --ink-2 */
}
@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.1);
    --s-blue: #3987e5;
    --s-orange: #d95926;
    --s-aqua: #199e70;
    --s-violet: #9085e9;
    --s-red: #e66767;
    --bar: #3987e5;
    --wash: rgba(255, 255, 255, 0.06);
    --track: rgba(255, 255, 255, 0.13);
    --chip-bg: rgba(255, 255, 255, 0.07);
    --peak: #c3c2b7;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
#app { max-width: 680px; margin: 0 auto; padding: 16px 14px 48px; }
.loading { color: var(--muted); padding: 48px 0; text-align: center; }

h1 { font-size: 20px; margin: 4px 0 14px; letter-spacing: -0.01em; }
h2 {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 13px; font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.05em; margin: 26px 0 10px;
}
h2 .meta { font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--muted); font-size: 12px; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.backlink {
  display: inline-flex; align-items: center; gap: 4px;
  color: var(--ink-2); text-decoration: none; font-size: 14px; font-weight: 500;
  padding: 6px 8px 6px 2px; margin-left: -2px; border-radius: 8px; min-height: 44px;
}
.backlink:active { background: var(--wash); }
.backlink svg { display: block; }

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

/* Stat tiles. Two per row is the phone default; gridCols() in app.js sets the
   column count inline from the group's longest label, so labels never cross
   a border and a row never ends in a one-tile orphan. */
.tiles { display: grid; gap: 8px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px;
  display: flex; flex-direction: column; min-width: 0;
}
.tile[data-tip] { cursor: default; -webkit-tap-highlight-color: transparent; }
@media (hover: hover) { .tile[data-tip]:hover { border-color: var(--axis); } }
.tile .k {
  display: flex; align-items: center; gap: 5px; min-width: 0;
  font-size: 11px; color: var(--muted); letter-spacing: 0.03em; text-transform: uppercase; white-space: nowrap;
}
.tile .k span { overflow: hidden; text-overflow: ellipsis; }
.tile .v {
  display: flex; align-items: baseline; gap: 3px; margin-top: 3px;
  font-size: 20px; font-weight: 600; letter-spacing: -0.01em; font-variant-numeric: tabular-nums;
}
.tile .v small { font-size: 12px; font-weight: 500; color: var(--ink-2); }
.tile .pb { display: inline-flex; margin-left: 2px; transform: translateY(1px); }
.tile .sub { font-size: 11px; color: var(--ink-2); margin-top: 1px; }
/* Comparison row, pinned to the bottom so tiles in a row share height */
.tile .cmp { margin-top: auto; padding-top: 8px; }

/* Hairline comparison bar: fill = share of the all-time best, tick = 3 month usual */
.cmp-bar { position: relative; height: 2px; border-radius: 1px; background: var(--track); }
.cmp-bar i { position: absolute; inset: 0 auto 0 0; display: block; min-width: 2px; border-radius: 1px; background: var(--ink-2); }
.cmp-bar.is-best i { background: var(--metric, var(--ink-2)); }
.cmp-bar u { position: absolute; top: -3px; bottom: -3px; width: 1px; background: var(--muted); }
@media (prefers-reduced-motion: no-preference) {
  .cmp-bar i { animation: cmp-fill 320ms cubic-bezier(0.2, 0, 0, 1) both; transform-origin: left; }
  @keyframes cmp-fill { from { transform: scaleX(0); } }
}

/* Group label above a tile row */
.tile-group { margin-bottom: 14px; }
.tile-group > h3 {
  font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted); margin: 0 2px 6px;
}

/* Legend */
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--ink-2); margin: 2px 0 8px; }
.legend .li { display: inline-flex; align-items: center; gap: 6px; }
.legend .dot { width: 9px; height: 9px; border-radius: 50%; }

svg { display: block; }
svg text { font-family: system-ui, -apple-system, "Segoe UI", sans-serif; font-variant-numeric: tabular-nums; }
.chart-wrap { position: relative; touch-action: pan-y; }

/* Tooltip */
.tooltip {
  position: fixed; z-index: 10; pointer-events: none;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  padding: 7px 10px; font-size: 12px; line-height: 1.5;
  font-variant-numeric: tabular-nums; max-width: min(320px, calc(100vw - 16px)); white-space: nowrap;
}
.tooltip .val { white-space: normal; text-align: right; }
.tooltip .tt-title { font-weight: 600; margin-bottom: 2px; }
.tooltip .row { display: flex; align-items: center; gap: 6px; }
.tooltip .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.tooltip .lbl { color: var(--ink-2); white-space: nowrap; }
.tooltip .val { margin-left: auto; font-weight: 600; padding-left: 10px; }

/* Ride list */
.ride-row {
  display: block; text-decoration: none; color: inherit;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; margin-bottom: 8px;
}
.ride-row:active { background: var(--wash); }
.ride-row .r-top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.ride-row .r-name { font-weight: 600; font-size: 15px; display: inline-flex; align-items: center; gap: 6px; }
.ride-row .r-date { color: var(--muted); font-size: 12px; white-space: nowrap; }
.ride-row .r-stats { color: var(--ink-2); font-size: 13px; margin-top: 3px; font-variant-numeric: tabular-nums; }
.ride-row .r-load { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* Zones */
.zone-row { display: grid; grid-template-columns: 118px 1fr auto; gap: 8px; align-items: center; font-size: 12.5px; padding: 3px 0; }
.zone-row .z-name { color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.zone-row .z-name b { color: var(--ink); font-weight: 600; }
.zone-track { display: block; background: var(--wash); border-radius: 4px; height: 14px; position: relative; }
.zone-fill { display: block; background: var(--bar); border-radius: 4px; height: 100%; min-width: 2px; }
.zone-row .z-val { color: var(--ink-2); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Tables */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -14px; padding: 0 14px; }
table { border-collapse: collapse; width: 100%; font-size: 12.5px; font-variant-numeric: tabular-nums; }
th { text-align: right; color: var(--muted); font-weight: 500; font-size: 11px; padding: 4px 8px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
td { text-align: right; padding: 5px 8px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; padding-left: 0; }
tr:last-child td { border-bottom: none; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid var(--border); border-radius: 10px;
  font: 600 14px system-ui, -apple-system, "Segoe UI", sans-serif;
  padding: 11px 16px; cursor: pointer; text-decoration: none;
  background: var(--surface); color: var(--ink); width: 100%; min-height: 44px;
}
.btn.primary { background: var(--s-blue); border-color: transparent; color: #fff; }
.btn:active { filter: brightness(0.93); }
.btn svg { display: block; }
/* One button since the trace stopped being opt-in. */
.btn-row { display: grid; gap: 8px; grid-template-columns: 1fr; margin-top: 14px; }

/* Token gate */
.gate { max-width: 320px; margin: 18vh auto 0; text-align: center; }
.gate input {
  width: 100%; font-size: 16px; padding: 11px 12px; margin: 14px 0 10px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--ink);
}
.gate .err { color: var(--s-red); font-size: 13px; margin-top: 8px; }

.note { color: var(--muted); font-size: 12px; margin-top: 8px; }


/* Wind tile: head / cross / tail split of moving time */
.wind-split { display: flex; gap: 2px; height: 4px; border-radius: 2px; overflow: hidden; }
.wind-split i { display: block; min-width: 0; }
.wind-legend { display: flex; justify-content: space-between; font-size: 11px; color: var(--ink-2); margin-top: 4px; }
