/* 5/3/1: one stylesheet. Colour tokens on :root, re-stepped for dark mode. */
:root {
  color-scheme: light;
  --bg: #f4f3f0;
  --surface: #fcfcfb;
  --surface-2: #efeee9;
  --border: #dcdad3;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #7a7974;
  --accent: #1c5cab;
  --accent-ink: #ffffff;
  --danger: #b42318;
  --warn-bg: #fff4d6;
  --warn-ink: #5c4300;
  --ok: #08752f;
  /* Lift identity: slots 1–4 of the validated categorical palette, in order. */
  --squat: #2a78d6;
  --bench: #eb6834;
  --deadlift: #1baf7a;
  --press: #eda100;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #242422;
    --border: #3a3936;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #93928b;
    --accent: #6da7ec;
    --accent-ink: #0b0b0b;
    --danger: #ff8a80;
    --warn-bg: #3a2f10;
    --warn-ink: #ffe3a3;
    --ok: #5fd38d;
    --squat: #3987e5;
    --bench: #d95926;
    --deadlift: #199e70;
    --press: #c98500;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #242422; --border: #3a3936;
  --text: #f0efec; --text-2: #c3c2b7; --text-3: #93928b; --accent: #6da7ec; --accent-ink: #0b0b0b;
  --danger: #ff8a80; --warn-bg: #3a2f10; --warn-ink: #ffe3a3; --ok: #5fd38d;
  --squat: #3987e5; --bench: #d95926; --deadlift: #199e70; --press: #c98500;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(5rem + env(safe-area-inset-bottom));
}
main { max-width: 56rem; margin: 0 auto; padding: 1rem 16px; }
a { color: var(--accent); }
h1, h2 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
p { margin: .5rem 0; }
code { background: var(--surface-2); padding: .1rem .35rem; border-radius: 4px; }
.page-title { margin: .5rem 0 1rem; }
.muted { color: var(--text-2); }
.small { font-size: .875rem; }
.break { word-break: break-all; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.eyebrow { text-transform: uppercase; letter-spacing: .06em; font-size: .75rem; color: var(--text-2); margin: 0 0 .25rem; }
.lead { font-size: 1.1rem; color: var(--text-2); margin-top: 0; }

/* header + tab bar: bottom on phones, top on wide screens */
.top { background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { display: block; max-width: 56rem; margin: 0 auto; padding: .6rem 16px; font-weight: 800; font-size: 1.15rem; color: var(--text); text-decoration: none; }
.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: flex;
  background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
}
.tabs a { flex: 1; display: flex; align-items: center; justify-content: center; height: 3rem; padding: 0 .2rem; font-size: .85rem; color: var(--text-2); text-decoration: none; }
.tabs a[aria-current] { color: var(--accent); font-weight: 700; box-shadow: inset 0 3px 0 var(--accent); }
@media (min-width: 720px) {
  body { padding-bottom: 2rem; }
  .top { display: flex; align-items: center; justify-content: space-between; padding: 0 max(16px, calc((100vw - 56rem) / 2 + 16px)); }
  .brand { margin: 0; padding: .75rem 0; }
  .tabs { position: static; border: 0; padding: 0; gap: .25rem; }
  .tabs a { flex: none; height: auto; padding: 1rem .75rem; font-size: .95rem; }
  .tabs a[aria-current] { box-shadow: inset 0 -3px 0 var(--accent); }
}

/* cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.card.narrow { max-width: 28rem; margin: 3rem auto; }
.card.hero h1 { font-size: 1.9rem; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; }
.flash { background: var(--surface); border-left: 4px solid var(--ok); padding: .6rem .9rem; border-radius: 6px; }
.warn { background: var(--warn-bg); color: var(--warn-ink); padding: .6rem .8rem; border-radius: 6px; }
.error { color: var(--danger); font-weight: 600; }
.notes { white-space: pre-wrap; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: .25rem 1rem; margin: .75rem 0; }
.facts dt { color: var(--text-2); }
.facts dd { margin: 0; }

/* lift identity swatch: colour is never the only cue, the name is always next to it */
.swatch { display: inline-block; width: .7rem; height: .7rem; border-radius: 3px; margin-right: .4rem; vertical-align: baseline; background: var(--lift, var(--text-3)); }
.lift-squat { --lift: var(--squat); }
.lift-bench { --lift: var(--bench); }
.lift-deadlift { --lift: var(--deadlift); }
.lift-press { --lift: var(--press); }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; margin-bottom: 1rem; }
@media (min-width: 720px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem; display: flex; flex-direction: column; gap: .15rem; }
.tile-label { font-size: .85rem; color: var(--text-2); }
.tile-value { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile-value small { font-size: .8rem; font-weight: 400; color: var(--text-2); }
.tile-sub { font-size: .8rem; color: var(--text-2); }

/* forms */
label { display: block; font-size: .9rem; color: var(--text-2); }
input, select, textarea {
  display: block; width: 100%; margin-top: .25rem; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .6rem .7rem; min-height: 2.75rem;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type="checkbox"], input[type="radio"] { display: inline; width: auto; min-height: 0; margin: 0 .4rem 0 0; accent-color: var(--accent); }
.check { display: flex; align-items: center; color: var(--text); padding: .3rem 0; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { padding: 0; margin-bottom: .5rem; font-weight: 600; color: var(--text); }
fieldset > .fields { margin-top: .5rem; }
.stack > * + * { margin-top: .9rem; }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr)); gap: .9rem .75rem; align-items: end; }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
button, .button {
  display: inline-block; font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent); border-radius: 8px; padding: .65rem 1.2rem; min-height: 2.75rem;
}
button.secondary, .button.secondary { background: transparent; color: var(--accent); }
button.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
button.big, .button.big { width: 100%; text-align: center; padding: .9rem; font-size: 1.1rem; }
.small-button { padding: .4rem .9rem; min-height: 2.25rem; margin-top: .5rem; }
details summary { cursor: pointer; font-weight: 600; padding: .25rem 0; }
.card > * + details, .stack + details, form + details { margin-top: 1.25rem; }
details[open] summary { margin-bottom: .75rem; }

