:root {
  --bg-top: #76d7ea;
  --bg-bottom: #cbf5b8;
  --wood-dark: #6d3d14;
  --wood-mid: #9c5a25;
  --wood-light: #f9d89c;
  --green-bright: #2ecc71;
  --green-dark: #1e8449;
  --gold: #f1c40f;
  --orange: #ff7f27;
  --red: #e74c3c;
  --card-bg: #fffdf7;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

body {
  font-family: "Microsoft YaHei", "PingFang SC", "Rounded Mplus 1c", sans-serif;
  background: linear-gradient(180deg, #b71540 0%, #e55039 45%, #f6b93b 100%);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  color: #3a2312;
  overflow-x: hidden;
}

#app-container {
  width: 100%;
  max-width: 1020px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 10px 14px;
  gap: 8px;
}

/* 顶部栏 */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  background: rgba(255, 252, 240, 0.94);
  border: 3px solid #8b5a2b;
  border-radius: 18px;
  padding: 8px 14px;
  box-shadow: 0 5px 0 rgba(109, 61, 20, 0.25);
}

.brand-badge {
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge-icon {
  font-size: 30px;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,0.2));
}

.brand-text h1 {
  font-size: 20px;
  font-weight: 900;
  color: #5c310e;
  line-height: 1.1;
}

.sub-tag {
  font-size: 11px;
  background: #e8f8f5;
  color: #117864;
  padding: 2px 7px;
  border-radius: 99px;
  font-weight: 700;
  border: 1px solid #a3e4d7;
}

.stats-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.stat-pill {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 800;
  border: 2px solid #8b5a2b;
  background: #fff6d6;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.08);
  white-space: nowrap;
}

.stat-icon {
  font-size: 16px;
}

.stat-label {
  font-size: 12px;
  color: #78471c;
}

.stat-value {
  font-size: 16px;
  color: #d35400;
  min-width: 18px;
  text-align: center;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.top-btn {
  background: #ffeaa7;
  border: 2px solid #8b5a2b;
  border-radius: 12px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 800;
  color: #4d290c;
  cursor: pointer;
  box-shadow: 0 3px 0 #8b5a2b;
  transition: transform 0.1s;
  white-space: nowrap;
}

.top-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #8b5a2b;
}

.top-btn.active {
  background: #a8e6cf;
  border-color: #1e8449;
  color: #0e4b26;
  box-shadow: 0 3px 0 #1e8449;
}

