:root {
  color-scheme: dark;
  --bg: #05070b;
  --panel: rgba(9, 13, 20, 0.74);
  --line: rgba(255, 255, 255, 0.11);
  --muted: #8b96aa;
  --text: #eef3fb;
  --cyan: #66e2f0;
  --violet: #aa7bff;
  --danger: #ff8798;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { min-height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  color: var(--text);
  background:
    radial-gradient(circle at 50% 46%, rgba(45, 81, 112, 0.18), transparent 30%),
    linear-gradient(145deg, #030509 0%, #070a10 48%, #04060a 100%);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif;
}

button, input { font: inherit; }
button { color: inherit; }

#presence {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0.5;
  pointer-events: none;
}

.ambient {
  position: fixed;
  width: 44vw;
  height: 44vw;
  border-radius: 50%;
  filter: blur(120px);
  pointer-events: none;
  opacity: 0.07;
}

.ambient-one { left: -16vw; top: 18vh; background: var(--cyan); }
.ambient-two { right: -18vw; bottom: -10vw; background: var(--violet); }

.topbar {
  position: fixed;
  z-index: 10;
  inset: 0 0 auto 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 82px;
  padding: 0 42px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  background: linear-gradient(to bottom, rgba(3, 5, 9, 0.75), transparent);
}

.brand-block { display: flex; align-items: baseline; gap: 14px; }
.brand-block strong { font: 600 24px/1 "Noto Serif SC", serif; letter-spacing: 0.18em; }
.brand-block span, .eyebrow { color: var(--muted); font-size: 10px; letter-spacing: 0.22em; }