/* template picker */
.templates { display: grid; gap: .5rem; }
.template { display: flex; gap: .5rem; align-items: flex-start; color: var(--text); padding: .6rem; border: 1px solid var(--border); border-radius: 8px; }
.template:has(input:checked) { border-color: var(--accent); background: var(--surface-2); }
.template input { margin-top: .3rem; }
.template-meta { display: block; margin: .1rem 0 .3rem; }
.template-desc { display: block; }
.phases { margin: .3rem 0 0; padding-left: 1.2rem; }
.review { display: grid; grid-template-columns: 1fr 9rem; gap: .75rem; align-items: end; padding: .6rem 0; border-bottom: 1px solid var(--border); }
.review > div { display: flex; flex-direction: column; gap: .15rem; }

/* number fields with − / + */
.field { display: flex; flex-direction: column; gap: .25rem; min-width: 0; }
.field-label { font-size: .9rem; color: var(--text-2); }
.stepper { display: flex; align-items: stretch; min-width: 0; }
.stepper input {
  margin: 0; min-width: 0; flex: 1; text-align: center; border-radius: 0;
  font-size: 1.1rem; font-variant-numeric: tabular-nums;
}
.step {
  flex: none; width: 2.75rem; min-height: 2.75rem; padding: 0; font-size: 1.3rem; font-weight: 500; line-height: 1;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  -webkit-user-select: none; user-select: none; touch-action: manipulation;
}
.step:first-child { border-radius: 8px 0 0 8px; border-right: 0; }
.step:last-child { border-radius: 0 8px 8px 0; border-left: 0; }
.step:active { background: var(--border); }

