/*
 * Ship's Log: the stylesheet.
 *
 * The idea: a bound training logbook. Warm paper, ink, ruled hairlines and tabular columns,
 * the way a deck log or a track-meet results sheet is printed. Three voices of type:
 *   Archivo (condensed for headings and labels, normal width for UI text)  the printed form
 *   IBM Plex Mono                                                          every number
 *   Newsreader                                                             what is written in it
 * One accent, signal vermilion (the coach's pen, the track, the lifejacket), for the next thing
 * to do, the primary action, and the one series in a chart. Done is not a colour: a done set is
 * inked in solid. Dark mode is the night-watch edition: navy-black chart room, parchment ink,
 * a brighter signal orange.
 *
 * Contents
 *   0. Fonts             6. Lists, rows, tiles, flags      11. Live workout: sets, work bar, rest
 *   1. Tokens            7. Bars, charts, tooltip          12. Change sheet
 *   2. Base              8. Today                          13. Other pages
 *   3. Page shell, nav   9. Workout plan and record        14. Wide screens
 *   4. Buttons          10. Disclosures                    15. Motion, print
 *   5. Forms
 *
 * States (set by the templates or app.js; see the header of app.js):
 *   [aria-pressed="true"] on .set    the set is done (inked in solid)
 *   .is-next  .is-pending            the set next in line (vermilion); a tick not yet saved (hatched)
 *   .is-done  .is-skipped            an exercise with every set ticked; one left out
 *   .is-busy                         a form/button while a slow post is in flight
 *   .is-over                         rest timer at zero; a stat bar past its target
 *   [aria-current]                   the current nav item, year or day
 *   [hidden]                         always wins (see Base)
 */

/* ---- 0. Fonts (fetched by `make fonts` into /static/fonts; see tools/fonts.txt) ------- */

@font-face {
  font-family: "Archivo";
  src: url("/static/fonts/archivo-latin-wdth-normal.woff2") format("woff2");
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Plex Mono";
  src: url("/static/fonts/ibm-plex-mono-latin-400-normal.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Plex Mono";
  src: url("/static/fonts/ibm-plex-mono-latin-600-normal.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Newsreader";
  src: url("/static/fonts/newsreader-latin-wght-normal.woff2") format("woff2");
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Newsreader";
  src: url("/static/fonts/newsreader-latin-wght-italic.woff2") format("woff2");
  font-weight: 200 800;
  font-style: italic;
  font-display: swap;
}

/* ---- 1. Tokens ------------------------------------------------------------------ */

:root {
  /* Paper and ink. Contrast on --bg: text 14.6, text-2 6.1, accent 5.0, warn 7.0, line-strong 3.3. */
  --bg: #f3eee4;            /* paper */
  --surface: #e9e2d4;       /* a recessed strip of the page */
  --field: #fbf8f2;         /* a box to write in */
  --line: #d5ccbb;          /* the ruling */
  --line-strong: #8a8273;   /* boundaries of things you can press (3:1) */
  --text: #1b1d21;          /* ink */
  --text-2: #5e584e;        /* pencil */
  --accent: #b83a16;        /* signal vermilion: next, primary action, the chart series */
  --on-accent: #fbf8f2;     /* 5.4:1 on --accent */
  --accent-soft: color-mix(in srgb, var(--accent) 11%, var(--bg));
  --done: var(--text);      /* done is inked in */
  --done-soft: var(--surface);
  --on-done: var(--bg);
  --warn: #9a1b35;          /* errors and destructive actions; text and borders only */
  --scrim: rgb(27 29 33 / 0.55);

  --f-sans: "Archivo", "Helvetica Neue", Arial, sans-serif;
  --f-mono: "Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --f-serif: "Newsreader", Georgia, "Times New Roman", serif;
  --cond: 78%;              /* font-stretch for headings and labels */
  --semi: 88%;              /* buttons and small labels */

  --gap-1: 4px;
  --gap-2: 8px;
  --gap-3: 12px;
  --gap-4: 16px;
  --gap-5: 24px;
  --gap-6: 40px;
  --tap: 44px;              /* smallest touch target */
  --radius: 2px;            /* a cut corner, not a rounded card */
  --measure: 66ch;
  --page: 1120px;
  --bar-h: 56px;            /* bottom tab bar */
  --safe-b: env(safe-area-inset-bottom, 0px);
}

/* The night-watch edition: navy-black chart room, parchment ink, brighter signal orange.
   Contrast on --bg: text 14.5, text-2 6.7, accent 6.8, warn 9.1, line-strong 3.9. */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121519;
    --surface: #1b2026;
    --field: #0d1013;
    --line: #2b323a;
    --line-strong: #6b7480;
    --text: #ece4d4;
    --text-2: #a39b8c;
    --accent: #ff7448;
    --on-accent: #121519;    /* 6.8:1 */
    --accent-soft: color-mix(in srgb, var(--accent) 16%, var(--bg));
    --warn: #ff9aa8;
    --scrim: rgb(0 0 0 / 0.65);
  }
}

/* ---- 2. Base -------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: var(--gap-4);
  scroll-padding-bottom: calc(var(--bar-h) + var(--safe-b) + var(--gap-5));
  background: var(--bg);
  color-scheme: light dark;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--f-sans);
  font-size: 16px;
  line-height: 1.5;
  font-stretch: 96%;
  font-variant-numeric: tabular-nums;
  overflow-wrap: break-word;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, p, ul, ol, dl, dd, figure, fieldset { margin: 0; padding: 0; }
ul, ol { list-style: none; }
fieldset { border: 0; min-width: 0; }
legend { padding: 0; }

h1, h2, h3 { font-stretch: var(--cond); letter-spacing: 0; }
h1 { font-size: 2.25rem; line-height: 1; font-weight: 800; letter-spacing: -0.005em; }
h2 { font-size: 1.0625rem; line-height: 1.2; font-weight: 750; text-transform: uppercase; letter-spacing: 0.06em; }
h3 { font-size: 1.1875rem; line-height: 1.2; font-weight: 700; }

a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 3px; text-decoration-color: var(--line-strong); }
a:hover { text-decoration-color: currentColor; }
b, strong { font-weight: 650; }

::selection { background: var(--accent); color: var(--on-accent); }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
main:focus, section:focus { outline: none; }

.vh {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
}

html.js .no-js-only { display: none; }

/* Written entries (notes, cues, rationale) are set in the serif: the hand in the book. */
.prose { max-width: var(--measure); white-space: pre-line; font-family: var(--f-serif); font-size: 1.0625rem; line-height: 1.5; font-stretch: normal; }
.meta, .help, .row-meta, .page-sub, .tile-sub, .unit, .optional, .block-meta, .eyebrow, .crumb { color: var(--text-2); }
.meta, .help, .row-meta, .tile-sub, .block-meta { font-size: 0.875rem; }
.help { max-width: var(--measure); }
.unit, .optional { font-size: 0.8125rem; font-weight: 400; }
.optional { font-family: var(--f-mono); font-size: 0.6875rem; text-transform: uppercase; letter-spacing: 0.04em; margin-left: 0.25em; }
.sep { color: var(--text-2); padding: 0 0.15em; }
.num { text-align: right; font-family: var(--f-mono); font-variant-numeric: tabular-nums; }

