:root {
  --bg-grad: linear-gradient(160deg, #0d0814 0%, #14081e 40%, #0a1020 100%);
  --serif: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  --text: #f0e6ff;
  --text-soft: #e8deff;
  --accent: #c084fc;
  --accent-soft: rgba(192, 132, 252, 0.5);
  --accent-faint: rgba(192, 132, 252, 0.15);
  --accent-trace: rgba(192, 132, 252, 0.08);
  --user-grad: linear-gradient(135deg, #7c3aed 0%, #5b21b6 100%);
  --surface: rgba(255, 255, 255, 0.04);
  --surface-warm: rgba(255, 255, 255, 0.055);
  --border: rgba(192, 132, 252, 0.1);
}

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

html, body {
  min-height: 100%;
  background: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--serif);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

body { min-height: 100vh; min-height: 100dvh; }

::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(192,132,252,0.2); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(192,132,252,0.35); }

button { font-family: inherit; }
button:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent-soft);
  outline-offset: 2px;
}

/* ===== No access screen ===== */

.no-access {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 24px;
  text-align: center;
}

.no-access-orb {
  width: 60px; height: 60px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffd1f0 0%, #f9a8d4 25%, #c084fc 65%, #818cf8 100%);
  box-shadow: 0 0 30px rgba(192,132,252,0.35);
  margin-bottom: 28px;
  opacity: 0.6;
}

.no-access-title {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 1.7rem;
  letter-spacing: 0.06em;
  color: var(--text);
  margin-bottom: 18px;
}

.no-access-text {
  font-family: var(--sans);
  font-size: 0.85rem;
  color: rgba(192,132,252,0.55);
  font-style: italic;
  line-height: 1.7;
  letter-spacing: 0.02em;
  max-width: 320px;
}

/* ===== App ===== */

.app {
  display: none;
  max-width: 620px;
  margin: 0 auto;
  padding: 22px 14px 14px;
  min-height: 100vh;
  min-height: 100dvh;
  flex-direction: column;
  gap: 14px;
}

/* ===== Header ===== */

.header { text-align: center; margin-bottom: 4px; }

.orb {
  width: 50px; height: 50px;
  margin: 0 auto 10px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 35%, #ffd1f0 0%, #f9a8d4 25%, #c084fc 65%, #818cf8 100%);
  box-shadow:
    0 0 30px rgba(192,132,252,0.35),
    inset 0 1px 8px rgba(255,255,255,0.4);
  animation: glow 5s ease-in-out infinite;
}

@keyframes glow {
  0%, 100% { box-shadow: 0 0 22px rgba(192,132,252,0.25), inset 0 1px 8px rgba(255,255,255,0.4); }
  50%      { box-shadow: 0 0 50px rgba(192,132,252,0.55), inset 0 1px 8px rgba(255,255,255,0.5); }
}

.title {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 1.7rem;
  letter-spacing: 0.06em;
  color: var(--text);
}

.subtitle {
  font-family: var(--sans);
  font-size: 0.74rem;
  color: rgba(192,132,252,0.5);
  font-style: italic;
  margin-top: 4px;
  letter-spacing: 0.03em;
}

/* ===== Tools ===== */

.tools {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.tool-btn {
  background: var(--accent-trace);
  border: 1px solid var(--accent-faint);
  border-radius: 20px;
  padding: 6px 16px;
  color: rgba(192,132,252,0.7);
  font-family: var(--sans);
  font-size: 0.74rem;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: all 0.2s;
}
.tool-btn:hover { background: rgba(192,132,252,0.12); color: rgba(192,132,252,0.9); }
.tool-btn--minor { color: rgba(255,255,255,0.35); border-color: rgba(255,255,255,0.08); background: rgba(255,255,255,0.03); }
.tool-btn--minor:hover { color: rgba(255,255,255,0.55); }

/* ===== Chat panel ===== */

.chat {
  flex: 1;
  background: var(--surface);
  border-radius: 22px;
  border: 1px solid var(--border);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  box-shadow:
    0 24px 80px rgba(0,0,0,0.55),
    inset 0 1px 0 rgba(255,255,255,0.03);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 420px;
}

.chat.is-hidden { display: none; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ===== Message bubbles ===== */

.msg {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  animation: fadeUp 0.4s ease forwards;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg--user { flex-direction: row-reverse; }

.avatar {
  width: 30px; height: 30px;
  flex-shrink: 0;
  margin-top: 3px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 35%, #ffd1f0 0%, #f9a8d4 25%, #c084fc 70%, #818cf8 100%);
  box-shadow:
    0 2px 10px rgba(192,132,252,0.35),
    inset 0 1px 4px rgba(255,255,255,0.3);
}

.bubble {
  max-width: 78%;
  padding: 11px 15px;
  font-size: 1rem;
  line-height: 1.65;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.bubble--assistant {
  background: var(--surface-warm);
  color: var(--text-soft);
  border: 1px solid rgba(192,132,252,0.09);
  border-radius: 4px 16px 16px 16px;
  font-family: var(--serif);
}

.bubble--user {
  background: var(--user-grad);
  color: #f5f0ff;
  border-radius: 16px 4px 16px 16px;
  font-family: var(--sans);
  font-size: 0.92rem;
  box-shadow: 0 4px 16px rgba(109,40,217,0.3);
}

.bubble p + p { margin-top: 0.6em; }

/* ===== Typing dots ===== */

.typing {
  display: flex;
  gap: 5px;
  padding: 4px 2px;
  align-items: center;
}
.typing span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: bounce 1.4s ease-in-out infinite;
}
.typing span:nth-child(2) { animation-delay: 0.18s; }
.typing span:nth-child(3) { animation-delay: 0.36s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.35; }
  40%           { transform: scale(1.1); opacity: 1; }
}

/* ===== Composer ===== */

.composer {
  padding: 11px 12px;
  border-top: 1px solid rgba(192,132,252,0.07);
  background: rgba(0,0,0,0.12);
  display: flex;
  gap: 9px;
  align-items: flex-end;
}

#input {
  flex: 1;
  resize: none;
  background: rgba(255,255,255,0.045);
  border: 1px solid rgba(192,132,252,0.16);
  border-radius: 14px;
  padding: 11px 14px;
  color: var(--text);
  font-family: var(--serif);
  font-size: 1rem;
  line-height: 1.55;
  max-height: 130px;
  overflow-y: auto;
  transition: border-color 0.2s;
}
#input::placeholder { color: rgba(192,132,252,0.35); }
#input:focus { outline: none; border-color: rgba(192,132,252,0.45); }

#sendBtn {
  width: 40px; height: 40px;
  flex-shrink: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, #c084fc, #818cf8);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 3px 14px rgba(192,132,252,0.4);
  transition: transform 0.15s, box-shadow 0.2s, opacity 0.2s;
}
#sendBtn:hover:not(:disabled) { transform: scale(1.05); }
#sendBtn:active:not(:disabled) { transform: scale(0.95); }
#sendBtn:disabled {
  background: rgba(192,132,252,0.12);
  color: rgba(192,132,252,0.35);
  cursor: not-allowed;
  box-shadow: none;
}

