:root {
  --bg: #0a0c10; --s1: #13161c; --s2: #1b1f27; --s3: #262b35; --line: #252a34;
  --accent: #3b82f6; --accent2: #60a5fa; --soft: #16294a;
  --text: #f3f4f6; --dim: #8b93a1; --ok: #22c55e; --gold: #f5b301; --bad: #ef4444; --warn: #f97316;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif; }
body { padding-top: var(--safe-t); overscroll-behavior-y: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
input, select, textarea { font: inherit; font-size: 16px; color: var(--text); }
a { color: var(--accent); text-decoration: none; }

#app { padding-bottom: calc(96px + var(--safe-b)); min-height: 100vh; }
#app.no-tabs { padding-bottom: calc(24px + var(--safe-b)); }
.screen { padding: 8px 20px 24px; display: flex; flex-direction: column; gap: 18px; }

.header { display: flex; align-items: center; gap: 8px; padding: 16px 0 4px; }
.header h1 { font-size: 32px; line-height: 1.1; font-weight: 900; letter-spacing: -0.5px; margin: 0; flex: 1; }
.header .back { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; margin-left: -8px; }
.over { font-size: 11px; font-weight: 700; letter-spacing: 1.4px; text-transform: uppercase; color: var(--dim); }
.over.accent { color: var(--accent); } .over.ok { color: var(--ok); } .over.warn { color: var(--warn); } .over.gold { color: var(--gold); } .over.bad { color: var(--bad); }
h2 { font-size: 20px; font-weight: 800; margin: 6px 0 0; }
h3 { font-size: 17px; font-weight: 800; margin: 0; }
.big { font-size: 24px; font-weight: 800; line-height: 1.2; }
.huge { font-size: 34px; font-weight: 900; letter-spacing: -0.5px; }
.dim { color: var(--dim); } .small { font-size: 13px; } .tiny { font-size: 11px; }
.ok { color: var(--ok); } .warn { color: var(--warn); } .bad { color: var(--bad); } .gold { color: var(--gold); } .acc { color: var(--accent); }
.row { display: flex; align-items: center; gap: 10px; } .grow { flex: 1; min-width: 0; }
.col { display: flex; flex-direction: column; gap: 10px; }
.wrap { display: flex; flex-wrap: wrap; gap: 8px; }

.card { background: var(--s1); border: 1px solid var(--line); border-radius: 24px; padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.card.tap { cursor: pointer; } .card.tap:active { transform: scale(0.99); }
.card.accent { border-color: rgba(59,130,246,.6); } .card.ok { border-color: rgba(34,197,94,.45); } .card.warn { border-color: rgba(249,115,22,.55); }
.card.gold { border-color: rgba(245,179,1,.5); } .card.bad { border-color: rgba(239,68,68,.45); } .card.soft { background: rgba(22,41,74,.45); border-color: rgba(59,130,246,.45); }

.btn { height: 52px; border-radius: 16px; background: var(--accent); color: #fff; font-weight: 800; font-size: 16px; display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; padding: 0 18px; }
.btn.ok { background: var(--ok); } .btn.grey { background: var(--s3); } .btn.bad { background: var(--bad); } .btn.gold { background: var(--gold); color: #111; }
.btn:disabled { opacity: .4; }
.btn.inline { width: auto; }
.link { color: var(--accent); font-weight: 700; padding: 6px 0; }
.link.dim { color: var(--dim); }

.pill { display: inline-flex; align-items: center; gap: 5px; padding: 6px 12px; border-radius: 999px; background: var(--s3); font-size: 13px; font-weight: 600; white-space: nowrap; }
.pill.acc { background: var(--soft); color: var(--accent); } .pill.sel { background: var(--accent); color: #fff; } .pill.ok { background: rgba(34,197,94,.15); color: var(--ok); } .pill.bad { background: rgba(239,68,68,.15); color: var(--bad); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); gap: 10px; }
.tile { background: var(--s1); border: 1px solid var(--line); border-radius: 20px; padding: 16px; }
.tile .v { font-size: 26px; font-weight: 800; margin-top: 4px; }

.tabbar { position: fixed; left: 0; right: 0; bottom: 0; background: var(--s1); border-top: 1px solid var(--line); display: flex; padding: 8px 4px calc(8px + var(--safe-b)); z-index: 20; }
.tabbar button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11px; font-weight: 600; color: var(--dim); padding: 4px 0; }
.tabbar button .ic { width: 56px; height: 30px; border-radius: 15px; display: grid; place-items: center; }
.tabbar button.on { color: var(--text); } .tabbar button.on .ic { background: var(--soft); color: var(--accent); }
svg.i { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
svg.i.s { width: 16px; height: 16px; }

.seg { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--line); margin: 0 -20px; padding: 0 16px; position: sticky; top: var(--safe-t); background: var(--bg); z-index: 5; }
.seg::-webkit-scrollbar { display: none; }
.seg button { padding: 12px 14px 10px; font-weight: 700; color: var(--dim); border-bottom: 3px solid transparent; white-space: nowrap; display: flex; flex-direction: column; align-items: center; }
.seg button.on { color: var(--text); border-bottom-color: var(--accent); }
.seg button .n { font-size: 11px; font-weight: 600; color: var(--dim); } .seg button .n.ok { color: var(--ok); }

/* Workout */
.wtop { position: sticky; top: 0; z-index: 6; background: var(--bg); padding: calc(10px + var(--safe-t)) 12px 6px; margin-top: calc(-1 * var(--safe-t)); display: flex; align-items: center; gap: 6px; }
.progress { height: 3px; background: var(--s2); margin: 0 -20px; } .progress > div { height: 100%; background: var(--accent); }
.banner { background: rgba(249,115,22,.12); color: var(--warn); font-size: 13px; font-weight: 600; padding: 8px 20px; margin: 0 -20px; }
.block { padding: 16px 12px 16px 18px; }
.block.current { border-color: rgba(59,130,246,.7); }
.letter { width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff; font-weight: 900; font-size: 13px; display: grid; place-items: center; flex: none; }
.setrow { border-radius: 16px; padding: 8px 6px; }
.setrow.next { background: rgba(22,41,74,.55); }
.setrow .lbl { width: 32px; font-weight: 900; font-size: 12px; color: var(--dim); flex: none; }
.setrow.next .lbl { color: var(--accent); }
.inputs { display: flex; gap: 8px; margin-top: 8px; align-items: center; }
.f { height: 44px; border-radius: 12px; background: var(--s2); border: 0; text-align: center; font-weight: 700; min-width: 0; flex: 1; padding: 0 4px; outline: none; }
.f::placeholder { color: var(--dim); font-weight: 400; }
.f:focus { background: var(--s3); }
select.f { appearance: none; -webkit-appearance: none; flex: 0 0 80px; font-size: 14px; text-align-last: center; }
select.f.unset { color: var(--dim); font-weight: 400; }
.stretch, .donerow, .collapsed, .menu button { text-align: left; width: 100%; }
.check { width: 48px; height: 44px; border-radius: 12px; background: var(--s3); color: var(--dim); display: grid; place-items: center; flex: none; }
.check.active { background: var(--accent); color: #fff; } .check.done { background: var(--ok); color: #fff; }
.donerow { display: flex; align-items: center; padding: 10px 6px; border-radius: 12px; }
.donerow .lbl { width: 32px; font-weight: 900; font-size: 12px; color: var(--ok); }
.collapsed { display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-radius: 20px; background: rgba(34,197,94,.08); border: 1px solid rgba(34,197,94,.3); }
.hitbar { background: rgba(34,197,94,.12); color: var(--ok); border-radius: 12px; padding: 10px 12px; font-size: 13px; font-weight: 600; }
.note { font-style: italic; color: var(--dim); font-size: 13px; }
.dots { width: 36px; height: 36px; display: grid; place-items: center; color: var(--dim); border-radius: 10px; flex: none; }
.stretch { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-radius: 18px; background: var(--s1); border: 1px solid var(--s2); font-weight: 600; }
.stretch.on { background: rgba(34,197,94,.1); border-color: rgba(34,197,94,.5); color: var(--dim); }
.box { width: 22px; height: 22px; border-radius: 6px; border: 2px solid var(--dim); display: grid; place-items: center; flex: none; }
.stretch.on .box { background: var(--ok); border-color: var(--ok); color: #fff; }

.restbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--s1); border-top: 1px solid var(--s3); border-radius: 28px 28px 0 0; padding: 16px 20px calc(16px + var(--safe-b)); box-shadow: 0 -10px 30px rgba(0,0,0,.4); }
.restbar .t { font-size: 40px; font-weight: 900; font-variant-numeric: tabular-nums; }
.restbar .bar { height: 6px; border-radius: 3px; background: var(--s3); margin: 10px 0 12px; overflow: hidden; } .restbar .bar > div { height: 100%; background: var(--accent); }
.restbar .btns { display: flex; gap: 8px; } .restbar .btns button { flex: 1; height: 44px; border-radius: 14px; background: var(--s3); font-weight: 700; }
.restbar .btns button.go { background: var(--accent); }

/* Sheets */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 40; display: flex; align-items: flex-end; touch-action: none; }
/* The sheet scrolls on its own; overscroll never chains to the page behind it. */
.sheet { background: var(--s1); width: 100%; max-height: 88vh; max-height: 88dvh; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; touch-action: pan-y; border-radius: 28px 28px 0 0; padding: 22px 20px calc(22px + var(--safe-b)); display: flex; flex-direction: column; gap: 14px; }
.sheet .btn { height: 58px; font-size: 17px; flex: none; }
/* Save stays pinned to the bottom of the sheet so it's always reachable. */
.sheet .btn.save { position: sticky; bottom: calc(-22px - var(--safe-b)); margin-bottom: calc(-22px - var(--safe-b)); height: 62px; border-radius: 18px;
  box-shadow: 0 -16px 20px 4px var(--s1), 0 calc(22px + var(--safe-b)) 0 0 var(--s1); }
body.locked { position: fixed; left: 0; right: 0; overflow: hidden; }
.btn.inline { min-width: 96px; }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--s3); align-self: center; margin-top: -8px; }
.menu button { display: flex; align-items: center; gap: 14px; width: 100%; padding: 14px 4px; font-size: 16px; font-weight: 600; border-bottom: 1px solid var(--line); text-align: left; }
.menu button:last-child { border-bottom: 0; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; color: var(--dim); font-weight: 600; }
.field input, .field textarea, .field select { background: var(--s2); border: 1px solid var(--s3); border-radius: 14px; padding: 12px 14px; outline: none; width: 100%; }
.field input:focus, .field textarea:focus { border-color: var(--accent); }
.checkrow { display: flex; align-items: center; gap: 12px; padding: 8px 0; font-weight: 600; }
.toggle { width: 50px; height: 30px; border-radius: 15px; background: var(--s3); position: relative; flex: none; transition: background .2s; }
.toggle::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: left .2s; }
.toggle.on { background: var(--accent); } .toggle.on::after { left: 23px; }

.hbar { height: 8px; border-radius: 4px; background: var(--s2); overflow: hidden; } .hbar > div { height: 100%; border-radius: 4px; }
.heat { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 1fr); gap: 3px; }
.heat div { aspect-ratio: 1; border-radius: 3px; background: var(--s2); }
.listrow { display: flex; align-items: center; gap: 10px; padding: 10px 4px; border-bottom: 1px solid var(--line); }
.listrow:last-child { border-bottom: 0; }
.toast { position: fixed; left: 20px; right: 20px; bottom: calc(110px + var(--safe-b)); z-index: 50; background: var(--s3); border-radius: 16px; padding: 14px 16px; font-weight: 600; box-shadow: 0 10px 30px rgba(0,0,0,.4); }
.trophy { font-size: 64px; text-align: center; animation: pop .5s cubic-bezier(.2,1.6,.4,1); }
@keyframes pop { from { transform: scale(.3); } to { transform: scale(1); } }
.empty { text-align: center; color: var(--dim); padding: 24px; }
.phase { display: flex; gap: 6px; } .phase div { flex: 1; text-align: center; padding: 8px 0; border-radius: 12px; background: var(--s2); }
.phase div.on { background: var(--accent); color: #fff; }