/* The small mono stamp: dates, kinds, counts above a title. */
.eyebrow {
  font-family: var(--f-mono); font-size: 0.75rem; line-height: 1.4;
  text-transform: uppercase; letter-spacing: 0.06em;
}

/* ---- 3. Page shell and navigation ------------------------------------------------ */

.skip-link {
  position: absolute; left: var(--gap-2); top: -100px; z-index: 50;
  padding: var(--gap-3) var(--gap-4); background: var(--bg); border: 2px solid var(--text);
}
.skip-link:focus { top: var(--gap-2); }

.site-header {
  display: flex; align-items: center; gap: var(--gap-5);
  max-width: var(--page); margin: 0 auto; padding: var(--gap-3) var(--gap-4);
  border-bottom: 1px solid var(--line);
}

/* The wordmark: the chip-log quadrant and the name in condensed capitals. */
.brand {
  display: inline-flex; align-items: center; gap: 10px; min-height: var(--tap);
  font-weight: 800; font-size: 1.0625rem; font-stretch: var(--cond); line-height: 1;
  text-transform: uppercase; letter-spacing: 0.12em; text-decoration: none; white-space: nowrap;
}
.brand-mark { flex: none; width: 28px; height: 28px; }
/* The mark keeps the favicon's colours in both editions so it is always the same object. */
.bm-plate { fill: #1b1d21; }
.bm-quad { fill: #e0532a; }
.bm-line { fill: #f3eee4; }
@media (prefers-color-scheme: dark) { .bm-plate { fill: #2a3139; } }
.bm-knots { fill: none; stroke: #f3eee4; stroke-width: 3; stroke-linecap: round; stroke-dasharray: 0.1 7.5; }

.site-nav { display: none; }          /* phones use the tab bar */
.site-nav ul { display: flex; flex-wrap: wrap; gap: 0 var(--gap-1); }
.site-nav a {
  display: flex; align-items: center; min-height: var(--tap); padding: 0 var(--gap-2);
  font-size: 0.8125rem; font-weight: 650; font-stretch: var(--semi); text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-2); text-decoration: none; border-bottom: 3px solid transparent; margin-bottom: -13px; padding-bottom: 10px;
}
.site-nav a:hover { color: var(--text); }
.site-nav a[aria-current] { color: var(--text); border-bottom-color: var(--accent); }

.main {
  display: flow-root;
  max-width: var(--page); margin: 0 auto;
  padding: var(--gap-4) var(--gap-4) calc(var(--bar-h) + var(--safe-b) + var(--gap-6));
}
.main > * + * { margin-top: var(--gap-5); }

/* The head of every page: stamp, title, a heavy rule like the top of a printed form. */
.page-head { padding-bottom: var(--gap-4); border-bottom: 3px solid var(--text); }
.page-head > * + * { margin-top: var(--gap-2); }
.page-head > .crumb + * { margin-top: 0; }
.page-sub { font-size: 0.9375rem; max-width: var(--measure); }
.crumb { font-size: 0.8125rem; font-weight: 650; font-stretch: var(--semi); text-transform: uppercase; letter-spacing: 0.08em; }
.crumb a { display: inline-flex; align-items: center; gap: 6px; min-height: var(--tap); margin-top: calc(var(--gap-2) * -1); text-decoration: none; color: var(--text-2); }
.crumb a:hover { color: var(--text); }
.crumb a::before { content: ""; width: 7px; height: 7px; border-left: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); margin-left: 2px; }

/* Section heads: a capitalised label on a ruled line, like a column head on the sheet. */
.section > * + * { margin-top: var(--gap-3); }
.section > h2 { padding-top: var(--gap-2); border-top: 1px solid var(--text); }
.section > h3, .sub-h { margin-top: var(--gap-5); }
/* Where ruled cards follow straight away, the head is a label over them, not another rule. */
.section:has(> .cards) > h2, .section:has(> .goal-list > .card) > h2 { padding-top: 0; border-top: 0; color: var(--text-2); }
.more-link { font-size: 0.875rem; font-weight: 650; font-stretch: var(--semi); text-transform: uppercase; letter-spacing: 0.08em; }
.more-link a { display: inline-flex; align-items: center; gap: 6px; min-height: var(--tap); text-decoration: none; }
.more-link a::after { content: ""; width: 6px; height: 6px; border-right: 2px solid var(--accent); border-top: 2px solid var(--accent); transform: rotate(45deg); }
.more-link a:hover { text-decoration: underline; }

/* Bottom tab bar: the book's thumb index. Text, deliberately: five words read faster than five pictures. */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding-bottom: var(--safe-b);
  background: var(--bg); border-top: 2px solid var(--text);
}
.tab {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: var(--bar-h); padding: var(--gap-1);
  font-size: 0.8125rem; font-weight: 650; font-stretch: var(--semi); text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-2); text-decoration: none; text-align: center; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.tab + .tab, .tab-more { border-left: 1px solid var(--line); }
.tab[aria-current], .tab.is-current { color: var(--text); font-weight: 800; }
.tab[aria-current]::before, .tab.is-current::before {
  content: ""; position: absolute; left: -1px; right: 0; top: -2px; height: 5px; background: var(--accent);
}
.tab-icon { display: none; }          /* deliberately text-only; see the comment above */
.tab-more { position: static; }
.tab-more > summary { list-style: none; }
.tab-more > summary::-webkit-details-marker { display: none; }
.tab-more[open] > summary { color: var(--text); background: var(--surface); }
.more-sheet {
  position: absolute; right: var(--gap-2); bottom: calc(100% + var(--gap-2));
  min-width: 220px; padding: var(--gap-1) 0;
  background: var(--bg); border: 2px solid var(--text); border-radius: var(--radius);
}
.more-sheet li + li { border-top: 1px solid var(--line); }
.more-sheet a {
  display: flex; align-items: center; min-height: 52px; padding: 0 var(--gap-4);
  font-size: 0.9375rem; font-weight: 650; font-stretch: var(--semi); text-transform: uppercase; letter-spacing: 0.08em;
  text-decoration: none;
}
.more-sheet a[aria-current] { box-shadow: inset 5px 0 0 var(--accent); }

/* "Sets not saved yet": sits above the tab bar on every page. */
.sync-note {
  position: fixed; left: var(--gap-2); right: var(--gap-2); z-index: 19;
  bottom: calc(var(--bar-h) + var(--safe-b) + var(--gap-2));
  display: flex; align-items: center; justify-content: space-between; gap: var(--gap-3);
  padding: var(--gap-1) var(--gap-1) var(--gap-1) var(--gap-3);
  background: var(--bg); color: var(--warn); border: 2px solid var(--warn); border-radius: var(--radius);
  font-size: 0.875rem; font-weight: 600;
}

/* ---- 4. Buttons ------------------------------------------------------------------- */

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--gap-2);
  min-height: var(--tap); min-width: var(--tap); padding: var(--gap-2) var(--gap-4);
  background: transparent; color: var(--text);
  border: 2px solid var(--text); border-radius: var(--radius);
  font-size: 0.875rem; font-weight: 700; font-stretch: var(--semi); line-height: 1.15;
  text-transform: uppercase; letter-spacing: 0.08em;
  text-decoration: none; text-align: center; touch-action: manipulation;
}
.btn:hover { background: var(--surface); }
.btn-primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, var(--text)); }
.btn-quiet {
  border-color: transparent; background: none; padding-left: var(--gap-2); padding-right: var(--gap-2);
  text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 4px;
  font-weight: 600; color: var(--text-2);
}
.btn-quiet:hover { background: none; color: var(--text); text-decoration-color: currentColor; }
.btn-danger { color: var(--warn); border-color: var(--warn); }
.btn-small { padding: var(--gap-1) var(--gap-3); font-size: 0.75rem; border-width: 1.5px; }   /* still 44px tall */
.btn-big { min-height: 60px; font-size: 1.0625rem; letter-spacing: 0.1em; }
.btn-block { display: flex; width: 100%; }
.btn.is-busy, .btn[aria-disabled="true"] { cursor: progress; background-image: repeating-linear-gradient(-45deg, transparent 0 6px, rgb(127 127 127 / 0.22) 6px 12px); }
.btn-row, .row-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--gap-2); }
.row-actions form, .btn-row form { display: inline-flex; }
.row-actions > a:not(.btn):not(.video-link) { display: inline-flex; align-items: center; min-height: var(--tap); font-size: 0.875rem; }

