/* Цвета берутся из темы Telegram; запасные значения — для открытия в обычном браузере. */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #0e1014);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #191c22));
  --text: var(--tg-theme-text-color, #f1f3f5);
  --muted: var(--tg-theme-hint-color, #8a93a2);
  --accent: var(--tg-theme-button-color, #4c8dff);
  --on-accent: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #ff6b6b);
  --line: color-mix(in srgb, var(--text) 10%, transparent);
  --soft: color-mix(in srgb, var(--text) 7%, transparent);
  --accent-soft: color-mix(in srgb, var(--accent) 18%, transparent);
  --radius: 18px;
}

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

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }

#view {
  max-width: 520px;
  margin: 0 auto;
  padding: 16px 16px calc(92px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

h1 { font-size: 26px; line-height: 1.15; margin: 0; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 22px; line-height: 1.2; margin: 0; font-weight: 700; letter-spacing: -0.01em; }
h3 { font-size: 15px; margin: 0; font-weight: 600; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.eyebrow { color: var(--muted); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }

.card { background: var(--card); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.section-title { margin: 8px 4px 0; }

/* --- кнопки */
.btn {
  display: flex; align-items: center; justify-content: center;
  min-height: 48px; padding: 0 18px; border-radius: 14px;
  font-weight: 600; background: var(--soft); flex: 1;
  transition: transform .08s ease, opacity .15s ease;
}
.btn:active, .rep:active, .step:active, .day-row:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.big { min-height: 56px; font-size: 18px; margin-top: 6px; }
.btn.danger { color: var(--danger); }
.btn.slim { min-height: 40px; font-size: 14px; }
.row { display: flex; gap: 10px; }

/* --- плитки с цифрами */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.tiles.three { grid-template-columns: repeat(3, 1fr); }
.tile { background: var(--card); border-radius: var(--radius); padding: 14px 16px; }
.tile b { display: block; font-size: 24px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.tile span { color: var(--muted); font-size: 13px; }
.card .tiles .tile { background: var(--soft); border-radius: 14px; padding: 12px; }
.card .tiles .tile b { font-size: 20px; }

/* --- список дней */
.day-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%;
  text-align: left; padding: 14px 0; border-top: 1px solid var(--line);
  transition: transform .08s ease;
}
.day-row:first-of-type { border-top: 0; padding-top: 2px; }
.day-row:last-of-type { padding-bottom: 2px; }
.day-row b { display: block; font-weight: 600; }
.badge { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 99px; background: var(--accent-soft); white-space: nowrap; }
.chev { color: var(--muted); font-size: 20px; }

/* --- тренировка */
.wk-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; padding: 0 4px; }
.wk-title { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.elapsed { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--muted); }

.strip { display: flex; gap: 4px; padding: 0 4px; }
.strip i { height: 6px; border-radius: 3px; background: var(--soft); overflow: hidden; position: relative; }
.strip i b { position: absolute; inset: 0 auto 0 0; background: var(--accent); border-radius: 3px; }
.strip i.cur { outline: 2px solid var(--accent-soft); outline-offset: 1px; }

.rest { flex-direction: row; align-items: center; gap: 18px; }
.ring-wrap { position: relative; width: 104px; height: 104px; flex: none; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 8; }
.ring-bg { stroke: var(--soft); }
.ring-fg { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .25s linear; }
.rest-time {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em;
}
.rest-side { flex: 1; display: flex; flex-direction: column; gap: 10px; min-width: 0; }

.set-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-top: 4px; }
.set-no { font-size: 18px; font-weight: 700; }
.note { font-size: 13px; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 13px; font-weight: 600; padding: 5px 10px; border-radius: 99px; background: var(--soft); font-variant-numeric: tabular-nums; }
.chip.fail { color: var(--muted); font-weight: 500; }

.weight { display: flex; align-items: stretch; gap: 10px; margin-top: 4px; }
.step { width: 60px; border-radius: 16px; background: var(--soft); font-size: 28px; font-weight: 500; transition: transform .08s ease; }
.w-val { flex: 1; border-radius: 16px; background: var(--soft); padding: 10px; display: flex; flex-direction: column; align-items: center; }
.w-cap { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.w-num { font-size: 38px; line-height: 1.1; font-weight: 700; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.w-num small { font-size: 16px; font-weight: 600; color: var(--muted); letter-spacing: 0; margin-left: 4px; }
.hint { font-size: 14px; background: var(--accent-soft); border-radius: 12px; padding: 10px 12px; }

.reps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.rep {
  height: 56px; border-radius: 14px; background: var(--soft);
  font-size: 21px; font-weight: 600; font-variant-numeric: tabular-nums; transition: transform .08s ease;
}
.rep.goal { background: var(--accent-soft); }
.rep.top { background: var(--accent); color: var(--on-accent); }
.reps.off .rep { opacity: .35; }

/* --- план, история, прогресс */
.item { display: flex; justify-content: space-between; gap: 12px; padding: 11px 0; border-top: 1px solid var(--line); }
.item:first-of-type { border-top: 0; }
.item > div:first-child { min-width: 0; }
.item b { font-weight: 600; display: block; }
.item .right { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.line { padding: 9px 0; border-top: 1px solid var(--line); font-size: 14px; }
.line b { display: block; font-weight: 600; }
.line span { color: var(--muted); font-variant-numeric: tabular-nums; }
.line em { display: block; font-style: normal; font-weight: 600; margin-top: 2px; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.setting { flex-direction: row; align-items: center; justify-content: space-between; gap: 14px; }
.setting select {
  font: inherit; font-weight: 600; color: var(--text); background: var(--soft);
  border: 0; border-radius: 12px; padding: 10px 12px; flex: none;
}
.setting select option { color: #000; }
.item .badge { display: inline-block; margin-top: 6px; }

.hist { text-align: left; width: 100%; }
.hist-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.hist-date { font-variant-numeric: tabular-nums; }

.chart { display: flex; align-items: flex-end; gap: 2px; height: 150px; border-bottom: 1px solid var(--line); padding-top: 22px; }
.col { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; position: relative; }
.col i { width: 100%; max-width: 28px; min-height: 3px; border-radius: 4px 4px 0 0; background: var(--accent); opacity: .4; transition: opacity .15s ease; }
.col.on i { opacity: 1; }
.col em { position: absolute; font-style: normal; font-size: 12px; font-weight: 600; white-space: nowrap; transform: translateY(-4px); font-variant-numeric: tabular-nums; }
.axis { display: flex; gap: 2px; }
.axis span { flex: 1; text-align: center; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.axis span.on { color: var(--text); font-weight: 600; }

.empty { text-align: center; padding: 36px 20px; color: var(--muted); }

/* --- нижняя навигация */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.tab { flex: 1; max-width: 130px; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 0; color: var(--muted); font-size: 11px; font-weight: 600; }
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab.on { color: var(--accent); }

/* --- всплывающие */
#toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(92px + env(safe-area-inset-bottom));
  margin: 0 auto; max-width: 420px; padding: 12px 16px; border-radius: 14px;
  background: var(--text); color: var(--bg); font-weight: 600; font-size: 14px; text-align: center;
  opacity: 0; transform: translateY(8px); pointer-events: none; transition: opacity .2s ease, transform .2s ease;
}
#toast.show { opacity: 1; transform: none; }

#modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); display: flex; align-items: flex-start; justify-content: center; padding: 18vh 16px 0; }
#modal[hidden] { display: none; }
.sheet { background: var(--card); border-radius: 22px; padding: 20px; width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; }
.sheet input {
  width: 100%; font: inherit; font-size: 34px; font-weight: 700; text-align: center; color: var(--text);
  background: var(--soft); border: 2px solid transparent; border-radius: 16px; padding: 12px; outline: none;
}
.sheet input:focus { border-color: var(--accent); }
.sheet input.bad { border-color: var(--danger); }
