:root {
  --bg: #fdf8f3;
  --surface: #ffffff;
  --surface-2: #faf7f4;
  --border: #ece2d9;
  --border-soft: #f3ece5;
  --text: #2a2320;
  --text-2: #6b6058;
  --text-3: #a5968a;
  --primary: #3b9dff;
  --primary-soft: #e4f1ff;
  --peach: #ff9b7a;
  --peach-soft: #fff1ea;
  --danger: #ef6b6b;
  --ok: #4bbd87;
  --warn: #f7b23b;
  --purple: #a97ae0;
  --radius: 16px;
  --radius-sm: 11px;
  /* 顶栏实际高度，由 JS 测量后写入；标签栏的 sticky 偏移依赖它 */
  --topbar-h: 59px;
  --shadow: 0 1px 2px rgba(90, 60, 30, .04), 0 6px 20px rgba(90, 60, 30, .07);
  --shadow-hover: 0 4px 10px rgba(90, 60, 30, .07), 0 12px 28px rgba(90, 60, 30, .10);
}

/* 图标 */
.ic { display: inline-block; vertical-align: -3px; flex: none; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 17px; }
h2 { font-size: 15px; }
h3 { font-size: 14px; }
p { margin: 0; }
code {
  background: #f1f3f5;
  border: 1px solid var(--border-soft);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 12px 20px;
  background: rgba(255, 255, 255, .88);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, #0091ff, #8e4ec6);
  color: #fff; font-weight: 700; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  letter-spacing: .5px;
}
.brand-txt p { color: var(--text-3); font-size: 12px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.datepick { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); }
.datepick input, .inline-pick input, .fld input, .fld select, .fld textarea, textarea {
  font: inherit; color: var(--text);
  background: #fff; border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 10px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.datepick input:focus, .inline-pick input:focus, .fld input:focus,
.fld select:focus, .fld textarea:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 145, 255, .12);
}
textarea { width: 100%; resize: vertical; }

