:root {
  color-scheme: dark;
  --bg: #0f1419;
  --bg-soft: #151c24;
  --surface: #1a2330cc;
  --surface-solid: #1a2330;
  --border: #2a3748;
  --border-soft: #243041;
  --text: #e6edf5;
  --muted: #8b9bb0;
  --accent: #8fb37a;
  --accent-strong: #6f955c;
  --user-bg: #2a3d2f;
  --assistant-bg: #1e2836;
  --danger: #d9898c;
  --shadow: 0 10px 40px #00000055;
  --radius: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

.hidden { display: none !important; }
.mobile-only { display: none; }

.sky {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: radial-gradient(1200px 700px at 20% -10%, #1d2a3a 0%, transparent 55%),
    radial-gradient(900px 600px at 90% 10%, #1a2830 0%, transparent 50%),
    linear-gradient(180deg, #0f1419 0%, #0c1016 100%);
}
.stars {
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(1.5px 1.5px at 12% 18%, #ffffffaa 50%, transparent 51%),
    radial-gradient(1px 1px at 28% 42%, #d7e6ff88 50%, transparent 51%),
    radial-gradient(1.2px 1.2px at 48% 22%, #ffffff77 50%, transparent 51%),
    radial-gradient(1px 1px at 67% 58%, #cfe0ff66 50%, transparent 51%),
    radial-gradient(1.4px 1.4px at 82% 30%, #ffffff99 50%, transparent 51%),
    radial-gradient(1px 1px at 91% 72%, #b8d0ff55 50%, transparent 51%),
    radial-gradient(1px 1px at 8% 78%, #ffffff66 50%, transparent 51%),
    radial-gradient(1.2px 1.2px at 38% 86%, #dbe8ff55 50%, transparent 51%);
  opacity: 0.7;
}
.glow {
  position: absolute;
  inset: auto -10% -20% -10%;
  height: 45%;
  background: radial-gradient(ellipse at center, #2a403255 0%, transparent 70%);
  filter: blur(8px);
}

.login-view {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(360px, 100%);
  background: var(--surface);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-soft);
  border-radius: 20px;
  padding: 28px 22px 22px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-card h1 {
  margin: 0;
  font-size: 1.45rem;
  letter-spacing: 0.04em;
  text-align: center;
}
.muted { color: var(--muted); margin: 0; text-align: center; font-size: 0.92rem; }
.login-card input {
  width: 100%;
  border: 1px solid var(--border);
  background: #0f1620;
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
}
.login-card input:focus { border-color: var(--accent); }
.login-card button {
  border: 0;
  border-radius: 12px;
  padding: 12px;
  background: var(--accent);
  color: #0f1419;
  font-weight: 650;
  cursor: pointer;
}
.login-card button:hover { background: var(--accent-strong); color: #fff; }
.error { color: var(--danger); margin: 0; text-align: center; font-size: 0.9rem; }

.app {
  position: relative;
  z-index: 1;
  height: 100dvh;
  display: grid;
  grid-template-columns: 280px 1fr;
}

.sidebar {
  background: color-mix(in oklab, var(--bg-soft) 88%, transparent);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  min-height: 0;
  backdrop-filter: blur(12px);
}
.sidebar-head, .sidebar-foot {
  padding: 14px;
  display: flex;
  gap: 8px;
  align-items: center;
}
.sidebar-foot { border-top: 1px solid var(--border-soft); }
.chat-list {
  flex: 1;
  overflow: auto;
  padding: 0 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.chat-item {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
}
.chat-item:hover { background: #ffffff0d; }
.chat-item.active {
  background: #ffffff12;
  border-color: var(--border);
}
.chat-item .title {
  display: block;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-item .meta {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.75rem;
}

.main {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
}
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(10px + var(--safe-top)) 14px 10px;
  border-bottom: 1px solid var(--border-soft);
  background: color-mix(in oklab, var(--bg) 70%, transparent);
  backdrop-filter: blur(14px);
}
.brand {
  margin: 0;
  font-size: 1.05rem;
  letter-spacing: 0.08em;
  font-weight: 650;
}
.spacer { flex: 1; }

.messages {
  overflow: auto;
  padding: 18px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.bubble {
  max-width: min(720px, 92%);
  padding: 12px 14px;
  border-radius: 16px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid var(--border-soft);
}
.bubble.user {
  align-self: flex-end;
  background: var(--user-bg);
  border-bottom-right-radius: 6px;
}
.bubble.assistant {
  align-self: flex-start;
  background: var(--assistant-bg);
  border-bottom-left-radius: 6px;
}
.bubble.system {
  align-self: center;
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 4px 8px;
}
.bubble.streaming::after {
  content: "▍";
  animation: blink 1s steps(1) infinite;
  margin-left: 2px;
  color: var(--accent);
}
@keyframes blink { 50% { opacity: 0; } }

.empty {
  margin: auto;
  text-align: center;
  color: var(--muted);
  max-width: 280px;
  line-height: 1.6;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 12px 14px calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--border-soft);
  background: color-mix(in oklab, var(--bg-soft) 85%, transparent);
  backdrop-filter: blur(14px);
}
.composer textarea {
  resize: none;
  max-height: 140px;
  min-height: 44px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: #0f1620;
  color: var(--text);
  padding: 12px 14px;
  outline: none;
  line-height: 1.4;
}
.composer textarea:focus { border-color: var(--accent); }

.btn {
  border: 1px solid var(--border);
  background: #ffffff0d;
  color: var(--text);
  border-radius: 12px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 600;
}
.btn:hover { background: #ffffff14; }
.btn.primary {
  background: var(--accent);
  border-color: transparent;
  color: #10160f;
}
.btn.primary:hover { background: var(--accent-strong); color: #fff; }
.btn.primary:disabled,
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn.ghost { background: transparent; }
.btn.send { min-width: 72px; }
.icon-btn { padding: 8px 10px; min-width: 40px; }

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: #00000066;
  z-index: 20;
}

@media (max-width: 820px) {
  .mobile-only { display: inline-flex; }
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    z-index: 30;
    inset: 0 auto 0 0;
    width: min(84vw, 320px);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    background: var(--surface-solid);
  }
  .sidebar.open { transform: translateX(0); }
  .bubble { max-width: 94%; }
}
