:root {
  color-scheme: dark;
  --bg: #080b14;
  --surface: rgba(17, 22, 39, 0.78);
  --surface-solid: #111627;
  --surface-2: #171d31;
  --text: #f7f8ff;
  --muted: #929bb6;
  --line: rgba(255, 255, 255, 0.08);
  --accent: #8a7dff;
  --accent-2: #57d7ff;
  --success: #62e6a7;
  --danger: #ff6f91;
  --warning: #ffd16a;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
  --level: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #eff2fb;
  --surface: rgba(255, 255, 255, 0.82);
  --surface-solid: #ffffff;
  --surface-2: #f4f6fd;
  --text: #171b2b;
  --muted: #66708c;
  --line: rgba(23, 27, 43, 0.1);
  --accent: #6557e8;
  --accent-2: #0089b8;
  --shadow: 0 24px 70px rgba(56, 62, 94, 0.15);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--text);
  background:
    radial-gradient(circle at 16% 0%, color-mix(in srgb, var(--accent) 24%, transparent), transparent 32rem),
    radial-gradient(circle at 90% 15%, color-mix(in srgb, var(--accent-2) 18%, transparent), transparent 28rem),
    var(--bg);
}
button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent-2) 65%, transparent); outline-offset: 3px; }
.hidden { display: none !important; }
.noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .045;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.55'/%3E%3C/svg%3E");
}

