/*
VOICE: a gym logbook — terse, numeric, fast to read between sets.
IDEA: a training ledger page; columns of weight × reps, ruled lines.
PICTURE: the live set logger is the picture; charts are clean ruled plots.
COLOUR and TYPE: plate red accent on graphite or paper white; Barlow Condensed for numbers, Inter for text.
LAYOUT: single column phone-first, bottom tab bar, sheets slide up from the bottom.
*/
:root {
  color-scheme: light dark;
  --bg: light-dark(#f3f4f6, #101215);
  --card: light-dark(#ffffff, #1a1d22);
  --card2: light-dark(#eceef2, #23272e);
  --ink: light-dark(#14161a, #eef0f3);
  --muted: light-dark(#5d6573, #9aa3b2);
  --line: light-dark(#dfe2e8, #2c313a);
  --accent: #e23a2c;
  --accent-ink: #ffffff;
  --good: light-dark(#13804b, #38c27a);
  --blue: light-dark(#1d5fd6, #6ea2ff);
  --num: 'Barlow Condensed', 'Arial Narrow', system-ui, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; min-width: 0; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 16px/1.45 Inter, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; overflow-x: clip; overscroll-behavior-y: contain; }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 28px; line-height: 1.1; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 18px; margin: 22px 0 8px; }
h3 { font-size: 16px; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-family: var(--num); font-weight: 600; font-variant-numeric: tabular-nums; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grow { flex: 1; }
.hidden { display: none !important; }

#app { max-width: 720px; margin: 0 auto; padding: calc(16px + var(--safe-t)) 16px calc(96px + var(--safe-b)); }
.top { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 14px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.card.tight { padding: 10px 12px; }
.list { background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; margin-bottom: 12px; }
.list > * { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; min-height: 52px; width: 100%; background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left; }
.list > *:last-child { border-bottom: 0; }
a.list { text-decoration: none; color: inherit; }
.list .sub { font-size: 13px; color: var(--muted); }
.chev::after { content: '›'; color: var(--muted); font-size: 22px; margin-left: auto; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-weight: 600; cursor: pointer; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--accent); }
.btn.block { width: 100%; }
.btn.big { min-height: 56px; font-size: 18px; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .list > *:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.btn:disabled { opacity: .45; }
.iconbtn { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-size: 20px; font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }

label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=number], input[type=date], input[type=time], input[type=search], select, textarea {
  width: 100%; min-height: 44px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-size: 16px;
}
textarea { min-height: 72px; resize: vertical; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; scrollbar-width: none; }
.chip { flex: none; min-height: 36px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); font-size: 14px; cursor: pointer; }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.seg { display: flex; background: var(--card2); border-radius: 12px; padding: 3px; margin-bottom: 12px; }
.seg button { flex: 1; min-height: 38px; border: 0; background: transparent; border-radius: 9px; font-weight: 600; font-size: 14px; cursor: pointer; }
.seg button.on { background: var(--card); box-shadow: 0 1px 3px rgba(0,0,0,.15); }

/* tab bar */
nav.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--card); border-top: 1px solid var(--line); display: flex; justify-content: center; padding-bottom: var(--safe-b); }
nav.tabs a { flex: 1; max-width: 140px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 6px; font-size: 12px; color: var(--muted); text-decoration: none; }
nav.tabs a svg { width: 24px; height: 24px; }
nav.tabs a.on { color: var(--accent); font-weight: 600; }

/* logger */
.exhead { display: flex; align-items: flex-start; gap: 8px; }
.exhead h3 { font-size: 18px; }
.hint { font-size: 13px; color: var(--muted); }
.sets { width: 100%; border-collapse: collapse; margin: 8px 0; }
.sets td, .sets th { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.sets th { font-size: 12px; color: var(--muted); font-weight: 500; }
.sets td:first-child, .sets th:first-child { text-align: left; color: var(--muted); width: 36px; }
.sets td.n { font-family: var(--num); font-size: 22px; font-weight: 600; }
.sets tr.warm td.n { color: var(--muted); }
.pr { display: inline-block; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 6px; vertical-align: middle; }
.entry { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 10px; margin-top: 8px; }
.stepper { display: flex; align-items: center; gap: 4px; background: var(--card2); border-radius: 12px; padding: 4px; }
.stepper input { text-align: center; font-family: var(--num); font-size: 26px; font-weight: 600; border: 0; background: transparent; min-height: 44px; padding: 0; }
.stepper .iconbtn { flex: none; width: 40px; height: 44px; background: var(--card); }
.stepper-label { font-size: 12px; color: var(--muted); text-align: center; margin-bottom: 2px; }

/* rest timer */
.rest { position: fixed; left: 12px; right: 12px; bottom: calc(70px + var(--safe-b)); z-index: 25; max-width: 696px; margin: 0 auto; background: var(--ink); color: var(--bg); border-radius: 16px; padding: 10px 12px; display: flex; align-items: center; gap: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.3); }
.rest .t { font-family: var(--num); font-size: 34px; font-weight: 700; min-width: 86px; }
.rest .bar { position: absolute; left: 0; bottom: 0; height: 4px; background: var(--accent); border-radius: 0 0 0 16px; transition: width 1s linear; }
.rest .btn { background: transparent; color: inherit; border-color: color-mix(in srgb, var(--bg) 30%, transparent); min-height: 40px; padding: 0 12px; }
.rest.done { background: var(--accent); color: #fff; }

/* sheet */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 720px; max-height: 92vh; overflow-y: auto; border-radius: 18px 18px 0 0; padding: 8px 16px calc(20px + var(--safe-b)); animation: up .18s ease-out; }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 10px; }
@keyframes up { from { transform: translateY(40px); opacity: .4; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } .rest .bar { transition: none; } }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(140px + var(--safe-b)); z-index: 60; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 90vw; }

/* stats & charts */
.stats { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 8px; margin-bottom: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
.stat .v { font-family: var(--num); font-size: clamp(22px, 6vw, 30px); font-weight: 700; line-height: 1.05; }
.stat .k { font-size: 12px; color: var(--muted); }
.fig { position: relative; height: 220px; }
.fig > svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.fig text { fill: var(--muted); font-size: 11px; font-family: Inter, system-ui, sans-serif; }
.fig .grid { stroke: var(--line); stroke-width: 1; }
.fig .ln { fill: none; stroke: var(--accent); stroke-width: 2.25; stroke-linejoin: round; }
.fig .ln2 { fill: none; stroke: var(--blue); stroke-width: 2; stroke-dasharray: 4 3; }
.fig .area { fill: color-mix(in srgb, var(--accent) 12%, transparent); }
.fig .dot { fill: var(--accent); }
.fig .bar { fill: var(--blue); }
.fig .tip { fill: var(--ink); font-weight: 600; font-size: 12px; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th, table.t td { padding: 7px 6px; border-bottom: 1px solid var(--line); text-align: left; }
table.t td.r, table.t th.r { text-align: right; white-space: nowrap; }
.scroll { overflow-x: auto; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0,1fr)); gap: 3px; }
.cal div { aspect-ratio: 1; border-radius: 6px; background: var(--card2); display: flex; align-items: center; justify-content: center; font-size: 12px; color: var(--muted); }
.cal div.has { background: var(--accent); color: #fff; font-weight: 700; cursor: pointer; }
.cal div.blank { background: transparent; }
.cal div.today { outline: 2px solid var(--blue); }