.video-link {
  display: inline-flex; align-items: center; gap: 6px; min-height: var(--tap); padding: 0 var(--gap-1);
  font-size: 0.875rem; font-weight: 600;
}
.video-link::before {
  content: ""; flex: none; width: 0; height: 0;
  border-left: 8px solid var(--accent); border-top: 5px solid transparent; border-bottom: 5px solid transparent;
}

/* ---- 5. Forms --------------------------------------------------------------------- */

.form > * + * { margin-top: var(--gap-4); }
.field > * + * { margin-top: 6px; }
label, legend { display: block; font-weight: 650; font-size: 0.9375rem; }
legend { margin-bottom: 6px; }

input[type="text"], input[type="search"], input[type="email"], input[type="password"], input[type="url"],
input[type="date"], input[type="file"], select, textarea {
  display: block; width: 100%; min-height: 48px; padding: var(--gap-2) var(--gap-3);
  background: var(--field); border: 1px solid var(--line-strong); border-radius: var(--radius);
  font-size: 1rem;                    /* 16px keeps iOS from zooming on focus */
  box-shadow: inset 0 -2px 0 var(--line);
}
input:focus-visible, select:focus-visible, textarea:focus-visible { outline-offset: 0; border-color: var(--text); }
input[type="date"], input[inputmode="decimal"], input[inputmode="numeric"] { font-family: var(--f-mono); }
::placeholder { color: var(--text-2); opacity: 0.8; }
/* Writing into the log is done in the serif. */
textarea { resize: vertical; font-family: var(--f-serif); font-size: 1.125rem; line-height: 1.45; }
input[type="file"] { padding: var(--gap-2); font-size: 0.875rem; }
input[type="file"]::file-selector-button {
  margin-right: var(--gap-3); padding: 6px var(--gap-3); background: none; color: var(--text);
  border: 1.5px solid var(--text); border-radius: var(--radius);
  font: 700 0.75rem/1.2 var(--f-sans); font-stretch: var(--semi); text-transform: uppercase; letter-spacing: 0.08em;
}
select {
  appearance: none; -webkit-appearance: none; padding-right: 36px;
  background-image: linear-gradient(45deg, transparent 50%, var(--text) 50%), linear-gradient(135deg, var(--text) 50%, transparent 50%);
  background-position: calc(100% - 18px) 52%, calc(100% - 12px) 52%;
  background-size: 6px 6px; background-repeat: no-repeat;
}

.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--gap-3); }
.field-grid > .field { margin: 0; }

/* A label, a short input and its button on one line. */
.inline-field { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px var(--gap-2); align-items: end; }
.inline-field > label { grid-column: 1 / -1; }
.inline-field .btn { min-height: 48px; }

/* Segmented choice: a row of boxes on the form; the chosen one is inked in. */
.seg-row { display: flex; flex-wrap: wrap; gap: 6px; }
.seg-opt { position: relative; flex: 1 1 auto; font-weight: 600; font-size: 0.9375rem; }
.seg-opt input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.seg-opt > span {
  display: flex; align-items: center; justify-content: center;
  min-height: 48px; min-width: var(--tap); padding: var(--gap-1) var(--gap-3);
  border: 1.5px solid var(--line-strong); border-radius: var(--radius); text-align: center;
  font-variant-numeric: tabular-nums;
}
.seg-opt:hover > span { border-color: var(--text); }
.seg-opt input:checked + span { background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 700; }
.seg-opt input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
.seg-opt input:disabled + span { opacity: 0.45; }
.seg-10 { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); }
.seg-10 .seg-opt > span { padding: var(--gap-1); }
/* Numbers in a seg row (minutes, effort) are set in the mono. */
.seg-10 .seg-opt, .composer .seg:first-of-type .seg-opt { font-family: var(--f-mono); font-size: 1rem; }

.chips { display: flex; flex-wrap: wrap; gap: var(--gap-2); }
.chip {
  display: inline-flex; flex-direction: column; align-items: flex-start; justify-content: center;
  min-height: var(--tap); padding: var(--gap-1) var(--gap-3);
  background: none; border: 1px dashed var(--line-strong); border-radius: var(--radius); text-align: left;
  font-size: 0.9375rem; line-height: 1.25;
  touch-action: manipulation;
}
.chip:hover { border-style: solid; border-color: var(--text); }
.chip-main { font-weight: 600; }
.chip-meta { font-family: var(--f-mono); font-size: 0.75rem; color: var(--text-2); }

.busy-note { font-size: 0.875rem; font-family: var(--f-serif); font-style: italic; }
.form.is-busy, form.is-busy { cursor: progress; }

.flash { max-width: var(--measure); padding: var(--gap-3) var(--gap-3) var(--gap-3) var(--gap-4); border: 1px solid var(--line-strong); border-left: 4px solid var(--text); border-radius: var(--radius); }
.flash-error, .status-line.is-error { border-color: var(--warn); color: var(--warn); }

/* ---- 6. Lists, rows, tiles, flags -------------------------------------------------- */

/* A card is a ruled block on the page, not a floating box. */
.card { padding-top: var(--gap-3); border-top: 2px solid var(--text); }
.card > * + * { margin-top: var(--gap-3); }
.cards { display: grid; gap: var(--gap-6) var(--gap-5); }
.cards > * { min-width: 0; }

