:root {
  --bg: #f6ecd9;
  --paper: #fffaf0;
  --ink: #3b2a1a;
  --muted: #8a735a;
  --accent: #e8762c;
  --ok: #3f9a5a;
  --bad: #d2483c;
  --line: #e3d2b3;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  font-size: 17px;
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
.page { max-width: 720px; margin: 0 auto; padding: 16px 16px 48px; }

/* ---------- home ---------- */
.hero { text-align: center; padding: 20px 0 8px; }
.hero h1 { margin: 0; font-size: 40px; letter-spacing: 8px; font-family: "Kaiti SC", "STKaiti", "KaiTi", serif; }
.hero p { margin: 2px 0 14px; color: var(--muted); }
.stats { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.stats span, .chip {
  background: var(--paper); border: 1px solid var(--line); border-radius: 999px; padding: 4px 14px; font-size: 15px;
}
.chip:disabled { opacity: .5; cursor: default; }
.shelf { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 12px; }
.mini-card { background: #fff3d6; border: 1px solid #e8c97a; border-radius: 10px; padding: 4px 10px; font-size: 14px; }
.mini-card span { margin-right: 4px; }

.unit { margin-top: 26px; border-left: 5px solid var(--u); padding-left: 14px; }
.unit h2 { margin: 0; font-size: 22px; }
.unit h2 small { display: block; font-size: 13px; color: var(--u); font-weight: 600; letter-spacing: 2px; }
.unit .sub { margin: 0 0 10px; color: var(--muted); font-size: 14px; }
.nodes { display: grid; gap: 8px; }
.node {
  display: grid; grid-template-columns: 40px 1fr auto; align-items: center; gap: 10px; text-align: left;
  background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px;
  transition: transform .12s, box-shadow .12s;
}
.node:not(.locked):hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(90, 60, 20, .15); }
.node .num {
  width: 36px; height: 36px; border-radius: 50%; background: var(--u); color: #fff;
  display: grid; place-items: center; font-weight: 700;
}
.node .st { font-size: 14px; color: var(--accent); font-weight: 600; white-space: nowrap; }
.node.locked { opacity: .55; cursor: default; }
.node.locked .st { color: var(--muted); font-weight: 400; }

/* ---------- lesson frame ---------- */
.topbar { display: grid; grid-template-columns: auto 1fr auto; gap: 6px 12px; align-items: center; margin-bottom: 14px; }
.back { color: var(--muted); padding: 4px 8px 4px 0; }
.ttl { font-weight: 700; }
.link { color: var(--muted); font-size: 14px; text-decoration: underline; }
.steps { grid-column: 1 / -1; display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.step {
  flex: 1 0 auto; font-size: 13px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--paper); white-space: nowrap;
}
.step.past { background: #f1dfb9; }
.step.cur { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.step:disabled { opacity: .45; cursor: default; }
.banner { background: #e4f4e6; border: 1px solid #b5dcbc; border-radius: 10px; padding: 6px 12px; font-size: 14px; margin-bottom: 12px; }

/* ---------- score + wrong-answer book ---------- */
.total { font-size: 20px; margin-top: 4px; }
.total b { font-size: 56px; line-height: 1; color: var(--accent); }
.total em { font-style: normal; background: var(--ink); color: #fff; border-radius: 999px; padding: 2px 12px; font-size: 15px; margin-left: 6px; vertical-align: middle; }
.parts { min-width: 0; max-width: 420px; margin: 10px auto; }
.parts td { border: 0; padding: 4px 6px; font-size: 14px; vertical-align: middle; white-space: nowrap; }
.parts td:nth-child(2) { width: 45%; }
.meter { height: 10px; background: var(--line); border-radius: 10px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--ok); }
.book h4 { margin: 18px 0 8px; color: var(--muted); font-size: 15px; }
.book .top { margin: 0 0 4px; }
.wq { background: var(--paper); border: 1px solid var(--line); border-left: 4px solid var(--bad); border-radius: 10px; padding: 10px 14px; margin-bottom: 8px; }
.wq .q { font-weight: 700; }
.wq .a { color: var(--ok); font-weight: 600; }
.wq .e { font-size: 14px; }
.wq .meta { font-size: 13px; color: var(--muted); margin-top: 4px; }
.empty { text-align: center; padding: 40px 0; color: var(--muted); }

.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 16px; }
.row.end { justify-content: flex-end; }
.primary { background: var(--accent); color: #fff; font-weight: 700; padding: 10px 22px; border-radius: 999px; box-shadow: 0 3px 0 #b85a1c; }
.primary:active { transform: translateY(2px); box-shadow: 0 1px 0 #b85a1c; }
.ghost { border: 1px solid var(--line); background: var(--paper); padding: 9px 16px; border-radius: 999px; }
.ghost:disabled { opacity: .4; cursor: default; }
.story .row { flex-wrap: wrap; }
h3 { margin: 0 0 6px; font-size: 21px; }
.hint { margin: 0 0 14px; color: var(--muted); font-size: 15px; }
.msg { min-height: 1.6em; text-align: center; font-weight: 600; margin: 12px 0 0; }

/* ---------- story ---------- */
.scene { position: relative; border-radius: 18px; overflow: hidden; border: 3px solid var(--ink); background: #000; }
.scene svg { display: block; width: 100%; height: auto; }
.scene .era, .scene .place {
  position: absolute; top: 10px; padding: 2px 12px; border-radius: 999px; font-size: 14px; font-weight: 700;
}
.scene .era { left: 10px; background: var(--accent); color: #fff; }
.scene .place { right: 10px; background: rgba(255, 250, 240, .9); }
.narr { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 12px 16px; margin: 14px 0 10px; }
.keys { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.keys li { background: #fff3d6; border-left: 4px solid var(--accent); border-radius: 6px; padding: 5px 12px; font-size: 15px; font-weight: 600; }
.dots { color: var(--muted); font-size: 14px; }

.lbl { font-size: 13px; font-weight: 700; fill: #3b2a1a; paint-order: stroke; stroke: #fffaf0; stroke-width: 3px; font-family: inherit; }
.lbl.light { fill: #fff; stroke: #2a2a2a; }
.pulse, .flicker, .flash, .swing, .rise, .drill, .pop, .bob, .spin, .mouth { transform-box: fill-box; transform-origin: center; }
.bob { animation: bob 1.6s ease-in-out infinite; }
.spin { animation: spin 6s linear infinite; }
.talking .kid .mouth { animation: talk .22s ease-in-out infinite alternate; }
@keyframes bob { 50% { transform: translateY(-3px); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes talk { from { transform: scaleY(.4); } to { transform: scaleY(2.2); } }
.pulse { animation: pulse 2.4s ease-in-out infinite; }
.flicker { animation: flicker .5s ease-in-out infinite alternate; transform-origin: bottom center !important; }
.flash { animation: flash 1.6s steps(1) infinite; }
.swing { animation: swing .7s ease-in-out infinite alternate; transform-origin: 0% 0% !important; }
.rise { animation: rise 2.4s ease-out infinite; }
.drill { animation: drill .35s linear infinite alternate; }
.pop { opacity: 0; animation: pop .5s ease-out forwards; }
.pop.d1 { animation-delay: .8s; }
.pop.d2 { animation-delay: 1.8s; }
.pop.d3 { animation-delay: 2.8s; }
@keyframes pulse { 50% { transform: scale(1.12); } }
@keyframes flicker { from { transform: scale(.92, 1.06); } to { transform: scale(1.08, .94); } }
@keyframes flash { 0%, 100% { opacity: 0; } 10%, 22% { opacity: 1; } 16% { opacity: .2; } 30% { opacity: 0; } }
@keyframes swing { from { transform: rotate(-35deg); } to { transform: rotate(25deg); } }
@keyframes rise { 0% { transform: translateY(26px); opacity: 0; } 40%, 100% { transform: translateY(-34px); opacity: 1; } }
@keyframes drill { from { transform: scaleX(.5); } to { transform: scaleX(1.4); } }
@keyframes pop { from { opacity: 0; transform: scale(.4); } to { opacity: 1; transform: scale(1); } }

/* ---------- summary ---------- */
.tblwrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); }
table { border-collapse: collapse; width: 100%; min-width: 520px; font-size: 15px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
thead th { background: #f1dfb9; }
tbody th { white-space: nowrap; color: var(--accent); }
tbody tr:last-child > * { border-bottom: 0; }
.tips { margin: 14px 0 0; padding-left: 0; list-style: none; display: grid; gap: 6px; }
.tips li::before { content: "💡 "; }
.tips li { font-weight: 600; font-size: 15px; }

/* ---------- timeline game ---------- */
.axis { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 8px; position: relative; padding-bottom: 6px; }
.slot { display: grid; gap: 6px; justify-items: center; }
.slot .drop {
  width: 100%; min-height: 76px; display: grid; place-items: center; border: 2px dashed var(--muted); border-radius: 14px;
  background: var(--paper); font-size: 18px; font-weight: 700; padding: 4px;
}
.slot b { font-size: 14px; border-top: 4px solid var(--ink); width: 100%; padding-top: 4px; text-align: center; }
.slot.ok .drop { border: 2px solid var(--ok); background: #e4f4e6; }
.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.tray { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 22px; min-height: 64px; }
.tcard { background: #fff; border: 2px solid var(--ink); border-radius: 14px; padding: 10px 16px; font-weight: 700; box-shadow: 0 3px 0 var(--ink); }
.tcard span { margin-right: 6px; }
.tcard.sel { background: #ffe2c2; border-color: var(--accent); box-shadow: 0 3px 0 var(--accent); transform: translateY(-4px); }

/* ---------- sort game ---------- */
.hud { display: flex; justify-content: space-between; font-weight: 700; font-size: 15px; }
.hud .combo { color: var(--accent); }
.timer { height: 8px; background: var(--line); border-radius: 8px; overflow: hidden; margin: 6px 0 14px; }
.timer i { display: block; height: 100%; width: 100%; background: var(--ok); transition: width .1s linear; }
.clue {
  background: #2e2318; color: #fff; border-radius: 18px; min-height: 150px; display: grid; place-items: center; align-content: center;
  text-align: center; padding: 16px; font-size: 20px; font-weight: 700;
}
.clue .big { display: block; font-size: 52px; line-height: 1.2; }
.clue.in { animation: pop .3s ease-out; }
.buckets { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin-top: 14px; }

/* ---------- match game ---------- */
.match { display: grid; grid-template-columns: 2fr 3fr; gap: 14px; }
.match .col { display: grid; gap: 8px; align-content: start; }
.mcard { background: #fff; border: 2px solid var(--ink); border-radius: 12px; padding: 10px 8px; font-weight: 700; box-shadow: 0 3px 0 var(--ink); min-height: 48px; }
.mcard.sel { background: #ffe2c2; border-color: var(--accent); box-shadow: 0 3px 0 var(--accent); }
.mcard.ok { background: #e4f4e6; border-color: var(--ok); box-shadow: none; color: #2c6b3e; cursor: default; }
.bucket { background: #fff; border: 2px solid var(--ink); border-radius: 14px; padding: 14px 4px; font-weight: 700; box-shadow: 0 3px 0 var(--ink); }
.bucket.right, .opt.right { background: #e4f4e6; border-color: var(--ok); box-shadow: 0 3px 0 var(--ok); }
.bucket.wrong, .opt.wrong { background: #fbe3e0; border-color: var(--bad); box-shadow: 0 3px 0 var(--bad); }

/* ---------- quiz ---------- */
.qn { color: var(--muted); font-size: 14px; }
.opts { display: grid; gap: 10px; margin-top: 12px; }
.opt {
  display: grid; grid-template-columns: 32px 1fr; gap: 10px; align-items: center; text-align: left;
  background: #fff; border: 2px solid var(--line); border-radius: 14px; padding: 10px 14px; box-shadow: 0 3px 0 var(--line);
}
.opt i { font-style: normal; font-weight: 700; width: 30px; height: 30px; border-radius: 50%; background: var(--bg); display: grid; place-items: center; }
.exp { margin-top: 14px; background: #fff3d6; border-radius: 12px; padding: 10px 14px; font-size: 15px; }

/* ---------- result ---------- */
.result { text-align: center; padding-top: 10px; }
.stars { font-size: 46px; }
.stars span { filter: grayscale(1); opacity: .3; }
.card { margin: 16px auto; max-width: 320px; background: linear-gradient(160deg, #fff7df, #f3d58f); border: 3px solid #b8892b; border-radius: 18px; padding: 16px; animation: pop .6s ease-out; }
.card .em { font-size: 64px; line-height: 1.2; }
.card p { margin: 6px 0 0; font-size: 14px; color: #6a4d1a; }
.note { color: var(--muted); font-size: 15px; }
.result .row.end { justify-content: center; }

@media (prefers-reduced-motion: reduce) {
  .scene svg * { animation: none !important; opacity: 1 !important; }
}

/* ---------- unit test ---------- */
.node.unit-test { border-style: dashed; border-color: var(--u); background: #fff; }
.node.unit-test .num { background: #fff; border: 2px solid var(--u); font-size: 1.05em; }
.node .t small { display: block; font-size: .78em; color: var(--muted); font-weight: 400; }
.material blockquote {
  margin: 8px 0 14px; padding: 12px 16px; background: var(--paper); border: 1px solid var(--line);
  border-left: 5px solid var(--accent); border-radius: 8px; white-space: pre-line; font-family: "Kaiti SC", "STKaiti", "KaiTi", serif; font-size: 1.05em;
}
.mq { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; margin-bottom: 10px; }
.mq .q { margin: 0 0 8px; font-weight: 700; }
.mq .a { margin: 0 0 4px; color: #2c6b3e; font-weight: 600; }
.mq .tip { margin: 0 0 8px; font-size: .88em; color: var(--muted); }
.rate { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: .88em; }
.rate button { border: 1px solid var(--line); background: var(--paper); border-radius: 999px; padding: 4px 12px; }
.rate button.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.mq[data-done] .rate button:not(.on) { opacity: .4; cursor: default; }

/* ---------- responsive type: text shrinks with the screen so phones are not oversized ---------- */
body { font-size: clamp(14px, 0.55vw + 12px, 17px); }
h3 { font-size: 1.25em; }
.hero h1 { font-size: clamp(28px, 7vw, 40px); letter-spacing: .18em; }
.unit h2 { font-size: 1.3em; }
.unit h2 small, .unit .sub, .node .st, .hint, .keys li, .tips li, .exp, .note, .qn, .dots, .wq .e, .wq .meta, .mini-card, .stats span, .chip, .link { font-size: .88em; }
table { font-size: .88em; }
.step { font-size: .78em; }
.clue { font-size: 1.2em; }
.slot .drop { font-size: 1.05em; }
.slot b, .scene .era, .scene .place { font-size: .82em; }
.total { font-size: 1.2em; }
.total b { font-size: clamp(40px, 11vw, 56px); }
.stars { font-size: clamp(34px, 10vw, 46px); }
.card .em { font-size: clamp(44px, 14vw, 64px); }
.clue .big { font-size: clamp(36px, 11vw, 52px); }

@media (max-width: 520px) {
  .page { padding: 10px 12px 36px; }
  .primary { padding: 8px 16px; }
  .ghost { padding: 7px 12px; }
  .narr { padding: 9px 12px; margin: 10px 0 8px; }
  .keys li { padding: 4px 10px; }
  .node { padding: 8px 10px; grid-template-columns: 32px 1fr auto; gap: 8px; }
  .node .num { width: 30px; height: 30px; }
  .opt { padding: 8px 10px; grid-template-columns: 28px 1fr; }
  .opt i { width: 26px; height: 26px; }
  .clue { min-height: 120px; padding: 12px; }
  .bucket, .tcard, .mcard { padding: 9px 6px; }
  .scene { border-width: 2px; border-radius: 14px; }
  .scene .era, .scene .place { top: 6px; padding: 1px 8px; }
  .story .row { gap: 6px; margin-top: 10px; }
  .match { gap: 8px; }
  th, td { padding: 6px 7px; }
}
