/* ===== 全局重置与基础样式 ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-bg: #fef6e4;
  --color-card: #ffffff;
  --color-primary: #f582ae;
  --color-primary-hover: #e0609a;
  --color-secondary: #8bd3dd;
  --color-accent: #ffc857;
  --color-text: #3d3d3d;
  --color-text-light: #7a7a7a;
  --color-border: #e8dfd5;
  --color-shadow: rgba(0, 0, 0, 0.08);

  /* 属性条颜色 */
  --bar-hunger-low: #66bb6a;
  --bar-hunger-high: #ef5350;
  --bar-mood-good: #ffc107;
  --bar-mood-bad: #9e9e9e;
  --bar-energy-good: #42a5f5;
  --bar-energy-bad: #ef5350;
  --bar-cleanliness-good: #26c6da;
  --bar-cleanliness-bad: #8d6e63;
  --bar-health-good: #66bb6a;
  --bar-health-bad: #ef5350;

  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.3s ease;
}

html {
  font-size: 16px;
}

body {
  font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 16px;
}

/* ===== 游戏容器 ===== */
.game-container {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-bottom: 24px;
}

/* ===== 顶部信息栏 ===== */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--color-card);
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: 0 2px 8px var(--color-shadow);
  flex-wrap: wrap;
  gap: 8px;
}

.money-display {
  font-size: 1.1rem;
  font-weight: 600;
  color: #d4a017;
  display: flex;
  align-items: center;
  gap: 4px;
}

.money-icon {
  font-size: 1.3rem;
}

.weather-display {
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 6px;
}

#weather-icon {
  font-size: 1.4rem;
}

.save-load-buttons {
  display: flex;
  gap: 6px;
}

/* ===== 宠物显示区域 ===== */
.pet-area {
  background: var(--color-card);
  border-radius: var(--radius);
  padding: 24px 16px;
  text-align: center;
  box-shadow: 0 2px 8px var(--color-shadow);
  position: relative;
}

.pet-name-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 8px;
}

.pet-name {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--color-text);
  cursor: default;
}

.pet-level-badge {
  background: var(--color-accent);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 20px;
  white-space: nowrap;
}

.pet-expression {
  font-size: 90px;
  line-height: 1.2;
  margin: 12px 0;
  transition: all var(--transition);
  animation: idle-bounce 2s ease-in-out infinite;
  user-select: none;
}

@keyframes idle-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.pet-age {
  font-size: 0.9rem;
  color: var(--color-text-light);
}

