/* ============================================================
   陪聊AI —— 全局样式
   设计语言：清新青绿渐变 + 毛玻璃 + 柔和圆角，自动适配深色模式
   ============================================================ */

:root {
  /* 主题渐变色：翡翠 → 青碧 → 天青 */
  --grad-1: #10b981;
  --grad-2: #14b8a6;
  --grad-3: #0ea5e9;
  --primary: #0d9488;

  /* 浅色模式 */
  --bg: #f3f7f5;
  --surface: rgba(255, 255, 255, 0.78);
  --surface-solid: #ffffff;
  --bubble-other: #ffffff;
  --text: #182b26;
  --text-sub: #7d928b;
  --hairline: rgba(15, 45, 38, 0.08);
  --shadow: 0 8px 28px rgba(13, 110, 95, 0.10);
  --input-bg: rgba(16, 145, 120, 0.07);
  --key-bg: rgba(255, 255, 255, 0.65);
  --key-active: rgba(13, 148, 136, 0.16);
  --scrim: rgba(10, 25, 21, 0.5);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1513;
    --surface: rgba(23, 34, 30, 0.78);
    --surface-solid: #1a2521;
    --bubble-other: #22302a;
    --text: #e8f1ec;
    --text-sub: #83968d;
    --hairline: rgba(255, 255, 255, 0.08);
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
    --input-bg: rgba(45, 212, 191, 0.10);
    --key-bg: rgba(255, 255, 255, 0.07);
    --key-active: rgba(45, 212, 191, 0.22);
    --scrim: rgba(0, 0, 0, 0.6);
  }
}

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

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC",
    "MiSans", "Segoe UI", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; border: none; background: none; color: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* ---------- 背景光斑 ---------- */
.bg-orbs { position: fixed; inset: 0; overflow: hidden; z-index: 0; pointer-events: none; }
.bg-orbs i {
  position: absolute; border-radius: 50%; filter: blur(70px); opacity: 0.5;
  animation: orb-float 16s ease-in-out infinite alternate;
}
.bg-orbs i:nth-child(1) {
  width: 46vmax; height: 46vmax; left: -14vmax; top: -12vmax;
  background: radial-gradient(circle, var(--grad-1), transparent 68%);
}
.bg-orbs i:nth-child(2) {
  width: 40vmax; height: 40vmax; right: -12vmax; top: 26%;
  background: radial-gradient(circle, var(--grad-3), transparent 68%);
  animation-delay: -6s;
}
.bg-orbs i:nth-child(3) {
  width: 36vmax; height: 36vmax; left: 8vmax; bottom: -14vmax;
  background: radial-gradient(circle, var(--grad-2), transparent 68%);
  animation-delay: -11s;
}
@media (prefers-color-scheme: dark) { .bg-orbs i { opacity: 0.3; } }
@keyframes orb-float {
  from { transform: translate(0, 0) scale(1); }
  to   { transform: translate(4vmax, -3vmax) scale(1.12); }
}

/* ---------- 通用毛玻璃 ---------- */
.glass {
  background: var(--surface);
  -webkit-backdrop-filter: blur(24px) saturate(1.5);
  backdrop-filter: blur(24px) saturate(1.5);
}

/* ---------- 视图容器 ---------- */
.view {
  position: fixed; inset: 0; z-index: 1;
  display: flex; flex-direction: column;
  animation: view-in 0.35s ease both;
}
@keyframes view-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

/* ============================================================
   登录 / 密语 / PIN 设置（认证类页面）
   ============================================================ */
.auth-view {
  align-items: center; justify-content: center;
  padding: 24px;
  padding-top: max(24px, env(safe-area-inset-top));
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  overflow-y: auto;
}

.auth-card {
  width: 100%; max-width: 360px;
  border-radius: 28px;
  border: 1px solid var(--hairline);
  box-shadow: var(--shadow);
  padding: 40px 30px 28px;
  text-align: center;
}

.logo {
  font-size: 52px; line-height: 1;
  margin-bottom: 14px;
  filter: drop-shadow(0 6px 16px rgba(13, 148, 136,0.35));
}

