/* Health — a quiet instrument panel.
   Layout: slim header (status + range) → one-line summary → four large vitals → a 12-column grid of
   compact cards. Any card opens a wide detail sheet with the full charts for that topic.
   Colour: neutral greys and one blue ramp; a single warm tone is reserved for warnings and peak effort. */
:root {
  color-scheme: light;
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-2: #f4f4f5;
  --ink: #111113;
  --ink-2: #55565c;
  --muted: #8b8c92;
  --line: #e9e9ec;
  --grid: #efeff1;
  --axis: #d4d4d8;
  --ghost: #cfd0d4;
  --a1: #e3edfb;
  --a2: #b5cff2;
  --a3: #74a6e8;
  --a4: #2a78d6;
  --a5: #1c5cab;
  --a6: #133f75;
  --warn: #c2551f;
  --good: #1f7a3d;
  --st-deep: var(--a5);
  --st-rem: var(--a3);
  --st-light: var(--a2);
  --st-awake: #d9d9dd;
  --lv-0: #e9e9ec;
  --lv-1: var(--a2);
  --lv-2: var(--a4);
  --lv-3: var(--a6);
  --z-0: #dcdce0;
  --z-1: var(--a3);
  --z-2: var(--a5);
  --z-3: var(--warn);
  --sleep-shade: var(--a2);
  --work-shade: #f3c9b3;
  --sit: #e4e4e7;
  --sit-long: #efb79b;
  --div-mid: #f1f1f3;
  --sp-0: var(--warn);
  --sp-1: var(--a1);
  --sp-2: var(--a2);
  --sp-3: var(--a3);
  --sp-4: var(--a5);
  /* gaurav.bar's faces: a grotesk for reading, monospace for numbers, labels and measurements */
  --font: "Helvetica Neue", Helvetica, Arial, "Liberation Sans", system-ui, sans-serif;
  --mono: "iA Writer Mono", "JetBrains Mono", "Berkeley Mono", "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  --r: 18px;
}
:root[data-scheme="dark"] {
  color-scheme: dark;
  --bg: #0b0b0d;
  --surface: #141417;
  --surface-2: #1b1b1f;
  --ink: #ececef;
  --ink-2: #a9aab0;
  --muted: #74757b;
  --line: #232328;
  --grid: #1d1d21;
  --axis: #34343a;
  --ghost: #3c3d43;
  --a1: #15233a;
  --a2: #1f3c66;
  --a3: #2f62a6;
  --a4: #4b8be0;
  --a5: #86b4ef;
  --a6: #c3daf7;
  --warn: #e07a45;
  --good: #45b46a;
  --st-awake: #46474d;
  --st-rem: var(--a4);
  --st-light: var(--a3);
  --lv-0: #26262b;
  --z-0: #2e2f34;
  --work-shade: #4a2c1d;
  --sit: #2a2a2f;
  --sit-long: #6b3a24;
  --div-mid: #1f1f23;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
body.locked { overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
:focus-visible { outline: 2px solid var(--a4); outline-offset: 2px; }

/* Header */
.top { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 86%, transparent); backdrop-filter: saturate(1.4) blur(12px); }
.top-in { max-width: 1240px; margin: 0 auto; padding: 16px max(20px, env(safe-area-inset-left)); display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.brand h1 { font-size: 17px; font-weight: 600; letter-spacing: -.01em; }
.status { font-size: 12.5px; color: var(--muted); display: inline-flex; align-items: center; gap: 7px; }
.status i { width: 6px; height: 6px; border-radius: 50%; background: var(--good); display: inline-block; }
.status i.running { background: var(--a4); animation: blink 1.2s ease-in-out infinite; }
.status i.error { background: var(--warn); }
@keyframes blink { 50% { opacity: .3; } }
@media (prefers-reduced-motion: reduce) { .status i.running { animation: none; } }
.range { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.seg { display: inline-flex; gap: 2px; background: var(--surface-2); border-radius: 999px; padding: 3px; }
.seg button { border: 0; background: none; border-radius: 999px; padding: 5px 12px; font-size: 13px; color: var(--ink-2); cursor: pointer; white-space: nowrap; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); font-weight: 560; }
.custom { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.custom input { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 4px 8px; font-size: 13px; }
.icon-btn { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 5px 12px; font-size: 13px; cursor: pointer; color: var(--ink-2); }
.icon-btn:hover { color: var(--ink); border-color: var(--axis); }
a.icon-btn { text-decoration: none; }
.icon-btn:disabled { opacity: .5; cursor: progress; }

/* Page */
main { max-width: 1240px; margin: 0 auto; padding: 8px max(20px, env(safe-area-inset-left)) 72px; display: flex; flex-direction: column; gap: 28px; }
.summary { font-size: clamp(19px, 2.2vw, 24px); line-height: 1.45; letter-spacing: -.012em; color: var(--ink-2); max-width: 62ch; text-wrap: pretty; padding-top: 18px; }
.summary b { color: var(--ink); font-weight: 560; }
.vitals { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.vital { text-align: left; border: 0; background: var(--surface); border-radius: var(--r); padding: 18px 20px 14px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; min-width: 0; transition: transform .15s ease, box-shadow .15s ease; }
.vital:hover, .card.open:hover { transform: translateY(-1px); box-shadow: 0 6px 24px rgba(0, 0, 0, .06); }
.vital .k { font-size: 13px; color: var(--muted); }
.vital .v { font-size: clamp(30px, 3.6vw, 42px); font-weight: 380; letter-spacing: -.035em; line-height: 1.12; font-variant-numeric: tabular-nums; }
.vital .v small { font-size: 15px; letter-spacing: 0; color: var(--muted); margin-left: 4px; font-weight: 400; }
.vital .c { font-size: 12.5px; color: var(--muted); min-height: 19px; }
.vital .spark { height: 36px; margin-top: 6px; }
.up { color: var(--good); } .dn { color: var(--warn); } .flat { color: var(--muted); }

.cards { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 12px; }
.card { grid-column: span 6; background: var(--surface); border-radius: var(--r); padding: 18px 20px; display: flex; flex-direction: column; gap: 10px; min-width: 0; position: relative; }
.card.s4 { grid-column: span 4; } .card.s12 { grid-column: span 12; }
.card.open { cursor: pointer; transition: transform .15s ease, box-shadow .15s ease; }
.card-h { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.card-h h2 { font-size: 14px; font-weight: 560; letter-spacing: -.005em; }
.card-h .more { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.card.open:hover .more { color: var(--a4); }
.figure { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.figure .n { font-size: 28px; font-weight: 400; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.figure .u { font-size: 13px; color: var(--muted); }
.note { font-size: 13px; color: var(--muted); line-height: 1.5; max-width: 75ch; }
.plot { width: 100%; min-width: 0; position: relative; }
.empty { display: flex; align-items: center; justify-content: center; min-height: 80px; color: var(--muted); font-size: 13px; text-align: center; padding: 14px; }
.finding { display: flex; gap: 12px; align-items: baseline; padding: 8px 0; border-top: 1px solid var(--line); }
.finding:first-of-type { border-top: 0; }
.finding .r { font-variant-numeric: tabular-nums; font-weight: 560; min-width: 52px; color: var(--a4); }
.finding span { font-size: 13.5px; color: var(--ink-2); }
.list-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 13.5px; }
.list-row:first-of-type { border-top: 0; }
.list-row .t { color: var(--ink); font-weight: 520; }
.list-row .m { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.bar-track { grid-column: 1 / -1; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; display: flex; gap: 1px; }
.bar-track i { display: block; height: 100%; }
.progress { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--a4); border-radius: 4px; }

/* Detail sheet */
.sheet { position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.sheet-bg { position: absolute; inset: 0; background: rgba(10, 10, 12, .38); backdrop-filter: blur(3px); animation: fade .18s ease; }
.sheet-panel { position: relative; width: min(1180px, 100%); height: min(94vh, 100%); background: var(--bg); border-radius: 22px 22px 0 0; display: flex; flex-direction: column; overflow: hidden; animation: rise .24s cubic-bezier(.2, .8, .2, 1); box-shadow: 0 -12px 48px rgba(0, 0, 0, .18); }
@media (min-width: 900px) { .sheet { align-items: center; } .sheet-panel { border-radius: 22px; height: 92vh; } }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .sheet-panel, .sheet-bg { animation: none; } }
.sheet-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; padding: 18px max(24px, env(safe-area-inset-left)) 12px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { font-size: 20px; font-weight: 600; letter-spacing: -.02em; }
.sheet-head .sub { font-size: 13px; color: var(--muted); }
.sheet-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.close { border: 0; background: var(--surface-2); width: 34px; height: 34px; border-radius: 50%; cursor: pointer; font-size: 18px; line-height: 1; color: var(--ink-2); }
.close:hover { color: var(--ink); }
.sheet-tabs { display: flex; gap: 4px; overflow-x: auto; padding: 8px max(20px, env(safe-area-inset-left)) 0; scrollbar-width: none; }
.sheet-tabs button { border: 0; background: none; padding: 8px 12px; border-radius: 10px; font-size: 13.5px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.sheet-tabs button[aria-current="true"] { color: var(--ink); background: var(--surface); font-weight: 560; }
/* Header and tabs keep their height; only the body scrolls (a tall view used to squash the tabs). */
.sheet-head, .sheet-tabs { flex: none; }
.sheet-body { flex: 1; min-height: 0; overflow-y: auto; padding: 18px max(24px, env(safe-area-inset-left)) 48px; display: flex; flex-direction: column; gap: 14px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.stat { background: var(--surface); border-radius: 14px; padding: 12px 14px; }
.stat .k { font-size: 12.5px; color: var(--muted); }
.stat .v { font-size: 22px; font-weight: 420; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .c { font-size: 12px; color: var(--muted); }
.panel { background: var(--surface); border-radius: var(--r); padding: 18px 20px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.panel h3 { font-size: 14px; font-weight: 560; }
.two { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 14px; }
.three { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: 14px; }
.callout { background: var(--surface-2); border-radius: 12px; padding: 10px 14px; font-size: 13.5px; color: var(--ink-2); }
.callout.warn { background: color-mix(in srgb, var(--warn) 10%, var(--surface)); color: var(--ink); }

/* Pickers, pills, legends */
.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pills button { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 4px 11px; font-size: 12.5px; color: var(--ink-2); cursor: pointer; }
.pills button[aria-pressed="true"] { border-color: var(--a4); color: var(--ink); background: var(--a1); }
.picker { display: inline-flex; gap: 6px; align-items: center; }
.picker select { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 5px 8px; font-size: 13px; }
.picker button { border: 1px solid var(--line); background: var(--surface); border-radius: 50%; width: 30px; height: 30px; cursor: pointer; }
.picker button:disabled { opacity: .35; cursor: default; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }
.legend i.line { height: 2px; width: 14px; border-radius: 1px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--muted); }
.chips b { color: var(--ink); font-weight: 560; font-variant-numeric: tabular-nums; }

/* SVG */
svg.chart { display: block; overflow: visible; }
svg.chart text { font-family: var(--mono); }
svg.chart { touch-action: pan-y; }
.tick { font-size: 11px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.tick.small { font-size: 10px; }
.val { font-size: 11px; fill: var(--ink-2); font-weight: 560; font-variant-numeric: tabular-nums; }
.lab { font-size: 12px; fill: var(--ink-2); }
.lab.strong { fill: var(--ink); font-weight: 600; }
.gl { stroke: var(--grid); stroke-width: 1; fill: none; }
.axis { stroke: var(--axis); stroke-width: 1; }
.ref { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 4; opacity: .7; }
.rule { stroke: var(--axis); stroke-width: 1; pointer-events: none; }
.line { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.hoverdot { fill: var(--surface); stroke-width: 2.5; pointer-events: none; }

/* Tooltip, tables, toast */
.tip { position: fixed; left: 0; top: 0; z-index: 60; pointer-events: none; opacity: 0; transition: opacity .1s; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px 11px; box-shadow: 0 8px 28px rgba(0, 0, 0, .14); font-size: 12.5px; min-width: 120px; max-width: 300px; }
.tip.on { opacity: 1; }
.tip-h { color: var(--muted); margin-bottom: 3px; }
.tip-r { display: flex; align-items: center; gap: 7px; font-variant-numeric: tabular-nums; }
.tip-r i { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
th { text-align: left; font-weight: 520; font-size: 12px; color: var(--muted); padding: 6px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.k { font-weight: 560; white-space: nowrap; }
td.w { color: var(--ink-2); min-width: 17rem; }
td.m { color: var(--muted); min-width: 8rem; }
td.sel, th.sel { background: var(--a1); color: var(--ink); }
code, pre { font-family: var(--mono); font-size: 12px; }
pre { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; overflow-x: auto; margin: 0; }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 70; background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 12px; font-size: 13px; opacity: 0; transform: translateY(8px); transition: all .2s; pointer-events: none; }
.toast.on { opacity: 1; transform: none; }
footer { max-width: 1240px; margin: 0 auto; padding: 0 max(20px, env(safe-area-inset-left)) 40px; color: var(--muted); font-size: 12px; }

@media (max-width: 980px) { .vitals { grid-template-columns: repeat(2, minmax(0, 1fr)); } .card, .card.s4 { grid-column: span 6; } }
@media (max-width: 640px) { .card, .card.s4, .card.s12 { grid-column: span 12; } .top-in { padding-top: 12px; } }

/* Insights */
.insight { border-radius: 14px; padding: 12px 14px; background: var(--surface-2); display: flex; flex-direction: column; gap: 4px; }
.insight.watch { background: color-mix(in srgb, var(--warn) 9%, var(--surface)); }
.insight.collecting { opacity: .75; }
.insight-h { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.insight-h b { font-size: 14px; font-weight: 580; }
.insight-h .area { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.insight-h .badge { margin-left: auto; font-size: 11.5px; color: var(--ink-2); background: var(--surface); border-radius: 999px; padding: 1px 8px; }
.insight.watch .badge { color: var(--warn); }
.insight.good .badge { color: var(--good); }
.insight .headline { font-size: 14px; color: var(--ink); line-height: 1.45; }
.insight .action { font-size: 13.5px; color: var(--a4); font-weight: 520; }
.insight-group { display: flex; flex-direction: column; gap: 8px; }
.insight-group h3 { font-size: 12.5px; color: var(--muted); font-weight: 560; text-transform: uppercase; letter-spacing: .05em; }

/* Passcode gate (website only), set like a page of gaurav.bar: a big lowercase heading, one line, a hairline field */
.gated .range > :not(#sync-now):not(#theme):not(a), .gated #sync-now { display: none; }
.gated .icon-btn { border: 0; background: none; padding: 4px 2px; font: 12px var(--mono); text-transform: lowercase; color: var(--muted); }
.gated .icon-btn:hover { color: var(--a4); }
.gated .brand h1 { font-weight: 700; letter-spacing: -.02em; text-transform: lowercase; }
.gated .status { font-family: var(--mono); text-transform: lowercase; }
.gate { grid-column: 1 / -1; max-width: 560px; margin: 10vh 0 18vh; display: flex; flex-direction: column; gap: 16px; }
.gate h2 { font-size: clamp(36px, 6.4vw, 56px); font-weight: 700; letter-spacing: -.035em; line-height: 1.02; color: var(--ink); }
.gate .prompt { font-family: var(--mono); font-size: .34em; font-weight: 400; color: var(--a4); vertical-align: .5em; margin-right: .32em; }
.gate-lede { font-size: 18px; line-height: 1.6; color: var(--ink-2); max-width: 44ch; }
.gate-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 10px 16px; margin-top: 8px; font: 13px var(--mono); }
.gate-row label { color: var(--muted); }
.gate input { width: 11ch; background: transparent; border: 0; border-bottom: 1px solid var(--axis); border-radius: 0; padding: 4px 2px; font: 20px var(--mono); letter-spacing: .4em; color: var(--ink); }
.gate input:focus { outline: none; border-bottom-color: var(--a4); }
.gate .go { background: none; border: 0; padding: 0; font: 13px var(--mono); color: var(--ink); cursor: pointer; }
.gate .go:hover { color: var(--a4); }
.gate-msg { min-height: 1.4em; font: 12px var(--mono); color: var(--muted); }
.gate-back { font: 12px var(--mono); color: var(--muted); text-decoration: none; }
.gate-back:hover { color: var(--a4); }

/* Numbers set in the monospace, as on gaurav.bar */
.vital .v, .figure .n, .stat .v, .chips b, .finding .r, .list-row .m, .tip-r, .status, .zoom-range, .zoom-stats b, .zoom-sel, table.splits td { font-family: var(--mono); letter-spacing: -.01em; }
.vital .v { font-weight: 400; letter-spacing: -.03em; }
.vital .v small, .figure .u { font-family: var(--font); }
.tip-h { font-family: var(--mono); font-size: 11.5px; }

/* Zoomable charts: a slim toolbar above, the selection's numbers below */
.zoom { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.zoom-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; font-size: 12px; color: var(--muted); }
.zoom-btns { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.zoom-btns button { border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); border-radius: 8px; min-width: 30px; height: 28px; padding: 0 9px; font: 13px var(--mono); cursor: pointer; }
.zoom-btns button:hover:not(:disabled) { color: var(--ink); border-color: var(--axis); }
.zoom-btns button:disabled { opacity: .35; cursor: default; }
.zoom-read:empty { display: none; }
.zoom-read { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); font-size: 12.5px; color: var(--muted); }
.zoom-sel { display: inline-flex; gap: 8px; align-items: baseline; color: var(--ink-2); }
.zoom-sel b { color: var(--ink); font-weight: 560; }
.zoom-stats { display: flex; flex-wrap: wrap; gap: 4px 14px; flex: 1; min-width: 220px; }
.zoom-stats b { color: var(--ink); font-weight: 520; }
.chart .brush { fill: var(--a4); fill-opacity: .12; stroke: var(--a4); stroke-opacity: .55; stroke-width: 1; pointer-events: none; }
.chart .ov { fill: transparent; cursor: crosshair; }
.chart .ov.brushable { cursor: col-resize; touch-action: pan-y; }
.chart .mark { fill: var(--surface); stroke: var(--ink); stroke-width: 1.5; pointer-events: none; }
.chart .mark-label { fill: var(--ink); font-size: 10.5px; pointer-events: none; }
.chart .unit { font-size: 10px; }

/* Maximise / minimise any titled panel */
.panel-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.max-btn { border: 0; background: none; color: var(--muted); width: 30px; height: 30px; border-radius: 8px; font-size: 15px; line-height: 1; cursor: pointer; flex: none; }
.max-btn:hover { color: var(--ink); background: var(--surface-2); }
.panel.max { position: fixed; inset: max(12px, 2vh) max(12px, 2vw); z-index: 30; overflow: auto; box-shadow: 0 0 0 100vmax rgba(10, 10, 12, .45), 0 24px 80px rgba(0, 0, 0, .3); }
.panel.max .max-btn { font-size: 20px; }

/* Per-kilometre splits */
table.splits td { white-space: nowrap; }
table.splits tr.best td { color: var(--ink); font-weight: 600; }

/* What the numbers below cover */
.scope { font-size: 13px; color: var(--muted); line-height: 1.5; max-width: 90ch; }
.scope b { color: var(--ink-2); font-weight: 560; }
