/* Оформление Mini App.

   Цвета берутся из темы Telegram — приложение должно выглядеть родным и в
   светлой, и в тёмной теме. Фолбэки нужны только для отладки в браузере,
   где переменных Telegram нет. */

:root{
  --bg:        var(--tg-theme-bg-color, #15171c);
  --fg:        var(--tg-theme-text-color, #f2f4f7);
  --muted:     var(--tg-theme-hint-color, #8b95a5);
  --card:      var(--tg-theme-secondary-bg-color, #1e222a);
  --accent:    var(--tg-theme-button-color, #2f9df4);
  --accent-fg: var(--tg-theme-button-text-color, #ffffff);

  --water:     #35a7f0;
  --water-dim: #35a7f033;
  --ok:        #35c47a;
  /* Задано обычной rgba, а не через color-mix: последний понимают только
     Safari 16.2 и новее, а на iPhone постарше свойство становится
     невалидным — и вместе с ним пропадают все рамки и разделители. */
  --line:      rgba(139, 149, 165, .28);
  --radius:    14px;
}

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

/* Экраны, вкладки и шаги переключаются атрибутом `hidden`, а браузерное
   правило [hidden]{display:none} лежит в пользовательской таблице стилей и
   проигрывает любому нашему классу с display при равной специфичности.
   Из-за этого `.boot{display:flex}` не давал спрятать заставку: кружок
   оставался на весь экран, а готовый онбординг уезжал ровно на экран вниз.
   Правило закрывает этот класс ошибок для всей разметки разом.            */
[hidden]{ display:none !important; }

body{
  margin:0;
  padding:0 16px calc(78px + env(safe-area-inset-bottom));
  background:var(--bg);
  color:var(--fg);
  font:16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust:100%;
}

h1{ font-size:23px; margin:20px 0 6px; }
h2{ font-size:19px; margin:20px 0 12px; }
.hint{ color:var(--muted); font-size:14px; margin:0 0 20px; }

/* ── Загрузка ─────────────────────────────────────────────── */

.boot{ display:flex; align-items:center; justify-content:center; height:100vh; }
.fail{ text-align:center; padding:0 24px; max-width:420px; }
.fail-emoji{ font-size:40px; margin-bottom:10px; }
.fail h2{ font-size:18px; margin:0 0 8px; }
.fail .hint{ margin:0; }
.spinner{
  width:26px; height:26px; border-radius:50%;
  border:2.5px solid var(--line); border-top-color:var(--accent);
  animation:spin .8s linear infinite;
}
@keyframes spin{ to{ transform:rotate(360deg); } }

/* ── Онбординг ────────────────────────────────────────────── */

.steps{ display:flex; gap:6px; padding-top:18px; }
.steps span{ flex:1; height:3px; border-radius:2px; background:var(--line); transition:background .2s; }
.steps span.on{ background:var(--accent); }

.field{ display:block; margin-bottom:16px; }
.field > span{ display:block; font-size:13px; color:var(--muted); margin-bottom:6px; }

input[type=number], input[type=time], select, .preset-input{
  width:100%; padding:13px 14px; font-size:17px; color:var(--fg);
  background:var(--card); border:1px solid var(--line); border-radius:var(--radius);
  appearance:none;
}
input:focus, select:focus{ outline:none; border-color:var(--accent); }

.row{ display:flex; gap:10px; }
.row > *{ flex:1; min-width:0; }

.segmented{ display:flex; gap:8px; }
.segmented button{
  flex:1; padding:13px; font-size:15px; border-radius:var(--radius);
  background:var(--card); color:var(--fg); border:1px solid var(--line);
}
.segmented button.on{ background:var(--accent); color:var(--accent-fg); border-color:var(--accent); }

.tz-card{
  background:var(--card); border-radius:var(--radius); padding:16px;
  margin-bottom:18px; border:1px solid var(--line);
}
.tz-name{ font-size:17px; font-weight:600; }
.tz-time{ color:var(--muted); font-size:14px; margin-top:2px; }
.tz-foot{ color:var(--muted); font-size:13px; text-align:center; margin-top:18px; }

.toggle{
  display:flex; align-items:center; gap:12px; padding:13px 14px; margin-bottom:10px;
  background:var(--card); border:1px solid var(--line); border-radius:var(--radius);
}
.toggle input{ width:20px; height:20px; accent-color:var(--accent); flex:none; }
.toggle span{ display:flex; flex-direction:column; }
.toggle small{ color:var(--muted); font-size:13px; }

.onb-nav{ display:flex; gap:10px; margin-top:26px; }
.onb-nav .btn{ flex:1; }

/* ── Кнопки ───────────────────────────────────────────────── */

.btn{
  display:block; width:100%; padding:15px; border:0; border-radius:var(--radius);
  font-size:16px; font-weight:600; background:var(--accent); color:var(--accent-fg);
}
.btn:active{ opacity:.75; }
.btn.ghost{ background:var(--card); color:var(--fg); border:1px solid var(--line); font-weight:500; }

/* ── Кольцо воды ──────────────────────────────────────────── */

.ring-wrap{ position:relative; width:230px; margin:26px auto 8px; }
.ring{ width:100%; transform:rotate(-90deg); }
.ring circle{ fill:none; stroke-width:14; stroke-linecap:round; }
.ring-bg{ stroke:var(--line); }
.ring-pace{ stroke:var(--water-dim); stroke-width:14; }
.ring-fill{
  stroke:var(--water); stroke-dasharray:502.65;
  transition:stroke-dashoffset .45s cubic-bezier(.4,0,.2,1), stroke .3s;
}
.ring-fill.done{ stroke:var(--ok); }

.ring-text{
  position:absolute; inset:0; display:flex; flex-direction:column;
  align-items:center; justify-content:center; pointer-events:none;
}
.ring-value{ font-size:34px; font-weight:700; letter-spacing:-.5px; }
.ring-goal{ color:var(--muted); font-size:14px; margin-top:2px; }

.pace{ text-align:center; color:var(--muted); font-size:14px; min-height:20px; margin:0 0 18px; }
.pace.behind{ color:var(--water); }
.pace.done{ color:var(--ok); }

.presets{ display:flex; gap:10px; margin-bottom:10px; }
.presets button{
  flex:1; padding:17px 4px; border:0; border-radius:var(--radius);
  background:var(--accent); color:var(--accent-fg); font-size:16px; font-weight:600;
}
.presets button:active{ transform:scale(.97); }

.row-actions{ display:flex; gap:10px; }

/* ── История ──────────────────────────────────────────────── */

.history{ display:flex; align-items:flex-end; gap:5px; height:70px; margin-top:26px; }
.history div{ flex:1; background:var(--water-dim); border-radius:3px 3px 0 0; min-height:3px; }
.history div.full{ background:var(--water); }

/* ── Заглушки будущих модулей ─────────────────────────────── */

.soon{ text-align:center; padding:70px 20px; }
.soon-emoji{ font-size:46px; margin-bottom:10px; }

/* ── Нижняя навигация ─────────────────────────────────────── */

.nav{
  position:fixed; left:0; right:0; bottom:0; display:flex;
  padding:6px 4px calc(6px + env(safe-area-inset-bottom));
  background:var(--bg); border-top:1px solid var(--line);
}
.nav button{
  flex:1; display:flex; flex-direction:column; align-items:center; gap:2px;
  padding:6px 0; border:0; background:none; color:var(--muted); font-size:19px;
}
.nav button span{ font-size:11px; }
.nav button.active{ color:var(--accent); }

/* ── Тост ─────────────────────────────────────────────────── */

.toast{
  position:fixed; left:50%; bottom:96px; transform:translateX(-50%);
  max-width:88%; padding:11px 18px; border-radius:22px;
  background:var(--card); border:1px solid var(--line);
  font-size:14px; text-align:center; z-index:20;
  animation:rise .2s ease-out;
}
@keyframes rise{ from{ opacity:0; transform:translate(-50%, 8px); } }
