:root {
  --bg: #06060e;
  --text: #edeaf8;
  --text-dim: #9895b0;
  --muted: #55516a;
  --line: rgba(255,255,255,0.06);
  --accent: #a855f7;
  --accent-2: #6366f1;
  --sky: #38bdf8;
  --warm: #f59e0b;
  --danger: #ef4444;
  --success: #34d399;
  --panel: rgba(10, 10, 20, 0.82);

  --orb-1: #e0f2fe;
  --orb-2: #bae6fd;
  --orb-3: #7dd3fc;
  --orb-4: #38bdf8;
  --orb-dark: #0a1828;

  --radius-xl: 24px;
  --radius-lg: 16px;
  --radius-md: 11px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: "Inter", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button, textarea, input { font: inherit; }

/* ── Фон + шумовая текстура ──────────────── */

body {
  background:
    radial-gradient(ellipse at 50% 38%, rgba(56, 189, 248, 0.07) 0%, transparent 55%),
    radial-gradient(ellipse at 20% 80%, rgba(99, 60, 180, 0.10) 0%, transparent 45%),
    radial-gradient(ellipse at 80% 90%, rgba(245, 158, 11, 0.04) 0%, transparent 35%),
    #06060e;
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.028;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='256' height='256'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='256' height='256' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 256px 256px;
}

/* ── Волновое поле (весь экран) ──────────── */
/*
   Волны рождаются из центра орба (≈38% сверху, 50% слева)
   и расходятся до краёв экрана.
*/

.wave-field {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  overflow: hidden;
}

.wave {
  position: absolute;
  top: 38%;
  left: 50%;
  border-radius: 50%;
  border: 1px solid rgba(125, 211, 252, 0.12);
  transform: translate(-50%, -50%) scale(0);
  animation: wave-idle 8s ease-out infinite;
}

.wave-1 { animation-delay: 0s; }
.wave-2 { animation-delay: 1.6s; }
.wave-3 { animation-delay: 3.2s; }
.wave-4 { animation-delay: 4.8s; }
.wave-5 { animation-delay: 6.4s; }

@keyframes wave-idle {
  0%   { width: 220px; height: 220px; opacity: 0.55; }
  100% { width: 220vmax; height: 220vmax; opacity: 0; }
}

/* Состояние — говорит */
body[data-orb="speaking"] .wave {
  animation-name: wave-speak;
  animation-duration: 3s;
  border-color: rgba(186, 230, 253, 0.22);
}
@keyframes wave-speak {
  0%   { width: 220px; height: 220px; opacity: 0.8; }
  100% { width: 220vmax; height: 220vmax; opacity: 0; }
}

/* Состояние — слушает */
body[data-orb="listening"] .wave {
  animation-name: wave-listen;
  animation-duration: 4s;
  border-color: rgba(168, 85, 247, 0.20);
}
@keyframes wave-listen {
  0%   { width: 220px; height: 220px; opacity: 0.7; }
  100% { width: 220vmax; height: 220vmax; opacity: 0; }
}

/* Состояние — думает */
body[data-orb="thinking"] .wave {
  animation-duration: 5s;
  border-color: rgba(99, 102, 241, 0.18);
}

/* ── Шапка ───────────────────────────────── */

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  background: rgba(6, 6, 14, 0.75);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--line);
}

.step-counter {
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-weight: 500;
  min-width: 36px;
}

.voice-chip {
  font-size: 0.68rem;
  color: var(--muted);
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(56, 189, 248, 0.18);
  color: rgba(56, 189, 248, 0.65);
  white-space: nowrap;
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  gap: 6px;
}

