:root {
  --bg: #0b0c10;
  --bg-soft: #14161d;
  --bg-card: #191c25;
  --bg-card-2: #20242f;
  --line: rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.13);
  --text: #eef1f7;
  --text-dim: #9aa1b2;
  --text-faint: #6b7383;
  --accent: #7c5cff;
  --accent-soft: rgba(124, 92, 255, 0.16);
  --ok: #3ddc97;
  --warn: #ffb454;
  --bad: #ff5d6c;
  --radius: 16px;
  --tab-h: 62px;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  overscroll-behavior: none;
}

body { overflow: hidden; }

.hidden { display: none !important; }

button, input, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* ---------- app shell ---------- */

.app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
}

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px 12px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(124, 92, 255, 0.08), transparent);
  backdrop-filter: blur(12px);
}

.topbar-main { flex: 1 1 auto; min-width: 0; }

.top-title {
  font-size: 17px;
  font-weight: 650;
  letter-spacing: 0.2px;
}

.top-sub {
  font-size: 12px;
  color: var(--text-faint);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.view {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.view.no-scroll { overflow: hidden; }

/* ---------- tabs ---------- */

.tabs {
  flex: 0 0 auto;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: rgba(16, 18, 24, 0.96);
  backdrop-filter: blur(18px);
  border-top: 1px solid var(--line);
}

.tab {
  flex: 1 1 0;
  border: 0;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 10.5px;
  color: var(--text-faint);
  padding: 0;
  cursor: pointer;
  transition: color 0.15s;
}

.tab .tab-ico { font-size: 19px; line-height: 1; filter: grayscale(0.55) opacity(0.75); transition: filter 0.15s; }
.tab.active { color: var(--text); }
.tab.active .tab-ico { filter: none; }

/* ---------- generic ---------- */

.pad { padding: 16px; }
.stack > * + * { margin-top: 12px; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}

.card-title { font-size: 13px; color: var(--text-dim); font-weight: 600; letter-spacing: 0.3px; }
.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.small { font-size: 12.5px; }
.tiny { font-size: 11.5px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.center { text-align: center; }

.boot {
  padding: 64px 24px;
  text-align: center;
  color: var(--text-faint);
  font-size: 13px;
  letter-spacing: 0.5px;
}
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1 1 auto; min-width: 0; }
.wrap { flex-wrap: wrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.btn {
  border: 1px solid var(--line-strong);
  background: var(--bg-card-2);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 550;
  cursor: pointer;
  transition: transform 0.08s, background 0.15s, border-color 0.15s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); border-color: rgba(255, 93, 108, 0.35); }
.btn.block { display: block; width: 100%; }
.btn.sm { padding: 7px 12px; font-size: 13px; border-radius: 10px; }

.icon-btn {
  border: 1px solid var(--line);
  background: var(--bg-card);
  color: var(--text-dim);
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 17px;
  cursor: pointer;
  padding: 0;
}

.input, .textarea {
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  padding: 11px 13px;
  outline: none;
  transition: border-color 0.15s;
}
.input:focus, .textarea:focus { border-color: var(--accent); }
.textarea { resize: vertical; min-height: 84px; line-height: 1.5; }

.field { display: block; }
.field > .label { display: block; font-size: 12.5px; color: var(--text-dim); margin-bottom: 6px; }
.field > .hint { display: block; font-size: 11.5px; color: var(--text-faint); margin-top: 5px; line-height: 1.45; }

/* ---------- chat ---------- */

.chat {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}

.msgs {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg { display: flex; gap: 8px; max-width: 86%; }
.msg.me { align-self: flex-end; flex-direction: row-reverse; }

.avatar {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  user-select: none;
  margin-top: 2px;
}

.bubble {
  padding: 9px 13px;
  border-radius: 16px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14.5px;
  line-height: 1.6;
}
.msg.me .bubble {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}
.msg.me .avatar { background: #2f3444; }
.msg.err .bubble { background: rgba(255, 93, 108, 0.12); border-color: rgba(255, 93, 108, 0.3); color: #ffb3ba; }

.bubble-typing { color: var(--text-faint); }

.msg-time {
  align-self: flex-end;
  font-size: 10px;
  color: var(--text-faint);
  padding: 0 4px 2px;
}

.composer {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: rgba(16, 18, 24, 0.96);
  backdrop-filter: blur(14px);
}

.composer .textarea {
  min-height: 42px;
  max-height: 132px;
  border-radius: 21px;
  padding: 10px 15px;
  resize: none;
}

.send {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: #fff;
  font-size: 17px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.08s;
}
.send:disabled { opacity: 0.4; }
.send:active { transform: scale(0.94); }

/* ---------- list ---------- */

.list { padding: 8px 0; }
.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--line);
}
.list-item:last-child { border-bottom: 0; }
.list-item:active { background: rgba(255, 255, 255, 0.03); }

.list-main { flex: 1 1 auto; min-width: 0; }
.list-title { font-size: 15px; font-weight: 550; display: flex; align-items: center; gap: 6px; }
.list-sub { font-size: 12.5px; color: var(--text-faint); margin-top: 2px; }
.list-right { flex: 0 0 auto; font-size: 11.5px; color: var(--text-faint); }

/* ---------- empty ---------- */

.empty {
  padding: 46px 28px;
  text-align: center;
  color: var(--text-faint);
}
.empty-ico { font-size: 34px; margin-bottom: 10px; opacity: 0.85; }
.empty-title { font-size: 15px; color: var(--text-dim); font-weight: 600; margin-bottom: 6px; }
.empty-desc { font-size: 13px; line-height: 1.6; white-space: pre-line; }

/* ---------- memory ---------- */

.mem {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.mem-head { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; }
.mem-time { font-size: 11.5px; color: var(--text-faint); }
.mem-imp { font-size: 10.5px; color: var(--warn); letter-spacing: 1px; }
.mem-sum { font-size: 14px; line-height: 1.6; }
.mem-sub {
  margin-top: 7px;
  padding: 7px 10px;
  border-left: 2px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 8px 8px 0;
  font-size: 12.5px;
  color: #cbc5f5;
  line-height: 1.55;
}
.mem-tags { margin-top: 7px; display: flex; flex-wrap: wrap; gap: 5px; }
.tag {
  font-size: 10.5px;
  color: var(--text-dim);
  border: 1px solid var(--line-strong);
  padding: 1px 7px;
  border-radius: 20px;
}
.mem-del { margin-left: auto; }

/* ---------- status dot ---------- */

.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; flex: 0 0 auto; }
.dot.ok { background: var(--ok); box-shadow: 0 0 8px rgba(61, 220, 151, 0.5); }
.dot.bad { background: var(--bad); }
.dot.warn { background: var(--warn); }

/* ---------- gate ---------- */

.gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 30%, #1a1d28, #08090c 70%);
  padding: 24px;
  z-index: 100;
}
.gate-card { width: 100%; max-width: 320px; text-align: center; }
.gate-title { font-size: 19px; font-weight: 650; margin-bottom: 6px; }
.gate-sub { font-size: 13px; color: var(--text-faint); margin-bottom: 22px; }
.gate-card .btn { margin-top: 12px; }
.gate-err { margin-top: 12px; font-size: 12.5px; color: var(--bad); min-height: 18px; }

/* ---------- sheet ---------- */

.sheet-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 40;
  display: flex;
  align-items: flex-end;
  animation: fade 0.15s ease-out;
}
.sheet {
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--line-strong);
  padding: 8px 16px calc(18px + env(safe-area-inset-bottom));
  animation: slideup 0.2s cubic-bezier(0.2, 0.9, 0.3, 1);
}
.sheet-handle {
  width: 38px;
  height: 4px;
  border-radius: 2px;
  background: var(--line-strong);
  margin: 6px auto 14px;
}
.sheet-title { font-size: 16px; font-weight: 650; margin-bottom: 14px; }

@keyframes fade { from { opacity: 0; } }
@keyframes slideup { from { transform: translateY(24px); opacity: 0.6; } }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 18px);
  transform: translateX(-50%) translateY(10px);
  background: rgba(30, 34, 44, 0.96);
  border: 1px solid var(--line-strong);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 20px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 60;
  max-width: 82vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- misc ---------- */

.divider { height: 1px; background: var(--line); margin: 14px 0; }
.section-label {
  font-size: 11.5px;
  letter-spacing: 0.6px;
  color: var(--text-faint);
  padding: 16px 16px 6px;
  text-transform: uppercase;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--line-strong);
  font-size: 11.5px;
  color: var(--text-dim);
}
