:root {
  --bg: #f3f4f6;
  --mine: #b7e39a;
  --her: #ffffff;
  --text: #1c1e21;
  --sub: #8a8f99;
  --accent: #5b8def;
  --border: #e4e6ea;
  --head: #ffffff;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; height: 100%; height: 100dvh;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Microsoft YaHei UI", "PingFang SC", sans-serif;
  font-size: 15px; overscroll-behavior: none;
}

body { display: flex; flex-direction: column; }

.muted { color: var(--sub); font-size: 13px; }
.err { color: #d0453f; font-size: 13px; min-height: 18px; margin: 8px 0 0; }

#gate {
  position: fixed; inset: 0; z-index: 50;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
#gate.hide { display: none; }
.gate-card {
  width: 100%; max-width: 320px; text-align: center;
  background: var(--her); border: 1px solid var(--border); border-radius: 16px;
  padding: 26px 22px;
}
.gate-avatar { width: 72px; height: 72px; border-radius: 18px; }
.gate-card h1 { font-size: 16px; font-weight: 500; margin: 12px 0 6px; }
#gate-input {
  width: 100%; margin: 14px 0 10px; padding: 11px 12px;
  border: 1px solid var(--border); border-radius: 10px;
  font-size: 14px; background: #fafbfc; color: var(--text);
}
#gate-input:focus { outline: none; border-color: var(--accent); }
#gate-btn {
  width: 100%; padding: 11px; border: 0; border-radius: 10px;
  background: var(--accent); color: #fff; font-size: 15px; font-weight: 500;
}