.auth-card h1 {
  font-size: 26px; font-weight: 700; letter-spacing: 6px;
  background: linear-gradient(120deg, var(--grad-1), var(--grad-2), var(--grad-3));
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
}

.subtitle {
  color: var(--text-sub); font-size: 13px; line-height: 1.7;
  margin: 10px 0 26px;
}

.field { margin-bottom: 14px; }

/* 机密输入框：text 类型 + 圆点遮罩（保留输入法可用），带明文切换按钮 */
.field-secret { position: relative; }
.field-secret input { padding-right: 52px; }
.masked { -webkit-text-security: disc; }
.eye-btn {
  position: absolute; right: 7px; top: 50%;
  transform: translateY(-50%);
  width: 38px; height: 38px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-sub);
  transition: color 0.15s, background 0.15s;
}
.eye-btn:active { color: var(--primary); background: var(--input-bg); }
.eye-btn.revealed { color: var(--primary); }
.field input {
  width: 100%; height: 50px;
  border: 1.5px solid transparent; border-radius: 16px;
  background: var(--input-bg);
  color: var(--text); font-size: 16px;
  padding: 0 18px; outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.field input::placeholder { color: var(--text-sub); }
.field input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(13, 148, 136,0.15);
}

.btn-primary {
  width: 100%; height: 50px;
  border-radius: 16px;
  background: linear-gradient(120deg, var(--grad-1), var(--grad-2) 55%, var(--grad-3));
  background-size: 160% 100%;
  color: #fff; font-size: 16px; font-weight: 600; letter-spacing: 2px;
  box-shadow: 0 10px 24px rgba(13, 148, 136,0.35);
  transition: transform 0.15s, box-shadow 0.15s, background-position 0.4s, opacity 0.2s;
}
.btn-primary:active { transform: scale(0.97); background-position: 100% 0; }
.btn-primary:disabled { opacity: 0.6; }

.btn-text {
  margin-top: 18px; padding: 8px;
  color: var(--text-sub); font-size: 13px;
  transition: color 0.2s;
}
.btn-text:active { color: var(--primary); }

.error-msg {
  min-height: 18px; margin: 2px 0 10px;
  color: #f0446c; font-size: 13px;
}

/* ============================================================
   PIN 码：圆点 + 数字键盘（设置页与锁屏共用）
   ============================================================ */
.pin-dots {
  display: flex; justify-content: center; gap: 16px;
  margin: 20px 0 26px; height: 14px;
}
.pin-dots span {
  width: 13px; height: 13px; border-radius: 50%;
  border: 1.5px solid var(--text-sub);
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}
.pin-dots span.filled {
  border-color: var(--primary);
  background: linear-gradient(120deg, var(--grad-1), var(--grad-2));
  transform: scale(1.15);
}
.pin-dots.shake { animation: dots-shake 0.4s; }
@keyframes dots-shake {
  20% { transform: translateX(-9px); } 40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); } 80% { transform: translateX(4px); }
}

.pin-pad {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 12px; max-width: 264px; margin: 0 auto;
}
.pin-pad button {
  height: 62px; border-radius: 20px;
  background: var(--key-bg);
  border: 1px solid var(--hairline);
  font-size: 24px; font-weight: 500; color: var(--text);
  display: flex; align-items: center; justify-content: center;
  transition: background 0.12s, transform 0.12s;
}
.pin-pad button:active { background: var(--key-active); transform: scale(0.94); }
.pin-pad button.pad-empty { visibility: hidden; }
.pin-pad button.pad-fn { font-size: 18px; color: var(--text-sub); }

/* ============================================================
   聊天视图
   ============================================================ */
.chat-view { z-index: 2; }

.chat-header {
  position: relative; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  padding-top: max(10px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--hairline);
}

.peer-info { display: flex; align-items: center; gap: 12px; }

.avatar {
  position: relative;
  width: 44px; height: 44px; border-radius: 16px;
  background: linear-gradient(135deg, var(--grad-1), var(--grad-3));
  color: #fff; font-size: 19px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px rgba(13, 148, 136,0.3);
}

