/* ============ Fonts ============ */
/* Archivo (SIL OFL 1.1, see fonts/OFL.txt): one variable family with weight 100-900 and width 62-125%.
   Latin subset from Google Fonts. Glyphs outside it (▲ ✓ ✕ ◐ …) fall back to the system font. */
@font-face { font-family: "Archivo"; src: url("fonts/archivo-roman.woff2") format("woff2"); font-style: normal; font-weight: 100 900; font-stretch: 62% 125%; font-display: swap; }
@font-face { font-family: "Archivo"; src: url("fonts/archivo-italic.woff2") format("woff2"); font-style: italic; font-weight: 100 900; font-stretch: 62% 125%; font-display: swap; }

/* ============ Theme: "bumper plates" ============
   Colors come from Olympic bumper plates (red 25, blue 20, yellow 15, green 10, white 5).
   Naming: --accent, --green, --red, --gold are safe as TEXT on any surface of the theme.
   The -fill variants are the bright plate colors for backgrounds; text on them is always --ink.
   Contrast measured: text 4.5:1 or better on --bg, --bg-2 and --bg-3; ink 5.5:1 or better on every fill. */
:root, :root[data-theme="dark"] {
  --bg: #101833;      /* platform navy */
  --bg-2: #1A2349;    /* cards */
  --bg-3: #232D5A;    /* inputs, chips, raised */
  --line: #2C3766;
  --line-2: #34407A;  /* empty plate slots, dashed outlines */
  --text: #F3F5FF;    /* chalk */
  --text-2: #A7B0D8;
  --text-3: #9199C9;
  --ink: #101833;     /* text on every bright fill, both themes */
  /* Plates: fills, and the variant to use when the plate color is text */
  --p-red: #FF5263;    --p-red-t: #FF6B7A;
  --p-blue: #5B8CFF;   --p-blue-t: #7DA3FF;
  --p-yellow: #FFC83D; --p-yellow-t: #FFC83D;
  --p-green: #2BD488;  --p-green-t: #2BD488;
  --p-white: #F3F5FF;  --on-p-white: #101833; /* the white 5 kg plate; an ink "training plate" in light */
  /* Accent (user scheme, default plate yellow) */
  --accent: #FFC83D;
  --accent-fill: #FFC83D;
  /* Tint behind accent text (ghost buttons, badges): a raised surface with a hint of accent. Mixed into --bg-3,
     not into transparency, so the yellow never blends with the navy underneath into olive. */
  --accent-soft: color-mix(in srgb, var(--accent) 8%, var(--bg-3));
  --green: var(--p-green-t);  --green-fill: var(--p-green);
  --red: var(--p-red-t);      --red-fill: var(--p-red);
  --gold: var(--p-yellow-t);  --gold-fill: var(--p-yellow);
  --on-accent: var(--ink); --on-green: var(--ink); --on-red: var(--ink);
  /* Type: one family, three widths */
  --font: "Archivo", -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  --wide: 122%;   /* display: titles, big numbers, timer, primary buttons (black italic) */
  --semi: 112%;   /* section headings */
  --narrow: 88%;  /* dense numbers: set inputs, previous column, tab labels */
  /* Shape: bigger containers get bigger corners */
  --r-xl: 28px;   /* sheets */
  --r-lg: 22px;   /* cards, tiles, rest bar */
  --r-md: 14px;   /* buttons in rows, inputs, set rows */
  --r-sm: 10px;   /* small badges */
  --r-pill: 999px;
  --shadow: 0 10px 30px rgba(4, 8, 24, .5);
  --mark: var(--accent); /* non-text marks: level bar, slider thumb, tab stripe, avatar ring */
  --btn-stretch: 115%; /* primary button labels: between --semi and --wide */
  /* Surfaces: cards need no outline on navy; white cards on chalk do (set in light) */
  --card-line: transparent;
  --scrim: rgba(6, 10, 26, .6); /* behind sheets */
}
:root[data-theme="light"] {
  --bg: #F1F3FA;      /* chalk */
  --bg-2: #FFFFFF;
  --bg-3: #E8EBF5;
  --line: #DDE1EE;
  --line-2: #C5CBE0;
  --text: #101833;
  --text-2: #464E72;
  --text-3: #5E668A;
  --p-red-t: #C8243A;
  --p-blue-t: #2457D6;
  --p-yellow-t: #8A6100;
  --p-green-t: #12784A;
  --p-white: #101833; --on-p-white: #F3F5FF;
  --accent: #835d11; /* scheme text colors are tuned to 4.5:1 on white, --bg and --accent-soft (4.6:1 or better) */
  --accent-soft: color-mix(in srgb, var(--accent) 6%, var(--bg-3));
  --shadow: 0 10px 30px rgba(16, 24, 51, .12);
  --mark: var(--accent-fill); /* on white the bright plate reads better than its deep text shade */
  --card-line: var(--line);
  --scrim: rgba(16, 24, 51, .45);
}

/* Color schemes. --accent-fill is the same bright color in both themes (ink text on it);
   --accent is the text color: the fill itself in dark, a deeper shade in light. */
