/* ============ 主题变量 ============ */
:root, html[data-theme="sunset"] {
  --bg: #fdf3ec;
  --bg-grad: radial-gradient(120% 90% at 20% 0%, #ffe9dc 0%, #fdf3ec 55%, #fcefe4 100%);
  --surface: #ffffff;
  --surface-soft: #fff8f3;
  --text: #4a3733;
  --text-soft: #9b857d;
  --accent: #ff8f6b;
  --accent-strong: #f0704a;
  --accent-soft: #ffe3d8;
  --bubble-ai: #ffffff;
  --bubble-user: linear-gradient(135deg, #ff9d7a, #f0704a);
  --bubble-user-text: #ffffff;
  --border: #f3e0d4;
  --shadow: 0 2px 16px rgba(240, 112, 74, .09);
  --danger: #e5484d;
  --theme-color: #ff8f6b;
}
html[data-theme="mint"] {
  --bg: #f0f7f3;
  --bg-grad: radial-gradient(120% 90% at 20% 0%, #e2f2ea 0%, #f0f7f3 55%, #eef6f1 100%);
  --surface: #ffffff;
  --surface-soft: #f4faf7;
  --text: #2f443c;
  --text-soft: #7f9a8e;
  --accent: #3cb88c;
  --accent-strong: #2a9d74;
  --accent-soft: #d8f0e5;
  --bubble-ai: #ffffff;
  --bubble-user: linear-gradient(135deg, #4bc79a, #2a9d74);
  --bubble-user-text: #ffffff;
  --border: #dceee5;
  --shadow: 0 2px 16px rgba(42, 157, 116, .09);
  --danger: #e5484d;
  --theme-color: #3cb88c;
}
html[data-theme="night"] {
  --bg: #171a24;
  --bg-grad: radial-gradient(120% 90% at 20% 0%, #1e2230 0%, #171a24 55%, #141722 100%);
  --surface: #212636;
  --surface-soft: #1c2130;
  --text: #e4e2ef;
  --text-soft: #8d8ba3;
  --accent: #8f9bff;
  --accent-strong: #7484ff;
  --accent-soft: #2a3050;
  --bubble-ai: #262c40;
  --bubble-user: linear-gradient(135deg, #7d8cff, #5f6ff0);
  --bubble-user-text: #ffffff;
  --border: #2e3550;
  --shadow: 0 2px 16px rgba(0, 0, 0, .35);
  --danger: #ff6369;
  --theme-color: #171a24;
}

/* ============ 基础 ============ */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg-grad) fixed, var(--bg);
  color: var(--text);
  overflow: hidden;
}
.hidden { display: none !important; }
button { font-family: inherit; border: none; background: none; cursor: pointer; color: inherit; }
input, textarea { font-family: inherit; }

.phone {
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg-grad) fixed;
}

/* ============ 登录页 ============ */
.auth-view {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border-radius: 28px;
  padding: 36px 28px;
  box-shadow: var(--shadow);
  text-align: center;
}
.auth-logo { font-size: 44px; }
.auth-title { font-size: 26px; margin-top: 8px; letter-spacing: 2px; }
.auth-sub { color: var(--text-soft); font-size: 13px; margin-top: 6px; margin-bottom: 24px; }
.auth-tabs {
  display: flex;
  background: var(--surface-soft);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 20px;
}
.auth-tab {
  flex: 1;
  padding: 9px;
  border-radius: 9px;
  font-size: 14px;
  color: var(--text-soft);
  transition: all .2s;
}
.auth-tab.active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 6px rgba(0,0,0,.06); }
.input {
  width: 100%;
  padding: 13px 16px;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  background: var(--surface-soft);
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border .2s;
  margin-bottom: 12px;
  resize: none;
}
.input:focus { border-color: var(--accent); }
.btn-primary {
  width: 100%;
  padding: 14px;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  transition: transform .1s, background .2s;
}
.btn-primary:active { transform: scale(.97); }
.btn-primary:disabled { opacity: .55; }
.btn-secondary {
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 600;
}
.btn-secondary.full { width: 100%; }
.btn-danger-ghost {
  width: 100%;
  padding: 11px;
  border-radius: 12px;
  border: 1.5px dashed var(--danger);
  color: var(--danger);
  font-size: 13px;
  margin-bottom: 10px;
  background: transparent;
}
.auth-error { color: var(--danger); font-size: 13px; margin-top: 12px; }

/* ============ 顶栏 ============ */
.chat-view { height: 100%; display: flex; flex-direction: column; min-height: 0; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  z-index: 5;
}
.topbar-character { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}
.topbar-name { font-size: 16px; font-weight: 700; }
.topbar-status { font-size: 11px; color: var(--text-soft); margin-top: 1px; }
.topbar-actions { display: flex; gap: 4px; }
.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 19px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .2s;
  color: var(--text);
}
.icon-btn:active { background: var(--accent-soft); }
.icon-btn.rec { background: var(--danger); color: #fff; animation: pulse 1.1s infinite; }
@keyframes pulse { 50% { opacity: .55; } }

/* ============ 聊天区 ============ */
.chat-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 16px 14px 8px;
  min-height: 0;
}
.message-list { display: flex; flex-direction: column; gap: 4px; }

.greeting-card {
  background: var(--surface);
  border-radius: 20px;
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  animation: rise .4s ease;
}
.greeting-hello { font-size: 17px; font-weight: 700; }
.greeting-sub { font-size: 13px; color: var(--text-soft); margin-top: 6px; line-height: 1.6; }
.greeting-streak {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 600;
}

.msg-row { display: flex; gap: 8px; margin-bottom: 10px; align-items: flex-end; animation: rise .25s ease; }
.msg-row.mine { flex-direction: row-reverse; }
.msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
  margin-bottom: 2px;
}
.msg-body { max-width: 76%; display: flex; flex-direction: column; gap: 3px; }
.mine .msg-body { align-items: flex-end; }
.bubble {
  padding: 11px 15px;
  border-radius: 20px;
  font-size: 15px;
  line-height: 1.65;
  word-break: break-word;
  white-space: pre-wrap;
  box-shadow: var(--shadow);
}
.bubble-left { background: var(--bubble-ai); border-bottom-left-radius: 6px; }
.bubble-right {
  background: var(--bubble-user);
  color: var(--bubble-user-text);
  border-bottom-right-radius: 6px;
}
.msg-meta { display: flex; gap: 8px; padding: 0 6px; font-size: 10px; color: var(--text-soft); align-items: center; }
.msg-speak { font-size: 12px; opacity: .7; }
.msg-speak.speaking { color: var(--accent-strong); opacity: 1; }
.cursor { display: inline-block; width: 2px; height: 1em; background: var(--text-soft); vertical-align: -0.15em; animation: blink .8s infinite; }
@keyframes blink { 50% { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

.typing-row { display: flex; gap: 8px; margin-top: 2px; }
.typing { display: flex; gap: 5px; align-items: center; min-height: 42px; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-soft);
  animation: bounce 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 30% { transform: translateY(-4px); opacity: .5; } }

.date-divider {
  text-align: center;
  font-size: 11px;
  color: var(--text-soft);
  margin: 10px 0 14px;
}

/* ============ 输入栏 ============ */
.inputbar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px calc(env(safe-area-inset-bottom, 0px) + 10px);
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
}
.mic-btn { flex-shrink: 0; margin-bottom: 2px; }
.input-text {
  flex: 1;
  max-height: 120px;
  padding: 11px 16px;
  border-radius: 22px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  outline: none;
  resize: none;
  transition: border .2s;
}
.input-text:focus { border-color: var(--accent); }
.send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform .1s, opacity .2s;
}
.send-btn:active { transform: scale(.92); }
.send-btn:disabled { opacity: .4; }
.send-btn.stop { background: var(--text-soft); }

