:root {
  --bg: #05060f;
  --panel: rgba(12, 14, 28, 0.72);
  --ink: #ececf1;
  --muted: #9aa3c2;
  --user: rgba(40, 48, 90, 0.92);
  --line: rgba(140, 170, 255, 0.14);
  --accent: #5ec8ff;
  --cyan: #3de0ff;
  --violet: #7a5cff;
  --font: "Avenir Next", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

/* —— space backdrop —— */
.cosmos {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
  background:
    radial-gradient(1200px 700px at 50% -10%, rgba(70, 40, 140, 0.35), transparent 60%),
    radial-gradient(900px 600px at 100% 80%, rgba(20, 60, 140, 0.28), transparent 55%),
    radial-gradient(700px 500px at 0% 70%, rgba(0, 140, 160, 0.18), transparent 50%),
    linear-gradient(180deg, #05060f 0%, #080a18 45%, #05060f 100%);
}

.nebula {
  position: absolute;
  border-radius: 50%;
  filter: blur(50px);
  opacity: 0.55;
  animation: drift 18s ease-in-out infinite alternate;
}

.nebula-a {
  width: 55vw;
  height: 55vw;
  top: -12%;
  right: -8%;
  background: radial-gradient(circle, rgba(90, 60, 220, 0.45), transparent 70%);
}

.nebula-b {
  width: 48vw;
  height: 48vw;
  bottom: 5%;
  left: -12%;
  background: radial-gradient(circle, rgba(30, 160, 220, 0.35), transparent 70%);
  animation-delay: -6s;
}

.nebula-c {
  width: 36vw;
  height: 36vw;
  top: 38%;
  left: 40%;
  background: radial-gradient(circle, rgba(255, 80, 140, 0.12), transparent 70%);
  animation-delay: -11s;
}

.stars {
  position: absolute;
  inset: 0;
  background-repeat: repeat;
}

.stars-a {
  background-image: radial-gradient(1.5px 1.5px at 20px 30px, rgba(255,255,255,0.9), transparent),
    radial-gradient(1px 1px at 80px 120px, rgba(255,255,255,0.7), transparent),
    radial-gradient(1.5px 1.5px at 160px 70px, rgba(180,220,255,0.85), transparent),
    radial-gradient(1px 1px at 240px 180px, rgba(255,255,255,0.6), transparent),
    radial-gradient(1px 1px at 300px 40px, rgba(255,255,255,0.75), transparent);
  background-size: 340px 220px;
  opacity: 0.7;
  animation: twinkle 5s ease-in-out infinite alternate;
}

.stars-b {
  background-image: radial-gradient(1px 1px at 50px 90px, rgba(255,255,255,0.8), transparent),
    radial-gradient(2px 2px at 140px 40px, rgba(160,210,255,0.9), transparent),
    radial-gradient(1px 1px at 210px 160px, rgba(255,255,255,0.55), transparent),
    radial-gradient(1.5px 1.5px at 280px 100px, rgba(255,255,255,0.7), transparent);
  background-size: 300px 200px;
  opacity: 0.55;
  animation: twinkle 7s ease-in-out infinite alternate-reverse;
}

.stars-c {
  background-image: radial-gradient(1px 1px at 30px 60px, rgba(255,255,255,0.5), transparent),
    radial-gradient(1px 1px at 110px 150px, rgba(200,180,255,0.65), transparent),
    radial-gradient(1.5px 1.5px at 190px 20px, rgba(255,255,255,0.8), transparent);
  background-size: 260px 180px;
  opacity: 0.4;
  animation: drift 40s linear infinite;
}

.shoot {
  position: absolute;
  top: 18%;
  left: -10%;
  width: 90px;
  height: 1.5px;
  background: linear-gradient(90deg, transparent, rgba(180, 230, 255, 0.95), transparent);
  border-radius: 2px;
  opacity: 0;
  transform: rotate(-18deg);
  animation: shoot 9s ease-in-out infinite;
}

.page {
  position: relative;
  z-index: 1;
  width: min(720px, 100%);
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 20px 16px 18px;
}

.brand {
  text-align: center;
  padding: 4px 0 8px;
}

.brand h1 {
  margin: 0;
  font-size: clamp(2rem, 6vw, 2.75rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  color: #fff;
  text-shadow:
    0 0 18px rgba(94, 200, 255, 0.45),
    0 0 40px rgba(122, 92, 255, 0.25);
}

.mascot-wrap {
  position: relative;
  display: flex;
  justify-content: center;
  padding: 4px 0 14px;
  transition: filter 0.4s ease;
}

.mascot-glow {
  position: absolute;
  top: 55%;
  left: 50%;
  width: min(260px, 55vw);
  height: min(140px, 30vw);
  transform: translate(-50%, -40%);
  background: radial-gradient(ellipse, rgba(61, 224, 255, 0.28), transparent 70%);
  filter: blur(8px);
  pointer-events: none;
  animation: pulse 4s ease-in-out infinite;
  transition: background 0.45s ease, opacity 0.45s ease;
}

.mascot-stage {
  position: relative;
  z-index: 1;
  width: min(300px, 62vw);
  animation: float 5.5s ease-in-out infinite;
  transform-origin: 50% 70%;
}

.mascot {
  width: 100%;
  height: auto;
  display: block;
  object-fit: contain;
  filter: drop-shadow(0 18px 32px rgba(0, 0, 0, 0.55)) drop-shadow(0 0 22px rgba(61, 224, 255, 0.18));
  transition: filter 0.4s ease;
}

.mascot-wrap[data-mood="idle"] .mascot-stage {
  animation: float 5.5s ease-in-out infinite;
}

.mascot-wrap[data-mood="thinking"] .mascot-stage {
  animation: think 1.1s ease-in-out infinite;
}

.mascot-wrap[data-mood="thinking"] .mascot {
  filter: drop-shadow(0 14px 28px rgba(0, 0, 0, 0.5)) drop-shadow(0 0 28px rgba(61, 224, 255, 0.45));
}

.mascot-wrap[data-mood="thinking"] .mascot-glow {
  background: radial-gradient(ellipse, rgba(61, 224, 255, 0.5), transparent 70%);
  animation: pulse 1.2s ease-in-out infinite;
}

.mascot-wrap[data-mood="reply"] .mascot-stage {
  animation: speak 2.4s ease-in-out infinite;
}

.mascot-wrap[data-mood="reply"] .mascot {
  filter: drop-shadow(0 16px 30px rgba(0, 0, 0, 0.5)) drop-shadow(0 0 34px rgba(122, 92, 255, 0.4));
}

.mascot-wrap[data-mood="reply"] .mascot-glow {
  background: radial-gradient(ellipse, rgba(122, 92, 255, 0.42), transparent 70%);
  animation: pulse 2s ease-in-out infinite;
}

.sound-btn {
  position: absolute;
  right: max(0px, calc(50% - min(150px, 31vw) - 28px));
  bottom: 18px;
  z-index: 3;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid rgba(140, 170, 255, 0.12);
  border-radius: 50%;
  background: rgba(8, 10, 22, 0.35);
  color: rgba(154, 163, 194, 0.45);
  cursor: pointer;
  display: grid;
  place-items: center;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: color 0.25s ease, border-color 0.25s ease, background 0.25s ease;
}

.sound-btn:hover {
  color: rgba(94, 200, 255, 0.7);
  border-color: rgba(94, 200, 255, 0.22);
}

.sound-btn .ring { opacity: 0; }
.sound-btn .mute { opacity: 0.85; }

.sound-btn[aria-pressed="true"] {
  color: rgba(94, 200, 255, 0.55);
  border-color: rgba(94, 200, 255, 0.18);
  background: rgba(12, 18, 40, 0.4);
}

.sound-btn[aria-pressed="true"] .ring { opacity: 0.7; }
.sound-btn[aria-pressed="true"] .mute { opacity: 0; }

.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-radius: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow:
    0 0 0 1px rgba(94, 200, 255, 0.06) inset,
    0 20px 50px -24px rgba(0, 20, 60, 0.85),
    0 0 60px -20px rgba(90, 60, 200, 0.35);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  overflow: hidden;
}

.chat {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.row {
  display: flex;
  width: 100%;
}

.row.bot { justify-content: flex-start; }
.row.user { justify-content: flex-end; }

.bubble {
  max-width: min(85%, 520px);
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
  animation: fade 0.25s ease;
}

.row.bot .bubble {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(140, 170, 255, 0.16);
  border-bottom-left-radius: 6px;
  color: var(--ink);
}

.row.user .bubble {
  background: linear-gradient(135deg, rgba(50, 70, 160, 0.95), rgba(30, 40, 100, 0.95));
  border: 1px solid rgba(120, 160, 255, 0.25);
  border-bottom-right-radius: 6px;
  color: #fff;
}

.typing .bubble {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  min-height: 42px;
}

.dots {
  display: inline-flex;
  gap: 4px;
}

.dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: bounce 1.05s infinite ease-in-out;
}

.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }

.cursor {
  display: inline-block;
  width: 7px;
  height: 1.05em;
  margin-left: 2px;
  vertical-align: text-bottom;
  background: var(--cyan);
  animation: blink 0.9s steps(1) infinite;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: end;
  padding: 12px 12px 14px;
  border-top: 1px solid var(--line);
  background: rgba(8, 10, 22, 0.75);
}

textarea {
  width: 100%;
  max-height: 140px;
  min-height: 44px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(16, 20, 40, 0.9);
  color: var(--ink);
  padding: 12px 14px;
  font: inherit;
  font-size: 15px;
  line-height: 1.4;
}

textarea:focus {
  outline: 1px solid rgba(94, 200, 255, 0.55);
  box-shadow: 0 0 0 3px rgba(94, 200, 255, 0.12);
}

.send {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(145deg, #e8f6ff, #9ad8ff);
  color: #0a1220;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 0 18px rgba(94, 200, 255, 0.35);
}

.send:disabled {
  opacity: 0.4;
  cursor: wait;
  box-shadow: none;
}

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.35; }
  40% { transform: translateY(-4px); opacity: 1; }
}

