/* Опора — спокойная, тихая визуальная система.
   Никаких «казинных» цветов (красный/золото/зелёное сукно), никаких мигающих анимаций. */

:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-2: #eceeea;
  --surface-3: #e2e5e0;
  --text: #17212b;
  --text-2: #3d4a56;
  --muted: #66737f;
  --line: #d9ddd7;
  --accent: #1d7f74;
  --accent-ink: #ffffff;
  --accent-soft: #d5ebe7;
  --calm: #4b6fa8;
  --calm-soft: #dfe7f4;
  --dusk: #6b5fb5;
  --dusk-soft: #e6e2f6;
  --warn: #b5583f;
  --warn-soft: #f6e3dc;
  --ok: #2f7d4f;
  --ok-soft: #dcefe3;
  --shadow: 0 1px 2px rgba(20, 30, 40, .06), 0 4px 16px rgba(20, 30, 40, .06);
  --radius: 16px;
  --radius-sm: 10px;
  --tap: 52px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --nav-h: 68px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1318;
    --surface: #161d24;
    --surface-2: #1d262f;
    --surface-3: #26313b;
    --text: #e7edf2;
    --text-2: #c3ccd4;
    --muted: #8f9ca8;
    --line: #2a3540;
    --accent: #5cc4b5;
    --accent-ink: #0b1a18;
    --accent-soft: #173733;
    --calm: #8fb0e8;
    --calm-soft: #1b2a40;
    --dusk: #b2a8f2;
    --dusk-soft: #262245;
    --warn: #ec9a83;
    --warn-soft: #3a221c;
    --ok: #7fcf9c;
    --ok-soft: #173225;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0e1318;
  --surface: #161d24;
  --surface-2: #1d262f;
  --surface-3: #26313b;
  --text: #e7edf2;
  --text-2: #c3ccd4;
  --muted: #8f9ca8;
  --line: #2a3540;
  --accent: #5cc4b5;
  --accent-ink: #0b1a18;
  --accent-soft: #173733;
  --calm: #8fb0e8;
  --calm-soft: #1b2a40;
  --dusk: #b2a8f2;
  --dusk-soft: #262245;
  --warn: #ec9a83;
  --warn-soft: #3a221c;
  --ok: #7fcf9c;
  --ok-soft: #173225;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
  min-height: 100dvh;
}

button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .8em; }
.icon { flex: none; display: block; }

/* ---- Каркас ---- */
#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
}
#app.no-nav { padding-bottom: calc(env(safe-area-inset-bottom) + 24px); }

.screen { padding: 0 16px; animation: fadein .18s ease-out; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .screen { animation: none; } * { transition: none !important; animation: none !important; } }

