/* 前台主题：极光 + 玻璃拟态 + 噪声粒子 */
@property --ang { syntax: '<angle>'; inherits: false; initial-value: 0deg; }

:root {
  --bg: #f3f4fb; --bg2: rgba(255,255,255,.55); --bg3: rgba(124,92,255,.10); --fg: #161827; --muted: #6a6f87; --line: rgba(40,40,100,.13);
  --accent: #6d4aff; --accent2: #0891b2; --accent-fg: #fff; --noise: #e0457b; --user-bg: rgba(124,92,255,.10);
  --glass: rgba(255,255,255,.68); --shadow: 0 12px 40px rgba(80,60,200,.16); --fx-rgb: 109,74,255; --aur: .30;
  --grad: var(--accent);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #07080f; --bg2: rgba(18,20,38,.55); --bg3: rgba(130,120,255,.14); --fg: #e9ebf7; --muted: #8b90ab; --line: rgba(160,170,255,.14);
    --accent: #8b7bff; --accent2: #22d3ee; --accent-fg: #07080f; --noise: #ff8a5c; --user-bg: rgba(124,92,255,.20);
    --glass: rgba(16,18,34,.62); --shadow: 0 14px 50px rgba(0,0,0,.55); --fx-rgb: 139,123,255; --aur: .42;
  }
}
body { background: var(--bg); overflow: hidden; }

