:root {
  --bg: #f6f4ef;
  --card: #ffffff;
  --ink: #1b2124;
  --muted: #5d676c;
  --line: #e3dfd6;
  --accent: #0f766e;
  --accent-soft: #d8efec;
  --accent-ink: #ffffff;
  --gym: #0f766e;
  --pool: #1d6fb8;
  --home: #8a5a14;
  --rest: #9aa3a7;
  --warn: #a15c00;
  --warn-bg: #fff3dc;
  --warn-line: #f0c777;
  --bad: #b42318;
  --bad-bg: #fde8e6;
  --good: #1f7a3a;
  --good-bg: #e3f4e8;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1416;
    --card: #182023;
    --ink: #eef2f3;
    --muted: #9fabb0;
    --line: #2a3438;
    --accent: #2bb3a5;
    --accent-soft: #143633;
    --accent-ink: #062321;
    --gym: #2bb3a5;
    --pool: #5aa9ef;
    --home: #e0a54a;
    --rest: #66737a;
    --warn: #f0b44c;
    --warn-bg: #33270f;
    --warn-line: #6b5120;
    --bad: #ff8a80;
    --bad-bg: #3a1714;
    --good: #6fd39a;
    --good-bg: #12301f;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1416; --card: #182023; --ink: #eef2f3; --muted: #9fabb0; --line: #2a3438;
  --accent: #2bb3a5; --accent-soft: #143633; --accent-ink: #062321;
  --gym: #2bb3a5; --pool: #5aa9ef; --home: #e0a54a; --rest: #66737a;
  --warn: #f0b44c; --warn-bg: #33270f; --warn-line: #6b5120;
  --bad: #ff8a80; --bad-bg: #3a1714; --good: #6fd39a; --good-bg: #12301f;
  --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: 17px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
img { max-width: 100%; display: block; }
button, input { font: inherit; color: inherit; }
a { color: var(--accent); }
.wrap { max-width: 760px; margin: 0 auto; padding: 0 16px; }

.top { background: var(--card); border-bottom: 1px solid var(--line); padding: 12px 0 10px; padding-top: calc(12px + env(safe-area-inset-top)); }
.brand { font-weight: 750; font-size: 19px; }
.sub { color: var(--muted); font-size: 15px; }

h1 { font-size: 26px; line-height: 1.2; margin: 20px 0 4px; }
h2 { font-size: 20px; margin: 28px 0 10px; display: flex; align-items: center; gap: 10px; }
h3 { font-size: 17px; margin: 0 0 6px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px; box-shadow: var(--shadow); margin-bottom: 12px; }

.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 650; padding: 3px 10px; border-radius: 99px; color: #fff; }
.pill.gym { background: var(--gym); } .pill.pool { background: var(--pool); } .pill.home { background: var(--home); } .pill.rest { background: var(--rest); }
:root:not([data-theme="light"]) .pill { color: #fff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .pill { color: #0b1214; } }

/* Day strip */
.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin: 14px 0 4px; }
.day { text-decoration: none; color: inherit; border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 6px 0 7px; text-align: center; cursor: pointer; }
.day b { display: block; font-size: 17px; }
.day small { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.day .dots { display: flex; justify-content: center; gap: 3px; margin-top: 3px; height: 7px; }
.day .dots i { width: 7px; height: 7px; border-radius: 50%; }
.day.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.day.today b { color: var(--accent); }
i.gym { background: var(--gym); } i.pool { background: var(--pool); } i.home { background: var(--home); }

/* Heel check */
.heel-row { margin: 10px 0 4px; }
.heel-row .lbl { font-weight: 650; margin-bottom: 6px; display: flex; justify-content: space-between; }
.scale { display: grid; grid-template-columns: repeat(11, 1fr); gap: 4px; }
.scale button { border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 8px 0; font-weight: 650; font-size: 15px; cursor: pointer; min-width: 0; }
.scale button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.scale-ends { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 3px; }

.banner { border-radius: 12px; padding: 12px 14px; margin-top: 12px; font-weight: 550; border: 1px solid; }
.banner.good { background: var(--good-bg); color: var(--good); border-color: transparent; }
.banner.warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-line); }
.banner.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }

/* Session header */
.sess-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.progressbar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin: 10px 0 2px; }
.progressbar > div { height: 100%; background: var(--accent); width: 0; transition: width .3s; }