/* workout logging */
.plain { list-style: none; padding: 0; margin: .5rem 0 1rem; }
.plan-line { padding: .2rem 0; }
.plan-line .muted { display: block; font-variant-numeric: tabular-nums; }
.lift-block .card-head { margin-bottom: .25rem; }
.lift-block .card-head h2 { margin: 0; }
.set-group { margin: 1rem 0 0; padding-bottom: .4rem; font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-2); }
.set { padding: .75rem 0; border-top: 1px solid var(--border); }
.set-head { display: flex; align-items: center; gap: .75rem; margin-bottom: .5rem; min-height: 2.75rem; }
.set-meta { flex: 1; display: flex; align-items: baseline; flex-wrap: wrap; gap: .25rem .5rem; min-width: 0; }
.set-meta .pct { font-size: .85rem; color: var(--text-2); font-variant-numeric: tabular-nums; }
.set-meta b { font-size: 1.05rem; }
.badge { align-self: center; font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--accent); border: 1px solid currentColor; border-radius: 999px; padding: .05rem .5rem; }
.badge.quiet { color: var(--text-2); }
.set .plates { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.set-inputs { display: grid; grid-template-columns: minmax(0, 1.1fr) auto minmax(0, 1fr); gap: .5rem; align-items: center; }
.times { color: var(--text-3); font-size: 1.1rem; }
.set.amrap .set-meta b { color: var(--accent); }
.set.amrap input[name$="-reps"] { border-color: var(--accent); }
.tick { flex: none; width: 2.75rem; height: 2.75rem; padding: 0; font-size: 1.2rem; background: transparent; color: var(--text-3); border: 1px solid var(--border); border-radius: 999px; }
.set.done .tick { background: var(--ok); border-color: var(--ok); color: #fff; }
.set.done .stepper input { background: var(--surface-2); }
.assistance { display: grid; gap: .5rem; margin: .75rem 0; }
.asst { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1.4fr); gap: .5rem; }
.asst input { margin: 0; }
.asst-head { font-size: .8rem; color: var(--text-2); }
.actions { display: flex; flex-direction: column; gap: .75rem; margin-top: 1rem; }

/* rest bar: pinned above the tab bar on phones, at the bottom on wide screens */
body.has-restbar { padding-bottom: calc(9rem + env(safe-area-inset-bottom)); }
.restbar {
  position: fixed; left: 0; right: 0; bottom: calc(3rem + 1px + env(safe-area-inset-bottom)); z-index: 9;
  display: flex; align-items: center; gap: .5rem; padding: .5rem 16px;
  background: var(--surface); border-top: 1px solid var(--border); box-shadow: 0 -2px 8px rgb(0 0 0 / .06);
}
.rest-status { flex: 1; display: flex; align-items: baseline; gap: .5rem; min-width: 0; }
.rest-label { font-size: .85rem; color: var(--text-2); }
.rest-label { white-space: nowrap; }
@media (max-width: 420px) { .rest-hint { display: none; } }
.rest-hint { font-size: .85rem; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.restbar output { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text-3); }
.restbar.running output { color: var(--text); }
.restbar.over output, .restbar.over .rest-label { color: var(--danger); }
.restbar button { padding: .5rem .8rem; min-height: 2.75rem; }
@media (min-width: 720px) {
  body.has-restbar { padding-bottom: 6rem; }
  .restbar { bottom: 0; padding-left: max(16px, calc((100vw - 56rem) / 2 + 16px)); padding-right: max(16px, calc((100vw - 56rem) / 2 + 16px)); }
}

/* lists & tables */
.list { list-style: none; padding: 0; margin: 0; }
.list li + li { border-top: 1px solid var(--border); }
.item { display: block; padding: .7rem 0; color: var(--text); text-decoration: none; }
.item-main { display: block; }
.item-main .muted { display: block; font-size: .95rem; margin-top: .1rem; }
.item-sub { display: block; margin-top: .2rem; font-size: .875rem; color: var(--text-2); font-variant-numeric: tabular-nums; }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; margin: .5rem 0 1rem; }
.chips a { padding: .35rem .8rem; border: 1px solid var(--border); border-radius: 999px; text-decoration: none; color: var(--text-2); font-size: .9rem; }
.chips a[aria-current] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.scroll-x { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
thead th { font-size: .8rem; color: var(--text-2); font-weight: 600; }
.num { text-align: right; }
.grid th .sub { display: block; font-size: .78rem; font-weight: 400; color: var(--text-2); }
.grid thead th { vertical-align: bottom; }
.grid tbody th { white-space: nowrap; }
.grid td { white-space: nowrap; }
.grid .done { color: var(--ok); text-decoration: none; font-weight: 600; }
.grid .todo { color: var(--text-2); }
.amrap-row td { font-weight: 600; }
.logged-sets { list-style: none; margin: .5rem 0 0; padding: 0; }
.logged-sets li { display: grid; grid-template-columns: 6.5rem 1fr auto; gap: .5rem; align-items: baseline; padding: .5rem 0; border-top: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.logged-sets li.amrap-row .ls-set { font-weight: 700; }
.ls-set .muted { font-weight: 400; white-space: nowrap; }
.ls-e1rm { color: var(--text-2); text-align: right; }
.actions-row { display: flex; gap: .75rem; align-items: center; margin-bottom: 1rem; }

/* charts */
.chart-box { position: relative; height: 240px; }
.chart-box.tall { height: 320px; }
.chart-box .empty { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; margin: 0; }
.multiples { display: grid; gap: 0 1rem; }
@media (min-width: 720px) { .multiples { grid-template-columns: 1fr 1fr; } }
.template:not(:has(input:checked)) .phases { display: none; }

/* "+" sets: reps to beat your best, and the live estimate for the reps typed */
.pr-line { display: flex; justify-content: space-between; align-items: baseline; gap: .25rem .75rem; flex-wrap: wrap; margin-top: .5rem; font-size: .95rem; }
.pr-target b { color: var(--accent); }
.pr-live { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--text-2); white-space: nowrap; }
.pr-live.is-pr { color: var(--ok); font-weight: 700; }