/* ----- background layers ----- */
.aurora { position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; }
.aurora i { position: absolute; border-radius: 50%; filter: blur(90px); opacity: var(--aur); will-change: transform; }
.aurora i:nth-child(1) { width: 55vmax; height: 55vmax; left: -15vmax; top: -20vmax; background: #6d4aff; animation: drift1 26s ease-in-out infinite alternate; }
.aurora i:nth-child(2) { width: 45vmax; height: 45vmax; right: -12vmax; top: 10vmax; background: #06b6d4; animation: drift2 32s ease-in-out infinite alternate; }
.aurora i:nth-child(3) { width: 40vmax; height: 40vmax; left: 25vw; bottom: -22vmax; background: #ec4899; animation: drift3 38s ease-in-out infinite alternate; }
@keyframes drift1 { to { transform: translate(18vmax, 12vmax) scale(1.2); } }
@keyframes drift2 { to { transform: translate(-16vmax, 14vmax) scale(.85); } }
@keyframes drift3 { to { transform: translate(-14vmax, -10vmax) scale(1.25); } }
.grain {
  position: fixed; inset: 0; z-index: 0; pointer-events: none; opacity: .07; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
#fx { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; pointer-events: none; }

.app { position: relative; z-index: 1; display: flex; height: 100vh; height: 100dvh; }

/* ----- logo ----- */
.logo {
  width: 28px; height: 28px; border-radius: 9px; flex: none; display: grid; place-items: center; position: relative;
  background: var(--accent);
}
.logo i { width: 11px; height: 11px; border: 2.4px solid var(--accent-fg); border-radius: 50%; }
@keyframes spin { to { --ang: 360deg; } }

/* ----- sidebar ----- */
.sidebar { width: 280px; flex: none; display: flex; flex-direction: column; padding: 12px; background: var(--glass); border-right: 1px solid var(--line); backdrop-filter: blur(22px) saturate(1.5); -webkit-backdrop-filter: blur(22px) saturate(1.5); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; padding: 6px 6px 14px; letter-spacing: .2px; }

.btn.new-chat {
  position: relative; overflow: hidden; width: 100%; display: flex; align-items: center; gap: 8px; margin-bottom: 10px; padding: 11px 14px;
  border: 1px solid var(--line); background: var(--bg3); border-radius: 14px; font-weight: 600; transition: transform .15s, box-shadow .2s, border-color .2s;
}
.btn.new-chat:hover { transform: translateY(-1px); border-color: var(--accent); box-shadow: 0 6px 20px rgba(124,92,255,.25); }
.btn.new-chat b { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 6px; background: var(--grad); color: var(--accent-fg); font-size: 15px; line-height: 1; }
.conv-list { flex: 1; overflow-y: auto; margin: 0 -6px; padding: 0 6px; }
.conv { position: relative; display: flex; align-items: center; gap: 4px; padding: 10px 12px; border-radius: 12px; cursor: pointer; font-size: 14.5px; transition: background .18s, transform .18s; animation: rise .4s both; animation-delay: calc(var(--i, 0) * 25ms); }
.conv:hover { background: var(--bg3); transform: translateX(3px); }
.conv.active { background: var(--bg3); }
.conv.active::before { content: ''; position: absolute; left: 0; top: 22%; bottom: 22%; width: 3px; border-radius: 3px; background: var(--grad); box-shadow: 0 0 10px var(--accent); }
.conv .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .del { border: 0; background: none; color: var(--muted); padding: 2px 7px; border-radius: 7px; opacity: 0; font-size: 15px; transition: opacity .15s; }
.conv:hover .del, .conv.active .del { opacity: 1; }
.conv .del:hover { color: #fff; background: var(--danger); }
.empty-list { color: var(--muted); font-size: 13px; text-align: center; padding: 24px 0; }
.user-box { display: flex; align-items: center; gap: 10px; padding: 12px 4px 2px; border-top: 1px solid var(--line); margin-top: 8px; font-size: 14px; }
.user-box .av { width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: var(--accent-fg); display: grid; place-items: center; font-weight: 700; flex: none; }
.user-box .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ----- main ----- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
.topbar { display: none; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--line); background: var(--glass); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); }
.topbar .ttl { flex: 1; text-align: center; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { border: 0; background: none; padding: 6px 9px; border-radius: 10px; font-size: 20px; line-height: 1; }
.icon-btn:hover { background: var(--bg3); }
.scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.thread { max-width: 800px; margin: 0 auto; padding: 28px 18px 16px; }

@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes riseR { from { opacity: 0; transform: translateX(18px) scale(.97); } to { opacity: 1; transform: none; } }

.msg { margin: 0 0 24px; display: flex; gap: 14px; animation: rise .45s cubic-bezier(.2,.8,.2,1) both; }
.msg.user { justify-content: flex-end; animation-name: riseR; }
.msg.user .bubble {
  background: var(--user-bg); border: 1px solid var(--line); padding: 10px 16px; border-radius: 20px 20px 6px 20px; max-width: 85%;
  white-space: pre-wrap; word-break: break-word; box-shadow: 0 4px 20px rgba(124,92,255,.10);
}
.msg.ai .avatar { margin-top: 2px; }
.msg.ai.busy .avatar { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 28px 4px rgba(34,211,238,.7); } }
.msg.ai .body { flex: 1; min-width: 0; overflow-wrap: anywhere; }

.status { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12.5px; margin-bottom: 8px; font-variant-numeric: tabular-nums; }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--grad); animation: bl 1s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .15s; } .dots i:nth-child(3) { animation-delay: .3s; }
@keyframes bl { 0%, 80%, 100% { opacity: .25; transform: scale(.7); } 40% { opacity: 1; transform: scale(1.15); } }
.bar { position: relative; height: 4px; background: var(--bg3); border-radius: 4px; overflow: hidden; width: 110px; }
.bar b { display: block; height: 100%; width: 0; background: var(--grad); transition: width .12s linear; position: relative; }
.bar b::after { content: ''; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, rgba(255,255,255,.7), transparent); animation: shine 1s linear infinite; }
@keyframes shine { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
.skiphint { margin-left: auto; opacity: .7; font-size: 12px; }

.md.diffusing { white-space: pre-wrap; word-break: break-word; padding-left: 14px; position: relative; font-variant-ligatures: none; }
.md.diffusing::before { content: ''; position: absolute; left: 0; top: 2px; bottom: 2px; width: 2px; border-radius: 2px; background: linear-gradient(180deg, var(--accent), var(--accent2), var(--accent)); background-size: 100% 300%; animation: rail 1.2s linear infinite; }
@keyframes rail { to { background-position: 0 -300%; } }
.diffusing .n { color: var(--noise); text-shadow: 0 0 10px var(--noise); }
.diffusing .s { color: var(--fg); }
.reveal { animation: reveal .8s cubic-bezier(.2,.8,.2,1) both; }
@keyframes reveal { from { filter: blur(10px); opacity: .15; transform: translateY(4px); } to { filter: none; opacity: 1; transform: none; } }
.err { color: var(--danger); font-size: 14px; }
.tools { margin-top: 6px; display: flex; gap: 4px; }
.tools button { border: 0; background: none; color: var(--muted); font-size: 12.5px; padding: 3px 9px; border-radius: 8px; }
.tools button:hover { background: var(--bg3); color: var(--fg); }

/* ----- welcome ----- */
.welcome { text-align: center; padding: 13vh 8px 0; }
.welcome .orb { width: 64px; height: 64px; border-radius: 20px; margin: 0 auto 22px; animation: float 4s ease-in-out infinite; }
.welcome .orb i { width: 26px; height: 26px; border-width: 5px; }
@keyframes float { 50% { transform: translateY(-8px); } }
.welcome h1 {
  font-size: clamp(26px, 5vw, 38px); margin: 0 0 10px; font-weight: 800; letter-spacing: .5px; min-height: 1.4em;
  color: var(--fg);
}
@keyframes shimmer { to { background-position: -250% 0; } }
.welcome p { color: var(--muted); margin: 0 0 30px; min-height: 1.6em; }
.sugs { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; max-width: 640px; margin: 0 auto; }
.sug {
  position: relative; overflow: hidden; text-align: left; font-size: 14.5px; line-height: 1.5; padding: 14px 16px; border-radius: 16px; cursor: pointer;
  border: 1px solid var(--line); background: var(--glass); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  transition: transform .2s, border-color .2s, box-shadow .2s; animation: rise .55s cubic-bezier(.2,.8,.2,1) both; animation-delay: calc(var(--i) * 90ms + 300ms);
}
.sug::before { content: ''; position: absolute; inset: 0; opacity: 0; transition: opacity .25s; background: radial-gradient(180px circle at var(--mx, 50%) var(--my, 50%), rgba(124,92,255,.28), transparent 70%); pointer-events: none; }
.sug:hover { transform: translateY(-3px); border-color: var(--accent); box-shadow: 0 10px 30px rgba(124,92,255,.22); }
.sug:hover::before { opacity: 1; }
.sug span { position: relative; }

/* ----- composer ----- */
.composer-wrap { padding: 4px 16px calc(14px + env(safe-area-inset-bottom)); }
.composer {
  position: relative; max-width: 800px; margin: 0 auto; border-radius: 24px; background: var(--glass); border: 1px solid var(--line);
  backdrop-filter: blur(20px) saturate(1.4); -webkit-backdrop-filter: blur(20px) saturate(1.4); box-shadow: var(--shadow);
  display: flex; flex-direction: column; padding: 12px 12px 10px 18px; transition: box-shadow .3s;
}
.composer::before {
  content: ''; position: absolute; inset: -1px; border-radius: inherit; padding: 1.5px; pointer-events: none; opacity: 0; transition: opacity .3s;
  background: conic-gradient(from var(--ang), transparent 0 55%, var(--accent), var(--accent2), #ec4899, transparent); animation: spin 3s linear infinite;
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor; mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
}
.composer:focus-within::before, .composer.busy::before { opacity: 1; }
.composer:focus-within { box-shadow: var(--shadow), 0 0 40px rgba(124,92,255,.22); }
.composer textarea { border: 0; outline: none; resize: none; background: none; width: 100%; max-height: 200px; line-height: 1.55; padding: 2px 0 6px; min-height: 30px; }
.composer textarea::placeholder { color: var(--muted); }
.crow { display: flex; align-items: center; gap: 10px; }
.model-chip { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; padding: 5px 11px 5px 9px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg3); color: var(--fg); max-width: 55%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.model-chip .dot { width: 7px; height: 7px; border-radius: 50%; background: #22c55e; flex: none; animation: ping 2s infinite; }
.model-chip em { font-style: normal; color: var(--muted); }
@keyframes ping { 0% { box-shadow: 0 0 0 0 rgba(34,197,94,.7); } 70%, 100% { box-shadow: 0 0 0 7px rgba(34,197,94,0); } }
.crow .sp { flex: 1; }
#counter { font-size: 12px; color: var(--muted); } #counter .over { color: var(--danger); font-weight: 700; }
.send {
  position: relative; overflow: hidden; width: 38px; height: 38px; border-radius: 50%; border: 0; display: grid; place-items: center; flex: none; font-size: 17px;
  background: var(--accent); color: var(--accent-fg); box-shadow: 0 4px 18px rgba(124,92,255,.4); transition: transform .15s, box-shadow .2s, opacity .2s;
}
.send:hover:not(:disabled) { transform: scale(1.1) rotate(-6deg); box-shadow: 0 6px 26px rgba(34,211,238,.55); }
.send:active:not(:disabled) { transform: scale(.94); }
.send:disabled { opacity: .3; box-shadow: none; cursor: not-allowed; }
.send.stop { animation: pulseBtn 1.2s ease-in-out infinite; }
@keyframes pulseBtn { 50% { box-shadow: 0 0 0 8px rgba(124,92,255,.0), 0 0 24px 4px rgba(236,72,153,.6); } }
.hint { max-width: 800px; margin: 8px auto 0; font-size: 12px; color: var(--muted); text-align: center; }
.ripple { position: absolute; border-radius: 50%; background: rgba(255,255,255,.45); transform: scale(0); animation: rp .6s ease-out forwards; pointer-events: none; }
@keyframes rp { to { transform: scale(1); opacity: 0; } }

/* ----- auth ----- */
.auth { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; overflow: auto; background: color-mix(in srgb, var(--bg) 55%, transparent); backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px); }
.card { position: relative; width: 100%; max-width: 390px; padding: 30px 26px 26px; border-radius: 26px; background: var(--glass); border: 1px solid var(--line); box-shadow: var(--shadow); animation: rise .6s cubic-bezier(.2,.8,.2,1) both; }
.card::before { content: ''; position: absolute; inset: -1px; border-radius: inherit; padding: 1.5px; pointer-events: none; background: conic-gradient(from var(--ang), transparent 0 50%, var(--accent), var(--accent2), #ec4899, transparent); animation: spin 5s linear infinite; -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor; mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0); }
.card .logo { width: 48px; height: 48px; border-radius: 15px; margin: 0 auto 14px; } .card .logo i { width: 19px; height: 19px; border-width: 4px; }
.card h1 { text-align: center; font-size: 24px; margin: 0 0 4px; }
.card .sub { text-align: center; color: var(--muted); margin: 0 0 22px; font-size: 14px; }
.card .tabs { display: flex; background: var(--bg3); border-radius: 12px; padding: 3px; margin-bottom: 16px; }
.card .tabs button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 10px; color: var(--muted); transition: all .2s; }
.card .tabs button.on { background: var(--glass); color: var(--fg); box-shadow: 0 1px 6px rgba(0,0,0,.18); font-weight: 600; }
.card .input { margin-bottom: 12px; background: var(--bg3); border-color: transparent; }
.card .input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124,92,255,.25); }
.card .btn.primary { width: 100%; padding: 12px; border: 0; background: var(--accent); color: var(--accent-fg); position: relative; overflow: hidden; box-shadow: 0 6px 22px rgba(124,92,255,.4); }
.card .msg-err { color: var(--danger); font-size: 14px; min-height: 22px; margin: -2px 0 6px; }

.toast { position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 9px 16px; border-radius: 12px; font-size: 14px; z-index: 100; max-width: 90vw; box-shadow: var(--shadow); animation: rise .3s both; }
.mask { display: none; }
::-webkit-scrollbar { width: 8px; height: 8px; } ::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; } ::-webkit-scrollbar-thumb:hover { background: var(--muted); }

@media (max-width: 800px) {
  .sidebar { position: fixed; z-index: 30; inset: 0 auto 0 0; width: min(84vw, 310px); transform: translateX(-100%); transition: transform .28s cubic-bezier(.2,.8,.2,1); padding-top: calc(12px + env(safe-area-inset-top)); }
  body.nav-open .sidebar { transform: none; box-shadow: var(--shadow); }
  .mask { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 20; backdrop-filter: blur(2px); }
  body.nav-open .mask { display: block; animation: rise .2s both; }
  .topbar { display: flex; padding-top: calc(8px + env(safe-area-inset-top)); }
  .conv .del { opacity: 1; }
  .thread { padding: 16px 12px 8px; }
  .composer-wrap { padding: 4px 10px calc(10px + env(safe-area-inset-bottom)); }
  .welcome { padding-top: 7vh; }
  .sugs { grid-template-columns: 1fr; }
  .msg { gap: 10px; } .msg.user .bubble { max-width: 92%; }
  .composer textarea { font-size: 16px; }
  .model-chip { max-width: 62%; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  #fx { display: none; }
}
