:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #111114;
  --muted: #6c6c72;
  --line: #e3e3e8;
  --accent: #0a7c4a;
  --accent-text: #ffffff;
  --accent-soft: #dff3e8;
  --warn: #b25b00;
  --today: #d92d20;
  --warn-soft: #fdeedc;
  --hard: #c0362c;
  --chip: #ececf1;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06);
  --radius: 16px;
  --tabs-h: 62px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --text: #f2f2f5;
    --muted: #9a9aa1;
    --line: #2f2f33;
    --accent: #30c27a;
    --accent-text: #00170b;
    --accent-soft: #123826;
    --warn: #ffb35c;
    --today: #ff453a;
    --warn-soft: #3a2a12;
    --hard: #ff6b5e;
    --chip: #2c2c2f;
    --shadow: none;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 17px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
  min-height: 100vh;
  overscroll-behavior-y: none;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; touch-action: manipulation; }
[hidden] { display: none !important; }

/* Шапка */
#top {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  padding: 14px 18px 10px;
  display: flex; align-items: baseline; gap: 12px;
}
#top h1 { font-size: 26px; line-height: 1.15; margin: 0; flex: 1; font-weight: 700; letter-spacing: -.3px; }
#top h1 small { display: block; font-size: 16px; font-weight: 500; color: var(--muted); letter-spacing: 0; margin-top: 2px; }
#top .count { font-size: 18px; font-weight: 600; color: var(--muted); white-space: nowrap; }
#top .back { font-size: 17px; color: var(--accent); font-weight: 600; padding: 8px 0; margin-right: 4px; }
.pending { font-size: 14px; color: var(--warn); background: var(--warn-soft); border-radius: 10px; padding: 4px 10px; align-self: center; }

main { padding: 4px 14px calc(var(--tabs-h) + env(safe-area-inset-bottom) + 24px); }

/* Нижние вкладки */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
#tabs button {
  flex: 1; height: var(--tabs-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); font-size: 13px; font-weight: 600;
}
#tabs svg { width: 27px; height: 27px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#tabs button.on { color: var(--accent); }

/* Карточки и строки */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px; }
.card h2 { font-size: 20px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 15px; }
.list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 12px; }

