/* ==========================================================================
   ГАВАНЬ / HAVEN — дизайн-система «Тихая гавань»
   Спокойная, тёмная-по-умолчанию тема для помощи при тревоге и панике.
   Никаких резких цветов, мягкие переходы, много воздуха, крупные касания.
   ========================================================================== */

:root {
  /* Палитра — «ночь у моря»: глубокий сине-бирюзовый + мягкая лаванда */
  --bg:        #0d1526;
  --bg2:       #122038;
  --bg-glow:   #16406b;
  --surface:   rgba(255,255,255,.055);
  --surface-2: rgba(255,255,255,.09);
  --border:    rgba(255,255,255,.10);
  --text:      #eaf1ff;
  --muted:     #9fb2d4;
  --faint:     #6f83a6;

  --accent:    #7fe3d4;   /* мятно-бирюзовый — «дыхание» */
  --accent-2:  #b9a9ff;   /* лаванда */
  --accent-3:  #ffd39b;   /* тёплый песок — акцент тепла */
  --sos:       #78e0cf;   /* мягкий, не тревожный */

  --radius:    22px;
  --radius-sm: 14px;
  --shadow:    0 18px 50px -20px rgba(0,0,0,.7);
  --ease:      cubic-bezier(.22,.61,.36,1);

  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

:root[data-theme="light"] {
  --bg:        #eef3fb;
  --bg2:       #e2ecfa;
  --bg-glow:   #cfe4ff;
  --surface:   rgba(20,40,80,.05);
  --surface-2: rgba(20,40,80,.08);
  --border:    rgba(20,40,80,.12);
  --text:      #14233d;
  --muted:     #4c608a;
  --faint:     #7c8db0;
  --accent:    #1f9e8c;
  --accent-2:  #6a53c9;
  --accent-3:  #c98a2b;
  --sos:       #1f9e8c;
  --shadow:    0 18px 50px -24px rgba(30,60,120,.35);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "SF Pro Text",
               system-ui, Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  background-image:
    radial-gradient(120% 80% at 50% -10%, var(--bg-glow) 0%, transparent 55%),
    radial-gradient(90% 60% at 100% 110%, rgba(185,169,255,.16) 0%, transparent 50%),
    linear-gradient(180deg, var(--bg2) 0%, var(--bg) 60%);
  background-attachment: fixed;
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
  line-height: 1.5;
}

/* ---- Оболочка ---- */
.app-shell {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: calc(var(--safe-top) + 10px) 18px calc(var(--safe-bottom) + 96px);
  display: flex; flex-direction: column;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 2px 14px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .mark {
  width: 34px; height: 34px; border-radius: 12px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 18px -6px rgba(127,227,212,.6);
}
.brand .mark svg { width: 20px; height: 20px; }
.brand .name { font-weight: 700; letter-spacing: .2px; font-size: 18px; }
.brand .name small { display:block; font-weight:500; font-size:11px; color:var(--muted); letter-spacing:.4px; margin-top:-2px;}

.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  display: grid; place-items: center; cursor: pointer;
  transition: background .2s var(--ease), transform .2s var(--ease);
}
.icon-btn:active { transform: scale(.94); }
.icon-btn svg { width: 20px; height: 20px; }

/* ---- Экраны ---- */
.screen { flex: 1; display: none; animation: fade .35s var(--ease); }
.screen.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(8px);} to { opacity:1; transform:none; } }

.h1 { font-size: 26px; font-weight: 700; letter-spacing: -.3px; margin: 6px 0 4px; }
.lead { color: var(--muted); font-size: 15.5px; margin: 0 0 20px; }
.sec-h { font-size: 13px; text-transform: uppercase; letter-spacing: 1.4px; color: var(--faint); margin: 26px 4px 12px; font-weight: 700; }

/* ---- Кнопка SOS ---- */
.sos {
  position: relative;
  width: 100%; border: none; cursor: pointer;
  border-radius: 26px; padding: 26px 22px;
  color: #05221d; text-align: left;
  background: linear-gradient(135deg, #8ff0e0 0%, var(--accent) 55%, #6fd6c6 100%);
  box-shadow: 0 22px 55px -18px rgba(127,227,212,.65);
  display: flex; align-items: center; gap: 16px;
  transition: transform .25s var(--ease);
  overflow: hidden;
}
.sos:active { transform: scale(.985); }
.sos::after {
  content:""; position:absolute; inset:0; border-radius:26px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.35);
  pointer-events:none;
}
.sos .pulse {
  width: 58px; height: 58px; flex: none; border-radius: 50%;
  background: rgba(255,255,255,.4); display: grid; place-items: center;
  animation: breathe 4.5s var(--ease) infinite;
}
.sos .pulse svg { width: 28px; height: 28px; }
@keyframes breathe { 0%,100%{ transform: scale(.85); opacity:.8;} 50%{ transform: scale(1.12); opacity:1;} }
.sos .txt strong { display: block; font-size: 20px; font-weight: 800; }
.sos .txt span { font-size: 13.5px; opacity: .8; }

