:root {
  --bg: #07090f;
  --sidebar: rgba(12, 15, 24, 0.72);
  --surface: rgba(22, 26, 38, 0.65);
  --surface-solid: #161a26;
  --border: rgba(120, 140, 200, 0.18);
  --text: #eef1f8;
  --muted: #9aa3b8;
  --accent: #7b9dff;
  --accent-2: #5ef0d0;
  --accent-3: #c084fc;
  --user-bg: rgba(40, 60, 120, 0.45);
  --danger: #f07178;
  --ok: #7fd99a;
  --radius: 18px;
  --font: "Inter", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --glow: 0 0 40px rgba(123, 157, 255, 0.25);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  overflow: hidden;
  perspective: 1200px;
}

/* ===== Living 3D stage ===== */
.stage {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  transform-style: preserve-3d;
}

.stage-gradient {
  position: absolute;
  inset: -20%;
  background:
    radial-gradient(ellipse 50% 40% at 20% 30%, rgba(123, 157, 255, 0.35), transparent 55%),
    radial-gradient(ellipse 45% 35% at 80% 20%, rgba(192, 132, 252, 0.28), transparent 50%),
    radial-gradient(ellipse 40% 40% at 60% 80%, rgba(94, 240, 208, 0.2), transparent 55%),
    radial-gradient(ellipse 60% 50% at 40% 60%, rgba(30, 40, 90, 0.5), transparent 70%);
  animation: aurora 18s ease-in-out infinite alternate;
  filter: blur(8px);
}

@keyframes aurora {
  0% { transform: translate3d(0, 0, 0) scale(1) rotate(0deg); }
  50% { transform: translate3d(3%, -2%, 40px) scale(1.08) rotate(2deg); }
  100% { transform: translate3d(-2%, 3%, 20px) scale(1.05) rotate(-1.5deg); }
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(40px);
  opacity: 0.55;
  mix-blend-mode: screen;
  animation: floatOrb 14s ease-in-out infinite;
  transform-style: preserve-3d;
}
.orb-a {
  width: 280px; height: 280px;
  left: 8%; top: 18%;
  background: radial-gradient(circle, rgba(123, 157, 255, 0.7), transparent 70%);
  animation-duration: 16s;
}
.orb-b {
  width: 220px; height: 220px;
  right: 12%; top: 28%;
  background: radial-gradient(circle, rgba(192, 132, 252, 0.65), transparent 70%);
  animation-duration: 20s;
  animation-delay: -4s;
}
.orb-c {
  width: 320px; height: 320px;
  left: 40%; bottom: 5%;
  background: radial-gradient(circle, rgba(94, 240, 208, 0.45), transparent 70%);
  animation-duration: 22s;
  animation-delay: -8s;
}

@keyframes floatOrb {
  0%, 100% { transform: translate3d(0, 0, 0) scale(1); }
  33% { transform: translate3d(30px, -40px, 60px) scale(1.12); }
  66% { transform: translate3d(-25px, 20px, 30px) scale(0.94); }
}

.grid-floor {
  position: absolute;
  left: -10%; right: -10%;
  bottom: -30%;
  height: 70%;
  background-image:
    linear-gradient(rgba(123, 157, 255, 0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(123, 157, 255, 0.07) 1px, transparent 1px);
  background-size: 48px 48px;
  transform: perspective(500px) rotateX(68deg) translateZ(-80px);
  mask-image: linear-gradient(to top, rgba(0,0,0,0.55), transparent 75%);
  animation: gridDrift 30s linear infinite;
}

@keyframes gridDrift {
  from { background-position: 0 0; }
  to { background-position: 48px 48px; }
}

.particles {
  position: absolute;
  inset: 0;
}

.particle {
  position: absolute;
  width: 3px; height: 3px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.7);
  box-shadow: 0 0 8px rgba(123, 157, 255, 0.8);
  animation: rise linear infinite;
}

@keyframes rise {
  0% { transform: translate3d(0, 100vh, 0) scale(0.4); opacity: 0; }
  10% { opacity: 0.8; }
  90% { opacity: 0.5; }
  100% { transform: translate3d(20px, -10vh, 80px) scale(1); opacity: 0; }
}

/* ===== Shell ===== */
.shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100vh;
  height: 100dvh;
  transform-style: preserve-3d;
}

