:root {
  color-scheme: light;
  --page: #f6f6f3;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  /* HR zones 1..5: one ordinal blue ramp */
  --z1: #86b6ef; --z2: #5598e7; --z3: #2a78d6; --z4: #1c5cab; --z5: #104281;
  --good: #0ca30c; --good-ink: #006300;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --radius: 16px;
  --tabbar-h: 64px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #242422;
    --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781;
    --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5; --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
    --z1: #184f95; --z2: #256abf; --z3: #3987e5; --z4: #6da7ec; --z5: #9ec5f4;
    --good-ink: #0ca30c;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #242422;
  --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781;
  --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5; --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
  --z1: #184f95; --z2: #256abf; --z3: #3987e5; --z4: #6da7ec; --z5: #9ec5f4;
  --good-ink: #0ca30c;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); text-decoration: none; }
button, input, textarea, select { font: inherit; color: inherit; }

/* ---------- shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.topbar-title { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn { color: var(--ink-2); display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; }
.icon-btn:active { background: var(--surface-2); }

main {
  max-width: 720px; margin: 0 auto;
  padding: 4px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
  outline: none;
}
.loading, .empty { color: var(--muted); text-align: center; padding: 48px 16px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); font-size: 11px; font-weight: 600;
}
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.active { color: var(--accent); }

/* ---------- cards & layout ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin: 12px 0;
}
.card-title { font-size: 13px; font-weight: 700; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.04em; margin: 0 0 12px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.card-title .aside { text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--muted); }
.section-h { font-size: 18px; font-weight: 700; margin: 24px 0 4px; }
.sub { color: var(--ink-2); font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 12px; }
.row.between { justify-content: space-between; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
@media (max-width: 380px) { .grid-4 { grid-template-columns: 1fr 1fr; } }

/* ---------- stats ---------- */
.stat { min-width: 0; }
.stat-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat-value { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; white-space: nowrap; }
.stat-value .unit { font-size: 13px; font-weight: 600; color: var(--ink-2); margin-left: 2px; }
.stat-note { font-size: 12px; color: var(--ink-2); margin-top: 2px; }
.hero-num { font-size: 44px; font-weight: 800; letter-spacing: -0.03em; line-height: 1; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--ink-2); white-space: nowrap;
}
.badge .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.badge.good { color: var(--good-ink); background: color-mix(in srgb, var(--good) 14%, transparent); }
.badge.warning { color: var(--ink); background: color-mix(in srgb, var(--warning) 30%, transparent); }
.badge.serious { color: var(--ink); background: color-mix(in srgb, var(--serious) 28%, transparent); }
.badge.critical { color: var(--critical); background: color-mix(in srgb, var(--critical) 14%, transparent); }

.progress { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress > div { height: 100%; border-radius: 999px; background: var(--accent); }

/* zone bar */
.zones { display: flex; height: 12px; gap: 2px; border-radius: 4px; overflow: hidden; }
.zones > span { display: block; height: 100%; min-width: 0; }
.zones.thin { height: 6px; }
.z1 { background: var(--z1); } .z2 { background: var(--z2); } .z3 { background: var(--z3); } .z4 { background: var(--z4); } .z5 { background: var(--z5); }
.zone-legend { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 8px; font-size: 12px; color: var(--ink-2); }
.zone-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }

/* ---------- lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border-top: 1px solid var(--border);
  color: inherit;
}
.list-item:first-child { border-top: 0; }
.list-item .main { flex: 1; min-width: 0; }
.list-item .title { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .meta { font-size: 13px; color: var(--ink-2); }
.list-item .right { text-align: right; font-variant-numeric: tabular-nums; }
.chev { color: var(--muted); }

/* workout type chip */
.wtype {
  display: inline-block; font-size: 11px; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase;
  padding: 2px 7px; border-radius: 6px; background: var(--surface-2); color: var(--ink-2);
}

/* day cards in week view */
.day { padding: 12px 0; border-top: 1px solid var(--border); }
.day:first-of-type { border-top: 0; }
.day-h { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.day-h .d { font-weight: 700; }
.day.today .d { color: var(--accent); }
.planned { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; margin: 6px 0; }
.planned .ptitle { font-weight: 650; }
.planned .ptarget { font-size: 14px; color: var(--ink-2); margin-top: 2px; }
.planned details { margin-top: 6px; font-size: 14px; color: var(--ink-2); }
.planned summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 13px; }
.actual { display: flex; align-items: center; gap: 8px; padding: 8px 2px 2px; font-size: 14px; color: inherit; }
.actual .a-main { flex: 1; }

/* week nav */
.week-nav { display: flex; align-items: center; justify-content: space-between; margin: 8px 0; }
.week-nav button { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; width: 44px; height: 40px; font-size: 20px; cursor: pointer; }
.week-nav .label { font-weight: 700; }

/* coach text */
.prose { font-size: 15px; color: var(--ink); }
.prose p { margin: 0 0 8px; }
.prose ul { margin: 0 0 8px; padding-left: 20px; }
.prose h4 { margin: 12px 0 4px; font-size: 15px; }

/* tables */
table.t { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
table.t th { text-align: right; color: var(--muted); font-weight: 600; font-size: 12px; padding: 6px 4px; border-bottom: 1px solid var(--border); }
table.t td { text-align: right; padding: 7px 4px; border-bottom: 1px solid var(--border); }
table.t th:first-child, table.t td:first-child { text-align: left; }

/* charts */
.chart-box { position: relative; height: 200px; }
.chart-box.tall { height: 240px; }
.chart-note { font-size: 13px; color: var(--ink-2); margin-top: 8px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); margin-bottom: 8px; }
.legend i { display: inline-block; width: 12px; height: 3px; border-radius: 2px; margin-right: 5px; vertical-align: 3px; }

/* segmented control */
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; font-size: 13px; font-weight: 650; color: var(--ink-2); cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); }

/* forms */
.field { display: block; margin: 12px 0; }
.field > span { display: block; font-size: 13px; font-weight: 650; color: var(--ink-2); margin-bottom: 6px; }
input[type=text], input[type=email], input[type=password], input[type=date], select, textarea {
  width: 100%; padding: 12px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface-2); font-size: 16px;
}
textarea { min-height: 160px; resize: vertical; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 700; cursor: pointer;
  background: var(--accent); color: var(--accent-ink);
}
.btn.secondary { background: var(--surface-2); color: var(--ink); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.btn-row { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
pre.report {
  white-space: pre-wrap; word-break: break-word; font-size: 12.5px; line-height: 1.45;
  background: var(--surface-2); border-radius: 12px; padding: 12px; max-height: 360px; overflow: auto; margin: 0;
}

.banner { border-radius: 12px; padding: 10px 12px; font-size: 14px; margin: 8px 0; }
.banner.critical { background: color-mix(in srgb, var(--critical) 12%, transparent); }
.banner.info { background: var(--surface-2); color: var(--ink-2); }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  transform: translateX(-50%) translateY(20px); opacity: 0; transition: .2s;
  background: var(--ink); color: var(--page); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600;
  pointer-events: none; z-index: 20; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.login { max-width: 380px; margin: 10vh auto 0; }
.login .hero-num { font-size: 30px; margin-bottom: 4px; }