/* ---- Сетка карточек ---- */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.tile {
  border: 1px solid var(--border); background: var(--surface);
  border-radius: var(--radius); padding: 18px 16px; cursor: pointer;
  text-align: left; color: var(--text);
  transition: background .2s var(--ease), transform .2s var(--ease), border-color .2s;
  display: flex; flex-direction: column; gap: 10px; min-height: 128px;
}
.tile:active { transform: scale(.97); }
.tile:hover { background: var(--surface-2); }
.tile .ti {
  width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center;
  background: linear-gradient(135deg, rgba(127,227,212,.22), rgba(185,169,255,.22));
  border: 1px solid var(--border);
}
.tile .ti svg { width: 22px; height: 22px; }
.tile h3 { margin: 0; font-size: 16px; font-weight: 700; }
.tile p { margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.4; }
.tile.wide { grid-column: 1 / -1; min-height: auto; flex-direction: row; align-items: center; }
.tile.wide .ti { flex: none; }

/* ---- Общие карточки/панели ---- */
.card {
  border: 1px solid var(--border); background: var(--surface);
  border-radius: var(--radius); padding: 20px;
}
.reassure {
  border: 1px solid rgba(127,227,212,.28);
  background: linear-gradient(135deg, rgba(127,227,212,.10), rgba(185,169,255,.08));
  border-radius: var(--radius); padding: 18px 18px; margin-top: 8px;
}
.reassure p { margin: 0; font-size: 14px; color: var(--text); }
.reassure p + p { margin-top: 8px; color: var(--muted); font-size: 13px; }

