/* ============================================================
   单词花园保卫战 · 视觉样式
   配色：暖纸白 #FFF7E6 / 蜜糖金 #FFD24C / 嫩芽绿 #7ED957 / 柔和蓝 #5B8DEF
   红线：不用纯红做错误态，不用倒计时压迫色，不做暗角压黑
   ============================================================ */

:root {
  --paper: #FFF7E6;
  --paper-2: #FFFCF2;
  --ink: #3A3226;
  --ink-soft: #6B6152;
  --grass-1: #CDEB8B;
  --grass-2: #B7DF74;
  --sun: #FFB547;
  --sun-2: #FFD24C;
  --green: #7ED957;
  --green-deep: #4F9E3B;
  --blue: #5B8DEF;
  --amber: #F2C879;
  --pink: #FF8FA3;
  --shadow: 0 6px 0 rgba(58, 50, 38, .12);
  --shadow-soft: 0 10px 28px rgba(58, 50, 38, .12);
  --radius: 20px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  font-size: 16px;
  overscroll-behavior: none;
}

#app { height: 100%; }

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
}
.screen.active { display: flex; }
.hidden { display: none !important; }

/* ---------------------------------------------------------- 通用按钮 */

.btn {
  border: 0;
  cursor: pointer;
  font-family: inherit;
  font-weight: 700;
  border-radius: 16px;
  padding: 13px 22px;
  font-size: 17px;
  transition: transform .12s ease, box-shadow .12s ease, background .15s ease;
}
.btn:active { transform: translateY(2px); }
.btn-primary {
  background: var(--sun);
  color: #4A2C00;
  box-shadow: 0 5px 0 #C97F1E;
}
.btn-primary:active { box-shadow: 0 2px 0 #C97F1E; }
.btn-primary:disabled {
  background: #E8E0CE;
  color: #A79C88;
  box-shadow: 0 5px 0 #D8CEB8;
  cursor: default;
}
.btn-ghost {
  background: rgba(58, 50, 38, .06);
  color: var(--ink-soft);
}
.btn-soft {
  background: #EAF4DC;
  color: #3F6B26;
  box-shadow: 0 4px 0 #CBE0B4;
}
.btn-danger {
  background: #FDECEC;
  color: #A34A3C;
  box-shadow: 0 4px 0 #F2D2CE;
  width: 100%;
}
.btn-xl { font-size: 20px; padding: 16px 34px; border-radius: 20px; }

.icon-btn {
  border: 0;
  background: rgba(58, 50, 38, .06);
  color: var(--ink);
  font-size: 20px;
  font-weight: 700;
  width: 46px;
  height: 46px;
  border-radius: 14px;
  cursor: pointer;
  display: grid;
  place-items: center;
  line-height: 1;
}
.icon-btn:active { transform: translateY(1px); }

/* ---------------------------------------------------------- 主菜单 */

.menu-wrap {
  margin: auto;
  width: min(720px, 92vw);
  padding: 28px 0 40px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.title-block { text-align: center; }
.title-art img {
  width: 104px;
  height: 104px;
  filter: drop-shadow(0 8px 14px rgba(58, 50, 38, .18));
  animation: bob 3.4s ease-in-out infinite;
}
@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-7px) rotate(2deg); }
}
.title-block h1 {
  margin: 4px 0 6px;
  font-size: clamp(26px, 5vw, 38px);
  letter-spacing: 1px;
}
.subtitle { margin: 0; color: var(--ink-soft); font-size: 15px; }

.section-label {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-soft);
  margin-bottom: 10px;
}

