/* ===========================================================
   植物大战僵尸 · 网页版  —  样式表
   （游戏 HUD 已画进 Canvas，这里只负责外层框架与弹窗）
   =========================================================== */

:root {
  --panel:  #2b1a0e;
  --gold:   #f5c542;
  --gold-2: #d9a520;
  --text:   #f6efe2;
  --green:  #4caf50;
  --red:    #e74c3c;
  --shadow: 0 6px 20px rgba(0, 0, 0, .45);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: #1b1206;
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#app {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 1180px;
  margin: 0 auto;
  background: #241608;
}

/* ---------------- 舞台 / 画布 ---------------- */
#stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at 50% 0%, #3f2a12 0%, #1b1206 70%);
  padding: 8px;
  overflow: hidden;
}

#game {
  display: block;
  border-radius: 10px;
  box-shadow: var(--shadow), 0 0 0 3px #3d2612, 0 0 0 6px #1a0f05;
  touch-action: none;
  cursor: pointer;
  max-width: 100%;
  max-height: 100%;
}

/* iOS/WebKit 的长按选图菜单与选区会打断游戏操作。保留表单文字编辑。 */
#stage, #stage canvas, #stage button, #stage svg {
  -webkit-user-select:none;
  user-select:none;
  -webkit-touch-callout:none;
}
#stage input, #stage textarea, #stage [contenteditable="true"] {
  -webkit-user-select:text;
  user-select:text;
  -webkit-touch-callout:default;
}

/* ---------------- Toast ---------------- */
#toast {
  position: absolute;
  top: 14px; left: 50%;
  transform: translateX(-50%);
  background: rgba(20, 12, 4, .92);
  border: 2px solid var(--gold-2);
  color: var(--gold);
  font-weight: 700;
  font-size: 14px;
  padding: 8px 18px;
  border-radius: 24px;
  pointer-events: none;
  opacity: 0;
  transition: opacity .25s, transform .25s;
  z-index: 30;
  white-space: nowrap;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(4px); }

/* ---------------- 遮罩 / 面板 ---------------- */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(10, 6, 2, .84);
  backdrop-filter: blur(3px);
  z-index: 40;
  padding: 16px;
  overflow-y: auto;
}
.overlay.hidden { display: none; }
.hidden { display: none !important; }

