:root {
  --bg: #04050a;
  --bg-2: #0a0f24;
  --text: #e6ecff;
  --muted: #8b96b8;
  --line: rgba(120, 170, 255, 0.14);
  --glass: rgba(255, 255, 255, 0.035);
  --accent: #4fc3ff;
  --accent-2: #7b5cff;
  --danger: #ff6b8a;
  --orb: 168px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background:
    radial-gradient(ellipse 80% 60% at 50% 0%, #101a44 0%, transparent 60%),
    radial-gradient(ellipse 60% 50% at 80% 100%, rgba(90, 40, 200, 0.18) 0%, transparent 70%),
    var(--bg);
  color: var(--text);
  font: 15px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }

/* ---------- Orb ---------- */
.orb { position: relative; width: var(--orb); height: var(--orb); transition: filter 0.8s ease; }
.orb.small { --orb: 120px; }
.orb > div { position: absolute; border-radius: 50%; }

.orb-glow {
  inset: -70%;
  background: radial-gradient(circle, rgba(70, 150, 255, 0.38) 0%, rgba(110, 70, 255, 0.16) 35%, transparent 65%);
  filter: blur(18px);
  animation: breathe 5s ease-in-out infinite;
}
.orb-core {
  inset: 0;
  overflow: hidden;
  background: radial-gradient(circle at 34% 28%, #f2fdff 0%, #9be8ff 10%, #3aa2ff 32%, #5a36ff 62%, #1a0a4a 88%, #0b0420 100%);
  box-shadow:
    0 0 30px 6px rgba(70, 170, 255, 0.55),
    0 0 90px 24px rgba(100, 70, 255, 0.35),
    inset 0 0 28px rgba(255, 255, 255, 0.35),
    inset -10px -14px 40px rgba(20, 0, 60, 0.7);
  animation: breathe 5s ease-in-out infinite;
}
.orb-swirl {
  position: absolute; inset: -20%; border-radius: 50%;
  background: conic-gradient(from 0deg, transparent 0deg, rgba(170, 245, 255, 0.55) 40deg, transparent 110deg,
    rgba(180, 120, 255, 0.5) 190deg, transparent 260deg, rgba(90, 210, 255, 0.45) 320deg, transparent 360deg);
  filter: blur(10px);
  mix-blend-mode: screen;
  animation: spin 11s linear infinite;
}
.orb-swirl.s2 { inset: -5%; opacity: 0.7; animation: spin 7s linear infinite reverse; }
.orb-core::after {
  content: ""; position: absolute; left: 18%; top: 12%; width: 38%; height: 26%; border-radius: 50%;
  background: radial-gradient(ellipse, rgba(255, 255, 255, 0.75), transparent 70%);
  filter: blur(4px);
}
.orb-ring {
  inset: -10%;
  border: 1px solid rgba(130, 200, 255, 0.4);
  animation: ripple 5s ease-out infinite;
}
.orb-ring.r2 { animation-delay: 2.5s; }

/* Zustände */
.orb.thinking { filter: hue-rotate(38deg) saturate(1.35) brightness(1.1); }
.orb.thinking .orb-core, .orb.thinking .orb-glow { animation-duration: 1.4s; }
.orb.thinking .orb-swirl { animation-duration: 2.4s; }
.orb.thinking .orb-swirl.s2 { animation-duration: 1.6s; }
.orb.thinking .orb-ring { animation-duration: 1.6s; }
.orb.thinking .orb-ring.r2 { animation-delay: 0.8s; }
.orb.speaking .orb-core { animation: flash 0.9s ease-out, breathe 5s ease-in-out 0.9s infinite; }
.orb.error { filter: hue-rotate(140deg) saturate(1.4); }
.orb.shake { animation: shake 0.45s ease; }

@keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.055); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes ripple { 0% { transform: scale(0.9); opacity: 0.75; } 100% { transform: scale(1.75); opacity: 0; } }
@keyframes flash { 0% { transform: scale(1.14); filter: brightness(1.6); } 100% { transform: scale(1); filter: brightness(1); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

@media (prefers-reduced-motion: reduce) {
  .orb *, .orb { animation-duration: 0s !important; animation-iteration-count: 1 !important; }
}

/* ---------- App-Layout ---------- */
body.app { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px max(16px, env(safe-area-inset-left)) 10px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: 0.32em; font-size: 13px; color: #cfe0ff; }
.brand-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.actions { display: flex; gap: 8px; }
.ghost {
  background: var(--glass); border: 1px solid var(--line); border-radius: 999px;
  padding: 7px 14px; font-size: 13px; color: var(--muted); cursor: pointer; transition: 0.2s;
}
.ghost:hover { color: var(--text); border-color: rgba(120, 190, 255, 0.4); }

.hero {
  display: grid; place-items: center; flex: 0 0 auto;
  height: calc(var(--orb) * 1.9);
  transition: height 0.6s ease, --orb 0.6s ease;
}
body.has-messages { --orb: 96px; }
body.has-messages .hero { height: calc(var(--orb) * 1.75); }
.status { text-align: center; color: var(--muted); font-size: 13px; letter-spacing: 0.04em; min-height: 20px; margin-bottom: 6px; }

.messages {
  flex: 1 1 auto; overflow-y: auto; padding: 8px 16px 16px;
  scroll-behavior: smooth;
  mask-image: linear-gradient(to bottom, transparent 0, #000 18px);
}
.msg { display: flex; max-width: 780px; margin: 0 auto 14px; animation: rise 0.35s ease; }
.msg.user { justify-content: flex-end; }
.bubble {
  max-width: min(85%, 640px); padding: 11px 15px; border-radius: 18px;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.user .bubble {
  background: linear-gradient(135deg, rgba(79, 195, 255, 0.22), rgba(123, 92, 255, 0.22));
  border: 1px solid rgba(120, 180, 255, 0.3);
  border-bottom-right-radius: 6px;
}
.msg.assistant .bubble {
  background: var(--glass); border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
}
.msg.error .bubble { border-color: rgba(255, 107, 138, 0.45); color: #ffc2cf; }
.msg.notice { justify-content: center; color: var(--muted); font-size: 12.5px; }
.bubble b { color: #fff; }
.bubble a { color: var(--accent); }
.bubble code {
  font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: rgba(120, 160, 255, 0.12); padding: 1px 5px; border-radius: 5px;
}
.bubble pre {
  margin: 8px 0; padding: 12px 14px; background: #070a16; border: 1px solid var(--line);
  border-radius: 12px; overflow-x: auto; white-space: pre;
  font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.typing { display: inline-flex; gap: 5px; padding: 4px 2px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); opacity: 0.4; animation: dot 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes dot { 0%, 100% { opacity: 0.25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-4px); } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.composer { flex: 0 0 auto; padding: 8px 16px max(14px, env(safe-area-inset-bottom)); }
.composer-inner {
  max-width: 780px; margin: 0 auto; display: flex; align-items: flex-end; gap: 8px;
  background: rgba(10, 14, 32, 0.85); border: 1px solid var(--line); border-radius: 22px;
  padding: 6px 6px 6px 16px; backdrop-filter: blur(12px);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.composer-inner:focus-within { border-color: rgba(79, 195, 255, 0.5); box-shadow: 0 0 0 4px rgba(79, 195, 255, 0.08), 0 0 30px rgba(79, 195, 255, 0.12); }
.composer textarea {
  flex: 1; resize: none; border: 0; outline: 0; background: transparent;
  padding: 9px 0; max-height: 180px; line-height: 1.45;
}
.composer textarea::placeholder { color: #5f6a8c; }
#send {
  flex: 0 0 auto; width: 40px; height: 40px; border: 0; border-radius: 50%; cursor: pointer;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 18px rgba(79, 195, 255, 0.45); transition: transform 0.15s, opacity 0.2s;
}
#send:hover { transform: scale(1.06); }
#send:disabled { opacity: 0.4; cursor: default; transform: none; }
.hint { max-width: 780px; margin: 6px auto 0; text-align: center; font-size: 11.5px; color: #4f5978; }

@media (max-width: 560px) {
  .hint { display: none; }
  .ghost { padding: 6px 11px; font-size: 12px; }
  .bubble { max-width: 92%; }
}

/* ---------- Login ---------- */
body.login { display: grid; place-items: center; min-height: 100dvh; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; text-align: center;
  display: flex; flex-direction: column; align-items: center;
}
.login-card .orb { margin: 40px 0 46px; }
.login-card h1 { margin: 0; font-size: 18px; letter-spacing: 0.42em; font-weight: 600; color: #d8e6ff; padding-left: 0.42em; }
.login-card .sub { margin: 6px 0 26px; color: var(--muted); font-size: 13.5px; }
.login-card form {
  width: 100%; display: flex; flex-direction: column; gap: 14px; text-align: left;
  background: rgba(10, 14, 32, 0.7); border: 1px solid var(--line); border-radius: 20px; padding: 22px;
  backdrop-filter: blur(12px);
}
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--muted); }
.login-card input {
  background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 13px; outline: 0; transition: 0.2s;
}
.login-card input:focus { border-color: rgba(79, 195, 255, 0.55); box-shadow: 0 0 0 4px rgba(79, 195, 255, 0.08); }
.login-card button {
  margin-top: 4px; border: 0; border-radius: 12px; padding: 12px; cursor: pointer; font-weight: 600; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 22px rgba(79, 195, 255, 0.35);
}
.login-card button:disabled { opacity: 0.6; cursor: default; }
.error { margin: 0; min-height: 18px; color: var(--danger); font-size: 13px; text-align: center; }