/* ---------- 标签页 ---------- */
.tabs {
  position: sticky; top: var(--topbar-h); z-index: 29;
  display: flex; gap: 4px; overflow-x: auto;
  padding: 8px 20px;
  background: rgba(255, 255, 255, .9);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.tab {
  flex: none; font: inherit; font-size: 13px; color: var(--text-2);
  background: transparent; border: 0; border-radius: 8px;
  padding: 6px 14px; cursor: pointer; white-space: nowrap;
  transition: background .15s, color .15s;
}
.tab:hover { background: #f1f3f5; color: var(--text); }
.tab.active { background: var(--primary-soft); color: #0068bd; font-weight: 600; }

.wrap { max-width: 1120px; margin: 0 auto; padding: 20px; }

.panel { display: none; }
.panel.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; } }

/* ---------- 卡片 ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card-hd {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 12px; flex-wrap: wrap;
}
.sub-hd { font-size: 13px; color: var(--text-2); margin-bottom: 8px; font-weight: 600; }
.hint { font-size: 12px; color: var(--text-3); }
.tip { font-size: 12px; color: var(--text-3); margin: 6px 0; line-height: 1.7; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 860px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- 按钮 ---------- */
.btn {
  font: inherit; font-size: 13px; cursor: pointer;
  background: #fff; color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 14px; transition: all .15s;
}
.btn:hover { background: #f7f8fa; border-color: #d3d7dd; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: #007fdc; border-color: #007fdc; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: #f5c7c9; }
.btn.danger:hover { background: #fef2f2; }
.btn.tiny { font-size: 12px; padding: 4px 10px; }

/* ---------- 表单 ---------- */
.form-row { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.form-row.sub { margin-top: 4px; }
.fld { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-2); }
.fld.grow { flex: 1 1 200px; }
.fld input, .fld select, .fld textarea { min-width: 120px; }
.hidden { display: none !important; }
.inline-pick { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); }

/* ---------- 芯片（饮食计数） ---------- */
.chips { display: flex; gap: 10px; flex-wrap: wrap; }
.chips-actions { margin-top: 12px; }
.chip {
  position: relative; font: inherit; cursor: pointer;
  display: flex; align-items: center; gap: 8px;
  background: #fff; border: 1px solid var(--border);
  border-radius: 999px; padding: 8px 16px;
  color: var(--text); transition: all .15s;
}
.chip:hover { border-color: var(--primary); background: var(--primary-soft); }
.chip.active { border-color: var(--primary); background: var(--primary-soft); color: #0068bd; }
.chip.big { padding: 11px 22px; font-size: 15px; }
.chip-name { font-weight: 600; }
.chip-badge {
  min-width: 22px; height: 22px; padding: 0 6px;
  border-radius: 999px; background: var(--primary); color: #fff;
  font-size: 12px; font-weight: 700; line-height: 22px; text-align: center;
}
.chip:not(.active) .chip-badge { background: #c9ced6; }
.chip-minus {
  border: 0; background: transparent; cursor: pointer;
  color: var(--text-3); font-size: 16px; line-height: 1; padding: 0 2px;
}
.chip-minus:hover { color: var(--danger); }

/* ---------- 列表 ---------- */
.rec-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.rec {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; background: #fafbfc;
  border: 1px solid var(--border-soft); border-radius: 9px;
}
.rec-main { flex: 1; min-width: 0; }
.rec-title { font-weight: 600; }
.rec-sub { font-size: 12px; color: var(--text-3); }
.rec-val { font-weight: 700; color: var(--text); white-space: nowrap; }
.rec-del {
  border: 0; background: transparent; cursor: pointer;
  color: var(--text-3); font-size: 15px; padding: 2px 6px; border-radius: 6px;
}
.rec-del:hover { color: var(--danger); background: #fef2f2; }
.tag {
  display: inline-block; font-size: 11px; padding: 1px 8px;
  border-radius: 999px; background: #eef0f3; color: var(--text-2); margin-right: 6px;
}

/* ---------- 分段选择 ---------- */
.segmented { display: flex; gap: 6px; flex-wrap: nowrap; overflow-x: auto; }
.segmented.wrap { flex-wrap: wrap; overflow: visible; }
.seg {
  flex: 1 1 auto; font: inherit; font-size: 13px; cursor: pointer;
  background: #fff; border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 12px; color: var(--text-2);
  white-space: nowrap; transition: all .15s;
}
.seg:hover { border-color: #c9ced6; }
.seg.active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.seg.active[data-tone="bad"] { background: var(--danger); border-color: var(--danger); }
.seg.active[data-tone="soso"] { background: var(--warn); border-color: var(--warn); }
.seg.active[data-tone="good"] { background: var(--ok); border-color: var(--ok); }
.seg.active[data-tone="great"] { background: var(--primary); border-color: var(--primary); }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.kpis.small { grid-template-columns: repeat(4, 1fr); margin: 12px 0; }
@media (max-width: 860px) { .kpis, .kpis.small { grid-template-columns: repeat(2, 1fr); } }
.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow);
}
.kpi-label { font-size: 12px; color: var(--text-3); }
.kpi-value { font-size: 22px; font-weight: 700; letter-spacing: -.02em; margin-top: 2px; }
.kpi-value small { font-size: 12px; font-weight: 500; color: var(--text-3); margin-left: 3px; }
.kpi-foot { font-size: 11px; color: var(--text-3); margin-top: 2px; }

/* ---------- 今日速览 ---------- */
.today-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 860px) { .today-grid { grid-template-columns: 1fr; } }
.today-item {
  display: flex; gap: 10px; padding: 10px 12px;
  background: #fafbfc; border: 1px solid var(--border-soft); border-radius: 9px;
}
.today-k { font-size: 12px; color: var(--text-3); flex: none; width: 68px; }
.today-v { font-size: 13px; color: var(--text); min-width: 0; }
.today-v .muted { color: var(--text-3); }

/* ---------- 手机计时 ---------- */
.screen-live {
  display: flex; align-items: center; gap: 16px;
  padding: 14px; background: #fafbfc;
  border: 1px solid var(--border-soft); border-radius: 10px; margin-bottom: 12px;
}
.live-num { font-size: 30px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.live-num small { font-size: 12px; font-weight: 500; color: var(--text-3); margin-left: 4px; }
.live-meta { flex: 1; min-width: 0; }
.live-meta .dot {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: #c9ced6; margin-right: 6px; vertical-align: middle;
}
.live-meta .dot.on { background: var(--ok); box-shadow: 0 0 0 3px rgba(48, 164, 108, .18); }
.live-meta > div { font-size: 12px; color: var(--text-2); }

/* ---------- 图表 ---------- */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.grid { stroke: #f3ece5; stroke-width: 1; }
.axis { stroke: #e5dbd1; stroke-width: 1; }
.ax-label { font-size: 11px; fill: #a5968a; font-family: inherit; }
.ax-value { font-size: 11px; fill: #6b6058; font-weight: 600; font-family: inherit; }
.ax-goal { font-size: 10px; fill: #ef6b6b; font-family: inherit; }
.donut-num { font-size: 26px; font-weight: 700; fill: #2a2320; font-family: inherit; }
.donut-cap { font-size: 11px; fill: #a5968a; font-family: inherit; }
.hm-day { font-size: 11px; fill: #6b6058; font-family: inherit; }
.hm-badge { font-size: 9px; fill: #a5968a; font-family: inherit; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 10px; }
.lg-item { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); }
.lg-item i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }
.chart-empty {
  padding: 30px 0; text-align: center; color: var(--text-3);
  font-size: 13px; background: var(--surface-2); border-radius: var(--radius-sm);
}

/* ---------- 其他 ---------- */
.prose { font-size: 13px; color: var(--text-2); line-height: 1.9; }
.prose ol { margin: 6px 0; padding-left: 20px; }
.prose p { margin: 6px 0; }
/* 底部留出小狗的活动空间 */
.foot { text-align: center; color: var(--text-3); font-size: 12px; padding: 8px 20px 96px; }

.toast {
  position: fixed; left: 50%; bottom: 32px; transform: translate(-50%, 16px);
  background: #3b322c; color: #fff; font-size: 13px;
  padding: 9px 18px; border-radius: 999px;
  opacity: 0; pointer-events: none; transition: all .22s; z-index: 80;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ================= 等宽选项网格（睡眠 / 身体评价） ================= */
.opt-grid { display: grid; gap: 8px; }
.opt-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.opt-grid.cols-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.opt-grid.cols-7 { grid-template-columns: repeat(7, minmax(0, 1fr)); }
@media (max-width: 780px) {
  .opt-grid.cols-5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .opt-grid.cols-7 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
.opt {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; min-height: 64px; padding: 9px 5px;
  background: #fff; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font: inherit; font-size: 12.5px; color: var(--text-2); cursor: pointer;
  transition: transform .16s, border-color .16s, background .16s, box-shadow .16s;
}
.opt:hover { border-color: #ffcbb2; background: var(--peach-soft); transform: translateY(-2px); }
.opt .ic { color: var(--text-3); transition: color .16s; }
.opt.active {
  border-color: var(--tone, var(--primary));
  background: var(--tone-soft, var(--primary-soft));
  color: var(--tone-ink, #0a66c2); font-weight: 650;
  box-shadow: 0 2px 8px rgba(90, 60, 30, .08);
}
.opt.active .ic { color: var(--tone-ink, #0a66c2); }
.opt-sub { font-size: 10px; opacity: .65; font-weight: 500; }

/* ================= 月历汇总 ================= */
.cal-head { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 5px; margin-bottom: 5px; }
.cal-head span { text-align: center; font-size: 11px; color: var(--text-3); font-weight: 600; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 5px; }
.cal-cell {
  position: relative; min-height: 62px; border-radius: var(--radius-sm);
  padding: 4px 3px 5px; background: var(--surface-2);
  border: 1.5px solid var(--border-soft);
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  cursor: pointer; overflow: hidden;
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
.cal-cell:hover { transform: translateY(-2px); box-shadow: var(--shadow-hover); border-color: #ffd0b8; }
.cal-cell.pad, .cal-cell.blank { background: transparent; border-color: transparent; cursor: default; }
.cal-cell.pad:hover, .cal-cell.blank:hover { transform: none; box-shadow: none; }
.cal-cell.is-today { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(59, 157, 255, .16); }
.cal-day {
  font-size: 10px; color: var(--text-3); font-weight: 700;
  align-self: flex-start; padding-left: 2px; line-height: 1.2;
}
.cal-icons {
  display: flex; flex-wrap: wrap; gap: 0; justify-content: center; align-items: center;
  min-height: 20px;
}
.cal-icons .ic { margin: 0 -1px; }
.cal-val { font-size: 10px; font-weight: 700; color: var(--text-2); line-height: 1.1; }
.cal-val.dim { color: var(--text-3); font-weight: 600; }
.cal-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; }
.cal-cell.t-great { background: #e2f1ff; border-color: #c4e2ff; }
.cal-cell.t-good { background: #e6f7ee; border-color: #c2ead6; }
.cal-cell.t-soso { background: #fdf4e3; border-color: #f7e4ba; }
.cal-cell.t-bad { background: #fdedec; border-color: #f7cccc; }
.cal-cell.t-busy { background: #fdeee7; border-color: #f9d5c3; }
.cal-cell.t-ok { background: #eaf7ef; border-color: #c8ead7; }
.cal-cell.t-over { background: #fdeaea; border-color: #f7c9c9; }
.cal-legend { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.cal-legend .lg-item { font-size: 11.5px; }
.cal-legend i.dot { width: 11px; height: 11px; border-radius: 4px; border: 1.5px solid rgba(0,0,0,.06); }
.cal-note { font-size: 11.5px; color: var(--text-3); margin-top: 8px; line-height: 1.7; }

/* ================= 记录项可编辑 ================= */
.rec-edit { display: flex; align-items: flex-end; gap: 8px; flex-wrap: wrap; flex: 1; }
.rec-edit .fld { font-size: 11px; }
.rec-edit input, .rec-edit select { padding: 5px 8px; font-size: 13px; }
.rec-actions { display: flex; gap: 4px; flex: none; }
.icon-btn {
  border: 1px solid transparent; background: transparent; cursor: pointer;
  color: var(--text-3); border-radius: 8px; padding: 4px 6px; line-height: 0;
  transition: all .15s;
}
.icon-btn:hover { color: var(--text); background: #f4efe9; }
.icon-btn.danger:hover { color: var(--danger); background: #fdeded; }
.icon-btn.ok:hover { color: var(--ok); background: #e7f7ef; }

/* ================= 芯片（饮食计数）增强 ================= */
.chip { border-radius: 14px; padding: 8px 14px 8px 16px; }
.chip .ic { color: var(--text-3); }
.chip.active .ic { color: #0a66c2; }
.chip-count { display: inline-flex; align-items: center; gap: 3px; }
.chip-step {
  width: 20px; height: 20px; border-radius: 50%; border: 0; cursor: pointer;
  background: rgba(0, 0, 0, .07); color: var(--text-2);
  font-size: 13px; line-height: 20px; padding: 0; text-align: center;
  transition: all .15s;
}
.chip-step:hover { background: var(--danger); color: #fff; }
.chip-step.plus:hover { background: var(--primary); color: #fff; }

/* ================= 会活动的小猫和小狗 ================= */
.dog-stage {
  position: fixed; left: 0; right: 0; bottom: 0; height: 132px;
  pointer-events: none; z-index: 45;
  /* 用 overflow: visible，避免跳跃到最高点时气泡被裁掉；
     横向位置由 JS 按 clientWidth 夹取，不会产生滚动条。 */
}
.pet {
  position: absolute; bottom: 8px;
  pointer-events: auto; cursor: pointer; will-change: transform;
  filter: drop-shadow(0 4px 8px rgba(120, 80, 40, .16));
}
.pet-flip { position: absolute; inset: 0; width: 100%; height: 100%; }
.pet.dog { width: 84px; height: 84px; }
.pet.cat { width: 78px; height: 78px; bottom: 9px; }
.pet-inner { width: 100%; height: 100%; position: relative; }
.pet-svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.pet-svg.sleep { display: none; }
.pet.sleep .pet-svg.stand { display: none; }
.pet.sleep .pet-svg.sleep { display: block; }
.pet-say {
  position: absolute; top: -6px; left: 50%; transform: translateX(-50%);
  background: #fff; border: 1.5px solid var(--border); border-radius: 999px;
  padding: 1px 9px; font-size: 11px; font-weight: 700; color: var(--text-2);
  opacity: 0; transition: opacity .2s, transform .2s; white-space: nowrap;
  box-shadow: var(--shadow);
}
.pet.bark .pet-say { opacity: 1; transform: translateX(-50%) translateY(-6px); }

/* 互动时头顶飘出的小图标：跳舞=音符，吃饭=爱心 */
.pet-fx { position: absolute; top: -2px; right: 0; line-height: 0; opacity: 0; }
.pet.dance .pet-fx, .pet.eat .pet-fx { animation: fxFloat 1.9s infinite ease-out; }
.pet.dance .pet-fx { color: #a97ae0; }
.pet.eat .pet-fx { color: #ef6b6b; }
.pet.cat.dance .pet-fx, .pet.cat.eat .pet-fx { animation-delay: .55s; }
@keyframes fxFloat {
  0% { opacity: 0; transform: translateY(4px) scale(.55); }
  25% { opacity: 1; transform: translateY(-4px) scale(1); }
  65% { opacity: 1; transform: translateY(-11px) scale(1); }
  100% { opacity: 0; transform: translateY(-20px) scale(.65); }
}

/* 共用的食盆，只在「一起吃饭」时出现 */
.pet-bowl {
  position: absolute; bottom: 7px; left: 0; width: 44px; height: 44px;
  display: none; filter: drop-shadow(0 3px 6px rgba(120, 80, 40, .18));
}
.pet-bowl svg { width: 100%; height: 100%; overflow: visible; }

/* ---- 腿部与尾巴：狗猫共用同一套动画 ---- */
.dg-leg, .ct-leg { transform-box: fill-box; transform-origin: top center; }
.dg-tail, .ct-tail { transform-box: fill-box; transform-origin: right center; }

.pet.walk .dg-tail { animation: tailWag .55s infinite ease-in-out; }
.pet.walk .ct-tail { animation: tailWag 1.1s infinite ease-in-out; }
.pet.walk .dg-leg-a { animation: legSwing .44s infinite ease-in-out; }
.pet.walk .dg-leg-b { animation: legSwing .44s infinite ease-in-out .22s; }
.pet.walk .dg-leg-c { animation: legSwing .44s infinite ease-in-out .11s; }
.pet.walk .dg-leg-d { animation: legSwing .44s infinite ease-in-out .33s; }
.pet.walk .ct-leg-a { animation: legSwing .42s infinite ease-in-out .08s; }
.pet.walk .ct-leg-b { animation: legSwing .42s infinite ease-in-out .29s; }
.pet.walk .ct-leg-c { animation: legSwing .42s infinite ease-in-out; }
.pet.walk .ct-leg-d { animation: legSwing .42s infinite ease-in-out .21s; }
.pet.walk .pet-inner { animation: petBob .44s infinite ease-in-out; }
.pet.jump .pet-inner { animation: petStretch .5s ease-out; }
@keyframes tailWag { 0%, 100% { transform: rotate(-10deg); } 50% { transform: rotate(16deg); } }
@keyframes legSwing { 0%, 100% { transform: rotate(-18deg); } 50% { transform: rotate(18deg); } }
@keyframes petBob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-2.5px); } }
@keyframes petStretch { 0% { transform: scale(1, 1); } 35% { transform: scale(.9, 1.14); } 100% { transform: scale(1, 1); } }

/* ---- 一起跑：更快更前倾 ---- */
.pet.chase .dg-tail { animation: tailWag .3s infinite ease-in-out; }
.pet.chase .ct-tail { animation: tailWag .5s infinite ease-in-out; }
.pet.chase .dg-leg-a, .pet.chase .ct-leg-a { animation: legSwing .26s infinite ease-in-out; }
.pet.chase .dg-leg-b, .pet.chase .ct-leg-b { animation: legSwing .26s infinite ease-in-out .13s; }
.pet.chase .dg-leg-c, .pet.chase .ct-leg-c { animation: legSwing .26s infinite ease-in-out .065s; }
.pet.chase .dg-leg-d, .pet.chase .ct-leg-d { animation: legSwing .26s infinite ease-in-out .195s; }
.pet.chase .pet-inner { animation: chaseLean .26s infinite ease-in-out; }
@keyframes chaseLean {
  0%, 100% { transform: rotate(-7deg) translateY(0); }
  50% { transform: rotate(-7deg) translateY(-3.5px); }
}

/* ---- 一起跳舞：面对面左右摇摆 ---- */
.pet.dance .pet-inner { animation: petDance .82s infinite ease-in-out; }
.pet.cat.dance .pet-inner { animation: petDance .82s infinite ease-in-out .41s; }
@keyframes petDance {
  0%, 100% { transform: rotate(-10deg) translateY(0); }
  25% { transform: rotate(0deg) translateY(-6px); }
  50% { transform: rotate(10deg) translateY(0); }
  75% { transform: rotate(0deg) translateY(-6px); }
}

/* ---- 一起吃饭：低头吃一口，再抬头 ---- */
.pet.eat .dg-head, .pet.eat .ct-head {
  transform-box: fill-box; transform-origin: bottom left;
  animation: petNibble 1.15s infinite ease-in-out;
}
.pet.cat.eat .ct-head { animation-delay: .57s; }
@keyframes petNibble {
  0%, 45% { transform: translate(0, 0) rotate(0deg); }
  70% { transform: translate(-1.5px, 3.5px) rotate(20deg); }
  85% { transform: translate(-1.5px, 3.5px) rotate(20deg); }
  100% { transform: translate(0, 0) rotate(0deg); }
}
.pet.eat .dg-tail { transform-box: fill-box; transform-origin: right center; animation: tailWag .42s infinite ease-in-out; }
.pet.eat .ct-tail { transform-box: fill-box; transform-origin: right center; animation: tailWag .85s infinite ease-in-out; }

/* ---- 睡觉 ---- */
.dg-z, .ct-z { font-size: 6px; font-weight: 700; fill: #a5968a; opacity: 0; }
.pet.sleep .dg-z1, .pet.sleep .ct-z1 { animation: zzz 2.6s infinite ease-out; }
.pet.sleep .dg-z2, .pet.sleep .ct-z2 { animation: zzz 2.6s infinite ease-out .6s; }
.pet.sleep .dg-z3, .pet.sleep .ct-z3 { animation: zzz 2.6s infinite ease-out 1.2s; }
.pet.sleep .pet-inner { animation: petBreath 3.4s infinite ease-in-out; }
.pet.sleep .dg-tail-sleep, .pet.sleep .ct-tail-sleep {
  transform-box: fill-box; transform-origin: right center;
  animation: tailWag 1.6s infinite ease-in-out;
}
.pet.cat.sleep .pet-inner { animation: petBreath 2.8s infinite ease-in-out; }
@keyframes zzz {
  0% { opacity: 0; transform: translate(0, 4px) scale(.7); }
  30% { opacity: .95; }
  100% { opacity: 0; transform: translate(5px, -9px) scale(1.25); }
}
@keyframes petBreath { 0%, 100% { transform: scale(1, 1); } 50% { transform: scale(1.025, .975); } }

.dog-toggle {
  display: inline-flex; align-items: center; gap: 5px;
  border: 1px solid var(--border); background: #fff; color: var(--text-2);
  border-radius: 999px; padding: 5px 11px; font: inherit; font-size: 12px; cursor: pointer;
  transition: all .15s;
}
.dog-toggle:hover { border-color: var(--peach); color: var(--text); background: var(--peach-soft); }
.dog-toggle.off { opacity: .55; }
.dog-stage.hidden { display: none; }

@media (prefers-reduced-motion: reduce) {
  .dog-stage { display: none; }
}

/* ================= 手机桌面（PWA）适配 ================= */

/* iPhone 刘海 / 底部横条：避免内容被遮挡 */
body {
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}
.dog-stage { padding-bottom: env(safe-area-inset-bottom); }
.toast { bottom: calc(32px + env(safe-area-inset-bottom)); }

/* 装到桌面后隐藏 Safari / Chrome 地址栏时，顶部多留一点呼吸位 */
@supports (display: standalone) {
  .topbar { padding-top: calc(10px + env(safe-area-inset-top)); }
}

/* 安装指引弹层 */
.sheet-mask {
  position: fixed; inset: 0; z-index: 120;
  background: rgba(58, 44, 34, .38);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0 0 calc(0px + env(safe-area-inset-bottom));
  animation: sheetIn .18s ease-out;
}
.sheet-mask[hidden] { display: none; }
@keyframes sheetIn { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  width: 100%; max-width: 520px;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 32px rgba(90, 60, 30, .16);
  animation: sheetUp .24s cubic-bezier(.2, .9, .3, 1);
}
@media (min-width: 600px) {
  .sheet-mask { align-items: center; }
  .sheet { border-radius: 20px; margin: 20px; animation-name: sheetPop; }
  @keyframes sheetPop { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }
}
@keyframes sheetUp { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }

.sheet h3 { margin: 0 0 6px; font-size: 17px; }
.sheet-sub { margin: 0 0 14px; font-size: 13px; color: var(--text-2); }
.sheet-steps { margin: 0 0 18px; padding-left: 20px; font-size: 13.5px; line-height: 1.9; color: var(--text); }
.sheet-steps li { margin-bottom: 4px; }
.sheet-steps b { color: var(--peach); font-weight: 600; }
.sheet-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ============================================================
   移动端适配
   ============================================================ */

/* 横屏时 iOS 会自作主张放大字号，锁住 */
html { -webkit-text-size-adjust: 100%; }

/* iOS Safari 的坑：输入框字号 < 16px 时，聚焦瞬间会强制放大整个页面，
   缩放后布局看着就像「散架」了。只在触控设备上抬到 16px，桌面端保持原样。 */
@media (pointer: coarse) {
  .datepick input, .inline-pick input,
  .fld input, .fld select, .fld textarea,
  .rec-edit input, .rec-edit select, textarea {
    font-size: 16px;
  }
  /* 触控设备上的小按钮也要够大，手指点得中 */
  .btn.tiny { min-height: 34px; padding: 6px 12px; }
  .icon-btn { min-height: 34px; min-width: 34px; }
}

/* 长文本不撑破容器，避免整页出现横向滚动 */
.rec-title, .rec-sub, .today-v, .chip-name,
.prose, .cal-note, .hint, .tip, .kpi-foot { overflow-wrap: anywhere; }

/* ============ 顶栏：断点放宽到 860px ============
 * 实测 768px（iPad 竖屏）顶栏就已经挤到换行了，
 * 所以顶栏的压缩规则要比其它组件更早生效。 */
@media (max-width: 860px) {
  .topbar { flex-wrap: wrap; gap: 6px 8px; padding: 8px 12px; }
  .brand { gap: 8px; }
  .logo { width: 26px; height: 26px; font-size: 10px; border-radius: 7px; }
  h1 { font-size: 14.5px; }
  .brand-txt p { display: none; }
  .topbar-right {
    gap: 6px; margin-left: auto;
    flex-wrap: wrap; justify-content: flex-end;
  }
  .datepick { gap: 4px; }
  .datepick > span { display: none; }
  .datepick input { padding: 5px 7px; max-width: 132px; font-size: 13px; }
  .topbar-right .btn { padding: 5px 9px; font-size: 12px; min-height: 32px; }
  .dog-toggle { min-height: 32px; }
  /* 窄屏下这两个按钮只留图标，不然顶栏会被挤成三行 */
  #btnInstall > span, #btnToday > span { display: none; }
  #btnInstall, #btnToday { padding: 5px 8px; min-width: 34px; justify-content: center; }
}

/* ============ 手机竖屏 ============ */
@media (max-width: 640px) {

  /* —— 标签栏：横向滚动，隐藏滚动条 —— */
  .tabs {
    padding: 6px 10px; gap: 3px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { padding: 7px 12px; font-size: 13px; }

  /* —— 容器与卡片 —— */
  .wrap { padding: 12px; }
  .card { padding: 13px; margin-bottom: 12px; border-radius: 14px; }
  .card-hd { gap: 8px; margin-bottom: 10px; }
  .grid-2 { gap: 12px; }

  /* —— KPI —— */
  .kpis { grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 12px; }
  .kpis.small { grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 10px 0; }
  .kpi { padding: 10px 12px; }
  .kpi-value { font-size: 19px; }

  /* —— 表单：每个字段独占一行，避免并排挤压 —— */
  .form-row { gap: 8px; margin-bottom: 8px; }
  .fld { flex: 1 1 100%; }
  .fld input, .fld select, .fld textarea { min-width: 0; width: 100%; }

  /* —— 按钮：触控目标至少 38px —— */
  .btn {
    min-height: 38px;
    display: inline-flex; align-items: center; justify-content: center;
  }
  .btn.tiny { min-height: 32px; }

  /* —— 芯片（饮食计数）—— */
  .chips { gap: 8px; }
  .chip { padding: 8px 12px 8px 13px; min-height: 44px; }
  .chip.big { padding: 10px 16px; font-size: 14.5px; min-height: 50px; }
  .chip-step { width: 26px; height: 26px; line-height: 26px; font-size: 16px; }
  .chip-minus { font-size: 18px; padding: 0 5px; }

  /* —— 选项网格（睡眠时段 / 身体评价）—— */
  .opt-grid { gap: 7px; }
  .opt-grid.cols-7 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .opt-grid.cols-5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .opt { min-height: 58px; padding: 8px 4px; font-size: 12px; }
  .opt-sub { font-size: 9.5px; }

  /* —— 月历：7 列在 390px 下每格仅约 41px，必须全面收紧 —— */
  .cal-head, .cal { gap: 3px; }
  .cal-head span { font-size: 10px; }
  .cal-cell { min-height: 54px; padding: 3px 1px 4px; border-radius: 9px; }
  .cal-day { font-size: 9px; padding-left: 1px; }
  .cal-icons { min-height: 17px; }
  .cal-icons .ic { width: 13px; height: 13px; margin: 0 -1.5px; }
  .cal-val { font-size: 9px; }
  .cal-bar { height: 2.5px; }
  .cal-legend { gap: 8px; margin-top: 10px; }
  .cal-legend .lg-item { font-size: 11px; }
  .cal-note { font-size: 11px; }

  /* —— 手机计时 —— */
  .screen-live { gap: 12px; padding: 12px; }
  .live-num { font-size: 25px; }

  /* —— 记录项 —— */
  .rec { padding: 9px 10px; gap: 8px; }
  .rec-val { font-size: 13px; }
  .rec-actions { gap: 2px; }
  .icon-btn { padding: 6px; }
  .rec-edit { gap: 6px; }
  .rec-edit .fld { flex: 1 1 100%; }

  /* —— 分段选择 —— */
  .seg { padding: 8px 11px; font-size: 12.5px; min-height: 40px; }

  /* —— 图表图例 —— */
  .legend { gap: 9px; margin-top: 8px; }
  .lg-item { font-size: 11.5px; }

  /* —— 今日速览 —— */
  .today-item { padding: 9px 10px; }
  .today-k { width: 58px; font-size: 11.5px; }
  .today-v { font-size: 12.5px; }

  /* —— 宠物：手机上等比缩小，别糊住内容 —— */
  .dog-stage { height: 108px; }
  .pet.dog { width: 62px; height: 62px; }
  .pet.cat { width: 57px; height: 57px; bottom: 7px; }
  .pet-say { font-size: 10px; padding: 1px 7px; }
  .foot { padding: 8px 16px 88px; }

  /* —— toast 抬到宠物头顶，免得被挡住 —— */
  .toast {
    bottom: calc(104px + env(safe-area-inset-bottom));
    max-width: calc(100vw - 40px);
    text-align: center;
  }
}

/* ============ 极窄屏（iPhone SE / 小屏安卓 360px） ============ */
@media (max-width: 400px) {
  .wrap { padding: 10px; }
  .card { padding: 11px; margin-bottom: 10px; }
  .cal-head, .cal { gap: 2px; }
  .cal-cell { min-height: 48px; padding: 2px 0 3px; }
  .cal-icons .ic { width: 12px; height: 12px; }
  .cal-val { font-size: 8.5px; }
  .kpi-value { font-size: 18px; }
  .kpi { padding: 9px 10px; }
  .chip { padding: 7px 11px 7px 12px; }
  .pet.dog { width: 54px; height: 54px; }
  .pet.cat { width: 50px; height: 50px; }
  .dog-stage { height: 96px; }
  .foot { padding-bottom: 78px; }
  .toast { bottom: calc(92px + env(safe-area-inset-bottom)); }
}

/* ============ 横屏（屏幕矮，宠物要收着点） ============ */
@media (orientation: landscape) and (max-height: 500px) {
  .dog-stage { height: 74px; }
  .pet.dog { width: 48px; height: 48px; }
  .pet.cat { width: 44px; height: 44px; bottom: 6px; }
  .foot { padding-bottom: 62px; }
  .toast { bottom: calc(76px + env(safe-area-inset-bottom)); }
}
