/* =====================================================================
   Тёмная тёплая тема (из «Дневника»): ночью не слепит.
   Крупные кнопки и шрифт: экран читается на ходу, одной рукой.
   ===================================================================== */
:root {
  color-scheme: dark;
  --bg: #11131a;
  --bg-glow: #1a1d2b;
  --surface: #191c26;
  --surface-2: #222634;
  --surface-3: #2b3041;
  --border: #2d3244;
  --text: #ece7dc;
  --text-2: #bdb6a7;
  --muted: #8b8577;
  --accent: #e9a95b;
  --accent-ink: #1d1407;
  --accent-soft: rgb(233 169 91 / .14);
  --danger: #f28b82;
  --safety-bg: #3a1f22;
  --safety-border: #f28b82;
  --grid: #272b3a;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #9085e9;
  --radius: 20px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Noto Serif", serif;
  --shadow: 0 1px 0 rgb(255 255 255 / .03) inset, 0 10px 30px rgb(0 0 0 / .25);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  color: var(--text);
  background: radial-gradient(120% 60% at 50% 0%, var(--bg-glow), var(--bg) 70%) fixed, var(--bg);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}
button, input, textarea, select { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; font-family: var(--serif); font-weight: 600; }
h2 { font-size: 1.35rem; letter-spacing: .01em; }
h3 { font-size: 1.05rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--danger); }
[hidden] { display: none !important; }
::selection { background: var(--accent); color: var(--accent-ink); }

/* ---- верх: заголовок слева, «Совсем плохо» справа ---- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: rgb(17 19 26 / .82);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: 640px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.topbar-title { min-width: 0; }
#title { font-family: var(--serif); font-size: 1.3rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#status { font-size: .8rem; color: var(--muted); min-height: 1.1em; }
.sos-btn {
  flex: none; min-height: 40px; padding: 6px 14px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--safety-border); background: var(--safety-bg); color: #ffd2cd; font-weight: 600;
}

/* ---- нижнее меню: парящая капсула ---- */
.tabs {
  position: fixed; z-index: 10; left: 50%; transform: translateX(-50%);
  bottom: calc(12px + env(safe-area-inset-bottom));
  width: min(calc(100% - 24px), 480px);
  display: flex; padding: 6px;
  background: rgb(34 38 52 / .88);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border: 1px solid var(--border); border-radius: 22px;
  box-shadow: 0 12px 32px rgb(0 0 0 / .45);
}
.tabs button {
  flex: 1; padding: 7px 0 6px; border: 0; border-radius: 16px;
  background: none; color: var(--muted); font-size: .7rem; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
}
.tab-ico { font-size: 1.15rem; line-height: 1.2; }
.tabs button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

main { max-width: 640px; margin: 0 auto; padding: 8px 16px; }

.card {
  background: var(--surface); border-radius: var(--radius);
  padding: 18px 16px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.field { margin: 14px 0; }
.field:first-of-type { margin-top: 8px; }
.field.row { display: flex; align-items: center; justify-content: space-between; gap: 6px 12px; flex-wrap: wrap; }
.field.row .choices, .field.row .stepper { margin-top: 0; }
.field.row .safety { flex-basis: 100%; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 14px 0; }
.pair .field { margin: 0; min-width: 0; }
.pair input[type="time"] { width: 100%; min-width: 0; }
.field-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.field-label { color: var(--text-2); font-size: .95rem; }
.field.info { color: var(--accent); font-family: var(--serif); font-size: 1.05rem; }
.field-hint { color: var(--muted); font-size: .8rem; margin-top: 2px; }

/* ---- цифры 0–10: сплошная полоса, выбранная — янтарный круг ---- */
.num-row {
  display: grid; grid-template-columns: repeat(11, 1fr); gap: 0;
  margin-top: 6px; padding: 3px; border-radius: 14px; background: var(--surface-2);
}
.num-btn {
  min-width: 0; height: 34px; padding: 0; border: 0; border-radius: 10px;
  background: none; color: var(--text-2); cursor: pointer;
  font-variant-numeric: tabular-nums; font-size: .95rem;
  transition: background-color .15s, color .15s;
}
.num-btn.on { background: var(--accent); color: var(--accent-ink); font-weight: 700; box-shadow: 0 0 14px rgb(233 169 91 / .35); }
.scale-ends { display: flex; justify-content: space-between; color: var(--muted); font-size: .7rem; line-height: 1.1; margin-top: 4px; padding: 0 4px; }

/* ---- варианты ответа ---- */
.choices { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.choice {
  padding: 6px 14px; min-height: 36px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2); cursor: pointer;
}
.choice.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }

