:root {
  --bg: #0e1014;
  --surface: #171a21;
  --surface-2: #20242e;
  --line: #2b303b;
  --text: #eef0f3;
  --muted: #98a1b0;
  --faint: #4b5262;
  --accent: #ff7a1a;
  --accent-2: #ff9d57;
  --on-accent: #1b0e02;
  --ok: #35c47a;
  --bad: #f0574f;
  --gold: #f5c542;
  --r: 16px;
  --nav-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(var(--nav-h) + var(--safe-b));
  overscroll-behavior-y: none;
}
body.has-rest { padding-bottom: calc(var(--nav-h) + var(--safe-b) + 122px); }
body.setup { padding-bottom: 24px; }
body.setup #tabs { display: none; }
body.sheet-open { overflow: hidden; }

#view { max-width: 640px; margin: 0 auto; padding: max(16px, env(safe-area-inset-top)) 16px 24px; }

h1 { font-size: 1.6rem; line-height: 1.2; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; line-height: 1.25; margin: 0 0 4px; }
h3.section { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 24px 4px 8px; }
p { margin: 6px 0; }
a { color: var(--accent-2); }
small { font-size: 0.8rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.bad { color: var(--bad); }
.lead { font-size: 1.05rem; margin: 4px 0 8px; }

/* ---------- surfaces */
.card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 14px;
  margin: 12px 0;
  color: inherit;
  text-decoration: none;
}
button.card { width: 100%; text-align: left; font: inherit; cursor: pointer; }
.page-head { margin: 4px 0 16px; }
.page-head .back { display: inline-block; color: var(--muted); text-decoration: none; margin-bottom: 6px; padding: 4px 0; }
.eyebrow { display: block; font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; color: var(--accent-2); margin-bottom: 4px; }
.row { display: flex; gap: 10px; margin-top: 14px; }
.row > .btn { flex: 1; }
.row.wrap { flex-wrap: wrap; }
.row.wrap > .btn { flex: 1 1 140px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* ---------- buttons */
.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 650;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
}
.btn svg { width: 20px; height: 20px; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.big { width: 100%; min-height: 56px; font-size: 1.05rem; margin-top: 12px; }
.btn.block { display: flex; width: 100%; margin-top: 10px; }
.btn.ghost { background: transparent; }
.btn.danger { background: transparent; border-color: var(--bad); color: var(--bad); }
.btn.sm { min-height: 40px; padding: 8px 12px; font-size: 0.9rem; }
.link { background: none; border: 0; padding: 4px 2px; color: var(--accent-2); font: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.icon-btn {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  padding: 0;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn.sm { width: 36px; height: 36px; }
.icon-btn:disabled { opacity: 0.3; }
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }

/* ---------- forms */
input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 44px;
  width: 100%;
}
textarea { resize: vertical; min-height: 64px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
.field { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); }
.card > .field:first-child, .card > h2 + .field, .card > h2 + p + .field { border-top: 0; }
.field > span { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.field small, .toggle small { color: var(--muted); font-weight: 400; font-size: 0.8rem; }
.field input, .field select { width: 108px; flex: none; text-align: right; }
.field select { text-align: left; }
.field em { font-style: normal; color: var(--muted); min-width: 28px; font-size: 0.9rem; }
.stack { display: flex; flex-direction: column; gap: 6px; padding: 8px 0; }
.stack > span { font-weight: 600; font-size: 0.92rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.title-input { font-weight: 700; font-size: 1.05rem; background: transparent; border-color: transparent; padding-left: 4px; }
.title-input:focus { background: var(--bg); }

.toggle { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 11px 0; border-top: 1px solid var(--line); cursor: pointer; }
.card > .toggle:first-child { border-top: 0; }
.toggle > span { display: flex; flex-direction: column; }
.toggle b { font-weight: 600; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.toggle i { flex: none; position: relative; width: 48px; height: 28px; border-radius: 14px; background: var(--line); transition: background 0.15s; }
.toggle i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform 0.15s; }
.toggle input:checked + i { background: var(--accent); }
.toggle input:checked + i::after { transform: translateX(20px); }
.toggle input:focus-visible + i { outline: 2px solid var(--accent-2); outline-offset: 2px; }

.seg { display: flex; gap: 6px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin-top: 8px; }
.seg button { flex: 1; min-height: 42px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font: inherit; font-weight: 650; cursor: pointer; }
.seg button.on { background: var(--surface-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.seg.sm { margin: 0; flex: none; width: 130px; }
.seg.sm button { min-height: 34px; }

/* ---------- chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 2px 16px 6px; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.chip.done { background: transparent; color: var(--ok); border-color: color-mix(in srgb, var(--ok) 55%, transparent); text-decoration: line-through; text-decoration-thickness: 1px; }
.chip.check { position: relative; padding: 0; overflow: hidden; }
.chip.check input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.chip.check span { padding: 6px 14px; }
.chip.check input:checked + span { background: var(--accent); color: var(--on-accent); }
.chip.check input:focus-visible + span { outline: 2px solid var(--accent-2); }

/* ---------- setup */
.hero { text-align: center; padding: 18px 8px 6px; }
.hero h1 { font-size: 2rem; margin-top: 10px; }
.logo { display: inline-grid; place-items: center; width: 72px; height: 72px; border-radius: 20px; background: var(--surface); border: 1px solid var(--line); color: var(--accent); }
.logo svg { width: 44px; height: 44px; }

/* ---------- home */
.hero-card h2 { font-size: 1.45rem; }
.lift-list { list-style: none; margin: 10px 0 0; padding: 0; }
.lift-list li { border-top: 1px solid var(--line); }
.lift-list li:first-child { border-top: 0; }
.lift-list button { display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: center; width: 100%; padding: 12px 2px; border: 0; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.lift-list b { min-width: 72px; text-align: right; font-size: 1.05rem; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 12px 0; }
.stat-grid.four { grid-template-columns: repeat(4, 1fr); }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 8px; text-align: center; min-width: 0; }
.stat b { display: block; font-size: 1.2rem; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat b small { font-size: 0.75rem; color: var(--muted); font-weight: 600; }
.stat span { font-size: 0.75rem; color: var(--muted); }
.tip-card p { font-size: 1.05rem; margin: 4px 0 6px; }

.hist .hist-row { display: grid; grid-template-columns: 10px 1fr auto 56px; gap: 10px; align-items: center; padding: 5px 0; }
.hist .hist-row b { text-align: right; font-variant-numeric: tabular-nums; }
.hist-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hist > .muted { margin-top: 6px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--faint); }
.dot.success { background: var(--ok); }
.dot.bonus { background: var(--gold); }
.dot.fail, .dot.deload { background: var(--bad); }
.dot.deload { box-shadow: inset 0 0 0 2px var(--bg); }

/* ---------- workout */
.wk-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 12px; }
#wk-clock { font-variant-numeric: tabular-nums; color: var(--text); font-weight: 600; }
.hint { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); background: color-mix(in srgb, var(--accent) 7%, var(--surface)); font-size: 0.92rem; }
.ex { transition: border-color 0.2s; }
.ex.success { border-color: color-mix(in srgb, var(--ok) 50%, var(--line)); }
.ex.fail { border-color: color-mix(in srgb, var(--bad) 45%, var(--line)); }
.ex-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.ex-title { min-width: 0; }
.ex-meta { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.weight {
  border: 0;
  background: none;
  padding: 0;
  color: var(--text);
  font: inherit;
  font-size: 1.7rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  text-decoration: underline dotted var(--faint);
  text-underline-offset: 5px;
}
.weight small { font-size: 0.9rem; font-weight: 600; color: var(--muted); margin-left: 3px; }
.warm { margin-top: 10px; padding: 8px 10px; background: var(--bg); border-radius: 12px; }
.warm-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 700; }
.warm .chip { min-height: 32px; padding: 4px 10px; font-size: 0.85rem; }
.plates-line { margin-top: 2px; }

.sets { display: grid; grid-template-columns: repeat(var(--n, 6), minmax(0, 58px)); gap: 26px 10px; margin: 14px 0 22px; }
.set {
  position: relative;
  aspect-ratio: 1;
  width: 100%;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: var(--surface-2);
  color: var(--faint);
  font-family: inherit;
  font-size: 1.3rem;
  font-weight: 800;
  line-height: 1;
  display: grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: transform 0.08s, background 0.12s;
}
.set .lbl { position: absolute; top: calc(100% + 5px); left: 50%; transform: translateX(-50%); font-size: 0.68rem; font-weight: 600; color: var(--muted); }
.set.done { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.set.over { background: var(--gold); border-color: var(--gold); color: #2a1f00; }
.set.miss { background: transparent; border-color: var(--bad); color: var(--bad); }
.set.amrap { background: transparent; border-style: dashed; border-color: color-mix(in srgb, var(--gold) 70%, transparent); color: var(--gold); }
.set.amrap.has { border-style: solid; border-color: var(--gold); background: color-mix(in srgb, var(--gold) 16%, transparent); }
.set.pressing { transform: scale(0.92); }
.sets.static { gap: 10px; margin-bottom: 8px; }
.sets.static .set { cursor: default; font-size: 1.1rem; }
.sets.static .set.todo { color: var(--faint); }

/* ---------- plate visual */
.platevis { display: flex; align-items: center; height: 92px; margin: 14px 0 4px; }
.pv-bar { width: 40px; height: 10px; background: #8b93a1; border-radius: 2px 0 0 2px; }
.plate { flex: none; display: grid; place-items: center; width: 24px; height: calc(86px * var(--h)); margin-right: 3px; border-radius: 4px; background: var(--c); color: #111; font-size: 0.62rem; font-weight: 800; }
.pv-collar { width: 8px; height: 22px; margin-right: 2px; background: #c9ced6; border-radius: 2px; }
.pv-sleeve { flex: 1; max-width: 46px; height: 12px; background: #8b93a1; border-radius: 0 3px 3px 0; }
.stepper { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; margin-top: 12px; }
.stepper input { text-align: center; font-size: 1.6rem; font-weight: 800; min-height: 56px; }
.stepper .btn { min-width: 76px; min-height: 56px; }

/* ---------- number picker */
.numgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 8px; margin: 14px 0 4px; }
.num { min-height: 52px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); font: inherit; font-size: 1.15rem; font-weight: 700; cursor: pointer; }
.num.target { border-color: var(--accent); color: var(--accent-2); }
.num.cur { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

/* ---------- results */
.res-head { padding: 4px 0 8px; }
.res-badge { display: inline-grid; place-items: center; width: 64px; height: 64px; border-radius: 50%; background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); margin-bottom: 8px; }
.res-badge.gold { background: color-mix(in srgb, var(--gold) 18%, transparent); color: var(--gold); }
.res-badge svg { width: 34px; height: 34px; }
.res { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.res-l, .res-r { display: flex; flex-direction: column; gap: 2px; }
.res-r { align-items: flex-end; text-align: right; }
.tag { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 0.8rem; font-weight: 700; background: var(--surface-2); color: var(--text); white-space: nowrap; }
.tag.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.tag.gold { background: color-mix(in srgb, var(--gold) 18%, transparent); color: var(--gold); }
.tag.bad { background: color-mix(in srgb, var(--bad) 16%, transparent); color: var(--bad); }
.tag.muted { color: var(--muted); }
.tag.sm { font-size: 0.72rem; padding: 2px 8px; }
.pr { display: inline-block; font-size: 0.68rem; font-weight: 800; padding: 1px 6px; border-radius: 6px; background: var(--gold); color: #2a1f00; vertical-align: 2px; }

/* ---------- calendar */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-top: 10px; text-align: center; }
.cal-grid .dow { font-size: 0.72rem; color: var(--muted); font-weight: 700; padding: 2px 0; }
.day { display: grid; place-items: center; aspect-ratio: 1; max-height: 44px; border-radius: 50%; font-size: 0.85rem; color: var(--muted); text-decoration: none; margin: 0 auto; width: 100%; max-width: 44px; }
.day.today { box-shadow: inset 0 0 0 1px var(--muted); color: var(--text); }
.day.has { color: var(--on-accent); font-weight: 800; }
.day.has.ok { background: var(--ok); }
.day.has.bad { background: var(--bad); }

/* ---------- progress */
.chart { width: 100%; height: auto; display: block; margin-top: 8px; }
.chart .gl { stroke: var(--line); stroke-width: 1; }
.chart .yl { fill: var(--muted); font-size: 10px; text-anchor: end; }
.chart .xl { fill: var(--muted); font-size: 10px; }
.chart .xl.end { text-anchor: end; }
.chart .ln { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .pt { fill: var(--ok); stroke: var(--surface); stroke-width: 1.5; }
.chart .pt.bonus { fill: var(--gold); }
.chart .pt.fail { fill: var(--bad); }
.chart .pt.deload { fill: var(--surface); stroke: var(--bad); stroke-width: 2; }
.chart .pt:not(.success):not(.bonus):not(.fail):not(.deload) { fill: var(--accent); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend .dot { width: 8px; height: 8px; }
.list-card { padding: 4px 14px; }
.sess { display: grid; grid-template-columns: 52px 52px 1fr auto; gap: 8px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); color: inherit; text-decoration: none; }
.sess:first-child { border-top: 0; }
.sess b { font-variant-numeric: tabular-nums; }

/* ---------- tips */
.link-card { display: flex; flex-direction: column; gap: 2px; }
.tip-list { margin: 0; padding-left: 20px; }
.tip-list li { margin: 7px 0; }
.tip-list.cues li::marker { color: var(--accent); }
.tip-list.bad-list li::marker { color: var(--bad); }

/* ---------- settings */
.prog-list { list-style: none; margin: 6px 0 10px; padding: 0; }
.prog-list li { display: flex; align-items: center; gap: 6px; border-top: 1px solid var(--line); padding: 4px 0; }
.prog-ex { flex: 1; display: flex; flex-direction: column; align-items: flex-start; min-width: 0; padding: 8px 2px; border: 0; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }

/* ---------- rest bar */
#restbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--nav-h) + var(--safe-b));
  z-index: 30;
  padding: 10px 16px 12px;
  background: #1c2030;
  border-top: 1px solid var(--line);
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.35);
}
#restbar.done { background: #11331f; border-top-color: var(--ok); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { background: #17462a; } }
.rb-wrap { max-width: 640px; margin: 0 auto; }
.rb-prog { height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; margin-bottom: 8px; }
.rb-prog i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.25s linear; }
#restbar.done .rb-prog i { background: var(--ok); }
.rb-main { display: flex; align-items: center; gap: 14px; cursor: pointer; }
.rb-time { min-width: 4.3ch; font-size: 2.3rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
#restbar.done .rb-time { color: var(--ok); }
.rb-info { flex: 1; min-width: 0; }
.rb-label, .rb-next { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rb-label { font-weight: 650; }
.rb-btns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }

/* ---------- nav */
#tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: rgba(14, 16, 20, 0.97);
  border-top: 1px solid var(--line);
}
#tabs a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); text-decoration: none; font-size: 0.7rem; font-weight: 650; }
#tabs a.on { color: var(--accent); }
#tabs a.live:not(.on) { color: var(--accent-2); }
#tabs svg { width: 24px; height: 24px; }

/* ---------- sheet */
#overlay { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
#overlay[hidden] { display: none; }
.backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.62); }
.sheet {
  position: relative;
  width: 100%;
  max-width: 640px;
  max-height: 88vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 22px 16px calc(20px + var(--safe-b));
  background: var(--surface);
  border-top: 1px solid var(--line);
  border-radius: 22px 22px 0 0;
  animation: sheet-up 0.22s ease-out;
}
.sheet::before { content: ""; display: block; width: 40px; height: 4px; margin: -10px auto 14px; border-radius: 2px; background: var(--line); }
.sheet > h2 { font-size: 1.25rem; }
@keyframes sheet-up { from { transform: translateY(48px); opacity: 0.4; } }

/* ---------- toast */
#toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--nav-h) + var(--safe-b) + 14px);
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100% - 32px);
  padding: 12px 16px;
  border-radius: 12px;
  background: #2a2f3b;
  color: var(--text);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  font-size: 0.92rem;
}
#toast[hidden] { display: none; }
body.has-rest #toast { bottom: calc(var(--nav-h) + var(--safe-b) + 136px); }

.empty { text-align: center; padding: 28px 16px; }

@media (max-width: 370px) {
  .stat-grid.four { grid-template-columns: repeat(2, 1fr); }
  .weight { font-size: 1.5rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before { animation: none !important; transition: none !important; }
}
