*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  --bg: #0b0b0a;
  --surface: #151513;
  --surface-2: #1e1d1a;
  --line: #2b2925;
  --text: #f5f0e8;
  --muted: #a39d92;
  --faint: #6f6a62;
  --accent: #d9bd86;
  --accent-ink: #14110b;
  --danger: #e0846e;
  --font-brand: 'Cinzel', serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --tab-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

html { background: var(--bg); }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.45;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- top bar & layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: baseline; justify-content: center; gap: 8px;
  padding: calc(var(--safe-t) + 14px) 16px 12px;
  background: rgba(11, 11, 10, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { font-family: var(--font-brand); font-weight: 600; letter-spacing: 0.28em; text-transform: uppercase; font-size: 15px; }
.brand-sub { font-family: var(--font-brand); color: var(--accent); letter-spacing: 0.28em; text-transform: uppercase; font-size: 12px; }

.view {
  max-width: 600px; margin: 0 auto;
  padding: 20px 16px calc(var(--tab-h) + var(--safe-b) + 96px);
  outline: none;
}
body.resting .view { padding-bottom: calc(var(--tab-h) + var(--safe-b) + 150px); }

h1 { font-family: var(--font-brand); font-weight: 600; font-size: 24px; letter-spacing: 0.06em; margin-bottom: 4px; }
h2 { font-size: 12px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); margin: 28px 0 10px; }
.sub { color: var(--muted); font-size: 14px; }
.small { font-size: 13px; }
.muted { color: var(--muted); }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tab-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: rgba(14, 14, 13, 0.96);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  font-size: 11px; font-weight: 500; letter-spacing: 0.04em; color: var(--faint);
}
.tabbar a.on { color: var(--text); }
.tabbar a.on svg { stroke: var(--accent); }
.tabbar svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- cards & buttons ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.card + .card { margin-top: 10px; }
button.card { width: 100%; text-align: left; display: block; }
button.card:active { background: var(--surface-2); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 46px; padding: 0 18px; border-radius: 12px;
  font-weight: 600; font-size: 15px;
  background: var(--surface-2); border: 1px solid var(--line);
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn.sm { height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn-row { display: flex; gap: 10px; }
.btn-row > .btn { flex: 1; }

.chip {
  display: inline-flex; align-items: center; height: 32px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface-2); font-size: 13px; font-weight: 500; white-space: nowrap;
}
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }

.tag { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.tag.pr { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; letter-spacing: 0.04em; }

.icon-btn { width: 36px; height: 36px; border-radius: 10px; display: inline-grid; place-items: center; color: var(--muted); }
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }

.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button { height: 32px; padding: 0 12px; border-radius: 8px; font-size: 13px; font-weight: 500; color: var(--muted); }
.seg button.on { background: var(--text); color: var(--bg); }

.field { display: block; }
.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; letter-spacing: 0.04em; }
.input, select.input {
  width: 100%; height: 46px; padding: 0 12px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--line); font-size: 16px;
}
.input:focus { outline: none; border-color: var(--accent); }
select.input { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 20px, calc(100% - 13px) 20px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }

.empty { text-align: center; color: var(--muted); padding: 36px 12px; }
.empty.small { padding: 20px 8px; font-size: 14px; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stats.two { grid-template-columns: repeat(2, 1fr); }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.stat b { display: block; font-size: 22px; font-weight: 600; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }

/* ---------- active workout ---------- */
.wo-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.wo-name { flex: 1; min-width: 0; background: none; border: none; font-family: var(--font-brand); font-size: 22px; font-weight: 600; letter-spacing: 0.04em; padding: 4px 0; border-bottom: 1px dashed transparent; }
.wo-name:focus { outline: none; border-bottom-color: var(--line); }
.timer { font-variant-numeric: tabular-nums; color: var(--accent); font-weight: 600; }

.ex-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 12px 8px; margin-bottom: 12px; }
.ex-title { font-weight: 600; font-size: 16px; }
.ex-meta { font-size: 12px; color: var(--muted); }
.sets { width: 100%; border-collapse: collapse; margin-top: 8px; font-variant-numeric: tabular-nums; }
.sets th { font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--faint); text-align: center; padding: 4px 2px; }
.sets td { text-align: center; padding: 3px 2px; }
.sets td.n { width: 30px; color: var(--muted); font-weight: 600; }
.sets td.prev { color: var(--faint); font-size: 13px; width: 26%; }
.sets td.ok { width: 48px; }
.sets tr.done td { background: rgba(217, 189, 134, 0.08); }
.sets tr.done td:first-child { border-radius: 8px 0 0 8px; }
.sets tr.done td:last-child { border-radius: 0 8px 8px 0; }
.set-in {
  width: 100%; max-width: 88px; height: 40px; text-align: center; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--line); font-size: 16px; font-weight: 600;
}
.set-in::placeholder { color: var(--faint); font-weight: 500; }
.set-in:focus { outline: none; border-color: var(--accent); }
.check { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); display: inline-grid; place-items: center; }
.check svg { width: 20px; height: 20px; fill: none; stroke: var(--faint); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.check.on { background: var(--accent); border-color: var(--accent); }
.check.on svg { stroke: var(--accent-ink); }
.pr-dot { display: block; font-size: 9px; font-weight: 800; color: var(--accent); letter-spacing: 0.06em; }
.ex-foot { display: flex; gap: 8px; padding-top: 6px; }
.ex-foot .btn { flex: 1; }

/* ---------- rest timer ---------- */
.rest {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tab-h) + var(--safe-b)); z-index: 25;
  background: var(--surface-2); border-top: 1px solid var(--line);
}
.rest-bar { height: 3px; background: var(--line); }
.rest-fill { height: 100%; background: var(--accent); width: 0; transition: width 0.25s linear; }
.rest-row { max-width: 600px; margin: 0 auto; display: flex; align-items: center; gap: 8px; padding: 10px 16px; }
.rest-label { font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.rest-time { flex: 1; font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; }
.rest.done .rest-time { color: var(--accent); }
.rest.done { animation: pulse 0.8s ease-in-out 3; }
@keyframes pulse { 50% { background: #3a3222; } }

/* ---------- sheet (modal) ---------- */
.sheet { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.6); }
.sheet-panel {
  position: relative; width: 100%; max-width: 600px; max-height: 92dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface); border: 1px solid var(--line); border-bottom: none;
  border-radius: 18px 18px 0 0; padding: 18px 16px calc(20px + var(--safe-b));
  animation: up 0.22s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.sheet-head h3 { flex: 1; font-family: var(--font-brand); font-size: 19px; font-weight: 600; letter-spacing: 0.04em; }
.sheet-sticky { position: sticky; top: -18px; background: var(--surface); padding: 2px 0 10px; z-index: 2; }

.pick-list .pick { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 11px 4px; border-bottom: 1px solid var(--line); }
.pick-list .pick:active { background: var(--surface-2); }
.pick .name { font-weight: 500; }
.pick .meta { font-size: 12px; color: var(--muted); }
.pick.sel { color: var(--accent); }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--safe-b) + 18px); z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); font-weight: 600; font-size: 14px;
  padding: 10px 16px; border-radius: 999px; transition: 0.2s; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- lists ---------- */
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: none; }
.wo-card .title { font-weight: 600; }
.wo-card .lines { margin-top: 8px; font-size: 13px; color: var(--muted); line-height: 1.6; }
.wo-card .figs { display: flex; gap: 14px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.wo-card .figs b { color: var(--text); font-weight: 600; }

.detail-ex { padding: 10px 0; border-bottom: 1px solid var(--line); }
.detail-ex .sets-line { font-size: 14px; color: var(--muted); margin-top: 4px; font-variant-numeric: tabular-nums; }

/* ---------- charts ---------- */
.chart-wrap { position: relative; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .grid { stroke: #24231f; stroke-width: 1; }
.chart .axis-t { fill: var(--faint); font-size: 11px; font-family: var(--font-body); font-variant-numeric: tabular-nums; }
.chart .ln { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: url(#areaGrad); }
.chart .dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart .last-label { fill: var(--text); font-size: 12px; font-weight: 600; font-family: var(--font-body); }
.chart .xhair { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.tip {
  position: absolute; pointer-events: none; background: var(--text); color: var(--bg);
  padding: 6px 10px; border-radius: 8px; font-size: 12px; line-height: 1.35; white-space: nowrap;
  transform: translate(-50%, calc(-100% - 10px)); opacity: 0; transition: opacity 0.1s;
}
.tip b { font-size: 14px; }
.tip.show { opacity: 1; }

/* ---------- muscle map ---------- */
.bodies { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.body-fig { text-align: center; }
.body-fig svg { width: 100%; max-height: 420px; }
.body-fig .cap { font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--faint); margin-top: 2px; }
.silhouette { fill: #1b1a17; }
.mz { stroke: var(--bg); stroke-width: 1.2; cursor: pointer; transition: fill 0.2s, opacity 0.2s; }
.mz.dim { opacity: 0.35; }
.mz.sel { stroke: var(--text); stroke-width: 1.6; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 12px; font-size: 12px; color: var(--muted); justify-content: center; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 5px; }
.m-info { min-height: 58px; margin-top: 10px; }
.m-row { display: grid; grid-template-columns: 14px 1fr auto; align-items: center; gap: 10px; padding: 10px 2px; border-bottom: 1px solid var(--line); width: 100%; text-align: left; }
.m-row i { width: 12px; height: 12px; border-radius: 3px; }
.m-row .d { font-variant-numeric: tabular-nums; font-weight: 600; }
.m-row .w { font-size: 12px; color: var(--muted); }
.m-row.sel { background: var(--surface-2); }

/* ---------- plate calc ---------- */
.barbell { display: flex; align-items: center; justify-content: center; height: 130px; margin: 14px 0 6px; }
.bar-sleeve { height: 10px; background: #4a4740; border-radius: 2px; }
.bar-shaft { height: 6px; width: 46px; background: #4a4740; }
.bar-collar { width: 8px; height: 26px; background: #6b675e; border-radius: 2px; }
.plate {
  width: 16px; margin: 0 1px; border-radius: 3px; background: var(--text); color: var(--bg);
  display: grid; place-items: center; font-size: 9px; font-weight: 700; writing-mode: vertical-rl;
}
.plate.dark { background: #8f897d; }
.plate-list { text-align: center; font-size: 14px; color: var(--muted); }
.plate-list b { color: var(--text); }

@media (min-width: 700px) {
  .view { padding-top: 32px; }
  .sheet { align-items: center; }
  .sheet-panel { border-radius: 18px; border-bottom: 1px solid var(--line); }
}

/* ---------- profiles & lock ---------- */
.topbar { position: sticky; }
.who {
  position: absolute; right: 14px; bottom: 9px; height: 28px; padding: 0 10px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface-2); font-size: 12px; font-weight: 600; color: var(--muted);
}
body.locked .tabbar, body.locked .rest { display: none; }
body.locked .view { padding-bottom: 40px; }
.lock { display: flex; flex-direction: column; align-items: center; text-align: center; padding-top: 6vh; }
.lock h1 { margin-top: 14px; }
.lock-star svg { width: 64px; height: 64px; }
.profiles { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; width: 100%; max-width: 360px; margin-top: 26px; }
.profile {
  display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 24px 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; font-weight: 600; font-size: 16px;
}
.profile:active { background: var(--surface-2); }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; display: inline-grid; place-items: center; flex: none;
  background: var(--accent); color: var(--accent-ink); font-family: var(--font-brand); font-weight: 600; font-size: 18px;
}
.profile .avatar, .avatar.big { width: 64px; height: 64px; font-size: 28px; }
.pin-dots { display: flex; gap: 18px; margin: 22px 0 28px; }
.pin-dots i { width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid var(--muted); }
.pin-dots i.on { background: var(--text); border-color: var(--text); }
.pin-dots.shake { animation: shake 0.35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.keypad { display: grid; grid-template-columns: repeat(3, 76px); gap: 14px 22px; }
.keypad button {
  width: 76px; height: 76px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--line);
  font-size: 28px; font-weight: 500;
}
.keypad button:active { background: var(--line); }
.keypad .kp-text { background: none; border: none; font-size: 15px; color: var(--muted); }

.lock .sub { min-height: 22px; }
.welcome { padding-top: 14vh; cursor: pointer; animation: fadein 0.4s ease-out; }
.welcome-kicker { margin-top: 22px; font-size: 13px; letter-spacing: 0.32em; text-transform: uppercase; color: var(--accent); }
.welcome-name { font-size: 40px; margin-top: 6px; }
@keyframes fadein { from { opacity: 0; transform: translateY(8px); } }
