:root {
  color-scheme: light;
  --bg: #eef3f4;
  --surface: #ffffff;
  --surface-2: #f6f9fa;
  --ink: #15262e;
  --ink-2: #4c5e67;
  --muted: #6f828b;
  --line: #d3dde1;
  --accent: #0e6b66;
  --accent-ink: #ffffff;
  --accent-soft: #d7ecea;
  --good: #2e7d4f;
  --warn: #a8570f;
  --bad: #b3261e;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-faint: #9fb9da;
  --grid: #e3eaed;
  --radius-lg: 14px;
  --radius: 10px;
  --radius-sm: 6px;
  --nav-h: 64px;
  --font: "Barlow", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-num: "Barlow Semi Condensed", "Barlow", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d161a; --surface: #142127; --surface-2: #101b20;
    --ink: #e3ecef; --ink-2: #a9bac1; --muted: #8197a0; --line: #24363e;
    --accent: #45b8ae; --accent-ink: #062523; --accent-soft: #173a3a;
    --good: #5cc28a; --warn: #e3a35a; --bad: #f08a80;
    --series-1: #3987e5; --series-2: #d95926; --series-faint: #345a85; --grid: #1e2e35;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d161a; --surface: #142127; --surface-2: #101b20;
  --ink: #e3ecef; --ink-2: #a9bac1; --muted: #8197a0; --line: #24363e;
  --accent: #45b8ae; --accent-ink: #062523; --accent-soft: #173a3a;
  --good: #5cc28a; --warn: #e3a35a; --bad: #f08a80;
  --series-1: #3987e5; --series-2: #d95926; --series-faint: #345a85; --grid: #1e2e35;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--font-num); font-weight: 600; line-height: 1.15; margin: 0; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- layout ---------- */
.shell { min-height: 100dvh; }
.view { max-width: 980px; margin: 0 auto; padding: 20px 16px calc(var(--nav-h) + 32px + env(safe-area-inset-bottom)); outline: none; }
.nav {
  position: fixed; inset: auto 0 0 0; z-index: 20;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  display: flex; background: var(--surface); border-top: 1px solid var(--line);
}
.nav .brand { display: none; }
.nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: .75rem; font-weight: 500;
}
.nav svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav a.active { color: var(--accent); }
.nav a[data-route="log"] svg { background: var(--accent); color: var(--accent-ink); border-radius: 50%; padding: 3px; width: 30px; height: 30px; stroke-width: 2.4; }
.nav a[data-route="log"].active svg { box-shadow: 0 0 0 3px var(--accent-soft); }
@media (min-width: 900px) {
  .shell { display: grid; grid-template-columns: 200px 1fr; }
  .nav { position: sticky; top: 0; height: 100dvh; flex-direction: column; border-top: 0; border-right: 1px solid var(--line); padding: 20px 12px; gap: 4px; }
  .nav .brand { display: flex; align-items: center; gap: 10px; font: 600 1.25rem var(--font-num); padding: 0 10px 20px; }
  .nav .brand img { border-radius: 7px; }
  .nav a { flex: 0; flex-direction: row; justify-content: flex-start; gap: 12px; padding: 10px; border-radius: var(--radius); font-size: .95rem; }
  .nav a.active { background: var(--accent-soft); }
  .view { padding: 32px 32px 48px; }
}

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin: 2px 0 0; color: var(--muted); }
.stack > * + * { margin-top: 16px; }
.grid-2 { display: grid; gap: 16px; }
@media (min-width: 720px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 16px; }
.panel > h2 { margin-bottom: 12px; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 10px; }
.panel-head .sub { color: var(--muted); font-size: .85rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* ---------- scale readout (the hero) ---------- */
.readout {
  background: var(--accent); color: var(--accent-ink);
  border-radius: var(--radius-lg); padding: 18px 18px 14px; position: relative; overflow: hidden;
}
.readout .row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.readout .label { font-size: .9rem; opacity: .85; }
.readout .big { font: 700 clamp(3.6rem, 16vw, 5.5rem)/0.95 var(--font-num); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.readout .big small { font-size: .3em; font-weight: 600; letter-spacing: 0; margin-left: 4px; opacity: .85; }
.readout .deltas { display: grid; grid-template-columns: repeat(3, auto); gap: 4px 18px; margin-top: 12px; font-size: .9rem; }
.readout .deltas b { display: block; font: 600 1.2rem var(--font-num); font-variant-numeric: tabular-nums; }
.readout .spark { position: absolute; right: 16px; top: 44px; width: 45%; height: 64px; opacity: .35; pointer-events: none; }
.readout .cta { background: var(--accent-ink); color: var(--accent); }
.readout .goal { margin-top: 14px; }
.goal-track { height: 6px; border-radius: 3px; background: color-mix(in srgb, var(--accent-ink) 25%, transparent); overflow: hidden; }
.goal-track i { display: block; height: 100%; background: var(--accent-ink); border-radius: 3px; }
.goal-text { display: flex; justify-content: space-between; font-size: .8rem; margin-top: 4px; opacity: .9; }

.dials { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; }
@media (min-width: 720px) { .dials { grid-template-columns: repeat(6, 1fr); } }
.dial { background: var(--surface); padding: 10px 12px; }
.dial .k { font-size: .78rem; color: var(--muted); }
.dial .v { font: 600 1.45rem/1.15 var(--font-num); font-variant-numeric: tabular-nums; }
.dial .v small { font-size: .65em; color: var(--muted); font-weight: 500; margin-left: 2px; }
.dial .d { font-size: .78rem; font-variant-numeric: tabular-nums; }
.better { color: var(--good); } .worse { color: var(--warn); } .flat { color: var(--muted); }
.readout .better, .readout .worse, .readout .flat { color: inherit; }

/* today checklist */
.checks { display: grid; gap: 8px; grid-template-columns: 1fr 1fr; }
@media (min-width: 720px) { .checks { grid-template-columns: repeat(4, 1fr); } }
.check {
  display: flex; flex-direction: column; gap: 2px; text-decoration: none; color: inherit;
  border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; background: var(--surface-2); min-height: 74px;
}
.check .k { font-size: .8rem; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.check .v { font: 600 1.15rem var(--font-num); font-variant-numeric: tabular-nums; }
.check.done .k::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--good); }
.check.todo .k::before { content: ""; width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--muted); }
.check.todo .v { color: var(--accent); font-family: var(--font); font-size: .95rem; font-weight: 600; }

