:root {
  --bg: #FFF6E9;
  --bg-soft: #FFF1DC;
  --card: #FFFDF8;
  --ink: #5A4632;
  --ink-soft: #8C7660;
  --line: #F0E0C8;
  --accent: #E8895A;
  --accent-deep: #D96F3F;
  --wood: #C89B6A;
  --wood-deep: #A97C4E;
  --shadow: 0 8px 24px rgba(120, 80, 40, 0.22);
  --radius: 20px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  overscroll-behavior: none;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
img { display: block; }
textarea, input, select { font-family: inherit; font-size: 16px; color: var(--ink); }
.hidden { display: none !important; }
::-webkit-scrollbar { width: 0; height: 0; }

/* ============ 家的场景（永远在背景） ============ */
.care-scene {
  position: fixed; inset: 0; z-index: 0;
  overflow: hidden;
  background: linear-gradient(180deg, #FFEFD4, #FFE2BC);
  touch-action: none;
}
.scene-track {
  position: absolute; top: 0; left: 0; height: 100%; width: 233%;
  transition: transform .35s cubic-bezier(.22,.9,.32,1);
  will-change: transform;
}
.scene-pano {
  position: absolute; inset: 0;
  background: url("../assets/generated/home-panorama.png") center / cover no-repeat;
}
.scene-pet {
  position: absolute; bottom: 22%; z-index: 2;
  width: clamp(170px, 26vw, 330px);
  filter: drop-shadow(0 12px 14px rgba(70, 45, 20, 0.30));
  transition: left .65s cubic-bezier(.22,.9,.32,1);
  pointer-events: auto; cursor: pointer;
}
.scene-pet.centered { width: clamp(190px, 30vw, 380px); }
.scene-pet.tap-pop { animation: petPop .45s ease; }
@keyframes petPop { 0% { transform: scale(1); } 40% { transform: scale(1.12) rotate(-3deg); } 100% { transform: scale(1); } }
.scene-pet.wobble { animation: petWobble .5s ease; }
@keyframes petWobble { 0%,100% { transform: rotate(0); } 25% { transform: rotate(-6deg); } 75% { transform: rotate(6deg); } }
.home-spots { position: absolute; inset: 0; z-index: 1; pointer-events: none; }
.home-spot {
  position: absolute; transform: translate(-50%, -50%);
  width: 46px; height: 46px;
  display: flex; align-items: center; justify-content: center;
  pointer-events: auto; cursor: pointer;
  border-radius: 50%;
}
.home-spot .hint-paw { font-size: 18px; opacity: .38; }
.home-spot .spot-emoji { font-size: 26px; }

.pet-speech {
  position: fixed; top: calc(14px + var(--safe-top)); left: 50%; transform: translateX(-50%);
  z-index: 5; width: max-content; max-width: 84%;
  min-height: 38px; display: flex; align-items: center; justify-content: center;
  background: rgba(255, 251, 244, 0.95);
  border-radius: 14px; box-shadow: var(--shadow);
  padding: 9px 16px; font-size: 14px; line-height: 1.6; color: var(--ink);
  text-align: center;
}
.scene-hint {
  position: fixed; bottom: calc(92px + var(--safe-bottom)); left: 50%; transform: translateX(-50%);
  font-size: 12px; color: var(--ink-soft); background: rgba(255, 251, 244, 0.9);
  padding: 6px 14px; border-radius: 999px; z-index: 5;
  transition: opacity .6s; pointer-events: none; white-space: nowrap;
}
.scene-hint.faded { opacity: 0; }
.out-note {
  position: fixed; bottom: calc(92px + var(--safe-bottom)); left: 50%; transform: translateX(-50%);
  z-index: 5; background: rgba(255, 250, 240, 0.95);
  border-radius: 999px; padding: 8px 16px; font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow);
}
.gift-banner {
  position: fixed; top: 38%; left: 50%; transform: translate(-50%, -50%);
  z-index: 6; background: rgba(255, 250, 240, 0.97);
  border: 2px solid #F5C566; border-radius: 18px;
  box-shadow: 0 12px 30px rgba(120, 80, 30, .35);
  padding: 16px 22px; font-size: 15px; line-height: 1.8; text-align: center;
  animation: giftIn .5s cubic-bezier(.22,1.4,.36,1);
  max-width: 86%;
}
@keyframes giftIn { from { transform: translate(-50%, -50%) scale(.5); opacity: 0; } to { transform: translate(-50%, -50%) scale(1); opacity: 1; } }
.overlay-emoji { position: absolute; pointer-events: none; z-index: 7; animation: floatUp 1.6s ease-out forwards; }
@keyframes floatUp { 0% { opacity: 0; transform: translateY(10px) scale(.5); } 20% { opacity: 1; } 100% { opacity: 0; transform: translateY(-46px) scale(1.05); } }

/* ============ 底部浮动操作钮 ============ */
.action-dock {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(16px + var(--safe-bottom)); z-index: 8;
  display: flex; gap: 14px;
  background: rgba(110, 76, 44, 0.72);
  padding: 8px 16px; border-radius: 999px;
  backdrop-filter: blur(8px);
  box-shadow: 0 6px 20px rgba(70, 45, 20, .35);
}
.dock-btn {
  width: 52px; height: 52px; border-radius: 50%;
  background: linear-gradient(180deg, #F7E3C8, #EACBA2);
  box-shadow: inset 0 -3px 0 rgba(140, 95, 45, .35), 0 3px 8px rgba(70, 45, 20, .3);
  font-size: 24px;
  transition: transform .12s;
}
.dock-btn:active { transform: scale(.9) translateY(2px); }

/* ============ 侧边功能栏 ============ */
.win-rail {
  position: fixed; right: calc(10px + var(--safe-right)); top: 50%; transform: translateY(-50%);
  z-index: 8; display: flex; flex-direction: column; gap: 10px;
}
.rail-btn {
  width: 46px; height: 46px; border-radius: 14px;
  background: rgba(110, 76, 44, 0.72);
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 12px rgba(70, 45, 20, .3);
  font-size: 21px;
  display: flex; align-items: center; justify-content: center;
  transition: transform .12s, background .2s;
}
.rail-btn:active { transform: scale(.9); }
.rail-btn.on { background: rgba(217, 111, 63, 0.9); }
.rail-btn { position: relative; }
.rail-badge {
  position: absolute; top: -5px; right: -5px;
  min-width: 18px; height: 18px; border-radius: 999px;
  background: #E5484D; color: #fff;
  font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  padding: 0 5px; box-shadow: 0 2px 6px rgba(0,0,0,.3);
}
.dog-letter-tag {
  font-size: 11px; font-weight: 700; color: #B06A3A;
  background: #FFF0DC; border-radius: 999px; padding: 3px 9px;
  margin-left: auto; margin-right: 8px;
}

/* ============ 功能窗口 ============ */
.app-window {
  position: fixed; inset: 0; z-index: 40;
  display: none; align-items: center; justify-content: center;
  padding: 14px;
  background: rgba(60, 42, 24, 0.42);
  backdrop-filter: blur(3px);
}
.app-window.open { display: flex; }
.win-card {
  width: min(94vw, 620px);
  max-height: 88dvh;
  display: flex; flex-direction: column;
  background: rgba(255, 251, 244, 0.97);
  border-radius: 24px;
  box-shadow: 0 24px 60px rgba(50, 30, 10, .4);
  overflow: hidden;
  animation: winIn .3s cubic-bezier(.22,1.2,.36,1);
}
@keyframes winIn { from { transform: translateY(24px) scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }
.win-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 14px 16px;
  background: linear-gradient(135deg, #F7E3C8, #EFD2A8);
  border-bottom: 1px solid rgba(160, 115, 65, .25);
}
.win-title { font-size: 16px; font-weight: 800; color: var(--wood-deep); }
.win-close {
  width: 32px; height: 32px; border-radius: 50%;
  background: rgba(255,255,255,.75); color: var(--ink);
  font-size: 14px; box-shadow: 0 2px 6px rgba(70,45,20,.2);
  margin-left: auto;
}
.win-body {
  padding: 16px; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.win-card-chat { height: min(82dvh, 680px); }
.win-card-chat .win-body { flex: 1; display: flex; flex-direction: column; }

/* ============ 通用卡片 / 按钮 / 表单 ============ */
.card {
  background: var(--card);
  border: 1px solid rgba(210, 170, 120, .35);
  border-radius: var(--radius);
  box-shadow: 0 4px 14px rgba(140, 95, 50, .10);
  padding: 16px;
  margin-bottom: 12px;
}
.card-title { margin: 0 0 12px; font-size: 15px; color: var(--accent-deep); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 16px; border-radius: 13px;
  font-size: 14px; font-weight: 700;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:active { background: var(--accent-deep); }
.btn.ghost { background: var(--bg-soft); color: var(--accent-deep); }
.btn.full { width: 100%; }
.btn.small { padding: 7px 12px; font-size: 12px; border-radius: 10px; }
.btn.danger { background: #FBE9E7; color: #B05C4E; }
.empty-tip { color: var(--ink-soft); font-size: 13px; text-align: center; padding: 18px 8px; line-height: 1.8; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 12px; }
.chip {
  background: var(--bg-soft); color: var(--accent-deep);
  font-size: 12px; padding: 6px 12px; border-radius: 999px; font-weight: 600;
}

/* 主页窗口 */
.hero-card { text-align: center; margin-bottom: 12px; }
.avatar-wrap {
  position: relative;
  width: 120px; height: 120px;
  margin: 4px auto 12px;
  border-radius: 50%; overflow: hidden;
  border: 4px solid #fff;
  box-shadow: var(--shadow);
  background: linear-gradient(145deg, #FFE9CE, #FFD9B8);
}
.avatar-wrap img { width: 100%; height: 100%; object-fit: cover; }
.avatar-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(90, 70, 50, 0.45);
  color: #fff; font-size: 13px; font-weight: 600;
  opacity: 0; transition: opacity .2s;
}
.avatar-wrap:hover .avatar-overlay, .avatar-wrap.no-photo .avatar-overlay { opacity: 1; }
.home-name { margin: 0 0 6px; font-size: 22px; }
.home-meta { color: var(--ink-soft); font-size: 13px; line-height: 1.7; }
.home-story { color: var(--ink); font-size: 14px; line-height: 1.9; margin: 10px auto 0; white-space: pre-wrap; }
.memorial-days { display: flex; flex-direction: column; gap: 10px; }
.mem-day {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg-soft); border-radius: 14px; padding: 12px 14px;
}
.mem-day .icon { font-size: 22px; }
.mem-day .body { flex: 1; }
.mem-day .title { font-size: 14px; font-weight: 700; }
.mem-day .desc { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }
.mem-day .del { color: #C98A8A; font-size: 16px; padding: 4px 8px; }
.gift-list { display: flex; flex-wrap: wrap; gap: 8px; }
.gift-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-soft); border-radius: 999px;
  padding: 7px 13px; font-size: 13px; font-weight: 600;
}
.gift-chip .g-date { font-size: 11px; color: var(--ink-soft); font-weight: 400; }

/* 回忆窗口 */
.sub-tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.sub-tab {
  flex: 1; padding: 9px 0; border-radius: 13px;
  background: var(--bg-soft); font-size: 14px; font-weight: 600; color: var(--ink-soft);
}
.sub-tab.active { background: var(--accent); color: #fff; }
.photo-wall { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.photo-item {
  position: relative; border-radius: 14px; overflow: hidden;
  aspect-ratio: 1; background: var(--bg-soft);
}
.photo-item img { width: 100%; height: 100%; object-fit: cover; }
.photo-item .del {
  position: absolute; top: 4px; right: 4px;
  width: 24px; height: 24px; border-radius: 50%;
  background: rgba(0,0,0,.45); color: #fff; font-size: 13px; line-height: 1;
}
.timeline { position: relative; padding-left: 22px; margin-bottom: 12px; }
.timeline::before { content: ""; position: absolute; left: 7px; top: 6px; bottom: 6px; width: 2px; background: var(--line); }
.diary-item { position: relative; margin-bottom: 16px; }
.diary-item::before {
  content: ""; position: absolute; left: -21px; top: 6px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent); border: 3px solid #fff; box-shadow: 0 0 0 2px var(--line);
}
.diary-card { background: var(--card); border-radius: 16px; box-shadow: var(--shadow); padding: 14px; }
.diary-date { font-size: 12px; color: var(--ink-soft); margin-bottom: 6px; }
.diary-text { font-size: 14px; line-height: 1.9; white-space: pre-wrap; }
.diary-photos { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.diary-photos img { width: 80px; height: 80px; object-fit: cover; border-radius: 10px; }

/* 信件窗口 */
.intro-card { text-align: center; color: var(--ink-soft); font-size: 14px; line-height: 1.8; }
.letter-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 12px; }
.mem-section-title { font-size: 13px; font-weight: 700; color: var(--accent-deep); margin: 6px 0 2px; }
.letter-item { background: var(--card); border-radius: 16px; box-shadow: var(--shadow); padding: 16px; }
.letter-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.letter-date { font-size: 12px; color: var(--ink-soft); }
.letter-text { font-size: 14px; line-height: 1.9; white-space: pre-wrap; }
.letter-reply {
  margin-top: 12px; border-top: 1px dashed var(--line); padding-top: 12px;
  background: linear-gradient(135deg, #FFF9EF, #FFF3E2);
  border-radius: 14px; padding: 14px;
}
.letter-reply-head { font-size: 13px; font-weight: 700; color: var(--accent-deep); margin-bottom: 6px; }
.letter-reply-text { font-size: 14px; line-height: 1.9; white-space: pre-wrap; }
.letter-reply-photo { margin-top: 10px; width: 130px; height: 130px; object-fit: cover; border-radius: 14px; border: 3px solid #fff; box-shadow: var(--shadow); }
.letter-reply .replying { color: var(--ink-soft); font-size: 13px; }

/* 聊天窗口 */
.win-card-chat .chat-pet { display: flex; align-items: center; gap: 10px; }
.win-card-chat .chat-pet img { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: var(--bg-soft); }
.chat-pet-name { font-weight: 700; font-size: 15px; }
.chat-pet-status { font-size: 12px; color: var(--ink-soft); }
.chat-log { flex: 1; overflow-y: auto; padding: 4px 2px; display: flex; flex-direction: column; gap: 10px; min-height: 120px; }
.msg { max-width: 84%; padding: 10px 14px; border-radius: 16px; font-size: 14px; line-height: 1.7; white-space: pre-wrap; word-break: break-word; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 6px; }
.msg.pet { align-self: flex-start; background: var(--card); box-shadow: var(--shadow); border-bottom-left-radius: 6px; }
.msg.error { align-self: center; background: #FBE9E7; color: #B05C4E; font-size: 13px; max-width: 92%; }
.msg.system { align-self: center; color: var(--ink-soft); font-size: 12px; }
.chat-input-wrap {
  display: flex; gap: 8px; align-items: flex-end;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 8px; margin-top: 10px;
}
.chat-input-wrap textarea {
  flex: 1; resize: none; border: none; outline: none; background: var(--bg-soft);
  border-radius: 12px; padding: 10px 12px; max-height: 110px; line-height: 1.5;
}

/* 设置窗口 */
.setting-tabs { display: flex; gap: 6px; margin-bottom: 14px; overflow-x: auto; }
.setting-tab {
  flex-shrink: 0; padding: 8px 14px; border-radius: 999px;
  background: var(--bg-soft); font-size: 13px; font-weight: 600; color: var(--ink-soft);
}
.setting-tab.active { background: var(--accent); color: #fff; }
.setting-view { display: none; }
.setting-view.active { display: block; }
.kv-row { display: flex; justify-content: space-between; align-items: center; padding: 12px 2px; border-bottom: 1px dashed var(--line); font-size: 14px; }
.kv-row:last-child { border-bottom: none; }
.test-result { font-size: 13px; margin-top: 8px; line-height: 1.6; }
.test-result.ok { color: #6E9E5C; }
.test-result.fail { color: #B05C4E; }

.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.form-group input, .form-group textarea, .form-group select {
  width: 100%; border: 1.5px solid var(--line); border-radius: 12px;
  padding: 10px 12px; background: #fff; outline: none;
}
.form-group textarea { resize: vertical; min-height: 72px; line-height: 1.7; }
.form-group input:focus, .form-group textarea:focus { border-color: var(--accent); }
.form-hint { font-size: 12px; color: var(--ink-soft); margin-top: 4px; line-height: 1.6; }
.form-row { display: flex; gap: 10px; }
.form-row .form-group { flex: 1; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.modal-actions .btn { flex: 1; }

/* 通用弹窗（小交互窗口：喂食/抚摸等） */
.modal {
  position: fixed; inset: 0; z-index: 60;
  display: none; align-items: center; justify-content: center;
  background: rgba(60, 42, 24, 0.3);
}
.modal.open { display: flex; }
.modal-sheet {
  width: min(88vw, 400px);
  max-height: 80dvh; overflow-y: auto;
  background: rgba(255, 251, 244, 0.97);
  border-radius: 22px;
  padding: 18px;
  animation: winIn .3s cubic-bezier(.22,1.2,.36,1);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-title { font-size: 16px; font-weight: 800; }
.modal-close { width: 32px; height: 32px; border-radius: 50%; background: var(--bg-soft); font-size: 14px; }

/* 宽屏（折叠屏展开）微调 */
@media (min-width: 1000px) {
  .scene-pet { width: clamp(150px, 20vw, 300px); }
  .scene-pet.centered { width: clamp(170px, 24vw, 360px); }
  .win-rail { right: calc(18px + var(--safe-right)); }
  .rail-btn { width: 54px; height: 54px; font-size: 24px; border-radius: 16px; }
  .win-card { width: min(88vw, 760px); }
}

/* 窄屏微调 */
@media (max-width: 380px) {
  .scene-pet { width: clamp(150px, 30vw, 260px); }
  .action-dock { gap: 10px; padding: 7px 12px; }
  .dock-btn { width: 48px; height: 48px; }
}

/* 横屏低高度时场景仍完整 */
@media (max-height: 500px) {
  .scene-pet { bottom: 4%; width: clamp(120px, 18vw, 240px); }
}
