:root {
  --bg: #0a0e13;
  --bg-soft: #10161d;
  --panel: rgba(20, 27, 36, 0.78);
  --panel-solid: #141b24;
  --border: rgba(255, 255, 255, 0.08);
  --text: #e8eef6;
  --muted: #93a1b3;
  --faint: #67758a;
  --mint: #7ee7c7;
  --mint-deep: #2fbf9b;
  --blue: #8ab4ff;
  --warm: #ffd6a5;
  --danger: #ff8a8a;
  --radius: 18px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.42);
  --font: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

/* ---------- background ---------- */
.aurora {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}
.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.55;
  animation: drift 18s ease-in-out infinite alternate;
}
.orb-a { width: 42vw; height: 42vw; background: #1f6f63; top: -12vw; left: -8vw; }
.orb-b { width: 34vw; height: 34vw; background: #2b4f8f; bottom: -10vw; right: -6vw; animation-delay: -6s; }
.orb-c { width: 26vw; height: 26vw; background: #6f4a2e; bottom: 18vh; left: 24vw; opacity: 0.35; animation-delay: -12s; }
@keyframes drift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to { transform: translate3d(4vw, 3vh, 0) scale(1.12); }
}
@media (prefers-reduced-motion: reduce) { .orb { animation: none; } }

/* ---------- login ---------- */
.login-screen {
  position: relative;
  z-index: 2;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(400px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 26px;
  padding: 36px 32px 28px;
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  text-align: center;
}
.login-avatar, .avatar {
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, var(--mint), #5ab6ff 70%);
  color: #06221d;
  font-weight: 700;
  box-shadow: 0 8px 22px rgba(94, 226, 195, 0.28);
}
.login-avatar {
  width: 64px;
  height: 64px;
  border-radius: 22px;
  margin: 0 auto 16px;
  font-size: 26px;
}
.login-card h1 { margin: 0; font-size: 26px; letter-spacing: 0.06em; }
.login-sub { margin: 6px 0 26px; color: var(--muted); font-size: 13px; letter-spacing: 0.08em; }
.login-card label { display: block; text-align: left; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.login-card input {
  width: 100%;
  padding: 13px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.25);
  outline: none;
}
.login-card input:focus { border-color: rgba(126, 231, 199, 0.55); }
.primary {
  width: 100%;
  margin-top: 14px;
  padding: 13px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(120deg, var(--mint), #62c9ff);
  color: #052019;
  font-weight: 650;
  letter-spacing: 0.04em;
}
.primary:active { transform: translateY(1px); }
.login-error { min-height: 18px; margin: 10px 0 0; color: var(--danger); font-size: 12px; }
.login-help { margin-top: 18px; text-align: left; color: var(--faint); font-size: 12px; }
.login-help summary { cursor: pointer; color: var(--muted); }
.login-help code { color: var(--warm); }

/* ---------- shell ---------- */
.shell {
  position: relative;
  z-index: 1;
  height: 100dvh;
  max-width: 880px;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 0 16px;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 4px 12px;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.avatar { width: 42px; height: 42px; border-radius: 15px; font-size: 18px; flex: none; }
.brand-text { min-width: 0; }
.brand-text h1 { margin: 0; font-size: 17px; font-weight: 650; }
.brand-text p { margin: 3px 0 0; font-size: 11.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); display: inline-block; }
.dot.online { background: var(--mint); box-shadow: 0 0 0 4px rgba(126, 231, 199, 0.12); }
.dot.offline { background: #f0b46a; box-shadow: 0 0 0 4px rgba(240, 180, 106, 0.1); }
.top-actions { display: flex; gap: 8px; }
.ghost {
  position: relative;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 8px 13px;
  border-radius: 11px;
  font-size: 12.5px;
}
.ghost:hover { color: var(--text); border-color: rgba(255, 255, 255, 0.18); }
.badge {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 17px;
  height: 17px;
  border-radius: 9px;
  background: var(--mint);
  color: #04231c;
  font-size: 10px;
  font-weight: 700;
  display: grid;
  place-items: center;
  padding: 0 4px;
}

/* ---------- chat ---------- */
.chat {
  overflow-y: auto;
  padding: 8px 4px 18px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.14) transparent;
  overscroll-behavior: contain;
}
.chat::-webkit-scrollbar { width: 6px; }
.chat::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.12); border-radius: 3px; }

.day-divider {
  text-align: center;
  color: var(--faint);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  margin: 18px 0 14px;
}
.msg {
  display: flex;
  gap: 10px;
  margin: 14px 0;
  animation: rise 0.28s ease both;
}
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg .mini-avatar {
  width: 30px;
  height: 30px;
  border-radius: 11px;
  flex: none;
  display: grid;
  place-items: center;
  font-size: 13px;
  background: linear-gradient(145deg, var(--mint), #5ab6ff);
  color: #06221d;
  font-weight: 700;
  margin-top: 2px;
}
.msg.user { flex-direction: row-reverse; }
.msg.user .mini-avatar { background: rgba(255, 255, 255, 0.08); color: var(--muted); }
.bubble-wrap { max-width: min(76%, 560px); display: flex; flex-direction: column; gap: 6px; }
.msg.user .bubble-wrap { align-items: flex-end; }
.bubble {
  padding: 12px 15px;
  border-radius: 17px;
  font-size: 14.5px;
  line-height: 1.62;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--panel-solid);
  border: 1px solid var(--border);
  border-top-left-radius: 6px;
}
.msg.user .bubble {
  background: linear-gradient(135deg, rgba(126, 231, 199, 0.92), rgba(98, 201, 255, 0.85));
  color: #052019;
  border: none;
  border-top-left-radius: 17px;
  border-top-right-radius: 6px;
  font-weight: 500;
}
.bubble.error { border-color: rgba(255, 138, 138, 0.4); color: #ffc9c9; }
.msg-meta { font-size: 10px; color: var(--faint); padding: 0 3px; }
.audio-row { display: flex; align-items: center; gap: 8px; }
.audio-row audio { height: 34px; max-width: 260px; }
.play-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: rgba(126, 231, 199, 0.12);
  color: var(--mint);
  display: grid;
  place-items: center;
}
.play-btn:hover { background: rgba(126, 231, 199, 0.22); }
.audio-loading { font-size: 11px; color: var(--muted); }

.empty-state {
  margin: 18vh auto 0;
  max-width: 320px;
  text-align: center;
  color: var(--muted);
}
.empty-state .big { font-size: 34px; margin-bottom: 10px; }
.empty-state p { font-size: 13px; line-height: 1.7; }

/* ---------- typing ---------- */
.typing { display: flex; gap: 5px; padding: 2px 14px 8px; }
.typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--mint);
  opacity: 0.35;
  animation: blink 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.18s; }
.typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* ---------- composer ---------- */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 9px;
  padding: 10px 4px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 62%, transparent);
}
.mic, .send {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 15px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.045);
  color: var(--muted);
  display: grid;
  place-items: center;
  transition: 0.18s ease;
}
.mic:hover { color: var(--mint); border-color: rgba(126, 231, 199, 0.4); }
.mic.recording { color: #ff9d9d; border-color: rgba(255, 138, 138, 0.55); background: rgba(255, 138, 138, 0.1); }
.send {
  background: linear-gradient(135deg, var(--mint), #62c9ff);
  color: #052019;
  border: none;
}
.send:disabled { opacity: 0.45; }
#input {
  flex: 1;
  min-height: 44px;
  max-height: 140px;
  resize: none;
  padding: 12px 15px;
  border-radius: 15px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.045);
  outline: none;
  line-height: 1.5;
  font-size: 14.5px;
}
#input:focus { border-color: rgba(126, 231, 199, 0.4); background: rgba(255, 255, 255, 0.06); }
#input::placeholder { color: var(--faint); }

.recording {
  position: fixed;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(28, 16, 18, 0.92);
  border: 1px solid rgba(255, 138, 138, 0.4);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 20;
  box-shadow: var(--shadow);
}
.rec-dot { width: 9px; height: 9px; border-radius: 50%; background: #ff6b6b; animation: pulse 1s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
.rec-hint { color: var(--faint); font-size: 11px; }

/* ---------- drawer ---------- */
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100dvh;
  width: min(400px, 92vw);
  background: rgba(14, 19, 26, 0.97);
  border-left: 1px solid var(--border);
  backdrop-filter: blur(20px);
  transform: translateX(105%);
  transition: transform 0.28s cubic-bezier(0.22, 0.8, 0.25, 1);
  z-index: 40;
  padding: 22px 20px;
  overflow-y: auto;
}
.drawer.open { transform: translateX(0); }
.drawer-head, .modal-head { display: flex; align-items: center; justify-content: space-between; }
.drawer-head h2, .modal-head h2 { margin: 0; font-size: 17px; }
.drawer-sub { color: var(--faint); font-size: 12px; line-height: 1.6; margin: 8px 0 18px; }
.icon-btn {
  width: 32px; height: 32px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
}
.task-list { display: flex; flex-direction: column; gap: 10px; }
.task-card {
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 13px 14px;
}
.task-top { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.task-type { font-size: 13px; font-weight: 600; }
.task-time { font-size: 10.5px; color: var(--faint); }
.chip {
  font-size: 10.5px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--muted);
}
.chip.queued { color: var(--warm); background: rgba(255, 214, 165, 0.1); }
.chip.running, .chip.claimed { color: var(--blue); background: rgba(138, 180, 255, 0.1); }
.chip.succeeded { color: var(--mint); background: rgba(126, 231, 199, 0.1); }
.chip.failed { color: var(--danger); background: rgba(255, 138, 138, 0.1); }
.progress { height: 3px; background: rgba(255, 255, 255, 0.07); border-radius: 2px; margin: 10px 0 8px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--mint), var(--blue)); width: 0; transition: width 0.3s; }
.task-msg { font-size: 11.5px; color: var(--muted); line-height: 1.5; word-break: break-word; }
.task-card audio { width: 100%; height: 34px; margin-top: 8px; }
.task-card a { color: var(--blue); font-size: 11.5px; }
.mask {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
  z-index: 30;
}

