/* AI 宠物 · 样式。移动优先，深色友好。 */

:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #1c1e26;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #f59e0b;
  --primary-dark: #d97706;
  --danger: #dc2626;
  --ok: #16a34a;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161c;
    --card: #1d2029;
    --text: #e6e8ef;
    --muted: #9aa1b1;
    --line: #2c3140;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 14px 40px;
}

.hidden { display: none !important; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
}

.card.center { text-align: center; padding: 40px 20px; }
.card.warn { border-color: #fca5a5; background: #fef2f2; }
@media (prefers-color-scheme: dark) {
  .card.warn { background: #3b1d1d; border-color: #7f1d1d; }
}

h1 { font-size: 20px; margin: 0 0 6px; }
h2 { font-size: 16px; margin: 0 0 10px; }

.muted { color: var(--muted); font-size: 13px; margin: 4px 0; }
.hint { color: var(--muted); font-size: 12px; margin: 8px 0 0; line-height: 1.5; }
.error { color: var(--danger); font-size: 13px; margin: 8px 0 0; min-height: 0; }

.emoji-xl { font-size: 56px; line-height: 1; }

/* 顶部 */
.pet-head { display: flex; align-items: center; gap: 14px; }
.pet-info { flex: 1; min-width: 0; }
.pet-info h1 { margin: 0; font-size: 20px; }
.form-line { margin: 2px 0 0; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.form-name { font-size: 13px; font-weight: 600; color: var(--primary); }
.lv-chip {
  font-size: 11px;
  font-weight: 700;
  padding: 1px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  color: var(--primary);
  white-space: nowrap;
}
.lv-max { opacity: 0.55; font-weight: 500; }

/* 宠物 SVG 主视觉 */
.pet-stage { position: relative; flex-shrink: 0; }
.pet-svg-wrap { width: 96px; height: 100px; display: grid; place-items: center; }
.pet-svg { width: 100%; height: 100%; overflow: visible; }
.stage-tag {
  position: absolute;
  left: 50%;
  bottom: -4px;
  transform: translateX(-50%);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--line);
  color: var(--muted);
  white-space: nowrap;
}
.stage-tag[data-stage="1"] { background: color-mix(in srgb, #10b981 18%, transparent); color: #0f766e; }
.stage-tag[data-stage="2"] { background: color-mix(in srgb, #3b82f6 18%, transparent); color: #1d4ed8; }
.stage-tag[data-stage="3"] { background: color-mix(in srgb, #a855f7 20%, transparent); color: #7e22ce; }
.stage-tag[data-stage="4"] { background: color-mix(in srgb, #f59e0b 24%, transparent); color: #b45309; }

/* 进化图鉴 */
.evo-head { display: flex; align-items: baseline; justify-content: space-between; }
.evo-head h2 { margin: 0; }
.evo-track {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(66px, 1fr));
  gap: 8px;
  margin-top: 12px;
}
.evo-item {
  text-align: center;
  padding: 6px 2px;
  border-radius: 10px;
  border: 1px solid transparent;
  opacity: 0.34;
  filter: grayscale(1);
  transition: opacity 0.2s ease, filter 0.2s ease, border-color 0.2s ease;
}
.evo-item.done { opacity: 1; filter: none; }
.evo-item.cur {
  border-color: color-mix(in srgb, var(--primary) 45%, transparent);
  background: color-mix(in srgb, var(--primary) 7%, transparent);
}
.evo-thumb { width: 46px; height: 46px; margin: 0 auto; }
.evo-thumb .pet-svg { width: 100%; height: 100%; }
.evo-lv { font-size: 10px; font-weight: 700; color: var(--muted); margin-top: 2px; }
.evo-form { font-size: 10px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.balance-badge {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: #4a2c00;
  font-weight: 700;
  font-size: 14px;
  padding: 6px 12px;
  border-radius: 999px;
  white-space: nowrap;
}

/* 进度条 */
.hunger-block, .exp-block { margin-top: 16px; }
.hunger-label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.bar {
  height: 10px;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, #34d399, #10b981);
  transition: width 0.35s ease, background 0.35s ease;
}
.bar-fill.low { background: linear-gradient(90deg, #fbbf24, #f59e0b); }
.bar-fill.critical { background: linear-gradient(90deg, #f87171, #dc2626); }
.bar-fill.exp { background: linear-gradient(90deg, #60a5fa, #3b82f6); }

/* 表单 */
.field { display: block; margin: 14px 0; }
.field > span { display: block; font-size: 13px; margin-bottom: 6px; font-weight: 500; }
.field em { font-style: normal; }

input[type="text"], textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}
input[type="text"]:focus, textarea:focus { border-color: var(--primary); }
textarea { resize: vertical; line-height: 1.55; }

/* 按钮 */
.btn {
  display: inline-block;
  padding: 9px 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  transition: transform 0.1s, background 0.15s, opacity 0.15s;
}
.btn:hover { background: var(--bg); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #3b2400;
  font-weight: 600;
}
.btn.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn.danger { color: var(--danger); border-color: #fca5a5; }

.row-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.row-btns .btn { flex: 1; min-width: 90px; }

/* 性格模板 */
.tpl-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 8px;
}
.tpl {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--bg);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s, background 0.15s;
}
.tpl:hover { border-color: var(--primary); }
.tpl:active { transform: scale(0.98); }
.tpl.active {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 10%, transparent);
}
.tpl-emoji { font-size: 20px; line-height: 1.2; }
.tpl-name { font-size: 13px; font-weight: 600; }
.tpl-desc { font-size: 11px; color: var(--muted); line-height: 1.35; }

/* 食物 */
.foods { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.food {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  text-align: center;
  background: var(--bg);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}
.food:hover { border-color: var(--primary); }
.food:active { transform: scale(0.97); }
.food.disabled { opacity: 0.45; cursor: not-allowed; }
.food .emoji { font-size: 30px; display: block; }
.food .name { font-size: 13px; margin-top: 4px; font-weight: 500; }
.food .cost { font-size: 12px; color: var(--muted); }

/* 打卡 */
.checkin-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

/* 流水 */
.ledger-box { margin-top: 14px; }
.ledger-box summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
  padding: 6px 0;
  user-select: none;
}
.ledger { list-style: none; margin: 8px 0 0; padding: 0; }
.ledger li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px dashed var(--line);
  font-size: 13px;
}
.ledger li:last-child { border-bottom: none; }
.ledger .amt.plus { color: var(--ok); font-weight: 600; }
.ledger .amt.minus { color: var(--danger); font-weight: 600; }
.ledger .when { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* 提示条 */
.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%);
  background: rgba(28, 30, 38, 0.94);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 99;
  max-width: 88vw;
  text-align: center;
  animation: toast-in 0.2s ease;
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.foot { text-align: center; color: var(--muted); font-size: 12px; margin-top: 20px; }

/* 排行榜 */
.rank-list { list-style: none; margin: 0; padding: 0; }
.rank-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.rank-item:last-child { border-bottom: none; }
.rank-no {
  width: 30px;
  text-align: center;
  font-weight: 700;
  color: var(--muted);
  flex-shrink: 0;
}
.rank-no.top1 { color: #f59e0b; font-size: 18px; }
.rank-no.top2 { color: #9ca3af; font-size: 17px; }
.rank-no.top3 { color: #b45309; font-size: 16px; }
.rank-main { flex: 1; min-width: 0; }
.rank-name { font-weight: 600; font-size: 14px; }
.rank-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.rank-meta { text-align: right; font-size: 12px; color: var(--muted); flex-shrink: 0; }
.rank-meta strong { display: block; font-size: 15px; color: var(--text); }
