:root {
  --bg: #FAF6F2;
  --surface: #FFFFFF;
  --surface-2: #F3ECE6;
  --ink: #2A211D;
  --muted: #7A6B63;
  --line: #E8DED6;
  --accent: #C4544A;
  --accent-ink: #FFFFFF;
  --accent-soft: #F7E2DD;
  --ok: #2F8560;
  --ok-soft: #DCEFE4;
  --warn: #A86A12;
  --warn-soft: #F8EBD3;
  --shadow: 0 1px 2px rgba(42, 33, 29, .05), 0 4px 16px rgba(42, 33, 29, .05);
  --radius: 18px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16120F;
    --surface: #211B17;
    --surface-2: #2B241F;
    --ink: #F3ECE7;
    --muted: #A8988E;
    --line: #3A312B;
    --accent: #E57D6F;
    --accent-ink: #1A1210;
    --accent-soft: #3E2521;
    --ok: #62C497;
    --ok-soft: #1D3A2C;
    --warn: #E3AA55;
    --warn-soft: #3A2C17;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
[hidden] { display: none !important; }

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 18px) 16px calc(env(safe-area-inset-bottom) + 96px);
}
body.in-workout #app { padding-bottom: calc(env(safe-area-inset-bottom) + 120px); }

h1 { font-size: 28px; line-height: 1.15; margin: 0; letter-spacing: -.02em; }
h2 { font-size: 19px; margin: 0 0 10px; letter-spacing: -.01em; }
h3 { font-size: 17px; margin: 0; letter-spacing: -.01em; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.eyebrow { font-size: 13px; font-weight: 600; color: var(--accent); text-transform: uppercase; letter-spacing: .06em; }
.stack > * + * { margin-top: 12px; }
.section { margin-top: 26px; }
.row { display: flex; align-items: center; gap: 12px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 12px; }
.card.accent { background: var(--accent-soft); border-color: transparent; }
.card.ok { background: var(--ok-soft); border-color: transparent; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 0 20px; border-radius: 14px;
  background: var(--accent); color: var(--accent-ink);
  font-weight: 650; font-size: 17px; width: 100%;
  transition: transform .08s ease, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn.secondary { background: var(--surface-2); color: var(--ink); }
.btn.danger { background: transparent; color: var(--accent); border: 1px solid var(--line); }
.btn.small { min-height: 40px; font-size: 15px; width: auto; padding: 0 14px; border-radius: 12px; }
.btn-ghost {
  min-height: 38px; padding: 0 12px; border-radius: 10px;
  background: rgba(255,255,255,.18); color: inherit; font-weight: 600; font-size: 15px;
}
.link { color: var(--accent); font-weight: 600; font-size: 15px; padding: 8px 0; }

/* Header */
.top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.date-chip { font-size: 14px; color: var(--muted); margin-top: 4px; }

/* Program progress */
.prog-bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin-top: 12px; }
.prog-bar > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.phase-pill {
  display: inline-block; font-size: 13px; font-weight: 600; padding: 4px 10px; border-radius: 99px;
  background: var(--surface-2); color: var(--ink);
}

/* Today */
.today { padding: 20px; }
.today .code {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: 13px; background: var(--accent); color: var(--accent-ink);
  font-weight: 750; font-size: 16px; flex: none;
}
.today h2 { margin: 0; font-size: 22px; }
.today .btn { margin-top: 16px; }
.today .btn + .btn { margin-top: 8px; }

/* Week strip */
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.day {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 0 10px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line);
  font-size: 12px; color: var(--muted); min-width: 0;
}
.day b { font-size: 16px; color: var(--ink); font-weight: 650; }
.day .tag { font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 6px; background: var(--surface-2); color: var(--ink); }
.day .tag.rest { background: transparent; color: var(--muted); font-weight: 500; }
.day.today { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.day.done .tag { background: var(--ok); color: #fff; }
.day.missed .tag { background: var(--warn-soft); color: var(--warn); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 12px; }
.stat b { display: block; font-size: 22px; letter-spacing: -.02em; }
.stat span { font-size: 12.5px; color: var(--muted); }

.session-list .item {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px;
}
.session-list .item + .item { margin-top: 8px; }
.session-list .code-sm {
  width: 36px; height: 36px; border-radius: 11px; background: var(--surface-2);
  display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; flex: none;
}
.session-list .item.is-done .code-sm { background: var(--ok); color: #fff; }
.session-list .grow { flex: 1; min-width: 0; }
.chev { color: var(--muted); font-size: 22px; line-height: 1; }

.banner {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--accent); color: var(--accent-ink); border-radius: 16px; padding: 14px 16px; margin-bottom: 16px;
}
.banner b { display: block; }

/* Workout */
.wk-head {
  position: sticky; top: 0; z-index: 5;
  margin: calc(-1 * (env(safe-area-inset-top) + 18px)) -16px 0;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px;
}
.back {
  width: 40px; height: 40px; border-radius: 12px; background: var(--surface-2);
  display: inline-flex; align-items: center; justify-content: center; font-size: 22px; flex: none;
}
.wk-head .grow { flex: 1; min-width: 0; }
.wk-head h1 { font-size: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.elapsed { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--muted); font-size: 15px; }
.wk-progress { height: 4px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.wk-progress span { display: block; height: 100%; background: var(--ok); transition: width .3s; }
.rule { font-size: 14px; color: var(--muted); margin: 14px 2px 12px; }

.ex-card { scroll-margin-top: 90px; }
.ex-card.complete { border-color: color-mix(in srgb, var(--ok) 45%, var(--line)); }
.ex-top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.ex-meta { font-size: 14px; color: var(--muted); margin-top: 2px; }
.ex-count {
  font-size: 13px; font-weight: 700; padding: 4px 9px; border-radius: 99px; background: var(--surface-2); flex: none;
  font-variant-numeric: tabular-nums;
}
.ex-card.complete .ex-count { background: var(--ok); color: #fff; }
.last { font-size: 14px; margin-top: 10px; color: var(--muted); }
.last b { color: var(--ink); font-weight: 600; }
.hint { font-size: 14px; margin-top: 8px; padding: 8px 10px; border-radius: 10px; }
.hint.up { background: var(--ok-soft); color: var(--ok); font-weight: 600; }
.hint.info { background: var(--surface-2); color: var(--ink); }
details.tip { margin-top: 8px; }
details.tip summary { font-size: 14px; font-weight: 600; color: var(--accent); cursor: pointer; list-style: none; padding: 4px 0; }
details.tip summary::-webkit-details-marker { display: none; }
details.tip summary::before { content: "▸ "; }
details.tip[open] summary::before { content: "▾ "; }
details.tip p { font-size: 14.5px; margin-top: 4px; }

.sets { margin-top: 12px; }
.set-head, .set-row { display: grid; grid-template-columns: 34px 1fr 1fr 52px; gap: 8px; align-items: center; }
.sets.bw .set-head, .sets.bw .set-row { grid-template-columns: 34px 1fr 52px; }
.set-head { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; padding: 0 0 6px; }
.set-head span:nth-child(n+2) { text-align: center; }
.set-row + .set-row { margin-top: 8px; }
.set-row .n { font-weight: 700; color: var(--muted); text-align: center; font-variant-numeric: tabular-nums; }
.set-row input {
  width: 100%; height: 46px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2);
  text-align: center; font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; outline: none;
  -moz-appearance: textfield; appearance: none;
}
.set-row input:focus { border-color: var(--accent); background: var(--surface); }
.set-row input::placeholder { color: var(--muted); opacity: .55; font-weight: 500; }
.check {
  height: 46px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--surface);
  display: inline-flex; align-items: center; justify-content: center; font-size: 20px; color: var(--muted);
  transition: background .15s, transform .08s;
}
.check:active { transform: scale(.94); }
.set-row.done .check { background: var(--ok); border-color: var(--ok); color: #fff; }
.set-row.done input { background: var(--ok-soft); border-color: transparent; }
.ex-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; }
.superset { font-size: 13.5px; color: var(--warn); font-weight: 600; margin-top: 8px; }

textarea {
  width: 100%; min-height: 80px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface);
  padding: 12px; font-size: 16px; resize: vertical; outline: none;
}
textarea:focus { border-color: var(--accent); }

/* Rest bar */
.restbar {
  position: fixed; left: 12px; right: 12px; z-index: 20;
  bottom: calc(env(safe-area-inset-bottom) + 12px);
  max-width: 536px; margin: 0 auto;
  background: var(--ink); color: var(--bg); border-radius: 18px; overflow: hidden;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
}
.restbar-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--accent); opacity: .9; transition: width .25s linear; }
.restbar-row { position: relative; display: flex; align-items: center; justify-content: space-between; padding: 12px 14px 12px 18px; }
.restbar-label { font-size: 13px; opacity: .85; font-weight: 600; }
.restbar-time { font-size: 28px; font-weight: 750; font-variant-numeric: tabular-nums; letter-spacing: -.02em; line-height: 1.1; }
.restbar-actions { display: flex; gap: 8px; }
.restbar.go .restbar-fill { width: 100% !important; background: var(--ok); }