.rows { border-top: 1px solid var(--line); }
.row {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--gap-1) var(--gap-3);
  min-height: 48px; padding: var(--gap-2) 0; border-bottom: 1px solid var(--line);
}
.row-main { flex: 1 1 12rem; min-width: 0; }
.row-main .row-meta { display: block; }
a.row-main { display: flex; align-items: center; min-height: var(--tap); font-weight: 600; }
.row-link {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--gap-1) var(--gap-3);
  flex: 1 1 100%; min-height: var(--tap); text-decoration: none;
}
.row-link:hover .row-main, .row-link:hover .log-title { text-decoration: underline; text-decoration-color: var(--accent); text-decoration-thickness: 2px; }
.row-link .row-main, .log-title { font-weight: 600; }
.row:has(> .row-link:hover) { background: var(--surface); }

/* Stat tiles: one ruled line of a results sheet. Cells share hairlines; numbers in the mono. */
.tiles {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 0; overflow: hidden;
  border-top: 2px solid var(--text); border-bottom: 1px solid var(--line);
}
/* Hairlines to the right and below each cell; the ones on the outer edge are clipped away. */
.tile { padding: var(--gap-2) var(--gap-3) var(--gap-3); min-width: 0; box-shadow: 1px 0 0 var(--line), 0 1px 0 var(--line); }
.tile dt {
  font-size: 0.75rem; font-weight: 650; font-stretch: var(--semi); color: var(--text-2);
  text-transform: uppercase; letter-spacing: 0.07em; line-height: 1.3;
}
.tile dd { margin-top: 6px; font-family: var(--f-mono); font-size: 1.375rem; font-weight: 600; line-height: 1.1; letter-spacing: -0.02em; }
.tile dd .unit { font-family: var(--f-sans); letter-spacing: 0; }
.tile-sub { display: block; font-weight: 400; }
.tile dd .tile-sub { margin-top: 4px; font-family: var(--f-sans); font-size: 0.8125rem; letter-spacing: 0; line-height: 1.3; }
.card .tiles, .open-card .tiles { border-top: 1px solid var(--line); }
.big-stat { font-size: 1rem; color: var(--text-2); }
.big-stat b { font-family: var(--f-mono); font-size: 2.75rem; font-weight: 600; line-height: 1; letter-spacing: -0.03em; color: var(--text); margin-right: 0.15em; }

.facts { border-top: 2px solid var(--text); max-width: 46rem; }
.facts > div { display: grid; grid-template-columns: 7.5rem minmax(0, 1fr); gap: var(--gap-3); padding: var(--gap-2) 0; border-bottom: 1px solid var(--line); }
.facts dt { color: var(--text-2); font-size: 0.75rem; font-weight: 650; font-stretch: var(--semi); text-transform: uppercase; letter-spacing: 0.07em; padding-top: 3px; }

/* Flags are rubber stamps: mono capitals in a ruled box. Good news is inked in vermilion. */
.flag {
  display: inline-block; padding: 1px 6px 0; border: 1px solid var(--text-2); border-radius: 1px;
  font-family: var(--f-mono); font-size: 0.6875rem; font-weight: 600; line-height: 1.5; letter-spacing: 0.05em;
  text-transform: uppercase; color: var(--text-2); white-space: nowrap; vertical-align: 0.15em;
}
.flag-good { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.flag-due { border-style: dashed; border-color: var(--accent); color: var(--accent); }

.tags { display: flex; flex-wrap: wrap; gap: var(--gap-2); }
.tag {
  padding: 2px var(--gap-2); border: 1px solid var(--line-strong); border-radius: 1px;
  font-size: 0.75rem; font-weight: 650; font-stretch: var(--semi); text-transform: uppercase; letter-spacing: 0.07em;
}
.tag-focus { background: var(--text); color: var(--bg); border-color: var(--text); }

.empty {
  max-width: var(--measure); padding: var(--gap-1) 0 var(--gap-1) var(--gap-4);
  border-left: 2px solid var(--line-strong);
  font-family: var(--f-serif); font-style: italic; font-size: 1.0625rem; line-height: 1.45; color: var(--text-2);
}
.empty a { color: var(--text); font-style: normal; font-family: var(--f-sans); font-size: 0.9375rem; font-weight: 600; }

/* Better is circled in the coach's pen; worse is left in pencil. Never colour alone. */
.delta { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
.delta.is-better {
  color: var(--accent); font-weight: 600;
  display: inline-block; white-space: nowrap; line-height: 1.25;
  padding: 0 0.45em; border: 1.5px solid var(--accent); border-radius: 999px;
}
.delta.is-worse { color: var(--text-2); }
.delta.is-up::after { content: " \2191"; }
.delta.is-down::after { content: " \2193"; }

/* Jump links within a page, the year switcher: an index strip. */
.pager ul { display: flex; flex-wrap: wrap; gap: 6px; }
.pager li { display: flex; }
.pager a {
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  display: flex; align-items: center; min-height: var(--tap); padding: 0 var(--gap-3);
  font-size: 0.8125rem; font-weight: 650; font-stretch: var(--semi); text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-2); text-decoration: none;
}
.pager a:hover { color: var(--text); background: var(--surface); }
.pager a[aria-current] { background: var(--text); color: var(--bg); border-color: var(--text); }
.pager.years a { font-family: var(--f-mono); font-size: 0.9375rem; letter-spacing: 0; text-transform: none; }
.count { font-family: var(--f-mono); font-weight: 400; color: var(--text-2); letter-spacing: 0; margin-left: 0.35em; }

/* ---- 7. Bars, charts, tooltip ------------------------------------------------------ */

progress, meter {
  -webkit-appearance: none; appearance: none;
  display: block; width: 100%; height: 8px; border: 0; border-radius: 0;
  background: var(--line); color: var(--text); accent-color: var(--text);
}
/* A bar is ink filling a ruled track; only the live workout's bar is in the signal colour. */
progress::-webkit-progress-bar { background: var(--line); border-radius: 0; }
progress::-webkit-progress-value { background: var(--text); border-radius: 0; }
progress::-moz-progress-bar { background: var(--text); }
.workbar progress::-webkit-progress-value, .open-card.is-active progress::-webkit-progress-value { background: var(--accent); }
.workbar progress::-moz-progress-bar, .open-card.is-active progress::-moz-progress-bar { background: var(--accent); }
meter::-webkit-meter-bar { height: 8px; background: var(--line); border: 0; border-radius: 0; }
meter::-webkit-meter-optimum-value, meter::-webkit-meter-suboptimum-value,
meter::-webkit-meter-even-less-good-value { background: var(--accent); border-radius: 0; }
meter::-moz-meter-bar { background: var(--accent); }

.stat-bars { display: grid; gap: var(--gap-4); }
.stat-bar > * + * { margin-top: 6px; }
.stat-bar + .stat-bar { margin-top: var(--gap-4); }
.stat-bars .stat-bar { margin: 0; }
.stat-bar-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--gap-3); }
.stat-bar-label { font-size: 0.8125rem; font-weight: 650; font-stretch: var(--semi); text-transform: uppercase; letter-spacing: 0.07em; }
.stat-bar-val { font-family: var(--f-mono); font-size: 0.875rem; color: var(--text-2); }
.stat-bar-val b { font-size: 1.125rem; color: var(--text); }
.stat-bar.is-over .stat-bar-val b { color: var(--warn); }
.stat-bar.is-over .stat-bar-val b::after { content: " (over)"; font-weight: 400; font-size: 0.8125rem; }
.stat-bar.is-over progress::-webkit-progress-value { background: var(--warn); }
.stat-bar.is-over progress::-moz-progress-bar { background: var(--warn); }