.pack-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}
.pack-card {
  text-align: left;
  border: 2px solid transparent;
  background: var(--paper-2);
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .12s ease, border-color .12s ease;
}
.pack-card:active { transform: translateY(2px); }
.pack-card.selected { border-color: var(--sun); background: #FFFBEC; }
.pack-top { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; }
.pack-name { font-weight: 800; font-size: 16px; }
.pack-cefr { font-size: 11px; font-weight: 700; color: var(--blue); background: #EAF1FE; border-radius: 999px; padding: 2px 8px; }
.pack-exam { font-size: 12px; color: var(--ink-soft); margin: 3px 0 9px; }
.pack-meter { height: 8px; border-radius: 999px; background: #EDE6D6; overflow: hidden; }
.pack-meter i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--green), var(--sun-2)); border-radius: 999px; transition: width .3s ease; }
.pack-count {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  font-size: 11px;
  color: var(--ink-soft);
  margin-top: 7px;
  white-space: nowrap;
}

.menu-actions { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.menu-sub { display: flex; gap: 10px; }
.progress-line { text-align: center; font-size: 13px; color: var(--ink-soft); }

/* ---------------------------------------------------------- 关卡选择 */

.levels-wrap {
  margin: auto;
  width: min(880px, 94vw);
  padding: 20px 0 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: 100%;
}
.levels-head { display: flex; align-items: center; gap: 14px; }
.levels-title { flex: 1; min-width: 0; }
.levels-title h2 { margin: 0; font-size: 20px; }
.levels-title p { margin: 2px 0 0; font-size: 12px; color: var(--ink-soft); }
.levels-progress { width: 128px; text-align: right; }
.lp-num { font-size: 18px; font-weight: 800; color: var(--green-deep); }
.lp-num small { font-size: 11px; color: var(--ink-soft); font-weight: 600; }
.lp-bar { height: 7px; border-radius: 999px; background: #EDE6D6; overflow: hidden; margin-top: 4px; }
.lp-bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--green), var(--sun-2)); transition: width .3s ease; }