/* Nav */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px 8px calc(env(safe-area-inset-bottom) + 6px);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.nav button { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; font-size: 11.5px; color: var(--muted); font-weight: 600; }
.nav svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav button.active { color: var(--accent); }

/* Segmented */
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); padding: 4px; border-radius: 13px; margin: 16px 0; }
.seg button { padding: 9px; border-radius: 10px; font-weight: 600; font-size: 15px; color: var(--muted); }
.seg button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* History */
.month { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 20px 4px 8px; }
.hist-item { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; }
.hist-item + .hist-item { margin-top: 8px; }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty .big { font-size: 40px; margin-bottom: 8px; }

/* Progress */
.prog-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; text-align: left; }
.prog-item + .prog-item { margin-top: 8px; }
.delta { font-weight: 700; font-size: 14px; padding: 3px 8px; border-radius: 99px; background: var(--ok-soft); color: var(--ok); white-space: nowrap; }
.delta.flat { background: var(--surface-2); color: var(--muted); }
.chart { width: 100%; height: auto; display: block; margin: 8px 0 4px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--accent); opacity: .1; }
.chart .dot { fill: var(--surface); stroke: var(--accent); stroke-width: 2; }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
table.mini { width: 100%; border-collapse: collapse; font-size: 14.5px; margin-top: 8px; }
table.mini td, table.mini th { padding: 8px 4px; border-bottom: 1px solid var(--line); text-align: left; }
table.mini th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
table.mini td:last-child, table.mini th:last-child { text-align: right; }

