/* 拾宠 · 像素游戏风样式 */
:root {
  --ink: #3d3a50;
  --bg: #f7f2e8;
  --panel: #ffffff;
  --primary: #79ad6b;
  --primary-dark: #55824a;
  --danger: #e06a5a;
  --gold: #f0b24a;
  --line: #e5ddcd;
  --muted: #9a937f;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  line-height: 1.5;
}

#app { max-width: 760px; margin: 0 auto; padding: 16px 16px 90px; }

/* —— 顶栏 —— */
header { display: flex; justify-content: space-between; align-items: center; padding: 6px 4px 16px; }
.logo { font-size: 26px; font-weight: 800; letter-spacing: 2px; }
.logo small { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: 1px; margin-left: 6px; }
.chance-chip {
  background: var(--panel); border: 2px solid var(--ink); border-radius: 999px;
  padding: 6px 14px; font-weight: 700; font-size: 14px;
  box-shadow: 2px 2px 0 rgba(61, 58, 80, .18);
}
.chance-chip b { color: var(--primary-dark); font-size: 18px; margin-left: 4px; }

.header-right { display: flex; gap: 10px; align-items: center; }
#help-btn {
  width: 34px; height: 34px; border-radius: 50%; cursor: pointer;
  border: 2px solid var(--ink); background: var(--panel); color: var(--ink);
  font-size: 16px; font-weight: 800;
  box-shadow: 2px 2px 0 rgba(61, 58, 80, .18);
}
#help-btn:hover { background: #fff3d6; }

/* —— 使用引导 —— */
.onboard-mask { z-index: 70; }
.modal.onboard { max-width: 380px; padding-top: 26px; }
.onboard-pet {
  width: 104px; margin: 0 auto 6px; text-align: center;
}
.onboard-pet .pet-sprite { margin: 0 auto; }
.onboard-pet-name { font-size: 11px; color: var(--muted); margin-top: 2px; }
.onboard-step { font-size: 11px; color: var(--muted); letter-spacing: 1px; }
.onboard-text { font-size: 13.5px; line-height: 1.8; margin: 10px 2px 14px; text-align: left; }
.onboard-dots { display: flex; gap: 6px; justify-content: center; margin-bottom: 16px; }
.onboard-dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.onboard-dots i.on { background: var(--primary); }

/* —— 页签 —— */
#tabs { display: flex; gap: 8px; margin-bottom: 16px; }
#tabs button {
  flex: 1; padding: 10px; font-size: 15px; font-weight: 700;
  background: var(--panel); color: var(--ink);
  border: 2px solid var(--ink); border-radius: 12px; cursor: pointer;
  opacity: .55; box-shadow: 2px 2px 0 rgba(61, 58, 80, .15);
  transition: opacity .15s, transform .15s;
}
#tabs button:hover { opacity: .8; }
#tabs button.active { opacity: 1; background: var(--primary); color: #fff; }

.view { display: none; }
.view.active { display: block; }

.stats-line { font-size: 12px; color: var(--muted); margin: 0 2px 10px; }

.hint { font-size: 12px; color: var(--muted); margin: 8px 2px; }

.section-title { font-size: 14px; font-weight: 800; margin: 18px 2px 10px; }
.section-title small { font-weight: 500; color: var(--muted); margin-left: 6px; }

/* 任务列表的可折叠分组标题 */
.group-head {
  display: flex; align-items: baseline; gap: 6px;
  font-size: 14px; font-weight: 800; margin: 18px 2px 10px;
  cursor: pointer; user-select: none;
}
.group-head:hover { color: var(--primary-dark); }
.group-head small { font-weight: 500; color: var(--muted); }
.group-arrow { display: inline-block; width: 14px; color: var(--muted); font-weight: 400; }

.empty {
  text-align: center; color: var(--muted); font-size: 14px;
  padding: 34px 12px;
}

