/* ============================================================
 * 灵词记 - style.css
 * 变量铁律：先定义后使用。变量集由用户规格给定（2026-10-25）。
 * 视觉基调：暗色暖底（近黑褐）+ 蓝色主色 + 金色灵砂/奖励色。
 * --accent 只用于主按钮与选中态；--gold 只用于灵砂/等级/奖励，不混用。
 * ============================================================ */
:root {
  --bg: #191713;        --bg2: #1E1B16;
  --card: #221F1A;      --card2: #2C2823;    --card3: #35302A;
  --line: #38332C;      --line2: #474038;
  --fg: #F2EEE7;        --dim: #A79D91;      --faint: #7E756A;
  --accent: #6B9BFF;    --accentFg: #10182B; --accentSoft: #1C2740;
  --gold: #D9B44A;      --goldSoft: rgba(217,180,74,.16);
  --ok: #38C97F;        --okSoft: #14301F;
  --bad: #FF6E85;       --badSoft: #3A1B22;
  --r-s: 10px;  --r: 16px;  --r-l: 20px;  --r-pill: 999px;
  --tap: 52px;
  --sh2: 0 2px 6px rgba(8,6,4,.30);
  --sh3: 0 4px 14px rgba(8,6,4,.34);
  --sh4: 0 8px 26px rgba(8,6,4,.40);
  --sh5: 0 16px 44px rgba(8,6,4,.50);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

/* ---- 布局铁律：#app 锁死视口，屏各自滚动 ---- */
#app {
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#screens {
  flex: 1;
  min-height: 0;
  position: relative;
}

/* 每个屏自带滚动容器；子元素禁收缩，防内容被裁 */
.screen {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  background: var(--bg);
}
.screen > * { flex-shrink: 0; }

/* 全局隐藏态：屏与覆盖层共用 */
.hide { display: none !important; }

/* ---- 屏内通用元素 ---- */
h2 { margin: 0; font-size: 20px; }
.screen > p { margin: 0; color: var(--dim); font-size: 14px; }

.card {
  background: var(--card2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 12px;
  box-shadow: var(--sh2);
}

/* ---- 返回按钮（非首页屏左上角，回上一屏，默认 home） ---- */
.backbtn {
  align-self: flex-start;
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-s);
  background: var(--card2);
  color: var(--fg);
  font-size: 14px;
  font-family: inherit;
}
.backbtn:active { background: var(--accentSoft); color: var(--accent); }

/* 首页立绘区：营地（game）唯一入口 */
.mascot-slot {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  min-height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--dim);
  font-size: 14px;
  box-shadow: var(--sh3);
}
.mascot-slot:active { border-color: var(--accent); }

/* battle 三个子区：P8-b 填充 */
.battle-zone {
  background: var(--card2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 12px;
  color: var(--dim);
  font-size: 14px;
}

/* ---- 全局覆盖层（浮于任何屏之上） ---- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(8, 6, 4, 0.55);
}
#toast {
  pointer-events: none;
  background: transparent;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 24px;
}
#toast-text {
  background: var(--card3);
  color: var(--fg);
  border: 1px solid var(--line2);
  border-radius: var(--r-pill);
  padding: 10px 18px;
  font-size: 14px;
  box-shadow: var(--sh4);
}

/* ============================================================
 * P4：学习卡 + 听音写词
 * ============================================================ */
.progress-line {
  color: var(--dim);
  font-size: 13px;
}

.word-big {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--fg);
}

.meta-row {
  color: var(--dim);
  font-size: 15px;
}
.ipa-wrap { font-family: Georgia, "Times New Roman", serif; }
.pos-tag {
  color: var(--accent);
  font-size: 13px;
}
.syl-tag {
  color: var(--faint);
  font-size: 14px;
  letter-spacing: 1px;
}

.zh-line {
  font-size: 17px;
  color: var(--fg);
}

.ex-block {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}
.ex-en {
  font-size: 15px;
  color: var(--fg);
}
.ex-en b { color: var(--accent); }
.dim-line {
  color: var(--dim);
  font-size: 13px;
}

.audio-row {
  display: flex;
  gap: 10px;
}
.audio-row .btn-ghost { flex: 1; }

.btn-primary {
  min-height: var(--tap);
  border: 0;
  border-radius: var(--r-s);
  background: var(--accent);
  color: var(--accentFg);
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
}
.btn-primary:active { filter: brightness(0.88); }

