/* ---------------------------------------------------------------- тема */
:root {
  --bg: #0f1216;
  --bg-soft: #151a21;
  --card: #1a2029;
  --card-2: #202834;
  --line: #2a3340;
  --text: #e6ebf2;
  --muted: #8b98a9;
  --accent: #3fb88f;
  --accent-soft: #173a30;
  --ok: #3fb950;
  --warn: #d9a441;
  --bad: #f0596b;
  --blue: #4c8dff;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --r: 14px;
  --r-sm: 9px;
  --tabbar-h: 62px;
}

:root[data-theme="light"] {
  --bg: #f2f4f8;
  --bg-soft: #e9edf3;
  --card: #ffffff;
  --card-2: #f5f7fa;
  --line: #dde3ec;
  --text: #16202c;
  --muted: #64748b;
  --accent: #14895f;
  --accent-soft: #d6f2e6;
  --ok: #1a7f37;
  --warn: #a86b00;
  --bad: #cf222e;
  --blue: #2563eb;
  --shadow: 0 10px 30px rgba(20, 30, 50, .10);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; padding: 0; min-height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h2, h3 { letter-spacing: -.01em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- кнопки и поля */
.btn {
  border: 1px solid var(--line);
  background: var(--card-2);
  border-radius: var(--r-sm);
  padding: 9px 14px;
  cursor: pointer;
  line-height: 1.2;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--accent); }
.btn-danger { color: var(--bad); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--card-2); border-color: transparent; }
.btn-icon { padding: 6px 10px; font-size: 18px; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-wide { width: 100%; padding: 12px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea, input.inp, select.inp {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus, input.inp:focus { border-color: var(--accent); }
.field textarea { min-height: 70px; resize: vertical; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.chip {
  border: 1px solid var(--line);
  background: var(--bg-soft);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13.5px;
  cursor: pointer;
}
.chip.is-on { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }

/* ---------------------------------------------------------------- вход */
.auth {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(1000px 500px at 15% -10%, var(--accent-soft), transparent 60%), var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px 26px 22px;
  box-shadow: var(--shadow);
}
.auth-card h1 { margin: 10px 0 2px; font-size: 25px; letter-spacing: -.02em; }
.auth-sub { margin: 0 0 20px; color: var(--muted); font-size: 13.5px; }
.seg { display: flex; gap: 4px; background: var(--bg-soft); border-radius: 10px; padding: 4px; margin-bottom: 18px; }
.seg-btn { flex: 1; border: 0; background: transparent; padding: 8px 10px; border-radius: 7px; cursor: pointer; color: var(--muted); }
.seg-btn.is-active { background: var(--card-2); color: var(--text); }
.auth-error {
  margin: 0 0 12px;
  padding: 9px 11px;
  border-radius: var(--r-sm);
  background: color-mix(in srgb, var(--bad) 16%, transparent);
  color: var(--bad);
  font-size: 13.5px;
}
.auth-hint { margin: 14px 0 0; text-align: center; color: var(--muted); font-size: 12.5px; }

/* ---------------------------------------------------------------- каркас */
.app { min-height: 100dvh; padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-title { font-weight: 700; font-size: 17px; }
.topbar-right { position: relative; }

.dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 230px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 30;
}
.dropdown button {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
}
.dropdown button:hover { background: var(--card-2); }

.view { max-width: 720px; margin: 0 auto; padding: 14px 14px 24px; }

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  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(--card) 94%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
.tabbar button {
  border: 0;
  background: transparent;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11.5px;
  cursor: pointer;
}
.tabbar .ti { font-size: 19px; line-height: 1; }
.tabbar button.is-active { color: var(--accent); }

/* ---------------------------------------------------------------- карточки */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 14px;
  margin-bottom: 12px;
}
.card h3 { margin: 0 0 8px; font-size: 15.5px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.card-head h3 { margin: 0; }

.msg-card { border-color: var(--accent); background: linear-gradient(180deg, var(--accent-soft), var(--card) 70%); }
.msg-card .msg-text { white-space: pre-wrap; margin: 6px 0 10px; }

.daynav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.daynav .d { text-align: center; }
.daynav .d b { display: block; font-size: 17px; }
.daynav .d span { font-size: 12.5px; color: var(--muted); }

.progress-line { height: 8px; background: var(--bg-soft); border-radius: 99px; overflow: hidden; margin: 6px 0 2px; }
.progress-line > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }

.focus-box { font-size: 13.5px; color: var(--muted); margin-top: 6px; white-space: pre-wrap; }

/* ---------------------------------------------------------------- задачи */
.tasks { list-style: none; margin: 0; padding: 0; }
.task {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--line);
}
.task:last-child { border-bottom: 0; }
.task-check {
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: transparent;
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 15px;
  color: transparent;
  margin-top: 1px;
}
.task.is-done .task-check { background: var(--accent); border-color: var(--accent); color: #fff; }
.task.is-skipped .task-check { border-style: dashed; color: var(--muted); }
.task-body { flex: 1; min-width: 0; cursor: pointer; }
.task-title { font-weight: 550; }
.task.is-done .task-title { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--line); }
.task-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.task-res { font-size: 13px; color: var(--accent); margin-top: 3px; }
.task-more { flex: none; color: var(--muted); }
.rule-btns { display: flex; gap: 6px; margin-top: 8px; }
.rule-btns .btn { padding: 6px 10px; font-size: 13px; }
.rule-btns .is-yes { background: var(--accent-soft); border-color: var(--accent); }
.rule-btns .is-no { background: color-mix(in srgb, var(--bad) 14%, transparent); border-color: var(--bad); }

.kind-badge {
  display: inline-block;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 99px;
  background: var(--bg-soft);
  color: var(--muted);
  margin-left: 6px;
  vertical-align: 1px;
}

.empty { text-align: center; padding: 22px 10px; color: var(--muted); }
.empty b { display: block; color: var(--text); margin-bottom: 4px; }

.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.quick .btn { padding: 12px 8px; }

/* ---------------------------------------------------------------- неделя */
.week-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.wday {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 3px;
  text-align: center;
  cursor: pointer;
  font-size: 12px;
}
.wday b { display: block; font-size: 15px; margin: 1px 0 3px; }
.wday.is-today { border-color: var(--accent); }
.wday .pct { font-size: 11.5px; color: var(--muted); }
.wday.full { background: var(--accent-soft); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
.stat { background: var(--bg-soft); border-radius: 10px; padding: 10px 12px; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 19px; font-weight: 700; margin-top: 2px; }
.stat .v small { font-size: 12px; font-weight: 400; color: var(--muted); }

.flag-warn { color: var(--warn); }
.flag-bad { color: var(--bad); }
.flag-ok { color: var(--ok); }

.alert {
  border-radius: var(--r-sm);
  padding: 10px 12px;
  font-size: 13.5px;
  margin: 10px 0;
}
.alert-warn { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--text); border: 1px solid var(--warn); }
.alert-bad { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--text); border: 1px solid var(--bad); }
.alert-info { background: var(--bg-soft); color: var(--muted); border: 1px solid var(--line); }

/* ---------------------------------------------------------------- таблицы и графики */
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th, .tbl td { text-align: left; padding: 7px 6px; border-bottom: 1px solid var(--line); }
.tbl th { color: var(--muted); font-weight: 500; font-size: 12.5px; }
.tbl td.r, .tbl th.r { text-align: right; }

.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .lbl { fill: var(--muted); font-size: 9px; }
.chart .ln { fill: none; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { stroke: var(--card); stroke-width: 1.5; }
.chart .lim { stroke: var(--warn); stroke-dasharray: 4 4; stroke-width: 1; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* ---------------------------------------------------------------- программа и тренировка */
.ex { padding: 10px 0; border-bottom: 1px solid var(--line); }
.ex:last-child { border-bottom: 0; }
.ex-head { display: flex; justify-content: space-between; gap: 8px; }
.ex-name { font-weight: 600; }
.ex-plan { color: var(--muted); font-size: 13px; white-space: nowrap; }
.ex-howto { font-size: 13px; color: var(--muted); margin-top: 4px; }
.ex-last { font-size: 12.5px; color: var(--blue); margin-top: 4px; }
.ex-hint { font-size: 12.5px; color: var(--accent); margin-top: 2px; }

.sets { margin-top: 8px; display: grid; gap: 6px; }
.set {
  display: grid;
  grid-template-columns: 22px 1fr 1fr 40px;
  gap: 6px;
  align-items: center;
}
.set .n { color: var(--muted); font-size: 12.5px; text-align: center; }
.set input { padding: 8px 8px; text-align: center; }
.set-ok {
  height: 38px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--bg-soft);
  cursor: pointer;
  color: var(--muted);
}
.set.is-done .set-ok { background: var(--accent); border-color: var(--accent); color: #fff; }
.set-head { display: grid; grid-template-columns: 22px 1fr 1fr 40px; gap: 6px; font-size: 11.5px; color: var(--muted); text-align: center; }

.checklist label { display: flex; gap: 10px; align-items: center; padding: 6px 0; font-size: 14px; }
.checklist input { width: 18px; height: 18px; accent-color: var(--accent); }

details.sect { margin-bottom: 10px; }
details.sect > summary { cursor: pointer; color: var(--muted); font-size: 13.5px; padding: 6px 0; }

.rest-timer {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + 14px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 8px 16px;
  background: var(--card);
  border: 1px solid var(--accent);
  border-radius: 999px;
  box-shadow: var(--shadow);
}
.rest-timer b { font-size: 20px; min-width: 2.2em; text-align: center; font-variant-numeric: tabular-nums; }
.rest-timer.is-over { border-color: var(--warn); }

.range-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; }
.range-row input[type=range] { width: 100%; accent-color: var(--accent); }
.range-row output { min-width: 2ch; font-weight: 700; text-align: right; }

/* ---------------------------------------------------------------- модалка */
.modal-root { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .55); }
.modal {
  position: relative;
  width: 100%;
  max-width: 560px;
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  box-shadow: var(--shadow);
}
.modal.is-full { max-width: 720px; height: 100dvh; max-height: 100dvh; border-radius: 0; }
@media (min-width: 640px) {
  .modal-root { align-items: center; }
  .modal { border-radius: 18px; }
  .modal.is-full { height: 94dvh; border-radius: 18px; }
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 10px 8px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-body { padding: 16px 18px; overflow: auto; flex: 1; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 10px 18px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); flex-wrap: wrap; }
.modal-foot:empty { display: none; }

.keybox {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 13px;
  word-break: break-all;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  padding: 10px;
  border-radius: var(--r-sm);
  user-select: all;
}

/* ---------------------------------------------------------------- тосты */
.toast-wrap {
  position: fixed;
  left: 0;
  right: 0;
  top: calc(10px + env(safe-area-inset-top));
  z-index: 80;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}
.toast {
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  padding: 9px 14px;
  box-shadow: var(--shadow);
  font-size: 14px;
  max-width: 92vw;
}
.toast.is-error { border-left-color: var(--bad); }

/* ---------------------------------------------------------------- схемы упражнений */
.fx { display: block; width: 100%; max-width: 250px; max-height: 28vh; height: auto; margin: 4px auto 8px; color: var(--text); }
.fx-floor { stroke: var(--line); stroke-width: 2; }
.fx-limb { stroke: currentColor; stroke-width: 6; stroke-linecap: round; }
.fx-limb.is-far { opacity: .38; }
.fx-head { fill: currentColor; }
.fx-db { fill: var(--blue); }
.fx-band { fill: none; stroke: #2bb5a0; stroke-width: 3; stroke-linecap: round; }
.fx-prop { fill: var(--card-2); stroke: var(--line); stroke-width: 1.5; }
.fx-prop-l { stroke: var(--muted); stroke-width: 3; stroke-linecap: round; opacity: .6; }

/* ---------------------------------------------------------------- пошаговая тренировка */
body.no-scroll { overflow: hidden; }
.player {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.pl-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(6px + env(safe-area-inset-top)) 8px 4px;
}
.pl-stepinfo { font-size: 13px; color: var(--muted); text-align: center; flex: 1; }
.pl-bar { margin: 0 14px; }
.pl-body { flex: 1; overflow: auto; padding: 14px 18px 18px; max-width: 620px; width: 100%; margin: 0 auto; }
.pl-foot {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  max-width: 620px;
  width: 100%;
  margin: 0 auto;
}
.pl-actions { flex: 1; display: flex; gap: 8px; }
.pl-actions .btn { padding: 14px 12px; white-space: normal; line-height: 1.2; }
.pl-actions .pl-main { flex: 1; font-size: 16px; }
.pl-group { font-size: 12.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--accent); text-align: center; }
.pl-title { text-align: center; margin: 4px 0 8px; font-size: 22px; }
.pl-target { text-align: center; font-size: 20px; font-weight: 700; margin: 4px 0; }
.pl-clock {
  font-size: 84px;
  font-weight: 800;
  text-align: center;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  margin: 14px 0 6px;
  color: var(--accent);
}
.pl-clock-rest { color: var(--blue); }
.pl-stepper {
  display: grid;
  grid-template-columns: 1fr 52px 64px 52px;
  align-items: center;
  gap: 8px;
  margin: 10px 0 4px;
}
.pl-stepper span { color: var(--muted); font-size: 14px; }
.pl-stepper b { text-align: center; font-size: 26px; font-variant-numeric: tabular-nums; }
.pl-stepper .btn { font-size: 22px; padding: 8px 0; }
.pl-setup { font-size: 13.5px; color: var(--text); background: var(--bg-soft); border-radius: var(--r-sm); padding: 8px 10px; margin: 6px 0; }
.pl-setup:empty { display: none; }
.pl-box { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 14px; margin: 10px 0; }
.pl-box ul, .pl-box ol { margin: 6px 0 0; padding-left: 20px; }
.pl-how { padding-left: 20px; margin: 8px 0; }
.pl-how li { margin-bottom: 4px; }
.pl-cue { font-size: 13.5px; margin: 6px 0; }

/* ---------------------------------------------------------------- фото еды */
.meals { display: grid; gap: 10px; }
.meal { display: grid; grid-template-columns: 88px 1fr; gap: 10px; align-items: start; cursor: pointer; }
.meal img { width: 88px; height: 88px; object-fit: cover; border-radius: 10px; background: var(--bg-soft); }
.meal-an { font-size: 13px; color: var(--accent); margin-top: 3px; }
.meal-an div { color: var(--text); }
.meal-preview { display: block; width: 100%; max-height: 42vh; object-fit: contain; border-radius: 12px; background: var(--bg-soft); margin-bottom: 12px; }