.chart-grid { display: grid; gap: var(--gap-5); }
.chart-grid > * { min-width: 0; }
.chart-card { padding-top: var(--gap-2); border-top: 1px solid var(--line-strong); }
.chart-card > * + * { margin-top: var(--gap-2); }
.chart-card > h3 { font-size: 0.8125rem; font-weight: 700; font-stretch: var(--semi); text-transform: uppercase; letter-spacing: 0.07em; }
.chart-card figcaption {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: var(--gap-1) var(--gap-3);
  font-size: 0.875rem; font-weight: 600; line-height: 1.3;
}
.chart-card figcaption > a { font-weight: 650; }
.chart-stat { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--gap-1) var(--gap-2); font-weight: 400; }
.chart-stat b { font-family: var(--f-mono); font-size: 1.125rem; font-weight: 600; letter-spacing: -0.02em; }
.chart-stat .tile-sub { display: inline; font-size: 0.8125rem; }

svg.chart { display: block; width: 100%; height: auto; max-width: 560px; overflow: visible; font-family: var(--f-mono); }
svg.spark { display: inline-block; width: 96px; height: 26px; vertical-align: middle; }
svg.ring { display: block; width: 64px; height: 64px; }
.c-grid { stroke: var(--line); stroke-width: 1; shape-rendering: crispEdges; }
.c-axis { stroke: var(--text-2); stroke-width: 1; shape-rendering: crispEdges; }
.c-target { stroke: var(--text); stroke-width: 1; stroke-dasharray: 2 3; }
.c-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.c-area { fill: var(--accent); fill-opacity: 0.08; stroke: none; }
.c-bar { fill: var(--accent); fill-opacity: 0.85; }
.c-dot { fill: var(--bg); stroke: var(--accent); stroke-width: 1.5; }
.c-end { fill: var(--accent); stroke: var(--bg); stroke-width: 2; }
.c-hit { fill: transparent; stroke: none; cursor: pointer; }
.c-hit.is-active { fill: var(--text); fill-opacity: 0.08; }
.c-text { fill: var(--text-2); font-size: 10.5px; }
.c-value { fill: var(--text); font-size: 12px; font-weight: 600; }
.c-track { fill: none; stroke: var(--line); stroke-width: 6; }
.c-prog { fill: none; stroke: var(--accent); stroke-width: 6; }

.tip {
  position: absolute; z-index: 40; max-width: 240px; padding: 4px var(--gap-2);
  background: var(--text); color: var(--bg); border-radius: 1px;
  font-family: var(--f-mono); font-size: 0.75rem; pointer-events: none;
}

table.split { width: 100%; border-collapse: collapse; border-top: 2px solid var(--text); }
.split th, .split td { padding: 6px var(--gap-2) 6px 0; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.split thead th { font-size: 0.6875rem; font-weight: 650; font-stretch: var(--semi); color: var(--text-2); text-transform: uppercase; letter-spacing: 0.07em; }
.split tbody th { font-weight: 500; font-size: 0.9375rem; white-space: nowrap; }
.split .num { text-align: right; padding-right: 0; padding-left: var(--gap-2); font-size: 0.9375rem; }
.split td.num b { font-weight: 600; }
.split-bar { width: 45%; }
.split meter { height: 6px; }

/* ---- 8. Today ----------------------------------------------------------------------- */

.today-grid, .today-side { display: grid; gap: var(--gap-6); }
.today-grid > *, .today-side > * { min-width: 0; margin: 0; }
.open-workouts { display: grid; gap: var(--gap-4); }
.open-workouts > * { margin: 0; }

/* The open workout is the one boxed thing on the page: an entry waiting in the book. */
.open-card { padding: var(--gap-4); border: 2px solid var(--text); border-radius: var(--radius); }
.open-card > * + * { margin-top: var(--gap-3); }
.open-card > .eyebrow + .open-title { margin-top: var(--gap-1); }
.open-card.is-active { border-color: var(--accent); box-shadow: inset 6px 0 0 var(--accent); padding-left: calc(var(--gap-4) + 6px); }
.open-card.is-active .eyebrow { color: var(--accent); font-weight: 600; }
.open-title { font-size: 1.75rem; line-height: 1.05; font-weight: 800; text-transform: none; letter-spacing: 0; }
.open-title a { text-decoration: none; }
.open-title a:hover { text-decoration: underline; text-decoration-color: var(--accent); }
.open-meta { font-family: var(--f-mono); font-size: 0.875rem; color: var(--text-2); }
.open-card .btn-row .btn { flex: 1 1 auto; }

.goal-list { display: grid; gap: var(--gap-5); }
.goal > * + * { margin-top: var(--gap-2); }
.goal-title { font-weight: 700; font-size: 1.0625rem; line-height: 1.3; }
.goal-nums { font-size: 0.875rem; color: var(--text-2); }
.goal-nums b { font-weight: 700; color: var(--text); }

/* ---- 9. Workout: plan and record ----------------------------------------------------- */

/* Why this plan: a note in the margin. */
.rationale { padding: var(--gap-1) 0 var(--gap-1) var(--gap-4); border-left: 3px solid var(--accent); }
.rationale > * + * { margin-top: var(--gap-2); }
.rationale .prose { font-size: 1.125rem; }

.plan, .record { display: grid; gap: var(--gap-6); }
.plan > *, .record > * { min-width: 0; }

.block { scroll-margin-top: var(--gap-4); }
.block-head {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--gap-1) var(--gap-3);
  padding-bottom: var(--gap-2); border-bottom: 2px solid var(--text);
}
.block-label { font-size: 1.25rem; font-weight: 800; letter-spacing: 0.06em; }
/* A superset letter is boxed, the way a coach writes A, B, C down the side of a programme. */
.block-label.is-letter {
  display: grid; place-items: center; width: 40px; height: 40px;
  background: var(--text); color: var(--bg);
  font-size: 1.625rem; letter-spacing: 0; line-height: 1;
}
.block-meta { font-family: var(--f-mono); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }

/* Rows in one block share a rail down from the letter: the bracket a coach draws. */
.plan-rows, .record-rows { border-left: 2px solid var(--text); }
.plan-row, .record-row { padding: var(--gap-3) 0 var(--gap-3) var(--gap-4); border-bottom: 1px solid var(--line); scroll-margin-top: var(--gap-4); }
.plan-row:last-child, .record-row:last-child { border-bottom: 0; }
.plan-row > * + *, .record-row > * + * { margin-top: var(--gap-2); }
.plan-row-head, .ex-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--gap-1) var(--gap-3); }
.ex-name { flex: 1 1 auto; min-width: 0; font-size: 1.3125rem; line-height: 1.15; font-weight: 750; }
.ex-name a { text-decoration: none; }
.ex-name a:hover { text-decoration: underline; text-decoration-color: var(--accent); }
.plan-row-head .flag, .ex-head .flag { flex: 0 0 auto; }
.ex-letter { font-family: var(--f-mono); font-weight: 600; font-size: 0.8em; font-stretch: normal; color: var(--accent); margin-right: 0.2em; }
.ex-target { font-family: var(--f-mono); font-size: 1rem; }
.ex-rest { color: var(--text-2); }
.ex-note { font-family: var(--f-serif); font-style: italic; font-size: 1.0625rem; padding-left: var(--gap-3); border-left: 2px solid var(--accent); max-width: var(--measure); }
.cues { color: var(--text-2); }
p.cues { font-size: 1rem; }
.is-skipped .ex-name, .is-skipped .ex-target { text-decoration: line-through; text-decoration-thickness: 2px; color: var(--text-2); }