/* —— 任务表单 —— */
.todo-form {
  background: var(--panel); border: 2px solid var(--ink); border-radius: 14px;
  padding: 14px; box-shadow: 3px 3px 0 rgba(61, 58, 80, .15);
}
.todo-form input[type="text"], .todo-form input:not([type]),
.todo-form input[type="date"], .todo-form input[type="time"] {
  width: 100%; padding: 10px 12px; font-size: 15px;
  border: 2px solid var(--line); border-radius: 10px; outline: none;
  background: #fdfbf6; color: var(--ink);
}
/* 日期快捷按钮（替代原生 date 弹层，见设计文档 §7）与时刻下拉 */
.date-quick { display: flex; gap: 5px; flex-wrap: wrap; width: 100%; }
.date-quick button {
  padding: 9px 12px; font-size: 14px; cursor: pointer;
  background: #fdfbf6; border: 2px solid var(--line); border-radius: 10px; color: var(--ink);
}
.date-quick button.on { border-color: var(--primary); background: #eef6e9; color: var(--primary-dark); font-weight: 700; }
#time-hour { flex: 0 0 108px; }
#time-minute { flex: 0 0 108px; }
#time-minute:disabled { opacity: .45; }
.inline-hint { font-size: 11px; color: var(--muted); align-self: center; flex: none; }

#repeat-row select { flex: 0 0 auto; min-width: 108px; }
.weekday-picker { display: flex; gap: 4px; flex-wrap: wrap; }
.weekday-picker[hidden] { display: none; }
.weekday-picker button {
  padding: 8px 11px; font-size: 13px; cursor: pointer;
  background: #fdfbf6; border: 2px solid var(--line); border-radius: 10px; color: var(--ink);
}
.weekday-picker button.on { border-color: var(--primary); background: #eef6e9; color: var(--primary-dark); font-weight: 700; }

.repeat-chip {
  display: inline-block; margin-left: 6px; padding: 0 8px; cursor: pointer;
  background: #fff3d6; border-radius: 999px; color: #a8742a; font-size: 11px;
}
.repeat-chip.danger { color: #fff; background: var(--danger); }
.todo-form input:focus { border-color: var(--primary); }
.form-row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.form-row select {
  flex: 1; min-width: 150px; padding: 9px 10px; font-size: 14px;
  border: 2px solid var(--line); border-radius: 10px; background: #fdfbf6; color: var(--ink);
  outline: none;
}
.diff { display: flex; gap: 4px; }
.diff button {
  padding: 8px 12px; font-size: 14px; background: #fdfbf6;
  border: 2px solid var(--line); border-radius: 10px; cursor: pointer; color: var(--gold);
}
.diff button.on { border-color: var(--gold); background: #fff7e6; }

button.primary {
  padding: 9px 18px; font-size: 14px; font-weight: 700; cursor: pointer;
  background: var(--primary); color: #fff;
  border: 2px solid var(--ink); border-radius: 10px;
  box-shadow: 2px 2px 0 rgba(61, 58, 80, .25);
}
button.primary:hover { background: var(--primary-dark); }
button.primary:disabled { background: #c9c4b4; cursor: not-allowed; box-shadow: none; }

button.mini {
  padding: 6px 12px; font-size: 12px; cursor: pointer;
  background: var(--panel); color: var(--muted);
  border: 2px solid var(--line); border-radius: 8px;
}
button.mini:hover { color: var(--ink); border-color: var(--ink); }
button.mini.danger { color: #fff; background: var(--danger); border-color: var(--ink); }

/* —— 任务列表 —— */
.todo-list { margin-top: 14px; }
.todo-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel); border: 2px solid var(--ink); border-radius: 12px;
  padding: 10px 12px; margin-bottom: 8px;
  box-shadow: 2px 2px 0 rgba(61, 58, 80, .12);
}
.todo-row .check {
  width: 26px; height: 26px; flex: none; cursor: pointer;
  border: 2px solid var(--ink); border-radius: 8px; background: #fdfbf6;
}
.todo-row .check:hover { background: #e8f3e3; }
.todo-row .done-check { cursor: default; background: var(--primary); color: #fff; text-align: center; line-height: 22px; font-size: 14px; }
.todo-main { flex: 1; min-width: 0; }
.todo-title { font-size: 15px; font-weight: 600; word-break: break-all; }
.todo-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.pet-chip {
  display: inline-block; margin-left: 6px; padding: 0 8px;
  background: #eef6e9; border-radius: 999px; color: var(--primary-dark); font-size: 11px;
}
.todo-row.done { opacity: .62; }
.todo-row.done .todo-title { text-decoration: line-through; }

/* 完成时"记一笔"的备注 */
#note-input {
  width: 100%; min-height: 84px; resize: vertical;
  padding: 10px 12px; font-size: 14px; font-family: inherit;
  border: 2px solid var(--line); border-radius: 10px; outline: none;
  background: #fdfbf6; color: var(--ink); margin: 10px 0 14px;
}
#note-input:focus { border-color: var(--primary); }
.todo-note {
  font-size: 12px; line-height: 1.7; color: var(--ink);
  background: #fdf8ee; border-left: 3px solid var(--gold);
  padding: 4px 9px; margin-top: 6px; border-radius: 0 8px 8px 0;
  word-break: break-all;
}

/* —— 刷新地 —— */
.ground-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.ground-tab {
  padding: 7px 13px; font-size: 13px; font-weight: 700; cursor: pointer;
  background: var(--panel); border: 2px solid var(--line); border-radius: 999px; color: var(--muted);
}
.ground-tab i { font-style: normal; color: var(--primary-dark); margin-left: 3px; }
.ground-tab.on { border-color: var(--ink); color: var(--ink); background: #fff; }

.scene {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; justify-content: flex-start;
  min-height: 200px; padding: 18px;
  border: 2px dashed var(--line); border-radius: 16px;
}
.wild-pet {
  width: 108px; padding: 12px 6px 10px; text-align: center; cursor: pointer;
  background: rgba(255, 255, 255, .85); border: 2px solid var(--ink); border-radius: 12px;
  box-shadow: 2px 2px 0 rgba(61, 58, 80, .15);
  transition: transform .12s;
}
.wild-pet:hover { transform: translateY(-3px); }
.wild-name { font-size: 13px; font-weight: 700; margin-top: 6px; }
.wild-pers { font-size: 11px; color: var(--muted); margin-top: 2px; }

.pet-sprite { image-rendering: pixelated; display: block; margin: 0 auto; }
.pet-sprite.silhouette { opacity: .5; }

/* —— 性格动画 —— */
@keyframes sway { 0%, 100% { transform: rotate(-2.5deg); } 50% { transform: rotate(2.5deg); } }
@keyframes squish { 0%, 86%, 100% { transform: scale(1, 1); } 91% { transform: scale(1.08, .88); } }
@keyframes hop { 0%, 55%, 100% { transform: translateY(0); } 65% { transform: translateY(-7px); } 75% { transform: translateY(0); } 82% { transform: translateY(-4px); } 88% { transform: translateY(0); } }
.anim-sway   { animation: sway 2.6s ease-in-out infinite; transform-origin: 50% 100%; }
.anim-squish { animation: squish 3.4s ease-in-out infinite; transform-origin: 50% 100%; }
.anim-hop    { animation: hop 2.2s ease-in-out infinite; transform-origin: 50% 100%; }
.anim-still  { animation: none; }

/* —— 弹窗 —— */
.modal-mask {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(61, 58, 80, .4);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  position: relative; width: 100%; max-width: 340px;
  background: var(--panel); border: 2px solid var(--ink); border-radius: 16px;
  padding: 22px 20px; text-align: center;
  box-shadow: 4px 4px 0 rgba(61, 58, 80, .3);
}
.modal-close {
  position: absolute; top: 8px; right: 12px; cursor: pointer;
  font-size: 20px; color: var(--muted); line-height: 1;
}
.modal-close:hover { color: var(--ink); }
.modal h3 { font-size: 18px; margin: 8px 0 4px; }
.rar { font-size: 11px; color: var(--gold); letter-spacing: 1px; vertical-align: 2px; }
.pers-line { font-size: 13px; margin: 4px 0; }
.src { font-size: 12px; color: var(--muted); margin: 4px 0; }
.cost { font-size: 13px; margin: 10px 0 14px; }
.cost b { color: var(--primary-dark); }
.modal-btns { display: flex; gap: 8px; justify-content: center; }

/* —— 图鉴 —— */
.dex-progress {
  background: var(--panel); border: 2px solid var(--ink); border-radius: 12px;
  padding: 12px 16px; font-size: 15px; font-weight: 700;
  box-shadow: 2px 2px 0 rgba(61, 58, 80, .15);
}
.dex-progress b { color: var(--primary-dark); }
.dex-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.dex-entry {
  background: var(--panel); border: 2px solid var(--ink); border-radius: 12px;
  padding: 12px 10px; text-align: center;
  box-shadow: 2px 2px 0 rgba(61, 58, 80, .12);
}
.dex-entry.locked { border-style: dashed; border-color: var(--line); box-shadow: none; }
.dex-entry.locked .pet-sprite { filter: grayscale(1) brightness(.55); }
.dex-name { font-size: 14px; font-weight: 700; margin-top: 6px; }
.dex-desc { font-size: 11px; color: var(--muted); margin-top: 3px; min-height: 30px; }
.dex-date { font-size: 10px; color: var(--gold); margin-top: 4px; }

/* —— 送达小剧场（§5.8）：信使叼信横穿，中点放信，跑出画面 —— */
.delivery-stage {
  position: fixed; left: 0; right: 0; bottom: 84px; height: 110px; z-index: 55;
  pointer-events: none;
}
.delivery-runner {
  position: absolute; bottom: 0; left: -90px;
  display: flex; flex-direction: column; align-items: center;
  animation: deliveryRun 3s cubic-bezier(.45, .05, .55, .95) forwards;
}
@keyframes deliveryRun {
  0%   { left: -90px; }
  42%  { left: 46%; }
  58%  { left: 46%; }
  100% { left: 108%; }
}
.delivery-runner .pet-sprite {
  animation: deliveryBounce .32s ease-in-out infinite alternate;
}
@keyframes deliveryBounce { from { transform: translateY(0); } to { transform: translateY(-6px); } }
.delivery-letter {
  position: absolute; top: -14px; right: -13px; font-size: 15px;
  animation: letterJourney 3s forwards;
}
@keyframes letterJourney {
  0%, 40%  { opacity: 1; transform: translateY(0) rotate(-8deg); }
  48%      { opacity: 1; transform: translateY(26px) rotate(6deg); }
  58%,100% { opacity: 0; transform: translateY(30px); }
}
.delivery-drop {
  position: absolute; bottom: 8px; left: 46%; font-size: 18px; opacity: 0;
  transform: translateX(-50%);
  animation: dropSparkle 3s forwards;
}
@keyframes dropSparkle {
  0%, 44% { opacity: 0; transform: translateX(-50%) scale(.5); }
  52%     { opacity: 1; transform: translateX(-50%) scale(1.25); }
  70%,100%{ opacity: 0; transform: translateX(-50%) scale(1); }
}
.delivery-caption {
  position: absolute; left: 0; right: 0; bottom: -28px;
  text-align: center; font-size: 12.5px; color: var(--ink);
}
.delivery-caption, .delivery-drop { text-shadow: 0 1px 0 rgba(255,255,255,.8); }

/* —— 刷新地：新到宠物的小降落（§5.8 落点呼应）—— */
.arrive-wrap { display: inline-block; }
.just-arrived { animation: dropIn .9s cubic-bezier(.3, 1.4, .6, 1); }
@keyframes dropIn {
  0%   { transform: translateY(-42px) scale(.7); opacity: 0; }
  60%  { transform: translateY(0) scale(1.06); opacity: 1; }
  80%  { transform: translateY(-6px) scale(1); }
  100% { transform: translateY(0) scale(1); }
}

/* —— 收服仪式感（方案 B）—— */
.catch-stage {
  position: fixed; inset: 0; z-index: 65;
  background: rgba(61, 58, 80, .45);
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.catch-halo {
  position: absolute; width: 250px; height: 250px; border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 215, 110, .6) 0%, rgba(255, 215, 110, 0) 65%);
  animation: haloIn 2s ease-in forwards;
}
@keyframes haloIn {
  0%   { transform: scale(2.2); opacity: 0; }
  25%  { transform: scale(1); opacity: 1; }
  55%  { transform: scale(.72); opacity: 1; }
  80%, 100% { transform: scale(.08); opacity: 0; }
}
.catch-pet { position: relative; animation: catchPet 2s ease-in forwards; }
@keyframes catchPet {
  0%, 20%  { transform: scale(1) rotate(0); opacity: 1; }
  30%, 45% { transform: scale(1.08) rotate(-4deg); }
  55%      { transform: scale(1.05) rotate(4deg); }
  70%      { transform: scale(1) rotate(0); }
  85%, 100%{ transform: scale(.04) rotate(360deg); opacity: 0; }
}
.catch-sparkle { position: absolute; font-size: 28px; opacity: 0; animation: catchSparkle 2.1s forwards; }
@keyframes catchSparkle {
  0%, 78% { opacity: 0; transform: scale(.4); }
  88%     { opacity: 1; transform: scale(1.3); }
  100%    { opacity: 0; transform: scale(1); }
}

/* —— 设置页（方案 A）—— */
.modal.settings { text-align: left; }
.set-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 11px 0; border-bottom: 1px dashed var(--line); font-size: 14px;
}
.set-sec { font-size: 12px; font-weight: 800; color: var(--muted); margin: 16px 0 8px; }
.set-sec small { font-weight: 500; }
.set-sec.danger { color: var(--danger); }

/* —— 任务页：月历（v0.11）—— */
.calendar-card {
  background: var(--panel); border: 2px solid var(--ink); border-radius: 14px;
  padding: 12px; box-shadow: 3px 3px 0 rgba(61, 58, 80, .15); margin-bottom: 16px;
}
.cal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.cal-title { font-weight: 800; font-size: 16px; flex: 1; text-align: center; }
.cal-nav {
  width: 34px; height: 34px; border: 2px solid var(--line); background: #fdfbf6;
  border-radius: 9px; font-size: 20px; line-height: 1; cursor: pointer; color: var(--ink);
}
.cal-nav:hover { border-color: var(--ink); }
.cal-today-btn {
  font-size: 12px; padding: 7px 11px; border: 2px solid var(--line);
  background: #fdfbf6; border-radius: 999px; cursor: pointer; color: var(--ink);
}
.cal-today-btn:hover { border-color: var(--ink); }
.cal-week { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal-cell {
  position: relative; min-height: 42px;
  border: 2px solid transparent; border-radius: 9px;
  background: none; font-size: 14px; color: var(--ink); cursor: pointer;
}
.cal-cell.blank { pointer-events: none; }
.cal-cell:hover { background: #f3efe3; }
.cal-cell.today { border-color: var(--gold); }
.cal-cell.selected { background: var(--primary); color: #fff; font-weight: 700; }
.cal-dot {
  position: absolute; bottom: 5px; left: 50%; transform: translateX(-50%);
  width: 5px; height: 5px; border-radius: 50%; background: var(--primary-dark);
}
.cal-cell.selected .cal-dot { background: #fff; }

/* —— 悬浮写任务按钮 —— */
.fab {
  position: fixed; right: 20px; bottom: 26px; z-index: 40;
  width: 58px; height: 58px; border-radius: 50%;
  background: var(--primary); color: #fff;
  font-size: 30px; line-height: 1; font-weight: 300;
  border: 2px solid var(--ink);
  box-shadow: 3px 3px 0 rgba(61, 58, 80, .25);
  cursor: pointer;
}
.fab:hover { background: var(--primary-dark); }

/* —— 写任务弹窗 —— */
.modal.task-modal { max-height: 82vh; max-height: 82dvh; overflow-y: auto; text-align: left; }
.modal.task-modal h3 { text-align: center; }
#tk-title {
  width: 100%; padding: 10px 12px; font-size: 16px;
  border: 2px solid var(--line); border-radius: 10px; outline: none;
  background: #fdfbf6; color: var(--ink); margin: 10px 0 4px;
}
#tk-title:focus { border-color: var(--primary); }
.tk-row { display: flex; gap: 8px; align-items: center; margin: 10px 0; flex-wrap: wrap; }
.tk-row[hidden] { display: none; }
.tk-label { width: 34px; flex: none; font-size: 13px; color: var(--muted); }
.tk-row select { flex: 1; min-width: 90px; padding: 9px 10px; font-size: 15px; border: 2px solid var(--line); border-radius: 10px; background: #fdfbf6; color: var(--ink); outline: none; }
#tk-hour, #tk-minute { flex: 0 0 96px; }
#tk-minute:disabled { opacity: .45; }
.tk-chip.on { background: #eef6e9; border-color: var(--primary); color: var(--primary-dark); }
.task-modal .weekday-picker { flex: 1; }
.task-modal .diff { flex: 1; }

/* —— toast —— */
#toast-root {
  position: fixed; bottom: 26px; left: 0; right: 0; z-index: 60;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--ink); color: #fff; font-size: 13px;
  padding: 9px 18px; border-radius: 999px;
  opacity: 0; transform: translateY(8px);
  transition: opacity .25s, transform .25s;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* —— 手机适配（方案 A）—— */
@media (max-width: 520px) {
  #app { padding: 10px 12px 70px; }
  header { padding: 4px 2px 12px; }
  .logo { font-size: 20px; letter-spacing: 1px; }
  .logo small { display: none; }
  #help-btn, #settings-btn { width: 32px; height: 32px; font-size: 15px; }
  .chance-chip { padding: 5px 11px; font-size: 13px; }
  .chance-chip b { font-size: 16px; }
  #tabs { gap: 6px; }
  #tabs button { padding: 10px 4px; font-size: 14px; }
  .todo-form { padding: 12px; }
  /* 16px 起防 iOS Safari 聚焦自动放大 */
  .todo-form input:not([type]), .todo-form input[type="text"],
  #note-input, .todo-form select { font-size: 16px; }
  .date-quick button { font-size: 14px; padding: 10px 11px; }
  .todo-row { padding: 10px 11px; }
  .todo-row .check { width: 34px; height: 34px; }
  .todo-row .done-check { line-height: 30px; }
  button.primary, button.mini { padding-top: 10px; padding-bottom: 10px; }
  button.mini { padding: 9px 13px; }
  .scene { min-height: 150px; padding: 12px; gap: 9px; }
  .wild-pet { width: 88px; padding: 10px 4px 8px; }
  .delivery-stage { bottom: 70px; height: 96px; }
  .delivery-caption { font-size: 11px; }
  .modal { padding: 18px 14px; }
  .modal-btns { flex-wrap: wrap; }
  .dex-grid { grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); }
  .cal-cell { min-height: 38px; font-size: 13px; }
  .fab { right: 14px; bottom: 20px; width: 54px; height: 54px; }
  .modal.task-modal { max-height: 78vh; }
  #toast-root { bottom: 18px; }
  .toast { max-width: 88vw; }
}