.sidebar {
  background: var(--sidebar);
  backdrop-filter: blur(24px) saturate(1.4);
  -webkit-backdrop-filter: blur(24px) saturate(1.4);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 0.85rem;
  gap: 0.75rem;
  overflow: hidden;
  transform: translateZ(20px);
  box-shadow: 8px 0 40px rgba(0, 0, 0, 0.35);
  animation: slideInLeft 0.7s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes slideInLeft {
  from { opacity: 0; transform: translate3d(-24px, 0, 0); }
  to { opacity: 1; transform: translate3d(0, 0, 20px); }
}

.sidebar-top { display: flex; flex-direction: column; gap: 0.75rem; }

.logo {
  display: flex; align-items: center; gap: 0.65rem;
  padding: 0.35rem 0.4rem;
}
.logo-mark {
  width: 36px; height: 36px; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center;
  font-weight: 700; color: #0a0c12; font-size: 1rem;
  box-shadow: var(--glow);
  animation: pulseGlow 3.5s ease-in-out infinite;
  transform: rotateX(8deg) rotateY(-8deg);
}
@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 16px rgba(123, 157, 255, 0.35); transform: rotateX(8deg) rotateY(-8deg) scale(1); }
  50% { box-shadow: 0 0 28px rgba(94, 240, 208, 0.5); transform: rotateX(4deg) rotateY(6deg) scale(1.04); }
}
.logo strong { display: block; font-size: 0.92rem; letter-spacing: 0.02em; }
.logo span { font-size: 0.72rem; color: var(--muted); }

.btn-new {
  display: flex; align-items: center; justify-content: center; gap: 0.45rem;
  width: 100%;
  padding: 0.65rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: linear-gradient(145deg, rgba(40, 50, 80, 0.6), rgba(20, 24, 36, 0.8));
  color: var(--text);
  font: inherit; font-weight: 600; font-size: 0.9rem;
  cursor: pointer;
  transition: transform 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
  transform-style: preserve-3d;
}
.btn-new:hover {
  border-color: var(--accent);
  transform: translateY(-2px) translateZ(8px);
  box-shadow: 0 8px 24px rgba(123, 157, 255, 0.2);
}

.session-list {
  flex: 1; overflow-y: auto;
  display: flex; flex-direction: column; gap: 0.25rem;
}
.session-item {
  text-align: left;
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  cursor: pointer;
  font: inherit; font-size: 0.85rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background 0.2s, color 0.2s, transform 0.2s;
}
.session-item:hover, .session-item.active {
  background: rgba(123, 157, 255, 0.12);
  color: var(--text);
  transform: translateX(4px);
}

.sidebar-bottom {
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
  display: flex; flex-direction: column; gap: 0.4rem;
}
.status-line { font-size: 0.75rem; color: var(--muted); }
.status-line.ok { color: var(--ok); }
.status-line.err { color: var(--danger); }
.linkish {
  background: none; border: none; color: var(--accent);
  font: inherit; font-size: 0.85rem; cursor: pointer; text-align: left; padding: 0;
}

.chat-pane {
  display: flex; flex-direction: column;
  min-width: 0; height: 100%;
  animation: fadeInPane 0.8s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes fadeInPane {
  from { opacity: 0; transform: translate3d(0, 12px, -20px); }
  to { opacity: 1; transform: translate3d(0, 0, 0); }
}

.chat-header {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: rgba(10, 12, 20, 0.4);
  backdrop-filter: blur(16px);
}
.chat-header h1 {
  margin: 0; font-size: 1rem; font-weight: 600; flex: 1;
  letter-spacing: 0.03em;
}
.header-badge {
  font-size: 0.72rem;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  background: rgba(20, 24, 36, 0.6);
  backdrop-filter: blur(8px);
}
.icon-btn {
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); border-radius: 10px; padding: 0.35rem 0.55rem;
  cursor: pointer; font-size: 1rem;
}
.mobile-only { display: none; }

.messages {
  flex: 1; overflow-y: auto;
  padding: 1.25rem 1rem 1rem;
  display: flex; flex-direction: column; gap: 1.1rem;
  scroll-behavior: smooth;
  transform-style: preserve-3d;
}