.online-dot {
  position: absolute; right: -3px; bottom: -3px;
  width: 13px; height: 13px; border-radius: 50%;
  background: #9aa0b5;
  border: 2.5px solid var(--surface-solid);
  transition: background 0.3s;
}
.online-dot.online { background: #34d399; }

.peer-name { font-size: 16px; font-weight: 600; }
.peer-status { font-size: 12px; color: var(--text-sub); margin-top: 1px; }

.icon-btn {
  width: 42px; height: 42px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-sub);
  transition: background 0.15s, color 0.15s, transform 0.15s;
  flex-shrink: 0;
}
.icon-btn:active { background: var(--input-bg); color: var(--primary); transform: scale(0.92); }

/* ---------- 消息列表 ---------- */
.msg-list {
  flex: 1; overflow-y: auto;
  padding: 16px 14px 10px;
  display: flex; flex-direction: column; gap: 3px;
  /* 不设 scroll-behavior:smooth——它会把「瞬时定位到底部」也变成慢速动画，
     途中经过顶部还会误触发历史加载；平滑滚动由 JS 显式指定 */
  overscroll-behavior: contain;
}

.history-loading {
  text-align: center; color: var(--text-sub);
  font-size: 12px; padding: 8px;
}

.time-divider {
  align-self: center;
  font-size: 11px; color: var(--text-sub);
  background: var(--input-bg);
  padding: 4px 12px; border-radius: 999px;
  margin: 12px 0 8px;
}

.msg-row {
  display: flex; max-width: 100%;
  animation: bubble-in 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
}
.msg-row.mine { justify-content: flex-end; }
@keyframes bubble-in {
  from { opacity: 0; transform: translateY(10px) scale(0.96); }
  to   { opacity: 1; transform: none; }
}

.bubble {
  position: relative;
  max-width: 76%;
  padding: 10px 14px;
  font-size: 16px; line-height: 1.45;
  word-break: break-word; white-space: pre-wrap;
  border-radius: 20px;
  margin-bottom: 6px;
}
.msg-row.mine .bubble {
  background: linear-gradient(135deg, var(--grad-1), var(--grad-2) 70%, var(--grad-3));
  color: #fff;
  border-bottom-right-radius: 7px;
  box-shadow: 0 5px 16px rgba(13, 148, 136,0.3);
}
.msg-row.theirs .bubble {
  background: var(--bubble-other);
  color: var(--text);
  border-bottom-left-radius: 7px;
  border: 1px solid var(--hairline);
  box-shadow: 0 3px 10px rgba(15, 45, 38, 0.06);
}

.bubble a { color: inherit; text-decoration: underline; text-underline-offset: 3px; word-break: break-all; }
.msg-row.theirs .bubble a { color: var(--primary); }

/* 纯 emoji 消息放大显示、去掉气泡底色 */
.bubble.emoji-only {
  background: none !important; border: none !important; box-shadow: none !important;
  font-size: 44px; line-height: 1.25; padding: 2px 6px;
}