.row {
  display: flex; align-items: center; gap: 12px;
  min-height: 64px; padding: 10px 14px;
  border-top: 1px solid var(--line);
  width: 100%; text-align: left;
}
.row:first-child { border-top: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .name { font-size: 18px; font-weight: 600; line-height: 1.2; }
.row .sub { font-size: 15px; color: var(--muted); margin-top: 2px; }
.row .plan { font-size: 16px; color: var(--muted); white-space: nowrap; text-align: right; }
.row.done .name { color: var(--muted); font-weight: 500; }

/* Отметки */
.mark {
  flex: none; width: 34px; height: 34px; border-radius: 50%;
  border: 2.5px solid var(--line);
  display: grid; place-items: center;
}
.mark.on { background: var(--accent); border-color: var(--accent); }
.mark.on::after {
  content: ""; width: 12px; height: 7px; border: solid var(--accent-text); border-width: 0 0 3px 3px;
  transform: translateY(-2px) rotate(-45deg);
}
.mark.big { width: 48px; height: 48px; }

/* Картинки */
.thumb {
  flex: none; width: 56px; height: 56px; border-radius: 12px; object-fit: cover;
  background: var(--chip) url("/img/placeholder.svg") center / 60% no-repeat;
}
.thumb.lg { width: 104px; height: 104px; border-radius: 14px; }

/* Текущее упражнение */
.current { padding: 16px 14px 14px; border-top: 1px solid var(--line); background: var(--card); }
.current:first-child { border-top: 0; }
.current .head { display: flex; gap: 14px; align-items: flex-start; }
.current .title { font-size: 22px; font-weight: 700; line-height: 1.2; }
.current .target { font-size: 19px; margin-top: 6px; font-weight: 600; }
.current .hint { font-size: 15px; color: var(--muted); margin-top: 6px; }
.current .hint.warn { color: var(--warn); }
.rest { font-size: 16px; color: var(--muted); font-variant-numeric: tabular-nums; margin: 14px 2px 0; display: flex; justify-content: space-between; }
.rest b { color: var(--text); font-weight: 700; font-size: 20px; }

.sets { display: grid; grid-template-columns: repeat(var(--n, 4), 1fr); gap: 8px; margin-top: 14px; }
.set { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.set .circle {
  width: 64px; height: 64px; border-radius: 50%;
  border: 3px solid var(--line);
  display: grid; place-items: center;
  font-size: 20px; font-weight: 700; color: var(--muted);
}
.set .circle.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.set .circle.on::after {
  content: ""; width: 20px; height: 11px; border: solid var(--accent-text); border-width: 0 0 4px 4px;
  transform: translateY(-3px) rotate(-45deg);
}
.set .val {
  min-width: 76px; min-height: 48px; padding: 4px 8px; border-radius: 12px; background: var(--chip);
  display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.15;
  font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.set .val small { font-size: 13px; font-weight: 500; color: var(--muted); }
.set .val.plan { color: var(--muted); font-weight: 600; }

.feel { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; }
.feel button {
  min-height: 56px; border-radius: 14px; background: var(--chip); font-weight: 700; font-size: 17px;
}
.feel button.on { background: var(--accent); color: var(--accent-text); }
.feel-q { margin-top: 16px; font-size: 16px; color: var(--muted); }

.actions { display: flex; gap: 8px; margin-top: 14px; }
.actions button { flex: 1; min-height: 48px; border-radius: 12px; background: var(--chip); font-weight: 600; font-size: 16px; }

/* Кнопки */
.btn {
  display: block; width: 100%; min-height: 58px; border-radius: 16px;
  background: var(--accent); color: var(--accent-text);
  font-size: 19px; font-weight: 700; margin: 8px 0;
}
.btn.secondary { background: var(--card); color: var(--accent); box-shadow: var(--shadow); }
.btn.plain { background: var(--chip); color: var(--text); }
.btn.danger { background: var(--chip); color: var(--hard); }
.btn:disabled { opacity: .5; }
.btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btns .btn { margin: 0; }

textarea, input[type=text], input[type=date], input[type=time], input[type=search], input[inputmode] {
  width: 100%; border: 1.5px solid var(--line); border-radius: 14px; background: var(--card);
  padding: 14px; font-size: 17px; outline: none;
}
textarea { min-height: 190px; resize: vertical; line-height: 1.4; }
textarea:focus, input:focus { border-color: var(--accent); }
label.field { display: block; font-size: 15px; color: var(--muted); margin: 12px 0 6px; }

.banner { background: var(--accent-soft); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; font-size: 17px; }
.banner b { display: block; font-size: 19px; margin-bottom: 2px; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }

/* Нижняя панель */
#sheet { position: fixed; inset: 0; z-index: 30; }
#sheet .backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .4); }
#sheet .panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-height: calc(100% - env(safe-area-inset-top) - 24px);
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--bg); border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
}
#sheet .panel.full { height: calc(100% - env(safe-area-inset-top) - 12px); }
.sheet-head { position: sticky; top: -8px; z-index: 2; background: var(--bg); display: flex; align-items: center; gap: 10px; padding: 12px 0 10px; }
.sheet-head h3 { flex: 1; margin: 0; font-size: 21px; line-height: 1.2; }
.close { width: 44px; height: 44px; border-radius: 50%; background: var(--chip); font-size: 26px; line-height: 1; color: var(--muted); }

/* Правка подхода */
.stepper { display: grid; grid-template-columns: 64px 1fr 64px; gap: 10px; align-items: center; }
.stepper button { height: 64px; border-radius: 16px; background: var(--card); font-size: 32px; font-weight: 600; box-shadow: var(--shadow); }
.stepper input { text-align: center; font-size: 30px; font-weight: 700; height: 64px; padding: 0 8px; font-variant-numeric: tabular-nums; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chips button { min-height: 44px; padding: 0 14px; border-radius: 22px; background: var(--chip); font-weight: 600; font-variant-numeric: tabular-nums; }
.chips button.on { background: var(--accent); color: var(--accent-text); }

/* Список упражнений */
.search { position: sticky; top: 58px; z-index: 2; background: var(--bg); padding-bottom: 10px; }
.group-title { font-size: 15px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; margin: 16px 4px 8px; }

/* Картинка крупно */
.viewer { position: fixed; inset: 0; z-index: 40; background: #000; display: flex; flex-direction: column; }
.viewer img { flex: 1; min-height: 0; width: 100%; object-fit: contain; }
.viewer .bar { display: flex; align-items: center; justify-content: space-between; padding: calc(env(safe-area-inset-top) + 8px) 16px 8px; color: #fff; }
.viewer .bar .close { background: rgba(255, 255, 255, .16); color: #fff; }
.viewer .dots { display: flex; justify-content: center; gap: 8px; padding: 14px 0 calc(env(safe-area-inset-bottom) + 18px); }
.viewer .dots i { width: 9px; height: 9px; border-radius: 50%; background: rgba(255, 255, 255, .35); }
.viewer .dots i.on { background: #fff; }

/* Календарь */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin: 0 0 8px; }
.cal-head h2 { margin: 0; font-size: 21px; }
.cal-head button { width: 48px; height: 48px; border-radius: 50%; background: var(--card); font-size: 26px; color: var(--accent); box-shadow: var(--shadow); }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; }
.cal .wd { font-size: 13px; font-weight: 700; color: var(--muted); padding: 6px 0; }
.cal .day {
  aspect-ratio: 1 / 1.05; border-radius: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.cal .day .num { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; }
.cal .day.done .num { background: var(--accent); color: var(--accent-text); }
.cal .day.planned .num { box-shadow: inset 0 0 0 2.5px var(--accent); color: var(--accent); }
.cal .day.skipped .num { color: var(--muted); text-decoration: line-through; background: var(--chip); }
.cal .day.today .num { background: var(--today); color: #fff; }
.cal .day.today.done .num, .cal .day.today.planned .num, .cal .day.today.skipped .num { outline: 2.5px solid var(--today); outline-offset: 2px; }
.cal .day.today.done .num { background: var(--accent); color: var(--accent-text); }
.cal .day.today.planned .num { background: none; color: var(--accent); }
.cal .day.today.skipped .num { background: var(--chip); color: var(--muted); }
.cal .day.other { visibility: hidden; }
.legend { display: flex; justify-content: center; gap: 18px; margin: 14px 0 4px; font-size: 15px; color: var(--muted); }
.legend span { display: flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 14px; border-radius: 50%; display: inline-block; }
.legend .l-done { background: var(--accent); }
.legend .l-planned { box-shadow: inset 0 0 0 2px var(--accent); }
.legend .l-skipped { background: var(--chip); border: 1.5px solid var(--muted); }

.status { display: inline-block; font-size: 14px; font-weight: 700; padding: 3px 10px; border-radius: 10px; background: var(--chip); }
.status.done { background: var(--accent-soft); color: var(--accent); }
.status.planned { background: var(--warn-soft); color: var(--warn); }

/* Прогресс */
.weight-in { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.weight-in .btn { margin: 0; padding: 0 22px; width: auto; }
.verdict { font-size: 17px; margin: 14px 0 4px; }
.chart { width: 100%; height: 120px; display: block; margin-top: 12px; }
.chart path { fill: none; stroke: var(--accent); stroke-width: 2.5; }
.chart circle { fill: var(--accent); }
.chart text { fill: var(--muted); font-size: 11px; }
.dir { font-size: 22px; font-weight: 700; width: 28px; text-align: center; }
.dir.up { color: var(--accent); }
.dir.down { color: var(--hard); }
.dir.same, .dir.none { color: var(--muted); }

#toast {
  position: fixed; left: 16px; right: 16px; z-index: 50;
  bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 14px);
  background: #1c1c1e; color: #fff; border-radius: 14px; padding: 14px 16px; font-size: 16px; text-align: center;
}
@media (prefers-color-scheme: dark) { #toast { background: #3a3a3c; } }

.add-set { display: block; margin: 10px 0 0 auto; min-height: 40px; padding: 0 12px; font-size: 15px; color: var(--muted); font-weight: 600; }
.link { display: block; width: 100%; min-height: 48px; color: var(--muted); font-size: 16px; }
