:root {
  --bg: #f6f7f9; --surface: #ffffff; --surface-2: #eef0f4; --line: #e1e4ea;
  --text: #14171c; --muted: #5d6573; --dim: #9aa1ad;
  --accent: #e8551f; --accent-ink: #ffffff; --accent-soft: #fde7dd;
  --good: #16a34a; --good-soft: #dcfce7; --gold: #c58a00; --danger: #d92d20;
  --chart: #e8551f; --chart-area: rgba(232, 85, 31, .12);
  --hm0: #e6e9ee; --hm1: #f6a27f; --hm2: #e8551f;
  --radius: 16px; --tab-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --surface: #181b21; --surface-2: #22262e; --line: #2a2f38;
    --text: #eef0f3; --muted: #9aa3b2; --dim: #5f6775;
    --accent: #ff6b35; --accent-ink: #160a04; --accent-soft: #3a2118;
    --good: #4ade80; --good-soft: #163522; --gold: #fbbf24; --danger: #f87171;
    --chart: #ff6b35; --chart-area: rgba(255, 107, 53, .14);
    --hm0: #22262e; --hm1: #7a3a20; --hm2: #ff6b35;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --surface: #181b21; --surface-2: #22262e; --line: #2a2f38;
  --text: #eef0f3; --muted: #9aa3b2; --dim: #5f6775;
  --accent: #ff6b35; --accent-ink: #160a04; --accent-soft: #3a2118;
  --good: #4ade80; --good-soft: #163522; --gold: #fbbf24; --danger: #f87171;
  --chart: #ff6b35; --chart-area: rgba(255, 107, 53, .14);
  --hm0: #22262e; --hm1: #7a3a20; --hm2: #ff6b35;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; overscroll-behavior-y: none;
}
main { max-width: 640px; margin: 0 auto; padding: 0 16px calc(var(--tab-h) + var(--safe-b) + 24px); outline: none; }
body.in-session main { padding-bottom: calc(var(--tab-h) + var(--safe-b) + 96px); }
h1 { font-size: 24px; margin: 0; letter-spacing: -.02em; }
h2 { font-size: 18px; margin: 0; }
h3 { font-size: 16px; margin: 0 0 8px; }
p { margin: 0 0 8px; }
a { color: inherit; text-decoration: none; }
.muted { color: var(--muted); }
.sub { color: var(--muted); font-size: 13px; }
.small { font-size: 13px; }
.dim { color: var(--dim); }
.pad { padding: 0 4px; }
.grow { flex: 1; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row { display: flex; align-items: center; }
.row.between { justify-content: space-between; gap: 8px; }
.row.gap { gap: 8px; }
.row.end { justify-content: flex-end; }
.row.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.ic { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; vertical-align: middle; }
.ic.gold { color: var(--gold); }
.ic.hot { color: var(--accent); width: 16px; height: 16px; }
.ic.big { width: 48px; height: 48px; }
.btn .ic, .chip .ic { width: 18px; height: 18px; }

/* header */
header.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 0 12px; margin: 0 -16px 8px; padding-left: 16px; padding-right: 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px);
}
.title-input { font: 700 20px/1.2 inherit; font-family: inherit; color: var(--text); background: transparent; border: 0; padding: 4px 0; width: 100%; border-bottom: 1px dashed transparent; }
.title-input:focus { outline: none; border-bottom-color: var(--line); }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 12px; border: 0;
  font: 600 15px/1 inherit; font-family: inherit; cursor: pointer;
  background: var(--surface-2); color: var(--text);
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; cursor: default; }
.btn:active:not(:disabled) { transform: scale(.98); }
.danger-text { color: var(--danger) !important; }
.icon-btn { display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; border: 0; background: transparent; color: var(--text); cursor: pointer; flex: none; }
.icon-btn:active { background: var(--surface-2); }
.icon-btn:disabled { opacity: .3; }
.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; text-align: left; }
.link.title { color: var(--text); }
.file-btn { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* cards & lists */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.stack > .card { margin-bottom: 0; }
.list { list-style: none; margin: 0 0 12px; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list li + li { border-top: 1px solid var(--line); }
.list .empty { padding: 20px 16px; color: var(--muted); }
.list.compact { border: 0; background: none; }
.list.compact li { padding: 4px 0; }
.row-link { display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 60px; cursor: pointer; }
.card .row-link { padding: 4px 0; }
.title { font-weight: 600; }
.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 99px; background: var(--surface-2); color: var(--muted); vertical-align: middle; }
.spark { flex: none; }
.spark path { fill: none; stroke: var(--chart); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
h2.group { margin: 20px 4px 8px; font-size: 15px; display: flex; justify-content: space-between; align-items: baseline; }

.banner { display: flex; align-items: center; gap: 12px; padding: 14px 16px; margin-bottom: 12px; border-radius: var(--radius); background: var(--accent); color: var(--accent-ink); }
.banner span { display: block; font-size: 13px; opacity: .85; }

/* inputs */
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { font-size: 12px; font-weight: 600; color: var(--muted); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid transparent;
  border-radius: 10px; padding: 10px 12px; min-height: 44px; width: 100%;
}
textarea { resize: vertical; min-height: 0; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
input[type=checkbox] { width: 22px; height: 22px; min-height: 0; accent-color: var(--accent); flex: none; }
.search { position: relative; margin-bottom: 10px; }
.search .ic { position: absolute; left: 12px; top: 11px; color: var(--muted); }
.search input { padding-left: 42px; }

/* chips */
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; min-height: 36px; padding: 0 14px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font: 600 13px inherit; font-family: inherit; cursor: pointer; }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.metric-chip { display: flex; flex-direction: column; align-items: flex-start; justify-content: center; min-height: 52px; border-radius: 14px; gap: 1px; }
.metric-chip b { font-size: 12px; opacity: .75; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(80px, 1fr)); gap: 8px; margin: 4px 0 12px; }
.stat { background: var(--surface-2); border-radius: 12px; padding: 10px; text-align: center; }
.stat b { display: block; font-size: 17px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }
.big-num { font-size: 28px; font-weight: 750; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.big-num small { font-size: 15px; font-weight: 600; color: var(--muted); }

/* home */
.week { display: flex; align-items: center; gap: 14px; }
.ring { width: 56px; height: 56px; transform: rotate(-90deg); flex: none; }
.ring circle { fill: none; stroke-width: 5; stroke-linecap: round; }
.ring-bg { stroke: var(--surface-2); }
.ring-fg { stroke: var(--accent); transition: stroke-dasharray .4s; }
.ex-names { color: var(--muted); font-size: 13px; margin: 2px 0 12px; }
.bw-row { align-items: center; }
.pr-list { list-style: none; margin: 0; padding: 0; }
.pr-list li { padding: 6px 0; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.pr-list li a { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.pr-list .ic { width: 18px; height: 18px; }

/* workouts */
.workout-card h3 { margin: 0; }
.builder { list-style: none; padding: 0; margin: 0 0 12px; }
.targets { margin-top: 10px; }
.targets .field { flex: 1; }

/* session */
.session-top .title-input { font-size: 18px; }
.clock { font-variant-numeric: tabular-nums; }
.entry { padding: 14px 12px; }
.entry-head .link { display: flex; align-items: center; gap: 6px; font-size: 16px; }
.entry-head .ic { width: 18px; height: 18px; }
.set-head, .set-row { display: grid; grid-template-columns: 36px minmax(0, 1fr) 72px 64px 44px; gap: 6px; align-items: center; }
.set-head { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 10px 0 4px; }
.set-head span:nth-child(n+3) { text-align: center; }
.set-row { padding: 4px 0; border-radius: 10px; position: relative; flex-wrap: wrap; }
.set-row input { text-align: center; padding: 8px 4px; font-weight: 600; font-variant-numeric: tabular-nums; }
.set-row input::placeholder { color: var(--dim); font-weight: 500; }
.set-n { width: 32px; height: 32px; border-radius: 9px; border: 0; background: var(--surface-2); color: var(--text); font: 700 13px inherit; font-family: inherit; cursor: pointer; }
.set-row.warm .set-n { background: var(--accent-soft); color: var(--accent); }
.prev { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.tick { width: 44px; height: 40px; border-radius: 10px; border: 0; background: var(--surface-2); color: var(--dim); cursor: pointer; display: grid; place-items: center; }
.set-row.done { background: var(--good-soft); }
.set-row.done .tick { background: var(--good); color: #fff; }
.set-row.done input { background: transparent; }
.pr-badge { grid-column: 2 / -1; display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 700; color: var(--gold); padding: 0 0 4px; }
.pr-badge .ic { width: 14px; height: 14px; }
.set-list .pr-badge { display: inline-flex; padding: 0; }
.entry > .row:last-child { margin-top: 8px; }

#restbar {
  position: fixed; left: 50%; transform: translate(-50%, 140%); bottom: calc(var(--tab-h) + var(--safe-b) + 10px);
  width: min(608px, calc(100% - 24px)); z-index: 20; border-radius: 16px; overflow: hidden;
  background: var(--text); color: var(--bg); box-shadow: 0 10px 30px rgba(0, 0, 0, .3); transition: transform .25s, visibility .25s;
  visibility: hidden; pointer-events: none;
}
#restbar.show { transform: translate(-50%, 0); visibility: visible; pointer-events: auto; }
#restbar .rest-fill { position: absolute; inset: 0; background: var(--accent); opacity: .35; transform-origin: left; }
#restbar .rest-row { position: relative; display: flex; align-items: center; gap: 8px; padding: 8px 10px 8px 14px; }
#restbar .rest-time { font-size: 20px; font-variant-numeric: tabular-nums; min-width: 52px; }
#restbar .btn { background: transparent; color: inherit; border: 1px solid color-mix(in srgb, var(--bg) 40%, transparent); min-height: 36px; }

/* session view */
.set-list { margin: 8px 0 0; padding-left: 22px; }
.set-list li { padding: 2px 0; font-variant-numeric: tabular-nums; }
.set-list li.warm { color: var(--muted); }
.hist { list-style: none; padding: 0; margin: 0; }
.hist li { padding: 10px 0; border-top: 1px solid var(--line); }
.hist li:first-child { border-top: 0; }
.sets-inline { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 14px; color: var(--muted); margin-top: 2px; font-variant-numeric: tabular-nums; }
.sets-inline .ic { width: 14px; height: 14px; }
.notes { white-space: pre-wrap; }
.date-badge { width: 44px; text-align: center; flex: none; background: var(--surface-2); border-radius: 10px; padding: 4px 0; }
.date-badge b { display: block; font-size: 17px; line-height: 1.1; }
.date-badge span { font-size: 11px; color: var(--muted); }
.pr-count { display: inline-flex; align-items: center; gap: 2px; color: var(--gold); font-size: 12px; font-weight: 700; }
.pr-count .ic { width: 14px; height: 14px; }
.celebrate { text-align: center; padding: 8px 0 12px; }
.celebrate h3 { font-size: 22px; margin: 6px 0 2px; }

/* heatmap */
.heatmap { width: 100%; height: auto; display: block; }
.heatmap rect { fill: var(--hm0); }
.heatmap .hm1 { fill: var(--hm1); }
.heatmap .hm2 { fill: var(--hm2); }
.heatmap .today { stroke: var(--text); stroke-width: 1.2; }
.hm-legend { display: flex; justify-content: space-between; margin-top: 6px; }

/* chart */
.chart { position: relative; margin: 4px 0 8px; touch-action: pan-y; user-select: none; }
.chart svg { display: block; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke: var(--chart); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--chart-area); }
.chart .dot { fill: var(--surface); stroke: var(--chart); stroke-width: 2; }
.chart .goal { stroke: var(--good); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart .goal-label { fill: var(--good); font-size: 11px; font-weight: 700; }
.chart .cursor-line { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .cursor-dot { fill: var(--chart); stroke: var(--surface); stroke-width: 2; }
.chart-tip { display: none; position: absolute; top: -6px; transform: translate(-50%, -100%); background: var(--text); color: var(--bg); padding: 6px 10px; border-radius: 10px; font-size: 12px; white-space: nowrap; pointer-events: none; text-align: center; }
.chart-tip b { display: block; font-size: 14px; }
.chart-empty { height: 140px; display: grid; place-items: center; color: var(--muted); background: var(--surface-2); border-radius: 12px; text-align: center; padding: 16px; font-size: 14px; }

/* form media */
.media { margin-bottom: 10px; }
.media-view { aspect-ratio: 16 / 11; background: var(--surface-2); border-radius: 14px; overflow: hidden; display: grid; place-items: center; }
.media-view iframe, .media-view video { width: 100%; height: 100%; border: 0; background: #000; }
.demo-svg { width: 100%; height: 100%; max-height: 100%; }
.demo-svg line { stroke-linecap: round; }
.demo-scene rect { fill: var(--line); }
.demo-scene line { stroke: var(--dim); stroke-width: 3; }
.demo-scene .demo-floor { stroke: var(--line); stroke-width: 2; }
.demo-scene .demo-cable { stroke: var(--dim); stroke-width: 1.5; stroke-dasharray: 3 3; }
.demo-scene .demo-sled { stroke: var(--muted); stroke-width: 5; }
.demo-near line { stroke: var(--text); stroke-width: 7; }
.demo-near .demo-head { fill: var(--text); }
.demo-far line { stroke: var(--dim); stroke-width: 7; }
.demo-plate { fill: var(--accent); stroke: var(--surface); stroke-width: 1.5; }
.demo-preview { height: 180px; background: var(--surface-2); border-radius: 14px; overflow: hidden; }
.cues { margin: 0; padding-left: 20px; }
.cues li { margin-bottom: 6px; }

/* sheets */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; }
.sheet-bg { position: absolute; inset: 0; background: rgba(0, 0, 0, .45); opacity: 0; transition: opacity .2s; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 640px; max-height: 88vh;
  background: var(--surface); border-radius: 20px 20px 0 0; display: flex; flex-direction: column;
  transform: translateY(100%); transition: transform .22s ease-out; padding-bottom: var(--safe-b);
}
.sheet.tall { height: 88vh; }
.sheet-wrap.open .sheet { transform: none; }
.sheet-wrap.open .sheet-bg { opacity: 1; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 8px 4px 20px; }
.sheet-body { padding: 4px 16px 20px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 12px; }
.sheet-foot { position: sticky; bottom: -20px; background: var(--surface); padding: 12px 0; margin-top: auto; }
.list.pick { margin: 0; flex: 1; }
.pick-row { gap: 12px; }
.pick-row.already .title { color: var(--muted); }
.menu { display: flex; flex-direction: column; }
.menu > button, .menu > a, .menu-field { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 0 4px; border: 0; background: none; color: var(--text); font: 500 16px inherit; font-family: inherit; text-align: left; cursor: pointer; border-bottom: 1px solid var(--line); }
.menu > button:disabled { opacity: .35; }
.menu-field input { width: 80px; margin-left: auto; text-align: center; }

/* tools */
.plate-row { display: flex; align-items: center; gap: 4px; min-height: 80px; padding: 8px; background: var(--surface-2); border-radius: 12px; overflow-x: auto; }
.plate { display: grid; place-items: center; width: 26px; border-radius: 5px; color: #fff; font-size: 11px; font-weight: 800; flex: none; writing-mode: vertical-rl; }
.plate.p25, .plate.p45 { height: 76px; background: #d92d20; }
.plate.p20, .plate.p35 { height: 70px; background: #2563eb; }
.plate.p15 { height: 62px; background: #d4a106; }
.plate.p10 { height: 54px; background: #16a34a; }
.plate.p5 { height: 44px; background: #64748b; }
.plate.p2_5 { height: 36px; background: #334155; }
.plate.p1_25 { height: 30px; background: #94a3b8; }
table.pct { width: 100%; border-collapse: collapse; margin-top: 8px; font-variant-numeric: tabular-nums; }
.pct th, .pct td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.pct th { font-size: 12px; color: var(--muted); }

/* settings */
.settings { padding: 4px 16px; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 56px; border-bottom: 1px solid var(--line); }
.setting:last-child { border-bottom: 0; }
.setting select { width: auto; max-width: 55%; }

/* tab bar */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; justify-content: center;
  height: calc(var(--tab-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(14px); border-top: 1px solid var(--line);
}
#tabbar a { flex: 1; max-width: 128px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); font-size: 11px; font-weight: 600; }
#tabbar a.on { color: var(--accent); }

#toast {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top, 0px) + 12px); transform: translate(-50%, -150%); z-index: 60;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px;
  display: flex; align-items: center; gap: 6px; transition: transform .25s; max-width: calc(100% - 32px);
}
#toast.show { transform: translate(-50%, 0); }
#toast .ic { width: 18px; height: 18px; }

@media (max-width: 360px) {
  .set-head, .set-row { grid-template-columns: 30px minmax(0, 1fr) 62px 54px 40px; gap: 4px; }
  .grid2 { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