/* ---- Кнопки ---- */
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); font-size: 15px; font-weight: 600; cursor: pointer;
  padding: 14px 20px; border-radius: 16px; transition: transform .2s var(--ease), background .2s;
}
.btn:active { transform: scale(.96); }
.btn.primary {
  border: none; color: #05221d;
  background: linear-gradient(135deg, var(--accent), #6fd6c6);
}
.btn.ghost { background: transparent; }
.btn.block { display: block; width: 100%; text-align: center; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

.back {
  display: inline-flex; align-items: center; gap: 6px; color: var(--muted);
  background: none; border: none; cursor: pointer; font-size: 15px; padding: 6px 0; margin-bottom: 6px;
}
.back svg { width: 18px; height: 18px; }

/* ==========================================================================
   ДЫХАНИЕ
   ========================================================================== */
.breath-stage {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 62dvh; text-align: center; gap: 20px;
}
.breath-circle {
  position: relative; width: 240px; height: 240px; display: grid; place-items: center;
}
.breath-circle .ring {
  position: absolute; inset: 0; border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, rgba(127,227,212,.5), rgba(127,227,212,.08) 60%, transparent 72%);
  transform: scale(.55);
  transition: transform linear;
  box-shadow: 0 0 80px -10px rgba(127,227,212,.5);
}
.breath-circle .ring2 {
  position:absolute; inset:0; border-radius:50%;
  border: 1.5px solid rgba(185,169,255,.35);
  transform: scale(.55); transition: transform linear;
}
.breath-circle .core {
  position: relative; z-index: 2; width: 130px; height: 130px; border-radius: 50%;
  background: rgba(13,21,38,.55); backdrop-filter: blur(4px);
  border: 1px solid var(--border);
  display: grid; place-items: center; text-align: center;
}
.breath-phase { font-size: 21px; font-weight: 700; }
.breath-count { font-size: 40px; font-weight: 300; font-variant-numeric: tabular-nums; letter-spacing: 1px; }
.breath-meta { color: var(--muted); font-size: 14px; }
.breath-cycles { color: var(--faint); font-size: 13px; }

.chip-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 9px 15px; font-size: 13.5px; cursor: pointer;
  transition: background .2s, border-color .2s;
}
.chip.active { background: linear-gradient(135deg, rgba(127,227,212,.9), #6fd6c6); color: #05221d; border-color: transparent; font-weight: 700; }

/* ==========================================================================
   ЗАЗЕМЛЕНИЕ 5-4-3-2-1
   ========================================================================== */
.ground-step { text-align: center; }
.ground-num {
  font-size: 76px; font-weight: 800; line-height: 1;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.ground-sense { font-size: 22px; font-weight: 700; margin: 10px 0 4px; }
.ground-hint { color: var(--muted); font-size: 15px; margin: 0 0 22px; }
.ground-dots { display: flex; gap: 8px; justify-content: center; margin: 20px 0; }
.ground-dots i { width: 9px; height: 9px; border-radius: 50%; background: var(--border); transition: background .3s; }
.ground-dots i.on { background: var(--accent); }
.tick-row { display:flex; gap:10px; justify-content:center; margin: 8px 0 20px; }
.tick {
  width: 46px; height: 46px; border-radius: 14px; border: 1.5px solid var(--border);
  background: var(--surface); color: var(--muted); font-size: 20px; cursor: pointer;
  transition: all .2s var(--ease);
}
.tick.done { background: linear-gradient(135deg, var(--accent), #6fd6c6); border-color: transparent; color:#05221d; }

/* ==========================================================================
   ЗВУКИ
   ========================================================================== */
.sound-list { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.sound {
  border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius);
  padding: 18px 14px; cursor: pointer; text-align: center; color: var(--text);
  transition: all .2s var(--ease);
}
.sound:active { transform: scale(.96); }
.sound.playing { border-color: var(--accent); background: linear-gradient(135deg, rgba(127,227,212,.15), rgba(185,169,255,.10)); }
.sound .si { font-size: 30px; margin-bottom: 8px; }
.sound .sn { font-size: 14px; font-weight: 600; }
.sound.playing .sn::after { content: " ●"; color: var(--accent); }

.volume-wrap { margin-top: 22px; display: flex; align-items: center; gap: 12px; }
.volume-wrap svg { width: 20px; height: 20px; color: var(--muted); flex: none; }
input[type=range] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 6px; border-radius: 999px;
  background: var(--surface-2); outline: none;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,.4);
}

/* ==========================================================================
   МЕДИТАЦИИ / ИСТОРИИ
   ========================================================================== */
.med-list { display: flex; flex-direction: column; gap: 12px; }
.med {
  border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius);
  padding: 16px 18px; cursor: pointer; display: flex; align-items: center; gap: 14px;
  transition: all .2s var(--ease); color: var(--text); text-align: left;
}
.med:active { transform: scale(.98); }
.med .mi { width: 44px; height: 44px; border-radius: 13px; flex: none; display: grid; place-items: center;
  background: linear-gradient(135deg, rgba(185,169,255,.25), rgba(127,227,212,.18)); border: 1px solid var(--border); font-size: 22px; }
.med .mtxt strong { display: block; font-size: 15.5px; }
.med .mtxt span { font-size: 12.5px; color: var(--muted); }

.player { text-align: center; }
.player .cover {
  width: 120px; height: 120px; border-radius: 28px; margin: 4px auto 18px;
  display: grid; place-items: center; font-size: 52px;
  background: linear-gradient(135deg, rgba(185,169,255,.3), rgba(127,227,212,.25));
  border: 1px solid var(--border);
}
.player-body {
  text-align: left; margin-top: 20px; color: var(--text); font-size: 17px; line-height: 1.75;
  max-height: 40dvh; overflow-y: auto; padding: 4px 4px 40px;
  -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 22px, #000 calc(100% - 30px), transparent 100%);
}
.player-body p { margin: 0 0 16px; transition: color .3s, opacity .3s; }
.player-body p.now { color: var(--accent); }
.player-body p.past { opacity: .45; }

.play-controls { display: flex; align-items: center; justify-content: center; gap: 22px; margin-top: 6px; }
.play-fab {
  width: 72px; height: 72px; border-radius: 50%; border: none; cursor: pointer;
  background: linear-gradient(135deg, var(--accent), #6fd6c6); color: #05221d;
  display: grid; place-items: center; box-shadow: 0 14px 34px -12px rgba(127,227,212,.7);
  transition: transform .2s var(--ease);
}
.play-fab:active { transform: scale(.92); }
.play-fab svg { width: 30px; height: 30px; }

/* ---- Нижняя навигация ---- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  padding: 8px 12px calc(var(--safe-bottom) + 8px);
  display: flex; justify-content: center; gap: 6px;
  background: linear-gradient(180deg, transparent, var(--bg) 40%);
  pointer-events: none;
}
.tabbar-inner {
  pointer-events: auto;
  display: flex; gap: 4px; padding: 6px;
  background: rgba(13,21,38,.72); backdrop-filter: blur(16px);
  border: 1px solid var(--border); border-radius: 999px; box-shadow: var(--shadow);
}
:root[data-theme="light"] .tabbar-inner { background: rgba(255,255,255,.8); }
.tab {
  border: none; background: none; cursor: pointer; color: var(--muted);
  padding: 10px 16px; border-radius: 999px; display: grid; place-items: center; gap: 3px;
  font-size: 10.5px; transition: color .2s, background .2s;
}
.tab svg { width: 22px; height: 22px; }
.tab.active { color: var(--accent); background: var(--surface); }

.footnote { color: var(--faint); font-size: 12px; text-align: center; margin: 26px 0 6px; line-height: 1.6; }
.footnote a { color: var(--muted); }

/* ==========================================================================
   ПОЧЕМУ ТАК ПРОИСХОДИТ + БЕЗОПАСНОСТЬ
   ========================================================================== */
.why-card {
  display: flex; gap: 14px; padding: 16px; margin-bottom: 12px;
  border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius);
}
.why-ic { font-size: 26px; flex: none; line-height: 1.2; }
.why-card strong { display: block; margin-bottom: 5px; font-size: 15.5px; }
.why-card p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.5; }

.safety-card {
  width: 100%; text-align: left; margin-top: 14px; cursor: pointer;
  display: flex; gap: 12px; align-items: flex-start; padding: 15px 16px;
  border-radius: var(--radius); color: var(--text);
  border: 1px solid rgba(255,211,155,.35); background: rgba(255,211,155,.09);
  transition: transform .2s var(--ease);
}
.safety-card:active { transform: scale(.98); }
.safety-card .sc-ic { color: var(--accent-3); flex: none; }
.safety-card .sc-ic svg { width: 24px; height: 24px; }
.safety-card strong { display: block; font-size: 14.5px; margin-bottom: 3px; }
.safety-card span { font-size: 12.5px; color: var(--muted); line-height: 1.45; }

.safety-block p { margin: 0 0 6px; font-size: 14px; }
.flags { margin: 10px 0; padding-left: 20px; }
.flags li { margin: 7px 0; font-size: 14px; color: var(--text); line-height: 1.45; }

/* ==========================================================================
   ЧАТ СО «СПУТНИКОМ»
   ========================================================================== */
.chat-head { display: flex; align-items: center; gap: 12px; padding: 2px 2px 12px; }
.chat-ava {
  width: 42px; height: 42px; border-radius: 13px; flex: none; display: grid; place-items: center;
  color: #05221d; background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.chat-ava svg { width: 22px; height: 22px; }
.chat-head strong { display: block; font-size: 16px; }
.chat-head span { font-size: 12px; color: var(--muted); }

.chat-feed {
  height: calc(100dvh - 300px); min-height: 190px; overflow-y: auto;
  -webkit-overflow-scrolling: touch; padding: 4px 2px; scroll-behavior: smooth;
}
.msg { display: flex; margin: 9px 0; }
.msg.user { justify-content: flex-end; }
.bubble {
  max-width: 84%; padding: 11px 14px; border-radius: 18px; font-size: 15px; line-height: 1.5;
  white-space: pre-wrap; word-wrap: break-word;
}
.msg.bot .bubble { background: var(--surface-2); border: 1px solid var(--border); border-bottom-left-radius: 6px; }
.msg.user .bubble { background: linear-gradient(135deg, var(--accent), #6fd6c6); color: #05221d; border-bottom-right-radius: 6px; }
.msg.escalate .bubble { border-color: rgba(255,211,155,.55); background: rgba(255,211,155,.12); }
.msg.typing .bubble { display: inline-flex; gap: 4px; padding: 14px 16px; }
.msg.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); opacity: .5; animation: blink 1.2s infinite; }
.msg.typing span:nth-child(2) { animation-delay: .2s; }
.msg.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,60%,100%{ opacity:.25; transform: translateY(0);} 30%{ opacity:1; transform: translateY(-3px);} }

.chat-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 2px 0 10px; }
.chat-chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--accent);
  border-radius: 999px; padding: 9px 14px; font-size: 13.5px; cursor: pointer; font-weight: 600;
  transition: background .2s;
}
.chat-chip:active { background: var(--surface-2); }
.chat-note { font-size: 12.5px; color: var(--faint); text-align: center; margin: 0 12px 12px; line-height: 1.5; }

.chat-input {
  display: flex; gap: 8px; align-items: flex-end; margin-top: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 22px; padding: 7px 7px 7px 14px;
}
.chat-input textarea {
  flex: 1; background: none; border: none; color: var(--text); font-size: 15px; resize: none;
  outline: none; font-family: inherit; line-height: 1.4; padding: 8px 0; max-height: 120px;
}
.chat-send {
  width: 44px; height: 44px; border-radius: 50%; border: none; flex: none; cursor: pointer;
  background: linear-gradient(135deg, var(--accent), #6fd6c6); color: #05221d;
  display: grid; place-items: center; transition: transform .2s var(--ease);
}
.chat-send:active { transform: scale(.9); }
.chat-send svg { width: 22px; height: 22px; }

.hide { display: none !important; }