.welcome {
  max-width: 640px; margin: 6vh auto 0; text-align: center; padding: 1rem;
  animation: welcomeIn 1s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes welcomeIn {
  from { opacity: 0; transform: translate3d(0, 30px, -60px) rotateX(12deg); }
  to { opacity: 1; transform: translate3d(0, 0, 0) rotateX(0); }
}
.welcome-icon {
  width: 64px; height: 64px; margin: 0 auto 1.1rem;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2), var(--accent-3));
  background-size: 200% 200%;
  display: grid; place-items: center;
  font-weight: 700; font-size: 1.5rem; color: #0a0c12;
  box-shadow: var(--glow);
  animation: iconSpin 8s ease-in-out infinite, gradientShift 6s ease infinite;
  transform-style: preserve-3d;
}
@keyframes iconSpin {
  0%, 100% { transform: rotateY(-12deg) rotateX(8deg); }
  50% { transform: rotateY(12deg) rotateX(-4deg) scale(1.05); }
}
@keyframes gradientShift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}
.welcome h2 { margin: 0 0 0.5rem; font-size: 1.4rem; font-weight: 650; }
.welcome p { color: var(--muted); margin: 0 0 1.35rem; }

.suggestions {
  display: grid; gap: 0.55rem;
  grid-template-columns: 1fr 1fr;
  text-align: left;
}
.suggestions button {
  background: rgba(22, 26, 38, 0.7);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 14px;
  padding: 0.8rem 0.95rem;
  font: inherit; font-size: 0.85rem;
  cursor: pointer; text-align: left;
  backdrop-filter: blur(12px);
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1), border-color 0.25s, box-shadow 0.3s;
  transform: translateZ(0);
}
.suggestions button:hover {
  border-color: rgba(123, 157, 255, 0.5);
  transform: translateY(-4px) translateZ(16px) scale(1.02);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35), 0 0 20px rgba(123, 157, 255, 0.15);
}

