/* ============================================================
   像素田园 —— 像素风样式（白天 / 夜晚双主题）
   ============================================================ */

* { box-sizing: border-box; }

:root {
  --page: #eef3e2;
  --panel: #fff9e8;
  --ink: #3a2f1e;
  --ink-2: #7a6a48;
  --accent: #4e9a47;
  --accent-ink: #ffffff;
  --accent-dark: #3a7a36;
  --border: #7a6a48;
  --shadow: rgba(58, 47, 30, 0.22);
  --tile: 46px;
}

html[data-theme] {
  --page: #0c1120;
  --panel: #1b2336;
  --ink: #e9eef8;
  --ink-2: #9aa6bd;
  --accent: #7fb0f0;
  --accent-ink: #0b1220;
  --accent-dark: #2b4d8a;
  --border: #40547f;
  --shadow: rgba(0, 0, 0, 0.55);
  --tile: 46px;
}

html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "PingFang SC", "Segoe UI", "Microsoft YaHei", sans-serif;
  background: var(--page);
  color: var(--ink);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

kbd {
  font-family: inherit;
  font-size: 12px;
  background: var(--surface-2, #eef0e6);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 6px;
}

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--accent-dark);
  color: #fff;
  padding: 10px 16px;
  border-bottom: 4px solid var(--border);
  flex-wrap: wrap;
  flex-shrink: 0;
}
.pixel-title {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0.08em;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.25);
  display: flex;
  align-items: center;
  gap: 8px;
}
.topbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.hud-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.16);
  border: 2px solid rgba(255, 255, 255, 0.4);
  padding: 3px 10px;
  font-size: 13px;
}
.px-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: rgba(255, 255, 255, 0.18);
  border: 2px solid rgba(255, 255, 255, 0.4);
  color: #fff;
  font-size: 14px;
  padding: 3px 10px;
  cursor: pointer;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
}
.px-btn:active { transform: translateY(1px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25); }

.icon-canvas { image-rendering: pixelated; display: inline-block; }

/* ---------- 卡片导航 ---------- */
.cards {
  display: flex;
  gap: 10px;
  max-width: 1120px;
  width: 100%;
  margin: 12px auto 0;
  padding: 0 16px;
  flex-shrink: 0;
}
.card {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--panel);
  border: 3px solid var(--border);
  box-shadow: 0 3px 0 var(--shadow);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  cursor: pointer;
}
.card:hover { filter: brightness(1.03); }
.card.is-active {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent-dark);
  transform: translateY(1px);
  box-shadow: 0 1px 0 var(--shadow);
}
.card .icon-canvas { margin-left: -4px; }

/* ---------- 主布局 ---------- */
.layout {
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
  max-width: 1120px;
  width: 100%;
  margin: 0 auto;
  padding: 12px 16px 16px;
  overflow: hidden;
}
.layout.shop-mode { grid-template-columns: 1fr; }
.layout.shop-mode .stage { display: none; }

.stage { min-width: 0; min-height: 0; overflow: auto; }

/* ---------- 场景 ---------- */
.scene-wrap { position: relative; width: fit-content; }
.scene-wrap[hidden] { display: none; }
.scene {
  display: grid;
  gap: 2px;
  padding: 8px;
  background: var(--accent-dark);
  border: 4px solid var(--border);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.18), 0 4px 0 var(--shadow);
  width: fit-content;
  image-rendering: pixelated;
}
.tile {
  width: var(--tile);
  height: var(--tile);
  position: relative;
  image-rendering: pixelated;
}
.tile canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
}

/* 夜晚轻纱 */
html[data-theme] .scene-wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(rgba(10, 18, 48, 0.24), rgba(16, 28, 64, 0.30));
  pointer-events: none;
  z-index: 3;
}

/* 雨天 */
.rain {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 4;
  opacity: 0.6;
}
.rain::before {
  content: "";
  position: absolute;
  inset: -40px;
  background-image: linear-gradient(
    115deg,
    transparent 0 42%,
    rgba(190, 215, 255, 0.8) 42% 46%,
    transparent 46% 100%
  );
  background-size: 14px 26px;
  animation: rainmove 0.5s linear infinite;
}
@keyframes rainmove { from { transform: translateY(0); } to { transform: translateY(26px); } }

/* 飘字 / 特效 */
.floaty {
  position: absolute;
  left: 50%;
  top: 0;
  transform: translateX(-50%);
  font-size: 14px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.92);
  border: 2px solid var(--border);
  padding: 1px 5px;
  pointer-events: none;
  animation: floatUp 0.9s forwards;
  z-index: 5;
  white-space: nowrap;
}
@keyframes floatUp {
  from { opacity: 1; transform: translate(-50%, 0); }
  to { opacity: 0; transform: translate(-50%, -26px); }
}
.fx {
  position: absolute;
  background: #8be04e;
  box-shadow: 0 0 2px #c8f77e;
  pointer-events: none;
  z-index: 6;
  animation: fxUp 0.7s ease-out forwards;
}
@keyframes fxUp {
  0% { transform: translateY(0) scale(1); opacity: 1; }
  100% { transform: translateY(-30px) scale(0.4); opacity: 0; }
}