.app-shell {
  width: min(980px, calc(100% - 28px));
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 0 max(28px, env(safe-area-inset-bottom));
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.brand { display: inline-flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 14px;
  color: white;
  font-weight: 900;
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 30px color-mix(in srgb, var(--accent) 35%, transparent);
}
.brand-mark.large { width: 58px; height: 58px; border-radius: 18px; font-size: 1.35rem; }
.brand strong, .brand small { display: block; }
.brand strong { letter-spacing: -.02em; }
.brand small { margin-top: 2px; color: var(--muted); font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; }
.top-actions { display: flex; gap: 8px; }
.icon-button {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  backdrop-filter: blur(18px);
  cursor: pointer;
  transition: transform .2s ease, border-color .2s ease, background .2s ease;
}
.icon-button:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.icon-button svg { width: 19px; fill: currentColor; }

.hero-card, .chat-card, .composer {
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
}
.hero-card {
  display: grid;
  grid-template-columns: 150px 1fr;
  align-items: center;
  gap: 24px;
  min-height: 190px;
  padding: 26px 32px;
  border-radius: 30px 30px 18px 18px;
  overflow: hidden;
}
.avatar {
  position: relative;
  display: grid;
  width: 128px;
  height: 128px;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
  border-radius: 42px;
  background:
    radial-gradient(circle at 35% 28%, rgba(255,255,255,.22), transparent 20%),
    linear-gradient(145deg, color-mix(in srgb, var(--accent) 80%, #111), color-mix(in srgb, var(--accent-2) 55%, #111));
  box-shadow:
    0 20px 50px color-mix(in srgb, var(--accent) 30%, transparent),
    0 0 calc(8px + var(--level) * 38px) color-mix(in srgb, var(--accent-2) calc(18% + var(--level) * 45%), transparent);
  transition: transform .25s ease, border-radius .25s ease, box-shadow .12s linear;
}
.avatar span { z-index: 2; font-size: 3.6rem; filter: drop-shadow(0 7px 8px rgba(0,0,0,.2)); }
.avatar[data-state="listening"] { transform: scale(1.04); border-radius: 50%; animation: breathe 1.4s ease-in-out infinite; }
.avatar[data-state="speaking"] { animation: speak .65s ease-in-out infinite alternate; }
.avatar[data-state="thinking"] span { animation: think 1.7s linear infinite; }
.orbit { position: absolute; inset: -11px; border: 1px solid color-mix(in srgb, var(--accent-2) 36%, transparent); border-radius: 50%; opacity: 0; }
.avatar[data-state="listening"] .orbit { opacity: .7; animation: orbitPulse 1.6s ease-out infinite; }
.avatar[data-state="listening"] .orbit-two { animation-delay: .8s; }
.status-row { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .88rem; font-weight: 650; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); box-shadow: 0 0 0 5px color-mix(in srgb, var(--muted) 15%, transparent); }
.status-dot.ready { background: var(--success); box-shadow: 0 0 0 5px color-mix(in srgb, var(--success) 15%, transparent); }
.status-dot.busy { background: var(--warning); box-shadow: 0 0 0 5px color-mix(in srgb, var(--warning) 15%, transparent); }
.status-dot.error { background: var(--danger); box-shadow: 0 0 0 5px color-mix(in srgb, var(--danger) 15%, transparent); }
.hero-copy h1 { margin: 12px 0 7px; font-size: clamp(1.65rem, 5vw, 2.8rem); line-height: 1; letter-spacing: -.055em; }
.hero-copy p { max-width: 620px; margin: 0; color: var(--muted); line-height: 1.65; }

.chat-card { position: relative; min-height: 350px; margin-top: 12px; border-radius: 18px; overflow: hidden; }
.message-list { height: min(48vh, 520px); min-height: 350px; overflow-y: auto; padding: 25px; scroll-behavior: smooth; }
.message-list::-webkit-scrollbar { width: 8px; }
.message-list::-webkit-scrollbar-thumb { border-radius: 999px; background: color-mix(in srgb, var(--muted) 25%, transparent); }
.empty-state { display: grid; height: 100%; min-height: 300px; place-items: center; text-align: center; color: var(--muted); }
.empty-state div { max-width: 360px; }
.empty-state strong { display: block; margin-bottom: 8px; color: var(--text); font-size: 1.1rem; }
.message { display: flex; margin: 14px 0; animation: messageIn .28s ease-out both; }
.message.user { justify-content: flex-end; }
.message.assistant { justify-content: flex-start; }
.message-bubble { max-width: min(76%, 650px); padding: 13px 16px 10px; border: 1px solid var(--line); border-radius: 18px; line-height: 1.55; overflow-wrap: anywhere; }
.message.user .message-bubble { color: white; border-bottom-right-radius: 5px; background: linear-gradient(145deg, var(--accent), color-mix(in srgb, var(--accent) 70%, #4b32bd)); }
.message.assistant .message-bubble { border-bottom-left-radius: 5px; background: var(--surface-2); }
.message-text { white-space: pre-wrap; }
.message-time { display: block; margin-top: 5px; font-size: .67rem; opacity: .62; }
.typing-dots { display: inline-flex; gap: 4px; align-items: center; min-width: 32px; }
.typing-dots i { width: 5px; height: 5px; border-radius: 50%; background: currentColor; animation: dot 1.2s infinite ease-in-out; }
.typing-dots i:nth-child(2) { animation-delay: .18s; }
.typing-dots i:nth-child(3) { animation-delay: .36s; }
.scroll-button { position: absolute; right: 18px; bottom: 16px; border: 1px solid var(--line); border-radius: 999px; padding: 9px 13px; color: var(--text); background: var(--surface-solid); box-shadow: 0 8px 24px rgba(0,0,0,.2); cursor: pointer; }

.composer { margin-top: 12px; padding: 18px 20px 20px; border-radius: 18px 18px 30px 30px; }
.composer-note { display: flex; align-items: center; justify-content: center; gap: 8px; margin-bottom: 16px; color: var(--muted); font-size: .78rem; text-align: center; }
.composer-note strong { color: var(--accent-2); text-transform: uppercase; letter-spacing: .08em; }
.controls { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 18px; }
.secondary-button {
  display: inline-flex;
  min-height: 46px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 15px;
  color: var(--muted);
  background: var(--surface-2);
  cursor: pointer;
  transition: color .2s ease, border-color .2s ease, transform .2s ease;
}
.secondary-button:hover:not(:disabled) { color: var(--text); border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); transform: translateY(-1px); }
.secondary-button:disabled { cursor: not-allowed; opacity: .38; }
.secondary-button svg { width: 17px; fill: currentColor; }
.mic-button {
  position: relative;
  z-index: 1;
  display: grid;
  width: 116px;
  height: 116px;
  place-items: center;
  border: 0;
  border-radius: 40px;
  color: white;
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
  box-shadow: 0 16px 44px color-mix(in srgb, var(--accent) 35%, transparent);
  cursor: pointer;
  transition: transform .18s ease, border-radius .2s ease, filter .2s ease;
}
.mic-button:hover:not(:disabled) { transform: translateY(-3px) scale(1.02); filter: saturate(1.1); }
.mic-button:active:not(:disabled) { transform: scale(.97); }
.mic-button:disabled { cursor: not-allowed; filter: grayscale(.75); opacity: .48; }
.mic-button svg { width: 34px; fill: currentColor; }
.mic-button #micLabel { font-size: .74rem; font-weight: 750; }
.mic-button[aria-pressed="true"] { border-radius: 50%; background: linear-gradient(145deg, #ff5f86, #ff856b); animation: micPulse 1s ease-in-out infinite alternate; }
.mic-ripple { position: absolute; inset: -10px; z-index: -1; border: 1px solid color-mix(in srgb, var(--accent-2) 50%, transparent); border-radius: inherit; opacity: 0; }
.mic-button[aria-pressed="true"] .mic-ripple { opacity: 1; animation: ripple 1.3s ease-out infinite; }

.toast-region { position: fixed; z-index: 50; right: max(18px, env(safe-area-inset-right)); bottom: max(18px, env(safe-area-inset-bottom)); display: grid; gap: 9px; width: min(390px, calc(100% - 36px)); }
.toast { padding: 13px 15px; border: 1px solid var(--line); border-radius: 15px; color: var(--text); background: var(--surface-solid); box-shadow: var(--shadow); animation: toastIn .25s ease-out both; }
.toast.error { border-color: color-mix(in srgb, var(--danger) 50%, var(--line)); }
.toast.success { border-color: color-mix(in srgb, var(--success) 50%, var(--line)); }

.login-overlay { position: fixed; z-index: 100; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(5, 7, 14, .76); backdrop-filter: blur(18px); }
.login-card { width: min(430px, 100%); padding: 32px; border: 1px solid var(--line); border-radius: 28px; background: var(--surface-solid); box-shadow: 0 30px 100px rgba(0,0,0,.45); }
.login-card .brand-mark { margin-bottom: 24px; }
.eyebrow { margin: 0 0 7px !important; color: var(--accent-2) !important; font-size: .7rem; font-weight: 850; letter-spacing: .17em; }
.login-card h2 { margin: 0; font-size: 2rem; letter-spacing: -.04em; }
.login-card p { color: var(--muted); line-height: 1.55; }
.login-card label { display: block; margin: 22px 0 8px; font-size: .82rem; font-weight: 750; }
.login-card input { width: 100%; min-height: 50px; border: 1px solid var(--line); border-radius: 14px; padding: 0 15px; color: var(--text); background: var(--surface-2); }
.form-error { min-height: 22px; margin: 7px 0 !important; color: var(--danger) !important; font-size: .78rem; }
.login-button { width: 100%; min-height: 51px; border: 0; border-radius: 14px; color: white; font-weight: 800; background: linear-gradient(145deg, var(--accent), var(--accent-2)); cursor: pointer; }

@keyframes breathe { 50% { transform: scale(1.08); } }
@keyframes speak { to { transform: translateY(-4px) rotate(1.5deg); border-radius: 34px 48px 36px 46px; } }
@keyframes think { to { transform: rotate(360deg); } }
@keyframes orbitPulse { from { transform: scale(.88); opacity: .8; } to { transform: scale(1.28); opacity: 0; } }
@keyframes messageIn { from { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes dot { 0%, 80%, 100% { transform: translateY(0); opacity: .4; } 40% { transform: translateY(-4px); opacity: 1; } }
@keyframes micPulse { to { box-shadow: 0 18px 56px rgba(255, 95, 134, .42); } }
@keyframes ripple { from { transform: scale(.84); opacity: .8; } to { transform: scale(1.24); opacity: 0; } }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 720px) {
  .app-shell { width: min(100% - 18px, 980px); }
  .hero-card { grid-template-columns: 84px 1fr; gap: 17px; min-height: 150px; padding: 20px; border-radius: 24px 24px 14px 14px; }
  .avatar { width: 78px; height: 78px; border-radius: 25px; }
  .avatar span { font-size: 2.35rem; }
  .hero-copy h1 { margin-top: 9px; }
  .hero-copy p { font-size: .86rem; line-height: 1.5; }
  .message-list { height: 46vh; padding: 17px 13px; }
  .message-bubble { max-width: 87%; }
  .composer { padding-inline: 13px; }
  .composer-note { display: block; }
  .composer-note strong { display: block; margin-bottom: 3px; }
  .controls { grid-template-columns: 1fr 104px 1fr; gap: 8px; }
  .mic-button { width: 100px; height: 100px; border-radius: 34px; }
  .secondary-button { min-width: 0; padding: 8px; font-size: 0; }
  .secondary-button svg { width: 22px; }
}

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