/* ---------- modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
}
.modal-card {
  width: min(520px, 100%);
  max-height: 86dvh;
  overflow-y: auto;
  background: var(--panel-solid);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 22px 22px 18px;
  box-shadow: var(--shadow);
}
.setting-group { border-top: 1px solid var(--border); margin-top: 18px; padding-top: 16px; }
.setting-group h3 { margin: 0 0 12px; font-size: 13px; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; }
.switch-row { display: flex; align-items: center; justify-content: space-between; font-size: 13.5px; margin-bottom: 12px; }
.switch-row input { width: 40px; height: 22px; accent-color: var(--mint-deep); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-size: 12.5px; color: var(--muted); }
.field select, .field input, .memory-add input {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.22);
  outline: none;
  color: var(--text);
}
.field-hint { font-size: 11.5px; color: var(--faint); line-height: 1.55; margin: 4px 0; }
.memory-add { display: flex; gap: 8px; margin: 8px 0 10px; }
.memory-add input { flex: 1; }
.small { padding: 8px 13px; border-radius: 10px; border: 1px solid var(--border); background: rgba(255, 255, 255, 0.05); font-size: 12px; }
.danger { color: var(--danger); border-color: rgba(255, 138, 138, 0.3); }
.memory-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 7px; max-height: 190px; overflow-y: auto; }
.memory-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--border);
  padding: 9px 11px;
  border-radius: 10px;
  font-size: 12.5px;
}
.memory-list button { background: none; border: none; color: var(--faint); font-size: 15px; }
.memory-list button:hover { color: var(--danger); }
.version { text-align: center; color: var(--faint); font-size: 10.5px; margin: 18px 0 0; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 86px;
  transform: translate(-50%, 18px);
  background: rgba(24, 31, 40, 0.96);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 12.5px;
  opacity: 0;
  pointer-events: none;
  transition: 0.25s ease;
  z-index: 80;
  max-width: 86vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 640px) {
  .shell { padding: 0 10px; }
  .topbar { padding-top: 12px; }
  .bubble-wrap { max-width: 84%; }
  .brand-text h1 { font-size: 16px; }
  .ghost { padding: 7px 10px; }
  .drawer { width: 100vw; }
  .composer { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
}
