:root {
  color-scheme: light;
  --page: #f7f6f3;
  --surface: #fff;
  --surface-soft: #fcfaf7;
  --ink: #282724;
  --muted: #827a71;
  --subtle: #a39a90;
  --line: #e9e5df;
  --line-soft: #f1ede8;
  --accent: #ce715f;
  --accent-dark: #ad5546;
  --accent-soft: #fff3ed;
  --honey: #f4dfaf;
  --green: #547460;
  --shadow: 0 8px 26px rgb(46 37 27 / 4%);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 82px; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--page);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible { outline: 3px solid rgb(206 113 95 / 35%); outline-offset: 2px; }
img { max-width: 100%; }

.app {
  width: min(100%, 1040px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px clamp(16px, 3vw, 32px) 64px;
}
.mast {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 5px 0 14px;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; font-size: 17px; font-weight: 650; letter-spacing: -.025em; }
.brand img { width: 42px; height: 42px; flex: none; object-fit: contain; }
.brand span { min-width: 0; }
.brand b { display: inline-block; padding: 4px 11px; border-radius: 999px; background: #fff0cf; font-weight: 650; }
.status { display: none; }

.nav {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  gap: 5px;
  overflow-x: auto;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  background: rgb(247 246 243 / 96%);
  backdrop-filter: blur(12px);
  scrollbar-width: none;
}
.nav::-webkit-scrollbar { display: none; }
.nav button {
  flex: none;
  padding: 9px 15px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 560;
  white-space: nowrap;
  cursor: pointer;
  transition: color .15s, background .15s;
}
.nav button:hover { background: #eeece7; color: var(--ink); }
.nav button.active { background: var(--honey); color: var(--ink); }
.tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 13px 0 11px;
}
.tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
  color: #5c554e;
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .15s;
}
.tool:hover { border-color: #d8cfc4; background: #fffdfa; }
.tool:active { transform: translateY(1px); }
.tool.primary { border-color: var(--accent); background: var(--accent); color: #fff; }
.tool.primary:hover { border-color: var(--accent-dark); background: var(--accent-dark); }
.toggle { display: inline-flex; align-items: center; gap: 7px; margin-left: auto; color: var(--muted); font-size: 13px; white-space: nowrap; }
.toggle input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
#content { padding-top: 9px; }
.section-head { display: flex; align-items: end; justify-content: space-between; gap: 12px; margin: 10px 0 17px; }
.section-head h2 { margin: 0; font-size: 23px; line-height: 1.25; letter-spacing: -.03em; font-weight: 680; }
.section-head p { margin: 5px 0 0; color: var(--muted); font-size: 14px; }
.hint { color: var(--subtle); font-size: 12px; white-space: nowrap; }
.hidden-answer { color: transparent !important; filter: blur(5px); user-select: none; }
.playing { outline: 2px solid rgb(206 113 95 / 38%) !important; outline-offset: 2px; }

/* Vocabulary overview and branch recall */
.branch-hero {
  display: flex;
  align-items: center;
  gap: 22px;
  min-height: 166px;
  margin: 8px 0 20px;
  padding: 16px 22px;
  border: 1px solid var(--line);
  border-radius: 19px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.branch-hero > img { width: 176px; height: 128px; flex: none; object-fit: contain; }
.branch-eyebrow { color: #9b806d; font-size: 10px; font-weight: 700; letter-spacing: .13em; }
.branch-hero-copy h2 { margin: 4px 0 4px; font-size: 27px; line-height: 1.2; letter-spacing: -.04em; font-weight: 700; }
.branch-hero-copy h2 small { margin-left: 7px; color: var(--muted); font-size: 15px; font-weight: 500; letter-spacing: 0; }
.branch-hero-copy p { margin: 0; color: var(--muted); font-size: 13px; }
.branch-progress-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 2px 7px; color: var(--muted); font-size: 13px; }
.branch-progress-top b { color: #554e47; font-weight: 600; }
.branch-progress { height: 4px; margin: 0 2px 13px; overflow: hidden; border-radius: 99px; background: #e9e4dd; }
.branch-progress i { display: block; height: 100%; border-radius: inherit; background: var(--accent); transition: width .25s ease; }
.branch-session {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 12px 0 3px;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface);
}
.branch-session span { color: var(--muted); font-size: 13px; }
.branch-stack { display: grid; gap: 13px; margin-top: 13px; }
.branch-panel {
  min-width: 0;
  padding: 17px 19px 14px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: var(--surface);
  box-shadow: var(--shadow);
  scroll-margin-top: 78px;
}
.branch-active { border-color: #d8a293; box-shadow: 0 0 0 2px rgb(206 113 95 / 8%), var(--shadow); }
.branch-panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.branch-title-lockup h3 { margin: 0; font-size: 17px; line-height: 1.3; font-weight: 670; letter-spacing: -.02em; }
.branch-title-lockup p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.branch-local-progress { color: var(--subtle); font-size: 12px; white-space: nowrap; }
.recall-instruction { margin: 10px 0 0; color: var(--muted); font-size: 12px; }
.recall-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 9px; margin: 14px 0 13px; }
.recall-card {
  display: flex;
  min-width: 0;
  min-height: 145px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 7px;
  border: 1px solid var(--line-soft);
  border-radius: 13px;
  background: var(--surface-soft);
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .15s;
}
.recall-card:hover { transform: translateY(-1px); border-color: #d8c8b9; background: #fff; }
.recall-card .icon-art { width: 100px; height: 92px; object-fit: contain; }
.recall-en { color: var(--ink); font-size: 13px; line-height: 1.25; font-weight: 620; text-align: center; }
.recall-card small { color: var(--muted); font-size: 11px; line-height: 1.3; text-align: center; }
.recall-card.answer-hidden { border-style: dashed; border-color: #dfd5c9; background: #fcfaf6; }
.recall-card.answer-hidden .icon-art { width: 106px; height: 104px; }
.branch-future .recall-card:disabled { opacity: .7; cursor: default; }
.branch-future .recall-card:disabled:hover { transform: none; border-color: var(--line-soft); }
.branch-panel-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 11px; border-top: 1px solid var(--line-soft); color: var(--muted); font-size: 12px; }
.branch-next { min-height: 38px; padding: 8px 15px; border: 0; border-radius: 10px; background: var(--accent); color: #fff; font-size: 13px; font-weight: 600; cursor: pointer; transition: background .15s, transform .15s; }
.branch-next:hover { background: var(--accent-dark); }
.branch-next:active { transform: translateY(1px); }
.branch-next.complete { background: var(--green); }

/* Parent and child Q&A */
.qa-list { display: grid; gap: 11px; }
.qa {
  display: grid;
  grid-template-columns: minmax(0, .76fr) minmax(0, 1.24fr);
  align-items: start;
  gap: 13px;
  padding: 15px 16px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.qa-question { min-width: 0; padding: 4px 14px 4px 0; border-right: 1px solid var(--line-soft); }
.qa-question-text { display: block; padding: 0; border: 0; background: transparent; color: var(--ink); font-size: 20px; line-height: 1.32; font-weight: 650; letter-spacing: -.02em; text-align: left; cursor: pointer; }
.qa-question-text:hover { color: var(--accent-dark); }
.zhline { margin-top: 5px; color: var(--muted); font-size: 12px; }
.qa-answer-list { display: grid; gap: 3px; }
.qa-answer-row { display: grid; grid-template-columns: minmax(0, 1fr) 88px; align-items: center; gap: 7px; min-height: 70px; padding: 2px 0; border-bottom: 1px solid var(--line-soft); }
.qa-answer-row:last-child { border-bottom: 0; }
.qa-answer-copy { min-width: 0; }
.answer { position: relative; display: block; width: 100%; padding: 2px 0 2px 15px; border: 0; background: transparent; color: var(--ink); font-size: 16px; line-height: 1.4; text-align: left; cursor: pointer; }
.answer::before { position: absolute; top: .62em; left: 1px; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); content: ""; }
.answer:hover { color: var(--accent-dark); }
.answer-zh { margin: 1px 0 0 15px; color: var(--muted); font-size: 12px; line-height: 1.35; }
.qa-answer-icon { display: grid; width: 82px; height: 72px; place-items: center; padding: 2px; border: 0; border-radius: 10px; background: transparent; cursor: pointer; transition: background .15s; }
.qa-answer-icon:hover { background: var(--accent-soft); }
.qa-answer-icon .icon-art { width: 100%; height: 100%; object-fit: contain; }

/* Story: one scene illustration followed by individually playable lines */
.story-list { display: grid; gap: 13px; }
.story-read-status { margin: -4px 0 10px; color: var(--muted); font-size: 12px; text-align: right; }
.story {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 13px 17px 15px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.story-illustration { display: flex; min-height: 180px; align-items: center; justify-content: center; padding: 0 0 11px; border-bottom: 1px solid var(--line-soft); }
.story-art { width: min(100%, 280px); aspect-ratio: 1; margin: 0 auto; background-size: 300% 200%; background-repeat: no-repeat; }
.story-copy { display: grid; gap: 5px; width: 100%; padding-top: 9px; }
.story-line { min-width: 0; }
.story-sentence { display: block; width: 100%; padding: 5px 7px; border: 0; border-radius: 8px; background: transparent; color: var(--ink); font-size: 15px; line-height: 1.5; font-weight: 560; text-align: left; cursor: pointer; transition: background .15s, color .15s; }
.story-sentence:hover, .story-sentence.playing { background: var(--accent-soft); color: var(--accent-dark); }
.story-sentence.reading { background: #fff0e8; color: var(--accent-dark); box-shadow: inset 3px 0 var(--accent); }
.story .translation { padding: 0 7px 3px; color: var(--muted); font-size: 12px; line-height: 1.45; }

/* Vocabulary sticker cards */
.flash-grid { display: grid; width: 100%; grid-template-columns: repeat(auto-fit, minmax(min(100%, 168px), 1fr)); gap: 10px; min-width: 0; }
.flash {
  position: relative;
  display: flex;
  width: 100%;
  min-width: 0;
  height: 190px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  overflow: hidden;
  padding: 9px 8px 7px;
  border: 1px dashed #b9afa4;
  border-radius: 15px;
  background: var(--surface);
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .15s;
}
.flash::before { position: absolute; inset: 5px; border: 1px dotted #e1d8ce; border-radius: 11px; content: ""; pointer-events: none; }
.flash:hover { transform: translateY(-1px); border-color: var(--accent); background: #fffdfa; }
.flash > .icon-art { width: 100%; height: 128px; min-height: 0; flex: 1; object-fit: contain; }
.flash-label { display: flex; max-width: 100%; flex-direction: column; align-items: center; gap: 2px; }
.flash b { display: inline-block; max-width: 100%; padding: 2px 10px; border-radius: 999px; background: #fff0ce; font-size: 14px; line-height: 1.35; font-weight: 620; text-align: center; overflow-wrap: anywhere; }
.flash small { color: var(--muted); font-size: 11px; line-height: 1.3; }
.flash.playing { outline: 2px solid rgb(206 113 95 / 38%); outline-offset: 2px; }

/* Lightweight vocabulary check */
.quiz { width: min(100%, 620px); margin: 12px auto; padding: 22px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); }
.quiz-top { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 12px; }
.quiz-picture { display: grid; width: 180px; height: 155px; place-items: center; margin: 12px auto 0; padding: 0; border: 0; border-radius: 14px; background: var(--surface-soft); cursor: pointer; }
.quiz-picture .icon-art { width: 150px; height: 135px; object-fit: contain; }
.quiz-prompt { margin: 5px 0 16px; color: #514a43; font-size: 15px; font-weight: 560; text-align: center; }
.options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.option { min-height: 46px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 11px; background: #fff; font-size: 14px; font-weight: 560; text-align: left; cursor: pointer; transition: border-color .15s, background .15s; }
.option:hover:not(:disabled) { border-color: #d6b4a4; background: #fffaf5; }
.option.correct { border-color: #9ab49f; background: #f1f7f1; }
.option.wrong { border-color: #d9a298; background: #fff2ef; }
.option:disabled { cursor: default; }
.feedback { min-height: 28px; padding: 10px 0 3px; color: var(--green); font-size: 13px; text-align: center; }
.quiz-actions, .quiz-review { display: flex; justify-content: space-between; gap: 8px; }
.quiz-review { justify-content: center; gap: 8px; margin: 12px auto; }

/* Optional printable reference sheets */
.reference-view { width: min(100%, 690px); margin: 0 auto; }
.reference-image { display: block; width: 100%; height: auto; background: #fff; }
.reference-caption { display: flex; justify-content: space-between; gap: 12px; padding: 9px 2px 0; color: var(--muted); font-size: 12px; }
.reference-controls { display: flex; justify-content: center; gap: 8px; overflow-x: auto; padding: 9px 0; }
.reference-controls button { padding: 7px 13px; border: 1px solid var(--line); border-radius: 999px; background: #fff; font-size: 12px; white-space: nowrap; cursor: pointer; }
.reference-controls button.active { border-color: var(--honey); background: #fff7e6; }

@media (max-width: 760px) {
  html { scroll-padding-top: 70px; }
  .app { padding: 8px 14px 38px; }
  .mast { padding-bottom: 10px; }
  .brand { gap: 8px; font-size: 14px; }
  .brand img { width: 36px; height: 36px; }
  .brand b { padding: 3px 8px; }
  .nav { top: 0; gap: 2px; padding: 6px 0; }
  .nav button { padding: 8px 12px; font-size: 13px; }
  .tools { gap: 6px; padding: 10px 0 8px; }
  .tool { min-height: 35px; padding: 7px 10px; font-size: 12px; }
  .toggle { margin-left: auto; font-size: 12px; }
  #content { padding-top: 7px; }
  .section-head { align-items: flex-start; margin: 8px 0 12px; }
  .section-head h2 { font-size: 20px; }
  .section-head p { font-size: 13px; }
  .section-head .hint { display: none; }
  .branch-hero { min-height: 120px; gap: 12px; margin: 5px 0 15px; padding: 10px 12px; border-radius: 15px; }
  .branch-hero > img { width: 112px; height: 90px; }
  .branch-eyebrow { font-size: 9px; }
  .branch-hero-copy h2 { font-size: 21px; }
  .branch-hero-copy h2 small { display: block; margin: 1px 0 0; font-size: 13px; }
  .branch-hero-copy p { font-size: 11px; }
  .branch-progress-top { font-size: 12px; }
  .branch-session { align-items: center; margin-top: 10px; padding: 9px 10px; }
  .branch-session span { font-size: 11px; }
  .branch-stack { gap: 10px; margin-top: 10px; }
  .branch-panel { padding: 14px 12px 11px; border-radius: 15px; scroll-margin-top: 70px; }
  .branch-title-lockup h3 { font-size: 15px; }
  .branch-title-lockup p, .branch-local-progress { font-size: 11px; }
  .recall-instruction { font-size: 11px; }
  .recall-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin: 11px 0; }
  .recall-card { min-height: 120px; padding: 7px 4px; border-radius: 11px; }
  .recall-card .icon-art { width: 78px; height: 72px; }
  .recall-card.answer-hidden .icon-art { width: 84px; height: 82px; }
  .recall-en { font-size: 11px; }
  .recall-card small { font-size: 10px; }
  .branch-panel-footer { align-items: center; gap: 8px; padding-top: 9px; font-size: 11px; }
  .branch-next { min-height: 35px; padding: 7px 10px; font-size: 12px; }
  .qa-list, .story-list { gap: 9px; }
  .qa { grid-template-columns: minmax(0, 1fr); gap: 7px; padding: 13px 12px; border-radius: 15px; }
  .qa-question { padding: 0 0 7px; border: 0; border-bottom: 1px solid var(--line-soft); }
  .qa-question-text { font-size: 18px; }
  .qa-answer-row { grid-template-columns: minmax(0, 1fr) 66px; min-height: 63px; gap: 6px; }
  .answer { font-size: 15px; }
  .answer-zh { font-size: 11px; }
  .qa-answer-icon { width: 62px; height: 57px; }
  .story { padding: 10px 12px 12px; border-radius: 15px; }
  .story-illustration { min-height: 135px; padding-bottom: 8px; }
  .story-art { width: min(100%, 238px); }
  .story-copy { gap: 4px; padding-top: 7px; }
  .story-sentence { padding: 5px; font-size: 14px; }
  .story-read-status { margin: -3px 1px 8px; font-size: 11px; }
  .story .translation { font-size: 11px; }
  .flash-grid { grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr)); gap: 8px; }
  .flash { height: 174px; padding: 7px 6px; border-radius: 13px; }
  .flash > .icon-art { height: 115px; }
  .flash b { font-size: 13px; }
  .flash small { font-size: 10px; }
  .quiz { margin: 8px auto; padding: 17px 13px; border-radius: 15px; }
  .quiz-picture { width: 150px; height: 130px; }
  .quiz-picture .icon-art { width: 126px; height: 112px; }
  .option { min-height: 43px; padding: 9px; font-size: 12px; }
}
@media (max-width: 390px) {
  .app { padding-right: 10px; padding-left: 10px; }
  .brand { font-size: 12px; }
  .brand img { width: 32px; height: 32px; }
  .nav button { padding: 7px 10px; font-size: 12px; }
  .toggle { font-size: 11px; }
  .flash-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .recall-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media print {
  body { background: #fff; }
  .mast, .nav, .tools, .section-head, .branch-session { display: none !important; }
  .app { width: 100%; padding: 0; }
  .reference-image { box-shadow: none; }
}
.tool:disabled { opacity: .45; cursor: not-allowed; }
.quiz-complete { width: min(100%, 500px); margin: 14px auto; padding: 28px 20px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); text-align: center; }
.quiz-check { display: grid; width: 50px; height: 50px; place-items: center; margin: 0 auto 10px; border-radius: 50%; background: #edf4ed; color: var(--green); font-size: 24px; }
.quiz-complete h3 { margin: 0; font-size: 20px; }
.quiz-complete p { margin: 8px 0 18px; color: var(--muted); }
.quiz-complete p b { color: var(--ink); font-size: 24px; }
.quiz-complete .quiz-actions { justify-content: center; }
@media (max-width: 760px) { .quiz-complete { padding: 22px 14px; border-radius: 15px; } }

.theme-loading,.theme-error{max-width:620px;margin:34px auto;padding:30px 24px;border:1px solid var(--line);border-radius:22px;background:#fff;color:var(--muted);text-align:center}
.theme-loading{min-height:120px;display:grid;place-items:center;font-size:14px}
.theme-error h1{margin:0;color:var(--ink);font-size:23px}
.theme-error p{margin:10px 0 20px;line-height:1.65}
.theme-error a{display:inline-flex;min-height:46px;align-items:center;padding:0 20px;border-radius:999px;background:var(--accent);color:#fff;text-decoration:none;font-weight:650}
@media(max-width:600px){.theme-loading,.theme-error{margin:22px auto;padding:24px 17px;border-radius:18px}}