/* Exercise card */
.ex { display: grid; grid-template-columns: 170px 1fr; gap: 14px; align-items: start; }
.ex + .ex { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 14px; }
.ex .num { font-size: 13px; font-weight: 700; color: var(--muted); }
.ex h3 { margin: 0 0 2px; cursor: pointer; }
.ex .dose { font-size: 22px; font-weight: 750; letter-spacing: -.01em; }
.ex .where { font-size: 14px; color: var(--muted); }
.ex.done h3 { text-decoration: line-through; text-decoration-color: var(--accent); text-decoration-thickness: 2px; }
.ex .flag { margin-top: 6px; font-size: 14px; color: var(--warn); font-weight: 600; }
.ex .later { margin-top: 6px; font-size: 14px; color: var(--muted); font-style: italic; }
.ex .swap { margin-top: 6px; font-size: 14px; background: var(--accent-soft); border-radius: 8px; padding: 6px 9px; }

.anim { position: relative; border-radius: 12px; overflow: hidden; background: #ddd; aspect-ratio: 3 / 2; cursor: pointer; }
.anim img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.anim img.b { animation: flip 3.2s infinite; }
.anim .tag { position: absolute; left: 6px; bottom: 6px; font-size: 11px; font-weight: 700; color: #fff; background: rgba(0,0,0,.62); padding: 2px 7px; border-radius: 6px; }
.anim .tag.t2 { animation: flip 3.2s infinite; }
.anim .tag.t1 { animation: flipr 3.2s infinite; }
.anim.svg { background: var(--card); border: 1px solid var(--line); display: grid; place-items: center; }
.anim.svg svg { width: 92%; height: 92%; }
@keyframes flip { 0%, 42% { opacity: 0; } 50%, 92% { opacity: 1; } 100% { opacity: 0; } }
@keyframes flipr { 0%, 42% { opacity: 1; } 50%, 92% { opacity: 0; } 100% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .anim img.b, .anim .tag.t2, .anim .tag.t1 { animation: none; }
  .anim img.b, .anim .tag.t2 { opacity: 0; }
}

.sets { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; align-items: center; }
.setbtn { min-width: 52px; height: 44px; border-radius: 10px; border: 2px solid var(--line); background: var(--bg); font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 4px; padding: 0 10px; }
.setbtn.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.kg { display: inline-flex; align-items: center; gap: 6px; border: 2px solid var(--line); border-radius: 10px; height: 44px; padding: 0 10px; background: var(--bg); }
.kg input { width: 58px; border: 0; background: transparent; font-weight: 700; font-size: 17px; outline: none; }
.kg span { color: var(--muted); font-size: 14px; }

/* Toggle */
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--accent-soft); border-radius: 12px; padding: 10px 12px; margin: 8px 0 14px; }
.switch { position: relative; width: 52px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; background: var(--rest); border-radius: 99px; transition: background .2s; }
.switch span::after { content: ""; position: absolute; width: 24px; height: 24px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform .2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(22px); }