/* 图片消息 */
.bubble.img-bubble {
  padding: 4px; overflow: hidden; border-radius: 18px;
  background: var(--bubble-other) !important;
  border: 1px solid var(--hairline);
  box-shadow: 0 4px 14px rgba(15, 45, 38, 0.1) !important;
}
.bubble.img-bubble .img-box {
  position: relative;
  border-radius: 15px; overflow: hidden;
  min-width: 120px; min-height: 90px;
  max-width: 100%;
  background: var(--input-bg);
  display: flex; align-items: center; justify-content: center;
}
.bubble.img-bubble img {
  display: block; max-width: 100%; max-height: 320px;
  border-radius: 15px;
}
.img-spinner {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-sub); font-size: 12px;
}
.img-spinner::before {
  content: ""; width: 22px; height: 22px;
  border: 2.5px solid var(--text-sub); border-top-color: transparent;
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 消息状态（发送中 / 失败） */
.msg-meta {
  align-self: flex-end;
  font-size: 10px; color: var(--text-sub);
  margin: 0 4px 8px;
  display: flex; align-items: center; gap: 3px;
}
.msg-meta .sending {
  width: 11px; height: 11px;
  border: 1.5px solid var(--text-sub); border-top-color: transparent;
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
.msg-meta .failed { color: #f0446c; font-size: 12px; }

/* ---------- 消息引用 ---------- */
.quote-block {
  border-left: 3px solid var(--primary);
  background: var(--input-bg);
  border-radius: 8px;
  padding: 6px 10px;
  margin-bottom: 6px;
  cursor: pointer;
}
.msg-row.mine .bubble .quote-block {
  border-left-color: rgba(255, 255, 255, 0.7);
  background: rgba(255, 255, 255, 0.16);
}
.quote-who { font-size: 11px; font-weight: 600; opacity: 0.85; margin-bottom: 2px; }
.quote-text {
  font-size: 12px; line-height: 1.4; opacity: 0.8;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; word-break: break-all; white-space: normal;
}
.bubble.img-bubble.has-quote { padding: 8px; }
.bubble.img-bubble.has-quote .quote-block { margin-bottom: 8px; }

/* 输入框上方的引用预览栏 */
.quote-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px 0;
}
.quote-bar-main {
  flex: 1; min-width: 0;
  border-left: 3px solid var(--primary);
  background: var(--input-bg);
  border-radius: 8px;
  padding: 6px 10px;
}
.quote-bar .quote-text { -webkit-line-clamp: 1; }

/* 消息操作浮层：快捷表态 + 引用 */
.msg-action {
  position: fixed; z-index: 40;
  background: var(--surface-solid);
  border: 1px solid var(--hairline);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 4px;
  animation: action-in 0.15s ease both;
}
.reaction-row {
  display: flex; gap: 2px;
  padding-bottom: 4px; margin-bottom: 2px;
  border-bottom: 1px solid var(--hairline);
}
.reaction-row button {
  width: 38px; height: 38px; border-radius: 11px;
  font-size: 21px;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.12s, background 0.12s;
}
.reaction-row button:active { transform: scale(1.25); background: var(--input-bg); }
#btn-quote {
  width: 100%;
  padding: 8px 14px; font-size: 14px; color: var(--text);
  display: flex; align-items: center; justify-content: center; gap: 6px;
  border-radius: 11px;
  transition: background 0.12s;
}
#btn-quote:active { background: var(--input-bg); }

/* 气泡角落的表态胶囊 */
.msg-row { position: relative; }
.reaction-pills {
  position: absolute; bottom: -9px; z-index: 2;
  display: flex; gap: 4px;
}
.msg-row.mine .reaction-pills { right: 12px; }
.msg-row.theirs .reaction-pills { left: 12px; }
.reaction-pill {
  background: var(--surface-solid);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 13px; line-height: 1.3;
  box-shadow: 0 2px 8px rgba(15, 45, 38, 0.14);
  transition: transform 0.12s;
}
.reaction-pill:active { transform: scale(1.15); }
.reaction-pill.own {
  border-color: var(--primary);
  background: var(--input-bg);
}
.msg-row.has-reactions { margin-bottom: 12px; }
@keyframes action-in {
  from { opacity: 0; transform: scale(0.9); }
  to   { opacity: 1; transform: none; }
}

/* 引用跳转后的高亮提示 */
.msg-row.flash .bubble {
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.5) !important;
  transition: box-shadow 0.3s;
}

/* ---------- 输入区 ---------- */
.composer-wrap {
  position: relative; z-index: 5;
  border-top: 1px solid var(--hairline);
}

.composer {
  display: flex; align-items: flex-end; gap: 4px;
  padding: 8px 10px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}

#msg-input {
  flex: 1;
  max-height: 108px;
  border: none; outline: none; resize: none;
  background: var(--input-bg);
  border-radius: 20px;
  color: var(--text); font-size: 16px; line-height: 1.4;
  font-family: inherit;
  padding: 10px 16px;
  transition: box-shadow 0.2s;
}
#msg-input:focus { box-shadow: 0 0 0 3px rgba(13, 148, 136,0.18); }
#msg-input::placeholder { color: var(--text-sub); }

