/* health.dfive.us — mobile-first.
   Every decision here answers one question: can you read this at arm's length,
   mid-set, with chalk on your hands? Hence the large numerals, the 48px minimum
   tap target, and the dark default (a phone propped against a rack at 6am). */

:root {
  --bg: #0b0f14;
  --bg-raise: #131a23;
  --bg-raise-2: #1b2531;
  --line: #26333f;
  --ink: #eef4fa;
  --ink-2: #9fb0c0;
  --ink-3: #66788a;
  --accent: #38bdf8;
  --accent-ink: #04141f;
  --good: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 14px;
  --tap: 48px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
:root[data-theme="light"] {
  --bg: #f6f8fb; --bg-raise: #ffffff; --bg-raise-2: #eef2f7;
  --line: #dbe3ec; --ink: #0f1720; --ink-2: #51637a; --ink-3: #8496aa;
  --accent: #0284c7; --accent-ink: #ffffff;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* Any rule that sets `display` outranks the `hidden` ATTRIBUTE, which is how
   the bottom sheet (display:flex) and the sign-in button (display:inline-flex)
   both rendered while marked hidden. Every hide in this app is the attribute,
   so state it once here rather than remembering it per component. */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
/* Tabular numerals everywhere a weight or rep count appears: a column of
   loads that jitters as digits change is genuinely harder to scan. */
.num, .set-load, .set-reps, .stat-value, .presc { font-variant-numeric: tabular-nums; }

/* ── chrome ───────────────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 6px;
  padding: calc(var(--safe-t) + 10px) 12px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { flex: 1; font-size: 19px; }
.topbar-back, .topbar-menu {
  width: 40px; height: 40px; border: 0; border-radius: 10px;
  background: transparent; color: var(--ink-2); font-size: 24px; line-height: 1;
}
.topbar-back { font-size: 30px; }
.view { padding: 14px 12px calc(96px + var(--safe-b)); max-width: 720px; margin: 0 auto; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tab {
  border: 0; background: none; color: var(--ink-3);
  padding: 8px 2px 10px; font-size: 10.5px; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  min-height: var(--tap);
}
.tab span { font-size: 21px; line-height: 1; }
.tab.is-active { color: var(--accent); }

/* ── cards ────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-raise); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin-bottom: 12px;
}
.card-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 10px; }
.card-head h2 { font-size: 16px; flex: 1; }
.card-sub { color: var(--ink-2); font-size: 13px; }
.muted { color: var(--ink-2); }
.dim { color: var(--ink-3); }
.tiny { font-size: 12px; }

.hero { text-align: left; }
.hero .eyebrow { color: var(--accent); font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .08em; }
.hero h2 { font-size: 25px; margin: 4px 0 2px; line-height: 1.2; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat { background: var(--bg-raise-2); border-radius: 11px; padding: 9px 8px; text-align: center; }
.stat-value { font-size: 19px; font-weight: 700; }
.stat-label { font-size: 10px; color: var(--ink-3); text-transform: uppercase;
  letter-spacing: .05em; margin-top: 1px; }

/* ── buttons ──────────────────────────────────────────────────────────── */
.btn {
  min-height: var(--tap); padding: 0 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg-raise-2); color: var(--ink);
  font-weight: 620; font-size: 15px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
}
.btn:active { transform: scale(.985); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--bad); }
.btn-block { display: flex; width: 100%; }
.btn-row { display: flex; gap: 8px; }
.btn-row > .btn { flex: 1; }
.btn:disabled { opacity: .45; }

