/* 学习页：固定全屏，页面本身永远不滚动 */
html, body {
  margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none;
  background: #efe9dc; color: #222;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-tap-highlight-color: transparent; -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none; -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
button:disabled { opacity: .35; cursor: default; }

/* 宽屏（电脑）也按平板宽度排版，居中，两边留空 */
#app { position: fixed; top: 0; bottom: 0; left: 0; right: 0; margin: 0 auto; max-width: 820px; display: flex; flex-direction: column; background: #efe9dc; }
@media (min-width: 821px) {
  html, body { background: #e2dac8; }
  #app { box-shadow: 0 0 0 1px #d9cfb8, 0 0 30px rgba(80, 60, 20, .10); }
}

/* 顶栏 */
#top {
  flex: none; height: calc(44px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 6px 0;
  display: flex; align-items: center; gap: 4px; background: #fff; border-bottom: 1px solid #e4dccb;
}
#top .ib { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 10px; }
#top .ib:active { background: #f1ece0; }
/* 标题只在宽屏显示；手机上顶栏放栏目切换 */
#title { display: none; flex: 1; min-width: 0; font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#tabs { flex: 1; min-width: 0; display: flex; justify-content: center; gap: 2px; }
#tabs button { flex: 0 1 64px; height: 34px; border-radius: 17px; font-size: 15px; color: #6d6450; }
#tabs button.on { background: #d0352b; color: #fff; font-weight: 600; }
body:not([data-tab="lesson"]) #menu { visibility: hidden; }
@media (min-width: 760px) {
  /* 宽屏左边多了标题：栏目按钮改成绝对居中，不跟着标题往右挤 */
  #top { position: relative; }
  #title { display: block; max-width: calc(50% - 210px); }
  #tabs { position: absolute; left: 50%; top: env(safe-area-inset-top); bottom: 0; transform: translateX(-50%); align-items: center; }
  #tabs button { flex: none; width: 72px; }
  #menu { margin-left: auto; }
}

/* 栏目 */
#views { flex: 1; min-height: 0; position: relative; }
.view { position: absolute; inset: 0; display: none; }
.view.on { display: flex; flex-direction: column; }
#v-exam, #v-set { overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; scrollbar-width: none; -webkit-user-select: text; user-select: text; }
#v-exam::-webkit-scrollbar, #v-set::-webkit-scrollbar, .kr-words::-webkit-scrollbar { display: none; }
/* 单词：单元条和按钮固定，只滚单词列表 */
#v-word { overflow: hidden; }

/* 课本区 */
#stage { flex: 1; position: relative; overflow: hidden; touch-action: none; contain: strict; }
#pageinfo {
  position: absolute; right: 8px; top: 6px; z-index: 20; pointer-events: none;
  font-size: 12px; color: #fff; background: rgba(0,0,0,.38); padding: 2px 8px; border-radius: 10px; font-variant-numeric: tabular-nums;
}
.kr-book.nohl .kr-hl { visibility: hidden; }
/* 翻译在顶部 / 底部（APP：蓝底白字） */
.kr-zhbar {
  position: absolute; left: 50%; top: 28px; z-index: 21; max-width: calc(100% - 32px); transform: translateX(-50%);
  background: #2f6fde; color: #fff; font-weight: 700; font-size: 15px; line-height: 1.4; padding: 8px 12px; border-radius: 5px;
  pointer-events: none; opacity: 0; transition: opacity .12s; text-align: center;
}
.kr-zhbar.bottom { top: auto; bottom: 10px; }
.kr-zhbar.on { opacity: 1; }
@media (min-width: 760px) { .kr-zhbar { font-size: 20px; padding: 14px 20px; } }
.kr-book { position: absolute; perspective: 1800px; perspective-origin: 0 50%; }
.kr-book.slide { overflow: hidden; }
.kr-page {
  position: absolute; inset: 0; background: #fffdf7; transform-origin: 0 50%;
  backface-visibility: hidden; -webkit-backface-visibility: hidden; will-change: transform;
  box-shadow: 0 1px 6px rgba(80, 60, 20, .18);
}
.kr-page img { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; transition: opacity .15s; pointer-events: none; }
.kr-page.loaded img { opacity: 1; }
.kr-page:not(.loaded)::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 28px; height: 28px; margin: -14px;
  border: 3px solid #e3d9c3; border-top-color: #c9a85c; border-radius: 50%; animation: kr-spin .8s linear infinite;
}
@keyframes kr-spin { to { transform: rotate(360deg); } }
.kr-shade { position: absolute; inset: 0; opacity: 0; pointer-events: none; background: linear-gradient(to right, rgba(0,0,0,.05), rgba(0,0,0,.45)); }
.kr-lock { position: absolute; inset: 0; display: none; pointer-events: none; background: rgba(255,255,255,.35); }
.kr-page.locked .kr-lock { display: block; }
.kr-page.locked .kr-lock::after {
  content: "🔒 本单元需解锁"; position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  background: rgba(0,0,0,.62); color: #fff; font-size: 13px; padding: 6px 12px; border-radius: 16px; white-space: nowrap;
}