.send-btn {
  width: 42px; height: 42px; border-radius: 15px;
  background: linear-gradient(135deg, var(--grad-1), var(--grad-2));
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 5px 14px rgba(13, 148, 136,0.4);
  transition: transform 0.15s, opacity 0.2s;
  flex-shrink: 0;
}
.send-btn:active { transform: scale(0.9); }
.send-btn:disabled { opacity: 0.45; }

/* ---------- 表情面板 ---------- */
.emoji-panel {
  height: 288px;
  display: flex; flex-direction: column;
  border-top: 1px solid var(--hairline);
  animation: panel-up 0.25s ease both;
  padding-bottom: env(safe-area-inset-bottom);
}
@keyframes panel-up {
  from { transform: translateY(30px); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

.emoji-grid {
  flex: 1; overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  padding: 10px 12px;
  gap: 2px;
}
.emoji-grid button {
  font-size: 26px; height: 46px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.12s, transform 0.12s;
}
.emoji-grid button:active { background: var(--input-bg); transform: scale(1.25); }

.emoji-tabs {
  display: flex; justify-content: space-around;
  padding: 6px 8px;
  border-top: 1px solid var(--hairline);
}
.emoji-tabs button {
  font-size: 20px; width: 40px; height: 38px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  opacity: 0.55; transition: opacity 0.15s, background 0.15s;
}
.emoji-tabs button.active { opacity: 1; background: var(--input-bg); }

/* ============================================================
   锁屏遮罩（必须完全不透明，遮住聊天内容）
   ============================================================ */
.lock-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  animation: lock-in 0.2s ease both;
}
@keyframes lock-in { from { opacity: 0; } to { opacity: 1; } }

.lock-content {
  position: relative; z-index: 1;
  text-align: center; padding: 24px; width: 100%; max-width: 340px;
}

.lock-icon {
  width: 74px; height: 74px; margin: 0 auto 16px;
  border-radius: 26px;
  background: linear-gradient(135deg, var(--grad-1), var(--grad-3));
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 12px 30px rgba(13, 148, 136,0.4);
}

.lock-content h2 { font-size: 21px; font-weight: 700; letter-spacing: 2px; }
.lock-hint { color: var(--text-sub); font-size: 13px; margin-top: 8px; min-height: 18px; }

/* ============================================================
   深历史验证弹层
   ============================================================ */
.history-gate {
  position: fixed; inset: 0; z-index: 45;
  background: var(--scrim);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  animation: lock-in 0.2s ease both;
}
.gate-card {
  width: 100%; max-width: 320px;
  border-radius: 24px;
  border: 1px solid var(--hairline);
  box-shadow: var(--shadow);
  padding: 26px 22px 20px;
  text-align: center;
  animation: img-zoom 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.1) both;
}
.gate-icon { font-size: 38px; line-height: 1; margin-bottom: 10px; }
.gate-card h3 { font-size: 17px; font-weight: 700; }
.gate-card .subtitle { margin: 6px 0 16px; }
.gate-btns { display: flex; gap: 10px; align-items: center; }
.gate-btns .btn-text { margin-top: 0; flex-shrink: 0; }
.gate-btns .btn-primary { flex: 1; height: 44px; }

/* ============================================================
   图片全屏预览
   ============================================================ */
.img-viewer {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(6, 14, 12, 0.92);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  display: flex; align-items: center; justify-content: center;
  animation: lock-in 0.2s ease both;
}
.img-viewer img {
  max-width: 100vw; max-height: 100vh;
  animation: img-zoom 0.25s cubic-bezier(0.2, 0.9, 0.3, 1.1) both;
}
@keyframes img-zoom {
  from { transform: scale(0.86); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

/* ============================================================
   轻提示
   ============================================================ */
.toast {
  position: fixed; left: 50%; bottom: 110px; z-index: 80;
  transform: translateX(-50%);
  background: var(--scrim); color: #fff;
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  font-size: 14px; padding: 10px 20px; border-radius: 999px;
  max-width: 80vw; text-align: center;
  animation: toast-in 0.25s ease both;
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------- 滚动条（桌面调试时更精致） ---------- */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-thumb { background: rgba(100, 160, 145, 0.35); border-radius: 2px; }
::-webkit-scrollbar-track { background: transparent; }
