:root {
  --bg: #101216;
  --card: #1a1d23;
  --card2: #22262e;
  --line: #2e333d;
  --text: #eef0f3;
  --muted: #9198a5;
  --accent: #ff8a3d;
  --accent-ink: #1a0d03;
  --good: #3ecf8e;
  --bad: #ff6b6b;
  --radius: 14px;
  --nav-h: 62px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) 0 calc(var(--nav-h) + env(safe-area-inset-bottom) + 70px);
  overscroll-behavior-y: contain;
}
body.locked { overflow: hidden; }
main { max-width: 560px; margin: 0 auto; padding: 0 14px; }
h1 { font-size: 26px; margin: 0; letter-spacing: -0.02em; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 22px 2px 8px; font-weight: 600; }
h3 { font-size: 16px; margin: 0 0 2px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.empty { color: var(--muted); text-align: center; padding: 40px 10px; }
.mt { margin-top: 14px; }
.mt-s { margin-top: 8px; }

.top { display: flex; align-items: center; gap: 10px; padding: 16px 2px 12px; position: sticky; top: 0; background: var(--bg); z-index: 5; }
.title-input { flex: 1; min-width: 0; background: transparent; border: 0; color: var(--text); font: 700 22px/1.2 var(--font); padding: 4px 0; outline: none; border-bottom: 1px dashed transparent; }
.title-input:focus { border-bottom-color: var(--line); }
.elapsed { font-variant-numeric: tabular-nums; color: var(--accent); font-weight: 700; background: var(--card); padding: 5px 10px; border-radius: 999px; }

.card { display: block; width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; color: inherit; text-align: left; font: inherit; }
.card.flat { background: var(--card2); border: 0; padding: 10px 12px; margin-bottom: 8px; }
button.card { cursor: pointer; }
button.card:active { background: var(--card2); }
.row { display: flex; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 4px; }
.gap { gap: 8px; }
.grow { flex: 1; }
.push { margin-left: auto; }
.line { padding: 7px 0; border-bottom: 1px solid var(--line); gap: 10px; }
.line:last-child { border-bottom: 0; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--card); color: var(--text); font: 600 15px var(--font); padding: 11px 16px; border-radius: 12px; cursor: pointer; min-height: 44px; }
.btn:active { transform: scale(0.98); }
.btn.block { display: flex; width: 100%; }
.btn.big { padding: 16px; font-size: 17px; margin-top: 6px; }
.btn.small { padding: 6px 12px; min-height: 34px; font-size: 13px; border-radius: 10px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.danger-ghost { background: transparent; color: var(--bad); border-color: #4a2a2e; }
.icon-btn { background: var(--card2); border: 0; color: var(--text); width: 36px; height: 36px; border-radius: 10px; font-size: 17px; cursor: pointer; flex: none; }

.tiles { display: flex; gap: 6px; }
.tiles > div { flex: 1; text-align: center; min-width: 0; }
.tiles b { display: block; font-size: 17px; line-height: 1.25; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.tiles span { font-size: 12px; color: var(--muted); }

.pick { display: flex; align-items: center; gap: 12px; }
.pick > div { flex: 1; min-width: 0; }
.pick .small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.go { color: var(--accent); font-weight: 700; }
.hist .small:last-child { margin-top: 4px; color: var(--text); opacity: 0.85; }

/* exercise card + set rows */
.ex-head { display: flex; align-items: flex-start; gap: 10px; justify-content: space-between; }
.hint { font-size: 13px; background: rgba(255, 138, 61, 0.1); color: #ffc49b; border-radius: 10px; padding: 8px 10px; margin: 10px 0 6px; }
.set { display: grid; grid-template-columns: 30px 1fr 74px 62px 44px; gap: 8px; align-items: center; padding: 5px 0; }
.set.head { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); padding-bottom: 0; }
.set.head span:nth-child(3), .set.head span:nth-child(4) { text-align: center; }
.set .n { text-align: center; font-weight: 700; color: var(--muted); }
.set .prev { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.set input { width: 100%; background: var(--card2); border: 1px solid transparent; color: var(--text); border-radius: 9px; padding: 9px 4px; font: 600 16px var(--font); text-align: center; font-variant-numeric: tabular-nums; -moz-appearance: textfield; }
.set input::-webkit-outer-spin-button, .set input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.set input:focus { outline: none; border-color: var(--accent); }
.chk { width: 44px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--card2); color: var(--muted); cursor: pointer; display: grid; place-items: center; }
.set.done { background: rgba(62, 207, 142, 0.08); border-radius: 10px; }
.set.done .chk { background: var(--good); border-color: var(--good); color: #062417; }
.set.done input { background: transparent; }

/* rest timer bar */
.rest { position: fixed; left: 10px; right: 10px; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 8px); max-width: 540px; margin: 0 auto; background: var(--card2); border: 1px solid var(--accent); border-radius: 14px; padding: 8px 8px 8px 14px; display: flex; align-items: center; gap: 6px; z-index: 20; overflow: hidden; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5); }
.rest[hidden] { display: none; }
.rest-fill { position: absolute; left: 0; top: 0; bottom: 0; background: rgba(255, 138, 61, 0.16); transition: width 0.5s linear; z-index: -1; }
.rest-label { color: var(--muted); font-size: 13px; }
.rest-time { font: 800 22px/1 var(--font); font-variant-numeric: tabular-nums; margin-right: auto; }
.rest button { background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 8px 11px; font: 600 14px var(--font); cursor: pointer; }

/* bottom nav */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: rgba(16, 18, 22, 0.96); backdrop-filter: blur(10px); border-top: 1px solid var(--line); display: flex; z-index: 10; }
.tabs button { flex: 1; background: none; border: 0; color: var(--muted); font: 600 11px var(--font); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; cursor: pointer; position: relative; }
.tabs svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabs button.on { color: var(--accent); }
.tabs button.live::after { content: ""; position: absolute; top: 9px; right: calc(50% - 17px); width: 8px; height: 8px; border-radius: 50%; background: var(--good); }

/* modal sheet */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); z-index: 30; display: flex; align-items: flex-end; justify-content: center; }
.modal[hidden] { display: none; }
.sheet { background: var(--bg); width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto; border-radius: 20px 20px 0 0; padding: 4px 16px calc(20px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); animation: up 0.18s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: var(--bg); padding: 14px 0 10px; z-index: 1; }
.sheet-head h2 { margin: 0; font-size: 19px; text-transform: none; letter-spacing: 0; color: var(--text); }
.pick-row { display: flex; flex-direction: column; align-items: flex-start; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); color: var(--text); padding: 12px 2px; font: 600 15px var(--font); cursor: pointer; }
.pick-row.danger { color: var(--bad); }
.pick-row:active { background: var(--card); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 6px; margin: 10px 0 4px; scrollbar-width: none; }
.chip { background: var(--card2); border: 1px solid var(--line); color: var(--text); border-radius: 999px; padding: 5px 11px; font: 600 13px var(--font); white-space: nowrap; }
button.chip { cursor: pointer; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* forms */
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.text, select { display: block; width: 100%; margin-top: 4px; background: var(--card); border: 1px solid var(--line); color: var(--text); border-radius: 11px; padding: 11px 12px; font: 16px var(--font); }
select.push { width: auto; margin-top: 0; padding: 7px 10px; }
.text:focus, select:focus { outline: none; border-color: var(--accent); }
main > .text, main > select { margin-bottom: 10px; }
.ritem { display: flex; gap: 10px; align-items: center; }
.ritem label { margin: 0; display: flex; align-items: center; gap: 6px; }
.ritem input { width: 58px; background: var(--card2); border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 6px; font: 600 15px var(--font); text-align: center; }
input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); }
.seg { display: inline-flex; background: var(--card2); border-radius: 10px; padding: 3px; }
.seg button { background: none; border: 0; color: var(--muted); padding: 6px 14px; border-radius: 8px; font: 600 14px var(--font); cursor: pointer; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }

/* tools */
.calc-out { margin-top: 4px; }
.plates { display: flex; align-items: center; gap: 4px; min-height: 84px; padding: 4px 0 8px; }
.plates::before { content: ""; width: 26px; height: 10px; background: var(--muted); border-radius: 3px; }
.plate { background: var(--accent); color: var(--accent-ink); font: 700 11px var(--font); border-radius: 4px; min-width: 26px; padding: 0 3px; display: grid; place-items: center; }
.big-num { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; }
.pct { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 8px; font-variant-numeric: tabular-nums; }
.pct div { background: var(--card2); border-radius: 8px; padding: 6px; text-align: center; font-weight: 600; font-size: 14px; }
.pct span { display: block; font-size: 11px; font-weight: 500; }

canvas { display: block; width: 100%; margin-top: 8px; }

.toast { position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 14px); transform: translate(-50%, -20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px; opacity: 0; pointer-events: none; transition: 0.2s; z-index: 40; max-width: calc(100% - 28px); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 360px) {
  .set { grid-template-columns: 24px 1fr 64px 54px 40px; gap: 6px; }
}