/* 点读框：4 条边 + 4 个圆角，只动 transform */
.kr-hl { position: absolute; left: 0; top: 0; width: 0; height: 0; z-index: 10; pointer-events: none; opacity: 0; transition: opacity .12s; }
.kr-hl.on { opacity: 1; }
.kr-hl > div { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
.kr-hl-t, .kr-hl-b { width: 1px; height: 2.5px; background: #e5262b; }
.kr-hl-l, .kr-hl-r { width: 2.5px; height: 1px; background: #e5262b; }
.kr-hl-tl, .kr-hl-tr, .kr-hl-bl, .kr-hl-br { width: 6px; height: 6px; border: 0 solid #e5262b; }
.kr-hl-tl { border-top-width: 2.5px; border-left-width: 2.5px; border-top-left-radius: 6px; }
.kr-hl-tr { border-top-width: 2.5px; border-right-width: 2.5px; border-top-right-radius: 6px; }
.kr-hl-bl { border-bottom-width: 2.5px; border-left-width: 2.5px; border-bottom-left-radius: 6px; }
.kr-hl-br { border-bottom-width: 2.5px; border-right-width: 2.5px; border-bottom-right-radius: 6px; }

/* 翻译框：样子照 APP TranslateView（白底、绿色 2 边框、圆角 5、粗体、左右留 5）；位置大小由 reader-dom.js 按 APP 规则算 */
.kr-zh {
  position: absolute; left: 0; top: 0; z-index: 11; pointer-events: none; opacity: 0; transition: opacity .12s;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  background: #fff; color: #000; font-weight: 700; line-height: 1.25; text-align: center;
  padding: 2px 5px; border: 2px solid #2fb344; border-radius: 5px; white-space: pre-wrap; word-break: break-word;
}
.kr-zh.on { opacity: 1; }
.kr-zh-meter { visibility: hidden; display: block; height: auto; padding: 0; border: 0; opacity: 0; transition: none; z-index: -1; }

/* 工具栏 */
#bar {
  flex: none; height: calc(56px + env(safe-area-inset-bottom)); padding: 0 6px env(safe-area-inset-bottom);
  display: flex; align-items: center; justify-content: space-around; background: #fff; border-top: 1px solid #e4dccb;
}
#bar button { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: #5b5240; min-width: 52px; padding: 4px 0; border-radius: 10px; }
#bar button:active { background: #f1ece0; }
#bar button.on { color: #d0352b; }
#bar svg, #top svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#play .i-pause { display: none; }
#play.on .i-play { display: none; }
#play.on .i-pause { display: inline; }

/* 加载中 / 出错 */
#loading { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; color: #8a7f68; font-size: 15px; z-index: 30; background: #efe9dc; }
#loading a { color: #c0392b; }

/* 目录抽屉 */
.mask { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.35); opacity: 0; visibility: hidden; transition: opacity .2s, visibility .2s; }
.mask.on { opacity: 1; visibility: visible; }
#drawer .panel {
  position: absolute; left: 0; top: 0; bottom: 0; width: min(82vw, 340px); background: #fff;
  padding: calc(env(safe-area-inset-top) + 10px) 0 env(safe-area-inset-bottom);
  transform: translateX(-100%); transition: transform .22s ease-out; display: flex; flex-direction: column;
}
#drawer.on .panel { transform: none; }
#drawer h3 { margin: 4px 16px 8px; font-size: 16px; }
#units { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; scrollbar-width: thin; }
#units li { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid #f1ece0; cursor: pointer; }
#units li:active { background: #faf6ec; }
#units b { flex: none; font-size: 14px; }
#units span { flex: 1; min-width: 0; font-size: 13px; color: #6d6450; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#units i { font-style: normal; font-size: 12px; color: #a39878; }

/* 锁定提示 */
#lockbox { display: grid; place-items: center; }
#lockbox .card { background: #fff; border-radius: 14px; padding: 20px 18px 16px; width: min(86vw, 320px); text-align: center; }
#lockbox p { margin: 0 0 16px; font-size: 15px; line-height: 1.5; }
#lockbox .btns { display: flex; gap: 10px; }
#lockbox .btns a, #lockbox .btns button { flex: 1; display: block; padding: 10px 0; border-radius: 10px; font-size: 15px; text-decoration: none; }
#buy { background: #f1ece0; color: #5b5240; }
#lockbox .btns a { background: #d0352b; color: #fff; }

/* 视频 */
#videobox { display: grid; place-items: center; background: rgba(0,0,0,.85); }
#video { max-width: 100%; max-height: 100%; }

/* 提示 */
#toast {
  position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 60; transform: translateX(-50%);
  background: rgba(0,0,0,.72); color: #fff; font-size: 14px; padding: 7px 14px; border-radius: 18px;
  opacity: 0; transition: opacity .2s; pointer-events: none; white-space: nowrap;
}
#toast.on { opacity: 1; }