.start-form { margin-top: var(--gap-5); }
.plan-admin { padding-top: var(--gap-4); border-top: 1px solid var(--text); }
.plan-admin > * + * { margin-top: var(--gap-4); }
.plan-admin form > * + * { margin-top: var(--gap-2); }

/* The record of a finished workout: every set as a small box, inked if it was done. */
.logged { display: flex; flex-wrap: wrap; gap: 6px; }
.logged-set {
  min-width: 68px; padding: 6px var(--gap-2); border: 1.5px solid var(--text); border-radius: var(--radius);
  text-align: center; font-family: var(--f-mono); font-size: 0.875rem; line-height: 1.3;
}
.logged-set.is-done { background: var(--text); color: var(--bg); }
.logged-set.is-missed { border-style: dashed; border-color: var(--line-strong); color: var(--text-2); }

/* Dave's archived sessions: his wording is the content, so it is set as writing. */
.record-row.is-trainer .trainer-text { font-size: 1.125rem; }
.record-row.is-note { color: var(--text-2); font-style: italic; }
.record-row.is-note .prose { font-style: italic; }
.record-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0 var(--gap-4); font-size: 0.875rem; color: var(--text-2); }
.record-meta a { display: inline-flex; align-items: center; min-height: var(--tap); }
.record-meta > a:first-child { font-weight: 600; color: var(--text); }
.trainer-intro { font-weight: 400; font-size: 1.1875rem; padding-left: var(--gap-4); border-left: 3px solid var(--accent); }

/* ---- 10. Disclosures ------------------------------------------------------------------ */

summary { cursor: pointer; }
details.extra > summary, details.history > summary, details.danger > summary, details.cues > summary, details.ex-more > summary {
  display: flex; align-items: center; gap: var(--gap-2); min-height: var(--tap);
  list-style: none; font-size: 0.875rem; font-weight: 650; font-stretch: var(--semi);
  text-transform: uppercase; letter-spacing: 0.07em; font-family: var(--f-sans); font-style: normal;
}
details > summary::-webkit-details-marker { display: none; }
details.extra > summary::before, details.history > summary::before, details.danger > summary::before,
details.cues > summary::before, details.ex-more > summary::before {
  content: "+"; display: inline-grid; place-items: center; width: 20px; height: 20px; flex: none;
  border: 1.5px solid currentColor; border-radius: 1px;
  font-family: var(--f-mono); font-size: 0.9375rem; font-weight: 600; line-height: 1; letter-spacing: 0;
}
details[open].extra > summary::before, details[open].history > summary::before, details[open].danger > summary::before,
details[open].cues > summary::before, details[open].ex-more > summary::before { content: "\2212"; }
summary:hover { text-decoration: underline; text-underline-offset: 4px; }
details.extra > * + *, details.history > * + *, details.danger > * + *, details.ex-more > * + *, details.cues > * + * { margin-top: var(--gap-3); }
details.cues > summary, details.ex-more > summary { color: var(--text-2); }
details.danger > summary { color: var(--warn); }
details.danger form > * + * { margin-top: var(--gap-2); }

/* ---- 11. Live workout ------------------------------------------------------------------ */

/* A workout is one column of the book: plan, live or record, it reads top to bottom. */
body[data-page^="workout-"] .main { max-width: 52rem; }
body.is-live .main { padding-bottom: calc(220px + var(--safe-b)); }   /* room for the work bar with the rest timer open */
html:has(body.is-live) { scroll-padding-bottom: calc(170px + var(--safe-b)); }
body.is-live .site-header { display: none; }                          /* in the gym the screen belongs to the workout */

.live-head h1 { font-size: 1.875rem; }
.live-head .page-sub { font-family: var(--f-mono); font-size: 0.8125rem; text-transform: uppercase; letter-spacing: 0.04em; }
.live-hint { font-size: 0.875rem; color: var(--text-2); max-width: var(--measure); }
.wake-note::before { content: "\00b7  "; }
[data-workout-live] > * + * { margin-top: var(--gap-6); }
[data-workout-live] > .page-head + * { margin-top: var(--gap-5); }

/* One exercise. The rail on the left carries on from the block letter. */
.block[data-block] > .ex { border-left: 2px solid var(--text); padding-left: var(--gap-3); }
.ex { padding: var(--gap-4) 0 var(--gap-4); border-bottom: 1px solid var(--line); scroll-margin-top: var(--gap-4); }
.block[data-block] > .ex:last-child { border-bottom: 0; }
.ex > * + * { margin-top: var(--gap-2); }
.ex-count { font-family: var(--f-mono); font-size: 1.125rem; font-weight: 600; color: var(--text-2); white-space: nowrap; }
.ex.is-done .ex-count { color: var(--text); }
.ex.is-done .ex-count::before {
  content: ""; display: inline-block; width: 0.7em; height: 0.38em; margin: 0 0.4em 0.2em 0;
  border-left: 3px solid currentColor; border-bottom: 3px solid currentColor; transform: rotate(-45deg);
}
.ex.is-done .ex-name { color: var(--text-2); }
.ex-now { font-family: var(--f-mono); font-weight: 600; color: var(--accent); }

