:root {
  --bg: #101114;
  --surface: #191a1e;
  --surface-2: #24262b;
  --line: #34363d;
  --text: #f3f3f1;
  --text-2: #c9c9c3;
  --muted: #a2a29b;
  --accent: #5ea2f2;
  --accent-ink: #07121f;
  --accent-soft: #1b2c44;
  --good: #57cf6b;
  --warn-bg: #3a2e12;
  --warn-ink: #f5cf7a;
  --danger: #f27c7c;
  --series: #5ea2f2;
  --grid: #2c2d33;
  --radius: 14px;
  --nav-h: 64px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f4f4f1; --surface: #fcfcfb; --surface-2: #efeee9; --line: #deddd6;
  --text: #0b0b0b; --text-2: #52514e; --muted: #63625d;
  --accent: #1f6bc7; --accent-ink: #ffffff; --accent-soft: #e3eefb;
  --good: #0a7d0a; --warn-bg: #fff4dc; --warn-ink: #6b4800; --danger: #c22f2f;
  --series: #1f6bc7; --grid: #e6e5df;
  color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root[data-theme="system"] {
    --bg: #f4f4f1; --surface: #fcfcfb; --surface-2: #efeee9; --line: #deddd6;
    --text: #0b0b0b; --text-2: #52514e; --muted: #63625d;
    --accent: #1f6bc7; --accent-ink: #ffffff; --accent-soft: #e3eefb;
    --good: #0a7d0a; --warn-bg: #fff4dc; --warn-ink: #6b4800; --danger: #c22f2f;
    --series: #1f6bc7; --grid: #e6e5df;
    color-scheme: light;
  }
}

* { 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.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.6rem; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; margin-bottom: 6px; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.view { max-width: 640px; margin: 0 auto; padding: 16px 16px calc(var(--nav-h) + 32px + env(safe-area-inset-bottom)); }
.loading { padding: 40px 0; text-align: center; }
.stack > * + * { margin-top: 14px; }
.stack-s > * + * { margin-top: 8px; }
.row { display: flex; align-items: center; }
.row.between { justify-content: space-between; gap: 10px; }
.gap { gap: 10px; } .gap-s { gap: 6px; } .wrap { flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.col { display: flex; flex-direction: column; }
.right { text-align: right; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; } .tiny { font-size: 0.78rem; }
.mono { font-family: ui-monospace, Consolas, monospace; white-space: pre-wrap; word-break: break-word; }
.plain { list-style: none; padding: 0; margin: 4px 0; }
.plain li { padding: 3px 0; }
ul { padding-left: 18px; margin: 6px 0; }

.page-head { padding-top: 6px; }
.page-head p { margin-top: 4px; }
.section-title { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 18px 0 6px; }
.eyebrow { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: block; color: inherit; }
.card.tight { padding: 10px 12px; }
.card.flat { background: var(--surface-2); border: 0; }
.card.focused { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.card.empty { text-align: center; padding: 28px 14px; }
.warn-card { background: var(--warn-bg); color: var(--warn-ink); border-color: transparent; }
.hero-card .hero-title, .card .hero-title { font-size: 1.35rem; font-weight: 700; margin: 4px 0 8px; }
.hero-card .btn { margin-top: 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text); font-weight: 600; cursor: pointer; text-align: center;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--danger); }
.btn.block { display: flex; width: 100%; }
.btn.small { min-height: 38px; padding: 0 12px; font-size: 0.875rem; }
.btn.big { min-height: 56px; font-size: 1.1rem; }
.link { background: none; border: 0; color: var(--accent); padding: 6px 2px; cursor: pointer; min-height: 32px; }
.link.danger { color: var(--danger); }
.icon-btn { background: none; border: 0; min-width: 40px; min-height: 40px; border-radius: 10px; cursor: pointer; color: var(--text-2); font-size: 1.05rem; }
.icon-btn:hover { background: var(--surface-2); }
.plain-btn { background: none; border: 0; text-align: left; padding: 0; cursor: pointer; }
.title-btn { background: none; border: 0; padding: 0; font-size: 1.25rem; font-weight: 700; text-align: left; cursor: pointer; }

.badge { display: inline-block; font-size: 0.72rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge.ok { background: var(--accent-soft); color: var(--text); }
.badge.warn { background: var(--warn-bg); color: var(--warn-ink); }
.badge.live { background: var(--accent); color: var(--accent-ink); }
.badge.muted { opacity: 0.75; }

.list-row {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 12px 4px; min-height: 56px;
  border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; color: inherit; cursor: pointer;
}
.list-row:last-child { border-bottom: 0; }
.row-title { font-weight: 600; }
section > .list-row { padding-left: 0; padding-right: 0; }

/* nav */
.nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
}
.nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: 0.72rem; font-weight: 600; }
.nav a[aria-current="page"] { color: var(--accent); }
.nav-icon { font-size: 1.25rem; line-height: 1; }