/* Plan grid */
.legend { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 14px; }
.grid { display: grid; grid-template-columns: 44px repeat(7, 1fr); gap: 4px; }
.grid .h { font-size: 12px; color: var(--muted); text-align: center; font-weight: 650; text-transform: uppercase; }
.grid .wk { font-size: 13px; color: var(--muted); font-weight: 700; display: flex; align-items: center; }
.cell { text-decoration: none; border-radius: 8px; min-height: 40px; display: flex; flex-direction: column; align-items: center; justify-content: center; font-weight: 750; font-size: 14px; cursor: pointer; border: 1px solid var(--line); background: var(--card); color: var(--muted); }
.cell.gym { background: var(--gym); border-color: var(--gym); color: #fff; }
.cell.pool { background: var(--pool); border-color: var(--pool); color: #fff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .cell.gym, :root:not([data-theme="light"]) .cell.pool { color: #0b1214; } }
:root[data-theme="dark"] .cell.gym, :root[data-theme="dark"] .cell.pool { color: #0b1214; }
.cell.past { opacity: .45; }
.cell.now { outline: 3px solid var(--ink); outline-offset: 1px; }
.cell small { font-size: 10px; font-weight: 600; opacity: .9; }
.phase { border-left: 5px solid var(--accent); }
.phase h3 { display: flex; justify-content: space-between; gap: 8px; }

/* Library */
.lib { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.lib .item { background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; cursor: pointer; text-align: left; padding: 0; }
.lib .item .anim { border-radius: 0; }
.lib .item div.t { padding: 8px 10px 10px; font-weight: 650; font-size: 15px; line-height: 1.25; }
.lib .item div.t small { display: block; font-weight: 500; color: var(--muted); font-size: 13px; margin-top: 2px; }

/* Sheet */
dialog { border: 0; padding: 0; width: min(680px, 100%); max-height: 92vh; border-radius: 18px 18px 0 0; margin: auto auto 0; background: var(--card); color: var(--ink); }
@media (min-width: 720px) { dialog { border-radius: 18px; margin: auto; } }
dialog::backdrop { background: rgba(0,0,0,.55); }
#sheetBody { padding: 0 0 20px; }
.sheet-img { aspect-ratio: 3 / 2; border-radius: 0; }
.sheet-pad { padding: 14px 16px 0; }
.close { position: sticky; top: 0; float: right; margin: 10px; z-index: 2; width: 40px; height: 40px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; font-size: 22px; line-height: 40px; cursor: pointer; }
.steps { counter-reset: s; list-style: none; padding: 0; margin: 10px 0; }
.steps li { counter-increment: s; position: relative; padding-left: 40px; margin-bottom: 10px; min-height: 30px; }
.steps li::before { content: counter(s); position: absolute; left: 0; top: -2px; width: 29px; height: 29px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-weight: 750; display: grid; place-items: center; font-size: 15px; }
.careful { background: var(--warn-bg); border: 1px solid var(--warn-line); color: var(--ink); border-radius: 12px; padding: 10px 12px; margin: 10px 0; }
.careful b { color: var(--warn); }
.gymphoto { border-radius: 12px; overflow: hidden; margin-top: 8px; }
.twoimg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 8px; }
.twoimg figure { margin: 0; }
.twoimg figcaption { font-size: 13px; color: var(--muted); font-weight: 650; margin-top: 3px; }
.twoimg img { border-radius: 10px; }

/* Gym */
.gymgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.gymgrid figure { margin: 0; background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.gymgrid img { aspect-ratio: 4 / 3; object-fit: cover; width: 100%; }
.gymgrid figcaption { padding: 8px 10px 10px; font-size: 15px; }
.gymgrid figcaption b { display: block; }

/* Lists */
.do, .dont { list-style: none; padding: 0; margin: 6px 0 0; }
.do li, .dont li { padding: 8px 0 8px 34px; position: relative; border-bottom: 1px solid var(--line); }
.do li:last-child, .dont li:last-child { border-bottom: 0; }
.do li::before, .dont li::before { position: absolute; left: 0; top: 7px; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 14px; }
.do li::before { content: "✓"; background: var(--good-bg); color: var(--good); }
.dont li::before { content: "✕"; background: var(--bad-bg); color: var(--bad); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 46px; padding: 0 18px; border-radius: 12px; border: 0; background: var(--accent); color: var(--accent-ink); font-weight: 700; cursor: pointer; text-decoration: none; }
.btn.ghost { background: transparent; border: 2px solid var(--line); color: var(--ink); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); font-weight: 600; }
.field input { height: 44px; border: 2px solid var(--line); border-radius: 10px; padding: 0 10px; background: var(--bg); font-size: 17px; color: var(--ink); }

.chart { width: 100%; height: auto; }
.chart text { fill: var(--muted); font-size: 11px; }
.keyline { display: inline-flex; align-items: center; gap: 6px; margin-right: 14px; font-size: 14px; }
.keyline i { width: 18px; height: 4px; border-radius: 2px; display: inline-block; }

table.log { width: 100%; border-collapse: collapse; font-size: 15px; }
table.log td, table.log th { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
table.log th { color: var(--muted); font-size: 13px; font-weight: 650; }

.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.compare .card { margin: 0; }

/* Bottom tabs */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; background: var(--card); border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(5, 1fr); padding-bottom: env(safe-area-inset-bottom); z-index: 5; }
.tabs a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 7px; text-decoration: none; color: var(--muted); font-size: 12px; font-weight: 650; }
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabs a.on { color: var(--accent); }

.foot { margin: 30px 0 10px; font-size: 13px; color: var(--muted); }

@media (max-width: 420px) {
  .ex { grid-template-columns: 140px 1fr; gap: 12px; }
  .ex .dose { font-size: 20px; }
  .scale button { font-size: 14px; padding: 7px 0; }
}