.macro { margin-top: 10px; }
.macro .top { display: flex; justify-content: space-between; font-size: .85rem; }
.bar { height: 8px; border-radius: 4px; background: var(--grid); overflow: hidden; margin-top: 3px; }
.bar i { display: block; height: 100%; background: var(--series-1); border-radius: 4px; }
.bar.over i { background: var(--warn); }

/* tables */
.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table { border-collapse: collapse; width: 100%; font-size: .88rem; font-variant-numeric: tabular-nums; }
th, td { text-align: right; padding: 7px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); }
th { color: var(--muted); font-weight: 500; font-size: .78rem; }
tbody tr:last-child td { border-bottom: 0; }
tr.link { cursor: pointer; }
tr.link:hover td { background: var(--surface-2); }

/* ---------- forms ---------- */
.log-tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 720px) { .log-tiles { grid-template-columns: repeat(3, 1fr); } }
.tile {
  display: flex; flex-direction: column; gap: 4px; align-items: flex-start; text-align: left;
  padding: 14px; border-radius: var(--radius-lg); border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); text-decoration: none; font: inherit; cursor: pointer; min-height: 96px;
}
.tile svg { width: 26px; height: 26px; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tile b { font: 600 1.05rem var(--font-num); }
.tile span { font-size: .8rem; color: var(--muted); }
.tile:hover { border-color: var(--accent); }

form.entry { display: grid; gap: 14px; }
.fields { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 720px) { .fields.wide { grid-template-columns: repeat(4, 1fr); } .fields.three { grid-template-columns: repeat(3, 1fr); } }
.fields .full { grid-column: 1 / -1; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: .82rem; color: var(--ink-2); font-weight: 500; }
label.f .u { color: var(--muted); font-weight: 400; }
input, select, textarea {
  font: 500 1rem var(--font); color: var(--ink); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 11px; width: 100%; min-height: 44px;
}
input[type="number"] { font-family: var(--font-num); font-size: 1.15rem; font-variant-numeric: tabular-nums; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { min-height: 70px; resize: vertical; }
.hint { font-size: .8rem; color: var(--muted); margin: 0; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
button, .btn {
  font: 600 .95rem var(--font); border-radius: var(--radius); border: 1px solid transparent; padding: 11px 16px; min-height: 44px;
  cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-ghost { background: transparent; color: var(--accent); padding: 8px 10px; min-height: 36px; }
.btn-danger { background: transparent; color: var(--bad); border-color: var(--line); }
button:disabled { opacity: .55; cursor: default; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { background: var(--surface); border: 1px solid var(--line); color: var(--ink-2); padding: 7px 12px; min-height: 36px; font-weight: 500; border-radius: 999px; }
.seg button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.scale5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.scale5 button { background: var(--surface-2); border: 1px solid var(--line); color: var(--ink); font-family: var(--font-num); font-size: 1.1rem; padding: 8px 0; }
.scale5 button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); text-decoration: none; font-size: .9rem; margin-bottom: 8px; }

.suggest { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.suggest button { justify-content: space-between; background: var(--surface); border: 0; border-bottom: 1px solid var(--line); border-radius: 0; color: var(--ink); font-weight: 500; text-align: left; }
.suggest button:last-child { border-bottom: 0; }
.suggest button span { color: var(--muted); font-size: .85rem; font-weight: 400; font-variant-numeric: tabular-nums; }

.list { display: flex; flex-direction: column; }
.item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item .t { font-weight: 500; }
.item .s { font-size: .82rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: .78rem; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2); }
.pill.good::before, .pill.warn::before, .pill.bad::before { content: ""; width: 7px; height: 7px; border-radius: 50%; }
.pill.good::before { background: var(--good); } .pill.warn::before { background: var(--warn); } .pill.bad::before { background: var(--bad); }

/* ---------- charts ---------- */
.chart-grid { display: grid; gap: 16px; }
@media (min-width: 720px) { .chart-grid { grid-template-columns: 1fr 1fr; } .chart-grid .wide { grid-column: 1 / -1; } }
.chart { position: relative; width: 100%; height: 190px; touch-action: pan-y; }
.chart.tall { height: 260px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .axis text { fill: var(--muted); font: 11px var(--font); font-variant-numeric: tabular-nums; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .tip {
  position: absolute; top: 0; pointer-events: none; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 6px 9px; font-size: .8rem; white-space: nowrap; box-shadow: 0 4px 14px rgba(13, 22, 26, .12);
  font-variant-numeric: tabular-nums; z-index: 2;
}
.chart .tip b { font-weight: 600; }
.chart .tip i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; }
.legend { display: flex; gap: 14px; font-size: .8rem; color: var(--ink-2); flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.legend i.dot { width: 8px; height: 8px; border-radius: 50%; }
.chart-empty { height: 120px; display: grid; place-items: center; color: var(--muted); font-size: .9rem; text-align: center; }

/* ---------- auth ---------- */
.auth { max-width: 380px; margin: 8vh auto 0; }
.auth .brand { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.auth .brand img { border-radius: 12px; }
.auth .brand h1 { font-size: 2rem; }

/* ---------- misc ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: var(--radius); font-size: .9rem;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (min-width: 900px) { .toast { bottom: 24px; } }
.sync-banner { position: sticky; top: 0; z-index: 30; background: var(--warn); color: #fff; text-align: center; padding: 6px 12px; font-size: .85rem; }
.sync-banner button { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.6); min-height: 28px; padding: 2px 10px; margin-left: 8px; font-size: .8rem; }
.loading { color: var(--muted); }
.empty { text-align: center; padding: 28px 16px; color: var(--muted); }
.empty .btn { margin-top: 10px; }
.note { font-size: .82rem; color: var(--muted); border-left: 3px solid var(--line); padding-left: 10px; margin: 0; }
details summary { cursor: pointer; color: var(--accent); font-weight: 500; }
.hidden { display: none !important; }

/* workout activity rows */
.act { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; background: var(--surface-2); }
.act input, .act select { background: var(--surface); }
.act-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.act-head .btn-ghost { min-height: 32px; padding: 4px 8px; color: var(--bad); }

/* the hidden attribute must win over display:flex on labels and buttons */
[hidden] { display: none !important; }

/* toggle switch */
.switch { position: relative; display: inline-flex; flex: none; width: 46px; height: 28px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; min-height: 0; }
.switch span[aria-hidden] { position: absolute; inset: 0; border-radius: 999px; background: var(--line); transition: background .15s; }
.switch span[aria-hidden]::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .15s; }
.switch input:checked + span[aria-hidden] { background: var(--accent); }
.switch input:checked + span[aria-hidden]::after { transform: translateX(18px); }
.switch input:focus-visible + span[aria-hidden] { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.dev-item { align-items: flex-start; gap: 14px; }
.dev-item .bm { margin-top: 8px; max-width: 360px; min-height: 38px; padding: 7px 10px; font-size: .9rem; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px 14px; max-height: 260px; overflow: auto; padding: 8px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); font-size: .9rem; }
.check-grid input { width: auto; min-height: 0; }
.opt-row, .opt-new { flex-wrap: wrap; gap: 8px; }
.opt-row input, .opt-new input { min-height: 38px; padding: 7px 10px; }
#admin-body .table-wrap td .btn-ghost { min-height: 32px; padding: 4px 6px; }
