/* 暖伴 · 移动端优先样式
   设计目标：字大、按钮大、对比清楚，老人也能上手。 */

:root {
  --bg: #fdf6ef;
  --bg-2: #ffffff;
  --ink: #2e2823;
  --ink-2: #6f645b;
  --ink-3: #a99c91;
  --line: #ece0d4;
  --accent: #e8825f;
  --accent-soft: #fdeee6;
  --bubble-me: #e8825f;
  --bubble-me-ink: #fff;
  --bubble-ai: #ffffff;
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1917;
    --bg-2: #262220;
    --ink: #f0e8e0;
    --ink-2: #b8ada3;
    --ink-3: #8b7f75;
    --line: #37312d;
    --accent: #e8825f;
    --accent-soft: #3a2a23;
    --bubble-me: #e8825f;
    --bubble-ai: #2c2724;
  }
}

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

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei",
               "Helvetica Neue", "Noto Sans CJK SC", sans-serif;
  font-size: 17px;
  line-height: 1.6;
  overscroll-behavior: none;
}

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

/* ── 启动页 ─────────────────────────────────────────── */
.splash {
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #fff3e9 0%, #fde9dd 100%);
  gap: 6px;
  transition: opacity .38s ease;
}
/* 淡出态：立即生效，不依赖任何定时器 */
.splash.bye { opacity: 0; pointer-events: none; }
.splash-logo { font-size: 64px; animation: float 2.4s ease-in-out infinite; }
@keyframes float { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-10px)} }
.splash-name { font-size: 30px; font-weight: 700; letter-spacing: 6px; margin-top: 10px; }
.splash-sub { color: #8a7a6c; font-size: 15px; }
.splash-tip { margin-top: 26px; color: #b3a498; font-size: 13px; }

/* ── 通用视图 ───────────────────────────────────────── */
.view { position: fixed; inset: 0; display: flex; flex-direction: column; }

/* ── 角色选择页 ─────────────────────────────────────── */
.home-head { padding: calc(28px + var(--safe-t)) 22px 10px; text-align: center; }
.home-title { font-size: 27px; font-weight: 700; letter-spacing: 5px; }
.home-sub { color: var(--ink-2); font-size: 15px; margin-top: 4px; }

.notice-bar {
  margin: 14px 16px 6px; padding: 12px 14px;
  background: var(--accent-soft); border-radius: 14px;
  color: var(--ink-2); font-size: 13.5px; line-height: 1.65;
}
.notice-bar b { color: var(--accent); }
.notice-bar.shared {
  background: #fff6e6; border: 1px solid #f0dcb4; color: #6d5220;
}
.notice-bar.shared b { color: #8a6420; }
.notice-close {
  display: block; margin-top: 8px; color: var(--accent);
  font-size: 13.5px; text-decoration: underline;
}

.role-list {
  flex: 1; overflow-y: auto; padding: 10px 16px 8px;
  -webkit-overflow-scrolling: touch;
}

.role-card {
  display: flex; align-items: center; gap: 14px;
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 14px;
  margin-bottom: 12px; width: 100%; text-align: left;
  transition: transform .12s ease, box-shadow .12s ease;
}
.role-card:active { transform: scale(.975); box-shadow: 0 2px 10px rgba(0,0,0,.06); }
.role-card .rc-avatar {
  width: 56px; height: 56px; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 29px; border-radius: 50%;
  background: var(--accent-soft);
}
.role-card .rc-main { flex: 1; min-width: 0; }
.role-card .rc-name { font-weight: 600; font-size: 18px; }
.role-card .rc-name .rc-rel {
  font-size: 12.5px; font-weight: 400; color: var(--accent);
  background: var(--accent-soft); padding: 2px 8px; border-radius: 20px; margin-left: 8px;
}
.role-card .rc-tag { color: var(--ink-2); font-size: 14px; margin-top: 2px; }
.role-card .rc-intro { color: var(--ink-3); font-size: 13px; margin-top: 4px; }
.role-card .rc-arrow { color: var(--ink-3); font-size: 22px; flex: none; }

.home-foot {
  padding: 10px 16px calc(16px + var(--safe-b));
  text-align: center; color: var(--ink-3); font-size: 13.5px;
}

/* ── 回忆模式 ──────────────────────────────────────── */
.role-card.legacy-entry {
  border-style: dashed;
  border-color: var(--accent);
  background: var(--accent-soft);
}
.role-card.legacy-entry .rc-avatar { background: rgba(226,130,95,.22); }

.legacy-bar {
  padding: 8px 14px;
  background: #fff4e0;
  color: #8a5a12;
  font-size: 12.5px;
  line-height: 1.5;
  border-bottom: 1px solid #f0d9ac;
}
.legacy-bar b { color: #b45309; }
@media (prefers-color-scheme: dark) {
  .legacy-bar { background: #3a2c17; color: #e6c58a; border-bottom-color: #55432a; }
  .legacy-bar b { color: #f0c98a; }
}

/* ── 向导 ──────────────────────────────────────────── */
.steps { display: flex; gap: 6px; margin-bottom: 14px; }
.step {
  flex: 1; text-align: center; font-size: 12.5px; padding: 7px 4px;
  border-radius: 10px; background: var(--bg-2); border: 1px solid var(--line); color: var(--ink-3);
}
.step.on { background: var(--accent); color: #fff; border-color: transparent; }
.step.done { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

.chip-wrap { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip {
  padding: 8px 14px; border-radius: 20px; border: 1px solid var(--line);
  background: var(--bg-2); font-size: 14.5px;
}
.chip.on { background: var(--accent); color: #fff; border-color: transparent; }
.chip small { opacity: .7; margin-left: 4px; font-size: 12px; }

.consent {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px; border-radius: 12px; background: #fff4e0;
  border: 1px solid #f0d9ac; margin: 12px 0; font-size: 13.5px; line-height: 1.6;
}
.consent input { width: 18px; height: 18px; margin-top: 2px; flex: none; }
.consent b { color: #b45309; }
@media (prefers-color-scheme: dark) {
  .consent { background: #3a2c17; border-color: #55432a; color: #e6c58a; }
  .consent b { color: #f0c98a; }
}

.tone-list { margin: 0 0 14px; padding-left: 20px; }
.tone-list li { font-size: 14px; margin: 5px 0; }

.rp-amounts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
.rp-card {
  border: 1px solid var(--line); border-radius: 14px; padding: 12px;
  background: var(--bg-2); text-align: center;
}
.rp-card.on { border-color: var(--accent); background: var(--accent-soft); }
.rp-card .amt { font-size: 21px; font-weight: 700; color: var(--accent); }
.rp-card .amt small { font-size: 13px; font-weight: 400; }
.rp-card .days { font-size: 12.5px; color: var(--ink-2); margin-top: 2px; }

.rp-preview {
  margin-top: 12px; padding: 12px 14px; border-radius: 12px;
  background: var(--accent-soft); font-size: 14px; line-height: 1.7;
}

.file-drop {
  border: 2px dashed var(--line); border-radius: 14px; padding: 22px 14px;
  text-align: center; color: var(--ink-2); font-size: 14px; margin-bottom: 12px;
}
.file-drop input { display: block; margin: 10px auto 0; max-width: 100%; }
.link-btn { color: var(--accent); font-size: 13.5px; padding: 6px 2px; }
.dot { margin: 0 8px; }

/* ── 聊天页 ─────────────────────────────────────────── */
.chat-head {
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + var(--safe-t)) 12px 10px;
  background: var(--bg-2); border-bottom: 1px solid var(--line);
}
.back-btn { font-size: 30px; color: var(--ink-2); width: 32px; line-height: 1; padding: 0; }
.chat-avatar {
  width: 40px; height: 40px; flex: none; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; background: var(--accent-soft);
}
.chat-meta { flex: 1; min-width: 0; }
.chat-name { font-weight: 600; font-size: 17px; }
.chat-sub { font-size: 12.5px; color: var(--ink-3); }
.icon-btn { font-size: 21px; padding: 6px 8px; border-radius: 10px; }
.icon-btn:active { background: var(--accent-soft); }

.msg-box {
  flex: 1; overflow-y: auto; padding: 16px 14px 8px;
  -webkit-overflow-scrolling: touch;
}
.msg { display: flex; margin-bottom: 14px; }
.msg.me { justify-content: flex-end; }
.bubble {
  max-width: 78%; padding: 11px 14px; border-radius: 16px;
  background: var(--bubble-ai); border: 1px solid var(--line);
  white-space: pre-wrap; word-break: break-word; font-size: 16.5px;
  box-shadow: 0 1px 2px rgba(0,0,0,.03);
}
.msg.me .bubble { background: var(--bubble-me); color: var(--bubble-me-ink); border-color: transparent; }
.bubble.crisis { border-color: #e0a23c; background: #fff6e6; }
.bubble .role-tag {
  display: block; font-size: 12px; color: var(--ink-3); margin-bottom: 3px;
}
.bubble .play {
  display: flex; width: fit-content; align-items: center; gap: 4px;
  margin-top: 8px; font-size: 12.5px; color: var(--accent);
  background: var(--accent-soft); padding: 4px 10px; border-radius: 20px;
}
.bubble .play.playing { background: var(--accent); color: #fff; }

.msg-time { text-align: center; font-size: 11.5px; color: var(--ink-3); margin: 6px 0 16px; }

.typing { display: flex; gap: 5px; padding: 4px 20px 10px; }
.typing span {
  width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3);
  animation: blink 1.3s infinite;
}
.typing span:nth-child(2){ animation-delay:.18s }
.typing span:nth-child(3){ animation-delay:.36s }
@keyframes blink { 0%,60%,100%{opacity:.25} 30%{opacity:1} }

.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 10px calc(8px + var(--safe-b));
  background: var(--bg-2); border-top: 1px solid var(--line);
}
.composer-input {
  flex: 1; resize: none; max-height: 120px; min-height: 42px;
  padding: 10px 14px; border-radius: 21px; border: 1px solid var(--line);
  background: var(--bg); line-height: 1.5; outline: none;
}
.composer-input:focus { border-color: var(--accent); }
.voice-btn { font-size: 22px; padding: 8px; border-radius: 50%; }
.voice-btn.rec { background: var(--accent); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.45} }
.send-btn {
  width: 42px; height: 42px; flex: none; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 21px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.send-btn:disabled { opacity: .4; }

/* ── 弹层 ───────────────────────────────────────────── */
.mask {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.42);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 520px; max-height: 86vh;
  background: var(--bg); border-radius: 20px 20px 0 0;
  display: flex; flex-direction: column;
  padding-bottom: var(--safe-b);
  animation: up .22s ease;
}
@keyframes up { from{transform:translateY(30px);opacity:.6} to{transform:translateY(0);opacity:1} }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px 10px; font-weight: 600; font-size: 17px;
  border-bottom: 1px solid var(--line);
}
.sheet-close { font-size: 20px; color: var(--ink-3); padding: 2px 6px; }
.sheet-body { overflow-y: auto; padding: 16px 18px 24px; font-size: 15.5px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13.5px; color: var(--ink-2); margin-bottom: 5px; }
.field input, .field textarea {
  width: 100%; padding: 11px 13px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg-2); outline: none;
}
.field input:focus, .field textarea:focus { border-color: var(--accent); }
.field .hint { font-size: 12.5px; color: var(--ink-3); margin-top: 4px; }

.btn {
  display: block; width: 100%; padding: 13px; border-radius: 14px;
  background: var(--accent); color: #fff; font-size: 16px; font-weight: 600;
  text-align: center; margin-top: 8px;
}
.btn.ghost { background: var(--bg-2); color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: #d9534f; }
.btn:disabled { opacity: .5; }

.mem-item {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 11px 13px; background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 12px; margin-bottom: 8px;
}
.mem-item .mem-text { flex: 1; font-size: 15px; }
.mem-item .mem-date { font-size: 11.5px; color: var(--ink-3); margin-top: 3px; }
.mem-del { color: var(--ink-3); font-size: 19px; padding: 0 3px; }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.stat {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 8px; text-align: center;
}
.stat .n { font-size: 21px; font-weight: 700; color: var(--accent); }
.stat .t { font-size: 12px; color: var(--ink-3); margin-top: 2px; }

.toast {
  position: fixed; left: 50%; bottom: calc(84px + var(--safe-b)); transform: translateX(-50%);
  background: rgba(40,32,26,.94); color: #fff; padding: 11px 18px; border-radius: 22px;
  font-size: 14.5px; z-index: 90; max-width: 84%; text-align: center;
}

.empty { text-align: center; color: var(--ink-3); padding: 28px 10px; font-size: 14.5px; }
.about-text { color: var(--ink-2); font-size: 14px; line-height: 1.75; }
.about-text h4 { color: var(--ink); font-size: 15px; margin: 16px 0 4px; }
.about-text a { color: var(--accent); }

/* ── 我的邀请码 ── */
.inv-qr { display: flex; justify-content: center; margin: 4px 0 14px; }
.inv-qr img {
  width: 208px; height: 208px; border-radius: 14px; background: #fff;
  border: 1px solid var(--line); padding: 6px; box-sizing: border-box;
}
.inv-code { text-align: center; font-size: 14px; color: var(--ink-3); margin-bottom: 4px; }
.inv-code b {
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 18px;
  letter-spacing: 2px; color: var(--accent);
}
.inv-link {
  text-align: center; font-size: 12px; color: var(--ink-3);
  word-break: break-all; margin-bottom: 16px;
}
.inv-ops { display: flex; gap: 10px; }
.inv-ops .btn { flex: 1; }
.inv-ops2 { text-align: center; margin-top: 14px; }
.mini-btn {
  font-size: 12.5px; color: var(--ink-3); background: none; border: none;
  text-decoration: underline; cursor: pointer; padding: 6px 8px;
}
