/* 手机端样式 —— 移动优先，兼顾 iOS 安全区 */
:root {
  --accent: #14b8a6;
  --accent-soft: rgba(20, 184, 166, 0.12);
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #16181d;
  --text-2: #6b7280;
  --text-3: #9ca3af;
  --border: rgba(0, 0, 0, 0.1);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

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

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

body {
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;      /* dvh 让移动端地址栏收起/展开时布局不跳 */
}

/* ---------- 顶栏 ---------- */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(var(--safe-t) + 8px) 10px 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.title { flex: 1; display: flex; align-items: center; gap: 9px; min-width: 0; }
.avatar { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; background: var(--accent-soft); }
.title-text { min-width: 0; }
.name { margin: 0; font-size: 14px; font-weight: 700; }
.sub {
  margin: 0;
  font-size: 11px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.icon-btn {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text-2);
  font-size: 17px;
  line-height: 1;
}
.icon-btn:active { background: rgba(0, 0, 0, 0.06); }

/* ---------- 消息流 ---------- */
.msgs {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 12px 4px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.empty { margin: auto; color: var(--text-3); font-size: 13.5px; }

.msg { display: flex; flex-direction: column; align-items: flex-start; max-width: 86%; }
.msg.user { align-self: flex-end; align-items: flex-end; }

.bubble {
  padding: 9px 12px;
  border-radius: 15px;
  background: var(--surface);
  border: 1px solid var(--border);
  /* 长英文/URL 不撑破气泡 */
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.msg.user .bubble {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.msg.error .bubble { background: #fef2f2; border-color: #fecaca; color: #b91c1c; }
.msg .time { margin-top: 3px; font-size: 10.5px; color: var(--text-3); }

.bubble-images { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 5px; }
.bubble-images img {
  max-width: 150px;
  max-height: 150px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

/* 打字指示 */
.typing { display: flex; gap: 4px; padding: 12px; }
.typing i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-3);
  animation: blink 1.2s infinite ease-in-out;
}
.typing i:nth-child(2) { animation-delay: 0.2s; }
.typing i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.3; } 40% { opacity: 1; } }

/* ---------- 待发图片 ---------- */
.pending {
  flex: 0 0 auto;
  display: flex;
  gap: 6px;
  padding: 8px 12px 0;
  overflow-x: auto;
}
.pending-item { position: relative; flex: 0 0 auto; }
.pending-item img {
  width: 54px; height: 54px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.pending-del {
  position: absolute; top: -5px; right: -5px;
  width: 20px; height: 20px;
  border: none; border-radius: 50%;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 11px;
  line-height: 1;
}

/* ---------- 输入区 ---------- */
.composer {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 7px;
  padding: 8px 10px calc(var(--safe-b) + 8px);
  background: var(--surface);
  border-top: 1px solid var(--border);
}
#input {
  flex: 1;
  min-height: 40px;
  max-height: 120px;
  padding: 9px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  resize: none;
}
#input:focus { outline: none; border-color: var(--accent); }
.send {
  flex: 0 0 auto;
  width: 40px; height: 40px;
  border: none; border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 17px;
  line-height: 1;
}
.send:disabled { opacity: 0.4; }
.send.stop { background: #ef4444; font-size: 13px; }

.err-bar {
  padding: 6px 12px;
  background: #fef2f2;
  color: #b91c1c;
  font-size: 12px;
}

/* ---------- 抽屉 / 面板 ---------- */
.drawer {
  position: fixed;
  top: 0; bottom: 0; left: 0;
  width: min(82vw, 330px);
  z-index: 30;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-t);
}
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
}
.session-list { flex: 1; overflow-y: auto; list-style: none; margin: 0; padding: 6px; }
.session-item {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
  padding: 11px 12px;
  border-radius: 11px;
}
.session-item.active { background: var(--accent-soft); }
.session-item .t { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-item .m { font-size: 11px; color: var(--text-3); }
.session-del { border: none; background: transparent; color: var(--text-3); font-size: 15px; padding: 4px 6px; }

.scrim { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, 0.35); }

/*
 * 设置面板：外层撑满全屏（可点空白关闭），内层贴底显示。
 * 之前外层只占底部一块，没有「面板外」的区域可点，
 * 关掉只能靠 ✕ —— 而它和抽屉叠加时容易被挡，用户实测「关不掉」。
 */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  background: rgba(0, 0, 0, 0.35);
  padding-top: var(--safe-t);
}
.sheet-inner {
  max-height: 88dvh;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  display: flex;
  flex-direction: column;
  padding-bottom: var(--safe-b);
}
.sheet-head {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
}
/*
 * 面板主体必须能吃满剩余高度（flex:1）才形成滚动容器。
 * 缺了这条，内容会被 `.sheet-inner` 的 max-height 直接截断 ——
 * 图鉴有 17 项，超出部分就再也点不到了。
 */
.sheet-body { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 16px 20px; }