/* ── option grids (mode / focus / program pickers) ───────────────────── */
.grid { display: grid; gap: 8px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.opt {
  text-align: left; padding: 12px; border-radius: 12px; min-height: var(--tap);
  border: 1.5px solid var(--line); background: var(--bg-raise-2); color: var(--ink);
}
.opt strong { display: block; font-size: 14.5px; }
.opt small { display: block; color: var(--ink-3); font-size: 11.5px; margin-top: 3px; line-height: 1.35; }
.opt[aria-pressed="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--bg-raise-2)); }
.opt:disabled { opacity: .35; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 8px 12px; border-radius: 999px; font-size: 13px; font-weight: 600;
  border: 1.5px solid var(--line); background: var(--bg-raise-2); color: var(--ink-2);
  min-height: 38px;
}
.chip[aria-pressed="true"] { border-color: var(--accent); color: var(--ink);
  background: color-mix(in srgb, var(--accent) 16%, transparent); }

/* ── the workout card: the screen that matters ────────────────────────── */
.block { margin-bottom: 14px; }
.block-head {
  display: flex; align-items: baseline; gap: 8px;
  padding: 0 2px 8px;
}
.block-head h2 { font-size: 17px; }
.block-tag {
  font-size: 10.5px; font-weight: 800; letter-spacing: .07em; text-transform: uppercase;
  color: var(--accent-ink); background: var(--accent); padding: 3px 7px; border-radius: 6px;
}
.block-note { color: var(--ink-2); font-size: 13px; padding: 0 2px 10px; }

.mv { background: var(--bg-raise); border: 1px solid var(--line);
  border-radius: var(--radius); margin-bottom: 9px; overflow: hidden; }
.mv-head { display: flex; align-items: center; gap: 10px; padding: 12px 13px; }
.mv-name { flex: 1; font-size: 17px; font-weight: 650; }
/* The prescription is the single most-read string in the app. */
.presc { font-size: 15px; font-weight: 700; color: var(--accent); white-space: nowrap; }
.mv-sub { padding: 0 13px 11px; color: var(--ink-2); font-size: 12.5px; }
.mv-plates { padding: 0 13px 11px; color: var(--ink-3); font-size: 12px; }
.pattern-dot { width: 9px; height: 9px; border-radius: 3px; flex: none; }

/* set rows — the tap targets */
.sets { border-top: 1px solid var(--line); }
.set {
  display: grid; grid-template-columns: 34px 1fr 1fr var(--tap);
  align-items: center; gap: 8px;
  padding: 7px 13px 7px 10px; border-bottom: 1px solid var(--line);
  min-height: var(--tap);
}
.set:last-child { border-bottom: 0; }
.set.is-warmup { opacity: .62; }
.set.is-done { background: color-mix(in srgb, var(--good) 11%, transparent); }
.set-idx { color: var(--ink-3); font-size: 12px; font-weight: 700; }
.set-field { display: flex; align-items: baseline; gap: 4px; }
.set-input {
  width: 100%; min-height: 42px; padding: 6px 8px; text-align: right;
  border: 1px solid var(--line); border-radius: 9px; background: var(--bg-raise-2);
  font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}
.set-input::-webkit-outer-spin-button,
.set-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.set-unit { font-size: 11px; color: var(--ink-3); font-weight: 700; width: 20px; }
.set-check {
  width: var(--tap); height: 42px; border-radius: 10px; border: 1.5px solid var(--line);
  background: var(--bg-raise-2); color: var(--ink-3); font-size: 20px;
}
.set-check[aria-pressed="true"] { background: var(--good); border-color: transparent; color: #04241a; }
.amrap-flag { color: var(--warn); font-weight: 800; font-size: 11px; }

.finishbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  padding: 10px 12px calc(10px + var(--safe-b));
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: blur(12px); border-top: 1px solid var(--line);
}
.finishbar .btn { width: 100%; }
.progress-line { height: 4px; border-radius: 2px; background: var(--bg-raise-2); margin-bottom: 9px; }
.progress-line > div { height: 100%; border-radius: 2px; background: var(--good); transition: width .2s; }

/* ── forms ────────────────────────────────────────────────────────────── */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12.5px; font-weight: 700; color: var(--ink-2);
  margin-bottom: 5px; }
.input, select.input, textarea.input {
  width: 100%; min-height: var(--tap); padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 11px;
  background: var(--bg-raise-2); font-size: 16px; /* 16px stops iOS zoom-on-focus */
}
textarea.input { min-height: 84px; resize: vertical; }
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper .btn { width: var(--tap); flex: none; font-size: 22px; padding: 0; }
.stepper .input { text-align: center; font-weight: 700; font-size: 19px; }
.row { display: flex; gap: 8px; align-items: flex-end; }
.row > * { flex: 1; }

/* ── charts (inline SVG) ──────────────────────────────────────────────── */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { fill: var(--ink-3); font-size: 9px; }
.chart .bar { fill: var(--accent); }
.chart .bar-dim { fill: var(--bg-raise-2); }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2;
  stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--accent); }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }

.matrix { display: grid; grid-template-columns: 1fr auto auto auto; gap: 0 10px;
  align-items: center; font-size: 13.5px; }
.matrix > * { padding: 7px 0; border-bottom: 1px solid var(--line); }
.matrix .hdr { font-size: 10px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--ink-3); font-weight: 700; }
.matrix .hit { color: var(--good); font-weight: 700; }
.matrix .miss { color: var(--ink-3); }

.heat { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 1fr);
  gap: 3px; overflow-x: auto; padding-bottom: 4px; }
.heat i { width: 12px; height: 12px; border-radius: 3px; background: var(--bg-raise-2); display: block; }
.heat i[data-n="1"] { background: color-mix(in srgb, var(--good) 55%, transparent); }
.heat i[data-n="2"] { background: var(--good); }

.legend { display: flex; flex-wrap: wrap; gap: 8px 14px; font-size: 12px; color: var(--ink-2); }
.legend i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; margin-right: 5px; }

/* ── list rows ────────────────────────────────────────────────────────── */
.list { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  background: var(--bg-raise); }
.item {
  display: flex; align-items: center; gap: 11px; width: 100%;
  padding: 13px; min-height: var(--tap); border: 0; border-bottom: 1px solid var(--line);
  background: none; text-align: left;
}
.item:last-child { border-bottom: 0; }
.item-main { flex: 1; min-width: 0; }
.item-title { font-weight: 620; font-size: 15px; }
.item-sub { color: var(--ink-3); font-size: 12.5px; margin-top: 1px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-right { color: var(--ink-3); font-size: 12.5px; text-align: right; flex: none; }

/* ── sheet / toast / boot ─────────────────────────────────────────────── */
.sheet { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; }
.sheet-scrim { position: absolute; inset: 0; background: rgba(0,0,0,.55); }
.sheet-body {
  position: relative; width: 100%; max-height: 88vh; overflow-y: auto;
  background: var(--bg-raise); border-radius: 20px 20px 0 0;
  padding: 8px 14px calc(20px + var(--safe-b));
  border-top: 1px solid var(--line);
  animation: rise .2s ease-out;
}
@keyframes rise { from { transform: translateY(18px); opacity: .6 } }
.sheet-grip { width: 38px; height: 4px; border-radius: 2px; background: var(--line);
  margin: 6px auto 12px; }

.toast {
  position: fixed; left: 50%; bottom: calc(78px + var(--safe-b)); transform: translateX(-50%);
  z-index: 70; background: var(--bg-raise-2); border: 1px solid var(--line);
  color: var(--ink); padding: 11px 16px; border-radius: 12px; font-size: 14px;
  font-weight: 600; max-width: 90vw; box-shadow: 0 8px 28px rgba(0,0,0,.4);
}
.toast.is-bad { border-color: var(--bad); color: var(--bad); }

.boot { min-height: 100dvh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px; padding: 24px; text-align: center; }
.boot-mark { font-size: 46px; }
.boot p { color: var(--ink-2); margin: 0; }
.boot-err { color: var(--bad) !important; font-size: 13px; max-width: 34ch; }

.empty { text-align: center; padding: 34px 18px; color: var(--ink-3); }
.empty .big { font-size: 34px; display: block; margin-bottom: 8px; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
