/* 硅基老孟 · 科幻基调：深空底 + 冷白光 + 唯一朱砂能量色 */
:root {
  --bg: #07080b;
  --bg-2: #0d0f14;
  --panel: rgba(255, 255, 255, .045);
  --panel-hi: rgba(255, 255, 255, .08);
  --ink: #e8ecf4;
  --ink-2: #a8b0c0;
  --ink-3: #626b7d;
  --line: rgba(160, 185, 255, .14);
  --cool: #cde1ff;
  --warm: #ff5c3c;
  --warm-soft: rgba(255, 92, 60, .18);
  --sans: -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  --ease: cubic-bezier(.22, .8, .24, 1);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background-image:
    radial-gradient(90% 55% at 50% 38%, rgba(70, 90, 160, .16), transparent 70%),
    radial-gradient(60% 40% at 50% 110%, rgba(255, 92, 60, .07), transparent 70%);
}
/* 极淡网格，给一点空间感 */
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 44px 44px;
  opacity: .18;
  -webkit-mask-image: radial-gradient(70% 50% at 50% 40%, #000, transparent);
  mask-image: radial-gradient(70% 50% at 50% 40%, #000, transparent);
}
body > * { position: relative; z-index: 1; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

/* ---------- 欢迎层 ---------- */
.welcome {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-content: center; justify-items: center; gap: 18px;
  background: var(--bg);
  animation: welcomeOut .28s var(--ease) .72s forwards;
}
.welcome.is-gone { animation: welcomeOut .18s var(--ease) forwards; }
@keyframes welcomeOut { to { opacity: 0; visibility: hidden; pointer-events: none; } }
.welcome__avatar {
  width: 104px; height: 104px; border-radius: 50%;
  display: grid; place-items: center; overflow: hidden;
  box-shadow: 0 0 0 1px var(--line), 0 0 60px -10px rgba(120, 150, 255, .45);
  animation: rise .5s var(--ease) both;
}
.welcome__avatar img { width: 100%; height: 100%; object-fit: cover; grid-area: 1 / 1; }
.welcome__core {
  grid-area: 1 / 1; width: 34px; height: 34px; border-radius: 50%;
  background: radial-gradient(circle at 40% 40%, #fff, var(--cool) 30%, var(--warm) 75%, transparent 76%);
  box-shadow: 0 0 30px 6px rgba(255, 92, 60, .35), 0 0 60px 12px rgba(120, 150, 255, .25);
}
.welcome__avatar img + .welcome__core { display: none; }
.welcome__name { margin: 0; font: 300 17px/1 var(--sans); letter-spacing: .5em; text-indent: .5em; color: var(--ink-2); animation: rise .5s var(--ease) .08s both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* ---------- 顶栏 ---------- */
.top {
  flex: none;
  z-index: 5; /* 菜单要盖过下面的舞台 */
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand__dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--warm); box-shadow: 0 0 10px 2px var(--warm-soft), 0 0 2px var(--warm);
  animation: pulse 2.8s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: .45; } }
.brand__name { font: 500 15px/1 var(--sans); letter-spacing: .28em; }
.top__actions { display: flex; gap: 4px; }
.ghost { padding: 8px 12px; border-radius: 999px; font-size: 14px; color: var(--ink-2); }
.ghost:active, .ghost[aria-expanded="true"] { background: var(--panel-hi); }
.menu {
  position: absolute; right: 16px; top: calc(100% - 4px); z-index: 20;
  min-width: 140px; padding: 6px; border-radius: 12px;
  background: rgba(20, 23, 30, .92); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  box-shadow: 0 0 0 1px var(--line), 0 16px 36px -12px rgba(0, 0, 0, .6);
}
.menu button { display: block; width: 100%; text-align: left; padding: 10px 12px; border-radius: 8px; font-size: 15px; }
.menu button:active { background: var(--panel-hi); }

/* ---------- 舞台 ---------- */
.stage {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column;
  padding: 0 16px 8px;
}
.hero {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 4px 0 20px; text-align: center;
}
.core {
  --size: min(78vw, 320px);
  position: relative; width: var(--size); height: var(--size);
  display: grid; place-items: center;
  transition: width .5s var(--ease), height .5s var(--ease);
}
.core__canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
/* HUD 细环：带刻度，慢转 */
.core__hud {
  position: absolute; inset: 9%; border-radius: 50%;
  border: 1px solid var(--line);
  -webkit-mask: repeating-conic-gradient(#000 0 1.2deg, transparent 1.2deg 6deg);
  mask: repeating-conic-gradient(#000 0 1.2deg, transparent 1.2deg 6deg);
  animation: spin 60s linear infinite;
  transition: border-color .4s, inset .4s var(--ease);
}
.core__hud--2 {
  inset: 3%; -webkit-mask: conic-gradient(#000 0 22%, transparent 22% 50%, #000 50% 64%, transparent 64%);
  mask: conic-gradient(#000 0 22%, transparent 22% 50%, #000 50% 64%, transparent 64%);
  animation-duration: 24s; animation-direction: reverse; opacity: .7;
}
@keyframes spin { to { transform: rotate(360deg); } }
.state { margin: 0; font: 12px/1.2 var(--mono); color: var(--ink-3); letter-spacing: .14em; min-height: 1.2em; transition: color .3s; }
.greet { margin: 0; max-width: 21em; font: 300 16px/1.8 var(--sans); color: var(--ink-2); text-wrap: pretty; }

/* 对话开始后：光核收到顶部做状态指示 */
body.is-chatting .hero {
  flex: none; flex-direction: row; justify-content: flex-start; gap: 10px; padding: 0 0 10px;
  position: sticky; top: 0; z-index: 2;
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  -webkit-mask-image: linear-gradient(#000 80%, transparent); mask-image: linear-gradient(#000 80%, transparent);
}
body.is-chatting .core { --size: 52px; }
body.is-chatting .core__hud--2 { display: none; }
body.is-chatting .greet { display: none; }

/* ---------- 语音七态（HUD 部分；粒子部分见 orb.js）---------- */
body[data-voice="connecting"] .core__hud--2 { animation-duration: 2s; border-color: var(--cool); }
body[data-voice="listening"] .core__hud { border-color: var(--warm); inset: calc(9% - var(--level, 0) * 6%); }
body[data-voice="listening"] .state { color: var(--warm); }
body[data-voice="thinking"] .core__hud { animation-duration: 8s; border-color: rgba(205, 225, 255, .35); }
body[data-voice="thinking"] .core__hud--2 { animation-duration: 3s; }
body[data-voice="speaking"] .core__hud { border-color: rgba(205, 225, 255, .3); }
body[data-voice="speaking"] .state, body[data-voice="thinking"] .state { color: var(--cool); }
body[data-voice="failed"] .core__hud, body[data-voice="interrupted"] .core__hud { animation-play-state: paused; }
body[data-voice="failed"] .state { color: var(--warm); }

@media (prefers-reduced-motion: reduce) {
  .core__hud, .brand__dot { animation: none !important; }
}

/* ---------- 对话流 ---------- */
.thread { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 16px; }
.msg { display: flex; flex-direction: column; max-width: 88%; animation: rise .32s var(--ease) both; }
.msg--me { align-self: flex-end; align-items: flex-end; }
.msg__body { margin: 0; font-size: 16px; line-height: 1.7; white-space: pre-wrap; word-break: break-word; }
.msg--me .msg__body {
  padding: 10px 14px; border-radius: 16px; border-bottom-right-radius: 4px;
  background: var(--panel-hi); box-shadow: inset 0 0 0 1px var(--line);
}
.msg--ai .msg__body { padding: 0 0 0 14px; border-left: 1px solid var(--warm); color: var(--ink); }
.msg--ai.is-streaming .msg__body::after { content: ""; display: inline-block; width: .45em; height: 1em; margin-left: 3px; vertical-align: -2px; background: var(--warm); box-shadow: 0 0 8px var(--warm); animation: caret 1s steps(1) infinite; }
@keyframes caret { 50% { opacity: 0; } }
.msg__voice { font: 11px var(--mono); color: var(--ink-3); margin-bottom: 4px; letter-spacing: .08em; }

/* ---------- 底部输入 ---------- */
.dock { flex: none; padding: 6px 16px calc(10px + var(--safe-b)); }
.disclosure { margin: 0 0 8px; text-align: center; font-size: 11.5px; color: var(--ink-3); letter-spacing: .06em; }
.composer {
  display: flex; align-items: center; gap: 6px;
  padding: 6px; border-radius: 999px;
  background: rgba(18, 21, 28, .85); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  box-shadow: inset 0 0 0 1px var(--line), 0 10px 30px -12px rgba(0, 0, 0, .7);
}
.composer:focus-within { box-shadow: inset 0 0 0 1px rgba(205, 225, 255, .35), 0 0 24px -8px rgba(120, 150, 255, .5); }
.composer input {
  flex: 1; min-width: 0; height: 40px; padding: 0 6px; border: 0; outline: 0; background: transparent;
  font: 16px var(--sans); color: var(--ink);
}
.composer input::placeholder { color: var(--ink-3); }
.mode, .send { flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; }
.mode svg, .send svg { width: 21px; height: 21px; fill: currentColor; }
.mode { color: var(--ink-2); }
.mode:active { background: var(--panel-hi); }
.send { background: var(--warm); color: #fff; box-shadow: 0 0 16px -2px var(--warm-soft); transition: opacity .2s, transform .2s var(--ease); }
.send:disabled { opacity: .2; transform: scale(.9); box-shadow: none; }
.hold {
  flex: 1; height: 40px; border-radius: 999px; font-size: 15px; letter-spacing: .24em;
  color: var(--ink); background: var(--panel); user-select: none; -webkit-user-select: none; touch-action: none;
  transition: background .15s, box-shadow .15s, transform .15s var(--ease);
}
.hold.is-pressed { background: var(--warm); color: #fff; box-shadow: 0 0 24px -2px var(--warm); transform: scale(.98); }
.hold.is-cancel { background: #3a3f4b; box-shadow: none; }
.composer.is-voice .send { display: none; }
.quota { margin: 6px 0 0; min-height: 1em; text-align: center; font: 11px var(--mono); color: var(--ink-3); letter-spacing: .06em; }

.toast {
  position: fixed; left: 50%; bottom: calc(110px + var(--safe-b)); transform: translateX(-50%);
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 10px;
  background: rgba(20, 23, 30, .95); box-shadow: inset 0 0 0 1px var(--line); color: var(--ink); font-size: 14px; z-index: 40;
  animation: rise .25s var(--ease);
}

@media (min-width: 760px) {
  .stage, .dock { width: 100%; max-width: 720px; margin: 0 auto; }
}

/* 本机邀请码及隐私告知 */
#loginDialog, #meDialog { width: min(90vw, 480px); max-height: 85dvh; overflow: auto; margin: auto; padding: 24px; border: 1px solid #666; border-radius: 16px; background: #15171d; color: #eee; }
#loginDialog::backdrop, #meDialog::backdrop { background: #000b; }
#loginForm { display: grid; gap: 16px; line-height: 1.7; }
#loginForm input[type=password] { display: block; width: 100%; padding: 10px; color: #111; background: #fff; }
#loginForm button { padding: 10px; }
#loginError { color: #ffb6a5; }

#meDialog button { display: block; width: 100%; margin-top: 16px; padding: 10px; }
