:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f1f3f5);
  --text: var(--tg-theme-text-color, #15191c);
  --hint: var(--tg-theme-hint-color, #7b858c);
  --link: var(--tg-theme-link-color, #2a7fc9);
  --btn: var(--tg-theme-button-color, #2a7fc9);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --accent: #2f9e8f;
  --accent-soft: rgba(47, 158, 143, .14);
  --warn: #d9822b;
  --line: rgba(127, 140, 150, .22);
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: var(--tg-theme-bg-color, #17212b);
    --bg2: var(--tg-theme-secondary-bg-color, #232e3c);
    --text: var(--tg-theme-text-color, #f2f4f5);
    --hint: var(--tg-theme-hint-color, #8d9aa6);
    --btn: var(--tg-theme-button-color, #3e95db);
    --accent: #4cc3b2;
    --accent-soft: rgba(76, 195, 178, .16);
  }
}
:root[data-theme="dark"] {
  --bg: var(--tg-theme-bg-color, #17212b);
  --bg2: var(--tg-theme-secondary-bg-color, #232e3c);
  --text: var(--tg-theme-text-color, #f2f4f5);
  --hint: var(--tg-theme-hint-color, #8d9aa6);
  --btn: var(--tg-theme-button-color, #3e95db);
  --accent: #4cc3b2;
  --accent-soft: rgba(76, 195, 178, .16);
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg2); color: var(--text); }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", Roboto, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
  overflow-x: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }

main { max-width: 480px; margin: 0 auto; padding: 12px 16px 0; }
h1 { font-size: 26px; line-height: 1.15; margin: 8px 0 4px; letter-spacing: -.01em; }
h2 { font-size: 17px; margin: 24px 4px 8px; }
.sub { color: var(--hint); margin: 0 0 12px; font-size: 15px; }

.block { background: var(--bg); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.list { background: var(--bg); border-radius: var(--radius); overflow: hidden; margin-bottom: 12px; }
.row { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 10px 16px; width: 100%;
  background: none; border: 0; text-align: left; }
.row + .row { border-top: 1px solid var(--line); }
.row .grow { flex: 1; min-width: 0; }
.row .meta { color: var(--hint); font-size: 14px; }
.row .time { color: var(--hint); font-size: 14px; }
.check { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line); flex: none;
  display: grid; place-items: center; }
.check.on { background: var(--accent); border-color: var(--accent); }
.check.on::after { content: ""; width: 6px; height: 11px; border: solid #fff; border-width: 0 2.5px 2.5px 0;
  transform: translateY(-1px) rotate(45deg); }

.btn { display: block; width: 100%; min-height: 50px; border: 0; border-radius: 12px; padding: 12px 16px;
  background: var(--btn); color: var(--btn-text); font-weight: 600; font-size: 17px; }
.btn.soft { background: var(--accent-soft); color: var(--text); font-weight: 500; }
.btn.ghost { background: transparent; color: var(--link); font-weight: 500; }
.btn + .btn { margin-top: 8px; }

/* Сейчас */
.now { display: grid; grid-template-columns: 112px 1fr; gap: 16px; align-items: center; }
.ring { position: relative; width: 112px; height: 112px; }
.ring svg { width: 112px; height: 112px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 9; }
.ring .track { stroke: var(--accent-soft); }
.ring .bar { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .6s ease; }
.ring .label { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring .big { font-size: 24px; font-weight: 700; line-height: 1; }
.ring .small { font-size: 11px; color: var(--hint); margin: 4px auto 0; max-width: 64px; line-height: 1.15; }
.now .state { font-size: 20px; font-weight: 650; line-height: 1.2; }
.now .state-sub { color: var(--hint); font-size: 14px; margin-top: 4px; }
.idle-fig { width: 112px; height: 112px; }

.switches { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 14px; }
.switches button { min-height: 44px; border: 0; border-radius: 10px; background: var(--bg2); font-size: 14px; padding: 6px 2px; }
.switches button[aria-pressed="true"] { background: var(--accent); color: #fff; font-weight: 600; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button { min-height: 44px; min-width: 52px; padding: 0 14px; border: 0; border-radius: 22px; background: var(--bg2); }
.chips button.on { background: var(--accent); color: #fff; }

/* Неделя */
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; }
.week .d { font-size: 12px; color: var(--hint); }
.week .today .d { color: var(--accent); font-weight: 700; }
.dots { display: grid; gap: 4px; justify-items: center; margin-top: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.dot.on { background: var(--accent); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--hint); font-size: 13px; margin-top: 12px; }
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-right: 5px; vertical-align: 1px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--bg); border-radius: var(--radius); padding: 12px; }
.stat b { display: block; font-size: 22px; }
.stat span { color: var(--hint); font-size: 13px; }
.pain { width: 100%; height: 90px; display: block; }
.pain rect { fill: var(--accent); }
.pain rect.high { fill: var(--warn); }
.pain text { fill: var(--hint); font-size: 9px; }

/* Нижние вкладки */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--bg); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); z-index: 5; }
.tabs button { background: none; border: 0; display: grid; justify-items: center; gap: 2px; color: var(--hint);
  font-size: 11px; min-height: 48px; padding: 4px 0; }
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs button[aria-current="page"] { color: var(--accent); }
.gear { position: absolute; right: 12px; top: 12px; width: 44px; height: 44px; border: 0; background: none; color: var(--hint); }
.gear svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.head { position: relative; padding-right: 48px; }

/* Плеер */
.player { position: fixed; inset: 0; background: var(--bg); z-index: 20; display: flex; flex-direction: column;
  padding: 12px 16px calc(16px + env(safe-area-inset-bottom)); }
.player .top { display: flex; align-items: center; gap: 12px; }
.player .progress { flex: 1; height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.player .progress i { display: block; height: 100%; background: var(--accent); transition: width .3s; }
.player .close { width: 44px; height: 44px; border: 0; background: none; font-size: 26px; color: var(--hint); }
.player .stage { flex: 1; display: flex; flex-direction: column; justify-content: center; max-width: 440px; width: 100%; margin: 0 auto; }
.player .fig { width: min(72vw, 300px); height: min(72vw, 300px); margin: 0 auto; display: block; }
.player .ex-name { font-size: 24px; font-weight: 700; text-align: center; margin: 8px 0 2px; }
.player .side { text-align: center; color: var(--accent); font-weight: 600; min-height: 22px; }
.player .how { text-align: center; margin: 8px 0 2px; }
.player .dont { text-align: center; color: var(--hint); font-size: 14px; }
.player .count { font-size: 56px; font-weight: 700; text-align: center; line-height: 1.1; margin: 10px 0; }
.player .count small { font-size: 18px; color: var(--hint); font-weight: 500; }
.player .rest { color: var(--hint); text-align: center; }
.player .controls { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; max-width: 440px; width: 100%; margin: 0 auto; }
.player .controls .btn { margin: 0; }
.player .controls .wide { grid-column: 1 / -1; }

/* Настройки */
.sheet { position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, .4); display: flex; align-items: flex-end; }
.sheet .panel { background: var(--bg2); width: 100%; max-height: 92vh; overflow: auto; border-radius: 16px 16px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
.mode { display: flex; gap: 12px; align-items: flex-start; }
.mode input { margin-top: 4px; width: 20px; height: 20px; accent-color: var(--accent); }
.field { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 52px; padding: 8px 16px; }
.field + .field { border-top: 1px solid var(--line); }
.field input, .field select { font: inherit; color: var(--text); background: var(--bg2); border: 0; border-radius: 8px; padding: 8px 10px; min-height: 40px; max-width: 55%; }

.toast { position: fixed; left: 16px; right: 16px; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 40;
  background: var(--text); color: var(--bg); border-radius: 12px; padding: 12px 16px; text-align: center; }
.empty { color: var(--hint); text-align: center; padding: 24px 8px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

[hidden] { display: none !important; }