.msg {
  display: flex; gap: 0.75rem;
  max-width: 820px; width: 100%;
  margin: 0 auto;
  transform-style: preserve-3d;
  animation: msgIn 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
}
@keyframes msgIn {
  from {
    opacity: 0;
    transform: translate3d(0, 24px, -40px) rotateX(8deg);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0) rotateX(0);
  }
}
.msg .avatar {
  width: 34px; height: 34px; border-radius: 11px;
  flex-shrink: 0;
  display: grid; place-items: center;
  font-size: 0.72rem; font-weight: 700;
  transform: translateZ(12px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}
.msg.user .avatar {
  background: linear-gradient(145deg, #3a5080, #1e2a4a);
  color: var(--accent);
}
.msg.assistant .avatar {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0a0c12;
  animation: pulseGlow 4s ease-in-out infinite;
}
.msg .bubble {
  flex: 1; min-width: 0;
  padding: 0.15rem 0;
}
.msg.user .bubble {
  background: linear-gradient(145deg, rgba(50, 70, 130, 0.5), rgba(30, 40, 80, 0.55));
  border: 1px solid rgba(123, 157, 255, 0.2);
  border-radius: 16px 16px 4px 16px;
  padding: 0.8rem 1.05rem;
  backdrop-filter: blur(12px);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.25);
  transform: translateZ(8px);
}
.msg.assistant .bubble {
  transform: translateZ(4px);
}
.msg .meta {
  font-size: 0.7rem; color: var(--muted); margin-top: 0.4rem;
  opacity: 0.85;
}
.msg .content {
  white-space: pre-wrap; word-break: break-word;
  font-size: 0.95rem;
}
.msg .content strong { font-weight: 600; }
.msg.assistant .content code {
  font-family: var(--mono); font-size: 0.85em;
  background: rgba(30, 36, 52, 0.9); padding: 0.12rem 0.35rem; border-radius: 5px;
  border: 1px solid var(--border);
}

.typing {
  display: flex; gap: 0.4rem; padding: 0.55rem 0;
}
.typing span {
  width: 8px; height: 8px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  animation: bounce3d 1.15s infinite ease-in-out;
  box-shadow: 0 0 10px rgba(123, 157, 255, 0.5);
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce3d {
  0%, 80%, 100% { transform: translateY(0) scale(0.85); opacity: 0.45; }
  40% { transform: translateY(-8px) scale(1.15); opacity: 1; }
}

.composer-wrap {
  padding: 0.5rem 1rem 1.1rem;
  max-width: 820px; width: 100%; margin: 0 auto;
  animation: composerIn 0.9s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes composerIn {
  from { opacity: 0; transform: translate3d(0, 20px, 0); }
  to { opacity: 1; transform: translate3d(0, 0, 0); }
}
.composer {
  display: flex; align-items: flex-end; gap: 0.5rem;
  background: rgba(18, 22, 34, 0.75);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.55rem 0.65rem;
  backdrop-filter: blur(20px) saturate(1.3);
  box-shadow:
    0 12px 40px rgba(0, 0, 0, 0.4),
    0 0 0 1px rgba(255, 255, 255, 0.03) inset,
    0 0 30px rgba(123, 157, 255, 0.08);
  transition: border-color 0.3s, box-shadow 0.3s, transform 0.3s;
  transform: translateZ(10px);
}
.composer:focus-within {
  border-color: rgba(123, 157, 255, 0.45);
  box-shadow:
    0 16px 48px rgba(0, 0, 0, 0.45),
    0 0 40px rgba(123, 157, 255, 0.18);
  transform: translateY(-2px) translateZ(16px);
}
.composer textarea {
  flex: 1; border: none; background: transparent;
  color: var(--text); font: inherit; font-size: 0.95rem;
  resize: none; max-height: 160px; outline: none;
  padding: 0.35rem 0.25rem; line-height: 1.45;
}
.composer .send {
  width: 38px; height: 38px; border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0a0c12;
  display: grid; place-items: center; cursor: pointer; flex-shrink: 0;
  transition: transform 0.25s, box-shadow 0.25s;
  box-shadow: 0 4px 16px rgba(123, 157, 255, 0.35);
}
.composer .send:hover:not(:disabled) {
  transform: scale(1.08) rotateZ(-8deg);
  box-shadow: 0 6px 24px rgba(94, 240, 208, 0.4);
}
.composer .send:disabled { opacity: 0.35; cursor: not-allowed; }
.disclaimer {
  text-align: center; font-size: 0.7rem; color: var(--muted);
  margin: 0.55rem 0 0;
  opacity: 0.85;
}

.modal {
  position: fixed; inset: 0;
  background: rgba(4, 6, 12, 0.65);
  backdrop-filter: blur(10px);
  display: grid; place-items: center;
  z-index: 50; padding: 1rem;
  animation: modalBg 0.3s ease;
}
@keyframes modalBg {
  from { opacity: 0; }
  to { opacity: 1; }
}
.modal.hidden { display: none; }
.modal-card {
  background: linear-gradient(160deg, rgba(28, 34, 52, 0.95), rgba(14, 18, 28, 0.98));
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 1.45rem;
  width: min(420px, 100%);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55), var(--glow);
  transform: translateZ(40px);
  animation: modalCard 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes modalCard {
  from { opacity: 0; transform: translate3d(0, 24px, -40px) scale(0.96); }
  to { opacity: 1; transform: translate3d(0, 0, 40px) scale(1); }
}
.modal-card h2 { margin: 0 0 1rem; font-size: 1.1rem; }
.modal-card label { display: block; margin-bottom: 0.85rem; }
.modal-card label span {
  display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.3rem;
}
.modal-card input {
  width: 100%; padding: 0.6rem 0.75rem;
  border-radius: 10px; border: 1px solid var(--border);
  background: rgba(8, 10, 16, 0.8); color: var(--text); font: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.modal-card input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(123, 157, 255, 0.2);
}
.modal-card .hint { font-size: 0.8rem; color: var(--muted); }
.modal-card code {
  font-family: var(--mono); font-size: 0.85em;
  background: rgba(0, 0, 0, 0.35); padding: 0.1rem 0.3rem; border-radius: 4px;
}
.modal-actions { display: flex; gap: 0.5rem; margin-top: 1rem; flex-wrap: wrap; }
.btn {
  font: inherit; font-weight: 600;
  padding: 0.5rem 1rem; border-radius: 10px;
  border: 1px solid transparent;
  background: linear-gradient(135deg, var(--accent), #5a7eef);
  color: #0a0c12; cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(123, 157, 255, 0.35); }
.btn.ghost {
  background: transparent; color: var(--text);
  border-color: var(--border);
}

@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(280px, 85vw);
    z-index: 40; transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-only { display: inline-flex; }
  .suggestions { grid-template-columns: 1fr; }
  .grid-floor { opacity: 0.4; }
}

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