input[type="text"], input[type="time"], input[type="number"], input[type="date"],
input[type="password"], textarea {
  width: 100%; padding: 9px 12px; margin-top: 6px;
  border: 1px solid transparent; border-radius: 12px; background: var(--surface-2);
}
input[type="time"], input[type="number"], input[type="date"] { width: auto; min-width: 8em; }
input::placeholder, textarea::placeholder { color: var(--muted); }
textarea { min-height: 72px; resize: vertical; font-family: var(--serif); font-size: 1.02rem; line-height: 1.5; }
input:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type="checkbox"] { accent-color: var(--accent); }

.stepper { display: flex; align-items: center; gap: 4px; margin-top: 6px; padding: 3px; border-radius: 14px; background: var(--surface-2); width: max-content; }
.stepper input { margin: 0; width: 3.4em; min-width: 0; text-align: center; padding: 5px 2px; background: none; font-variant-numeric: tabular-nums; }
.stepper button { width: 34px; height: 34px; flex: none; border-radius: 10px; border: 0; background: var(--surface-3); color: var(--text); cursor: pointer; font-size: 1.15rem; }

.btn {
  display: inline-block; padding: 10px 18px; min-height: 44px; border-radius: 14px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); cursor: pointer;
  text-decoration: none; text-align: center;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.btn.danger { color: var(--danger); }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.btn.big { display: block; width: 100%; min-height: 60px; padding: 16px 18px; font-size: 1.15rem; border-radius: 18px; }
.stack { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.link-btn { border: 0; background: none; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; padding: 6px 0; }

/* ---- безопасность: отличается от акцента ---- */
.safety {
  background: var(--safety-bg); border: 1px solid var(--safety-border);
  border-radius: 16px; padding: 14px 16px; margin-top: 12px; font-size: 1.05rem;
}
.safety a { color: #ffd2cd; font-weight: 700; }
.card.safety { box-shadow: none; }
.safety .btn { color: #ffd2cd; border-color: var(--safety-border); background: none; }

/* ---- графики ---- */
.seg { display: inline-flex; padding: 3px; border-radius: 14px; background: var(--surface-2); margin-bottom: 14px; }
.seg button { border: 0; border-radius: 11px; background: none; color: var(--text-2); padding: 7px 14px; min-height: 36px; cursor: pointer; }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

.chart { position: relative; margin-bottom: 22px; }
.chart-title { font-family: var(--serif); font-size: 1.05rem; margin-bottom: 4px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; touch-action: pan-y; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .8rem; color: var(--text-2); margin-bottom: 4px; }
.legend i { display: inline-block; width: 12px; height: 4px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }
.grid-line { stroke: var(--grid); stroke-width: 1; }
.axis-text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.end-label { fill: var(--text-2); font-size: 11px; }
.crosshair { stroke: var(--muted); stroke-width: 1; }
.hit { fill: transparent; }
.s1 { --c: var(--series-1); } .s2 { --c: var(--series-2); }
.s3 { --c: var(--series-3); } .s4 { --c: var(--series-4); }
.legend i.s1, .legend i.s2, .legend i.s3, .legend i.s4 { background: var(--c); }
path.line { fill: none; stroke: var(--c); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
circle.dot { fill: var(--c); stroke: var(--surface); stroke-width: 2; }
path.bar { fill: var(--c); }
.threshold { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 4; opacity: .6; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--surface-3); border: 1px solid var(--border); border-radius: 12px;
  padding: 6px 10px; font-size: .8rem; box-shadow: 0 8px 24px rgb(0 0 0 / .4); white-space: nowrap;
}
.tooltip b { display: block; margin-bottom: 2px; }
.tooltip i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--c); }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
.tile { background: var(--surface-2); border-radius: 16px; padding: 12px 14px; }
.tile-value { font-family: var(--serif); font-size: 1.6rem; font-weight: 600; color: var(--accent); font-variant-numeric: tabular-nums; }
.tile-label { font-size: .78rem; color: var(--text-2); }

/* ---- вход ---- */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border-radius: 24px; padding: 28px 24px; box-shadow: var(--shadow); }
.login-card h1 { font-size: 2rem; color: var(--accent); }
.login-card label { display: block; margin-top: 14px; color: var(--text-2); }
.login-card .btn { width: 100%; margin-top: 22px; }