.btn-ghost {
  min-height: 44px;
  border: 1px solid var(--line2);
  border-radius: var(--r-s);
  background: var(--card3);
  color: var(--fg);
  font-size: 14px;
  font-family: inherit;
}
.btn-ghost:active { background: var(--accentSoft); }

.btn-col { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }

/* drill：拼写输入与判定 */
.type-box {
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  letter-spacing: 3px;
  color: var(--fg);
  background: var(--bg2);
  border: 1px solid var(--line2);
  border-radius: var(--r);
}
.verdict {
  font-size: 18px;
  font-weight: 700;
}
.verdict.ok { color: var(--ok); }
.verdict.bad { color: var(--bad); }
.answer-line {
  font-size: 15px;
  color: var(--fg);
}
.nearmiss {
  font-size: 13px;
  color: var(--gold);
  background: var(--goldSoft);
  border-radius: var(--r-s);
  padding: 6px 10px;
}

/* 软键盘 */
#kb {
  background: transparent;
  display: flex;
  align-items: flex-end;
  padding: 0 0 env(safe-area-inset-bottom, 0px) 0;
  pointer-events: none; /* P13 治本：inset:0 全屏层不拦截点击，页面按钮照常可点 */
}
#kb-pad {
  pointer-events: auto; /* 只有键盘面板本身可点 */
  width: 100%;
  background: var(--card);
  border-top: 1px solid var(--line2);
  padding: 8px 4px 10px 4px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.kb-row {
  display: flex;
  justify-content: center;
  gap: 6px;
}
.kb-key {
  flex: 1;
  max-width: 44px;
  height: 46px;
  border: 1px solid var(--line2);
  border-radius: var(--r-s);
  background: var(--card3);
  color: var(--fg);
  font-size: 17px;
  font-family: inherit;
}
.kb-key:active {
  background: var(--accentSoft);
  color: var(--accent);
  transform: scale(0.96);
}
.kb-wide { max-width: 88px; flex: 1.6; font-size: 14px; }
.kb-enter {
  background: var(--accent);
  color: var(--accentFg);
  border-color: var(--accent);
}
.kb-enter:active { filter: brightness(0.88); color: var(--accentFg); }

/* ============================================================
 * P5：词表与自建词单
 * ============================================================ */

/* 单元 chips 横向滑条：滚动条隐藏 + 边缘渐隐遮罩 */
#browse-chips-wrap {
  position: relative;
  flex-shrink: 0;
}
#browse-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;              /* Firefox */
  -ms-overflow-style: none;
  padding: 2px;
}
#browse-chips::-webkit-scrollbar {   /* WebKit */
  display: none;
}
.chip {
  flex-shrink: 0;
  min-width: 44px;
  min-height: 36px;
  padding: 6px 12px;
  border: 1px solid var(--line2);
  border-radius: var(--r-pill);
  background: var(--card2);
  color: var(--dim);
  font-size: 14px;
  font-family: inherit;
}
.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accentFg);
  font-weight: 600;
}
.chip-fade {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 28px;
  pointer-events: none;
}
.fade-l {
  left: 0;
  background: linear-gradient(to right, var(--bg), rgba(25, 23, 19, 0));
}
.fade-r {
  right: 0;
  background: linear-gradient(to left, var(--bg), rgba(25, 23, 19, 0));
}

/* 单词行 */
.browse-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 10px 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-s);
  user-select: none;
  -webkit-user-select: none;
}
.browse-row.picked {
  background: var(--accentSoft);
  border-color: var(--accent);
}
.browse-row .rw-mark { color: var(--accent); font-weight: 700; min-width: 18px; }
.browse-row .rw-w { color: var(--fg); font-size: 16px; font-weight: 600; }
.browse-row .rw-ipa { color: var(--faint); font-size: 13px; font-family: Georgia, serif; }
.browse-row .rw-zh { color: var(--dim); font-size: 13px; flex: 1; }

/* 底部操作条 */
.action-bar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 0 12px 0;
}

/* 输入行 */
.input-row { display: flex; gap: 10px; margin-top: 10px; }
.txt-input {
  flex: 1;
  min-height: 44px;
  border: 1px solid var(--line2);
  border-radius: var(--r-s);
  background: var(--bg2);
  color: var(--fg);
  font-size: 15px;
  font-family: inherit;
  padding: 0 12px;
}
.txt-input::placeholder { color: var(--faint); }