.session-block { display: flex; align-items: center; gap: 10px; color: #abb4c4; font-size: 12px; }
.connection-dot { width: 7px; height: 7px; border-radius: 50%; background: #5b6473; box-shadow: 0 0 0 4px rgba(91, 100, 115, 0.09); }
.connection-dot.connected { background: #6ce4b1; box-shadow: 0 0 15px rgba(108, 228, 177, 0.8); }
.connection-dot.connecting { background: #e5ca74; animation: blink 1s infinite; }
.divider { width: 1px; height: 16px; margin: 0 4px; background: var(--line); }
.text-button { padding: 4px 0; border: 0; color: var(--muted); background: none; cursor: pointer; }
.text-button:hover { color: var(--text); }

main { position: relative; z-index: 2; min-height: 100vh; }

.auth-shell {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(420px, calc(100vw - 40px));
  padding: 38px;
  transform: translate(-50%, -47%);
  border: 1px solid var(--line);
  border-radius: 4px;
  background: linear-gradient(150deg, rgba(15, 21, 31, 0.9), rgba(6, 9, 15, 0.82));
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(24px);
}

.auth-shell::before {
  content: "";
  position: absolute;
  inset: -1px auto auto 12%;
  width: 76%;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--cyan), transparent);
}

.auth-shell h1 { margin: 12px 0 8px; font: 600 34px/1.2 "Noto Serif SC", serif; letter-spacing: 0.06em; }
.auth-copy { margin: 0 0 28px; color: var(--muted); font-size: 14px; }
.auth-tabs { display: flex; gap: 24px; margin-bottom: 22px; border-bottom: 1px solid var(--line); }
.auth-tab { position: relative; padding: 0 0 11px; border: 0; color: var(--muted); background: none; cursor: pointer; }
.auth-tab.active { color: var(--text); }
.auth-tab.active::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px; background: var(--cyan); }
.field { display: grid; gap: 8px; margin: 15px 0; }
.field span { color: #aeb8c8; font-size: 12px; }
.field input, .message-form input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 2px;
  outline: none;
  color: var(--text);
  background: rgba(255, 255, 255, 0.035);
}
.field input { height: 46px; padding: 0 14px; }
.field input:focus, .message-form input:focus { border-color: rgba(102, 226, 240, 0.55); box-shadow: 0 0 0 3px rgba(102, 226, 240, 0.06); }
.form-message { min-height: 20px; margin: 8px 0; color: var(--danger); font-size: 12px; }
.form-message.success { color: #76dcac; }
.primary-button {
  width: 100%;
  height: 48px;
  border: 1px solid rgba(102, 226, 240, 0.5);
  border-radius: 2px;
  background: linear-gradient(120deg, rgba(40, 141, 153, 0.34), rgba(92, 55, 145, 0.38));
  cursor: pointer;
  transition: 180ms ease;
}
.primary-button:hover { transform: translateY(-1px); border-color: var(--cyan); }
.primary-button:disabled { opacity: 0.5; cursor: wait; }

.companion-shell { min-height: 100vh; }
.hero-copy { position: absolute; top: 18vh; left: 7vw; width: min(360px, 30vw); }
.hero-copy h1 { margin: 15px 0 10px; font: 600 clamp(32px, 4vw, 60px)/1.15 "Noto Serif SC", serif; letter-spacing: 0.08em; }
.hero-copy p { max-width: 320px; color: var(--muted); line-height: 1.9; font-size: 13px; }

.presence-center { position: absolute; top: 48%; left: 49%; width: min(30vw, 390px); aspect-ratio: 1; transform: translate(-50%, -50%); }
.presence-core { position: absolute; inset: 28%; border-radius: 50%; background: radial-gradient(circle at 40% 35%, #e7ffff, #6ed8e7 8%, #5d69bf 34%, #1a1531 68%, transparent 72%); filter: drop-shadow(0 0 34px rgba(102, 226, 240, 0.36)); transition: transform 200ms ease, filter 200ms ease; }
.presence-core.active { transform: scale(1.12); filter: drop-shadow(0 0 58px rgba(102, 226, 240, 0.62)); }
.presence-ring { position: absolute; border: 1px solid rgba(117, 208, 226, 0.18); border-radius: 50%; animation: orbit 18s linear infinite; }
.ring-one { inset: 13%; border-top-color: rgba(170, 123, 255, 0.7); }
.ring-two { inset: 2%; border-right-color: rgba(102, 226, 240, 0.62); animation-duration: 28s; animation-direction: reverse; }

.chat-panel {
  position: absolute;
  top: 112px;
  right: 42px;
  bottom: 124px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  width: min(360px, 30vw);
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(20px);
}
.panel-heading { display: flex; align-items: center; justify-content: space-between; padding: 20px 22px 16px; border-bottom: 1px solid var(--line); }
.panel-heading h2 { margin: 7px 0 0; font: 500 16px/1.2 "Noto Serif SC", serif; letter-spacing: 0.08em; }
.icon-button { width: 30px; height: 30px; border: 1px solid var(--line); border-radius: 50%; color: var(--muted); background: transparent; cursor: pointer; }
.messages { overflow: auto; padding: 18px 20px; scrollbar-width: thin; }
.empty-state { margin-top: 28px; color: #697386; text-align: center; font-size: 12px; }
.message { margin-bottom: 16px; }
.message .role { display: block; margin-bottom: 5px; color: #697386; font-size: 9px; letter-spacing: 0.16em; }
.message .content { display: inline-block; max-width: 92%; padding: 9px 11px; border: 1px solid rgba(255, 255, 255, 0.07); color: #cdd5e2; background: rgba(255, 255, 255, 0.035); line-height: 1.65; font-size: 13px; }
.message.user { text-align: right; }
.message.user .content { border-color: rgba(102, 226, 240, 0.14); background: rgba(102, 226, 240, 0.06); }
.message.pending .content::after { content: " ·"; animation: blink 1s infinite; }
.message-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 14px; border-top: 1px solid var(--line); }
.message-form input { height: 40px; padding: 0 11px; }
.message-form button { border: 1px solid rgba(102, 226, 240, 0.25); border-radius: 2px; background: rgba(102, 226, 240, 0.08); cursor: pointer; }

.voice-dock { position: absolute; left: 50%; bottom: 36px; display: flex; flex-direction: column; align-items: center; gap: 9px; transform: translateX(-50%); }
.voice-button { display: flex; align-items: center; gap: 11px; min-width: 166px; height: 54px; padding: 0 22px; border: 1px solid rgba(102, 226, 240, 0.35); border-radius: 28px; background: rgba(8, 16, 24, 0.72); box-shadow: 0 12px 38px rgba(0, 0, 0, 0.32); cursor: pointer; backdrop-filter: blur(12px); }
.voice-button:hover { border-color: var(--cyan); }
.voice-button.active { border-color: rgba(255, 135, 152, 0.7); }
.mic-symbol { color: var(--cyan); font-size: 10px; box-shadow: 0 0 16px var(--cyan); }
.voice-button.active .mic-symbol { color: var(--danger); box-shadow: 0 0 16px var(--danger); animation: blink 1s infinite; }
.voice-label { font-size: 12px; letter-spacing: 0.12em; }
.voice-hint { color: #697386; font-size: 10px; }
.e2e-button { border: 0; color: var(--muted); background: transparent; font-size: 10px; cursor: pointer; }

@keyframes orbit { to { transform: rotate(360deg); } }
@keyframes blink { 50% { opacity: 0.4; } }

@media (max-width: 900px) {
  body { overflow: auto; }
  .topbar { height: 68px; padding: 0 18px; }
  .brand-block span, .session-block .divider, #displayName { display: none; }
  .companion-shell { display: grid; min-height: 100vh; padding: 94px 16px 150px; }
  .hero-copy { position: relative; top: auto; left: auto; width: 100%; text-align: center; }
  .hero-copy p { margin: 0 auto; }
  .presence-center { position: relative; top: auto; left: 50%; width: min(64vw, 300px); margin: 24px 0; transform: translateX(-50%); }
  .chat-panel { position: relative; top: auto; right: auto; bottom: auto; width: 100%; min-height: 340px; }
  .voice-dock { position: fixed; z-index: 8; bottom: 20px; }
}

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