/* 四年级数学冒险岛 —— 共享样式（我的世界 × 宝可梦 主题） */
:root {
  --grass: #5cb943;
  --grass-dark: #3d8b2f;
  --dirt: #8b5a2b;
  --stone: #7d7d7d;
  --diamond: #4aedd9;
  --gold: #fcd535;
  --redstone: #e74c3c;
  --poke-red: #ee1515;
  --poke-yellow: #ffcb05;
  --poke-blue: #3b4cca;
  --ink: #2b2b2b;
  --paper: #fffdf5;
  --sky: #cfeeff;
  --ok: #2e9e44;
  --bad: #d9483b;
  --shadow: 0 4px 0 rgba(0,0,0,.18);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, var(--sky) 0%, #eef9e7 45%, var(--paper) 100%);
  background-attachment: fixed;
  line-height: 1.75;
  font-size: 17px;
}

.wrap { max-width: 900px; margin: 0 auto; padding: 16px 20px 80px; }

/* ---------- 顶部导航 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: var(--grass);
  border-bottom: 6px solid var(--grass-dark);
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.topbar .inner {
  max-width: 900px; margin: 0 auto; padding: 10px 20px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.topbar a {
  color: #fff; text-decoration: none; font-weight: 700;
  background: rgba(0,0,0,.22); padding: 6px 14px; border-radius: 8px;
  border: 2px solid rgba(255,255,255,.35);
}
.topbar a:hover { background: rgba(0,0,0,.4); }
.topbar .lesson-no {
  margin-left: auto; color: #fff; font-weight: 800;
  background: var(--poke-red); padding: 6px 14px; border-radius: 999px;
  border: 3px solid #fff; box-shadow: var(--shadow);
}

/* ---------- 标题区 ---------- */
.hero {
  margin: 24px 0; padding: 24px 28px;
  background: #fff; border: 4px solid var(--ink); border-radius: 16px;
  box-shadow: 8px 8px 0 rgba(0,0,0,.12);
  position: relative; overflow: hidden;
}
.hero::before {
  content: ""; position: absolute; right: -20px; top: -20px;
  width: 120px; height: 120px; border-radius: 50%;
  background: radial-gradient(circle at 50% 42%, var(--poke-red) 0 44%, var(--ink) 44% 56%, #fff 56% 100%);
  opacity: .12;
}
.hero h1 { margin: 0 0 8px; font-size: 30px; }
.hero .unit-badge {
  display: inline-block; background: var(--poke-blue); color: #fff;
  padding: 3px 12px; border-radius: 999px; font-size: 14px; font-weight: 700;
  margin-bottom: 8px;
}
.hero p { margin: 6px 0 0; color: #555; }

/* ---------- 学习目标 ---------- */
.goals {
  background: #fff8dc; border: 3px dashed var(--gold);
  border-radius: 12px; padding: 14px 20px; margin: 20px 0;
}
.goals h2 { margin: 0 0 6px; font-size: 19px; }
.goals ul { margin: 6px 0 2px; padding-left: 22px; }

/* ---------- 章节标题 ---------- */
h2.sec {
  margin: 40px 0 14px; font-size: 24px;
  padding: 8px 16px; color: #fff; border-radius: 10px;
  background: var(--grass); border: 3px solid var(--grass-dark);
  box-shadow: var(--shadow);
}
h2.sec.quiz-title { background: var(--poke-blue); border-color: #2a3798; }
h2.sec.hard-title { background: var(--redstone); border-color: #a93226; }

/* ---------- 知识卡片 ---------- */
.card {
  background: #fff; border: 3px solid var(--ink); border-radius: 14px;
  padding: 18px 22px; margin: 18px 0;
  box-shadow: 6px 6px 0 rgba(0,0,0,.1);
}
.card h3 { margin: 0 0 10px; font-size: 20px; }
.card h3 .tag {
  font-size: 13px; vertical-align: middle; margin-left: 8px;
  background: var(--diamond); color: #06503f; padding: 2px 10px; border-radius: 999px;
}

/* 主题故事框：我的世界 / 宝可梦 */
.story {
  border-radius: 12px; padding: 14px 18px; margin: 14px 0;
  border: 3px solid transparent;
}
.story.mc {
  background: #e8f5e0; border-color: var(--grass-dark);
}
.story.poke {
  background: #fff1f1; border-color: var(--poke-red);
}
.story .who { font-weight: 800; display: block; margin-bottom: 4px; }

/* 自动插图：JS 会按题干关键词插入真实图片 */
.with-illo {
  display: grid;
  align-items: center;
  gap: 14px;
}
.story-illo {
  grid-template-columns: 112px 1fr;
  overflow: hidden;
}
.story-illo.illo-right { grid-template-columns: 1fr 112px; }
.q-illo {
  grid-template-columns: 1fr 76px;
}
.hard-illo {
  grid-template-columns: 1fr 118px;
  overflow: hidden;
}
.illo-copy { min-width: 0; }
.card-illo {
  margin: 0;
  align-self: stretch;
  min-height: 88px;
  display: flex;
  align-items: end;
  justify-content: center;
  border-radius: 10px;
  background:
    linear-gradient(180deg, rgba(255,255,255,.82), rgba(255,255,255,.4)),
    repeating-linear-gradient(45deg, rgba(0,0,0,.06) 0 8px, transparent 8px 16px);
  border: 2px solid rgba(43,43,43,.18);
  pointer-events: none;
}
.card-illo img {
  display: block;
  width: 92px;
  max-height: 116px;
  object-fit: contain;
  filter: drop-shadow(0 5px 0 rgba(0,0,0,.16));
}
.q-illo .card-illo {
  align-self: start;
  min-height: 68px;
  border-radius: 999px;
  background: #fff9d6;
}
.q-illo .card-illo img {
  width: 64px;
  max-height: 72px;
}
.hard-illo .card-illo img {
  width: 112px;
  max-height: 150px;
}
.card-illo[data-illo="steve"],
.card-illo[data-illo="creeper"],
.card-illo[data-illo="villager"] { background-color: #e8f5e0; }
.card-illo[data-illo="pikachu"],
.card-illo[data-illo="raichu"],
.card-illo[data-illo="pokeball"] { background-color: #fff9d6; }
.card-illo[data-illo="charmander"],
.card-illo[data-illo="charizard"] { background-color: #fff1e2; }
.card-illo[data-illo="squirtle"] { background-color: #e5f5ff; }
.card-illo[data-illo="eevee"] { background-color: #fff0dd; }

/* 阵营 PK 小舞台 */
.pk-scene {
  margin: 28px 0 22px;
  background: #fff;
  border: 4px solid var(--ink);
  border-radius: 14px;
  box-shadow: 7px 7px 0 rgba(0,0,0,.12);
  overflow: hidden;
}
.pk-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 16px;
  color: #fff;
  background: linear-gradient(90deg, var(--poke-red), var(--poke-blue) 50%, var(--grass-dark));
  font-weight: 900;
}
.pk-head strong { font-size: 14px; font-weight: 800; }
.pk-arena {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 82px 1fr;
  min-height: 210px;
  background:
    linear-gradient(90deg, rgba(255,203,5,.22), rgba(74,237,217,.12) 50%, rgba(92,185,67,.22)),
    linear-gradient(180deg, #cfeeff 0 58%, #7fcf5e 58% 100%);
}
.pk-arena::after {
  content: "";
  position: absolute;
  left: 8%; right: 8%; bottom: 28px;
  height: 16px;
  border-radius: 50%;
  background: rgba(0,0,0,.16);
}
.pk-side {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: end;
  padding: 14px 12px 20px;
  min-width: 0;
}
.pk-side img {
  width: min(170px, 45vw);
  height: 134px;
  object-fit: contain;
  filter: drop-shadow(0 8px 0 rgba(0,0,0,.18));
  transition: transform .18s ease;
}
.pk-mc img { image-rendering: pixelated; }
.pk-side b {
  margin-top: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,.85);
  border: 2px solid rgba(43,43,43,.16);
}
.pk-hp {
  width: min(190px, 90%);
  height: 13px;
  margin-bottom: 10px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: #fff;
  overflow: hidden;
}
.pk-hp span {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, var(--ok), var(--poke-yellow));
  transition: width .2s ease;
}
.pk-vs {
  position: relative;
  z-index: 1;
  align-self: center;
  justify-self: center;
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  border: 4px solid #fff;
  font-weight: 1000;
  box-shadow: 0 5px 0 rgba(0,0,0,.22);
}
.pk-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  padding: 12px 14px;
  background: #f7f7f7;
  border-top: 3px solid rgba(43,43,43,.12);
}
.pk-controls button {
  font: inherit;
  font-weight: 900;
  cursor: pointer;
  border: 3px solid var(--ink);
  border-radius: 10px;
  padding: 8px 18px;
  color: var(--ink);
  background: #fff;
  box-shadow: 0 3px 0 rgba(0,0,0,.2);
}
.pk-controls button:first-child { background: #fff9d6; border-color: var(--poke-yellow); }
.pk-controls button:last-child { background: #e8f5e0; border-color: var(--grass-dark); }
.pk-controls button:hover { transform: translateY(-1px); }
.pk-log {
  margin: 0;
  padding: 10px 16px 14px;
  text-align: center;
  font-weight: 800;
}
.pk-scene.hit-mc .pk-mc img,
.pk-scene.hit-poke .pk-poke img { animation: pk-hit .24s ease; }
.pk-scene.hit-mc .pk-poke img,
.pk-scene.hit-poke .pk-mc img { animation: pk-attack .24s ease; }
@keyframes pk-hit {
  0%, 100% { transform: translateX(0); }
  35% { transform: translateX(8px) rotate(2deg); }
  70% { transform: translateX(-8px) rotate(-2deg); }
}
@keyframes pk-attack {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-8px) scale(1.06); }
}

/* 重点结论框 */
.key {
  background: linear-gradient(90deg, #fff9e0, #fff);
  border-left: 8px solid var(--gold);
  padding: 12px 18px; margin: 14px 0; border-radius: 8px;
  font-weight: 700;
}
.key .k-icon { margin-right: 6px; }

/* 例题框 */
.example {
  background: #f0f7ff; border: 2px solid var(--poke-blue);
  border-radius: 10px; padding: 12px 18px; margin: 14px 0;
}
.example .ex-title { font-weight: 800; color: var(--poke-blue); }

/* 竖式/算式等宽展示 */
.math-block {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  background: #263238; color: #aef79a;
  padding: 14px 20px; border-radius: 10px;
  white-space: pre; overflow-x: auto; margin: 12px 0;
  font-size: 16px; line-height: 1.6;
}

table.nice {
  border-collapse: collapse; margin: 12px 0; width: 100%;
  background: #fff; font-size: 16px;
}
table.nice th, table.nice td {
  border: 2px solid var(--ink); padding: 8px 12px; text-align: center;
}
table.nice th { background: var(--grass); color: #fff; }

/* ---------- 练习题 ---------- */
.q {
  background: #fff; border: 3px solid var(--poke-blue); border-radius: 14px;
  padding: 16px 20px; margin: 16px 0;
  box-shadow: 5px 5px 0 rgba(59,76,202,.15);
}
.q .q-text { margin: 0 0 12px; font-weight: 700; }
.q .q-opts { display: flex; flex-wrap: wrap; gap: 10px; }
.q .q-opts button {
  font: inherit; font-weight: 700; cursor: pointer;
  background: #f4f6ff; color: var(--ink);
  border: 3px solid var(--poke-blue); border-radius: 10px;
  padding: 8px 18px; min-width: 84px;
  transition: transform .08s;
}
.q .q-opts button:hover { transform: translateY(-2px); background: #e6ebff; }
.q.answered .q-opts button { cursor: default; opacity: .75; }
.q .q-opts button.right {
  background: var(--ok); border-color: #1d7030; color: #fff; opacity: 1 !important;
}
.q .q-opts button.wrong {
  background: var(--bad); border-color: #99271d; color: #fff; opacity: 1 !important;
}
.q .q-exp {
  display: none; margin-top: 12px; padding: 10px 14px;
  background: #fffbe6; border-left: 6px solid var(--gold); border-radius: 6px;
  font-size: 15.5px;
}
.q.answered .q-exp { display: block; }
.q .verdict { display: none; font-weight: 800; margin-top: 10px; }
.q.answered .verdict { display: block; }
.q .verdict.good { color: var(--ok); }
.q .verdict.bad { color: var(--bad); }

/* 计分板 */
.scoreboard {
  position: sticky; bottom: 12px; margin: 24px 0 8px;
  background: var(--ink); color: #fff; border-radius: 999px;
  padding: 10px 22px; font-weight: 800; text-align: center;
  border: 3px solid var(--gold); box-shadow: 0 4px 14px rgba(0,0,0,.3);
}
.scoreboard .emoji { margin-right: 6px; }

/* ---------- 高难度挑战 ---------- */
.hard {
  background: #fff; border: 3px solid var(--redstone); border-radius: 14px;
  padding: 18px 22px; margin: 20px 0;
  box-shadow: 6px 6px 0 rgba(231,76,60,.15);
}
.hard .hard-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  font-weight: 800; font-size: 18px; margin-bottom: 10px;
}
.hard .stars { color: var(--poke-yellow); text-shadow: 0 0 2px #b8860b; letter-spacing: 2px; }
.hard details {
  margin: 10px 0; border-radius: 10px; overflow: hidden;
  border: 2px solid #ddd;
}
.hard details summary {
  cursor: pointer; padding: 10px 16px; font-weight: 800;
  background: #f7f7f7; list-style: none;
}
.hard details summary::before { content: "▶ "; font-size: 12px; }
.hard details[open] summary::before { content: "▼ "; }
.hard details .body { padding: 12px 18px; background: #fff; }
.hard details.hint summary { background: #fff6d6; }
.hard details.solution summary { background: #e8f5e0; }
.hard .step { margin: 8px 0; padding-left: 10px; border-left: 4px solid var(--grass); }
.hard .final {
  margin-top: 12px; padding: 10px 14px; border-radius: 8px;
  background: #e8f5e0; border: 2px solid var(--grass-dark); font-weight: 800;
}

/* ---------- 页脚导航 ---------- */
.pager {
  display: flex; justify-content: space-between; gap: 12px;
  margin-top: 48px; flex-wrap: wrap;
}
.pager a {
  flex: 1; min-width: 200px; text-align: center;
  background: var(--grass); color: #fff; text-decoration: none;
  font-weight: 800; padding: 14px 18px; border-radius: 12px;
  border: 3px solid var(--grass-dark); box-shadow: var(--shadow);
}
.pager a.home { background: var(--poke-blue); border-color: #2a3798; }
.pager a:hover { filter: brightness(1.08); }
.pager a.disabled { pointer-events: none; opacity: .4; }

/* ---------- 首页目录 ---------- */
.unit-block { margin: 26px 0; }
.unit-block > h2 {
  font-size: 22px; margin: 0 0 12px;
  padding: 8px 16px; border-radius: 10px; color: #fff;
  background: var(--dirt); border: 3px solid #5f3d1c; box-shadow: var(--shadow);
}
.lesson-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.lesson-card {
  display: block; background: #fff; text-decoration: none; color: var(--ink);
  border: 3px solid var(--ink); border-radius: 14px; padding: 14px 18px;
  box-shadow: 5px 5px 0 rgba(0,0,0,.1); transition: transform .1s;
}
.lesson-card:hover { transform: translateY(-3px); border-color: var(--poke-red); }
.lesson-card .no {
  display: inline-block; background: var(--poke-red); color: #fff;
  font-weight: 800; border-radius: 8px; padding: 2px 10px; font-size: 14px;
  margin-bottom: 6px;
}
.lesson-card h3 { margin: 2px 0 6px; font-size: 18px; }
.lesson-card p { margin: 0; font-size: 14px; color: #666; }

.roadmap {
  background: #fff; border: 3px solid var(--ink); border-radius: 14px;
  padding: 18px 24px; margin: 18px 0; box-shadow: 6px 6px 0 rgba(0,0,0,.1);
}
.roadmap ol { padding-left: 24px; }

@media (max-width: 600px) {
  body { font-size: 16px; }
  .hero h1 { font-size: 24px; }
  .wrap { padding: 12px 14px 70px; }
  .story-illo,
  .story-illo.illo-right { grid-template-columns: 76px 1fr; }
  .story-illo.illo-right .card-illo { grid-column: 1; grid-row: 1; }
  .story-illo.illo-right .illo-copy { grid-column: 2; grid-row: 1; }
  .q-illo { grid-template-columns: 1fr 54px; }
  .hard-illo { grid-template-columns: 1fr 72px; }
  .card-illo { min-height: 64px; }
  .card-illo img { width: 66px; max-height: 82px; }
  .q-illo .card-illo { min-height: 50px; }
  .q-illo .card-illo img { width: 46px; max-height: 52px; }
  .hard-illo .card-illo img { width: 68px; max-height: 94px; }
  .pk-head { display: block; }
  .pk-head strong { display: block; margin-top: 2px; }
  .pk-arena {
    grid-template-columns: 1fr 48px 1fr;
    min-height: 178px;
  }
  .pk-vs {
    width: 46px;
    height: 46px;
    font-size: 14px;
    border-width: 3px;
  }
  .pk-side { padding: 12px 6px 18px; }
  .pk-side img {
    width: min(104px, 35vw);
    height: 96px;
  }
  .pk-hp { height: 11px; }
  .pk-controls button {
    flex: 1 1 150px;
    padding: 8px 10px;
  }
}