/* 数学题目武道牌匾 */
.question-board {
  background: linear-gradient(180deg, #5c1916 0%, #380d0b 100%);
  border: 5px solid #f1c40f;
  border-radius: 22px;
  padding: 10px 18px;
  color: #ffffff;
  box-shadow: 0 6px 0 #2c0806, inset 0 2px 8px rgba(255, 215, 0, 0.25);
  position: relative;
}

.boss-banner {
  background: linear-gradient(90deg, #f39c12, #f1c40f, #f39c12);
  color: #5c2500;
  font-weight: 900;
  text-align: center;
  padding: 4px 12px;
  border-radius: 12px;
  margin-bottom: 6px;
  font-size: 15px;
  animation: pulseGlow 1.1s infinite alternate;
}

@keyframes pulseGlow {
  from { box-shadow: 0 0 6px #f1c40f; }
  to { box-shadow: 0 0 16px #fff200; }
}

.question-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.speak-btn, .hint-btn {
  background: #ffbe2e;
  border: 3px solid #6e3b0c;
  border-radius: 14px;
  padding: 6px 12px;
  font-size: 14px;
  font-weight: 900;
  color: #4a2504;
  cursor: pointer;
  box-shadow: 0 3px 0 #6e3b0c;
  white-space: nowrap;
}

.hint-btn {
  background: #7ed6df;
  border-color: #136f78;
  color: #093b40;
  box-shadow: 0 3px 0 #136f78;
}

.speak-btn:active, .hint-btn:active {
  transform: translateY(2px);
}

.question-content {
  text-align: center;
  flex: 1 1 180px;
  min-width: 180px;
}

.question-tag {
  font-size: 13px;
  color: #b8e994;
  font-weight: 700;
  margin-bottom: 2px;
  white-space: nowrap;
}

.question-Equation {
  font-size: 34px;
  font-weight: 900;
  letter-spacing: 1px;
  color: #fff9d2;
  white-space: nowrap;
  text-shadow: 0 3px 0 #0e260b, 0 0 12px rgba(255, 241, 118, 0.45);
}

/* 可视化数苹果/凑十法辅助区 */
.visual-helper {
  margin-top: 8px;
  background: rgba(255, 255, 255, 0.14);
  border: 2px dashed rgba(255, 255, 255, 0.45);
  border-radius: 14px;
  padding: 8px 12px;
  text-align: center;
}

.visual-helper-content {
  font-size: 16px;
  line-height: 1.5;
  color: #fffde7;
  font-weight: 700;
}

.ten-frame-box {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  background: rgba(0, 0, 0, 0.28);
  border: 2px solid #f6e58d;
  border-radius: 10px;
  padding: 5px 8px;
  margin: 4px 6px;
  vertical-align: middle;
}

.boss-progress-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 6px;
  font-size: 12px;
  color: #d4efdf;
}

.boss-dots {
  display: flex;
  gap: 6px;
}

.b-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  border: 2px solid #f9ca24;
  transition: all 0.25s;
}

.b-dot.filled {
  background: #f9ca24;
  box-shadow: 0 0 8px #f9ca24;
  transform: scale(1.15);
}

/* 主游戏画布舞台 */
.stage-wrapper {
  position: relative;
  width: 100%;
  background: #87ceeb;
  border: 4px solid #784212;
  border-radius: 24px;
  overflow: hidden;
  box-shadow: 0 8px 0 rgba(92, 49, 14, 0.35);
}

#game-canvas {
  display: block;
  width: 100%;
  height: auto;
  cursor: pointer;
  touch-action: manipulation;
}

.controls-overlay {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 16px;
  background: linear-gradient(180deg, #f9e79f 0%, #f5cba7 100%);
  border-top: 3px solid #8b5a2b;
}

.step-guide {
  font-size: 16px;
  font-weight: 800;
  color: #4a2306;
  flex: 1;
}

. step-guide strong {
  color: #c0392b;
}

.chop-btn {
  background: linear-gradient(180deg, #ff5e57 0%, #ff3f34 100%);
  border: 3px solid #781e19;
  border-radius: 18px;
  padding: 9px 24px;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 5px 0 #781e19, 0 0 18px rgba(255, 63, 52, 0.55);
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: transform 0.08s, filter 0.15s;
  animation: chopBtnBounce 0.9s infinite alternate;
}

@keyframes chopBtnBounce {
  from { box-shadow: 0 5px 0 #781e19, 0 0 10px rgba(255, 63, 52, 0.4); }
  to { box-shadow: 0 5px 0 #781e19, 0 0 24px rgba(255, 215, 0, 0.85); }
}

.chop-btn.disabled {
  background: #bdc3c7;
  border-color: #7f8c8d;
  box-shadow: 0 4px 0 #7f8c8d;
  color: #555;
  cursor: not-allowed;
  animation: none;
}

.chop-btn:not(.disabled):active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #781e19;
}

.chop-btn-main {
  font-size: 20px;
  font-weight: 900;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.3);
}

.chop-btn-sub {
  font-size: 11px;
  opacity: 0.92;
}

/* 底部功能坞 */
.bottom-dock {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.dock-btn {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fffdf7;
  border: 3px solid #8b5a2b;
  border-radius: 16px;
  padding: 9px 12px;
  cursor: pointer;
  box-shadow: 0 4px 0 #8b5a2b;
  text-align: left;
  transition: transform 0.1s, background 0.15s;
}

.dock-btn:hover {
  background: #fff5cc;
}

.dock-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #8b5a2b;
}

.dock-icon {
  font-size: 28px;
}

.dock-info {
  display: flex;
  flex-direction: column;
}

.dock-info strong {
  font-size: 15px;
  color: #4a2504;
}

.dock-info small {
  font-size: 12px;
  color: #7f5539;
}

.red-dot {
  position: absolute;
  top: -8px;
  right: 8px;
  background: #ff3838;
  color: #fff;
  font-size: 11px;
  font-weight: 900;
  padding: 2px 8px;
  border-radius: 99px;
  border: 2px solid #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
  animation: pulseGlow 0.8s infinite alternate;
}

/* 弹窗通用 */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(25, 15, 5, 0.65);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
  z-index: 100;
}

.hidden {
  display: none !important;
}

.modal-card {
  width: 100%;
  max-width: 720px;
  max-height: 86vh;
  overflow-y: auto;
  background: #fffdf5;
  border: 4px solid #784212;
  border-radius: 24px;
  padding: 20px;
  box-shadow: 0 10px 0 #4a2504;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.modal-header h2 {
  font-size: 22px;
  color: #5c310e;
}

.close-btn {
  background: #ff6b6b;
  color: #fff;
  border: 2px solid #8b1e1e;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 18px;
  font-weight: 900;
  cursor: pointer;
}

.modal-desc {
  font-size: 14px;
  color: #6e4720;
  margin-bottom: 14px;
}

.shop-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}

.shop-item {
  background: #fff8e7;
  border: 3px solid #c89d66;
  border-radius: 16px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
}

.shop-item.equipped {
  border-color: #27ae60;
  background: #eafaf1;
}

.shop-item-icon {
  font-size: 38px;
}

.shop-item-title {
  font-size: 16px;
  font-weight: 900;
  color: #4a2504;
}

.shop-item-perk {
  font-size: 12px;
  color: #16a085;
  font-weight: 700;
}

.shop-action-btn {
  margin-top: 4px;
  width: 100%;
  padding: 7px 10px;
  border-radius: 12px;
  border: 2px solid #5c310e;
  font-weight: 900;
  font-size: 14px;
  cursor: pointer;
  background: #f9ca24;
  color: #4a2504;
  box-shadow: 0 3px 0 #5c310e;
}

.shop-action-btn.equip {
  background: #2ecc71;
  border-color: #145a32;
  color: #fff;
  box-shadow: 0 3px 0 #145a32;
}

.shop-action-btn:disabled {
  background: #dcdde1;
  border-color: #7f8c8d;
  color: #666;
  box-shadow: none;
  cursor: not-allowed;
}

/* 难度选择卡片 */
.diff-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.diff-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fff8e7;
  border: 3px solid #c89d66;
  border-radius: 16px;
  padding: 12px 16px;
  cursor: pointer;
}