/* One box per set: big enough for a thumb at arm's length. Empty is a ruled box; done is inked in. */
.sets { display: grid; grid-template-columns: repeat(auto-fill, minmax(74px, 1fr)); gap: var(--gap-2); margin-top: var(--gap-3); }
.set, .set-add {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 76px; padding: var(--gap-1);
  background: var(--field); color: var(--text);
  border: 2px solid var(--text); border-radius: var(--radius);
  touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.set-no { font-family: var(--f-mono); font-size: 1.75rem; font-weight: 600; line-height: 1; }
.set-val { min-height: 1.2em; font-family: var(--f-mono); font-size: 0.75rem; line-height: 1.2; text-align: center; }

/* Next: the box the eye should land on. Vermilion frame, tinted ground, a corner flag. */
.set.is-next { border-color: var(--accent); border-width: 3px; background: var(--accent-soft); color: var(--text); }
.set.is-next::before {
  content: ""; position: absolute; top: -3px; left: -3px; width: 0; height: 0;
  border-top: 16px solid var(--accent); border-right: 16px solid transparent;
}

/* Done: inked in solid, with a tick in the corner. */
.set[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: var(--bg); }
.set::after {
  content: ""; position: absolute; top: 8px; right: 7px; width: 13px; height: 7px;
  border-left: 3px solid currentColor; border-bottom: 3px solid currentColor; transform: rotate(-45deg);
  clip-path: inset(0 0 0 100%);
}
.set[aria-pressed="true"]::after { clip-path: inset(0 0 0 0); }
/* Not saved yet: the ink is still wet. Hatched instead of solid, with a dashed frame. */
.set.is-pending { border-style: dashed; }
.set[aria-pressed="true"].is-pending {
  background: repeating-linear-gradient(-45deg, var(--text) 0 5px, color-mix(in srgb, var(--text) 72%, var(--bg)) 5px 8px);
  border-color: var(--text); outline: 2px dashed var(--warn); outline-offset: 2px;
}
.set:active { transform: scale(0.96); }
.set-add {
  border-style: dashed; border-width: 1.5px; border-color: var(--line-strong); background: none; color: var(--text-2);
  font-size: 0.8125rem; font-weight: 700; font-stretch: var(--semi); text-transform: uppercase; letter-spacing: 0.08em;
}
.set-add:hover { border-color: var(--text); color: var(--text); }

/* The bar that replaces the tab bar while a workout is under way. */
.workbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding-bottom: var(--safe-b);
  background: var(--bg); border-top: 2px solid var(--text);
}
.workbar > * { max-width: var(--page); margin: 0 auto; }
.workbar-main { display: flex; align-items: center; gap: var(--gap-4); padding: var(--gap-2) var(--gap-4); }
.workbar-progress { flex: 1; min-width: 0; }
.workbar-progress > * + * { margin-top: 6px; }
.workbar-count { font-family: var(--f-mono); font-size: 0.8125rem; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.04em; }
.workbar-count b { font-size: 1.375rem; color: var(--text); letter-spacing: -0.02em; }
.workbar-count [data-progress-total] { color: var(--text); font-weight: 600; }
.workbar .btn-primary { min-height: 52px; padding: 0 var(--gap-5); }
.workbar .sync-note { position: static; margin: var(--gap-2) auto 0; width: calc(100% - 2 * var(--gap-2)); }

/* Rest: the whole strip goes dark (light in the night edition) so it reads from across the room. */
.rest {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--gap-1) var(--gap-3);
  padding: var(--gap-2) var(--gap-4) var(--gap-3);
  background: var(--text); color: var(--bg);
}
.rest-label { font-size: 0.8125rem; font-weight: 750; font-stretch: var(--semi); text-transform: uppercase; letter-spacing: 0.1em; }
.rest-time { font-family: var(--f-mono); font-size: 2.5rem; font-weight: 600; line-height: 1; letter-spacing: -0.03em; min-width: 4ch; }
.rest-time { margin-right: auto; }
.rest-for { order: 5; flex: 1 1 100%; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.875rem; opacity: 0.8; }
.rest .btn { color: inherit; border-color: currentColor; background: none; }
.rest .btn:hover { background: rgb(127 127 127 / 0.2); }
.workbar { --col: 52rem; }   /* the workout column, so the bar lines up with the sets above it */
.workbar > * { max-width: var(--col); }
.workbar > .rest { max-width: none; padding-inline: max(var(--gap-4), calc((100% - var(--col)) / 2 + var(--gap-4))); }
.rest.is-over { background: var(--accent); color: var(--on-accent); }
.rest.is-over .rest-for { color: inherit; opacity: 1; }

.finish { scroll-margin-top: var(--gap-4); }
.finish > h2 { border-top-width: 3px; }

/* ---- 12. Change sheet -------------------------------------------------------------------- */

dialog.sheet {
  width: 100%; max-width: 100%; max-height: 92dvh; margin: auto 0 0; padding: var(--gap-4) var(--gap-4) calc(var(--gap-4) + var(--safe-b));
  background: var(--bg); color: var(--text);
  border: 0; border-top: 4px solid var(--accent); border-radius: 0; overflow-y: auto;
}
dialog.sheet::backdrop { background: var(--scrim); }
.sheet h2 { font-size: 1.5rem; text-transform: none; letter-spacing: 0; font-weight: 800; line-height: 1.1; padding-bottom: var(--gap-3); border-bottom: 1px solid var(--line); }
.sheet form > * + * { margin-top: var(--gap-4); }
.stepper > * + * { margin-top: 6px; }
.stepper-row input::placeholder { font-size: 1rem; font-weight: 400; letter-spacing: 0.04em; text-transform: uppercase; }
.stepper label, .sheet legend { font-size: 0.8125rem; text-transform: uppercase; letter-spacing: 0.07em; font-stretch: var(--semi); }
.stepper-row { display: flex; gap: 6px; }
.stepper-row input {
  flex: 1 1 0; min-width: 0; min-height: 60px; text-align: center;
  font-family: var(--f-mono); font-size: 1.625rem; font-weight: 600; letter-spacing: -0.02em;
  border: 2px solid var(--text);
}
.step {
  flex: 0 0 auto; min-width: 56px; min-height: 60px; padding: 0 var(--gap-2);
  background: none; border: 1.5px solid var(--line-strong); border-radius: var(--radius);
  font-family: var(--f-mono); font-size: 1rem; font-weight: 600; touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.step:hover { border-color: var(--text); background: var(--surface); }
.step:active { background: var(--text); color: var(--bg); }
.sheet-actions { display: grid; grid-template-columns: 1fr 2fr; gap: var(--gap-2); padding-top: var(--gap-2); }
.sheet-actions .btn { min-height: 56px; }

/* ---- 13. Other pages ---------------------------------------------------------------------- */

/* Sign in: the cover of the book. */
.login { max-width: 24rem; margin: 0 auto; padding: 12vh var(--gap-4) var(--gap-6); }
.login > * + * { margin-top: var(--gap-4); }
.login-cover { padding: var(--gap-5) var(--gap-4) var(--gap-4); border: 3px solid var(--text); outline: 1px solid var(--text); outline-offset: 3px; text-align: center; }
.login .brand { flex-direction: column; gap: var(--gap-3); font-size: 2.25rem; letter-spacing: 0.14em; }
.login .brand-mark { width: 56px; height: 56px; }
.login-sub { margin-top: var(--gap-3); color: var(--text-2); font-family: var(--f-mono); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.2em; }
.login .form { margin-top: var(--gap-6); }

/* Log: a ledger. Day in the mono column, entry, then the stamps. */
.log-row .row-link {
  display: grid; grid-template-columns: 4.25rem minmax(0, 1fr); align-items: start; gap: 2px var(--gap-2);
  padding: var(--gap-1) 0;
}
.log-row .log-meta { grid-column: 2; }
.log-row .log-meta:empty { display: none; }
.log-day {
  padding-top: 3px;
  font-family: var(--f-mono); font-size: 0.8125rem; text-transform: uppercase; letter-spacing: 0.02em; color: var(--text-2);
}
.log-main { flex: 1 1 10rem; min-width: 0; }
.log-title, .log-detail { display: block; }
.log-title { font-size: 1.0625rem; line-height: 1.3; }
.log-detail { font-size: 0.875rem; color: var(--text-2); }
.log-meta { display: flex; align-items: center; gap: var(--gap-2); font-size: 0.8125rem; color: var(--text-2); }
.log-rpe { font-family: var(--f-mono); font-size: 0.75rem; text-transform: uppercase; }
.month > h2 { display: flex; align-items: baseline; }

/* Tests */
.test-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--gap-2); }
.test-head h3 { font-size: 1.375rem; }
.test { scroll-margin-top: var(--gap-4); }
.protocol { font-family: var(--f-serif); font-size: 1rem; max-width: var(--measure); line-height: 1.5; }
.protocol .meta { font-family: var(--f-sans); font-size: 0.8125rem; }
.protocol-label { font-family: var(--f-sans); font-weight: 700; font-size: 0.75rem; font-stretch: var(--semi); text-transform: uppercase; letter-spacing: 0.07em; margin-right: 0.3em; }
.test-form > * + * { margin-top: var(--gap-2); }
.history .row-main b { font-family: var(--f-mono); font-weight: 600; margin-right: 0.4em; }

