:root {
  --bg: #fbf6ef;
  --card: #fffdf9;
  --ink: #3d3530;
  --muted: #8a7f76;
  --line: #eee4d8;
  --accent: #e9a27c;
  --accent-ink: #ffffff;
  --soft: #f6ebe0;
  --hunger: #f0b37e;
  --mood: #ef9fb0;
  --energy: #9cc7a4;
  --clean: #8fbbe0;
  --stage-top: #fdf1e4;
  --stage-bottom: #f3e3d1;
  --error: #c4513f;
  --shadow: 0 2px 12px rgba(120, 90, 60, .08);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #23201d; --card: #2d2925; --ink: #f1e9e0; --muted: #a99d91; --line: #3c3631;
    --soft: #38322c; --stage-top: #3a332d; --stage-bottom: #2f2a25; --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #23201d; --card: #2d2925; --ink: #f1e9e0; --muted: #a99d91; --line: #3c3631;
  --soft: #38322c; --stage-top: #3a332d; --stage-bottom: #2f2a25; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 8px; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); font-size: 13px; }
.error { color: var(--error); font-size: 13px; min-height: 1em; margin: 6px 0 0; }

.app { max-width: 520px; margin: 0 auto; padding: 12px 16px calc(24px + env(safe-area-inset-bottom)); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 14px; margin: 12px 0; box-shadow: var(--shadow); }

.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.title { display: flex; align-items: center; gap: 4px; min-width: 0; }
.title h1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { border: 0; background: transparent; color: var(--muted); font-size: 18px; padding: 6px 8px; cursor: pointer; border-radius: 10px; }
.who { display: flex; background: var(--soft); border-radius: 999px; padding: 3px; }
.who-btn { border: 0; background: transparent; color: var(--muted); padding: 6px 14px; border-radius: 999px; font: inherit; cursor: pointer; }
.who-btn.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); font-weight: 600; }

/* 舞台：固定高度，角色按 manifest 的内容框和锚点定位，切换姿态时不跳位 */
.stage { position: relative; padding: 0; overflow: hidden; background: linear-gradient(var(--stage-top), var(--stage-bottom)); }
.cat-box { position: relative; height: 260px; }
.cat-img { position: absolute; object-fit: contain; user-select: none; transition: opacity .25s ease; }
.cat-img.breathe { animation: breathe 3.6s ease-in-out infinite; transform-origin: 50% 90%; }
@keyframes breathe { 0%, 100% { transform: scaleY(1); } 50% { transform: scaleY(1.015); } }
@media (prefers-reduced-motion: reduce) {
  .cat-img.breathe { animation: none; }
  .cat-img, .bubble { transition: none; }
}
.cat-missing { position: absolute; inset: 40px 24px; display: grid; place-items: center; text-align: center; border: 2px dashed var(--line); border-radius: 16px; color: var(--muted); font-size: 13px; }
.behavior { text-align: center; margin: 0; padding: 0 16px 6px; font-weight: 600; }
.pose-note { text-align: center; margin: 0; padding: 0 16px 12px; font-size: 12px; color: var(--muted); }
.badge { position: absolute; top: 10px; left: 10px; z-index: 2; background: rgba(60, 60, 90, .75); color: #fff; font-size: 12px; padding: 4px 10px; border-radius: 999px; }
.bubble {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 3;
  width: calc(100% - 32px); max-width: 420px; background: var(--card); color: var(--ink);
  border: 1px solid var(--line); border-radius: 16px; padding: 10px 14px; font-size: 14px; box-shadow: var(--shadow);
}
.bubble.bad { border-color: var(--error); }

.stat { display: grid; grid-template-columns: 40px 1fr 42px; align-items: center; gap: 10px; margin: 6px 0; font-size: 14px; }
.stat b { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.bar { height: 10px; border-radius: 999px; background: var(--soft); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; border-radius: inherit; transition: width .4s ease; }
#bar-hunger { background: var(--hunger); } #bar-mood { background: var(--mood); }
#bar-energy { background: var(--energy); } #bar-clean { background: var(--clean); }
.bonds { display: flex; gap: 8px; margin-top: 10px; }
.bond { flex: 1; background: var(--soft); border-radius: 12px; padding: 8px 10px; font-size: 13px; }
.bond b { font-size: 16px; margin-left: 4px; }
.detail { margin-top: 8px; font-size: 14px; }
.detail summary { color: var(--muted); cursor: pointer; }
.detail p { margin: 6px 0; }

.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.tab { border: 1px solid var(--line); background: var(--soft); color: var(--ink); border-radius: 12px; padding: 10px 0; font: inherit; cursor: pointer; }
.tab.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.options { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; min-height: 44px; }
.btn { border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 999px; padding: 10px 16px; font: inherit; cursor: pointer; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn:disabled { opacity: .5; cursor: default; }

.event { border-top: 1px dashed var(--line); padding-top: 10px; margin-top: 10px; }
.event:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
.event p { margin: 0 0 8px; }
.event .row { display: flex; flex-wrap: wrap; gap: 8px; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.list li:last-child { border-bottom: 0; }
.list .t { font-weight: 600; }
.list .empty { color: var(--muted); }

.foot { display: flex; justify-content: space-between; align-items: center; padding: 6px 2px; }
.link { border: 0; background: transparent; color: var(--muted); text-decoration: underline; font: inherit; font-size: 13px; cursor: pointer; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; text-align: center; }
.login-card input, #rename-input { width: 100%; font: inherit; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); margin: 10px 0; }
.login-card .btn { width: 100%; }

dialog { border: 1px solid var(--line); border-radius: 18px; background: var(--card); color: var(--ink); width: min(360px, calc(100% - 32px)); padding: 16px; }
dialog::backdrop { background: rgba(0, 0, 0, .3); }
dialog .row { display: flex; justify-content: flex-end; gap: 8px; }