.screen-head {
  position: sticky; top: 0; z-index: 5;
  display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) 0 8px;
  background: var(--bg);
}
.screen-title { font-size: 1.1rem; text-align: center; margin: 0; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.screen-body { padding-top: 8px; }
.icon-btn, .icon-btn-spacer { width: 44px; height: 44px; }
.icon-btn {
  display: grid; place-items: center; border: 0; border-radius: 12px;
  background: transparent; color: var(--text-2); cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }

/* ---- Нижняя навигация ---- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-inner { max-width: 560px; margin: 0 auto; display: grid; grid-template-columns: repeat(5, 1fr); height: var(--nav-h); align-items: center; }
.nav a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 550; padding: 6px 0;
}
.nav a.active { color: var(--accent); }
.nav a.nav-sos {
  margin: -18px auto 0; width: 64px; height: 64px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); justify-content: center;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 45%, transparent);
  font-size: 11px; font-weight: 700;
}

/* ---- Кнопки ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: var(--tap); padding: 12px 20px; border-radius: 14px; border: 0;
  font-weight: 620; font-size: 1rem; cursor: pointer; text-decoration: none; text-align: center;
  transition: transform .08s ease, background .15s ease;
  user-select: none; -webkit-user-select: none;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn-full { width: 100%; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-secondary { background: var(--surface-2); color: var(--text); }
.btn-ghost { background: transparent; color: var(--text-2); border: 1px solid var(--line); }
.btn-calm { background: var(--calm-soft); color: var(--calm); }
.btn-dusk { background: var(--dusk-soft); color: var(--dusk); }
.btn-warn { background: var(--warn-soft); color: var(--warn); }
.btn-lg { min-height: 64px; font-size: 1.1rem; border-radius: 18px; }
.btn-xl { min-height: 84px; font-size: 1.2rem; border-radius: 22px; }
.btn-sm { min-height: 40px; padding: 8px 14px; font-size: .92rem; border-radius: 12px; }

/* ---- Карточки и текст ---- */
.card {
  background: var(--surface); border-radius: var(--radius); padding: 18px;
  box-shadow: var(--shadow); margin-bottom: 14px;
}
.card.flat { box-shadow: none; border: 1px solid var(--line); }
.card.soft { background: var(--surface-2); box-shadow: none; }
.card.accent { background: var(--accent-soft); box-shadow: none; }
.card.calm { background: var(--calm-soft); box-shadow: none; }
.card.dusk { background: var(--dusk-soft); box-shadow: none; }
.card.warn { background: var(--warn-soft); box-shadow: none; }
.card.ok { background: var(--ok-soft); box-shadow: none; }
.card h2, .card h3 { margin-top: 0; }
.card > :last-child { margin-bottom: 0; }

.muted { color: var(--muted); }
.small { font-size: .88rem; }
.tiny { font-size: .78rem; }
.big { font-size: 1.25rem; line-height: 1.4; }
.huge { font-size: 2.4rem; font-weight: 750; letter-spacing: -0.02em; line-height: 1.1; }
.center { text-align: center; }
.strong { font-weight: 650; }
.lead { font-size: 1.15rem; line-height: 1.5; color: var(--text); }
.quote {
  border-left: 3px solid var(--accent); padding: 4px 0 4px 14px; margin: 0 0 12px;
  font-size: 1.1rem; line-height: 1.55; white-space: pre-wrap;
}
.eyebrow { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 650; margin-bottom: 6px; }
.section-title { font-size: .85rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 650; margin: 22px 4px 10px; }

.row { display: flex; align-items: center; }
.row.gap { gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row > .btn { flex: 1; }
.stack > * + * { margin-top: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.spacer { height: 16px; }

/* Плитки-ссылки */
.tile {
  display: flex; align-items: center; gap: 14px; width: 100%;
  background: var(--surface); border: 0; border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow); text-align: left; cursor: pointer; text-decoration: none; color: var(--text);
  margin-bottom: 10px; min-height: 64px;
}
.tile:active { transform: scale(.99); }
.tile .tile-icon { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.tile .tile-icon.calm { background: var(--calm-soft); color: var(--calm); }
.tile .tile-icon.dusk { background: var(--dusk-soft); color: var(--dusk); }
.tile .tile-icon.warn { background: var(--warn-soft); color: var(--warn); }
.tile .tile-icon.ok { background: var(--ok-soft); color: var(--ok); }
.tile .tile-text { flex: 1; min-width: 0; }
.tile .tile-title { font-weight: 640; display: block; }
.tile .tile-sub { color: var(--muted); font-size: .88rem; display: block; margin-top: 2px; }

/* ---- Поля ввода ---- */
.field { display: block; margin-bottom: 14px; }
.field-label { display: block; font-weight: 600; font-size: .92rem; margin-bottom: 6px; color: var(--text-2); }
.field-hint { display: block; font-size: .8rem; color: var(--muted); margin-top: 6px; }
.input {
  width: 100%; min-height: 50px; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font-size: 1rem; outline: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.textarea { min-height: 110px; resize: vertical; line-height: 1.5; }

/* Шкала 0–10 */
.scale-wrap { margin: 8px 0 14px; }
.scale { display: grid; grid-template-columns: repeat(11, 1fr); gap: 4px; }
.scale-dot {
  aspect-ratio: 1; min-height: 30px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text-2); font-weight: 600; font-size: .9rem; cursor: pointer; padding: 0;
}
.scale-dot.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.scale-labels { display: flex; justify-content: space-between; font-size: .78rem; color: var(--muted); margin-top: 6px; }

/* Чипы */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 14px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--text-2);
  padding: 9px 14px; border-radius: 999px; font-size: .92rem; cursor: pointer; min-height: 40px;
}
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--text); font-weight: 600; }

/* ---- Таймер ---- */
.countdown {
  --progress: 0;
  width: 210px; height: 210px; margin: 10px auto 16px; border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background:
    radial-gradient(closest-side, var(--bg) 86%, transparent 87% 100%),
    conic-gradient(var(--accent) calc(var(--progress) * 360deg), var(--surface-3) 0);
}
.countdown-time { font-size: 3rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.countdown-label { color: var(--muted); font-size: .9rem; }

/* Дыхательный шар */
.breath {
  width: 200px; height: 200px; margin: 20px auto; border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--calm) 55%, transparent), color-mix(in srgb, var(--calm) 15%, transparent));
  transform: scale(.55); transition: transform 4s ease-in-out;
  display: grid; place-items: center;
}
.breath-label { font-size: 1.1rem; font-weight: 600; color: var(--text); transform: scale(1.6); }

/* ---- Прогресс-полоски ---- */
.bar { height: 10px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }

/* Шаги мастера */
.steps { display: flex; gap: 6px; justify-content: center; margin: 4px 0 18px; }
.steps span { width: 28px; height: 4px; border-radius: 4px; background: var(--surface-3); }
.steps span.done { background: var(--accent); }

