:root {
  --night: #06080d;
  --night-2: #0c1220;
  --ecto: #9dffb0;
  --ecto-dim: rgba(157, 255, 176, 0.35);
  --mist: #dfe9ff;
  --mist-dim: #8a97b3;
  --pumpkin: #ff9a4d;
  --ghost-bubble: rgba(205, 225, 255, 0.07);
  --ghost-edge: rgba(205, 225, 255, 0.16);
  --me-bubble: rgba(255, 154, 77, 0.13);
  --me-edge: rgba(255, 154, 77, 0.32);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: radial-gradient(ellipse at 50% -10%, #142038 0%, var(--night-2) 35%, var(--night) 75%);
  background-color: var(--night);
  color: var(--mist);
  font: 16px/1.45 "Nunito", system-ui, sans-serif;
  overflow: hidden;
}

/* Drifting fog behind everything */
.fog { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.fog-layer {
  position: absolute;
  inset: -40% -60%;
  background:
    radial-gradient(closest-side at 30% 60%, rgba(180, 200, 255, 0.07), transparent),
    radial-gradient(closest-side at 70% 40%, rgba(157, 255, 176, 0.05), transparent),
    radial-gradient(closest-side at 50% 90%, rgba(180, 200, 255, 0.06), transparent);
  filter: blur(30px);
  animation: drift 38s linear infinite alternate;
}
.fog-layer.b { animation-duration: 55s; animation-direction: alternate-reverse; opacity: 0.8; }
@keyframes drift {
  from { transform: translateX(-12%) translateY(2%); }
  to   { transform: translateX(12%) translateY(-3%); }
}

.room {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 640px;
  margin: 0 auto;
  padding: 0 16px;
  padding-bottom: env(safe-area-inset-bottom);
}

/* Header */
.ghost-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 20px 0 14px;
  border-bottom: 1px solid var(--ghost-edge);
}
.avatar-wrap { flex: none; animation: float 5s ease-in-out infinite; }
.avatar {
  display: block;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  opacity: 0.9;
  box-shadow: 0 0 18px var(--ecto-dim), 0 0 2px var(--ecto);
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}
.who { min-width: 0; }
.name {
  margin: 0;
  font: 400 clamp(26px, 7vw, 34px)/1.05 "Creepster", "Nunito", cursive;
  letter-spacing: 0.04em;
  color: var(--ecto);
  text-shadow: 0 0 12px var(--ecto-dim);
  animation: flicker 9s infinite;
}
@keyframes flicker {
  0%, 92%, 100% { opacity: 1; }
  93% { opacity: 0.35; }
  94% { opacity: 1; }
  96% { opacity: 0.55; }
  97% { opacity: 1; }
}
.status {
  margin: 4px 0 0;
  font-size: 14px;
  color: var(--mist-dim);
  display: flex;
  align-items: center;
  gap: 6px;
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ecto);
  box-shadow: 0 0 8px var(--ecto);
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.35; } }

/* Conversation */
.log {
  flex: 1;
  overflow-y: auto;
  padding: 18px 0 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  scrollbar-width: thin;
  scrollbar-color: var(--ghost-edge) transparent;
}
.bubble {
  max-width: 82%;
  padding: 9px 14px;
  border-radius: 18px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  animation: appear 0.45s ease-out both;
}
.bubble.ghost {
  align-self: flex-start;
  background: var(--ghost-bubble);
  border: 1px solid var(--ghost-edge);
  border-bottom-left-radius: 6px;
  text-shadow: 0 0 8px rgba(205, 225, 255, 0.25);
}
.bubble.me {
  align-self: flex-end;
  background: var(--me-bubble);
  border: 1px solid var(--me-edge);
  border-bottom-right-radius: 6px;
}
.bubble.me + .bubble.ghost,
.bubble.ghost + .bubble.me { margin-top: 10px; }
@keyframes appear {
  from { opacity: 0; filter: blur(6px); transform: translateY(4px); }
  to   { opacity: 1; filter: blur(0); transform: none; }
}
.note {
  align-self: center;
  margin: 8px 0;
  font-size: 13px;
  color: var(--mist-dim);
  font-style: italic;
}

.typing {
  margin: 0 0 6px;
  font-size: 13px;
  color: var(--mist-dim);
}
.dots i {
  display: inline-block;
  width: 4px;
  height: 4px;
  margin-left: 3px;
  border-radius: 50%;
  background: var(--mist-dim);
  animation: blink 1.2s infinite;
}
.dots i:nth-child(2) { animation-delay: 0.2s; }
.dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.2; } 40% { opacity: 1; } }

/* Composer */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 0 16px;
}
.composer textarea {
  flex: 1;
  min-width: 0;
  height: 44px;
  max-height: 140px;
  padding: 10px 16px;
  line-height: 22px;
  overflow-y: hidden;
  border-radius: 22px;
  border: 1px solid var(--ghost-edge);
  background: rgba(12, 18, 32, 0.85);
  color: var(--mist);
  font: inherit;
  resize: none;
  outline: none;
}
.composer textarea::placeholder { color: var(--mist-dim); }
.composer textarea:focus { border-color: var(--ecto-dim); box-shadow: 0 0 0 3px rgba(157, 255, 176, 0.08); }
.composer button {
  flex: none;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--ecto);
  color: var(--night);
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 0 14px var(--ecto-dim);
}
.composer button:disabled { opacity: 0.35; cursor: default; box-shadow: none; }
.composer button:focus-visible { outline: 2px solid var(--mist); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  .fog-layer, .avatar-wrap, .name, .dot, .dots i { animation: none; }
  .bubble { animation-duration: 0.01s; }
}