.tb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.03);
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.tb-btn:hover { background: rgba(255,255,255,0.07); color: var(--text-dim); }
.tb-btn--danger { border-color: rgba(239,68,68,0.2); color: rgba(239,68,68,0.55); }
.tb-btn--danger:hover { background: rgba(239,68,68,0.10); color: #fca5a5; }

/* ── Основная сцена ──────────────────────── */

.scene {
  position: relative;
  z-index: 10;
  height: 100dvh;
  padding-top: 42px; /* высота topbar */
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ── Орб-сцена ───────────────────────────── */

.orb-stage {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px 20px 20px;
  gap: 14px;
}

/* ── Строка фазы ─────────────────────────── */

.phase-line {
  display: flex;
  align-items: center;
  gap: 10px;
  transition: opacity 0.3s, transform 0.3s;
}

.phase-line.is-changing {
  opacity: 0;
  transform: translateY(-6px);
}

.phase-tag {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  padding: 3px 10px;
  border-radius: 999px;
  transition: background 0.4s, border-color 0.4s, color 0.4s;
  /* default */
  background: rgba(168,85,247,0.10);
  border: 1px solid rgba(168,85,247,0.22);
  color: #c084fc;
}

.phase-tag[data-phase="Скрининг"]     { background: rgba(14,165,233,0.10); border-color: rgba(14,165,233,0.25); color: #38bdf8; }
.phase-tag[data-phase="Диагностика"]  { background: rgba(245,158,11,0.10); border-color: rgba(245,158,11,0.25); color: #fbbf24; }
.phase-tag[data-phase="Индукция"]     { background: rgba(99,102,241,0.10); border-color: rgba(99,102,241,0.25); color: #818cf8; }
.phase-tag[data-phase="Корень"]       { background: rgba(236,72,153,0.10); border-color: rgba(236,72,153,0.25); color: #f472b6; }
.phase-tag[data-phase="Сопротивление"]{ background: rgba(234,179,8,0.10);  border-color: rgba(234,179,8,0.25);  color: #facc15; }
.phase-tag[data-phase="Инстинкты"]    { background: rgba(249,115,22,0.10); border-color: rgba(249,115,22,0.25); color: #fb923c; }
.phase-tag[data-phase="Интеграция"]   { background: rgba(52,211,153,0.10); border-color: rgba(52,211,153,0.25); color: #34d399; }

.phase-sep {
  color: var(--muted);
  font-size: 0.75rem;
  opacity: 0.5;
}

.phase-title {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-dim);
  letter-spacing: -0.01em;
  max-width: 320px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Орб ─────────────────────────────────── */

.orb {
  position: relative;
  width: 220px;
  height: 220px;
  flex-shrink: 0;
}

.orb-core {
  position: absolute;
  inset: 10%;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 32%,
    #ffffff 0%,
    #e0f2fe 14%,
    #bae6fd 32%,
    #7dd3fc 55%,
    #1e3a5f 80%,
    var(--orb-dark) 95%
  );
  box-shadow:
    0 0 28px rgba(186, 230, 253, 0.85),
    0 0 65px rgba(125, 211, 252, 0.48),
    0 0 110px rgba(56, 189, 248, 0.22),
    inset 0 0 28px rgba(224, 242, 254, 0.55);
  animation: orb-breathe 4.5s ease-in-out infinite;
}

.orb-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid rgba(186, 230, 253, 0.20);
  animation: orb-ring 4.5s ease-in-out infinite;
}
.orb-ring-1 { animation-delay: 0s; }
.orb-ring-2 { inset: -11%; border-color: rgba(125, 211, 252, 0.12); animation-delay: 1.5s; }
.orb-ring-3 { inset: -24%; border-color: rgba(56, 189, 248, 0.07); animation-delay: 3s; }

.orb-pulse {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid transparent;
}

@keyframes orb-breathe {
  0%, 100% { transform: scale(1); box-shadow: 0 0 28px rgba(186,230,253,0.85), 0 0 65px rgba(125,211,252,0.48), 0 0 110px rgba(56,189,248,0.22), inset 0 0 28px rgba(224,242,254,0.55); }
  50%       { transform: scale(1.055); box-shadow: 0 0 40px rgba(186,230,253,1), 0 0 90px rgba(125,211,252,0.6), 0 0 140px rgba(56,189,248,0.30), inset 0 0 36px rgba(224,242,254,0.68); }
}

@keyframes orb-ring {
  0%, 100% { opacity: 0.85; transform: scale(1); }
  50%       { opacity: 0.22; transform: scale(1.07); }
}

/* — Говорит — */
.orb--speaking .orb-core { animation: orb-speak 0.95s ease-in-out infinite; }
.orb--speaking .orb-ring-1 { animation: orb-ring-speak 0.95s ease-in-out infinite; }
.orb--speaking .orb-ring-2 { animation: orb-ring-speak 0.95s ease-in-out infinite 0.32s; }
.orb--speaking .orb-ring-3 { animation: orb-ring-speak 0.95s ease-in-out infinite 0.64s; }
.orb--speaking .orb-pulse-1 { animation: orb-pulse-out 1.6s ease-out infinite; }
.orb--speaking .orb-pulse-2 { animation: orb-pulse-out 1.6s ease-out infinite 0.8s; }

@keyframes orb-speak {
  0%, 100% { transform: scale(1); }
  30% { transform: scale(1.12); box-shadow: 0 0 50px rgba(186,230,253,1), 0 0 100px rgba(125,211,252,0.75), 0 0 160px rgba(56,189,248,0.38); }
  65% { transform: scale(0.95); }
}
@keyframes orb-ring-speak {
  0%, 100% { opacity: 0.5; transform: scale(1); }
  30% { opacity: 1; transform: scale(1.12); }
}
@keyframes orb-pulse-out {
  0%   { transform: scale(1); border-color: rgba(186,230,253,0.65); opacity: 1; }
  100% { transform: scale(2.6); border-color: rgba(186,230,253,0); opacity: 0; }
}

/* — Слушает — */
.orb--listening .orb-core {
  animation: orb-listen 0.65s ease-in-out infinite;
  background: radial-gradient(circle at 38% 32%,
    #c7e8ff 0%, var(--orb-4) 22%, var(--orb-3) 48%, var(--orb-2) 68%, var(--orb-dark) 88%
  );
}
.orb--listening .orb-ring-1 { animation: orb-ring 0.65s ease-in-out infinite; border-color: rgba(224,242,254,0.45); }

@keyframes orb-listen {
  0%, 100% { transform: scale(0.96); box-shadow: 0 0 20px rgba(224,242,254,0.85), 0 0 50px rgba(186,230,253,0.42); }
  50%       { transform: scale(1.08); box-shadow: 0 0 40px rgba(255,255,255,0.95), 0 0 90px rgba(186,230,253,0.65); }
}

/* — Думает — */
.orb--thinking .orb-core { animation: orb-think 2.2s linear infinite; }
@keyframes orb-think {
  0%   { filter: hue-rotate(0deg); }
  100% { filter: hue-rotate(360deg); }
}

/* — Подтверждение — */
.orb--confirm .orb-core {
  animation: orb-confirm 0.45s ease-out forwards, orb-breathe 4.5s ease-in-out infinite 0.45s;
  background: radial-gradient(circle at 38% 32%, #fff 0%, #bbf7d0 14%, #34d399 38%, #059669 62%, #022c22 88%);
}
.orb--confirm .orb-pulse-1 { animation: orb-pulse-out 0.55s ease-out; }
.orb--confirm .orb-pulse-2 { animation: orb-pulse-out 0.55s ease-out 0.18s; }
@keyframes orb-confirm {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.20); box-shadow: 0 0 60px rgba(52,211,153,1), 0 0 120px rgba(52,211,153,0.5); }
  100% { transform: scale(1); }
}

/* ── Hover / Press орба ──────────────────── */

.orb {
  cursor: pointer;
}

.orb--hover .orb-core {
  box-shadow:
    0 0 38px rgba(186, 230, 253, 1),
    0 0 80px rgba(125, 211, 252, 0.65),
    0 0 130px rgba(56, 189, 248, 0.32),
    inset 0 0 34px rgba(224, 242, 254, 0.70);
  filter: brightness(1.12);
  transition: box-shadow 0.4s ease, filter 0.4s ease;
}

.orb--hover .orb-ring-1 { border-color: rgba(186, 230, 253, 0.40); }
.orb--hover .orb-ring-2 { border-color: rgba(125, 211, 252, 0.26); }
.orb--hover .orb-ring-3 { border-color: rgba(56, 189, 248, 0.16); }

.orb--pressed .orb-core {
  animation: orb-press 0.38s cubic-bezier(0.34, 1.56, 0.64, 1) forwards, orb-breathe 4.5s ease-in-out infinite 0.38s !important;
}
.orb--pressed .orb-pulse-1 { animation: orb-pulse-out 0.5s ease-out !important; }
.orb--pressed .orb-pulse-2 { animation: orb-pulse-out 0.5s ease-out 0.1s !important; }

@keyframes orb-press {
  0%   { transform: scale(1); }
  30%  { transform: scale(0.88); filter: brightness(1.3); }
  100% { transform: scale(1.14); box-shadow: 0 0 55px rgba(186,230,253,1), 0 0 110px rgba(125,211,252,0.7), 0 0 160px rgba(56,189,248,0.38); }
}

/* ── Подпись орба ────────────────────────── */

.orb-label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.02em;
  transition: color 0.35s;
  text-align: center;
}
body[data-orb="speaking"]  .orb-label { color: var(--orb-1); }
body[data-orb="listening"] .orb-label { color: var(--orb-4); }
body[data-orb="thinking"]  .orb-label { color: #a5b4fc; }

.orb-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
}

.icon-btn {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.04);
  color: var(--muted);
  font-size: 0.82rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  position: relative;
}
.icon-btn:hover { background: rgba(168,85,247,0.14); color: var(--text); border-color: rgba(168,85,247,0.28); }

/* mic-status скрыт из потока, показывается тултипом при наведении на #toggle-mic */
.mic-hint {
  display: none;
}

#toggle-mic {
  anchor-name: --mic-btn;
}

#toggle-mic::after {
  content: attr(data-hint);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 0.7rem;
  color: var(--text-dim);
  background: rgba(15, 13, 30, 0.95);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 200;
}

#toggle-mic:hover::after {
  opacity: 1;
}

/* ── Контентная зона ─────────────────────── */

.content-zone {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 620px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: 0 20px 20px;
}

.progress-rail {
  height: 2px;
  background: rgba(255,255,255,0.05);
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 20px;
  flex-shrink: 0;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-2), var(--accent), var(--warm));
  border-radius: 99px;
  transition: width 0.55s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 0 10px rgba(168,85,247,0.6);
}