/* ============ 抽屉 ============ */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade .2s ease;
}
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: 100%;
  max-width: 520px;
  max-height: 86dvh;
  background: var(--surface);
  border-radius: 24px 24px 0 0;
  display: flex;
  flex-direction: column;
  animation: slideUp .28s cubic-bezier(.2,.9,.3,1);
}
@keyframes slideUp { from { transform: translateY(60px); opacity: .4; } }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--border); margin: 10px auto 0; }
.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px 10px;
  border-bottom: 1px solid var(--border);
}
.sheet-header h2 { font-size: 17px; }
.sheet-body { padding: 16px 20px calc(env(safe-area-inset-bottom, 0px) + 20px); overflow-y: auto; }

/* 角色 */
.character-list { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.character-card {
  padding: 16px 14px;
  border-radius: 18px;
  border: 2px solid var(--border);
  background: var(--surface-soft);
  text-align: left;
  transition: border .2s, transform .1s;
  position: relative;
}
.character-card:active { transform: scale(.97); }
.character-card.active { border-color: var(--accent); background: var(--accent-soft); }
.character-card .cc-emoji { font-size: 28px; }
.character-card .cc-name { font-size: 15px; font-weight: 700; margin-top: 6px; }
.character-card .cc-title { font-size: 11px; color: var(--accent-strong); margin-top: 1px; }
.character-card .cc-tagline { font-size: 12px; color: var(--text-soft); margin-top: 5px; line-height: 1.5; }
.character-card .cc-check {
  position: absolute; top: 10px; right: 12px;
  color: var(--accent-strong); font-size: 15px; font-weight: 700;
}
.divider {
  display: flex; align-items: center; gap: 12px;
  color: var(--text-soft); font-size: 12px;
  margin: 20px 0 14px;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.custom-form .custom-row { display: flex; gap: 10px; }
.custom-row .input { flex: 1; }
.emoji-input { width: 58px; text-align: center; flex: none; }
.custom-form textarea.input { min-height: 44px; height: auto; }

/* 记忆 */
.memory-note { font-size: 12.5px; color: var(--text-soft); line-height: 1.7; margin-bottom: 14px; }
.summary-box {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.7;
  margin-bottom: 14px;
  white-space: pre-wrap;
}
.summary-box .summary-title { font-size: 11px; color: var(--accent-strong); font-weight: 700; margin-bottom: 4px; }
.memory-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
}
.memory-item .mi-text { flex: 1; font-size: 14px; line-height: 1.6; }
.memory-item .mi-text input {
  width: 100%;
  padding: 8px 10px;
  border: 1.5px solid var(--accent);
  border-radius: 10px;
  background: var(--surface-soft);
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.memory-item .mi-ops { display: flex; gap: 2px; flex-shrink: 0; }
.memory-item .mi-ops button { font-size: 14px; padding: 4px 6px; opacity: .55; }
.memory-item .mi-ops button:active { opacity: 1; }
.empty-hint { text-align: center; color: var(--text-soft); font-size: 13.5px; line-height: 2; padding: 30px 0 10px; }
.empty-hint small { font-size: 11.5px; opacity: .7; }

/* 设置 */
.setting-section { margin-bottom: 24px; }
.setting-section h3 { font-size: 13px; color: var(--text-soft); font-weight: 600; margin-bottom: 10px; }
.setting-section h3 small { font-weight: 400; opacity: .7; }
.theme-row { display: flex; gap: 10px; }
.theme-swatch {
  flex: 1;
  height: 52px;
  border-radius: 14px;
  border: 2.5px solid transparent;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 6px;
  transition: border .2s, transform .1s;
}
.theme-swatch:active { transform: scale(.96); }
.theme-swatch.active { border-color: var(--text); }
.theme-sunset { background: linear-gradient(135deg, #ffe3d8, #ff9d7a); color: #a34a2c; }
.theme-mint { background: linear-gradient(135deg, #d8f0e5, #4bc79a); color: #1e6b4f; }
.theme-night { background: linear-gradient(135deg, #2a3050, #171a24); color: #aab2ff; }
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0 14px;
  font-size: 14.5px;
}
.switch { appearance: none; width: 46px; height: 27px; border-radius: 14px; background: var(--border); position: relative; transition: background .2s; outline: none; }
.switch:checked { background: var(--accent); }
.switch::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 21px; height: 21px;
  border-radius: 50%;
  background: #fff;
  transition: left .2s;
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
.switch:checked::after { left: 22px; }
.account-info { font-size: 13px; color: var(--text-soft); margin-bottom: 12px; line-height: 1.8; }
.admin-note { font-size: 12px; color: var(--accent-strong); background: var(--accent-soft); border-radius: 10px; padding: 10px 12px; line-height: 1.6; margin-bottom: 12px; }
.temp-label { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-soft); flex: 1; }
.temp-input { width: 76px; margin-bottom: 0; }
#btnSaveConfig { width: auto; padding: 10px 20px; }
.setting-section .input { margin-bottom: 10px; }

/* Toast */
.toast {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 90px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(30, 30, 34, .92);
  color: #fff;
  padding: 11px 20px;
  border-radius: 999px;
  font-size: 13.5px;
  z-index: 99;
  max-width: 82%;
  text-align: center;
  animation: toastIn .25s ease;
  box-shadow: 0 4px 20px rgba(0,0,0,.25);
}
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(8px); } }

/* 桌面上给手机框一点氛围 */
@media (min-width: 560px) {
  body { display: flex; align-items: center; justify-content: center; background: var(--bg); }
  .phone {
    height: min(880px, 94dvh);
    border-radius: 36px;
    overflow: hidden;
    box-shadow: 0 24px 80px rgba(0,0,0,.18);
    border: 1px solid var(--border);
  }
  .sheet-overlay { align-items: center; }
  .sheet { border-radius: 24px; max-height: 84vh; }
}
