:root {
  --bg: #f6f4f1;
  --surface: #ffffff;
  --surface-2: #efece7;
  --ink: #1c1b19;
  --ink-2: #57534c;
  --muted: #827c73;
  --line: #e2ded7;
  --accent: #d9480f;
  --accent-ink: #ffffff;
  --accent-soft: #fde8dc;
  --full: #d9480f;
  --short: #1971c2;
  --hard: #7048e8;
  --rest: #868e96;
  --warn-bg: #fff4d6;
  --warn-ink: #7a5300;
  --shadow: 0 1px 2px rgba(28, 27, 25, .06), 0 2px 8px rgba(28, 27, 25, .04);
  --r: 16px;
  --tab-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121110;
    --surface: #1c1b19;
    --surface-2: #262421;
    --ink: #f2efe9;
    --ink-2: #bdb7ad;
    --muted: #8c867c;
    --line: #34312c;
    --accent: #ff8a4c;
    --accent-ink: #1c1206;
    --accent-soft: #3a2416;
    --full: #ff8a4c;
    --short: #4dabf7;
    --hard: #9775fa;
    --rest: #868e96;
    --warn-bg: #3a2e10;
    --warn-ink: #ffd772;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121110; --surface: #1c1b19; --surface-2: #262421; --ink: #f2efe9; --ink-2: #bdb7ad; --muted: #8c867c;
  --line: #34312c; --accent: #ff8a4c; --accent-ink: #1c1206; --accent-soft: #3a2416; --full: #ff8a4c; --short: #4dabf7;
  --hard: #9775fa; --rest: #868e96; --warn-bg: #3a2e10; --warn-ink: #ffd772; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
svg { display: block; }
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 18px; font-weight: 650; }
h3 { font-size: 16px; font-weight: 650; margin-bottom: 8px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); font-weight: 400; }
.small { font-size: 14px; }
.center { text-align: center; }

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(var(--tab-h) + env(safe-area-inset-bottom) + 24px);
}

/* ---------- headers ---------- */
.day-head, .page-head { margin-bottom: 14px; }
.page-head h1 { padding: 8px 0; }
.day-nav { display: flex; align-items: center; gap: 8px; }
.day-nav h1, .day-title { flex: 1; text-align: center; }
.eyebrow { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); }
.day-head .link-btn { display: block; margin: 6px auto 0; }

.icon-btn {
  width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
  color: var(--ink-2); background: var(--surface); box-shadow: var(--shadow); border: 1px solid var(--line);
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn.sm { width: 40px; height: 40px; flex: none; }
.icon-btn:active { transform: scale(.96); }

.link-btn { color: var(--accent); font-weight: 600; font-size: 15px; padding: 8px 0; min-height: 36px; }
.link-btn.danger { color: #c92a2a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .link-btn.danger { color: #ff8787; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 16px; border-radius: 12px; font-weight: 600; text-decoration: none;
}
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: var(--surface-2); color: var(--ink); }
.btn.block { width: 100%; margin: 4px 0 8px; }
.btn:active { transform: scale(.98); }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }

/* ---------- why ---------- */
.why {
  width: 100%; text-align: left; display: flex; align-items: baseline; gap: 12px;
  padding: 14px 16px; margin-bottom: 14px; border-radius: var(--r);
  background: var(--accent-soft); color: var(--ink);
}
.why-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); flex: none; }
.why-text { font-size: 17px; font-weight: 600; }

/* ---------- segmented ---------- */
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 14px; }
.seg-btn { min-height: 40px; border-radius: 10px; font-size: 14px; font-weight: 600; color: var(--ink-2); }
.seg-btn[aria-checked="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.seg-btn[aria-checked="true"]::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; background: var(--c); }
.t-full { --c: var(--full); } .t-short { --c: var(--short); } .t-hard-moment { --c: var(--hard); } .t-rest { --c: var(--rest); }

.hint { color: var(--ink-2); font-size: 15px; margin: 10px 2px; }
.hint.small { font-size: 14px; margin: 0 0 10px; }

.banner { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; margin: 10px 0; font-size: 15px; }
.banner svg { width: 20px; height: 20px; flex: none; margin-top: 1px; }
.banner.warn { background: var(--warn-bg); color: var(--warn-ink); }

/* ---------- lists ---------- */
.list-head { display: flex; align-items: baseline; justify-content: space-between; margin: 20px 2px 10px; }
.count { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ink-2); }
.ex-list, .hard-list { display: flex; flex-direction: column; gap: 10px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: 14px 16px; margin-top: 14px; box-shadow: var(--shadow);
}