@keyframes blink {
  0%, 45% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

@keyframes fade {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

@keyframes drift {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(-3%, 4%) scale(1.06); }
}

@keyframes twinkle {
  from { opacity: 0.35; }
  to { opacity: 0.85; }
}

@keyframes shoot {
  0%, 78% { opacity: 0; transform: translateX(0) rotate(-18deg); }
  80% { opacity: 1; }
  92% { opacity: 0; transform: translateX(110vw) rotate(-18deg); }
  100% { opacity: 0; transform: translateX(110vw) rotate(-18deg); }
}

@keyframes float {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-8px) rotate(-1.2deg); }
}

@keyframes think {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-6px) scale(1.03); }
}

@keyframes speak {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  25% { transform: translateY(-5px) rotate(1.5deg); }
  75% { transform: translateY(-3px) rotate(-1.2deg); }
}

@keyframes pulse {
  0%, 100% { opacity: 0.55; transform: translate(-50%, -40%) scale(1); }
  50% { opacity: 0.9; transform: translate(-50%, -40%) scale(1.08); }
}

@media (max-width: 520px) {
  .page { padding: 14px 10px 12px; }
  .mascot-stage { width: min(220px, 62vw); }
  .bubble { max-width: 92%; font-size: 14px; }
  .sound-btn {
    right: max(0px, calc(50% - min(110px, 31vw) - 24px));
    bottom: 12px;
    width: 26px;
    height: 26px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .nebula, .stars, .shoot, .mascot-stage, .mascot-glow { animation: none !important; }
}