.content-body {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 22px 24px;
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.055);
  border-radius: var(--radius-xl);
  backdrop-filter: blur(32px);
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.06) transparent;
}

/* ── Текст сессии ────────────────────────── */

.prompt {
  font-size: 1rem;
  line-height: 1.82;
  color: var(--text);
  white-space: pre-wrap;
}

.helper {
  font-size: 0.83rem;
  color: var(--text-dim);
  line-height: 1.65;
}

.coach-notes {
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  background: rgba(168,85,247,0.055);
  border: 1px solid rgba(168,85,247,0.11);
  font-size: 0.8rem;
  color: var(--text-dim);
  line-height: 1.6;
}

.safety-banner {
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  background: rgba(239,68,68,0.07);
  border: 1px solid rgba(239,68,68,0.18);
  font-size: 0.83rem;
  color: #fca5a5;
  line-height: 1.6;
}

/* ── Варианты выбора ─────────────────────── */

.choice-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.choice-chip {
  padding: 8px 18px;
  border-radius: 999px;
  border: 1px solid rgba(168,85,247,0.22);
  background: rgba(168,85,247,0.055);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.87rem;
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.choice-chip:hover { background: rgba(168,85,247,0.15); border-color: rgba(168,85,247,0.42); color: var(--text); }
.choice-chip.is-selected { background: rgba(168,85,247,0.22); border-color: var(--accent); color: #e9d5ff; }

/* ── Ввод ────────────────────────────────── */

.input-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

textarea#answer-input {
  width: 100%;
  padding: 11px 13px;
  background: rgba(255,255,255,0.025);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  color: var(--text);
  resize: vertical;
  outline: none;
  line-height: 1.65;
  transition: border-color 0.2s;
}
textarea#answer-input:focus { border-color: rgba(168,85,247,0.42); }
textarea#answer-input::placeholder { color: var(--muted); opacity: 0.65; }

.range-wrap {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 4px;
}
.range-wrap input[type=range] { flex: 1; accent-color: var(--accent); }
.range-wrap strong { min-width: 22px; text-align: right; font-variant-numeric: tabular-nums; }

.input-label {
  font-size: 0.68rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-weight: 700;
  display: block;
  margin-bottom: 4px;
}

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

.nav-row {
  display: flex;
  gap: 8px;
  padding-top: 4px;
}

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

.primary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 22px;
  border-radius: var(--radius-md);
  border: none;
  background: linear-gradient(135deg, #60a5fa 0%, #a78bfa 50%, #c084fc 100%);
  color: #fff;
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  letter-spacing: 0.01em;
  transition: opacity 0.15s, transform 0.1s, box-shadow 0.2s;
  box-shadow: 0 4px 18px rgba(168,85,247,0.30);
}
.primary-btn:hover { opacity: 0.90; box-shadow: 0 6px 26px rgba(168,85,247,0.44); }
.primary-btn:active { transform: scale(0.97); }

.ghost-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.025);
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.ghost-btn:hover { background: rgba(255,255,255,0.06); color: var(--text); border-color: rgba(255,255,255,0.10); }