/* 词单行 / picker 行 */
.list-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
}
.list-row .li-main { flex: 1; min-width: 0; }
.list-row .li-name { color: var(--fg); font-size: 16px; font-weight: 600; }
.list-row .li-meta { color: var(--faint); font-size: 12px; margin-top: 2px; }
.list-row .li-btns { display: flex; gap: 6px; flex-shrink: 0; }
.list-row .li-btns .btn-ghost {
  min-height: 36px;
  padding: 4px 10px;
  font-size: 13px;
}
.picker-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 10px 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-s);
}
.picker-row.picked { background: var(--accentSoft); border-color: var(--accent); }
.picker-row .pk-w { color: var(--fg); font-size: 15px; font-weight: 600; }
.picker-row .pk-zh { color: var(--dim); font-size: 13px; flex: 1; }
.picker-row .pk-mark { color: var(--accent); font-weight: 700; min-width: 18px; }

/* 单词卡片浮层（wcard）：mask 与 box 是兄弟节点，点 box 内部不会关闭 */
#wcard, #modal {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
#wcard-mask, #modal-mask {
  position: absolute;
  inset: 0;
}
#wcard-box, #modal-box {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 420px;
  max-height: 80%;
  overflow-y: auto;
  box-shadow: var(--sh5);
}
.wcard-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: var(--r-pill);
  background: var(--card3);
  color: var(--dim);
  font-size: 15px;
}
.wcard-close:active { color: var(--fg); background: var(--line2); }

/* ============================================================
 * P6：测验 / 听写 / 批改 / 统计
 * ============================================================ */

/* quiz 选项：判定后高亮正确与错误 */
.opt {
  min-height: 48px;
  border: 1px solid var(--line2);
  border-radius: var(--r-s);
  background: var(--card2);
  color: var(--fg);
  font-size: 15px;
  font-family: inherit;
  text-align: left;
  padding: 8px 14px;
}
.opt:active { background: var(--accentSoft); }
.opt.ok {
  background: var(--okSoft);
  border-color: var(--ok);
  color: var(--ok);
  font-weight: 600;
}
.opt.bad {
  background: var(--badSoft);
  border-color: var(--bad);
  color: var(--bad);
}
.opt:disabled { opacity: 1; }

/* 听写 */
#dictation-input { min-height: 64px; }

/* 批改行 */
.mk-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-s);
}
.mk-row .mk-typed { flex: 1; color: var(--fg); font-size: 15px; overflow: hidden; text-overflow: ellipsis; }
.mk-row .mk-arrow { color: var(--faint); }
.mk-row .mk-answer { flex: 1; color: var(--dim); font-size: 14px; }
.mk-row .mk-verdict { flex-shrink: 0; font-weight: 700; font-size: 14px; }
.mk-row .mk-verdict.ok { color: var(--ok); }
.mk-row .mk-verdict.bad { color: var(--bad); }

/* 统计数字 */
.stat-num { font-size: 30px; font-weight: 700; color: var(--fg); }

/* ============================================================
 * P7：设置 + 本地账号 + 选册
 * ============================================================ */
#login {
  display: flex;
  align-items: center;
  justify-content: center;
}
#login-mask {
  position: absolute;
  inset: 0;
}
#login-box {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 420px;
  max-height: 80%;
  overflow-y: auto;
  box-shadow: var(--sh5);
}
#login-box > * { flex-shrink: 0; }
#login-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--fg);
  margin-bottom: 10px;
}
#login-nick { width: 100%; margin-bottom: 10px; }
#login-users {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}
.login-user {
  text-align: left;
  padding: 12px 14px;
  border-radius: var(--r-s);
  border: 1px solid var(--line);
  background: var(--card2);
  color: var(--fg);
  font-size: 15px;
}
.login-user:active { background: var(--card3); }
.set-name {
  font-size: 18px;
  font-weight: 600;
  color: var(--fg);
  margin: 6px 0 10px;
}
#set-book-name { margin: 6px 0 10px; }
.btn-ghost.danger {
  color: var(--bad);
  border-color: var(--line2);
  background: var(--badSoft);
}
#booksel-list { gap: 10px; }
#booksel-list .active {
  border-color: var(--accent);
  color: var(--accent);
}

/* ============================================================
 * P8-a：词灵营地（game / dex / map）
 * ============================================================ */