:root[data-scheme="ocean"] { --accent-fill: #5B8CFF; --accent: #7DA3FF; }
:root[data-theme="light"][data-scheme="ocean"] { --accent: #285fc3; }
:root[data-scheme="ember"] { --accent-fill: #FF7A50; --accent: #FF7A50; }
:root[data-theme="light"][data-scheme="ember"] { --accent: #a84323; }
:root[data-scheme="forest"] { --accent-fill: #3ECF8E; --accent: #3ECF8E; }
:root[data-theme="light"][data-scheme="forest"] { --accent: #147245; }
:root[data-scheme="violet"] { --accent-fill: #B59CFF; --accent: #B59CFF; }
:root[data-theme="light"][data-scheme="violet"] { --accent: #6c50be; }
:root[data-scheme="rose"] { --accent-fill: #FF7A90; --accent: #FF7A90; }
:root[data-theme="light"][data-scheme="rose"] { --accent: #af394a; }
:root[data-scheme="gold"] { --accent-fill: #FFC83D; --accent: #FFC83D; }
/* Yellow has no readable deep shade (it turns brown), so in light the gold scheme writes in ink
   and keeps the yellow for fills and marks. */
:root[data-theme="light"][data-scheme="gold"] { --accent: #101833; }
:root[data-scheme="aqua"] { --accent-fill: #22D3EE; --accent: #22D3EE; }
:root[data-theme="light"][data-scheme="aqua"] { --accent: #066d85; }
:root[data-scheme="indigo"] { --accent-fill: #8F98FF; --accent: #A3AAFF; }
:root[data-theme="light"][data-scheme="indigo"] { --accent: #4f46e5; }
:root[data-scheme="magenta"] { --accent-fill: #EC84FA; --accent: #EC84FA; }
:root[data-theme="light"][data-scheme="magenta"] { --accent: #a520b5; }
:root[data-scheme="mint"] { --accent-fill: #5EEAD4; --accent: #5EEAD4; }
:root[data-theme="light"][data-scheme="mint"] { --accent: #0a7067; }
:root[data-scheme="lime"] { --accent-fill: #A3E635; --accent: #A3E635; }
:root[data-theme="light"][data-scheme="lime"] { --accent: #456f09; }
:root[data-scheme="copper"] { --accent-fill: #E8A066; --accent: #E8A066; }
:root[data-theme="light"][data-scheme="copper"] { --accent: #965216; }

/* Training families (famOf() in core/state.js): push red, pull blue, legs yellow, core green.
   --fam is the fill, --fam-t the same color when used as text. */
.fam-push { --fam: var(--p-red); --fam-t: var(--p-red-t); }
.fam-pull { --fam: var(--p-blue); --fam-t: var(--p-blue-t); }
.fam-legs { --fam: var(--p-yellow); --fam-t: var(--p-yellow-t); }
.fam-core { --fam: var(--p-green); --fam-t: var(--p-green-t); }
.fam-other { --fam: var(--text-3); --fam-t: var(--text-2); }
/* Text or icon drawn ON a --fam fill. Ink on the plates; the neutral "other" fill is mid-grey in
   light, where ink would drop to 3:1, so it takes the page color instead (5:1 or better both themes). */
.fam-push, .fam-pull, .fam-legs, .fam-core { --on-fam: var(--ink); }
.fam-other { --on-fam: var(--bg); }

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}
/* No visible scrollbars anywhere: the app scrolls like a native screen. */
* { scrollbar-width: none; }
*::-webkit-scrollbar { display: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
/* Keyboard focus: one visible ring. Text fields set outline: none further down and show focus with their own border. */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Type roles (one family, Archivo):
   display  = italic 900, var(--wide): page titles, big numbers, rest timer, sheet titles (800)
   heading  = upright 800, var(--semi), sentence case: card and section titles
   body/UI  = normal width 400-700; dense numbers (set inputs, Previous, tab labels) use var(--narrow)
   No all-caps labels: text reads as written. */

/* Text size preference: the whole UI is scaled, so spacing and tap targets grow with the text.
   "Large" only kicks in where the scaled layout still has 320px or more to work with. */
:root[data-text="small"] { zoom: .92; }
@media (min-width: 360px) { :root[data-text="large"] { zoom: 1.1; } }
@media (min-width: 420px) { :root[data-text="large"] { zoom: 1.16; } } /* 420 / 1.16 = 362: still a full-size layout */

#app { max-width: 560px; margin: 0 auto; min-height: 100%; padding-top: env(safe-area-inset-top); }

/* ============ Views & tab bar ============ */
.view { display: none; padding: 18px 16px calc(96px + env(safe-area-inset-bottom)); animation: fadein .15s ease; }
.view.active { display: block; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

#tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  display: flex; justify-content: space-around;
  max-width: 560px; margin: 0 auto;
  background: color-mix(in srgb, var(--bg-2) 92%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  padding: 8px 4px calc(8px + env(safe-area-inset-bottom));
}
#tabbar button {
  position: relative;
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--text-3); font-size: 11px; font-weight: 600; font-stretch: var(--narrow); padding: 2px 0;
}
#tabbar button .ti {
  width: 23px; height: 23px; fill: none; stroke: currentColor;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
#tabbar button.active { color: var(--accent); }
#tabbar button.active span { font-weight: 800; }
#tabbar button.active .ti { stroke-width: 2.2; }
/* Active tab: a short slanted stripe above the icon, like a painted lane mark */
#tabbar button.active::before {
  content: ""; position: absolute; top: -7px; left: 50%; width: 22px; height: 4px; margin-left: -11px;
  border-radius: 1px; background: var(--mark); transform: skewX(-20deg);
}

/* ============ Profile ============ */
.avatar-btn {
  width: 44px; height: 44px; border-radius: 50%; background: var(--bg-3);
  border: 0; font-size: 20px; display: inline-flex;
  align-items: center; justify-content: center; line-height: 1;
}
.avatar-big {
  width: 84px; height: 84px; border-radius: 50%; background: var(--accent-soft);
  border: 3px solid var(--mark); font-size: 44px; display: flex;
  align-items: center; justify-content: center; margin: 4px auto 16px; line-height: 1;
}
.avatar-btn, .avatar-big { overflow: hidden; padding: 0; flex-shrink: 0; }
.avatar-img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; display: block; }
.emoji-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin-bottom: 14px; }
.emoji-grid button {
  aspect-ratio: 1; border-radius: var(--r-md); background: var(--bg-3); border: 2px solid transparent;
  font-size: 24px; display: flex; align-items: center; justify-content: center; line-height: 1;
  transition: transform .08s;
}
.emoji-grid button:active { transform: scale(.92); }
.emoji-grid button.on { border-color: var(--accent); background: var(--accent-soft); }

.lvl-bar {
  height: 8px; border-radius: var(--r-pill); background: var(--bg-3);
  margin-top: 14px; overflow: hidden;
}
.lvl-bar .fill { height: 100%; border-radius: var(--r-pill); background: var(--mark); transition: width .3s ease; }

/* ============ Training heatmap ============ */
/* A calendar of plates: a busier day gets a BIGGER plate, never a paler one (accent blended into navy
   turned olive). Each cell draws a centred disc, so the tap area stays the same size at every level. */
.hm {
  display: grid; grid-auto-flow: column;
  grid-template-rows: repeat(7, 1fr); gap: 3px;
}
.hm-cell {
  aspect-ratio: 1; border-radius: 50%; --hm-c: var(--line-2); --hm-r: 34%;
  background: radial-gradient(circle closest-side, var(--hm-c) 0 var(--hm-r), transparent calc(var(--hm-r) + 2%));
}
.row .hm-cell { width: 12px; height: 12px; aspect-ratio: auto; flex-shrink: 0; }
.hm-cell.future { background: none; }
.hm-cell.lvl0 { --hm-c: var(--line-2); --hm-r: 34%; }
.hm-cell.lvl1 { --hm-c: var(--hm-1); --hm-r: 50%; }
.hm-cell.lvl2 { --hm-c: var(--hm-2); --hm-r: 66%; }
.hm-cell.lvl3 { --hm-c: var(--hm-3); --hm-r: 82%; }
.hm-cell.lvl4 { --hm-c: var(--hm-4); --hm-r: 100%; }
/* A fuller day is a bigger disc AND a deeper color: pale -> the accent -> deep. Mixed with white and
   black, never with the navy background. Yellow cannot darken without turning olive, so the default
   gold scheme gets a hand-tuned heat ramp that warms toward amber instead. */
:root {
  --hm-1: color-mix(in oklab, var(--accent-fill) 45%, #fff);
  --hm-2: color-mix(in oklab, var(--accent-fill) 75%, #fff);
  --hm-3: var(--accent-fill);
  --hm-4: color-mix(in oklab, var(--accent-fill) 78%, #000);
}
:root[data-theme="light"] { --hm-1: color-mix(in oklab, var(--accent-fill) 62%, #fff); } /* pale on white needs more color */
:root[data-scheme="gold"] { --hm-1: #FFE7A3; --hm-2: #FFD45E; --hm-3: #FFB224; --hm-4: #F08400; }
:root[data-theme="light"][data-scheme="gold"] { --hm-1: #FFDA75; }
/* All-time sheet: month label + 7 day columns, one row per week */
.hm-full { display: grid; grid-template-columns: 40px repeat(7, minmax(0, 1fr)); gap: 4px; align-items: center; max-width: 400px; margin: 0 auto; }
.hm-full .hm-cell { width: 100%; height: auto; aspect-ratio: 1; }
.hm-full .mo, .hm-full .dow { font-size: 11px; font-weight: 600; color: var(--text-3); white-space: nowrap; }
.hm-full .dow { text-align: center; margin-bottom: 2px; }

/* Levels sheet */
.info-btn {
  display: inline-flex; align-items: center; justify-content: center; vertical-align: middle;
  width: 18px; height: 18px; margin-left: 4px; border-radius: 50%;
  border: 1.5px solid var(--text-3); color: var(--text-3);
  font-size: 11px; font-weight: 800; font-family: var(--font); font-style: italic; line-height: 1;
}
.lvl-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); color: var(--text-3); }
.lvl-row:last-child { border-bottom: 0; }
.lvl-row .n { width: 24px; height: 24px; border-radius: 50%; background: var(--bg-3); font-size: 12px; font-weight: 800; font-style: italic; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.lvl-row b { flex: 1; font-size: 15px; }
.lvl-row .at, .lvl-row .mark { font-size: 12.5px; font-variant-numeric: tabular-nums; }
.lvl-row .mark { min-width: 76px; text-align: right; } /* wide enough for a bold "you are here", so the counts line up */
.lvl-row.done { color: var(--text); }
.lvl-row.done .n { background: var(--accent-soft); color: var(--accent); }
.lvl-row.done .mark { color: var(--accent); font-weight: 700; }
.lvl-row.cur .n { background: var(--accent-fill); color: var(--on-accent); }
.lvl-row.cur b { color: var(--accent); }

/* ============ Top of Home ============ */
/* Under the greeting: date and weather as small pills, then one line with the fact of the day.
   The pill look is the inner span (30px); a tappable pill's button keeps a 40px tap area around it. */
.home-top { margin: -8px 0 16px; }
.top-pills { display: flex; flex-wrap: wrap; align-items: center; gap: 0 8px; }
.top-pill { display: inline-flex; align-items: center; min-height: 40px; padding: 0; border: 0; background: none; color: var(--text-2); }
.top-pill > span {
  display: inline-flex; align-items: center; gap: 5px; height: 30px; padding: 0 12px; white-space: nowrap;
  border-radius: var(--r-pill); background: var(--bg-2); border: 1px solid var(--card-line);
  font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums;
}
button.top-pill > span { transition: transform .08s ease; }
button.top-pill:active > span { transform: scale(.96); }
.top-pill.act > span { color: var(--accent); }
.top-pill.wait > span { color: var(--text-3); }
.top-fact { margin-top: 4px; font-size: 13.5px; line-height: 1.45; color: var(--text-2); max-width: 62ch; }
/* Weather sheet */
.wx-now { display: flex; align-items: center; gap: 16px; }
.wx-now b { display: block; font-size: 17px; font-weight: 800; font-stretch: var(--semi); }
.wx-big { font-style: italic; font-weight: 900; font-stretch: var(--wide); font-size: 34px; line-height: 1; white-space: nowrap; }

/* ============ Quote of the day ============ */
.quote-card {
  padding: 2px 2px;
  margin: 0 0 18px;
}
.quote-card p {
  font-size: 15px; line-height: 1.5; font-style: italic; color: var(--text-2);
}
.quote-card span {
  display: block; margin-top: 6px; font-size: 13px; font-weight: 700; color: var(--accent);
}

/* ============ Goals ============ */
.goal-row { display: flex; align-items: center; gap: 11px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.goal-row:last-child { border-bottom: 0; }
.goal-check {
  width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid var(--text-3); color: var(--on-green); font-size: 14px; font-weight: 800;
  display: flex; align-items: center; justify-content: center; transition: background .12s, border-color .12s, transform .08s;
}
.goal-check, .info-btn { position: relative; }
.goal-check::after { content: ""; position: absolute; inset: -10px; } /* 26px ring, 46px touch area */
.info-btn::after { content: ""; position: absolute; inset: -13px; }
.goal-check:active { transform: scale(.88); }
.goal-row.done .goal-check { background: var(--green-fill); border-color: var(--green-fill); color: var(--ink); }
.goal-text { flex: 1; font-size: 15px; min-width: 0; overflow-wrap: break-word; }
.goal-row.done .goal-text { color: var(--text-3); text-decoration: line-through; }
.goal-del { color: var(--text-3); font-size: 14px; flex-shrink: 0; width: 40px; height: 40px; margin: -7px -10px -7px 0; display: flex; align-items: center; justify-content: center; }

/* ============ Notes & review ============ */
.ex-note {
  width: 100%; background: var(--bg-3); border: 1px solid transparent; border-radius: var(--r-md);
  padding: 10px 12px; font: inherit; font-size: 14px; color: var(--text);
  resize: none; min-height: 58px; outline: none; margin: 2px 0 10px; display: block;
}
.ex-note:focus { border-color: var(--accent); }
.pencil { color: var(--text-3); font-size: 17px; padding: 4px 8px; }
.pencil.has-note { color: var(--accent); }
/* Safari ignores accent-color for the empty part of the track and drew it near-white in dark mode. */
input[type="range"] { width: 100%; height: 32px; margin: 4px 0 0; background: transparent; -webkit-appearance: none; appearance: none; }
input[type="range"]::-webkit-slider-runnable-track { height: 8px; border-radius: 4px; background: var(--bg-3); border: 1px solid var(--line); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 26px; height: 26px; margin-top: -10px; border-radius: 50%; background: var(--mark); border: 3px solid var(--bg-2); box-shadow: 0 0 0 1px var(--line-2), 0 1px 4px rgba(0,0,0,.35); }
input[type="range"]::-moz-range-track { height: 8px; border-radius: 4px; background: var(--bg-3); border: 1px solid var(--line); }
input[type="range"]::-moz-range-thumb { width: 22px; height: 22px; border-radius: 50%; background: var(--mark); border: 3px solid var(--bg-2); }
/* Workout summary and review cards (were inline styles; the 359px block tightens them) */
.wk-summary .card { margin-bottom: 14px; }
.card.rev-card { padding: 14px; margin-bottom: 14px; }
.rev-badge {
  display: inline-block; color: var(--accent); background: var(--accent-soft); font-weight: 700;
  border-radius: var(--r-pill); padding: 1px 8px; font-variant-numeric: tabular-nums;
}

/* ============ Common bits ============ */
.page-h {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 18px;
}
.page-h h1 {
  font-size: 30px; font-weight: 900; font-style: italic; font-stretch: var(--wide);
  letter-spacing: -.01em; line-height: 1.05; min-width: 0; overflow-wrap: break-word;
}
.icon-btn {
  width: 44px; height: 44px; border-radius: var(--r-md); background: var(--bg-3);
  border: 0; font-size: 17px; display: inline-flex;
  align-items: center; justify-content: center; color: var(--text-2);
}
/* Cards are flat surfaces: no shadow, no outline on navy (--card-line is transparent in dark). */
.card {
  background: var(--bg-2); border: 1px solid var(--card-line);
  border-radius: var(--r-lg); padding: 16px; margin-bottom: 12px;
}
/* Inside a sheet (itself --bg-2) a card is an inset panel on the page color. */
.sheet .card { background: var(--bg); }
/* Section headings: inside a card (.card h3), or standing alone between blocks (.sec-h). */
.card h3, .sec-h {
  font-size: 17px; font-weight: 800; font-stretch: var(--semi); letter-spacing: 0;
  color: var(--text); line-height: 1.25; margin-bottom: 10px;
}
.sec-h { margin: 6px 0 8px; }
.row > .sec-h { margin: 0; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
/* Archivo's own "normal" leading is about 1.08, which makes running text read as a block. */
p { line-height: 1.45; }
/* Primary button: an accent pill with an italic display label. */
.btn {
  display: block; width: 100%; text-align: center; padding: 15px 20px; min-height: 50px;
  border-radius: var(--r-pill); font-size: 16px; line-height: 20px;
  font-weight: 800; font-style: italic; font-stretch: var(--btn-stretch); letter-spacing: 0;
  background: var(--accent-fill); color: var(--on-accent); transition: transform .08s ease, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; }
/* A see-through yellow pill turned olive on navy: a disabled primary button goes flat and muted instead. */
.btn:not(.ghost, .subtle, .danger, .google):disabled { opacity: 1; background: var(--bg-3); color: var(--text-3); }
.btn.ghost, .btn.subtle, .btn.danger, .btn.google { font-style: normal; font-weight: 700; font-stretch: 100%; }
.btn.ghost { background: var(--accent-soft); color: var(--accent); }
.btn.subtle { background: var(--bg-3); color: var(--text-2); }
.btn.danger { background: transparent; color: var(--red); }
.btn.sm { min-height: 40px; padding: 10px 16px; font-size: 14px; width: auto; display: inline-block; border-radius: var(--r-pill); white-space: nowrap; }
.btn.google { background: #fff; color: #1f1f1f; border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; gap: 10px; }
:root[data-theme="dark"] .btn.google { background: #131314; color: #e3e3e3; border-color: #3a3a3c; }
.g-logo { width: 18px; height: 18px; flex: none; }
.auth-or { display: flex; align-items: center; gap: 10px; margin: 14px 0; color: var(--text-3); font-size: 12px; }
.auth-or::before, .auth-or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.row { display: flex; align-items: center; gap: 10px; }
.spread { justify-content: space-between; }
.empty {
  text-align: center; color: var(--text-3); padding: 36px 20px; font-size: 14px; line-height: 1.5;
}
.empty .big { font-size: 34px; display: block; margin-bottom: 8px; }

/* Full-page empty states (History / Workout) center vertically so short tabs
   don't leave an awkward void above the tab bar. */
#view-history.active, #view-workout.active {
  display: flex; flex-direction: column;
  min-height: calc(100dvh - env(safe-area-inset-top));
}
#view-history > .empty, #view-workout > .empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
}

/* ============ Dashboard ============ */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.stat {
  background: var(--bg-2); border: 1px solid var(--card-line); border-radius: var(--r-lg); padding: 14px;
}
/* .stat-lite: the same figures without the tile, for use inside a card (Progress: streak, level). */
.stat .lab, .stat-lite .lab { font-size: 12px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.stat-lite .lab { margin-bottom: 4px; }
.stat .val, .stat-lite .val {
  font-size: 25px; font-weight: 900; font-style: italic; font-stretch: var(--wide);
  letter-spacing: -.01em; line-height: 1.1; font-variant-numeric: tabular-nums;
}
.stat-lite .val { font-size: 24px; }
.stat .val small, .stat-lite .val small {
  font-size: 12.5px; font-weight: 700; font-style: normal; font-stretch: 100%; letter-spacing: 0; color: var(--text-2);
}
.stat .sub, .stat-lite .sub { font-size: 12px; color: var(--text-3); margin-top: 4px; }
.stat-lite .sub { font-size: 13px; }
.stat .sub.up { color: var(--green); }
.stat .sub.down { color: var(--red); }
/* Home tiles wear a fixed plate color each (the tile id is the class). Everything on a plate is ink:
   the green/red trend colors would fail contrast there, so the ▲▼ arrows carry the meaning. */
.stat.t-bodyweight { --tile: var(--p-yellow); }
.stat.t-workoutsWeek { --tile: var(--p-blue); }
.stat.t-volumeWeek { --tile: var(--p-red); }
.stat.t-setsWeek { --tile: var(--p-green); }
.stat.t-streak { --tile: var(--p-red); }
.stat.t-timeWeek { --tile: var(--p-white); --on-tile: var(--on-p-white); } /* white 5 kg plate in dark, ink training plate in light */
.stat.t-bodyweight, .stat.t-workoutsWeek, .stat.t-volumeWeek, .stat.t-setsWeek, .stat.t-streak, .stat.t-timeWeek {
  background: var(--tile); border-color: transparent; color: var(--on-tile, var(--ink));
}
:is(.t-bodyweight, .t-workoutsWeek, .t-volumeWeek, .t-setsWeek, .t-streak, .t-timeWeek) :is(.lab, .val, .val small, .sub, .sub.up, .sub.down) {
  color: var(--on-tile, var(--ink));
}
:is(.t-bodyweight, .t-workoutsWeek, .t-volumeWeek, .t-setsWeek, .t-streak, .t-timeWeek) .lab { font-weight: 700; }
:is(.t-bodyweight, .t-workoutsWeek, .t-volumeWeek, .t-setsWeek, .t-streak, .t-timeWeek) .sub { font-weight: 600; }
/* The sleep tile keeps a neutral surface: its stage bar has colors of its own. */
.stat.t-sleep { background: var(--bg-2); }
.pr-line { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.pr-line:last-child { border-bottom: 0; }
.pr-line .medal { font-size: 18px; }
.pr-line .what { flex: 1; min-width: 0; }
.pr-line .what b { display: block; font-size: 15px; font-weight: 700; }
.pr-line .what span { font-size: 12px; color: var(--text-2); }
.pr-line .when { font-size: 12px; color: var(--text-3); white-space: nowrap; }

/* ============ Workout tab / routines ============ */
.routine {
  background: var(--bg-2); border: 1px solid var(--card-line); border-radius: var(--r-lg);
  padding: 14px 16px; margin-bottom: 10px; display: flex; align-items: center; gap: 12px;
}
.routine .info { flex: 1; min-width: 0; }
.routine .info b { font-size: 17px; font-weight: 800; font-stretch: var(--semi); display: block; margin-bottom: 2px; }
.routine .info span { font-size: 13px; color: var(--text-2); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.routine .go {
  background: var(--accent-soft); color: var(--accent); font-weight: 800; font-size: 14px;
  padding: 10px 18px; border-radius: var(--r-pill); flex-shrink: 0; min-height: 40px;
}

/* ============ History ============ */
.session {
  background: var(--bg-2); border: 1px solid var(--card-line); border-radius: var(--r-lg);
  padding: 14px 16px; margin-bottom: 10px; width: 100%; text-align: left; display: block;
}
.session .top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 4px; }
.session .top b { font-size: 17px; font-weight: 800; font-stretch: var(--semi); }
.session .top time { font-size: 12px; color: var(--text-3); white-space: nowrap; }
.month-h { font-size: 16px; font-weight: 800; font-stretch: var(--semi); color: var(--text-2); letter-spacing: 0; margin: 20px 2px 8px; }
.page-h + .month-h { margin-top: 4px; }
.session .meta { font-size: 13px; color: var(--text-2); margin-bottom: 8px; display: flex; align-items: center; gap: 14px; font-variant-numeric: tabular-nums; }
.session .ex-line { font-size: 13.5px; color: var(--text-2); padding: 2px 0; display: flex; justify-content: space-between; gap: 8px; }
.session .ex-line .best { color: var(--text-3); white-space: nowrap; font-variant-numeric: tabular-nums; }
.badge-pr {
  display: inline-block; vertical-align: 1px;
  font-size: 11px; font-weight: 800; font-style: normal; color: var(--ink);
  background: var(--gold-fill);
  font-stretch: 100%; border-radius: var(--r-pill); padding: 2px 8px;
}

/* ============ Exercise library ============ */
.search {
  width: 100%; background: var(--bg-3); border: 1px solid transparent; border-radius: var(--r-pill);
  padding: 12px 18px; font-size: 15px; margin-bottom: 14px; outline: none;
}
.search::placeholder { color: var(--text-3); }
.search:focus { border-color: var(--accent); }
/* Muscle group heading with a dot in its family color */
.muscle-h {
  display: flex; align-items: center; gap: 8px;
  font-size: 16px; font-weight: 800; font-stretch: var(--semi); color: var(--text); letter-spacing: 0; margin: 20px 0 6px;
}
.muscle-h::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--fam, var(--accent)); flex-shrink: 0; }
.ex-item {
  width: 100%; text-align: left; display: flex; align-items: center; gap: 12px;
  padding: 11px 4px; border-bottom: 1px solid var(--line);
}
/* The exercise "plate": family color with an ink abbreviation */
.ex-item .dot {
  width: 38px; height: 38px; border-radius: 50%; background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 12px; font-stretch: var(--narrow); flex-shrink: 0;
}
.ex-item .dot[class*="fam-"] { background: var(--fam); color: var(--on-fam, var(--ink)); }
.ex-item .dot { text-transform: capitalize; }
.ex-item .nm { flex: 1; min-width: 0; }
.ex-item .nm b { display: block; font-size: 15px; font-weight: 700; }
.ex-item .nm span { font-size: 12px; color: var(--text-3); }
.ex-item .sel { color: var(--accent); font-size: 18px; font-weight: 800; width: 22px; text-align: center; }

/* ============ Active workout ============ */
#active-overlay {
  position: fixed; inset: 0; z-index: 50; background: var(--bg);
  overflow-y: auto; max-width: 560px; margin: 0 auto;
}
.aw-head {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
  padding: 12px 16px calc(10px); padding-top: calc(12px + env(safe-area-inset-top));
}
.aw-head .r1 { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 44px; }
.aw-title {
  background: none; border: 0; outline: none; font-size: 22px; font-weight: 900; font-style: italic;
  font-stretch: var(--wide); letter-spacing: -.01em; color: var(--text); width: 100%; min-width: 0; padding: 2px 0;
}
.aw-title:focus { box-shadow: inset 0 -2px 0 var(--accent); }
.aw-finish {
  background: var(--green-fill); color: var(--on-green); padding: 11px 20px; min-height: 44px;
  border-radius: var(--r-pill); font-size: 15px; font-weight: 800; font-style: italic; font-stretch: var(--btn-stretch);
  flex-shrink: 0; transition: transform .08s ease;
}
.aw-finish:active { transform: scale(.96); }
/* Fixed line height: the toast in a workout sits right under this header, at a top set in px (see #toast). */
.aw-stats { display: flex; gap: 18px; margin-top: 6px; font-size: 13px; line-height: 16px; white-space: nowrap; font-weight: 600; color: var(--text-2); font-variant-numeric: tabular-nums; }

/* Loading bar: the workout as a barbell. One plate slot per set in exercise order, a solid muted plate
   while pending, the exercise's family color once done; the plate just ticked drops on.
   .mini is the read-only strip on routine cards, history cards and the summary sheet.
   updateLoadBar() (workout.js) changes the plates in place while typing, so keep this markup flat. */
.aw-load {
  display: flex; align-items: center; gap: 3px; height: 26px; margin: 10px 0 4px;
  overflow-x: clip; /* a very long workout loses plates off the end instead of widening the page */
}
.aw-load::before, .aw-load::after { content: ""; height: 6px; border-radius: 3px; background: var(--line-2); }
.aw-load::before { flex: 0 0 14px; }   /* sleeve stub */
.aw-load::after { flex: 1 1 0; }       /* the bar running on */
.plate { display: block; flex: 0 1 8px; min-width: 3px; height: 24px; border-radius: 3px; background: var(--line-2); }
.plate.on { background: var(--fam, var(--accent-fill)); }
.plate.on.drop { transform-origin: 50% 100%; animation: plate-drop .38s cubic-bezier(.3, 1.45, .55, 1) both; }
.aw-load.mini { height: 14px; gap: 2px; margin: 9px 0 6px; }
.aw-load.mini::before, .aw-load.mini::after { content: none; }
.aw-load.mini .plate { flex: 0 1 5px; min-width: 2px; height: 14px; border-radius: 2px; }

.aw-body { padding: 14px 16px calc(130px + env(safe-area-inset-bottom)); }

.aw-ex { margin-bottom: 24px; }
.aw-ex .exh { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
/* Exercise name in its family color, after a small plate ring */
.aw-ex .exh b {
  display: flex; align-items: center; gap: 9px; min-width: 0;
  color: var(--fam-t, var(--accent)); font-size: 18px; line-height: 1.2;
  font-weight: 800; font-style: italic; font-stretch: var(--btn-stretch);
}
.aw-ex .exh b::before {
  content: ""; flex: 0 0 14px; width: 14px; height: 14px; border-radius: 50%;
  border: 4px solid var(--fam, var(--accent-fill));
}
.aw-ex .exh .row { flex-shrink: 0; gap: 4px; }
.aw-ex .exh .opts { color: var(--text-3); font-size: 18px; min-width: 40px; min-height: 40px; }
.aw-ex .exh .chip { min-height: 34px; }

.set-grid-h, .set-row .grid {
  display: grid; grid-template-columns: 40px 1fr 76px 64px 44px; gap: 8px; align-items: center;
}
/* "Show previous" off: the column goes and the two inputs share the room */
.aw-ex.no-prev .set-grid-h, .aw-ex.no-prev .set-row .grid { grid-template-columns: 40px 1fr 1fr 44px; }
.aw-ex.no-prev .set-grid-h > :nth-child(2), .aw-ex.no-prev .set-row .prev { display: none; }
.set-grid-h {
  font-size: 12px; font-weight: 600; font-stretch: var(--narrow); color: var(--text-3);
  letter-spacing: 0; padding: 4px 2px; text-align: center;
}
.set-grid-h :first-child { text-align: left; padding-left: 6px; }
.set-row { position: relative; overflow: hidden; border-radius: var(--r-md); margin-bottom: 4px; }
/* The grid stays opaque: it covers the red Delete button until it is swiped aside. */
.set-row .grid {
  position: relative; z-index: 1; background: var(--bg); padding: 5px 2px;
  transition: transform .15s ease, background .15s ease; border-radius: var(--r-md);
  touch-action: pan-y; font-stretch: var(--narrow);
}
.set-row.done .grid { background: color-mix(in srgb, var(--green-fill) 12%, var(--bg)); } /* done = green, as on Finish and habits */
/* Set number: a small round plate; with effort on it is a tappable pill that also shows the RIR dot */
.set-row .snum {
  display: flex; align-items: center; justify-content: center; gap: 4px;
  width: 32px; height: 32px; margin-left: 2px; padding: 0; border-radius: 50%;
  box-shadow: inset 0 0 0 1.5px var(--line-2); color: var(--text-2);
  font-size: 15px; font-weight: 900; font-style: italic; font-variant-numeric: tabular-nums;
}
.set-row.done .snum:not(.eff) { color: var(--green); box-shadow: inset 0 0 0 1.5px var(--green-fill); }
.set-row .snum.eff { width: auto; min-width: 36px; height: 40px; margin-left: 0; padding: 0 5px; border-radius: var(--r-pill); background: var(--bg-3); box-shadow: none; }
.set-row .snum.eff:active { transform: scale(.94); }
.set-row.done .snum.eff { background: color-mix(in srgb, var(--bg-3) 70%, transparent); }
.set-row .prev { display: flex; align-items: center; justify-content: center; gap: 5px; }
.set-row .snum { position: relative; }
/* Corner badge, out of the flow: number + trophy + effort dot in a row needed
   ~50px and the column is 40, which pushed the number out and cut the dot. */
.set-row .snum .pr { position: absolute; top: -3px; right: -6px; font-size: 11px; font-style: normal; line-height: 1; pointer-events: none; }
.set-row .prev { font-size: 13px; font-weight: 600; color: var(--text-3); text-align: center; white-space: nowrap; overflow: hidden; font-variant-numeric: tabular-nums; }
.set-row input {
  width: 100%; background: var(--bg-3); border: 0; border-radius: var(--r-md);
  text-align: center; padding: 11px 4px; font-size: 17px; line-height: 20px; font-weight: 700; font-stretch: var(--narrow); outline: none;
  font-variant-numeric: tabular-nums;
}
.set-row input::placeholder { color: var(--text-3); }
.set-row.done input { background: transparent; }
.set-row.done .prev { color: var(--text-2); } /* --text-3 on the tinted row dipped under 4.5:1 */
.opts { min-width: 40px; min-height: 40px; }
.set-row input:focus { box-shadow: 0 0 0 2px var(--accent); }
.set-check {
  width: 40px; height: 40px; margin: 0 auto; border-radius: 12px;
  background: var(--bg-3); color: var(--text-3); font-size: 17px; font-weight: 800;
  display: flex; align-items: center; justify-content: center; transition: background .12s, color .12s, transform .08s;
}
.set-check:active { transform: scale(.92); }
.set-row.done .set-check { background: var(--green-fill); color: var(--on-green); }
.set-del {
  position: absolute; top: 0; right: 0; bottom: 0; width: 84px; z-index: 0;
  background: var(--red-fill); color: var(--on-red); font-weight: 800; font-size: 14px;
  display: flex; align-items: center; justify-content: center; border-radius: 0 var(--r-md) var(--r-md) 0;
  visibility: hidden; /* its red bled around the row's rounded corners as a hairline */
}
.set-row:has(.grid[style*="translateX"]) .set-del { visibility: visible; }
.add-set {
  width: 100%; min-height: 44px; padding: 10px; border-radius: var(--r-pill); background: transparent;
  border: 1.5px dashed var(--line-2); color: var(--text-2); font-weight: 700; font-size: 14px; margin-top: 4px;
}

/* ============ Routine editor ============ */
.rt-ex { margin-bottom: 18px; }
.rt-ex .exh { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.rt-ex .exh .nm { min-width: 0; }
.rt-ex .exh b {
  display: block; color: var(--fam-t, var(--accent)); font-size: 17px; font-weight: 800; font-style: italic; font-stretch: var(--btn-stretch);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rt-ex .exh span { font-size: 12px; color: var(--text-3); }
.rt-ex .exh .opts { color: var(--text-3); font-size: 15px; min-width: 40px; min-height: 40px; margin-right: -10px; flex-shrink: 0; }
.rt-grid { display: grid; grid-template-columns: 34px minmax(0, 1fr) minmax(0, 1fr) 36px; gap: 8px; align-items: center; font-stretch: var(--narrow); }
.rt-h {
  font-size: 12px; font-weight: 600; color: var(--text-3);
  letter-spacing: 0; padding: 4px 2px; text-align: center;
}
.rt-h :first-child { text-align: left; padding-left: 10px; }
.rt-set { padding: 3px 2px; }
.rt-set .snum { font-weight: 900; font-style: italic; color: var(--text-2); font-size: 15px; padding-left: 10px; font-variant-numeric: tabular-nums; }
.rt-set input {
  width: 100%; min-width: 0; background: var(--bg-3); border: 0; border-radius: var(--r-md);
  text-align: center; padding: 11px 4px; font-size: 16px; line-height: 20px; font-weight: 700; font-stretch: var(--narrow); outline: none;
  font-variant-numeric: tabular-nums;
}
.rt-set input:focus { box-shadow: 0 0 0 2px var(--accent); }
.rt-set input::placeholder { color: var(--text-3); font-weight: 500; }
.rt-del {
  width: 36px; height: 36px; margin: 0 auto; border-radius: 50%; background: var(--bg-3);
  color: var(--text-3); font-size: 18px; font-weight: 800; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.rt-del:active { background: var(--red-fill); color: var(--on-red); }

/* ============ Effort (reps in reserve) ============ */
.rir-4 { --rc: var(--green); }
.rir-3 { --rc: color-mix(in srgb, var(--green) 50%, var(--gold)); }
.rir-2 { --rc: var(--gold); }
.rir-1 { --rc: color-mix(in srgb, var(--gold) 40%, var(--red)); }
.rir-0 { --rc: var(--red); }
.rir-dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; background: var(--rc, var(--text-3)); flex-shrink: 0; box-shadow: 0 0 0 2px color-mix(in srgb, var(--rc, var(--text-3)) 25%, transparent); }
/* Hollow ring = effort not logged yet. A dashed border on an 11px circle drew as a broken "C". */
.rir-dot.unset { background: transparent; border: 1.5px solid var(--text-3); box-shadow: none; }
.rir-opt {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 11px 14px; border-radius: var(--r-md); background: var(--bg-3); margin-bottom: 8px; border: 2px solid transparent;
}
.rir-opt .rir-dot { width: 12px; height: 12px; }
.rir-opt .tx b { display: block; font-size: 15px; }
.rir-opt.on { border-color: var(--rc); }
.rir-tag { font-size: 11px; font-weight: 800; color: color-mix(in srgb, var(--rc) 60%, var(--text)); background: color-mix(in srgb, var(--rc) 14%, transparent); padding: 1px 7px; border-radius: var(--r-pill); align-self: center; }

/* ============ Settings hub ============ */
.settings-id { display: flex; align-items: center; gap: 14px; margin: 2px 0 16px; }
.settings-id b { display: block; font-size: 18px; font-weight: 800; font-stretch: var(--semi); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.settings-list { border: 1px solid var(--card-line); border-radius: var(--r-lg); overflow: hidden; background: var(--bg-2); }
.sheet .settings-list { background: var(--bg); }
.settings-row { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 13px 14px; border-bottom: 1px solid var(--line); }
.settings-row:last-child { border-bottom: 0; }
.settings-row:active { background: var(--bg-3); }
.settings-row .ic { width: 34px; height: 34px; border-radius: var(--r-sm); background: var(--bg-3); display: flex; align-items: center; justify-content: center; font-size: 17px; flex-shrink: 0; }
.settings-row .tx { flex: 1; min-width: 0; }
.settings-row .tx b { display: block; font-size: 15px; font-weight: 700; }
.settings-row .tx span { font-size: 12.5px; color: var(--text-3); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.settings-row .chev { color: var(--text-3); font-size: 20px; }
.field label.toggle-row, .toggle-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 0; margin: 0;
  border-bottom: 1px solid var(--line); cursor: pointer; font-size: 15px; font-weight: 400; color: var(--text);
}
.field label.toggle-row:last-child, .toggle-row:last-child { border-bottom: 0; }
.toggle-row b { display: block; font-size: 15px; font-weight: 700; }
.toggle-row > span { min-width: 0; }
.field .toggle-row input, .toggle-row input {
  appearance: none; -webkit-appearance: none; width: 46px; height: 28px; border-radius: var(--r-pill); padding: 0; border: 0;
  background: var(--line-2); position: relative; flex-shrink: 0; transition: background .15s; margin: 0;
}
.field .toggle-row input:focus { border: 0; }
.toggle-row input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.toggle-row input::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .15s;
}
.toggle-row input:checked { background: var(--accent-fill); }
.toggle-row input:checked::after { transform: translateX(18px); }
/* Home screen preferences: a toggle plus up/down arrows per card */
.home-card-row { display: flex; align-items: center; gap: 6px; border-bottom: 1px solid var(--line); }
.home-card-row:last-child { border-bottom: 0; }
.field .home-card-row label.toggle-row { flex: 1; min-width: 0; border-bottom: 0; }
.home-card-row.off b { color: var(--text-3); }
.home-card-row .mv { width: 44px; height: 44px; flex-shrink: 0; border-radius: var(--r-md); background: var(--bg-3); color: var(--text-2); font-size: 13px; }
.home-card-row .mv:disabled { opacity: .3; }
.scheme-row { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 9px 4px; border-bottom: 1px solid var(--line); }
.scheme-row:last-child { border-bottom: 0; }
.scheme-row .sw { width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0; }
.scheme-row b { flex: 1; font-size: 15px; font-weight: 700; }
.scheme-row .ck { color: var(--accent); font-weight: 800; visibility: hidden; }
.scheme-row.on .ck { visibility: visible; }
/* Home-screen icon picker: each tile is the real 192px PNG, rounded like the OS does */
.icon-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.icon-grid button { aspect-ratio: 1; padding: 0; border-radius: 16px; border: 2px solid var(--line); background: var(--bg-3); overflow: hidden; transition: transform .08s, border-color .12s; }
.icon-grid button img { display: block; width: 100%; height: 100%; border-radius: 14px; }
.icon-grid button:active { transform: scale(.94); }
.icon-grid button.on { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ============ Rest timer bar ============ */
/* The accent capsule: ink on the bright accent fill. The ink overlay (.fill) is the time left. */
#rest-bar {
  position: fixed; left: 12px; right: 12px; z-index: 60;
  bottom: calc(12px + env(safe-area-inset-bottom)); /* .aw-body's bottom padding lets the last buttons scroll clear of it */
  max-width: 536px; margin: 0 auto;
  background: var(--accent-fill); color: var(--ink); border: 0; border-radius: var(--r-lg);
  box-shadow: var(--shadow); overflow: hidden;
}
#rest-bar .fill {
  position: absolute; inset: 0; background: rgba(16, 24, 51, .12); transform-origin: left;
  /* The timer sets a new width twice a second; gliding to each one makes the bar
     drain continuously. Slightly longer than the 500ms tick, so the next target
     arrives before the glide ends and the bar never pauses. */
  transition: transform .6s linear; will-change: transform;
}
@media (prefers-reduced-motion: reduce) { #rest-bar .fill { transition: none; } }
#rest-bar .inner {
  position: relative; display: flex; align-items: center; gap: 8px; padding: 9px 14px;
}
#rest-bar .t {
  font-size: 26px; font-weight: 900; font-style: italic; font-stretch: var(--wide); letter-spacing: -.01em;
  line-height: 1.1; font-variant-numeric: tabular-nums; min-width: 74px;
}
#rest-bar .lab { flex: 1; min-width: 0; font-size: 12px; font-weight: 500; color: var(--ink); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
/* Pale pills rather than darker ones: ink text keeps 5:1 or better on every scheme's fill (the blue
   "ocean" fill is the darkest, and an ink tint under the ink overlay took it below 4:1). */
#rest-bar button {
  flex-shrink: 0; background: rgba(255, 255, 255, .3); color: var(--ink); border: 0; border-radius: var(--r-pill);
  min-height: 40px; min-width: 44px; padding: 10px 12px; font-weight: 800; font-size: 13px; line-height: 20px; font-variant-numeric: tabular-nums;
}
#rest-bar .skip { background: var(--ink); color: var(--accent-fill); }

/* ============ Modals ============ */
#modal-root .overlay {
  position: fixed; inset: 0; z-index: 70; background: var(--scrim);
  display: flex; align-items: flex-end; justify-content: center; animation: fadein .12s;
}
.sheet {
  background: var(--bg-2); width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto; overflow-x: hidden;
  border-radius: var(--r-xl) var(--r-xl) 0 0; padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  animation: sheetup .2s cubic-bezier(.2, .9, .3, 1);
}
.sheet::before { content: ""; display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--line-2); margin: 0 auto 12px; }
@keyframes sheetup { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
.sheet-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.sheet-h b {
  font-size: 20px; font-weight: 800; font-style: italic; font-stretch: var(--wide); letter-spacing: -.01em;
  line-height: 1.15; min-width: 0; overflow-wrap: break-word;
}
.sheet-h .row { flex-shrink: 0; }
.sheet-h .x { color: var(--text-3); font-size: 22px; width: 44px; height: 44px; margin: -8px -12px -8px 0; display: flex; align-items: center; justify-content: center; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12.5px; font-weight: 700; color: var(--text-2); margin-bottom: 6px; }
.field input, .field select {
  width: 100%; background: var(--bg-3); border: 1px solid transparent; border-radius: var(--r-md);
  padding: 11px 13px; font-size: 15px; outline: none;
}
.field input::placeholder { color: var(--text-3); }
.field input:focus, .field select:focus { border-color: var(--accent); }
/* Without this Safari keeps its own 23px-tall menu button and ignores the padding above. The chevron is two gradients. */
.field select {
  -webkit-appearance: none; appearance: none; padding-right: 36px; min-height: 44px;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%), linear-gradient(135deg, var(--text-2) 50%, transparent 50%);
  background-position: calc(100% - 19px) 50%, calc(100% - 14px) 50%; background-size: 5px 5px; background-repeat: no-repeat;
}
.chip-row { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  min-height: 36px; padding: 7px 14px; border-radius: var(--r-pill); background: var(--bg-3); border: 1px solid transparent;
  font-size: 13px; font-weight: 700; color: var(--text-2);
}
.chip.on { background: var(--accent-fill); border-color: var(--accent-fill); color: var(--ink); }

/* ============ Progress / charts ============ */
.seg { display: flex; gap: 2px; background: var(--bg-3); border: 0; border-radius: var(--r-pill); padding: 4px; margin-bottom: 12px; }
.seg button { flex: 1; min-height: 40px; padding: 8px 4px; border-radius: var(--r-pill); font-size: 13px; font-weight: 700; color: var(--text-2); }
.seg button.on { background: var(--accent-fill); color: var(--ink); font-weight: 800; }
.chart-wrap { position: relative; }
.chart-wrap svg { display: block; width: 100%; height: auto; }
.chart-tip {
  position: absolute; top: 4px; left: 8px; font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums;
  color: var(--accent); pointer-events: none; background: var(--bg-3); padding: 3px 8px; border-radius: var(--r-sm);
}
.ex-pick-btn {
  width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: var(--bg-2); border: 1px solid var(--card-line); border-radius: var(--r-lg);
  padding: 13px 16px; font-weight: 800; font-stretch: var(--semi); font-size: 16px; margin-bottom: 12px; text-align: left;
}
.ex-pick-btn span { color: var(--text-3); font-weight: 500; font-stretch: 100%; font-size: 14px; flex-shrink: 0; }
.kv { display: flex; justify-content: space-between; padding: 7px 0; font-size: 14px; border-bottom: 1px solid var(--line); }
.kv:last-child { border-bottom: 0; }
.kv b { font-weight: 800; font-variant-numeric: tabular-nums; }

.bw-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; font-variant-numeric: tabular-nums; }
.bw-row:last-child { border-bottom: 0; }
.bw-row .d { color: var(--text-2); }
.bw-row .del { color: var(--text-3); font-size: 15px; width: 40px; height: 40px; margin: -8px -12px -8px 0; }

/* ============ Toast ============ */
#toast {
  position: fixed; top: calc(14px + env(safe-area-inset-top)); left: 16px; right: 16px; z-index: 90;
  max-width: 420px; margin: 0 auto; background: var(--bg-3); color: var(--text); border: 0;
  border-radius: var(--r-lg); padding: 13px 18px; font-size: 14px; font-weight: 600;
  box-shadow: var(--shadow); text-align: center; animation: toast-in .22s ease-out;
}
/* Done / saved: the quiet toast with a green tick in front. */
#toast.ok::before { content: "✓"; color: var(--green); font-weight: 800; margin-right: 8px; }
/* PR: a solid gold banner that drops in with a small bounce. Only real PRs use it.
   showToast([title, detail], "pr") gives it a display-type title line and a plain detail line. */
#toast.pr {
  background: var(--gold-fill); color: var(--ink); font-size: 15px; font-weight: 800; font-style: italic; font-stretch: var(--semi);
  text-align: left; animation: pr-drop .45s cubic-bezier(.3, 1.4, .5, 1);
}
#toast.pr b { display: block; font: italic 900 17px/1.15 var(--font); font-stretch: var(--wide); letter-spacing: -.01em; }
#toast.pr span { display: block; margin-top: 3px; font-style: normal; font-weight: 600; font-size: 13px; font-stretch: 100%; line-height: 1.3; }
/* In a workout the toast sits just under the sticky header, so it covers neither Finish nor the
   loading bar. 129px is that header's height: padding 12 + title row 44 + stats 6+16 + bar 10+26+4 +
   padding 10 + border 1 (see .aw-head, .aw-stats, .aw-load). Change it with them. */
body:has(#active-overlay:not([hidden])) #toast { top: calc(129px + 8px + env(safe-area-inset-top)); }

/* History detail set lines */
.hd-ex { margin-bottom: 16px; }
.hd-ex b { color: var(--fam-t, var(--accent)); display: block; margin-bottom: 4px; font-size: 15px; font-weight: 800; }
.hd-set { display: flex; gap: 12px; font-size: 14px; padding: 3px 0; color: var(--text-2); font-variant-numeric: tabular-nums; }
.hd-set .n { width: 22px; color: var(--text-3); font-weight: 700; }

/* ============ Sleep ============ */
/* Sleep reads as night: a blue-plate ramp, independent of the user's accent; awake is the yellow plate. */
button.stat.sl-card { display: block; width: 100%; text-align: left; }
button.stat.sl-card:active { transform: scale(.99); }
.sl-big { font-size: 30px; font-weight: 900; font-style: italic; font-stretch: var(--wide); letter-spacing: -.01em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.sl-big small { font-size: 14px; font-weight: 700; font-style: normal; font-stretch: 100%; letter-spacing: 0; color: var(--text-2); }
.sl-stages { display: flex; gap: 2px; height: 10px; margin: 9px 0 3px; border-radius: 5px; overflow: hidden; }
.sl-seg { display: block; min-width: 3px; }
.sl-deep { background: var(--p-blue); }
.sl-core { background: color-mix(in srgb, var(--p-blue) 62%, var(--bg-3)); }
.sl-rem { background: color-mix(in srgb, var(--p-blue) 34%, var(--bg-3)); }
.sl-awake { background: var(--p-yellow); }
.sl-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px; font-size: 12px; color: var(--text-2); }
.sl-legend span { display: inline-flex; align-items: center; gap: 5px; }
.sl-legend i { width: 10px; height: 10px; border-radius: 50%; min-width: 0; }
.sl-legend b { color: var(--text); font-weight: 700; }
.sl-bars { position: relative; display: flex; align-items: flex-end; gap: 4px; height: 130px; padding: 0 26px 18px 0; } /* right gutter: the goal label */
.sl-col { position: relative; flex: 1; height: 100%; display: flex; align-items: flex-end; justify-content: center; }
.sl-col > span { position: absolute; bottom: -17px; font-size: 10px; color: var(--text-3); }
.sl-bar { width: 100%; max-width: 18px; min-height: 2px; border-radius: 6px 6px 2px 2px; background: color-mix(in srgb, var(--p-blue) 50%, var(--bg-3)); }
.sl-bar.ok { background: var(--p-blue); }
.sl-goal { position: absolute; left: 0; right: 26px; height: 0; border-top: 1px dashed var(--text-3); pointer-events: none; }
.sl-steps { margin: 2px 0 12px; font-size: 13px; color: var(--text-2); }
.sl-steps summary { font-weight: 700; color: var(--accent); padding: 10px 0; cursor: pointer; }
.sl-steps ol { padding-left: 20px; display: grid; gap: 9px; line-height: 1.45; }
.sl-steps b { color: var(--text); }
.sl-steps code { font-family: ui-monospace, Menlo, monospace; font-size: 12px; background: var(--bg-3); border-radius: 5px; padding: 1px 5px; overflow-wrap: anywhere; }
/* The goal label sits in the gutter at the end of its line, never above a bar (a long night covered it). */
.sl-goal span { position: absolute; left: calc(100% + 4px); top: -7px; font-size: 10px; line-height: 12px; color: var(--text-3); white-space: nowrap; }

/* ============ Coach ============ */
#view-coach.active { padding-bottom: calc(176px + env(safe-area-inset-bottom)); } /* room for the composer above the tab bar */
/* The other tabs slide up 4px as they fade in. A transform on an ancestor re-anchors position:fixed children
   to that ancestor, so the composer would jump to the end of the content for the length of the animation. */
#view-coach { animation-name: cofade; }
@keyframes cofade { from { opacity: 0; } to { opacity: 1; } }
.co-empty { padding: 4px 2px; }
.co-link { color: var(--accent); font-weight: 700; text-decoration: underline; font-size: inherit; }
.co-sugg { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 18px; }
.co-sugg .chip { min-height: 40px; color: var(--text); }
.co-sugg .chip:disabled { opacity: .5; }
.co-privacy { line-height: 1.45; }
.co-thread { display: flex; flex-direction: column; gap: 10px; }
.co-msg { max-width: 88%; padding: 10px 14px; border-radius: 20px; font-size: 15px; line-height: 1.45; overflow-wrap: anywhere; }
.co-msg.me { align-self: flex-end; background: var(--accent-fill); color: var(--ink); border-bottom-right-radius: 6px; }
.co-msg.ai { align-self: flex-start; background: var(--bg-2); border: 1px solid var(--card-line); border-bottom-left-radius: 6px; }
.co-msg p + p, .co-msg p + ul, .co-msg p + ol, .co-msg ul + p, .co-msg ol + p { margin-top: 8px; }
.co-msg ul, .co-msg ol { padding-left: 20px; display: grid; gap: 4px; }
.co-dots { display: inline-flex; gap: 4px; padding: 5px 0; }
.co-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); animation: codot 1s infinite ease-in-out; }
.co-dots i:nth-child(2) { animation-delay: .15s; } .co-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes codot { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
@media (prefers-reduced-motion: reduce) { .co-dots i { animation: none; } }
.co-composer {
  position: fixed; left: 0; right: 0; bottom: calc(66px + env(safe-area-inset-bottom)); z-index: 39;
  max-width: 560px; margin: 0 auto; padding: 8px 12px; display: flex; align-items: flex-end; gap: 8px;
  background: var(--bg); border-top: 1px solid var(--line);
}
.co-composer textarea {
  flex: 1; min-width: 0; resize: none; background: var(--bg-3); border: 1px solid transparent; border-radius: 22px;
  padding: 10px 14px; font-size: 16px; line-height: 1.35; outline: none; color: var(--text); font-family: inherit; max-height: 120px;
}
.co-composer textarea::placeholder { color: var(--text-3); }
.co-composer textarea:focus { border-color: var(--accent); }
.co-send { width: 42px; height: 42px; flex-shrink: 0; border-radius: 50%; background: var(--accent-fill); color: var(--ink); font-size: 20px; font-weight: 800; transition: transform .08s ease; }
.co-send:active { transform: scale(.94); }
.co-send:disabled { background: var(--bg-3); color: var(--text-3); } /* not opacity: 40% yellow over navy reads olive */
.co-usage { text-align: center; margin-top: 14px; font-size: 11px; }

/* ============ Motion ============ */
/* Only in answer to an action: a plate dropping onto the bar, the PR banner, toasts and sheets arriving,
   buttons squishing (the :active rules above). */
@keyframes plate-drop {
  0% { transform: translateY(-10px) scaleY(.6); opacity: 0; }
  60% { transform: translateY(1px) scaleY(1.08); opacity: 1; }
  100% { transform: none; opacity: 1; }
}
/* Transform only: the banner is solid at every frame (a fade let the bar show through it). */
@keyframes pr-drop {
  0% { transform: translateY(-24px) scale(.96); }
  60% { transform: translateY(3px) scale(1.02); }
  100% { transform: none; }
}
@keyframes toast-in { from { transform: translateY(-8px); opacity: 0; } to { transform: none; opacity: 1; } }
/* Motion preference, and the phone's own Reduce Motion setting: these must stay after every animation above. */
:root[data-motion="reduced"] *, :root[data-motion="reduced"] *::before, :root[data-motion="reduced"] *::after { animation: none !important; transition: none !important; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ============ Small phones (iPhone SE, 320px) ============ */
@media (max-width: 359px) {
  /* Narrower inputs give the Previous column ~68px; at full size it got 28 and showed "0×5" for "80×5".
     Reps needs 56: a target like "12-15" is 50px wide in tabular figures, and 50px of column cut its last digit.
     The set number keeps 40px: in 36 its effort pill (40px tall) drew as an oval instead of a round plate. */
  .set-grid-h, .set-row .grid { grid-template-columns: 40px 1fr 56px 56px 40px; gap: 6px; }
  .set-row .prev { font-size: 12px; gap: 3px; }
  .set-row .prev .rir-dot { width: 8px; height: 8px; box-shadow: none; }
  .set-row input { padding: 11px 2px; }
  /* No room for the label beside three buttons; the timer itself is what matters. */
  #rest-bar .lab { visibility: hidden; }
  #rest-bar .inner { gap: 6px; padding: 9px 10px; }
  #rest-bar .t { min-width: 58px; font-size: 22px; }
  #tabbar button { font-size: 10px; }
  /* Wide display type takes more room: titles and big figures step down a size. */
  .page-h h1 { font-size: 26px; }
  .stat .val { font-size: 21px; }
  .sheet-h b { font-size: 18px; }
  .aw-title { font-size: 20px; }
  /* Exercise names: at 18px semi-wide even "Bench Press" broke onto two lines beside the header buttons. */
  .aw-ex .exh b { font-size: 16px; font-stretch: 100%; gap: 7px; }
  #toast.pr b { font-size: 15px; }
  /* Home tiles side by side: a one-line label ("Bodyweight") next to a two-line one ("Workouts this week")
     put the big figures at different heights. Every label keeps two lines' room. */
  .stat-grid > div.stat:not([style]) .lab { line-height: 15px; min-height: 30px; }
  /* Words that can go when room is short, e.g. "44 active days" reads "44 days" in the Training pill. */
  .hide-narrow { display: none; }
  /* Workout summary: Done must be on screen when the sheet opens on a 568px-tall phone. */
  .wk-summary .card { padding: 12px 14px; margin-bottom: 10px; }
  .wk-summary .aw-load.mini { margin-top: 0; }
  .wk-summary .kv { padding: 5px 0; }
  .wk-summary .ex-note { min-height: 44px; }
}

/* Large text on a 360-395px phone lays out like a phone under 360px (395 / 1.1), but the query above
   only sees the real width. Same compact rules, so the Previous column is not clipped again. */
@media (min-width: 360px) and (max-width: 395px) {
  :root[data-text="large"] .set-grid-h, :root[data-text="large"] .set-row .grid { grid-template-columns: 40px 1fr 56px 56px 40px; gap: 6px; }
  :root[data-text="large"] .aw-ex.no-prev .set-grid-h, :root[data-text="large"] .aw-ex.no-prev .set-row .grid { grid-template-columns: 40px 1fr 1fr 40px; }
  :root[data-text="large"] .set-row .prev { font-size: 12px; gap: 3px; }
  :root[data-text="large"] .set-row .prev .rir-dot { width: 8px; height: 8px; box-shadow: none; }
  :root[data-text="large"] .set-row input { padding: 11px 2px; }
  :root[data-text="large"] #rest-bar .lab { visibility: hidden; }
  :root[data-text="large"] #rest-bar .inner { gap: 6px; padding: 9px 10px; }
  :root[data-text="large"] #rest-bar .t { min-width: 58px; font-size: 22px; }
  :root[data-text="large"] #tabbar button { font-size: 10px; }
  :root[data-text="large"] .page-h h1 { font-size: 26px; }
  :root[data-text="large"] .stat .val { font-size: 21px; }
  :root[data-text="large"] .sheet-h b { font-size: 18px; }
  :root[data-text="large"] .aw-title { font-size: 20px; }
  :root[data-text="large"] .aw-ex .exh b { font-size: 16px; font-stretch: 100%; gap: 7px; }
  :root[data-text="large"] #toast.pr b { font-size: 15px; }
  :root[data-text="large"] .stat-grid > div.stat:not([style]) .lab { line-height: 15px; min-height: 30px; }
  :root[data-text="large"] .hide-narrow { display: none; }
  :root[data-text="large"] .wk-summary .card { padding: 12px 14px; margin-bottom: 10px; }
  :root[data-text="large"] .wk-summary .aw-load.mini { margin-top: 0; }
  :root[data-text="large"] .wk-summary .kv { padding: 5px 0; }
  :root[data-text="large"] .wk-summary .ex-note { min-height: 44px; }
}