/* Список */
.list { list-style: none; padding: 0; margin: 0; }
.list li { padding: 12px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
ul.bullets { padding-left: 20px; margin: 0 0 12px; }
ul.bullets li { margin-bottom: 6px; }

/* Чек-лист */
.check {
  display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer;
}
.check:last-child { border-bottom: 0; }
.check-box {
  width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--line); flex: none;
  display: grid; place-items: center; margin-top: 1px; color: var(--accent-ink);
}
.check.done .check-box { background: var(--accent); border-color: var(--accent); }
.check.done .check-title { color: var(--muted); text-decoration: line-through; }
.check-title { font-weight: 600; }
.check-sub { font-size: .88rem; color: var(--muted); margin-top: 2px; }

/* Статистика */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--surface); border-radius: 14px; padding: 12px; box-shadow: var(--shadow); }
.stat-value { font-size: 1.5rem; font-weight: 720; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.stat-label { font-size: .76rem; color: var(--muted); line-height: 1.3; }

/* Таблица */
.table { width: 100%; border-collapse: collapse; font-size: .92rem; font-variant-numeric: tabular-nums; }
.table th, .table td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: right; }
.table th:first-child, .table td:first-child { text-align: left; }
.table th { font-weight: 600; color: var(--muted); font-size: .8rem; }

/* Контакты */
.contact-card { display: flex; flex-direction: column; gap: 10px; }
.contact-name { font-weight: 680; font-size: 1.05rem; }
.contact-role { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.contact-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.fallback-line { text-align: center; font-size: .8rem; color: var(--muted); margin: 18px 0 4px; }
.fallback-line a { color: var(--muted); }

/* ---- Тосты и модалки ---- */
#toast-host { position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 14px); display: grid; justify-items: center; gap: 8px; z-index: 50; pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: .92rem; box-shadow: var(--shadow); transition: opacity .3s, transform .3s; max-width: 90vw; }
.toast.out { opacity: 0; transform: translateY(8px); }
.modal-overlay { position: fixed; inset: 0; background: rgba(5, 10, 15, .55); z-index: 60; display: flex; align-items: flex-end; justify-content: center; padding: 16px; }
.modal { background: var(--surface); border-radius: 20px; padding: 20px; width: 100%; max-width: 520px; max-height: 85dvh; overflow: auto; margin-bottom: env(safe-area-inset-bottom); }
.modal-text { font-size: 1.05rem; margin-bottom: 18px; }
@media (min-width: 600px) { .modal-overlay { align-items: center; } }

/* PIN-экран */
.pin { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100dvh; padding: 24px; }
.pin-dots { display: flex; gap: 14px; margin: 22px 0; }
.pin-dots span { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--muted); }
.pin-dots span.on { background: var(--text); border-color: var(--text); }
.pin-pad { display: grid; grid-template-columns: repeat(3, 72px); gap: 14px; }
.pin-pad button { width: 72px; height: 72px; border-radius: 50%; border: 0; background: var(--surface-2); font-size: 1.5rem; font-weight: 600; cursor: pointer; }
.pin-pad button:active { background: var(--surface-3); }

/* Главная */
.hero { padding: calc(env(safe-area-inset-top) + 18px) 0 6px; }
.hero-greet { color: var(--muted); font-size: .95rem; margin-bottom: 4px; }
.hero-title { font-size: 1.6rem; font-weight: 720; margin: 0 0 4px; }
.sos-big {
  width: 100%; min-height: 108px; border: 0; border-radius: 24px; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); text-align: left; padding: 18px 20px;
  display: flex; align-items: center; gap: 16px; box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 35%, transparent);
  margin: 14px 0 12px;
}
.sos-big .t1 { font-size: 1.35rem; font-weight: 740; display: block; }
.sos-big .t2 { font-size: .92rem; opacity: .85; display: block; margin-top: 2px; }
.quick-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.quick-row .btn { min-height: 60px; }

/* Утилиты */
.hidden { display: none !important; }
.mt0 { margin-top: 0 !important; } .mt8 { margin-top: 8px; } .mt16 { margin-top: 16px; } .mt24 { margin-top: 24px; }
.mb0 { margin-bottom: 0 !important; } .mb8 { margin-bottom: 8px; } .mb16 { margin-bottom: 16px; }
.pre { white-space: pre-wrap; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
canvas.chart { width: 100%; height: 220px; display: block; }
details.more { margin: 8px 0 14px; }
details.more summary { cursor: pointer; color: var(--accent); font-weight: 600; padding: 8px 0; list-style: none; }
details.more summary::-webkit-details-marker { display: none; }
details.more summary::before { content: '＋ '; }
details.more[open] summary::before { content: '－ '; }