.diff-card.active {
  border-color: #27ae60;
  background: #eafaf1;
}

.diff-card h3 {
  font-size: 17px;
  color: #4a2504;
}

.diff-card p {
  font-size: 13px;
  color: #78471c;
}

/* 奖状与树屋面板 */
.certificate-box {
  background: linear-gradient(135deg, #fff9e6 0%, #fff0b3 100%);
  border: 6px double #d35400;
  border-radius: 18px;
  padding: 18px;
  text-align: center;
  margin-bottom: 14px;
}

.certificate-box h3 {
  font-size: 24px;
  color: #c0392b;
  margin-bottom: 8px;
}

.cert-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 12px 0;
}

.cert-stat-card {
  background: rgba(255, 255, 255, 0.8);
  border-radius: 12px;
  padding: 10px;
  border: 2px solid #f39c12;
}

.cert-stat-card strong {
  display: block;
  font-size: 22px;
  color: #d35400;
}

@media (max-width: 600px) {
  .question-content {
    order: -1;
    flex: 1 1 100%;
  }
  .question-main {
    justify-content: center;
  }
  .question-Equation {
    font-size: 28px;
  }
  .bottom-dock {
    grid-template-columns: repeat(2, 1fr);
  }
  .controls-overlay {
    flex-direction: column;
    text-align: center;
  }
  .chop-btn {
    width: 100%;
  }
}