/* ── Диалог подтверждения ────────────────── */

.confirm-dialog {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.72);
  backdrop-filter: blur(16px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  padding: 20px;
}

.confirm-box {
  background: rgba(10, 9, 22, 0.98);
  border: 1px solid rgba(168,85,247,0.18);
  border-radius: var(--radius-xl);
  box-shadow: 0 0 70px rgba(168,85,247,0.14), 0 28px 80px rgba(0,0,0,0.75);
  padding: 32px 36px;
  max-width: 440px;
  width: 100%;
  text-align: center;
}

.confirm-label {
  font-size: 0.68rem;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 11px;
  font-weight: 700;
}

.confirm-text {
  font-size: 1.15rem;
  line-height: 1.5;
  color: var(--text);
  margin-bottom: 22px;
  font-weight: 500;
}

.confirm-actions { display: flex; gap: 10px; justify-content: center; }

.confirm-hint {
  margin-top: 13px;
  font-size: 0.72rem;
  color: var(--muted);
}

/* ── Утилиты ─────────────────────────────── */

.hidden { display: none !important; }

.js-only {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
}

/* ── Адаптив ─────────────────────────────── */

@media (max-width: 680px) {
  .orb { width: 170px; height: 170px; }
  .orb-ring-3 { display: none; }
  .content-zone { padding: 0 12px 14px; }
  .content-body { padding: 16px 16px; }
  .topbar-actions .tb-btn:not(#export-session):not(#reset-session) { display: none; }
}

@media (max-width: 420px) {
  .phase-title { display: none; }
  .orb { width: 140px; height: 140px; }
}