/* status bar */
.status { position: sticky; top: 0; z-index: 15; background: var(--surface); border-bottom: 1px solid var(--line); }
.status-main { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 8px 16px; color: var(--text); max-width: 640px; margin: 0 auto; }
.status-clock { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.status-totals { font-size: 0.875rem; color: var(--text-2); font-variant-numeric: tabular-nums; }
.status-rest { position: relative; overflow: hidden; background: var(--accent-soft); }
.status-rest.over { background: var(--accent); color: var(--accent-ink); }
.rest-fill { position: absolute; inset: 0; background: rgba(127,127,127,.22); transform-origin: left; }
.rest-inner { position: relative; display: flex; align-items: center; gap: 6px; padding: 6px 16px; max-width: 640px; margin: 0 auto; }
.rest-label { font-size: 0.75rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px; }
.rest-time { font-size: 1.4rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; }
.status-rest .btn { min-height: 40px; padding: 0 10px; background: var(--surface); color: var(--text); border-color: transparent; }

/* superset */
.superset { background: var(--accent-soft); border-radius: var(--radius); padding: 10px; }
.superset > * + * { margin-top: 10px; }
.superset-tag { font-weight: 700; font-size: 0.85rem; }

/* exercise */
.ex-card { padding: 12px; scroll-margin-top: 110px; }
.ex-card > * + * { margin-top: 8px; }
.ex-head { display: flex; align-items: center; gap: 8px; }
.ex-name { font-weight: 700; font-size: 1.08rem; }
.ex-count { font-weight: 800; font-variant-numeric: tabular-nums; }
.ex-link { color: inherit; }
.ex-group { margin-bottom: 0; }

/* set table */
.set-table { --cols: 34px minmax(0, 1fr) 56px 44px 46px 44px; }
.set-head { display: grid; grid-template-columns: var(--cols); gap: 4px; padding: 0 2px 2px; font-size: 0.7rem; font-weight: 600; color: var(--muted); text-align: center; }
.set-head span:nth-child(2) { text-align: left; }
.set-group + .set-group { margin-top: 4px; }
.set-row { display: grid; grid-template-columns: var(--cols); gap: 4px; align-items: center; border-radius: 10px; padding: 2px; font-variant-numeric: tabular-nums; }
.set-row.done { background: var(--accent-soft); }
.marker { grid-column: 1; grid-row: 1 / span 2; height: 40px; border: 0; border-radius: 8px; background: var(--surface-2); font-weight: 800; cursor: pointer; }
.marker.m-f, .marker.m-d { background: var(--warn-bg); color: var(--warn-ink); }
.marker.m-w, .marker.m-c { color: var(--muted); }
.prev { font-size: 0.75rem; line-height: 1.2; color: var(--muted); min-width: 0; }
.prev-rir { white-space: nowrap; }
.val { text-align: center; font-weight: 700; }
.cell { height: 42px; min-width: 0; padding: 0 2px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); font-weight: 700; font-size: 1rem; cursor: pointer; }
.cell.target { color: var(--muted); font-weight: 500; border-style: dashed; }
.cell.typed { color: var(--text); background: var(--surface-2); }
.cell.empty { color: var(--muted); }
.cell.active { outline: 2px solid var(--accent); outline-offset: 0; }
.tick { grid-column: 6; grid-row: 1 / span 2; height: 42px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); color: var(--muted); font-size: 1.15rem; font-weight: 800; cursor: pointer; }
.tick.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
/* Only two-line rows need these to span both lines. */
.set-row:not(.sided) .marker, .set-row:not(.sided) .tick { grid-row: 1; }
.pr-note { font-size: 0.8rem; padding: 2px 4px 2px 40px; color: var(--text-2); }
.pr-tag { background: var(--warn-bg); color: var(--warn-ink); font-weight: 800; font-size: 0.7rem; padding: 1px 6px; border-radius: 6px; }
.list-row.selected { background: var(--accent-soft); border-radius: 10px; padding-left: 8px; }

