:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #efece5;
  --text: #1a1c1e;
  --muted: #6a6e74;
  --line: #e1ddd4;
  --accent: #f0612a;
  --accent-ink: #ffffff;
  --accent-soft: #fde6dc;
  --good: #1f8a5b;
  --good-soft: #dcf1e6;
  --fig: #1f2226;
  --fig-far: #b9b5ab;
  --prop: #d9d4c9;
  --ground: #cfc9bd;
  --prot: #f0a37f;
  --veg: #8fc79a;
  --carb: #f2cf73;
  --fat: #c9a6e8;
  --shadow: 0 1px 2px rgba(20, 20, 20, .05), 0 6px 20px rgba(20, 20, 20, .05);
  --radius: 18px;
  --tabbar-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1113; --surface: #181b1f; --surface-2: #22262c; --text: #f2f0eb; --muted: #9aa0a8;
    --line: #2b3037; --accent: #ff7a42; --accent-soft: #3a2218; --good: #46c08a; --good-soft: #15322a;
    --fig: #f2f0eb; --fig-far: #5b616a; --prop: #343a42; --ground: #3a4048;
    --prot: #c9764f; --veg: #4f8f5c; --carb: #b8943c; --fat: #8c6bb0;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1113; --surface: #181b1f; --surface-2: #22262c; --text: #f2f0eb; --muted: #9aa0a8;
  --line: #2b3037; --accent: #ff7a42; --accent-soft: #3a2218; --good: #46c08a; --good-soft: #15322a;
  --fig: #f2f0eb; --fig-far: #5b616a; --prop: #343a42; --ground: #3a4048;
  --prot: #c9764f; --veg: #4f8f5c; --carb: #b8943c; --fat: #8c6bb0;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
h1, h2, h3, h4 { line-height: 1.2; margin: 0; letter-spacing: -0.01em; }
p { margin: 0 0 .75em; }
[hidden] { display: none !important; }

/* ---------- Top bar & tabs ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 18px; letter-spacing: -0.02em; }
.brand svg { width: 26px; height: 26px; }
.week-pill { font-size: 13px; font-weight: 700; background: var(--accent-soft); color: var(--accent); padding: 4px 10px; border-radius: 999px; }

main { max-width: 720px; margin: 0 auto; padding: 4px 16px 0; }
.view { animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

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

/* ---------- Shared ---------- */
.page-title { font-size: 30px; font-weight: 800; letter-spacing: -0.03em; margin: 8px 0 6px; }
.lede { color: var(--muted); font-size: 16px; margin-bottom: 16px; }
.muted { color: var(--muted); }
.fine { color: var(--muted); font-size: 13px; margin: 10px 0 0; }
.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; margin: 0 0 14px; border: 1px solid var(--line);
}
.card h2 { font-size: 19px; font-weight: 750; margin-bottom: 12px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 14px; padding: 13px 18px; font-weight: 700; font-size: 16px;
  background: var(--surface-2); color: var(--text); transition: transform .08s ease, filter .15s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.good { background: var(--good); color: #fff; }
.btn.block { width: 100%; }
.btn.lg { padding: 16px 20px; font-size: 18px; border-radius: 16px; }
.btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 7px 13px; font-size: 14px; font-weight: 600;
}
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

/* ---------- Figure ---------- */
.fig { display: block; width: 100%; height: auto; }
.fig-limb, .fig-trunk { fill: none; stroke: var(--fig); stroke-linecap: round; stroke-linejoin: round; stroke-width: 9; }
.fig-limb.far { stroke: var(--fig-far); }
.fig-trunk { stroke-width: 15; }
.fig-head { fill: var(--fig); }
.fig-eye { fill: var(--bg); }
.fig-ground { stroke: var(--ground); stroke-width: 2; stroke-linecap: round; }
.fig-prop { fill: var(--prop); }
.fig-db-bar { stroke: var(--accent); stroke-width: 3; stroke-linecap: round; fill: none; }
.fig-db { stroke: var(--accent); stroke-width: 6; stroke-linecap: round; fill: none; }
.fig-db.end { stroke-width: 12; }
.fig-db.far, .fig-db-bar.far { opacity: .45; }

/* ---------- Today ---------- */
.hello { margin: 6px 0 14px; }
.hello .date { color: var(--muted); font-weight: 600; font-size: 14px; }
.hero {
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
  border-radius: 22px; overflow: hidden; margin-bottom: 14px;
}
.hero-fig { background: linear-gradient(180deg, var(--accent-soft), transparent 90%); padding: 8px 18% 0; }
.hero-body { padding: 4px 18px 18px; }
.hero-kicker { font-size: 13px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .06em; }
.hero h1 { font-size: 30px; font-weight: 800; letter-spacing: -0.03em; margin: 2px 0 4px; }
.hero .sub { color: var(--muted); margin-bottom: 12px; }
.stats { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.stat { background: var(--surface-2); border-radius: 12px; padding: 8px 12px; min-width: 0; }
.stat b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); font-weight: 600; }
.deload-note { background: var(--surface-2); border-radius: 12px; padding: 10px 14px; font-size: 14px; margin-bottom: 12px; }
.done-banner { display: flex; align-items: center; gap: 10px; background: var(--good-soft); color: var(--good); font-weight: 700; padding: 10px 14px; border-radius: 12px; margin-bottom: 12px; }
.daypick { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 12px; scrollbar-width: none; }
.daypick::-webkit-scrollbar { display: none; }
.daypick .chip { white-space: nowrap; }