/* ---- печать: всегда светлая ---- */
@media print {
  :root { color-scheme: light; --bg: #fff; --bg-glow: #fff; --surface: #fff; --surface-2: #f2f2f2; --text: #000; --text-2: #333; --muted: #555;
          --grid: #ccc; --border: #bbb; --accent: #000; --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #6250d6; }
  body { padding: 0; background: #fff; }
  .topbar, .tabs, .no-print { display: none !important; }
  main { max-width: none; padding: 0; }
  .card { box-shadow: none; padding: 0; break-inside: avoid; }
  .chart { break-inside: avoid; }
}

/* ---- лестница ---- */
.step-list { display: flex; flex-direction: column; gap: 8px; }
.step-row {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 60px;
  padding: 12px 14px; border: 1px solid transparent; border-radius: 16px;
  background: var(--surface); color: var(--text); text-align: left; cursor: pointer; box-shadow: var(--shadow);
}
.step-num {
  flex: none; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); color: var(--text-2); font-weight: 600; font-variant-numeric: tabular-nums;
}
.step-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.step-title { font-size: 1.02rem; }
.step-meta { font-size: .8rem; color: var(--muted); }
.chip { flex: none; font-size: .72rem; padding: 3px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.status-active { border-color: var(--accent); }
.status-active .step-num { background: var(--accent); color: var(--accent-ink); }
.status-active .chip { background: var(--accent-soft); color: var(--accent); }
.status-done .step-title { color: var(--text-2); }
.status-done .step-num { color: var(--accent); }
.add-btn { width: 100%; margin-top: 10px; border-style: dashed; background: none; color: var(--text-2); }
.section-title { margin-top: 26px; color: var(--text-2); }
.card.tools { background: none; box-shadow: none; padding: 6px 0; }
.card.tools .btn-row { margin-top: 6px; }

/* ---- шкала SUDS 0–100: крупное число и ползунок ---- */
.suds { margin-top: 6px; }
.suds-num { font-family: var(--serif); font-size: 2.6rem; font-weight: 600; line-height: 1.1; color: var(--accent); font-variant-numeric: tabular-nums; text-align: center; }
.suds-range { width: 100%; height: 44px; margin: 4px 0 0; background: none; accent-color: var(--accent); -webkit-appearance: none; appearance: none; }
.suds-range::-webkit-slider-runnable-track { height: 10px; border-radius: 5px; background: var(--surface-3); }
.suds-range::-moz-range-track { height: 10px; border-radius: 5px; background: var(--surface-3); }
.suds-range::-webkit-slider-thumb { -webkit-appearance: none; width: 34px; height: 34px; margin-top: -12px; border-radius: 50%; background: var(--accent); border: 0; box-shadow: 0 0 14px rgb(233 169 91 / .35); }
.suds-range::-moz-range-thumb { width: 34px; height: 34px; border-radius: 50%; background: var(--accent); border: 0; }
.suds-range.unset::-webkit-slider-thumb { background: var(--muted); box-shadow: none; }
.suds-range.unset::-moz-range-thumb { background: var(--muted); }

/* ---- выход ---- */
.center { text-align: center; }
.big-text { font-family: var(--serif); font-size: 1.3rem; line-height: 1.3; margin: 4px 0; }
.choices.vertical { flex-direction: column; }
.choices.vertical .choice { text-align: left; min-height: 44px; }
.clock { font-family: var(--serif); font-size: 4rem; font-weight: 600; text-align: center; line-height: 1.05; margin-top: 18px; font-variant-numeric: tabular-nums; }
.suds-now { text-align: center; margin-top: 10px; }
.suds-now-num { font-family: var(--serif); font-size: 2.4rem; font-weight: 600; color: var(--accent); font-variant-numeric: tabular-nums; }
.advice { text-align: center; margin: 4px 0 14px; color: var(--text-2); }
.advice.ok { color: var(--series-3); font-weight: 600; }
.card.ask { border: 1px solid var(--accent); }
.card.warn { border: 1px solid var(--accent); }
.btn-row.two { display: grid; grid-template-columns: 1fr 1fr; margin-top: 0; }
.btn.panic { color: #ffd2cd; border-color: var(--safety-border); background: var(--safety-bg); }
.half-line { stroke: var(--series-3); stroke-width: 1.5; stroke-dasharray: 5 5; }
.half-text { fill: var(--series-3); font-size: 11px; }

/* ---- дыхание ---- */
.overlay { position: fixed; inset: 0; z-index: 50; background: var(--bg); overflow-y: auto; }
.overlay-inner { max-width: 640px; margin: 0 auto; padding: calc(24px + env(safe-area-inset-top)) 16px 24px; display: flex; flex-direction: column; gap: 16px; }
.breath { display: grid; place-items: center; height: 300px; }
.breath-circle {
  width: 120px; height: 120px; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle, rgb(233 169 91 / .35), rgb(233 169 91 / .12));
  border: 2px solid var(--accent); transform: scale(1);
  transition-property: transform; transition-timing-function: ease-in-out; transition-duration: 4s;
}
.breath-circle.full { transform: scale(2.2); }
.breath-label { font-family: var(--serif); font-size: 1.2rem; color: var(--text); transform: none; }

/* ---- предложения ---- */
.card.suggest { border: 1px solid var(--border); }
.card.suggest.good { border-color: var(--series-3); }
.card.suggest.good h2 { color: var(--series-3); }

/* ---- настройки ---- */
h3.sub { margin: 20px 0 0; color: var(--accent); font-size: .95rem; }
.stepper-value { min-width: 4.2em; text-align: center; font-variant-numeric: tabular-nums; }
input[type="tel"] { width: 100%; padding: 9px 12px; margin-top: 6px; border: 1px solid transparent; border-radius: 12px; background: var(--surface-2); }

/* ---- Сейчас ---- */
.card.hero { padding: 22px 18px; }
.hero-kicker { color: var(--accent); font-size: .85rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.hero-title { font-family: var(--serif); font-size: 1.6rem; line-height: 1.25; margin: 8px 0 18px; }
.marks { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin: 4px 0 18px; }
.mark { padding: 5px 12px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: .85rem; }
.mark.ok { background: var(--accent-soft); color: var(--accent); }
.progress { padding: 0 4px; }
.progress-text { color: var(--text-2); font-size: .9rem; margin-bottom: 6px; }
.progress-bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 4px; }
.breath-circle { gap: 2px; align-content: center; }
.breath-count { font-size: .9rem; color: var(--text-2); font-variant-numeric: tabular-nums; }
.breath-circle.holding { border-style: dashed; }
.breath-circle.top { transform: scale(2.45); }

/* ---- Совсем плохо: сначала одно действие ---- */
.help-calm { min-height: 50vh; display: flex; flex-direction: column; justify-content: center; gap: 22px; }
.help-toggle { display: block; margin: 28px auto 0; font-size: .95rem; }
.help-more { margin-top: 8px; }
.btn.danger-call { color: #ffd2cd; border-color: var(--safety-border); background: var(--safety-bg); }
.more-out { margin: -6px 0 16px; }
.more-out .btn.big { min-height: 48px; font-size: 1rem; padding: 10px; }
#view-retro input[type="time"] { margin-top: 10px; }

/* ---- мои выходы ---- */
.history-link { display: block; margin: 18px auto 0; }
.day-group { margin-bottom: 18px; }
.day-title { color: var(--text-2); font-size: .95rem; margin: 6px 4px 8px; }
.session-row .step-num.time { width: auto; min-width: 52px; padding: 0 8px; border-radius: 10px; font-size: .85rem; }
.chip.low { background: rgb(25 158 112 / .18); color: var(--series-3); }
.pair input[type="date"], .pair input[type="time"] { width: 100%; min-width: 0; }