/* set lines in summaries */
.set-list { display: flex; flex-direction: column; gap: 4px; }
.set-line {
  display: grid; grid-template-columns: 38px 1fr auto; align-items: center; gap: 8px; width: 100%;
  background: var(--surface-2); border: 0; border-radius: 10px; padding: 8px 10px; text-align: left; cursor: pointer; min-height: 44px;
  font-variant-numeric: tabular-nums;
}
.set-line.deleted { opacity: 0.45; text-decoration: line-through; }
.set-type { font-size: 0.7rem; font-weight: 800; text-align: center; border-radius: 6px; padding: 3px 0; background: var(--surface); color: var(--text-2); }
.t-working .set-type { background: var(--accent); color: var(--accent-ink); }
.sides { color: var(--text-2); font-size: 0.85rem; }
.set-meta { white-space: nowrap; }

.rec { border-radius: 10px; padding: 7px 10px; background: var(--surface-2); font-size: 0.875rem; font-variant-numeric: tabular-nums; }
.rec p { margin-top: 6px; }
.rec-main { font-size: 1.15rem; font-weight: 800; margin-top: 2px; font-variant-numeric: tabular-nums; }
summary { cursor: pointer; color: var(--text-2); }

/* number pad */
.pad { position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; max-width: 640px; margin: 0 auto; padding: 8px 12px calc(10px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -8px 24px rgba(0,0,0,.35); }
.pad-head, .pad-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.pad-head { font-size: 0.875rem; min-height: 32px; }
.pad-value { font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.pad-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 6px; }
.pad-rir { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin-top: 6px; }
.pad-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 6px; }
.pad-key { min-height: 50px; border: 0; border-radius: 10px; background: var(--surface-2); font-size: 1.3rem; font-weight: 700; cursor: pointer; }
.pad-key.alt { font-size: 0.95rem; color: var(--text-2); }
.pad-key.on { background: var(--accent); color: var(--accent-ink); }
.pad-key.next { background: var(--accent); color: var(--accent-ink); font-size: 1rem; }
.pad-key.wide { grid-column: span 2; }
.pad-open .view { padding-bottom: 400px; }