/* ---------- exercise card ---------- */
.ex { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; }
.ex-head { display: flex; align-items: center; gap: 4px; padding: 8px 8px 8px 10px; }
.check {
  width: 44px; height: 44px; border-radius: 50%; flex: none; display: grid; place-items: center;
  border: 2px solid var(--line); color: transparent; transition: background .15s, border-color .15s;
}
.check svg { width: 22px; height: 22px; }
.check.sm { width: 32px; height: 32px; }
.check.sm svg { width: 18px; height: 18px; }
.ex.done .check, .hard.on .check { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.ex-title { flex: 1; text-align: left; padding: 6px 6px; min-height: 44px; display: flex; flex-direction: column; justify-content: center; }
.ex-name { font-weight: 650; font-size: 17px; }
.ex-rx { font-size: 14px; color: var(--ink-2); }
.ex-rx .logged { color: var(--ink); font-weight: 500; }
.ex-note { font-size: 13px; color: var(--muted); font-style: italic; }
.chev { color: var(--muted); padding-right: 4px; }
.chev svg, .rules-head svg { width: 22px; height: 22px; transition: transform .15s; }
.ex.open .chev svg, .open > .rules-head svg, .rules-head[aria-expanded="true"] svg { transform: rotate(180deg); }

.ex-body { padding: 4px 16px 16px; border-top: 1px solid var(--line); }
.last { font-size: 14px; color: var(--ink-2); background: var(--surface-2); padding: 8px 10px; border-radius: 10px; margin: 12px 0 8px; }
.ex-body > .hint.small { margin-top: 12px; }
.label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin: 10px 0 6px; text-transform: uppercase; letter-spacing: .05em; }
.field-row .label { margin-top: 12px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px 4px; padding: 2px 16px 8px; scrollbar-width: none; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip {
  min-height: 40px; padding: 8px 14px; border-radius: 999px; font-weight: 600; font-size: 15px; white-space: nowrap;
  background: var(--surface-2); color: var(--ink-2); border: 1.5px solid transparent;
}
.chip[aria-pressed="true"] { background: var(--accent-soft); color: var(--ink); border-color: var(--accent); }
.input.chip-input { width: 92px; min-height: 40px; border-radius: 999px; padding: 6px 14px; }

.input {
  width: 100%; background: var(--surface-2); border: 1.5px solid transparent; border-radius: 12px;
  padding: 10px 12px; min-height: 44px; font-size: 16px; /* 16px stops iOS zoom */
}
.input:focus { outline: none; border-color: var(--accent); }
textarea.input { resize: vertical; line-height: 1.4; }

.sets { margin-top: 12px; }
.set-row { display: flex; align-items: center; justify-content: space-between; padding: 4px 0; }
.set-n { font-weight: 600; color: var(--ink-2); font-size: 15px; }
.stepper { display: flex; align-items: center; gap: 4px; }
.step { width: 44px; height: 44px; border-radius: 12px; background: var(--surface-2); display: grid; place-items: center; color: var(--ink); }
.step svg { width: 18px; height: 18px; }
.step:active { background: var(--line); }
.reps { min-width: 104px; text-align: center; font-size: 15px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.reps strong { font-size: 19px; color: var(--ink); }
.set-actions { display: flex; gap: 18px; }

.howto { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.howto p { color: var(--ink-2); font-size: 15px; }
.howto .cue { font-size: 13px; color: var(--muted); }
.video { position: relative; width: 100%; aspect-ratio: 16 / 9; border-radius: 12px; overflow: hidden; background: #000; margin: 8px 0; }
.video iframe, .video video { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

.done-card { margin-top: 14px; padding: 18px; border-radius: var(--r); background: var(--accent); color: var(--accent-ink); text-align: center; }
.done-title { display: flex; justify-content: center; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; }
.done-title svg { width: 22px; height: 22px; }
.done-why { margin: 8px 0 0; font-size: 20px; font-weight: 700; }

/* ---------- hard moment ---------- */
.hard {
  width: 100%; text-align: left; display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px;
  border-radius: 14px; background: var(--surface); border: 1px solid var(--line);
}
.hard-wrap .hard { background: var(--surface-2); border-color: transparent; }
.hard-name { display: block; font-weight: 650; }
.hard-desc { display: block; font-size: 14px; color: var(--ink-2); }
.hard-wrap .hard-list { margin-top: 10px; }

.rules-head { width: 100%; display: flex; justify-content: space-between; align-items: center; font-weight: 650; min-height: 32px; text-align: left; }
.rules-head .muted { font-weight: 400; }
.rule-list { margin: 10px 0 0; padding-left: 20px; color: var(--ink-2); }
.rule-list li { margin: 6px 0; }

.rest-card { margin-top: 20px; padding: 18px; border-radius: var(--r); background: var(--surface-2); }
.rest-card h2 { margin-bottom: 6px; }
.rest-card p { color: var(--ink-2); }
.rest-card svg { display: inline; width: 16px; height: 16px; vertical-align: -3px; }

/* ---------- calendar ---------- */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow { text-align: center; font-size: 12px; font-weight: 600; color: var(--muted); padding: 4px 0; }
.cal-cell {
  position: relative; aspect-ratio: 1; border-radius: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--surface); border: 1px solid var(--line); font-variant-numeric: tabular-nums; gap: 1px;
}
.cal-cell.empty { background: none; border: 0; }
.cal-num { font-size: 15px; font-weight: 500; }
.cal-tag { font-size: 11px; font-weight: 700; line-height: 1; padding: 2px 5px; border-radius: 6px; background: var(--c); color: var(--surface); }
.cal-cell[class*="t-"] { background: color-mix(in srgb, var(--c) 14%, var(--surface)); border-color: color-mix(in srgb, var(--c) 35%, var(--line)); }
.cal-cell.today .cal-num { color: var(--accent); font-weight: 800; }
.cal-cell.today { box-shadow: inset 0 0 0 2px var(--accent); }
.cal-cell.sel { outline: 2px solid var(--ink); outline-offset: 1px; }
.plus-dot { position: absolute; top: 5px; right: 5px; width: 7px; height: 7px; border-radius: 50%; background: var(--hard); box-shadow: 0 0 0 2px var(--surface); }
.legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 14px; margin: 14px 0 4px; font-size: 13px; color: var(--ink-2); }
.leg { display: inline-flex; align-items: center; gap: 6px; }
.leg-sw { font-style: normal; font-size: 11px; font-weight: 700; padding: 2px 5px; border-radius: 6px; background: var(--c); color: var(--surface); }
.detail-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.badge { font-size: 13px; font-weight: 700; padding: 3px 8px; border-radius: 8px; background: var(--c); color: var(--surface); white-space: nowrap; }
.detail-list { list-style: none; margin: 4px 0 10px; padding: 0; }
.detail-list li { padding: 8px 0; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; }
.detail-list li span { font-size: 14px; color: var(--ink-2); }
.detail-list li em { font-size: 14px; color: var(--muted); }
.detail-note { color: var(--ink-2); font-style: italic; }

/* ---------- progress ---------- */
.hero { padding: 14px 4px 4px; }
.hero-num { font-size: 34px; font-weight: 750; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.hero-num .arrow { color: var(--accent); }
.hero-sub { color: var(--ink-2); font-size: 14px; }
.chart { position: relative; }
.chart svg { width: 100%; height: auto; 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(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .pt { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart .pt.active { r: 6.5; }
.chart .hit { fill: transparent; cursor: pointer; outline: none; }
.tip {
  position: absolute; transform: translate(-50%, -100%); background: var(--ink); color: var(--bg);
  font-size: 13px; padding: 6px 10px; border-radius: 8px; white-space: nowrap; pointer-events: none; z-index: 2;
}
.tip[data-align="start"] { transform: translate(-12px, -100%); }
.tip[data-align="end"] { transform: translate(calc(-100% + 12px), -100%); }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 4px 0 6px; }
.table td { padding: 8px 8px 8px 0; border-top: 1px solid var(--line); vertical-align: top; }
.table td:first-child { white-space: nowrap; color: var(--ink-2); width: 72px; }
.empty-state { text-align: center; padding: 40px 16px; color: var(--ink-2); }

/* ---------- more ---------- */
.mot-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.mot-row { display: flex; gap: 8px; align-items: center; }
.mot-row .btn { flex: none; }
.ex-edit { border-top: 1px solid var(--line); padding: 10px 0; }
.ex-edit:first-of-type { border-top: 0; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.form-grid label { font-size: 13px; font-weight: 600; color: var(--ink-2); display: flex; flex-direction: column; gap: 4px; }
.form-grid .span2 { grid-column: span 2; }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tab-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); font-size: 12px; font-weight: 600; }
.tab svg { width: 24px; height: 24px; }
.tab[aria-current="page"] { color: var(--accent); }

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

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

.sync-status { font-weight: 600; margin-bottom: 10px; }
.sync-status.err { color: #c92a2a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .sync-status.err { color: #ff8787; } }