.field { display: block; margin-bottom: 15px; }
.field > span { display: block; margin-bottom: 5px; font-size: 12.5px; color: var(--text-2); }
.field small { display: block; margin-top: 4px; font-size: 11px; color: var(--text-3); line-height: 1.5; }
.field input, .field select {
  width: 100%;
  padding: 10px 11px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  /* 16px 可避免 iOS 聚焦时自动放大页面 */
  font-size: 16px;
}
.field .row { display: flex; align-items: center; gap: 8px; }
.field .row input { flex: 1; }

.sheet-actions { display: flex; gap: 9px; margin-top: 4px; }
.btn {
  flex: 1;
  padding: 11px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: #b91c1c; border-color: #fecaca; }

.test-result { margin: 10px 0 0; font-size: 12px; color: var(--text-2); white-space: pre-wrap; }

.danger-zone {
  margin-top: 26px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.danger-zone small { display: block; margin-top: 8px; font-size: 11px; color: var(--text-3); }

/* 大图预览 */
.lightbox {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center;
  background: rgba(0, 0, 0, 0.88);
  padding: 16px;
}
.lightbox img { max-width: 100%; max-height: 100%; }

/* ---------- 她的立绘（顶部常驻） ---------- */
.pet-strip {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: linear-gradient(180deg, var(--accent-soft), transparent);
}
.pet-img {
  width: 68px;
  height: 84px;
  object-fit: contain;
  flex: 0 0 auto;
  /* 和桌面端一致的轻浮动，别像静态贴图 */
  animation: pet-breathe 3.6s ease-in-out infinite;
}
@keyframes pet-breathe {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}
.pet-meta { min-width: 0; }
.pet-outfit { margin: 0; font-size: 13px; font-weight: 700; color: rgb(var(--theme-accent, 20 184 166)); }
.pet-note { margin: 2px 0 0; font-size: 11px; color: var(--text-3); }

/* ---------- 图鉴 ---------- */
.gallery-tip {
  margin: 0 0 12px;
  font-size: 12px;
  color: var(--text-3);
  line-height: 1.6;
}
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.g-item {
  position: relative;
  padding: 10px 8px;
  border-radius: 13px;
  border: 1px solid var(--border);
  background: var(--bg);
  text-align: center;
}
.g-item.locked { opacity: 0.55; }
.g-item img {
  width: 100%;
  height: 108px;
  object-fit: contain;
  display: block;
}
.g-item .g-title {
  margin: 6px 0 0;
  font-size: 12px;
  font-weight: 700;
}
.g-item .g-hint {
  margin: 3px 0 0;
  font-size: 10.5px;
  color: var(--text-3);
  line-height: 1.4;
}
/* 未解锁用剪影 + 问号，比直接藏起来更有「可收集」的感觉 */
.g-item.locked img { filter: brightness(0) opacity(0.25); }
.g-lock {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -60%);
  font-size: 22px;
}

/* ---------- 解锁动画 ---------- */
.reveal {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center;
  /*
   * 遮罩要足够实：这张卡是「她发来的照片」，背景透出图鉴卡片会显得
   * 她的身体和背后的小图叠在一起（实测截图里很脏）。
   */
  background: rgba(0, 0, 0, 0.88);
  backdrop-filter: blur(6px);
  padding: 22px;
}
.reveal-card {
  width: 100%;
  max-width: 330px;
  padding: 20px 18px 18px;
  border-radius: 18px;
  background: var(--surface);
  text-align: center;
  animation: reveal-pop 0.32s cubic-bezier(0.2, 0.9, 0.3, 1.3);
  /*
   * 必须自己形成层叠上下文（position + z-index），否则卡片内的元素都是
   * static，会跟图鉴卡片里同样是 static 的 .g-title/.g-hint 抢绘制顺序 ——
   * 立绘是透明 PNG，那些文字就从她身体里透出来（实测：腰上浮着「穿红外套」）。
   * 单独给 <img> 加背景盖不住，因为文字是在**图之上**被绘制的。
   */
  position: relative;
  z-index: 1;
}
@keyframes reveal-pop {
  from { opacity: 0; transform: scale(0.9) translateY(12px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.reveal-badge {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 700;
  color: rgb(var(--theme-accent, 20 184 166));
}
.reveal-img {
  width: 100%;
  max-height: 210px;
  object-fit: contain;
  /*
   * 立绘必须有不透明背景。
   * PNG 带透明通道，背后（图鉴卡片）的文字会从她的身体里透出来 ——
   * 实测截图里能看到腰部浮着「穿红外套」几个字，很脏。
   * 给图片本身一个和卡片一致的底色即可遮住。
   */
  background: var(--surface);
}
.reveal-title { margin: 10px 0 0; font-size: 15px; font-weight: 700; }
.reveal-line {
  margin: 6px 0 16px;
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.6;
}

/* 开关型字段：勾选框和文字同一行 */
.switch-field {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.switch-field > span { margin-bottom: 0; flex: 1; }
.switch-field > input[type="checkbox"] {
  width: 20px; height: 20px;
  margin: 0;
  accent-color: rgb(var(--theme-accent, 20 184 166));
}
.switch-field > small { flex: 0 0 100%; margin-top: 0; }