/* ===== 属性面板 ===== */
.attributes-panel {
  background: var(--color-card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 2px 8px var(--color-shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.attr-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.attr-label {
  font-size: 0.85rem;
  font-weight: 600;
  width: 72px;
  flex-shrink: 0;
  white-space: nowrap;
}

.progress-bar-container {
  flex: 1;
  height: 14px;
  background: #eee;
  border-radius: 7px;
  overflow: hidden;
  position: relative;
}

.progress-bar {
  height: 100%;
  border-radius: 7px;
  transition: width 0.4s ease, background-color 0.4s ease;
  min-width: 0;
}

.attr-value {
  font-size: 0.85rem;
  font-weight: 600;
  width: 32px;
  text-align: right;
  flex-shrink: 0;
}

/* 饥饿条：值越高越红（越饿越危险） */
.bar-hunger {
  background: linear-gradient(90deg, var(--bar-hunger-low), var(--bar-hunger-high));
}

/* 心情条：值越高越好 */
.bar-mood {
  background: linear-gradient(90deg, var(--bar-mood-bad), var(--bar-mood-good));
}

/* 精力条 */
.bar-energy {
  background: linear-gradient(90deg, var(--bar-energy-bad), var(--bar-energy-good));
}

/* 清洁条 */
.bar-cleanliness {
  background: linear-gradient(90deg, var(--bar-cleanliness-bad), var(--bar-cleanliness-good));
}

/* 健康条 */
.bar-health {
  background: linear-gradient(90deg, var(--bar-health-bad), var(--bar-health-good));
}

/* ===== 按钮通用样式 ===== */
.btn {
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  outline: none;
  user-select: none;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 3px 10px var(--color-shadow);
}

.btn:active {
  transform: translateY(0);
}

.btn:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* ===== 操作按钮区 ===== */
.action-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.btn-action {
  background: var(--color-card);
  color: var(--color-text);
  padding: 12px 8px;
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.btn-action:hover {
  border-color: var(--color-primary);
  background: #fff5f9;
}

.btn-adventure {
  grid-column: span 3;
  background: linear-gradient(135deg, #ffecd2, #fcb69f);
  border-color: #fcb69f;
  font-size: 1rem;
  padding: 14px;
}

.btn-adventure:hover {
  background: linear-gradient(135deg, #ffd9b3, #f7a58c);
  border-color: #f7a58c;
}

/* ===== 面板切换按钮 ===== */
.panel-toggles {
  display: flex;
  gap: 10px;
}

.btn-toggle {
  flex: 1;
  background: var(--color-secondary);
  color: #fff;
  padding: 12px;
  font-size: 1rem;
}

.btn-toggle:hover {
  background: #72c5d0;
}

.btn-toggle.active {
  background: #5ab5c1;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15);
}

/* ===== 商店/背包面板 ===== */
.panel {
  background: var(--color-card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 2px 8px var(--color-shadow);
  animation: panel-slide-in 0.25s ease;
}

@keyframes panel-slide-in {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.panel.hidden {
  display: none;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.panel-header h3 {
  font-size: 1.1rem;
  font-weight: 700;
}

.btn-close {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--color-text-light);
  padding: 4px 8px;
  border-radius: 4px;
  transition: all var(--transition);
}

.btn-close:hover {
  background: #f0f0f0;
  color: var(--color-text);
}

.item-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 280px;
  overflow-y: auto;
}

.item-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: #fafafa;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  gap: 8px;
}

.item-info {
  flex: 1;
  min-width: 0;
}

.item-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.item-desc {
  font-size: 0.75rem;
  color: var(--color-text-light);
  margin-top: 2px;
}

.item-price {
  font-size: 0.8rem;
  color: #d4a017;
  font-weight: 600;
  white-space: nowrap;
}

.item-quantity {
  font-size: 0.8rem;
  color: var(--color-text-light);
  font-weight: 600;
  white-space: nowrap;
}

.btn-buy,
.btn-use {
  padding: 6px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-buy {
  background: var(--color-accent);
  color: #fff;
}

.btn-buy:hover {
  background: #e6b34e;
}

.btn-use {
  background: var(--color-primary);
  color: #fff;
}

.btn-use:hover {
  background: var(--color-primary-hover);
}

.empty-hint {
  text-align: center;
  color: var(--color-text-light);
  font-size: 0.9rem;
  padding: 20px 0;
}

/* ===== 音频控制区 ===== */
.audio-controls {
  background: var(--color-card);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: 0 2px 8px var(--color-shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.audio-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.audio-row label {
  font-size: 0.85rem;
  font-weight: 600;
  width: 100px;
  flex-shrink: 0;
}

.volume-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: #e0e0e0;
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}

.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--color-primary);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

.volume-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--color-primary);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

.btn-mute {
  background: #f0f0f0;
  color: var(--color-text);
  padding: 8px 16px;
  align-self: flex-start;
}

.btn-mute:hover {
  background: #e0e0e0;
}

.btn-mute.muted {
  background: var(--color-primary);
  color: #fff;
}

.btn-save,
.btn-load {
  background: #f0f0f0;
  color: var(--color-text);
  padding: 6px 12px;
  font-size: 0.8rem;
}

.btn-save:hover,
.btn-load:hover {
  background: #e0e0e0;
}

/* ===== Toast 通知 ===== */
.toast-container {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  width: 90%;
  max-width: 400px;
}

.toast {
  background: var(--color-card);
  color: var(--color-text);
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  font-size: 0.9rem;
  font-weight: 500;
  animation: toast-in 0.3s ease, toast-out 0.3s ease 2.7s forwards;
  pointer-events: auto;
  text-align: center;
  border-left: 4px solid var(--color-primary);
  width: 100%;
}

.toast.toast-success {
  border-left-color: #66bb6a;
}

.toast.toast-error {
  border-left-color: #ef5350;
}

.toast.toast-info {
  border-left-color: var(--color-secondary);
}

.toast.toast-warning {
  border-left-color: var(--color-accent);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toast-out {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-12px);
  }
}

/* ===== 死亡遮罩层 ===== */
.death-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  animation: fade-in 0.5s ease;
}

.death-overlay.hidden {
  display: none;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.death-content {
  background: var(--color-card);
  border-radius: 20px;
  padding: 40px 32px;
  text-align: center;
  max-width: 360px;
  width: 90%;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  animation: death-pop 0.4s ease 0.2s both;
}

@keyframes death-pop {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.death-emoji {
  font-size: 80px;
  margin-bottom: 16px;
}

.death-content h2 {
  font-size: 1.3rem;
  color: var(--color-text);
  margin-bottom: 8px;
}

.death-message {
  font-size: 0.9rem;
  color: var(--color-text-light);
  margin-bottom: 24px;
}

.btn-restart {
  background: var(--color-primary);
  color: #fff;
  padding: 14px 32px;
  font-size: 1.1rem;
  border-radius: var(--radius);
}

.btn-restart:hover {
  background: var(--color-primary-hover);
}

/* ===== 宠物状态视觉提示 ===== */
.pet-area.sick {
  background: #fff3e0;
  border: 2px solid #ffb74d;
}

.pet-area.sick .pet-expression {
  animation: sick-shake 0.5s ease-in-out infinite;
}

@keyframes sick-shake {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-3deg); }
  75% { transform: rotate(3deg); }
}

/* ===== 进化动画 ===== */
.pet-expression.evolving {
  animation: evolve-glow 1.5s ease-in-out;
}

@keyframes evolve-glow {
  0% { transform: scale(1); filter: brightness(1); }
  30% { transform: scale(1.3); filter: brightness(1.5) hue-rotate(30deg); }
  60% { transform: scale(0.9); filter: brightness(2) hue-rotate(60deg); }
  100% { transform: scale(1); filter: brightness(1); }
}

/* ===== 交互反应动画 ===== */
.pet-expression.reaction-feed {
  animation: reaction-eat 1s ease;
}

@keyframes reaction-eat {
  0%, 100% { transform: scale(1); }
  20% { transform: scale(1.1) rotate(-5deg); }
  40% { transform: scale(0.95) rotate(5deg); }
  60% { transform: scale(1.1) rotate(-3deg); }
  80% { transform: scale(0.98) rotate(2deg); }
}

.pet-expression.reaction-play {
  animation: reaction-play 1s ease;
}

@keyframes reaction-play {
  0%, 100% { transform: translateY(0); }
  25% { transform: translateY(-15px) rotate(10deg); }
  50% { transform: translateY(0) rotate(-10deg); }
  75% { transform: translateY(-10px) rotate(5deg); }
}

.pet-expression.reaction-bath {
  animation: reaction-bath 1s ease;
}

@keyframes reaction-bath {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.15); opacity: 0.8; }
}

.pet-expression.reaction-sleep {
  animation: reaction-sleep 1s ease;
}

@keyframes reaction-sleep {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(0.9); opacity: 0.6; }
}

/* ===== 响应式布局 ===== */

/* 手机竖屏 (< 480px) */
@media (max-width: 479px) {
  body {
    padding: 8px;
  }

  .game-container {
    gap: 12px;
    max-width: 100%;
  }

  .pet-expression {
    font-size: 72px;
  }

  .action-buttons {
    grid-template-columns: repeat(2, 1fr);
  }

  .btn-adventure {
    grid-column: span 2;
  }

  .top-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .save-load-buttons {
    justify-content: flex-end;
  }

  .attr-label {
    width: 60px;
    font-size: 0.8rem;
  }
}

/* 手机横屏 / 小平板 (480px - 767px) */
@media (min-width: 480px) and (max-width: 767px) {
  .game-container {
    max-width: 480px;
  }

  .pet-expression {
    font-size: 80px;
  }

  .action-buttons {
    grid-template-columns: repeat(3, 1fr);
  }

  .btn-adventure {
    grid-column: span 3;
  }
}

/* iPad / 平板 (768px - 1023px) */
@media (min-width: 768px) and (max-width: 1023px) {
  body {
    padding: 24px;
  }

  .game-container {
    max-width: 600px;
    gap: 20px;
  }

  .pet-expression {
    font-size: 110px;
  }

  .pet-area {
    padding: 32px 24px;
  }

  .pet-name {
    font-size: 1.6rem;
  }

  .action-buttons {
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
  }

  .btn-adventure {
    grid-column: span 4;
  }

  .btn-action {
    padding: 14px 10px;
    font-size: 1rem;
  }

  .attributes-panel {
    padding: 20px;
    gap: 14px;
  }

  .attr-label {
    width: 80px;
    font-size: 0.9rem;
  }

  .progress-bar-container {
    height: 18px;
    border-radius: 9px;
  }

  .progress-bar {
    border-radius: 9px;
  }

  .panel {
    padding: 20px;
  }

  .audio-controls {
    padding: 18px 20px;
  }
}

/* PC 桌面 (>= 1024px) */
@media (min-width: 1024px) {
  body {
    padding: 32px;
    align-items: center;
  }

  .game-container {
    max-width: 520px;
    gap: 20px;
  }

  .pet-expression {
    font-size: 120px;
  }

  .pet-area {
    padding: 36px 24px;
  }

  .pet-name {
    font-size: 1.6rem;
  }

  .action-buttons {
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
  }

  .btn-adventure {
    grid-column: span 4;
  }

  .btn-action {
    padding: 14px 10px;
    font-size: 1rem;
  }

  .btn-action:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--color-shadow);
  }

  .attributes-panel {
    padding: 20px;
    gap: 14px;
  }

  .attr-label {
    width: 80px;
    font-size: 0.9rem;
  }

  .progress-bar-container {
    height: 18px;
    border-radius: 9px;
  }

  .progress-bar {
    border-radius: 9px;
  }

  .top-bar {
    padding: 14px 20px;
  }

  .panel {
    padding: 20px;
  }

  .audio-controls {
    padding: 18px 20px;
  }

  .death-content {
    padding: 48px 40px;
    max-width: 400px;
  }
}

/* ===== 滚动条美化 ===== */
.item-list::-webkit-scrollbar {
  width: 6px;
}

.item-list::-webkit-scrollbar-track {
  background: transparent;
}

.item-list::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 3px;
}

.item-list::-webkit-scrollbar-thumb:hover {
  background: #aaa;
}

/* ===== 连接状态提示 ===== */
.connection-lost {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: #ef5350;
  color: #fff;
  padding: 10px 24px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  z-index: 1500;
  box-shadow: 0 4px 12px rgba(239, 83, 80, 0.4);
  animation: toast-in 0.3s ease;
}