.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
  gap: 12px;
  overflow-y: auto;
  padding-bottom: 8px;
}
.level-card {
  text-align: left;
  border: 2px solid transparent;
  background: var(--paper-2);
  border-radius: 18px;
  padding: 12px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .12s ease, border-color .12s ease;
}
.level-card:active { transform: translateY(2px); }
.level-card.current { border-color: var(--sun); background: #FFFBEC; }
.level-card.complete { border-color: var(--green); background: #F4FBEC; }
.level-card.locked { opacity: .5; box-shadow: none; cursor: default; }
.lc-head { display: flex; align-items: center; justify-content: space-between; }
.lc-stage { font-weight: 800; font-size: 15px; }
.lc-badge { font-size: 11px; font-weight: 700; color: var(--ink-soft); }
.level-card.complete .lc-badge { color: var(--green-deep); }
.lc-words { display: flex; flex-wrap: wrap; gap: 5px; margin: 9px 0 7px; }
.lc-word {
  font-size: 12px;
  font-weight: 700;
  color: #4A4234;
  background: #F0EADA;
  border-radius: 8px;
  padding: 3px 7px;
  letter-spacing: .3px;
}
.lc-word.done { background: #DDF3C6; color: #3F6B26; }
.lc-waves { font-size: 11px; color: var(--ink-soft); }

/* ---------------------------------------------------------- 战斗 HUD */

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 14px;
  background: var(--paper-2);
  box-shadow: 0 3px 12px rgba(58, 50, 38, .07);
  z-index: 3;
  flex-wrap: wrap;
}
.hud-left { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.sun-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #FFF1CF;
  border-radius: 999px;
  padding: 4px 14px 4px 6px;
  font-weight: 800;
  font-size: 18px;
  color: #7A4A00;
  transition: transform .16s ease;
}
.sun-chip.bump { transform: scale(1.14); }
.sun-ico { width: 26px; height: 26px; }
.hud-meta { font-size: 13px; color: var(--ink-soft); font-weight: 600; }
.hud-dot { margin: 0 5px; opacity: .5; }

.word-track { display: flex; gap: 6px; flex-wrap: wrap; }
.wt-chip {
  font-size: 12px;
  font-weight: 700;
  color: #8B8069;
  background: #F0EADA;
  border-radius: 8px;
  padding: 3px 8px;
  letter-spacing: .4px;
  transition: background .2s ease, color .2s ease;
}
.wt-chip.done { background: #DDF3C6; color: #3F6B26; }

.hud-right { display: flex; align-items: center; gap: 8px; }
.breach-chip { font-size: 16px; letter-spacing: 1px; }

/* ---------------------------------------------------------- 战场 */

.stage { position: relative; flex: 1; min-height: 0; }
#field { display: block; width: 100%; height: 100%; touch-action: none; cursor: pointer; }

.sun-hint {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 241, 207, .96);
  color: #7A4A00;
  font-weight: 700;
  font-size: 13px;
  padding: 8px 16px;
  border-radius: 999px;
  box-shadow: var(--shadow-soft);
  pointer-events: none;
  animation: floatY 1.8s ease-in-out infinite;
}
@keyframes floatY {
  0%, 100% { transform: translate(-50%, 0); }
  50% { transform: translate(-50%, -5px); }
}

.prep-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  /* 关键：遮罩不能吃掉战场的点击，否则准备阶段既不能种植物也不能收阳光 */
  pointer-events: none;
  background: rgba(255, 247, 230, .18);
}
.prep-card {
  pointer-events: auto;
  background: var(--paper-2);
  border-radius: 24px;
  padding: 22px 26px;
  text-align: center;
  box-shadow: var(--shadow-soft);
  max-width: 320px;
}
.prep-title { font-weight: 800; font-size: 18px; margin-bottom: 6px; }
.prep-tip { font-size: 13px; color: var(--ink-soft); margin-bottom: 16px; line-height: 1.5; }

.toast {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  background: rgba(58, 50, 38, .88);
  color: #FFF7E6;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 999px;
  pointer-events: none;
  max-width: 86%;
  text-align: center;
}

/* ---------------------------------------------------------- 卡槽 */

.cardbar {
  display: flex;
  gap: 9px;
  padding: 10px 14px 14px;
  background: var(--paper-2);
  box-shadow: 0 -3px 14px rgba(58, 50, 38, .07);
  overflow-x: auto;
  z-index: 3;
}
.card {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 9px;
  border: 2px solid #E6DECB;
  background: #FFFDF7;
  border-radius: 16px;
  padding: 8px 14px 8px 8px;
  cursor: pointer;
  min-width: 132px;
  box-shadow: 0 4px 0 #EDE6D6;
  transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease;
}
.card:active { transform: translateY(2px); box-shadow: 0 2px 0 #EDE6D6; }
.card.selected { border-color: var(--sun); background: #FFFBEC; box-shadow: 0 4px 0 #F0D79A; }
.card.ready { border-color: var(--green); }
.card.poor .card-cost { color: #B0A791; }
.card-art { width: 46px; height: 46px; flex: 0 0 auto; }
.card-body { text-align: left; }
.card-name { font-size: 13px; font-weight: 800; white-space: nowrap; }
.card-meta { display: flex; align-items: center; gap: 6px; margin-top: 3px; }
.card-cost { font-size: 12px; font-weight: 800; color: #8B6A12; }
.card-cost::before { content: "☀ "; }
.card-cost.free { color: var(--green-deep); }
.card-cost.free::before { content: ""; }
.card-verb { font-size: 11px; color: var(--ink-soft); white-space: nowrap; }
.card-ready {
  position: absolute;
  top: -7px;
  right: -5px;
  font-size: 10px;
  font-weight: 800;
  color: #2F6B1C;
  background: var(--green);
  border-radius: 999px;
  padding: 2px 7px;
  opacity: 0;
  transform: scale(.7);
  transition: opacity .16s ease, transform .16s ease;
}
.card.ready .card-ready { opacity: 1; transform: scale(1); }

/* ---------------------------------------------------------- 结算 */

.result-wrap {
  margin: auto;
  width: min(560px, 92vw);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 24px 0 36px;
}
.result-art {
  width: 116px;
  height: 116px;
  margin: 0 auto;
  filter: drop-shadow(0 8px 16px rgba(58, 50, 38, .16));
}
.result-wrap h2 { margin: 0; font-size: 22px; }
.result-sub { margin: 0; color: var(--ink-soft); font-size: 14px; line-height: 1.6; }
.result-words { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.rw-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #F0EADA;
  border-radius: 12px;
  padding: 8px 12px;
  min-width: 74px;
}
.rw-chip.done { background: #DDF3C6; }
.rw-en { font-weight: 800; font-size: 15px; letter-spacing: .4px; }
.rw-zh { font-size: 11px; color: var(--ink-soft); margin-top: 2px; }
.result-stats { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.stat-pill {
  background: var(--paper-2);
  border-radius: 14px;
  padding: 10px 16px;
  box-shadow: var(--shadow);
  min-width: 96px;
}
.stat-pill span { display: block; font-weight: 800; font-size: 18px; color: var(--green-deep); }
.stat-pill small { font-size: 11px; color: var(--ink-soft); }
.result-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ---------------------------------------------------------- 弹框 */

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  /* 不用 backdrop-filter：全屏模糊叠在「每帧重绘的 canvas」上，是拖拽卡顿的头号元凶 */
  background: rgba(255, 247, 230, .72);
  padding: 16px;
  overscroll-behavior: contain;
}
.spell-panel {
  position: relative;
  width: min(520px, 100%);
  max-height: 94vh;
  overflow-y: auto;
  background: var(--paper-2);
  border-radius: 26px;
  padding: 20px 20px 22px;
  box-shadow: var(--shadow-soft);
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  border: 0;
  background: rgba(58, 50, 38, .07);
  color: var(--ink-soft);
  width: 36px;
  height: 36px;
  border-radius: 12px;
  font-size: 16px;
  cursor: pointer;
}
.spell-head { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.word-main {
  flex: 1;
  min-width: 0;
  background: #FFF6E0;
  border-radius: 20px;
  padding: 12px 16px;
}
.word-en {
  font-size: clamp(28px, 7vw, 42px);
  font-weight: 800;
  letter-spacing: 2px;
  line-height: 1.15;
  word-break: break-all;
}
.word-ipa {
  font-size: 14px;
  color: var(--ink-soft);
  margin-top: 2px;
  min-height: 18px;
  letter-spacing: .5px;
}
.word-meta { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.word-zh { font-size: 26px; font-weight: 800; }
.unit-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--paper-2);
  border-radius: 16px;
  padding: 8px 12px;
  box-shadow: var(--shadow);
}
.unit-btn {
  border: 0;
  background: rgba(58, 50, 38, .07);
  color: var(--ink);
  width: 40px;
  height: 40px;
  border-radius: 12px;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
}
.unit-btn:disabled { opacity: .35; cursor: default; }
.unit-label { flex: 1; text-align: center; line-height: 1.35; }
.unit-label strong { display: block; font-size: 15px; }
.unit-label span { font-size: 11.5px; color: var(--ink-soft); }
.word-len { font-size: 12px; color: var(--ink-soft); }
.btn-speak {
  background: #EAF1FE;
  color: #2F5FB0;
  font-size: 14px;
  padding: 8px 14px;
  border-radius: 12px;
  box-shadow: none;
}

.slot-row { display: flex; gap: 8px; justify-content: center; margin-bottom: 16px; flex-wrap: wrap; }
.slot {
  width: 54px;
  height: 62px;
  border-radius: 14px;
  border: 3px dashed #D6CCB6;
  background: #FFFDF7;
  display: grid;
  place-items: center;
  font-size: 26px;
  font-weight: 800;
  color: var(--ink);
  transition: border-color .15s ease, background .15s ease, transform .15s ease;
}
.slot.filled { border-style: solid; border-color: var(--sun); background: #FFF3D2; }
.slot.hover { border-color: var(--blue); background: #EAF1FE; }
/* 拖拽期间关掉过渡：避免每次 hover 变化都重启动画、引发额外重绘 */
.dragging-active #slot-row .slot { transition: none; }
.dragging-active .letter-card { transition: none; }

.tray-label { text-align: center; font-size: 12px; color: var(--ink-soft); margin-bottom: 10px; }
.card-tray {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  min-height: 66px;
  padding: 10px;
  background: #F6F0E0;
  border-radius: 18px;
}
.letter-card {
  width: 54px;
  height: 62px;
  border-radius: 14px;
  background: #FFFFFF;
  border: 2px solid #E6DECB;
  box-shadow: 0 4px 0 #E6DECB;
  display: grid;
  place-items: center;
  font-size: 26px;
  font-weight: 800;
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.letter-card.distractor { background: #FBF3FF; border-color: #E6D8F0; box-shadow: 0 4px 0 #E6D8F0; }
.letter-card.dragging {
  cursor: grabbing;
  /* 拖拽副本只做位移：去掉阴影与过渡，减少每帧绘制成本 */
  box-shadow: none;
  border-color: var(--sun);
  z-index: 80;
  transition: none;
}

.spell-feedback {
  min-height: 22px;
  text-align: center;
  font-size: 13px;
  color: #8A6A1E;
  margin: 10px 0 4px;
  font-weight: 600;
}
.spell-actions { display: flex; gap: 10px; justify-content: center; margin-top: 8px; }
.spell-actions .btn { flex: 1; max-width: 200px; }

/* ---------------------------------------------------------- 家长 / 隐私 */

.parent-panel, .privacy-panel {
  position: relative;
  width: min(480px, 100%);
  max-height: 92vh;
  overflow-y: auto;
  background: #FFFDF7;
  border-radius: 24px;
  padding: 22px;
  box-shadow: var(--shadow-soft);
}
.parent-panel h3, .privacy-panel h3 { margin: 0 0 10px; font-size: 19px; }
.parent-note { font-size: 13px; color: var(--ink-soft); line-height: 1.65; margin: 0 0 14px; }
.parent-grid { display: flex; gap: 10px; margin-bottom: 14px; }
.parent-stat {
  flex: 1;
  background: #F6F0E0;
  border-radius: 14px;
  padding: 12px 8px;
  text-align: center;
}
.parent-stat span { display: block; font-size: 20px; font-weight: 800; color: var(--green-deep); }
.parent-stat label { font-size: 11px; color: var(--ink-soft); }
.parent-rows { display: flex; flex-direction: column; gap: 2px; margin-bottom: 12px; }
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 4px;
  border-bottom: 1px solid #F0EADA;
  font-size: 15px;
}
.row input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--green-deep); }
.parent-tip { font-size: 12px; color: var(--ink-soft); line-height: 1.6; margin: 0 0 14px; }
.privacy-panel ul { margin: 0 0 16px; padding-left: 20px; font-size: 13.5px; line-height: 1.85; color: var(--ink-soft); }
.privacy-panel .btn { width: 100%; }

/* ---------------------------------------------------------- 减弱动画 */

.reduce-motion *, .reduce-motion *::before, .reduce-motion *::after {
  animation: none !important;
  transition: none !important;
}

@media (max-width: 560px) {
  .hud { padding: 7px 10px; gap: 8px; }
  .sun-chip { font-size: 16px; }
  .word-track { order: 3; width: 100%; }
  .card { min-width: 116px; padding: 6px 10px 6px 6px; }
  .card-art { width: 38px; height: 38px; }
  .slot, .letter-card { width: 46px; height: 54px; font-size: 22px; }
  .word-pic { width: 84px; height: 84px; font-size: 44px; }
}