.panel {
  background: linear-gradient(#3d2612, #241608);
  border: 3px solid #6d5408;
  border-radius: 16px;
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(255,255,255,.06);
  padding: 22px 24px;
  text-align: center;
  max-width: 460px;
  width: 100%;
  animation: pop .22s ease;
}
.panel.wide { max-width: 760px; }
@keyframes pop { from { transform: scale(.94); opacity: 0; } }

.title {
  font-size: clamp(24px, 5vw, 38px);
  color: var(--gold);
  text-shadow: 0 3px 0 #7a5c0c, 0 0 24px rgba(245,197,66,.4);
  margin-bottom: 6px;
  letter-spacing: 2px;
}
.subtitle { font-size: 13px; color: #b9a582; margin-bottom: 18px; }
.panel h2 { color: var(--gold); font-size: 22px; margin-bottom: 12px; }
.muted { color: #b9a582; font-size: 13px; margin-bottom: 14px; }

/* ---------------- 关卡选择 ---------------- */
#level-select {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.level-card {
  background: linear-gradient(#4a7c23, #2f5413);
  border: 2px solid #7ec850;
  border-radius: 12px;
  padding: 12px 8px;
  cursor: pointer;
  transition: transform .12s, box-shadow .15s;
  text-align: center;
}
.level-card:hover:not(.locked) { transform: translateY(-3px); box-shadow: 0 6px 16px rgba(126,200,80,.35); }
.level-card .lv-num  { font-size: 12px; color: #cdeaa8; letter-spacing: 1px; }
.level-card .lv-name { font-size: 15px; font-weight: 800; margin: 3px 0 5px; }
.level-card .lv-desc { font-size: 11px; color: #d8e9c0; line-height: 1.35; }
.level-card .lv-stars { font-size: 12px; margin-top: 5px; letter-spacing: 1px; }
.level-card.locked {
  background: linear-gradient(#3a3a3a, #242424);
  border-color: #555;
  cursor: not-allowed;
  opacity: .75;
}
.level-card.locked .lv-name, .level-card.locked .lv-desc { color: #999; }

.best-box { font-size: 13px; color: #cbb87d; margin-bottom: 6px; }
.best-box strong { color: var(--gold); }
.best-box .sep { margin: 0 8px; opacity: .5; }
.credits { font-size: 11px; color: #8a7a5c; margin-top: 14px; line-height: 1.6; }

/* ---------------- 按钮 ---------------- */
.btn-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 16px;
}

.btn {
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  color: #f6efe2;
  background: linear-gradient(#6b4423, #4a2d14);
  border: 2px solid #8b6b3a;
  border-radius: 10px;
  padding: 10px 20px;
  cursor: pointer;
  transition: transform .1s, filter .15s;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: linear-gradient(#7ec850, #4e8b28);
  border-color: #b6ff87;
  color: #12290a;
  text-shadow: 0 1px 0 rgba(255,255,255,.35);
}
.btn.small { font-size: 12.5px; padding: 8px 14px; }
.btn.muted { opacity: .6; }
.btn.active { background: linear-gradient(#7ec850, #4e8b28); border-color: #b6ff87; color: #12290a; }

kbd {
  background: #1a0f05;
  border: 1px solid #6d5408;
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 5px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 11px;
  color: var(--gold);
}

/* ---------------- 帮助 ---------------- */
.help-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  text-align: left;
  margin-top: 6px;
}
.help-grid section {
  background: rgba(0,0,0,.28);
  border: 1px solid #6d5408;
  border-radius: 10px;
  padding: 10px 12px;
}
.help-grid h3 { font-size: 14px; color: var(--gold); margin-bottom: 6px; }
.help-grid p  { font-size: 12.5px; line-height: 1.6; color: #ddd0b8; }
.help-grid b  { color: #fff; }

/* ---------------- 开关（自动拾取阳光） ---------------- */
.switch-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px solid rgba(109, 84, 8, .55);
  cursor: pointer;
  user-select: none;
}
.switch-row input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  position: relative;
  flex: 0 0 auto;
  width: 38px; height: 20px;
  border-radius: 10px;
  background: #1a0f05;
  border: 2px solid #6d5408;
  transition: background .18s, border-color .18s;
}
.switch-knob {
  position: absolute;
  top: 2px; left: 2px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #8a7a5c;
  transition: transform .18s, background .18s;
}
.switch-row input:checked + .switch-track { background: #4e8b28; border-color: #b6ff87; }
.switch-row input:checked + .switch-track .switch-knob { transform: translateX(18px); background: #eaffd6; }
.switch-row input:focus-visible + .switch-track { box-shadow: 0 0 0 3px rgba(126, 200, 80, .5); }
.switch-label { font-size: 12.5px; color: #ddd0b8; font-weight: 600; }

/* ---------------- 结算 ---------------- */
#result-title { font-size: 28px; }
#result-title.win  { color: #8ce06a; text-shadow: 0 0 20px rgba(126,200,80,.6); }
#result-title.lose { color: #ff7b6b; text-shadow: 0 0 20px rgba(231,76,60,.6); }
#result-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 16px 0 4px;
  text-align: left;
}
.stat {
  background: rgba(0,0,0,.3);
  border: 1px solid #6d5408;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
}
.stat span { color: #b9a582; }
.stat strong { color: var(--gold); }

/* ---------------- 移动端 ---------------- */
@media (max-width: 640px) {
  .panel { padding: 16px; }
  #result-stats { grid-template-columns: 1fr; }
  .title { letter-spacing: 1px; }
}
