/* 灵魂陪伴 · 适老化大字样式（纯原生，无任何外部依赖，可离线）
   2026-11-18 修订：
   - 补齐 App 层样式（离线条 / 安装条 / 安装说明抽屉）——之前 HTML 里写了这些元素，
     CSS 里却没有对应规则，装 App 引导会变成页面底部的一行裸文字；
   - 输入栏不再用负外边距（会导致横向滚动），改为安全区内边距；
   - 顶栏/底栏适配刘海屏与底部横条。
*/
:root {
  --bg: #f6f3ec;
  --panel: #ffffff;
  --ink: #22201c;
  --ink-soft: #5c574e;
  --line: #ddd6c8;
  --brand: #2f6f5e;
  --brand-soft: #e4efe9;
  --warn: #b3541e;
  --warn-soft: #fbeade;
  --danger: #a02b2b;
  --radius: 16px;
  --fs-base: 20px;
  --fs-lg: 24px;
  --fs-xl: 30px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-text-size-adjust: 100%; }

/* hidden 属性必须优先，否则 .install-bar{display:flex} 会把 hidden 顶掉 */
[hidden] { display: none !important; }

html { scroll-padding-bottom: 130px; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Heiti SC", sans-serif;
  font-size: var(--fs-base);
  line-height: 1.62;
}

.wrap { max-width: 860px; margin: 0 auto; padding: 0 14px 24px; }
main.wrap { padding-bottom: 104px; }          /* 给底部输入栏留位，最后一条消息不被挡住 */

/* ---------------- 离线提示条（断网时出现，老人不能只看到白屏） ---------------- */
.offline-bar {
  position: sticky;
  top: 0;
  z-index: 45;
  background: var(--danger);
  color: #fff;
  font-size: 17px;
  font-weight: 700;
  text-align: center;
  padding: calc(8px + var(--safe-top)) 14px 8px;
}