.switch { display: flex; align-items: center; gap: 10px; min-height: 40px; cursor: pointer; }
.switch input { width: 22px; height: 22px; accent-color: var(--accent); }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { min-height: 42px; border: 0; border-radius: 9px; background: none; font-weight: 600; color: var(--text-2); cursor: pointer; padding: 0 6px; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* tiles */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.tile.accent { border-color: var(--accent); }
.tile-label { font-size: 0.78rem; color: var(--muted); font-weight: 600; }
.tile-val { font-size: 1.35rem; font-weight: 800; margin: 2px 0; font-variant-numeric: tabular-nums; }
.tile-sub { font-size: 0.75rem; color: var(--muted); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 6px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.cardio { padding: 8px 0; border-bottom: 1px solid var(--line); }
.cardio:last-child { border-bottom: 0; }

/* chart */
.chart { position: relative; margin-top: 10px; }
.chart-svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; }
.chart .series-line { fill: none; stroke: var(--series); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--series); stroke: var(--surface); stroke-width: 2; }
.chart .dot.hollow { fill: var(--surface); stroke: var(--series); stroke-width: 2; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:focus { outline: none; }
.chart .crosshair { stroke: var(--text-2); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-tip {
  position: absolute; top: 0; transform: translateX(-50%); pointer-events: none; opacity: 0;
  background: var(--text); color: var(--bg); padding: 6px 9px; border-radius: 8px; font-size: 0.8rem; white-space: nowrap; transition: opacity .1s;
}
.chart-tip .muted { color: inherit; opacity: 0.8; }
.chart-tip.on { opacity: 1; }

.tbl { width: 100%; border-collapse: collapse; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.tbl th, .tbl td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl th { color: var(--muted); font-weight: 600; font-size: 0.78rem; }

/* plan */
.plan-name { font-size: 1.1rem; margin-bottom: 4px; }
.plan-day { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 12px; }
.plan-day > * + * { margin-top: 8px; }
.plan-item { display: flex; align-items: center; gap: 6px; background: var(--surface-2); border-radius: 10px; padding: 8px 6px 8px 10px; }
.ss-letter { display: inline-block; background: var(--accent); color: var(--accent-ink); border-radius: 6px; font-size: 0.72rem; padding: 0 6px; margin-right: 6px; }

/* progress insights */
.period-nav .center { text-align: center; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-top: 8px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.sw { display: inline-block; width: 14px; height: 14px; border-radius: 4px; border: 1px solid var(--line); }
.sw-none { background: var(--surface-2); }
.sw-below { background: repeating-linear-gradient(45deg, var(--accent-soft) 0 3px, var(--accent) 3px 5px); }
.sw-within { background: var(--accent); }
.sw-above { background: radial-gradient(circle, var(--warn-ink) 1.2px, var(--warn-bg) 1.5px) 0 0 / 5px 5px; }
.sw-partial { background: transparent; border: 2px dashed var(--accent); }
.bodymap { width: 100%; max-width: 360px; display: block; margin: 0 auto; }
.bm-skin { fill: var(--surface-2); }
.bm-m { stroke: var(--line); stroke-width: 1; }
.bm-none { fill: var(--surface); }
.bm-below { fill: var(--accent-soft); }
.bm-within { fill: var(--accent); }
.bm-above { fill: var(--warn-bg); }
.bm-overlay { pointer-events: none; }
.bm-pat { fill: var(--accent); }
.bm-hit { fill: transparent; cursor: pointer; }
.bm-hit:focus { outline: none; stroke: var(--text); stroke-width: 2; }
.bm-label { fill: var(--muted); font-size: 10px; }
.muscle-row { min-height: 52px; padding-top: 8px; padding-bottom: 8px; }
.st-none { color: var(--muted); }
.st-below { color: var(--text-2); }
.st-within { color: var(--good); }
.st-above { color: var(--warn-ink); }
.target-row { display: grid; grid-template-columns: 1fr 64px auto 64px; gap: 8px; align-items: center; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-top: 6px; }
.cal-head { text-align: center; font-size: 0.72rem; color: var(--muted); font-weight: 600; }
.cal-day { display: flex; align-items: center; justify-content: center; height: 38px; border-radius: 9px; font-size: 0.9rem; border: 2px solid transparent; background: none; font-variant-numeric: tabular-nums; }
.cal-day.out { opacity: 0; }
.cal-day.detailed { background: var(--accent); color: var(--accent-ink); font-weight: 800; cursor: pointer; }
.cal-day.partial { border: 2px dashed var(--accent); font-weight: 700; cursor: pointer; }
.cal-day.today { box-shadow: inset 0 0 0 2px var(--text-2); }
.chips-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.mchip { background: var(--surface-2); border-radius: 99px; padding: 4px 10px; font-size: 0.85rem; }
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; }
.check { display: flex; align-items: center; gap: 8px; min-height: 36px; font-size: 0.9rem; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

/* settings */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.tabs a { white-space: nowrap; padding: 8px 12px; border-radius: 99px; background: var(--surface-2); color: var(--text-2); font-weight: 600; font-size: 0.85rem; }
.tabs a.on { background: var(--accent); color: var(--accent-ink); }
.machine-row { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.machine-row:last-child { border-bottom: 0; }
.inc { display: flex; flex-direction: column; width: 84px; }
.inc input { min-height: 40px; }
.audit { list-style: none; padding: 0; }
.audit li { padding: 8px 0; border-bottom: 1px solid var(--line); }

/* forms */
.field { display: flex; flex-direction: column; gap: 4px; }
.field-label { font-size: 0.8rem; font-weight: 600; color: var(--text-2); }
.hint { font-size: 0.75rem; color: var(--muted); }
input[type=text], input[type=number], input[type=search], input[type=date], input[type=time], select, textarea {
  width: 100%; min-height: 46px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); padding: 8px 10px;
}
textarea { min-height: 64px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.fs { border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin: 0; }
.fs > * + * { margin-top: 8px; }
.fs legend { font-size: 0.8rem; color: var(--text-2); padding: 0 4px; }

/* sheets & toasts */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto; background: var(--surface); border-radius: 18px 18px 0 0;
  padding: 0 16px calc(20px + env(safe-area-inset-bottom)); animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.sheet-head { position: sticky; top: 0; background: var(--surface); display: flex; align-items: center; justify-content: space-between; padding: 14px 0 10px; z-index: 1; }
.sheet-body { padding-bottom: 8px; }
.pick-list { max-height: 45vh; overflow-y: auto; }
.toasts { position: fixed; left: 0; right: 0; top: 56px; z-index: 60; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast { pointer-events: auto; background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 12px; display: flex; gap: 12px; align-items: center; max-width: 560px; box-shadow: 0 6px 24px rgba(0,0,0,.25); }
.toast .link { color: inherit; text-decoration: underline; font-weight: 700; }
.warn-bar { background: var(--warn-bg); color: var(--warn-ink); padding: 10px 16px; font-size: 0.9rem; text-align: center; }

@media (min-width: 560px) {
  .tiles { grid-template-columns: repeat(4, 1fr); }
  .sheet-wrap { align-items: center; }
  .sheet { border-radius: 18px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* Machine library (specs/003) */
.pick-head { margin: 12px 0 4px; font-size: 0.9rem; }
.stack-xs { display: flex; flex-direction: column; gap: 2px; align-items: flex-end; }