/* Guide */
.guide h2 { margin-top: 4px; }
.guide p + p, .guide ul + p, .guide p + ul { margin-top: 8px; }
.guide ul { margin: 0; padding-left: 20px; }
.guide li + li { margin-top: 6px; }
.guide table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.guide td, .guide th { padding: 7px 4px; border-bottom: 1px solid var(--line); text-align: left; }
.guide th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* Forms */
.field { display: block; }
.field + .field { margin-top: 16px; }
.field > span { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.field input[type=text], .field input[type=date], .field select {
  width: 100%; height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2);
  padding: 0 12px; font-size: 16px; outline: none; appearance: none; -webkit-appearance: none;
}
.field select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
.field input:focus, .field select:focus { border-color: var(--accent); }
.field .help { font-size: 13px; color: var(--muted); margin-top: 6px; }
.choice { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.choice button {
  padding: 14px 10px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--surface);
  font-weight: 650; text-align: center;
}
.choice button small { display: block; font-weight: 500; color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.choice button.active { border-color: var(--accent); background: var(--accent-soft); }
.days-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.toggle input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.settings-group + .settings-group { margin-top: 12px; }

/* Onboarding */
.onboard { padding-top: 24px; }
.onboard .logo { width: 72px; height: 72px; border-radius: 20px; display: block; margin-bottom: 18px; }
.onboard h1 { font-size: 32px; }

/* Modal sheet */
.modal { position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.4); animation: fade .2s ease; }
.sheet {
  position: relative; width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto;
  background: var(--bg); border-radius: 22px 22px 0 0;
  padding: 8px 18px calc(env(safe-area-inset-bottom) + 22px);
  animation: up .25s cubic-bezier(.2,.8,.2,1);
}
.sheet-grip { width: 40px; height: 5px; border-radius: 99px; background: var(--line); margin: 4px auto 14px; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } }
.summary-big { font-size: 46px; text-align: center; margin: 4px 0; }
.summary-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 16px 0; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 50;
  bottom: calc(env(safe-area-inset-bottom) + 96px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 15px; font-weight: 600;
  max-width: calc(100% - 32px); text-align: center; box-shadow: 0 8px 24px rgba(0,0,0,.2);
}

@media (min-width: 600px) {
  #app { padding-top: 32px; }
}