.game-res-row {
  display: flex;
  gap: 14px;
  align-items: baseline;
  font-size: 15px;
  color: var(--dim);
  margin-bottom: 8px;
}
.game-res-row b {
  font-size: 20px;
  color: var(--gold);
  font-weight: 700;
}
.game-res-row span:nth-child(2) b { color: var(--accent); }
.game-res-row span:nth-child(3) b { color: var(--fg); }
#game-top .dim-line, #game-actions .dim-line { margin: 2px 0; }
.li-btn {
  padding: 8px 12px;
  border-radius: var(--r-s);
  border: 1px solid var(--line2);
  background: var(--accentSoft);
  color: var(--accent);
  font-size: 13px;
}
.li-btn:active { background: var(--card3); }
#game-attr-rows .mk-row { justify-content: space-between; }
.dex-unit {
  color: var(--dim);
  font-size: 13px;
  margin: 12px 0 4px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 4px;
}
.dex-w { color: var(--fg); font-size: 15px; }
#dex-list .mk-row, #map-list .mk-row { padding: 7px 0; border-bottom: 1px solid var(--line); }

/* ============================================================
 * P8-b：战斗
 * ============================================================ */
#battle-hand {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.hand-card {
  padding: 10px 12px;
  border-radius: var(--r-s);
  border: 1px solid var(--line2);
  background: var(--card2);
  color: var(--fg);
  font-size: 14px;
}
.hand-card:active { background: var(--card3); }
#battle-log {
  white-space: pre-wrap;
  color: var(--dim);
  font-size: 13px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-s);
  padding: 10px;
  min-height: 90px;
}
#battle-settle-body {
  white-space: pre-wrap;
  color: var(--fg);
  font-size: 14px;
}

/* ================= P11 正式首页 ================= */
.home-top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 2px 10px;
  flex-shrink: 0;
}
.home-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accentSoft);
  color: var(--accentFg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: bold;
  flex-shrink: 0;
}
.home-nick {
  font-size: 16px;
  font-weight: bold;
  color: var(--fg);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.home-streak {
  font-size: 12px;
  color: var(--gold);
  flex-shrink: 0;
}
.home-gear {
  width: 34px;
  height: 34px;
  border-radius: var(--r);
  border: 1px solid var(--line);
  background: var(--card2);
  color: var(--dim);
  font-size: 17px;
  flex-shrink: 0;
}
.home-books {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  margin-bottom: 10px;
}
.home-chip {
  flex: 1;
  padding: 8px 0;
  border-radius: var(--r-pill);
  border: 1px solid var(--line);
  background: var(--card2);
  color: var(--dim);
  font-size: 14px;
}
.home-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accentFg);
  font-weight: bold;
}
.home-counts {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  margin-bottom: 10px;
}
.home-count {
  flex: 1;
  background: var(--card2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 10px 0;
  text-align: center;
}
.home-count-num {
  font-size: 22px;
  font-weight: bold;
  color: var(--accent);
}
.home-count-label {
  font-size: 12px;
  color: var(--dim);
  margin-top: 2px;
}
.home-progress {
  background: var(--card2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 10px 12px;
  flex-shrink: 0;
  margin-bottom: 10px;
}
.home-progress-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}
.home-progress-title {
  font-size: 13px;
  color: var(--dim);
}
.home-progress-num {
  font-size: 13px;
  color: var(--gold);
  font-weight: bold;
}
.home-progress-bar {
  height: 8px;
  border-radius: 4px;
  background: var(--bg2);
  overflow: hidden;
}
.home-progress-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--gold);
  transition: width 0.3s;
}
.home-search {
  flex-shrink: 0;
  margin-bottom: 10px;
}
.home-search input {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  border-radius: var(--r);
  border: 1px solid var(--line);
  background: var(--card2);
  color: var(--fg);
  font-size: 14px;
}
.home-search-results {
  margin-top: 6px;
}
.home-search-item {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--fg);
  font-size: 14px;
}
.home-search-item:active { background: var(--card3); }
.home-search-item .zh {
  color: var(--dim);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.home-mascot {
  flex-shrink: 0;
  border-radius: var(--r-l);
  overflow: hidden;
  background: var(--card2);
  border: 1px solid var(--line);
  text-align: center;
}
.home-mascot img {
  display: block;
  width: 100%;
  max-height: 240px;
  object-fit: contain;
}
.home-mascot:active { border-color: var(--accent); }
.home-mascot-hint {
  text-align: center;
  padding: 6px 0 10px;
  flex-shrink: 0;
}
.home-main-actions {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 8px;
}
.home-btn-big {
  padding: 14px 0;
  font-size: 16px;
}
.home-btn-row {
  display: flex;
  gap: 8px;
}
.home-btn-row .btn-ghost { flex: 1; }

/* ================= P12 演示进度角标 ================= */
.demo-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--r-pill);
  background: var(--goldSoft);
  color: var(--gold);
  font-size: 11px;
  font-weight: bold;
  flex-shrink: 0;
}
#game-demo-badge { margin-bottom: 8px; }