/* ---------------- 安装到主屏引导条 ---------------- */
.install-bar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  justify-content: space-between;
  background: #fff3d6;
  border-bottom: 2px solid #e7c980;
  padding: calc(10px + var(--safe-top)) 14px 10px;
}
.app-standalone .install-bar { display: none !important; }
.install-txt { flex: 1 1 200px; font-size: 17px; color: #7a5200; font-weight: 600; }
.install-act { display: flex; gap: 8px; }
.install-act button {
  min-height: 44px;
  font-size: 16px;
  padding: 4px 14px;
  border-width: 2px;
}

/* ---------------- 安装说明抽屉 ---------------- */
.sheet-mask {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(24, 21, 18, .55);
  padding: 12px;
}
.sheet {
  width: 100%;
  max-width: 540px;
  max-height: 82vh;
  overflow-y: auto;
  background: var(--panel);
  border-radius: 18px 18px 14px 14px;
  padding: 18px 18px calc(18px + var(--safe-bottom));
  box-shadow: 0 -8px 30px rgba(0, 0, 0, .18);
}
.sheet h2 { margin: 0 0 10px; font-size: 22px; }
.sheet ol { margin: 0; padding-left: 24px; font-size: 18px; line-height: 1.75; }
.sheet li { margin-bottom: 8px; }
.sheet code { background: #f2eee3; padding: 1px 6px; border-radius: 6px; font-size: 16px; }
.sheet .close { margin-top: 12px; }

/* ---------------- 顶部状态条 ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: #fffdf8;
  border-bottom: 2px solid var(--line);
  padding: calc(10px + var(--safe-top)) 14px 10px;
}
.topbar .row { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; }
.who { font-size: var(--fs-lg); font-weight: 700; }
.who-sel {
  font-size: 19px; font-weight: 700; padding: 4px 10px; min-height: 44px; max-width: 62vw;
  border-radius: 10px; border: 2px solid var(--brand); background: #fff; color: var(--brand);
}
.stage-tag {
  background: var(--brand-soft); color: var(--brand);
  border-radius: 999px; padding: 2px 12px; font-size: 17px; font-weight: 600;
}
.clock-tag { color: var(--ink-soft); font-size: 17px; font-variant-numeric: tabular-nums; }
.quiet-tag {
  background: #ece9e0; color: #4a4640; border: 1.5px solid #c9c3b4;
  border-radius: 999px; padding: 2px 12px; font-size: 16px; font-weight: 700;
}

/* AI 合成标识（常驻，合规 FR-10.x） */
.ai-badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: #fff3d6; color: #7a5200; border: 1.5px solid #e7c980;
  border-radius: 999px; padding: 3px 12px; font-size: 16px; font-weight: 700;
}
.disclaimer { color: var(--ink-soft); font-size: 15px; margin-top: 6px; }

/* ---------------- 通用面板 ---------------- */
.card {
  background: var(--panel); border: 2px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin-top: 14px;
}
.card h2 { margin: 0 0 10px; font-size: var(--fs-lg); }
.card h3 { margin: 14px 0 8px; font-size: var(--fs-base); color: var(--ink-soft); }
.muted { color: var(--ink-soft); font-size: 16px; }
.hr { height: 2px; background: var(--line); margin: 12px 0; border-radius: 2px; }

/* ---------------- 按钮（大触控区，≥52px 便于老人点击） ---------------- */
button, .btn {
  font-family: inherit; font-size: var(--fs-base); font-weight: 600;
  min-height: 52px; padding: 10px 18px;
  border-radius: 12px; border: 2px solid var(--brand);
  background: var(--brand); color: #fff; cursor: pointer;
}
button:active { transform: translateY(1px); }
button.ghost { background: #fff; color: var(--brand); }
button.warn { background: var(--warn); border-color: var(--warn); }
button.danger { background: #fff; color: var(--danger); border-color: var(--danger); }
button.big { font-size: var(--fs-lg); min-height: 64px; width: 100%; }
button:disabled { opacity: .55; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }

/* ---------------- 对话区 ---------------- */
#chat {
  display: flex; flex-direction: column; gap: 12px;
  padding: 12px 4px 6px; min-height: 220px;
}
.bubble {
  max-width: 88%; padding: 12px 16px; border-radius: 18px;
  font-size: 22px; line-height: 1.6; word-break: break-word; white-space: pre-wrap;
}
.bubble.ai { background: var(--brand-soft); color: #14332a; align-self: flex-start; border-bottom-left-radius: 6px; }
.bubble.me { background: #e8e3d6; color: var(--ink); align-self: flex-end; border-bottom-right-radius: 6px; }
.bubble.sys {
  align-self: center; background: var(--warn-soft); color: var(--warn);
  font-size: 17px; max-width: 96%; text-align: center;
}
.bubble .tag { display: block; margin-top: 6px; font-size: 14px; color: #6d6a63; }

/* ---------------- 输入区 ---------------- */
.inputbar {
  position: sticky; bottom: 0; left: 0; right: 0; z-index: 25;
  background: #fffdf8; border-top: 2px solid var(--line);
  padding: 10px 14px calc(12px + var(--safe-bottom));
}
.inputrow { display: flex; gap: 10px; align-items: flex-end; max-width: 860px; margin: 0 auto; }
textarea#text {
  flex: 1; font-family: inherit; font-size: 22px; line-height: 1.5;
  padding: 12px 14px; border-radius: 12px; border: 2px solid var(--line);
  background: #fff; color: var(--ink); resize: none; min-height: 56px;
}
textarea#text:focus { outline: 3px solid var(--brand-soft); border-color: var(--brand); }

/* ---------------- 列表 / 表格 ---------------- */
ul.list { list-style: none; margin: 0; padding: 0; }
ul.list li {
  border-top: 1.5px dashed var(--line); padding: 10px 0; font-size: 18px;
}
ul.list li:first-child { border-top: none; }
.kv { color: var(--ink-soft); font-size: 16px; }
.pill {
  display: inline-block; border-radius: 999px; padding: 1px 10px;
  font-size: 15px; background: var(--brand-soft); color: var(--brand); font-weight: 600;
}
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.danger { background: #f7dede; color: var(--danger); }
.pill.grey { background: #ece9e0; color: #6d6a63; }

input[type="text"], input[type="number"], input[type="time"], select {
  font-family: inherit; font-size: 19px; padding: 10px 12px;
  border-radius: 10px; border: 2px solid var(--line); background: #fff; color: var(--ink);
}
label.field { display: block; margin-top: 10px; font-size: 17px; color: var(--ink-soft); }
label.field > * { margin-top: 6px; width: 100%; }

/* 多行输入（记忆批量导入等） */
textarea.edit-area {
  font-family: inherit; font-size: 18px; line-height: 1.6; padding: 10px 12px;
  border-radius: 10px; border: 2px solid var(--line); background: #fff; color: var(--ink);
  resize: vertical; min-height: 120px;
}
textarea.edit-area:focus { outline: 3px solid var(--brand-soft); border-color: var(--brand); }

/* 导入预览里的"顺便建提醒"勾选区 */
.imp-rem { margin-top: 12px; border-top: 2px solid var(--line); padding-top: 10px; }
.imp-check {
  display: flex; gap: 10px; align-items: flex-start; margin-top: 8px;
  font-size: 18px; line-height: 1.5; cursor: pointer;
  border: 2px solid var(--line); border-radius: 12px; padding: 10px 12px; background: #fff;
}
.imp-check input[type="checkbox"] { width: 26px; height: 26px; margin-top: 2px; flex: none; }
.imp-check.off { opacity: .6; cursor: default; background: #f6f3ec; }

/* ---------------- 今日待办看板 ---------------- */
.board-counts { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 4px; }
.board-counts .chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 2px solid var(--line); border-radius: 999px;
  padding: 4px 14px; font-size: 17px; font-weight: 700;
  background: #f7f4ec; color: var(--ink-soft);
}
.board-counts .chip.hot { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }
.board-counts .chip.warn { border-color: var(--danger); background: #f7dede; color: var(--danger); }
.board-row {
  border-top: 1.5px dashed var(--line);
  padding: 10px 0;
}
.board-row:first-of-type { border-top: none; }
.board-row .br-main { font-size: 20px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.board-row .kv { margin-top: 2px; }
.board-row .btn-row { margin-top: 8px; }
.attn-edit { margin-top: 8px; }
.attn-edit input[type="text"] { width: 100%; font-size: 17px; }

/* ---------------- 提醒确认卡 ---------------- */
.reminder-card {
  border: 3px solid var(--warn); background: var(--warn-soft);
  border-radius: var(--radius); padding: 14px 16px; margin-top: 14px;
}
.reminder-card .title { font-size: var(--fs-lg); font-weight: 700; color: var(--warn); }
.reminder-card .say { font-size: 21px; margin-top: 8px; }

/* ---------------- 提示条 ---------------- */
#toast {
  position: fixed; left: 50%; bottom: calc(120px + var(--safe-bottom)); transform: translateX(-50%);
  background: #2c2a26; color: #fff; padding: 12px 20px; border-radius: 12px;
  font-size: 18px; max-width: 90%; opacity: 0; pointer-events: none;
  transition: opacity .25s; z-index: 60;
}
#toast.on { opacity: .96; }

/* ---------------- 导航 ---------------- */
.navlink { display: inline-block; margin-top: 10px; font-size: 18px; color: var(--brand); font-weight: 700; }

/* ---------------- 家属端表格 ---------------- */
table.data { width: 100%; border-collapse: collapse; font-size: 17px; }
table.data th, table.data td { border: 1.5px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; }
table.data th { background: #f2eee3; font-weight: 700; }
table.data td input[type="time"] { font-size: 16px; padding: 4px 6px; width: auto; }
table.data td button { min-height: 38px; font-size: 15px; padding: 2px 10px; }
/* 窄屏上表格别把字挤成竖排：外滑动 + 首列不换行 */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll table.data { min-width: 540px; }
.table-scroll table.data th { white-space: nowrap; }

/* ---------------- 多档案 / 提醒条目（手机上不挤成竖排） ---------------- */
.persona-row, .item-row { border-top: 1.5px dashed var(--line); padding: 10px 0; }
.persona-row:first-child, .item-row:first-child { border-top: none; }
.persona-row.cur { background: var(--brand-soft); border-radius: 12px; padding: 10px; }
.persona-row .pi, .item-row .pi {
  font-size: 19px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
}
.item-row .kv { margin-top: 4px; }
.inline-edit {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px;
  font-size: 17px; color: var(--ink-soft);
}
.inline-edit input[type="time"] { width: auto; font-size: 17px; padding: 6px 8px; }
.inline-edit button { min-height: 44px; font-size: 16px; padding: 4px 14px; }

@media (max-width: 420px) {
  :root { --fs-base: 19px; --fs-lg: 22px; --fs-xl: 26px; }
  .bubble { font-size: 21px; max-width: 92%; }
  .card { padding: 12px; }
}

/* ---------------- 连不上服务器时的顶部提示条 ---------------- */
.need-server {
  position: sticky; top: 0; z-index: 40;
  background: #fff3d6; border-bottom: 2px solid var(--danger); color: #7a3b00;
}
.need-server .wrap { display: flex; align-items: center; gap: 12px; padding: 10px 16px; }
.need-server span { flex: 1; font-size: 17px; line-height: 1.45; }
.need-server button {
  flex: none; min-height: 44px; padding: 0 16px; font-size: 16px;
  border-radius: 10px; border: 2px solid var(--danger); background: #fff; color: var(--danger);
  font-weight: 700;
}
/* 跳转到设置时闪一下，告诉老人"要填的就是这儿" */
input.flash { animation: flashBorder 1.6s ease-out 2; }
@keyframes flashBorder {
  0%, 100% { box-shadow: 0 0 0 0 rgba(31,111,178,0); }
  40% { box-shadow: 0 0 0 6px rgba(31,111,178,.35); }
}

/* ==================================================================
   小狗智能体舞台（Puppy Agent）
   形象来自老方家那只棕色泰迪，白底方图 + 白卡承载，不做抠图
   ================================================================== */
.stage {
  position: relative;
  display: flex; flex-direction: column; align-items: center;
  padding: 8px 0 4px;
  min-height: 54vh;
}

/* 狗说话时的气泡：大字、居中、浮在狗上方 */
.stage-bubble {
  position: relative;
  max-width: 92%;
  margin: 4px auto 10px;
  background: #fff;
  border: 3px solid var(--brand);
  border-radius: 22px;
  padding: 14px 18px;
  font-size: 22px;
  line-height: 1.5;
  color: var(--ink);
  box-shadow: 0 6px 18px rgba(0,0,0,.10);
  animation: bubbleIn .28s ease-out;
  max-height: 34vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.stage-bubble::after {
  content: '';
  position: absolute; left: 50%; bottom: -13px; transform: translateX(-50%);
  width: 0; height: 0;
  border-left: 12px solid transparent;
  border-right: 12px solid transparent;
  border-top: 12px solid var(--brand);
}
@keyframes bubbleIn {
  from { opacity: 0; transform: translateY(8px) scale(.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* 狗本体：白卡 + 轻微漂浮 */
.puppy-wrap {
  position: relative;
  width: min(78vw, 330px);
  aspect-ratio: 1 / 1;
  border-radius: 28px;
  background: #fff;
  box-shadow: 0 10px 30px rgba(60, 40, 20, .16), 0 2px 0 rgba(0,0,0,.03) inset;
  overflow: hidden;
  animation: puppyIn .55s cubic-bezier(.2, 1.4, .4, 1) both;
}
@keyframes puppyIn {
  0%   { opacity: 0; transform: translateY(40px) scale(.82); }
  60%  { opacity: 1; transform: translateY(-6px) scale(1.04); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

.puppy {
  display: block; width: 100%; height: 100%;
  object-fit: cover; object-position: center bottom;
  animation: breathe 3.6s ease-in-out infinite;
  transform-origin: 50% 92%;
  user-select: none; -webkit-user-drag: none;
}
@keyframes breathe {
  0%, 100% { transform: scale(1) translateY(0); }
  50%      { transform: scale(1.022) translateY(-2px); }
}

/* 说话中：上下浮动快一点 */
.puppy-wrap.talking .puppy { animation: talkBob .42s ease-in-out infinite; }
@keyframes talkBob {
  0%, 100% { transform: translateY(0) scale(1); }
  50%      { transform: translateY(-7px) scale(1.015); }
}

/* 提醒：轻微点头 */
.puppy-wrap.alerting .puppy { animation: nod 1.1s ease-in-out infinite; }
@keyframes nod {
  0%, 100% { transform: rotate(0deg); }
  25%      { transform: rotate(-2.5deg); }
  75%      { transform: rotate(2.5deg); }
}

/* 报警：抖动 + 红色脉冲边缘 */
.puppy-wrap.alarming {
  animation: shakeWrap .5s ease-in-out infinite;
  box-shadow: 0 0 0 0 rgba(200, 40, 40, .55), 0 10px 30px rgba(60,40,20,.16);
}
@keyframes shakeWrap {
  0%, 100% { transform: translateX(0);    box-shadow: 0 0 0 0 rgba(200,40,40,.55), 0 10px 30px rgba(60,40,20,.16); }
  25%      { transform: translateX(-5px); box-shadow: 0 0 0 10px rgba(200,40,40,.14), 0 10px 30px rgba(60,40,20,.16); }
  75%      { transform: translateX(5px);  box-shadow: 0 0 0 10px rgba(200,40,40,.14), 0 10px 30px rgba(60,40,20,.16); }
}

/* 狗嘴里叼的牌子（HTML 画，文字可动态换） */
.puppy-sign {
  position: absolute;
  left: 50%; top: 48%;
  transform: translate(-50%, 0) rotate(-3deg);
  min-width: 46%;
  max-width: 78%;
  padding: 10px 14px;
  background: #efe3c4;
  border: 2px solid #d8c79a;
  border-radius: 8px;
  box-shadow: 0 6px 14px rgba(90, 60, 20, .22);
  font-size: 19px;
  font-weight: 700;
  line-height: 1.35;
  color: #5a3a1a;
  text-align: center;
  animation: signIn .4s cubic-bezier(.2,1.5,.4,1) both;
}
@keyframes signIn {
  from { opacity: 0; transform: translate(-50%, 14px) rotate(-8deg) scale(.8); }
  to   { opacity: 1; transform: translate(-50%, 0) rotate(-3deg) scale(1); }
}

/* 状态文字 */
.stage-status {
  margin-top: 10px;
  font-size: 17px;
  color: var(--ink-soft);
  min-height: 24px;
  text-align: center;
}
.stage-status .dot { animation: blink 1.2s infinite; }
@keyframes blink { 0%,100%{opacity:.25} 50%{opacity:1} }

/* 历史记录抽屉 */
.history-toggle {
  display: block; width: 100%; text-align: center;
  background: none; border: none; color: var(--ink-soft);
  font-size: 16px; padding: 10px; min-height: 44px;
}
.history-toggle::before { content: '▾ '; }
.history-toggle.open::before { content: '▴ '; }
#chatCard.collapsed #chat { display: none; }

/* ==================================================================
   沉浸式宠物屏：打开 App 只看到狗
   ================================================================== */
html, body { height: 100%; }
body.pet-mode { overflow: hidden; background: var(--bg); }

.pet-stage {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: env(safe-area-inset-top) 12px calc(env(safe-area-inset-bottom) + 96px);
  background:
    radial-gradient(120% 80% at 50% 0%, #fff9ee 0%, var(--bg) 55%, #f1ece1 100%);
}

/* 气泡脱离文档流，出现时不推挤小狗 */
.pet-bubble {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 18px);
  left: 16px; right: 16px;
  max-height: 26vh;
  overflow-y: auto;
  margin: 0;
  z-index: 5;
}

.pet-puppy {
  width: min(84vw, 400px);
  aspect-ratio: 1 / 1;
  border-radius: 32px;
  box-shadow: 0 16px 40px rgba(90, 60, 20, .18), 0 0 0 6px rgba(255,255,255,.65);
}

.pet-stage .stage-status {
  position: static;
  margin-top: 14px;
  font-size: 18px;
}

/* 底部：一颗大按钮 */
.pet-bar {
  position: fixed;
  left: 16px; right: 16px;
  bottom: calc(env(safe-area-inset-bottom) + 16px);
  display: flex; gap: 10px; z-index: 30;
}
.talk-btn {
  flex: 1;
  min-height: 66px;
  font-size: 21px;
  font-weight: 700;
  border-radius: 20px;
  border: none;
  background: var(--brand);
  color: #fff;
  box-shadow: 0 8px 20px rgba(47, 111, 94, .35);
  transition: transform .12s ease, background .2s;
}
.talk-btn:active, .talk-btn.listening {
  transform: scale(.97);
  background: var(--danger);
}
.type-btn {
  flex: none; width: 72px; min-height: 66px;
  border-radius: 20px; font-size: 16px;
  white-space: nowrap; padding: 0 6px;
  border: 2px solid var(--line); background: #fff; color: var(--ink-soft);
}

/* 打字区浮在按钮上方 */
.inputbar.dock {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(env(safe-area-inset-bottom) + 92px);
  padding: 10px 16px 12px;
  background: #fff;
  border-top: 2px solid var(--line);
  box-shadow: 0 -6px 18px rgba(0,0,0,.06);
  z-index: 35;
}

/* 设置齿轮：很小很淡，老人不会误触 */
.gear-btn {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 8px);
  right: 10px;
  width: 40px; height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,.55);
  color: var(--ink-soft);
  font-size: 20px; line-height: 1;
  opacity: .5;
  z-index: 40;
}

/* 抽屉 */
.panel {
  position: fixed; inset: 0; z-index: 60;
  background: var(--bg);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: panelIn .22s ease-out;
}
@keyframes panelIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.panel-bar {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: rgba(246,243,236,.96);
  border-bottom: 2px solid var(--line);
}
.panel-bar strong { font-size: 19px; }
.panel-bar button { min-height: 40px; }
.panel-body { padding: 12px 0 calc(env(safe-area-inset-bottom) + 24px); }
.panel-body .inputbar { position: static; box-shadow: none; border-top: none; }

/* 睡觉 / 抖擞精神 */
.puppy-wrap.sleeping { box-shadow: 0 10px 26px rgba(90,60,20,.12), 0 0 0 6px rgba(255,255,255,.5); }
.puppy-wrap.sleeping .puppy { animation: sleepBreath 5.2s ease-in-out infinite; }
@keyframes sleepBreath {
  0%, 100% { transform: scale(1) translateY(0); }
  50%      { transform: scale(1.012) translateY(2px); }
}

.puppy-wrap.waking .puppy { animation: wakeShake .55s ease-in-out 3; }
@keyframes wakeShake {
  0%, 100% { transform: rotate(0deg) translateX(0); }
  20%      { transform: rotate(-4deg) translateX(-4px); }
  50%      { transform: rotate(4deg) translateX(4px) scale(1.02); }
  80%      { transform: rotate(-2deg) translateX(-2px); }
}

/* 沉浸模式下提醒卡片浮在按钮上方 */
.pet-reminder { position: fixed; left: 12px; right: 12px; bottom: calc(env(safe-area-inset-bottom) + 96px); z-index: 25; }
.pet-reminder .reminder-card { margin: 0 0 8px; }

/* 合规小字：不打扰，但必须在 */
.pet-legal {
  position: fixed; left: 0; right: 0;
  bottom: calc(env(safe-area-inset-bottom) + 2px);
  text-align: center;
  font-size: 11px; color: rgba(90, 80, 60, .42);
  pointer-events: none;
}

/* 抽屉打开时：狗看不见，动画停掉（省电，也避免后台空转） */
body.panel-open .puppy { animation-play-state: paused; }

/* ===== 狗直接站在页面上（已抠图，不再是白卡里的照片） ===== */
.pet-puppy {
  background: transparent;
  box-shadow: none;
  border-radius: 0;
  overflow: visible;
  width: min(88vw, 430px);
  animation: petIn .78s cubic-bezier(.2, 1.3, .4, 1) both;
}
/* 脚下的一圈影子，让狗"落"在页面上 */
.pet-puppy::after {
  content: '';
  position: absolute; left: 50%; bottom: 2%;
  transform: translateX(-50%);
  width: 56%; height: 18px;
  background: radial-gradient(ellipse at center, rgba(90,60,20,.24) 0%, rgba(90,60,20,0) 72%);
  border-radius: 50%;
  pointer-events: none;
  animation: shadowPulse 7s ease-in-out infinite;
}
@keyframes shadowPulse {
  0%, 62%, 100% { transform: translateX(-50%) scaleX(1); opacity: .9; }
  74% { transform: translateX(-50%) scaleX(.86); opacity: .6; }
  82% { transform: translateX(-50%) scaleX(1); opacity: .95; }
}
@keyframes petIn {
  0%   { opacity: 0; transform: translateY(70px) scale(.68) rotate(-5deg); }
  55%  { opacity: 1; transform: translateY(-16px) scale(1.06) rotate(2deg); }
  76%  { transform: translateY(6px) scale(.975) rotate(-1deg); }
  100% { opacity: 1; transform: translateY(0) scale(1) rotate(0deg); }
}

/* 待机：呼吸 + 隔一会儿蹦一下（"跳来跳去"） */
.pet-puppy .puppy { animation: live 7s ease-in-out infinite; transform-origin: 50% 94%; }
@keyframes live {
  0%, 34%, 100% { transform: translateY(0) scale(1); }
  44%           { transform: translateY(-4px) scale(1.016); }
  56%           { transform: translateY(0) scale(1); }
  66%           { transform: translateY(-16px) scale(1.03); }
  74%           { transform: translateY(0) scale(.982); }
  80%           { transform: translateY(-5px) scale(1.008); }
  86%           { transform: translateY(0) scale(1); }
}
.pet-puppy.talking .puppy { animation: talkBob .42s ease-in-out infinite; }
.pet-puppy.sleeping .puppy { animation: sleepBreath 5.2s ease-in-out infinite; }
.pet-puppy.waking .puppy { animation: wakeShake .55s ease-in-out 3; }
.pet-puppy.alerting .puppy { animation: nod 1.1s ease-in-out infinite; }
.pet-puppy.alarming { animation: shakeWrap .5s ease-in-out infinite; }

/* ===== 行为层：位置（外层）/ 转身（中间层）/ 动作（图片自身） ===== */
/* 位置与转身必须分层：图片的 transform 已被 live/talkBob 等动画占用 */
.pet-puppy {
  width: min(76vw, 360px);
  transition: transform 1.15s cubic-bezier(.4, .1, .3, 1);
  will-change: transform;
}
.puppy-body {
  width: 100%; height: 100%;
  transition: transform .45s cubic-bezier(.34, 1.56, .64, 1);
  transform: scaleX(var(--fx, 1));
  transform-origin: 50% 88%;
}
.puppy-body img { display: block; width: 100%; height: 100%; object-fit: contain; }

/* 趴下时整体压扁一点，像真的把身体放下去 */
.pet-puppy.lying .puppy-body { transform: scaleX(var(--fx, 1)) translateY(6%) scaleY(.96); }

/* 张望：轻轻左右转一下头 */
.pet-puppy.looking .puppy { animation: lookAround 1.6s ease-in-out; }
@keyframes lookAround {
  0%, 100% { transform: rotate(0deg); }
  30%      { transform: rotate(-3.5deg); }
  70%      { transform: rotate(3.5deg); }
}

/* 抖毛：快速小幅左右 */
.pet-puppy.shaking .puppy { animation: shakeFur .5s ease-in-out 2; }
@keyframes shakeFur {
  0%, 100% { transform: translateX(0) rotate(0deg); }
  25%      { transform: translateX(-4px) rotate(-2deg); }
  75%      { transform: translateX(4px) rotate(2deg); }
}

/* 沉浸模式下提示放顶部：底部被按钮和提醒卡片占满，压在上面会挡住「稍后提醒」 */
body.pet-mode #toast {
  bottom: auto;
  top: calc(env(safe-area-inset-top) + 74px);
  max-height: 40vh;
  overflow-y: auto;
}
/* 提醒卡片别太高，把狗挤没了 */
.pet-reminder .reminder-card { max-height: 34vh; overflow-y: auto; }

/* 沉浸模式下提示放顶部：底部被按钮和提醒卡片占满，压在上面会挡住「稍后提醒」 */
body.pet-mode #toast {
  bottom: auto;
  top: calc(env(safe-area-inset-top) + 74px);
  max-height: 40vh;
  overflow-y: auto;
}
/* 提醒卡片别太高，把狗挤没了 */
.pet-reminder .reminder-card { max-height: 34vh; overflow-y: auto; }

/* 首次引导：让小狗到桌面上 */
.pet-intro {
  position: fixed;
  left: 12px; right: 12px;
  bottom: calc(env(safe-area-inset-bottom) + 96px);
  z-index: 45;
  background: #fff;
  border: 3px solid var(--brand);
  border-radius: 20px;
  padding: 16px 18px;
  box-shadow: 0 12px 30px rgba(0,0,0,.16);
  animation: bubbleIn .3s ease-out;
}
.pet-intro .pi-title { font-size: 20px; font-weight: 700; color: var(--ink); margin-bottom: 6px; }
.pet-intro .pi-desc { font-size: 15px; line-height: 1.55; color: var(--ink-soft); margin-bottom: 12px; }
.pet-intro .btn-row { display: flex; gap: 10px; }
.pet-intro .btn-row button { flex: 1; min-height: 48px; }

/* ===== 视频动作层 =====
   视频是白底 mp4（逐帧抠图成本太高），靠 multiply 让白色"消失"融入米色页面，
   狗本体是深棕色，相乘后颜色几乎不变。 */
.puppy-body { position: relative; }
.puppy-video {
  /* video 只当"素材源"，绝不能显示出来 —— 显示的是下面 canvas 抠过的帧。
     也不能用 display:none（会让部分浏览器停止解码），所以只做透明 + 尺寸保留。 */
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center bottom;
  opacity: 0;
  pointer-events: none;
  z-index: -1;
}

/* 视频帧经 canvas 实时抠白底后再显示，所以看到的是 canvas 不是 video */
.puppy-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center bottom;
  pointer-events: none;
}

/* 视频 ↔ 静态图切换：淡入，盖住两者尺寸差异造成的"跳一下" */
.puppy { transition: opacity .22s ease; }

/* 动画 WebP：自带透明通道，不需要 canvas 逐帧抠图了 */
.puppy-anim {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center bottom;
  pointer-events: none;
}



/* 声纹录入 */
.vr-script {
  background: #fffdf7;
  border: 2px dashed var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 16px;
  line-height: 1.7;
  color: var(--ink);
  margin-bottom: 10px;
}
#voiceRecBox .record-on { background: var(--danger) !important; color: #fff; }
.vr-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 16px;
}
.vr-row .tag { font-size: 13px; color: var(--ink-soft); }

/* 记事列表 */
.notes-box { margin: 8px 0 4px; }
.note-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; margin-bottom: 8px;
  background: #fff; border: 2px solid var(--line); border-radius: 12px;
  font-size: 16px;
}
.note-row .nt-main { flex: 1; min-width: 0; }
.note-row .nt-title { color: var(--ink); word-break: break-all; }
.note-row .nt-when { font-size: 13px; color: var(--brand); margin-top: 2px; }
.note-row .nt-kind {
  flex: none; font-size: 12px; padding: 2px 8px; border-radius: 8px;
  background: #f0ece1; color: var(--ink-soft);
}
.note-row button { flex: none; min-height: 38px; font-size: 14px; padding: 0 12px; }
.notes-empty { color: var(--ink-soft); font-size: 15px; padding: 6px 2px; }

/* 识别调试 */
.calib-list { margin-top: 8px; }
.calib-row {
  font-size: 14px; padding: 8px 10px; margin-bottom: 6px;
  background: #fff; border-radius: 10px; border-left: 4px solid var(--line);
  line-height: 1.5;
}
.calib-row.ok { border-left-color: #3f8f5a; }
.calib-row.bad { border-left-color: #c0642f; }
.calib-row .cl-a { color: var(--ink-soft); }
.calib-row .cl-b { color: var(--ink); font-weight: 600; }

/* 生效中的偏好 */
.prefs-box { margin: 8px 0; }
.pref-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #eef6f0; color: #2f6b46;
  border-radius: 10px; padding: 6px 10px; margin: 0 6px 6px 0; font-size: 14px;
}
.pref-chip button {
  background: none; border: none; color: #6b8f79; font-size: 16px;
  cursor: pointer; padding: 0 2px; min-height: auto;
}

/* 调试快捷跳转 */
.quick-jump {
  position: sticky; top: 0; z-index: 6;
  background: rgba(255,255,255,.96);
  padding: 8px 0 10px; margin: -4px 0 10px;
  border-bottom: 1px solid var(--line);
}
.quick-jump button { margin: 0 6px 0 0; min-height: 40px; font-size: 14px; padding: 0 14px; }

/* 记忆列表 */
.mem-list { margin-top: 8px; }
.mem-row {
  display: flex; gap: 8px; align-items: flex-start;
  padding: 9px 11px; margin-bottom: 6px;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  font-size: 15px; line-height: 1.5;
}
.mem-row .m-type {
  flex: none; font-size: 12px; padding: 2px 7px; border-radius: 6px;
  background: #f0ece1; color: #7a6a4f; margin-top: 2px;
}
.mem-row .m-body { flex: 1; min-width: 0; word-break: break-all; }
.mem-row .m-time { display: block; font-size: 12px; color: #9b8f7a; margin-top: 3px; }
.mem-row button { flex: none; min-height: 34px; font-size: 13px; padding: 0 10px; }

/* 对话记录 */
.hist-list { max-height: 320px; overflow-y: auto; margin-top: 8px; }
.hist-row {
  font-size: 15px; line-height: 1.55; padding: 7px 10px; margin-bottom: 5px;
  border-radius: 9px; word-break: break-all;
}
.hist-row.u { background: #eef6f0; color: #2f5d43; }
.hist-row.a { background: #fff; border: 1px solid var(--line); color: var(--ink); }
.hist-row .h-at { display: block; font-size: 11px; color: #9b8f7a; margin-top: 2px; }
#wxLine { margin-bottom: 6px; }

/* 家庭成员 */
.fam-row {
  display: flex; gap: 6px; margin-bottom: 8px; align-items: center;
}
.fam-row input { flex: 1; min-width: 0; }
.fam-row .rel { flex: 0 0 74px; }
.fam-row button { flex: none; min-height: 38px; padding: 0 10px; font-size: 13px; }
.fam-row .elder-tag {
  flex: none; font-size: 11px; padding: 2px 6px; border-radius: 6px;
  background: #eef6f0; color: #2f6b46;
}
