/* 比特冒险岛 Bit Island — 绿色卡通风 + iPad 专项 */
:root {
  --g: #57b349; --g-dark: #3e9134; --g-light: #8fd97f; --g-pale: #eaf6e4;
  --g-pale2: #ddf0d2; --ink: #2b3a28; --muted: #6b7d66;
  --coin: #f5b942; --bump: #e26d5a; --card: #ffffff;
  --shadow: 0 4px 14px rgba(62, 145, 52, 0.18);
  --radius: 18px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, "PingFang SC", "Segoe UI", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, #d9f2cf 0%, #eaf6e4 45%, #fff8e1 100%);
  -webkit-font-smoothing: antialiased;
}
body {
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  touch-action: manipulation;
}
#app {
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  max-width: 1080px;
  margin: 0 auto;
}

/* ---------- 通用控件（触控目标 ≥48px） ---------- */
button {
  font-family: inherit;
  border: none; cursor: pointer;
  border-radius: 14px;
  font-weight: 700;
  min-height: 48px;
  padding: 0 18px;
  font-size: 16px;
  touch-action: manipulation;
  transition: transform 0.08s ease, box-shadow 0.12s ease;
}
button:active { transform: scale(0.96); }
.btn { background: #fff; color: var(--ink); border: 2px solid var(--g-pale2); box-shadow: var(--shadow); }
.btn.primary { background: var(--g); color: #fff; border-color: var(--g-dark); }
.btn.danger { background: var(--bump); color: #fff; border-color: #c75a49; }
.btn.big { min-height: 54px; font-size: 18px; padding: 0 26px; }
.btn:disabled { opacity: 0.45; }
.icon-btn { background: #fff; border: 2px solid var(--g-pale2); min-width: 48px; box-shadow: var(--shadow); }
button, input, textarea { outline-color: var(--g); }

/* ---------- 地图页 ---------- */
.map-header { text-align: center; margin: 8px 0 18px; position: relative; }
.map-title { font-size: 34px; margin: 0; display: flex; align-items: center; justify-content: center; gap: 10px; }
.map-bot { font-size: 40px; }
.map-sub { color: var(--muted); font-size: 15px; margin-top: 4px; }
.star-badge {
  display: inline-block; margin-top: 10px;
  background: #fff; border: 2px solid var(--coin);
  color: #a97b0c; border-radius: 999px; padding: 8px 18px; font-size: 16px; font-weight: 800;
}
.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
}
.level-card {
  background: var(--card); border: 3px solid var(--g-pale2);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 10px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  min-height: 120px; justify-content: center;
}
.level-card:not(.locked):hover { border-color: var(--g); transform: translateY(-2px); }
.level-card.locked { opacity: 0.6; filter: grayscale(0.5); }
.lv-num {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--g); color: #fff; font-size: 20px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
}
.level-card.locked .lv-num { background: #b9c9b3; }
.lv-name { font-size: 16px; font-weight: 800; }
.lv-concept { font-size: 13px; color: var(--muted); }
.lv-concept .en { color: var(--g-dark); font-weight: 700; }
.lv-stars { color: var(--coin); font-size: 16px; letter-spacing: 2px; }
.lv-stars .dim { color: #dcd2ae; }
.map-foot { text-align: center; color: var(--muted); font-size: 13px; margin: 22px 0 6px; }
.reset-btn {
  display: block; margin: 6px auto 20px;
  background: transparent; border: 2px dashed #c9d8c2; color: var(--muted);
  min-height: 40px; font-size: 13px; border-radius: 12px;
}
.snake-entry {
  display: block; margin: 20px auto 0; min-height: 56px; font-size: 18px;
  background: #fff; border: 3px solid var(--coin); color: #a97b0c;
  box-shadow: var(--shadow); border-radius: var(--radius); padding: 0 26px;
}

/* ---------- 关卡页 ---------- */
.level-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.level-bar-title { font-size: 16px; font-weight: 800; flex: 1; min-width: 0; }
.stage { display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap; }
.stage-blocks { flex-direction: column; }
.world-pane { flex: 0 1 auto; max-width: 100%; overflow: auto; }
.world-canvas { display: block; border-radius: 14px; box-shadow: var(--shadow); background: var(--g-pale); max-width: 100%; }
.world-opts { margin-top: 8px; }
.spd { min-height: 40px; }
.story-pane { width: 100%; margin-bottom: 10px; }
.story {
  background: #fff; border: 2px solid var(--g-pale2); border-radius: var(--radius);
  padding: 12px 16px; box-shadow: var(--shadow); font-size: 16px; line-height: 1.6;
  margin-bottom: 8px;
}
.task {
  background: linear-gradient(90deg, var(--g-pale), #fff);
  border: 2px solid var(--g-light); border-radius: var(--radius);
  padding: 12px 16px; font-size: 16px; font-weight: 700; line-height: 1.55;
}

/* 代码面板 */
.code-pane { flex: 1 1 340px; min-width: 300px; display: flex; flex-direction: column; gap: 10px; }
.pane-label { font-size: 15px; font-weight: 800; color: var(--g-dark); }
.editor-wrap { border: 3px solid var(--g-pale2); border-radius: 14px; overflow: hidden; background: #fff; box-shadow: var(--shadow); }
.editor {
  width: 100%; min-height: 210px; border: none; resize: vertical;
  font: 17px/1.55 "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  padding: 12px; background: #fff; color: var(--ink);
  /* iPad: 字号 ≥16px 防聚焦缩放；关掉一切自动纠正 */
  font-size: 17px;
  -webkit-text-size-adjust: 100%;
}
.frag-bar { display: flex; flex-wrap: wrap; gap: 8px; }
.frag {
  background: var(--g-pale); border: 2px solid var(--g-light); color: var(--g-dark);
  font: 700 14px "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  min-height: 42px; padding: 0 12px; border-radius: 10px;
}
.run-bar { display: flex; gap: 10px; flex-wrap: wrap; }
.run-btns { display: flex; gap: 10px; flex-wrap: wrap; }
.hint {
  background: #fffbe9; border: 2px dashed var(--coin); border-radius: 14px;
  padding: 10px 14px; font-size: 15px; line-height: 1.55; white-space: pre-wrap;
}
.error-box {
  display: none; background: #fff; border: 2px solid var(--bump);
  border-radius: 14px; padding: 12px 14px; font-size: 15px; line-height: 1.55;
}
.error-box.show { display: block; animation: pop 0.25s ease; }
.error-box.sandbox { border-color: var(--g); background: var(--g-pale); }
@keyframes pop { from { transform: scale(0.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---------- 积木 ---------- */
.block-palette { display: flex; gap: 10px; flex-wrap: wrap; margin: 8px 0; }
.pal-chip {
  font-size: 20px; min-width: 72px; font-weight: 800;
  background: #fff; border: 3px solid var(--g-pale2); border-radius: 14px; box-shadow: var(--shadow);
  color: var(--ink);
}
.pal-chip.rep { color: var(--g-dark); border-color: var(--g-light); }
.pal-chip.up { color: #3e9134; } .pal-chip.down { color: #b36b2e; }
.pal-chip.left { color: #4a7fb5; } .pal-chip.right { color: #b54a6f; }
.board-wrap {
  background: #fff; border: 3px solid var(--g-pale2); border-radius: var(--radius);
  padding: 12px; min-height: 120px; box-shadow: var(--shadow);
}
.blocks-board { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.blocks-empty { color: var(--muted); font-size: 14px; padding: 8px; }
.block-chip {
  position: relative; font-size: 26px; font-weight: 800; min-width: 64px; height: 56px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 12px; border: 2px solid; background: var(--g-pale);
}
.block-chip.sm { font-size: 20px; min-width: 48px; height: 44px; }
.block-chip.up { color: #3e9134; border-color: #8fd97f; }
.block-chip.down { color: #b36b2e; border-color: #e8c49a; }
.block-chip.left { color: #4a7fb5; border-color: #a9c8e8; }
.block-chip.right { color: #b54a6f; border-color: #e8a9bd; }
.chip-x {
  position: absolute; top: -9px; right: -9px; width: 26px; height: 26px;
  min-height: 26px; padding: 0; font-size: 13px; border-radius: 50%;
  background: var(--bump); color: #fff; border: 2px solid #fff; line-height: 1;
}
.block-repeat {
  border: 3px solid var(--g-light); border-radius: 14px; padding: 8px;
  background: linear-gradient(180deg, var(--g-pale), #fff);
  cursor: pointer;
}
.block-repeat.selected { border-color: var(--g); border-style: solid; box-shadow: 0 0 0 3px rgba(87,179,73,0.25); }
.rep-sel-hint { font-size: 12px; color: var(--muted); font-weight: 700; }
.repeat-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.repeat-badge {
  background: var(--g); color: #fff; border-radius: 8px; padding: 4px 10px;
  font-weight: 800; font-size: 14px; font-family: "SF Mono", ui-monospace, monospace;
}
.rep-btn { min-height: 40px; min-width: 40px; padding: 0 10px; background: #fff; border: 2px solid var(--g-pale2); }
.rep-num { font-weight: 800; min-width: 34px; text-align: center; }
.chip-x-head { position: static; margin-left: 4px; }
.repeat-body { display: flex; gap: 6px; flex-wrap: wrap; padding: 4px; background: rgba(255,255,255,0.7); border-radius: 10px; min-height: 52px; align-items: center; }

/* ---------- 覆盖层 ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(43, 58, 40, 0.45);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  padding: 20px; backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.result-card, .concept-card, .recap-card {
  background: #fff; border-radius: 24px; box-shadow: 0 10px 40px rgba(0,0,0,0.25);
  padding: 28px 26px; text-align: center; max-width: 520px; width: 100%;
  max-height: 86dvh; overflow-y: auto; animation: pop 0.25s ease;
}
.result-stars { font-size: 42px; letter-spacing: 4px; color: var(--coin); }
.result-stars .dim { color: #e3dcc2; }
.result-msg { font-size: 20px; font-weight: 800; margin: 10px 0 20px; }
.result-card .btn, .concept-card .btn { display: block; width: 100%; margin-top: 12px; }
.concept-tag { color: var(--muted); font-weight: 800; letter-spacing: 2px; }
.concept-name { color: var(--g-dark); margin: 8px 0 12px; font-size: 24px; }
.concept-body { font-size: 16.5px; line-height: 1.7; text-align: left; background: var(--g-pale); border-radius: 14px; padding: 14px 16px; }
.recap-card { text-align: left; }
.recap-title { font-size: 21px; font-weight: 800; color: var(--g-dark); text-align: center; margin-bottom: 14px; }
.recap-section { margin-bottom: 14px; }
.recap-h { font-weight: 800; font-size: 16px; margin-bottom: 6px; }
.recap-body { font-size: 15.5px; line-height: 1.65; background: var(--g-pale); border-radius: 12px; padding: 10px 14px; }
.recap-list { margin: 4px 0 0; padding-left: 22px; font-size: 15px; line-height: 1.7; }
.recap-btns { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.recap-btns .btn { flex: 1; }

/* ---------- 贪吃蛇 ---------- */
.snake-card {
  background: #fff; border-radius: 24px; padding: 22px; max-width: 480px; width: 100%;
  max-height: 92dvh; overflow-y: auto; box-shadow: 0 10px 40px rgba(0,0,0,0.25);
  text-align: center; animation: pop 0.25s ease;
}
.snake-title { font-size: 22px; font-weight: 800; color: var(--g-dark); }
.snake-sub { font-size: 14.5px; color: var(--muted); line-height: 1.6; margin: 8px 0 12px; }
.snake-cfg { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; margin-bottom: 10px; }
.snake-cfg-item { display: flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 700; }
.snake-cfg input[type="range"] { width: 110px; accent-color: var(--g); }
.snake-canvas { border-radius: 14px; max-width: 100%; height: auto; touch-action: none; }
.snake-score { font-size: 16px; font-weight: 800; margin: 10px 0; color: var(--ink); }
.snake-bar { display: flex; gap: 10px; justify-content: center; }

/* ---------- 响应式 ---------- */
/* iPad 横屏：世界|代码 并排 */
@media (orientation: landscape) and (min-width: 900px) {
  .stage { flex-wrap: nowrap; }
  .story-pane { width: 100%; }
}
/* iPad 竖屏窄：代码面板拉满 */
@media (max-width: 700px) {
  #app { padding: 10px; }
  .map-title { font-size: 27px; }
  .level-bar-title { font-size: 14px; }
  .stage { flex-direction: column; }
  .code-pane { min-width: 0; width: 100%; }
  .world-pane { margin: 0 auto; }
  .level-grid { grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 10px; }
  .lv-name { font-size: 14px; }
}
/* 横屏矮屏（iPad 分屏）：压缩故事区 */
@media (orientation: landscape) and (max-height: 620px) {
  .story { font-size: 14px; padding: 8px 12px; }
  .task { font-size: 14px; padding: 8px 12px; }
  .editor { min-height: 130px; }
}