/* 调试信息 */
#debug {
  display: none; position: fixed; right: 4px; top: calc(48px + env(safe-area-inset-top)); z-index: 70; pointer-events: none;
  background: rgba(0,0,0,.7); color: #7cff8a; font: 11px/1.45 ui-monospace, Menlo, monospace; padding: 4px 7px; border-radius: 6px; white-space: pre;
}

/* ---------- 单词 / 练习共用 ---------- */
.kr-empty { text-align: center; color: #8a7f68; padding: 40px 16px; font-size: 15px; list-style: none; }
.kr-chips { flex: none; display: flex; gap: 6px; padding: 10px 10px 4px; overflow-x: auto; scrollbar-width: none; position: sticky; top: 0; z-index: 2; background: #efe9dc; }
.kr-chips::-webkit-scrollbar { display: none; }
.kr-chip { flex: none; padding: 6px 12px; border-radius: 16px; background: #fff; font-size: 14px; color: #5b5240; white-space: nowrap; }
.kr-chip.on { background: #d0352b; color: #fff; }
.kr-chip.lock { color: #a39878; }
.kr-tbtn { padding: 7px 12px; border-radius: 9px; background: #fff; font-size: 14px; color: #5b5240; }
.kr-tbtn.main { background: #d0352b; color: #fff; }
.kr-tbtn.on { background: #f6d24a; color: #4a3b00; }
.kr-tbtn:active { filter: brightness(.94); }

/* 单词 */
.kr-wtools { flex: none; display: flex; gap: 8px; padding: 6px 10px 8px; }
.kr-words { flex: 1 1 auto; min-height: 0; list-style: none; margin: 0 10px calc(10px + env(safe-area-inset-bottom)); padding: 0; background: #fff; border-radius: 12px; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; scrollbar-width: none; -webkit-user-select: text; user-select: text; }
.kr-words li { display: flex; align-items: center; gap: 6px; padding: 10px 8px 10px 4px; border-bottom: 1px solid #f1ece0; cursor: pointer; transition: background .15s; }
.kr-words li:last-child { border-bottom: 0; }
.kr-words li.cur { background: #fff3d6; }
.kr-wtxt { flex: 1; min-width: 0; }
.kr-wen b { font-size: 19px; margin-right: 6px; }
.kr-wen i { font-style: normal; font-size: 13px; color: #a39878; }
.kr-wzh { font-size: 14px; color: #5b5240; margin-top: 2px; }
.kr-eye { flex: none; width: 34px; height: 34px; font-size: 16px; opacity: .55; display: none; }
.kr-words.m1 .kr-eye, .kr-words.m2 .kr-eye { display: block; }
.kr-words.m0 li { padding-left: 12px; }
.kr-words.m1 li:not(.peek) .kr-wzh { visibility: hidden; }
.kr-words.m2 li:not(.peek) .kr-wen { visibility: hidden; }
.kr-words li.peek .kr-eye { opacity: 1; }
.kr-star { flex: none; width: 36px; height: 36px; font-size: 20px; color: #c9bfa6; }
.kr-star.on { color: #f0a400; }

/* 练习 */
.kr-exmenu { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 16px 16px 24px; }
.kr-seg { display: inline-flex; background: #e4dccb; border-radius: 10px; padding: 3px; gap: 2px; }
.kr-seg button { padding: 6px 14px; border-radius: 8px; font-size: 14px; color: #5b5240; }
.kr-seg button.on { background: #fff; color: #d0352b; font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.kr-exbtn { width: min(80vw, 280px); padding: 12px 0; border-radius: 12px; background: #2f6fde; color: #fff; font-size: 17px; letter-spacing: 2px; }
.kr-exbtn.plain { background: #fff; color: #5b5240; }
.kr-exbtn:active { filter: brightness(.92); }
.kr-exnote { margin: 4px 0 0; font-size: 13px; color: #8a7f68; text-align: center; }
.kr-exhead { flex: none; display: flex; align-items: center; gap: 8px; padding: 10px; }
.kr-extitle { flex: 1; font-weight: 600; font-size: 15px; }
.kr-exprog { font-size: 13px; color: #8a7f68; font-variant-numeric: tabular-nums; }
.kr-excard { position: relative; margin: 0 10px; background: #fff; border-radius: 14px; padding: 18px 14px 14px; }
.kr-exq { font-size: 18px; font-weight: 600; line-height: 1.5; }
.kr-spk { display: flex; align-items: center; gap: 6px; margin: 14px auto 0; padding: 9px 20px 9px 16px; border-radius: 24px; background: #2f6fde; color: #fff; font-size: 16px; }
.kr-spk svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.kr-spk:active { filter: brightness(.9); }
.kr-opts { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-top: 16px; }
.kr-opt { width: min(100%, 360px); min-height: 50px; padding: 8px; border-radius: 12px; background: #f6f1e4; font-size: 17px; line-height: 1.3; word-break: break-word; border: 2px solid transparent; }
.kr-opt.right { background: #dff5e3; border-color: #2fb344; }
.kr-opt.wrong { background: #fde2e1; border-color: #e5262b; }
.kr-write { display: flex; gap: 8px; margin-top: 16px; }
.kr-write input { flex: 1; min-width: 0; font: inherit; font-size: 19px; padding: 9px 12px; border-radius: 10px; border: 2px solid #e4dccb; outline: none; }
.kr-write input:focus { border-color: #2f6fde; }
.kr-write input.right { border-color: #2fb344; }
.kr-write input.wrong { border-color: #e5262b; }
.kr-exfb { min-height: 24px; margin-top: 12px; font-size: 16px; font-weight: 600; text-align: center; }
.kr-exfb.right { color: #2a9d3f; }
.kr-exfb.wrong { color: #d0352b; }
.kr-exnav { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 10px 20px; }
.kr-exscore { font-size: 13px; color: #8a7f68; }
.kr-exdone { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 40px 16px; }
.kr-exbig { font-size: 56px; }
.kr-exdone p { margin: 0 0 8px; font-size: 17px; }

/* 设置 */
.kr-set { list-style: none; margin: 12px 10px; padding: 0; background: #fff; border-radius: 12px; }
.kr-set li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 12px; border-bottom: 1px solid #f1ece0; font-size: 15px; flex-wrap: wrap; }
.kr-set li:last-child { border-bottom: 0; }
.kr-switch button { width: 50px; height: 30px; border-radius: 15px; background: #d9d2c2; position: relative; transition: background .2s; }
.kr-switch button::after { content: ""; position: absolute; left: 3px; top: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform .2s; }
.kr-switch button.on { background: #2fb344; }
.kr-switch button.on::after { transform: translateX(20px); }
.kr-setfoot { margin: 8px 16px 24px; font-size: 13px; color: #8a7f68; text-align: center; }
.kr-setfoot a { color: #c0392b; }
.kr-excard, .kr-set, .kr-exmenu, .kr-exdone { flex: none; }
.kr-chips { position: static; }

@media (min-width: 821px) { #drawer .panel { left: calc(50% - 410px); } }