/* Exercises */
.filters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--gap-3); align-items: end; }
.filters > * { margin: 0; }
.filters .field-grow, .filters .field-actions { grid-column: 1 / -1; }
.filters label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.07em; font-stretch: var(--semi); color: var(--text-2); }
.field-actions { display: flex; align-items: center; gap: var(--gap-4); }
.field-actions > * { margin: 0; }
.field-actions .btn { min-height: 48px; }
.field-actions a { display: inline-flex; align-items: center; min-height: var(--tap); font-size: 0.875rem; font-weight: 600; }
.result-count { font-size: 0.875rem; color: var(--text-2); }
/* An exercise's history is a ledger of dates. */
[aria-labelledby="hist-h"] a.row-main { font-family: var(--f-mono); font-size: 0.9375rem; font-weight: 600; text-decoration: none; }
[aria-labelledby="hist-h"] a.row-main:hover { text-decoration: underline; text-decoration-color: var(--accent); }
.ex-row .row-meta { flex: 1 1 100%; }
.video-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--gap-1) var(--gap-3); }

/* Food */
.day-nav { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: var(--gap-2); padding: var(--gap-1) 0; border-bottom: 1px solid var(--line); }
.day-nav > :first-child { justify-self: start; }
.day-nav > :last-child { justify-self: end; }
.day-nav .btn { font-family: var(--f-mono); text-transform: none; letter-spacing: 0; font-weight: 600; border-color: var(--line-strong); }
.day-now { text-align: center; }
.day-now b { font-size: 1.125rem; font-weight: 750; font-stretch: var(--cond); text-transform: uppercase; letter-spacing: 0.06em; }
.day-now .meta { display: block; font-family: var(--f-mono); font-size: 0.75rem; text-transform: uppercase; }
.usuals { display: flex; flex-wrap: wrap; gap: var(--gap-2); }
.food-row form { flex: 0 0 auto; }
.food-row .row-meta { font-family: var(--f-mono); font-size: 0.75rem; margin-top: 2px; }
.food-row .row-meta b { font-weight: 600; color: var(--text); }

/* Settings */
.targets > * + * { margin-top: var(--gap-2); }
.targets-label { font-weight: 650; font-size: 0.9375rem; }
.status-line { padding-left: var(--gap-3); border-left: 4px solid var(--text); }
.status-line.is-error { border-left-color: var(--warn); }
.status-line time { font-family: var(--f-mono); font-size: 0.875rem; }

/* ---- 14. Wide screens ------------------------------------------------------------------------ */

@media (min-width: 480px) {
  .seg-10 { grid-template-columns: repeat(10, minmax(0, 1fr)); }
  .seg-opt { flex: 0 1 auto; }
  .seg-opt > span { min-width: 56px; }
  .field-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .sets { grid-template-columns: repeat(auto-fill, minmax(92px, 108px)); }
  .set, .set-add { min-height: 84px; }
}

@media (min-width: 640px) {
  .chart-grid, .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters { grid-template-columns: 2fr repeat(3, minmax(0, 1fr)) auto; }
  .filters .field-grow, .filters .field-actions { grid-column: auto; }
  .ex-row .row-meta { flex: 0 1 auto; text-align: right; }
  /* The sheet becomes a centred dialog. */
  dialog.sheet { width: 30rem; margin: auto; border: 2px solid var(--text); border-top: 6px solid var(--accent); padding: var(--gap-5); }
  .form:not(.filters):not(.test-form) { max-width: 38rem; }
  .log-row .row-link { grid-template-columns: 5.5rem minmax(0, 1fr) auto; gap: var(--gap-4); }
  .log-row .log-meta { grid-column: 3; padding-top: 3px; }
  .start-form .btn-big { max-width: 24rem; }
}

@media (min-width: 760px) {
  /* Everything fits in the header: no tab bar. */
  .site-nav { display: block; margin-left: auto; }
  .site-header { padding: 0 var(--gap-5); min-height: 64px; border-bottom: 2px solid var(--text); }
  .site-nav a { margin-bottom: -2px; padding: 0 var(--gap-2); min-height: 62px; }
  .tabbar { display: none; }
  .main { padding: var(--gap-6) var(--gap-5) var(--gap-6); }
  .main > * + * { margin-top: var(--gap-6); }
  html { scroll-padding-bottom: var(--gap-5); }
  .sync-note { bottom: var(--gap-3); left: auto; right: var(--gap-4); max-width: 26rem; }
  body.is-live .site-header { display: flex; }
  h1 { font-size: 3.25rem; letter-spacing: -0.01em; }
  .live-head h1 { font-size: 2.75rem; }
  h2 { font-size: 1.125rem; }
  .workbar-main { padding: var(--gap-3) var(--gap-5); }
}

@media (min-width: 960px) {
  .today-grid { grid-template-columns: minmax(0, 6fr) minmax(0, 5fr); align-items: start; gap: var(--gap-6) 64px; }
  .chart-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--gap-6) var(--gap-5); }
  .open-workouts { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
  /* Goals on the wide pages sit side by side instead of stretching a bar across the screen. */
  #goals .goal-list, #active-h ~ .goal-list { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--gap-6) var(--gap-5); align-items: start; }
}

/* ---- 15. Motion, print ------------------------------------------------------------------------ */

/* The set tick is the one thing that moves: a quick press, the ink lands, the tick is drawn.
   Transitions, not keyframes, so boxes already done don't replay it when the page loads. */
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
  .set { transition: background-color 120ms ease-out, border-color 120ms ease-out, color 120ms ease-out, transform 90ms ease-out; }
  .set::after { transition: clip-path 160ms 90ms ease-out; }
  .btn, .seg-opt > span, .tab, .pager a { transition: background-color 120ms, color 120ms, border-color 120ms; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
  .set:active { transform: none; }
}

@media print {
  :root { --bg: #fff; --text: #000; --text-2: #444; --line: #bbb; --field: #fff; }
  .site-header, .tabbar, .workbar, .sync-note, .skip-link, .row-actions, .plan-admin, .start-form { display: none !important; }
  .main { padding-bottom: 0; }
}