.block-h { display: flex; align-items: baseline; justify-content: space-between; margin: 18px 2px 8px; }
.block-h h3 { font-size: 16px; font-weight: 750; }
.block-h span { font-size: 13px; color: var(--muted); font-weight: 600; }
.ex-list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.ex-row { display: flex; align-items: center; gap: 12px; padding: 8px 14px 8px 8px; border-top: 1px solid var(--line); width: 100%; background: none; border-left: 0; border-right: 0; border-bottom: 0; text-align: left; }
.ex-row:first-child { border-top: 0; }
.ex-thumb { width: 78px; flex: 0 0 78px; background: var(--surface-2); border-radius: 12px; }
.ex-info { flex: 1; min-width: 0; }
.ex-info b { display: block; font-size: 15px; font-weight: 650; }
.ex-info span { font-size: 13px; color: var(--muted); }
.ex-amt { font-weight: 750; font-variant-numeric: tabular-nums; font-size: 15px; white-space: nowrap; }

/* ---------- Week / library ---------- */
.week-list { display: grid; gap: 10px; }
.wday { display: flex; align-items: center; gap: 14px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; text-align: left; width: 100%; }
.wday.today { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.wday .dname { width: 44px; font-weight: 800; color: var(--muted); font-size: 14px; }
.wday .dmain { flex: 1; min-width: 0; }
.wday .dmain b { display: block; }
.wday .dmain span { color: var(--muted); font-size: 13px; }
.wday .dot { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); flex: 0 0 auto; display: grid; place-items: center; }
.wday .dot.done { background: var(--good); border-color: var(--good); }
.wday .dot svg { width: 14px; height: 14px; stroke: #fff; stroke-width: 3; fill: none; }
.why { margin-top: 16px; }
.why li { margin-bottom: 6px; }
.lib { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.lib-card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.lib-card .fig-wrap { background: var(--surface-2); }
.lib-card .lib-body { padding: 10px 12px 12px; }
.lib-card b { display: block; font-size: 15px; }
.lib-card span { font-size: 12.5px; color: var(--muted); }
.lib-card ul { margin: 8px 0 0; padding-left: 18px; font-size: 13px; color: var(--muted); }
.lib-filter { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0 12px; }
h2.section { font-size: 22px; font-weight: 800; margin: 26px 0 10px; letter-spacing: -0.02em; }

/* ---------- Diet ---------- */
.calc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.calc-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 650; color: var(--muted); }
.calc-grid .span2 { grid-column: span 2; }
.calc-grid input, .calc-grid select, .field {
  width: 100%; border: 1px solid var(--line); background: var(--surface-2); border-radius: 10px; padding: 10px 11px; font-size: 16px; color: var(--text);
}
.calc-grid .inline { display: flex; align-items: center; gap: 6px; color: var(--text); font-weight: 500; }
.calc-grid .inline input { width: 64px; }
.targets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 16px; }
.target { background: var(--surface-2); border-radius: 14px; padding: 10px; text-align: center; }
.target b { display: block; font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.target span { font-size: 12px; color: var(--muted); font-weight: 650; }
.target.kcal { background: var(--accent-soft); }
.target.kcal b { color: var(--accent); }
.targets .note { grid-column: 1 / -1; font-size: 13px; color: var(--muted); }
.rules { padding-left: 20px; margin: 0; }
.rules li { margin-bottom: 10px; }
.ticks { list-style: none; padding: 0; margin: 0; }
.ticks li { position: relative; padding-left: 24px; margin-bottom: 10px; }
.ticks li::before { content: ""; position: absolute; left: 2px; top: 8px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.plate { display: grid; grid-template-columns: 170px 1fr; gap: 16px; align-items: center; }
.plate svg { width: 100%; }
.plate-t { font-size: 15px; font-weight: 800; fill: #1a1c1e; }
.legend { list-style: none; padding: 0; margin: 0; font-size: 14px; }
.legend li { display: flex; gap: 8px; margin-bottom: 8px; }
.legend i { flex: 0 0 12px; height: 12px; border-radius: 4px; margin-top: 5px; }
.meal-h { font-size: 15px; font-weight: 750; margin: 18px 0 8px; color: var(--accent); }
.meals { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.meal { background: var(--surface-2); border-radius: 14px; padding: 12px; }
.meal h4 { font-size: 15px; margin-bottom: 4px; }
.meal p { font-size: 13.5px; color: var(--muted); margin: 0 0 6px; }
.meal .mac { font-size: 12.5px; font-weight: 700; font-variant-numeric: tabular-nums; }
.meal em { display: block; font-size: 12px; color: var(--muted); margin-top: 4px; }
.snacks { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.adjust { width: 100%; border-collapse: collapse; font-size: 14px; }
.adjust th, .adjust td { text-align: left; padding: 9px 8px; border-top: 1px solid var(--line); vertical-align: top; }
.adjust th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; border-top: 0; }
.grocery { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.grocery h4 { font-size: 14px; margin-bottom: 4px; }
.grocery p { font-size: 14px; color: var(--muted); }
.honest { border-color: var(--accent); }

/* ---------- Progress ---------- */
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px; }
.kpi b { display: block; font-size: 28px; font-weight: 800; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.kpi span { font-size: 12.5px; color: var(--muted); font-weight: 650; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.cal .dh { font-size: 11px; color: var(--muted); text-align: center; font-weight: 700; }
.cal .c { aspect-ratio: 1; border-radius: 7px; background: var(--surface-2); display: grid; place-items: center; font-size: 11px; color: var(--muted); font-weight: 650; }
.cal .c.done { background: var(--good); color: #fff; }
.cal .c.today { box-shadow: 0 0 0 2px var(--accent) inset; }
.cal .c.future { opacity: .4; }
.wi-form { display: flex; gap: 8px; margin-bottom: 12px; }
.wi-form input { flex: 1; min-width: 0; }
.wi-table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.wi-table th, .wi-table td { text-align: left; padding: 8px 6px; border-top: 1px solid var(--line); }
.wi-table th { font-size: 12px; color: var(--muted); border-top: 0; }
.wi-table .down { color: var(--good); font-weight: 700; }
.wi-table .up { color: var(--accent); font-weight: 700; }
.backup-btns { display: flex; gap: 10px; }
.backup-btns .btn { flex: 1; }
.backup-nag { background: var(--accent-soft); color: var(--accent); font-weight: 650; font-size: 14px; border-radius: 10px; padding: 8px 12px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.set-row:first-of-type { border-top: 0; }
.set-row small { display: block; color: var(--muted); font-size: 13px; }
.switch { position: relative; width: 50px; height: 30px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: .2s; }
.switch span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch input:checked + span { background: var(--good); }
.switch input:checked + span::after { transform: translateX(20px); }

/* ---------- Player ---------- */
.player {
  position: fixed; inset: 0; z-index: 50; background: var(--bg);
  display: flex; flex-direction: column;
  padding: calc(env(safe-area-inset-top) + 8px) 16px calc(env(safe-area-inset-bottom) + 12px);
  overflow-y: auto;
}
.player.rest { background: linear-gradient(180deg, var(--accent-soft), var(--bg) 55%); }
.pl-top { display: flex; align-items: center; gap: 10px; max-width: 560px; width: 100%; margin: 0 auto; }
.icon-btn { width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--surface-2); display: grid; place-items: center; flex: 0 0 auto; }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.pl-meta { flex: 1; min-width: 0; text-align: center; }
.pl-block { font-weight: 750; font-size: 14px; }
.pl-count { font-size: 12px; color: var(--muted); font-weight: 600; }
.pl-progress { height: 5px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 10px auto 0; max-width: 560px; width: 100%; }
.pl-progress span { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s ease; }
.pl-body { flex: 1; display: flex; flex-direction: column; max-width: 560px; width: 100%; margin: 0 auto; padding-top: 6px; }
.pl-fig { background: var(--surface); border: 1px solid var(--line); border-radius: 22px; padding: 4px 6%; }
.rest .pl-fig { opacity: .92; }
.pl-label { text-align: center; font-size: 13px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); margin-top: 14px; }
.pl-name { text-align: center; font-size: 26px; font-weight: 800; letter-spacing: -0.02em; margin: 4px 0 2px; }
.pl-name small { display: block; font-size: 15px; color: var(--accent); font-weight: 700; letter-spacing: 0; }
.pl-muscles { text-align: center; color: var(--muted); font-size: 14px; margin: 0 0 8px; }
.pl-center { display: flex; align-items: center; justify-content: center; gap: 18px; margin: 6px 0 10px; }
.adj { width: 46px; height: 46px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); font-size: 24px; font-weight: 600; display: grid; place-items: center; line-height: 1; }
.ring { position: relative; width: 168px; height: 168px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .track { stroke: var(--surface-2); }
.ring .bar { stroke: var(--accent); transition: stroke-dashoffset .1s linear; }
.ring.done .bar { stroke: var(--good); }
.ring-time { position: absolute; inset: 0; display: grid; place-items: center; font-size: 46px; font-weight: 800; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.reps { text-align: center; min-width: 150px; }
.reps b { display: block; font-size: 72px; line-height: 1; font-weight: 850; letter-spacing: -0.04em; font-variant-numeric: tabular-nums; }
.reps span { font-size: 15px; color: var(--muted); font-weight: 650; }
.pl-actions { display: flex; gap: 10px; margin: 4px 0 12px; }
.pl-actions .btn { flex: 1; }
.pl-actions .btn.primary { flex: 2; }
.pl-extra { display: flex; flex-direction: column; gap: 10px; }
.weight-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 8px 12px; font-size: 14px; font-weight: 650; }
.weight-row input { width: 80px; border: 1px solid var(--line); background: var(--surface-2); border-radius: 8px; padding: 6px 8px; font-size: 16px; }
.weight-row small { color: var(--muted); font-weight: 500; flex-basis: 100%; }
.cues { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.cues h4 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 6px; }
.cues ul { margin: 0; padding-left: 18px; font-size: 14.5px; }
.cues li { margin-bottom: 3px; }
.cues .alt { font-size: 13px; color: var(--muted); margin: 8px 0 0; }
.pl-nav { display: flex; justify-content: space-between; gap: 10px; margin-top: 14px; max-width: 560px; width: 100%; margin-left: auto; margin-right: auto; }
.pl-nav .btn { background: transparent; color: var(--muted); padding: 10px 12px; font-size: 15px; }
.next-up { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 8px 14px 8px 8px; margin-top: 8px; }
.next-up .ex-thumb { width: 96px; flex-basis: 96px; }
.next-up small { display: block; font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }
.next-up b { font-size: 17px; }
.next-up span { display: block; color: var(--muted); font-size: 14px; }
.summary { text-align: center; padding-top: 40px; }
.summary .big { font-size: 64px; }
.summary h2 { font-size: 30px; font-weight: 850; margin: 8px 0; letter-spacing: -0.03em; }
.summary .stats { justify-content: center; margin: 18px 0 24px; }

@media (max-width: 420px) {
  .plate { grid-template-columns: 1fr; }
  .plate svg { max-width: 190px; margin: 0 auto; }
  .targets { grid-template-columns: repeat(2, 1fr); }
  .ring { width: 150px; height: 150px; }
  .ring-time { font-size: 40px; }
  .reps b { font-size: 64px; }
  .pl-name { font-size: 23px; }
}
@media (min-height: 800px) { .pl-fig { padding: 8px 8%; } }