.head {
  flex: 0 0 auto; display: flex; align-items: center; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 10px 8px;
  background: var(--head); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.icon-btn {
  width: 34px; height: 34px; border: 0; background: transparent; color: var(--sub);
  display: flex; align-items: center; justify-content: center; border-radius: 8px;
}
.head-avatar { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; background: #eef1f5; }
.head-main { flex: 1 1 auto; min-width: 0; }
.head-title { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.head-sub { display: flex; gap: 10px; color: var(--sub); font-size: 12px; margin-top: 2px; }
.chip {
  border: 1px solid var(--border); background: #f7f8fa; color: var(--sub);
  font-size: 11px; padding: 1px 7px; border-radius: 20px; line-height: 17px;
}
.chip.on { color: #2f7d4f; border-color: #cfe7d8; background: #eef8f1; }
.chip.sleep { color: #8a6d3b; border-color: #eadfc4; background: #fdf6e7; }
.chip.busy { color: #8a5a3b; border-color: #efdbc9; background: #fdf1e8; }
.chip.away { color: #6b6f7a; border-color: #e2e4e9; background: #f2f3f5; }
.chip.rel { color: #4a6fa5; border-color: #cfdcf0; background: #eef3fb; cursor: pointer; }

/* ---- 关系档案 ---- */
.rel-wrap { padding: 2px 0 6px; }
.rel-stage { font-size: 20px; font-weight: 600; margin-bottom: 2px; }
.rel-line { color: var(--sub); font-size: 12px; margin-bottom: 10px; }
.rel-bar { height: 8px; border-radius: 4px; background: #e6e9ee; overflow: hidden; }
.rel-bar > i { display: block; height: 100%; background: #5b8def; }
.rel-bar-txt { color: var(--sub); font-size: 11px; margin-top: 4px; }
.rel-row { display: flex; justify-content: space-between; padding: 8px 0;
  border-bottom: 1px solid #f0f1f4; font-size: 13px; }
.rel-row:last-child { border-bottom: none; }
.rel-row b { font-weight: 600; }
.rel-sec { font-size: 12px; color: var(--sub); margin: 14px 0 6px; }
.rel-log { font-size: 12px; line-height: 1.7; max-height: 190px; overflow-y: auto; }
.rel-log div { color: #444; }
.rel-log .up { color: #2f7d4f; }
.rel-log .down { color: #b4453b; }

.chat {
  flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 12px 12px 160px; display: flex; flex-direction: column; gap: 8px;
}

.bubble-row { display: flex; gap: 8px; align-items: flex-end; max-width: 100%; }
.bubble-row.me { justify-content: flex-end; }
.bubble {
  max-width: 78%; padding: 9px 12px; border-radius: 14px;
  background: var(--her); color: var(--text); border: 1px solid var(--border);
  white-space: pre-wrap; word-break: break-word; line-height: 1.55;
  font-size: 15px;
}
.me .bubble { background: var(--mine); border-color: #a8d78c; }
.bubble.recalld {
  background: #f4f4f6; color: var(--sub); border-style: dashed;
  font-size: 13px; text-align: center;
}
.who {
  font-size: 11px; color: var(--sub); margin: 0 0 3px 2px;
}
.divider {
  align-self: center; color: var(--sub); font-size: 11px;
  background: rgba(0,0,0,.04); padding: 2px 10px; border-radius: 20px; margin: 6px 0;
}
.typing { display: inline-flex; gap: 4px; align-items: center; }
.typing i {
  width: 5px; height: 5px; border-radius: 50%; background: var(--sub); display: block;
  animation: blink 1.2s infinite ease-in-out;
}
.typing i:nth-child(2) { animation-delay: .18s; }
.typing i:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

.sprite {
  position: fixed; left: -14px; bottom: calc(66px + var(--safe-b));
  width: 44vw; max-width: 220px; pointer-events: auto;
  filter: drop-shadow(0 6px 14px rgba(0,0,0,.08));
  transition: transform .18s ease;
  z-index: 5;
  touch-action: none;          /* 拖动立绘时不要触发页面滚动 */
  user-select: none; -webkit-user-select: none;
  cursor: grab;
}
.sprite.dragging {
  transition: none !important;  /* 拖动跟手，不要过渡拖尾 */
  cursor: grabbing;
  opacity: .92;
}
.sprite.bounce { transform: translateY(-10px) rotate(-2deg); }

.inputbar {
  flex: 0 0 auto; display: flex; gap: 8px; align-items: flex-end;
  padding: 8px 10px calc(8px + var(--safe-b));
  background: var(--head); border-top: 1px solid var(--border);
  position: sticky; bottom: 0; z-index: 20;
}
#text {
  flex: 1 1 auto; resize: none; max-height: 120px;
  border: 1px solid var(--border); border-radius: 12px;
  padding: 9px 12px; font-size: 15px; line-height: 1.4;
  background: #fafbfc; color: var(--text); font-family: inherit;
}
#text:focus { outline: none; border-color: var(--accent); }
.send {
  flex: 0 0 auto; border: 0; border-radius: 12px; padding: 10px 16px;
  background: #31a24c; color: #fff; font-size: 15px; font-weight: 500;
}
.send:disabled { background: #cbd2dc; }

.pick {
  flex: 0 0 auto; width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid var(--border); background: #fafbfc; color: var(--sub);
  font-size: 22px; line-height: 1; display: flex; align-items: center;
  justify-content: center; padding: 0; margin-bottom: 1px;
}
.pick:active { background: #eef1f5; }

/* 聊天里的照片缩略图（我发的图） */
.photo-thumb {
  display: block; max-width: 172px; max-height: 172px;
  border-radius: 10px; object-fit: cover;
}
.photo-thumb + .s-txt { margin-top: 4px; }

.drawer {
  position: fixed; top: 0; left: 0; bottom: 0; width: 76%; max-width: 300px;
  background: #eceef2; transform: translateX(-102%);
  transition: transform .22s ease; z-index: 30; overflow-y: auto;
  padding-bottom: 20px;
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  font-size: 12px; color: var(--sub); padding: 14px 16px 6px;
}
.drawer-list { background: var(--head); }
.d-item {
  display: flex; align-items: center; gap: 10px; padding: 11px 16px;
  border-bottom: 1px solid var(--border);
}
.d-item.active { background: #dfe7f7; }
.d-item img { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; background: #eef1f5; }
.d-item .d-name { font-size: 15px; }
.d-item .d-sub { font-size: 11px; color: var(--sub); }
.scrim {
  position: fixed; inset: 0; background: rgba(0,0,0,.25);
  opacity: 0; pointer-events: none; transition: opacity .2s ease; z-index: 25;
}
.scrim.on { opacity: 1; pointer-events: auto; }

.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%) translateY(10px);
  background: rgba(28,30,33,.9); color: #fff; font-size: 13px;
  padding: 8px 14px; border-radius: 10px; opacity: 0;
  transition: opacity .2s ease, transform .2s ease; pointer-events: none; z-index: 40;
  max-width: 80vw; text-align: center;
}
.toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }

.poke {
  position: fixed; left: 12px; bottom: calc(120px + var(--safe-b));
  font-size: 13px; color: #fff; background: rgba(28,30,33,.82);
  padding: 6px 12px; border-radius: 12px; opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .2s ease; transform: translateY(6px); z-index: 6;
}
.poke.on { opacity: 1; transform: translateY(0); }

.install {
  position: fixed; left: 10px; right: 10px; bottom: calc(72px + var(--safe-b));
  display: flex; align-items: center; gap: 8px;
  background: var(--head); border: 1px solid var(--border); border-radius: 14px;
  padding: 9px 12px; z-index: 22;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .08);
}
.install.hide { display: none; }
.install-ico { color: var(--accent); font-size: 15px; }
.install-txt { flex: 1 1 auto; font-size: 12px; color: var(--sub); line-height: 1.45; }
.install-yes {
  border: 0; border-radius: 9px; background: var(--accent); color: #fff;
  font-size: 13px; padding: 6px 12px;
}
.install-yes.hide { display: none; }
.install-no {
  border: 0; background: transparent; color: var(--sub); font-size: 18px;
  line-height: 1; padding: 0 2px;
}

.d-ico { width: 36px; text-align: center; color: var(--accent); font-size: 16px; }

.sheet {
  position: fixed; inset: 0; z-index: 45; background: rgba(0, 0, 0, .28);
  display: flex; align-items: flex-end;
}
.sheet.hide { display: none; }
.sheet-card {
  width: 100%; background: var(--her); border-radius: 18px 18px 0 0;
  padding: 18px 18px calc(18px + var(--safe-b));
}
.sheet-title { font-size: 15px; font-weight: 500; margin-bottom: 10px; }
.sheet-body { font-size: 13px; color: var(--text); line-height: 1.85; }
.sheet-body b { font-weight: 500; color: var(--accent); }
.sheet-body .s-note { color: var(--sub); font-size: 12px; }
.sheet-close {
  width: 100%; margin-top: 14px; border: 0; border-radius: 12px;
  background: #eef1f5; color: var(--text); font-size: 15px; padding: 11px;
}


.sticker-img {
  max-width: 116px; max-height: 116px; display: block; margin: 2px 0;
}
.bubble .s-txt { margin-top: 4px; }

.of-grid { display: flex; flex-wrap: wrap; gap: 7px; margin: 8px 0 4px; }
.of-chip {
  border: 1px solid var(--border); background: #f7f8fa; color: var(--text);
  font-size: 13px; padding: 7px 13px; border-radius: 20px;
}
.of-chip.cur { background: #dfe7f7; border-color: var(--accent); color: var(--accent); }
.gen-btns { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.gen-btn {
  border: 1px solid var(--border); background: #f7f8fa; color: var(--text);
  border-radius: 12px; padding: 11px 12px; font-size: 14px; text-align: left;
}
.gen-btn b { font-weight: 500; }
.gen-btn .g-sub { display: block; font-size: 12px; color: var(--sub); margin-top: 2px; }
.gen-status {
  margin-top: 10px; font-size: 13px; color: var(--sub);
  min-height: 20px; white-space: pre-wrap;
}
.net-off { color: #d0453f !important; font-size: 11px; }