/* 成长进度条 */
.tile-progress {
  position: absolute;
  left: 2px;
  bottom: 2px;
  height: 3px;
  width: 0%;
  background: #9be15d;
  opacity: 0;
  transition: width 0.2s linear, opacity 0.2s;
  pointer-events: none;
  z-index: 2;
}
.tile-progress.mature { background: #ffd23f; }
.tile-progress.breeding { background: #f0a9b0; }

/* ---------- 侧栏 ---------- */
.panel { display: flex; flex-direction: column; gap: 10px; min-width: 0; min-height: 0; overflow-y: auto; }
.panel-module { display: flex; flex-direction: column; gap: 12px; }
.panel-module[hidden] { display: none; }
.panel-section {
  background: var(--panel);
  border: 3px solid var(--border);
  box-shadow: 0 3px 0 var(--shadow);
  padding: 10px;
}
.panel-title {
  margin: 0 0 10px;
  font-size: 15px;
  letter-spacing: 0.06em;
  border-bottom: 2px solid var(--border);
  padding-bottom: 6px;
}
.muted { color: var(--ink-2); font-size: 12px; }

/* 资源栏 */
.resbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; font-size: 13px; }
.res-item { color: var(--ink); }
.res-item b { font-variant-numeric: tabular-nums; }
.px-btn-panel {
  background: var(--accent);
  color: var(--accent-ink);
  border: 2px solid var(--border);
  box-shadow: 0 2px 0 var(--shadow);
  padding: 3px 10px;
  cursor: pointer;
  font-size: 12px;
}
.px-btn-panel:disabled { opacity: 0.45; cursor: default; }
.px-btn-panel:active:not(:disabled) { transform: translateY(1px); box-shadow: 0 1px 0 var(--shadow); }
.expand-btn { width: 100%; padding: 6px; }

/* 工具栏 */
.toolbar { display: grid; grid-template-columns: repeat(auto-fill, minmax(66px, 1fr)); gap: 6px; }
.tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 4px;
  background: var(--panel);
  border: 3px solid var(--border);
  box-shadow: 0 3px 0 var(--shadow);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  color: var(--ink);
}
.tool-btn:hover { filter: brightness(1.03); }
.tool-btn:active,
.tool-btn.is-active { transform: translateY(2px); box-shadow: 0 1px 0 var(--shadow); }
.tool-btn.is-active {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent-dark);
}
.tool-btn .icon-canvas { display: block; }
.tool-badge {
  font-size: 11px;
  color: var(--accent-ink);
  background: var(--accent);
  border: 2px solid var(--border);
  padding: 0 5px;
  line-height: 1.6;
}

/* 图鉴 */
.collection,
.animal-collection {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 6px;
}
.collection-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px;
  border: 2px solid var(--border);
  background: var(--page);
  text-align: center;
}
.collection-card canvas { width: 32px; height: 32px; image-rendering: pixelated; }
.collection-card.locked { opacity: 0.45; }
.cc-name { font-size: 12px; color: var(--ink); }
.cc-count { font-size: 11px; color: var(--ink-2); }

/* 动物选择 */
.animal-select { display: grid; grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); gap: 8px; }
.animal-btn { font-size: 12px; }

/* 商店 */
.shop-list { display: flex; flex-direction: column; gap: 10px; }
.shop-group-title {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--ink-2);
  border-bottom: 2px dashed var(--border);
  padding-bottom: 4px;
}
.shop-group-title:first-child { margin-top: 0; }
.shop-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: var(--panel);
  border: 2px solid var(--border);
  box-shadow: 0 2px 0 var(--shadow);
}
.shop-item .icon-canvas { flex-shrink: 0; }
.shop-info { flex: 1; min-width: 0; }
.shop-name { font-size: 14px; color: var(--ink); }
.shop-sub { font-size: 11px; color: var(--ink-2); display: flex; align-items: center; flex-wrap: wrap; gap: 3px; margin-top: 2px; }
.shop-sub .icon-canvas { margin-right: 1px; }
.shop-item.owned { opacity: 0.75; }
.recipe-item .px-btn-panel { white-space: nowrap; flex-shrink: 0; }

/* 状态 */
.status { margin: 0; min-height: 22px; font-size: 13px; color: var(--ink); }
.harvest-line { margin: 8px 0 0; }

/* ---------- 响应式 ---------- */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  :root, html[data-theme] { --tile: 40px; }
}
@media (max-width: 520px) {
  :root, html[data-theme] { --tile: 34px; }
  .pixel-title { font-size: 17px; }
  .card { font-size: 13px; padding: 7px 10px; }
}