/* ===== Initial loader ===== */

.loader {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
  padding: 32px 0;
}
.loader span {
  width: 8px; height: 8px;
  background: var(--accent);
  border-radius: 50%;
  animation: bounce 1.4s ease-in-out infinite;
}
.loader span:nth-child(2) { animation-delay: 0.18s; }
.loader span:nth-child(3) { animation-delay: 0.36s; }

/* ===== Breathing overlay ===== */

.breath {
  display: none;
  background: var(--surface);
  border-radius: 22px;
  border: 1px solid var(--border);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  padding: 50px 24px 38px;
  text-align: center;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 420px;
}
.breath.is-active { display: flex; }

.breath-circle {
  width: 120px; height: 120px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(192,132,252,0.3) 0%, transparent 70%);
  border: 1.5px solid rgba(192,132,252,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 32px;
  animation: breathPulse 2s ease-in-out infinite;
}
.breath-inner {
  width: 60px; height: 60px;
  border-radius: 50%;
  background: rgba(192,132,252,0.25);
}

@keyframes breathPulse {
  0%, 100% { transform: scale(1); opacity: 0.65; }
  50%      { transform: scale(1.18); opacity: 1; }
}

.breath-phase {
  font-family: var(--serif);
  font-size: 1.6rem;
  letter-spacing: 0.06em;
  color: var(--text);
  margin-bottom: 8px;
  min-height: 1.6em;
}

.breath-help {
  font-family: var(--sans);
  font-size: 0.78rem;
  color: rgba(192,132,252,0.5);
  margin-bottom: 32px;
}

.breath-stop {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 18px;
  padding: 8px 22px;
  color: rgba(255,255,255,0.55);
  font-family: var(--sans);
  font-size: 0.78rem;
  cursor: pointer;
  transition: background 0.2s;
}
.breath-stop:hover { background: rgba(255,255,255,0.08); }

/* ===== Footer ===== */

.footer-note {
  text-align: center;
  font-family: var(--sans);
  font-size: 0.7rem;
  color: rgba(255,255,255,0.18);
  line-height: 1.5;
  max-width: 380px;
  margin: 0 auto;
}

/* ===== Confirm dialog ===== */

.dialog {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
  animation: fadeIn 0.2s ease;
}
.dialog.is-open { display: flex; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.dialog-box {
  background: rgba(20, 8, 30, 0.95);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 24px 22px 18px;
  max-width: 380px;
  width: 100%;
  box-shadow: 0 30px 80px rgba(0,0,0,0.7);
}

.dialog-text {
  font-family: var(--serif);
  color: var(--text);
  font-size: 1.05rem;
  margin-bottom: 22px;
  line-height: 1.5;
}
.dialog-sub {
  display: block;
  font-size: 0.82rem;
  color: rgba(192,132,252,0.5);
  margin-top: 6px;
  font-style: italic;
}

.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; }

.dialog-btn {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 14px;
  padding: 9px 18px;
  color: rgba(255,255,255,0.7);
  font-family: var(--sans);
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.2s;
}
.dialog-btn:hover { background: rgba(255,255,255,0.1); color: rgba(255,255,255,0.9); }
.dialog-btn--danger {
  background: rgba(220,38,38,0.15);
  border-color: rgba(220,38,38,0.3);
  color: #fca5a5;
}
.dialog-btn--danger:hover {
  background: rgba(220,38,38,0.25);
  color: #fecaca;
}

/* ===== Mobile ===== */

@media (max-width: 480px) {
  .app { padding: 16px 10px 10px; gap: 10px; }
  .title { font-size: 1.5rem; }
  .chat { min-height: 360px; }
  .bubble { font-size: 0.95rem; max-width: 84%; }
  .bubble--user { font-size: 0.88rem; }
}

/* ===== Reduced motion ===== */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
