/* ==========================================================================
   style.css —— 华为 MATE60PRO 适配样式
   --------------------------------------------------------------------------
   设计基准：Mate 60 Pro 逻辑分辨率约 393 × 873 CSS px（挖孔屏 + 底部手势条）
   ★ 一屏一任务：题面 + 选项必须在一屏内看完，不滚动
   ★ 触控目标 ≥ 44px；大按钮、大字号
   ★ 尊重 prefers-reduced-motion
   ★ 深色模式跟随系统
   ========================================================================== */

:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --fg: #1a1d21;
  --fg2: #5b6570;
  --fg3: #98a2ad;
  --line: #e3e7ec;
  --line2: #cfd6de;
  --brand: #E01F26;
  --brand-d: #C2171D;
  --ok: #10b981;
  --ok-bg: #ecfdf5;
  --bad: #ef4444;
  --bad-bg: #fef2f2;
  --warn: #f59e0b;
  --warn-bg: #fffbeb;
  --purple: #8b5cf6;
  --purple-bg: #f5f3ff;
  --teal: #0d9488;
  --radius: 14px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --card: #171b22;
    --fg: #e8ecf1;
    --fg2: #a4b0bd;
    --fg3: #6b7784;
    --line: #262c35;
    --line2: #333b45;
    --brand: #F0565C;
    --brand-d: #E01F26;
    --ok-bg: #0d2620;
    --bad-bg: #2a1414;
    --warn-bg: #2a2110;
    --purple-bg: #1e1b33;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "HarmonyOS Sans SC", "PingFang SC",
               "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  /* ★ 全屏（PWA fullscreen）下禁止整页滚动回弹，避免下拉露出白底 */
  overscroll-behavior: none;
  overscroll-behavior-y: none;
  /* ★ 禁止横向边缘滑动 —— 这是浏览器"右划返回/前进"手势的来源，
       在某些国产浏览器里会触发"资讯推荐页"（华为浏览器的新闻流）。
       overscroll-behavior-x + touch-action 一起上，双保险。 */
  overscroll-behavior-x: none;
  touch-action: pan-y;                 /* 只允许纵向滚动，横向手势不响应 */
  -webkit-tap-highlight-color: transparent;
}
body {
  min-height: 100vh;
  min-height: 100dvh;          /* 动态视口高度：全屏时地址栏收起不跳动 */
}
@supports (padding: max(0px)) {
  :root {
    /* 全屏时顶部要避让挖孔：safe-t 与一个最小值取大者 */
    --safe-t: max(env(safe-area-inset-top, 0px), 8px);
    --safe-b: max(env(safe-area-inset-bottom, 0px), 8px);
  }
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: calc(var(--safe-t) + 10px) 16px calc(var(--safe-b) + 24px);
  min-height: 100vh;
  min-height: 100dvh;
}

/* ===== 全屏模式（display:fullscreen）=====
   状态栏已隐藏 → 顶部不需要留太多余量，但也必须避开刘海/挖孔 */
@media (display-mode: fullscreen) {
  #app { padding-top: calc(var(--safe-t) + 4px); }
  /* 顶部进度条贴到最上沿，视觉更整 */
  .hd { margin-top: 0; }
}
/* 独立窗口模式（standalone）：状态栏还在，仍需正常避让 */
@media (display-mode: standalone) {
  #app { padding-top: calc(var(--safe-t) + 10px); }
}

/* ---------- 顶栏 ---------- */
.hd {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 0 14px;
}
.hd-l { display: flex; align-items: baseline; gap: 9px; }
.logo {
  font-size: 19px; font-weight: 700; letter-spacing: 0.5px;
  color: var(--fg);
}
.sub { font-size: 12px; color: var(--fg3); }
.bk {
  background: none; border: none; color: var(--brand);
  font-size: 15px; font-family: inherit; padding: 8px 10px 8px 0;
}
.accent {
  min-width: 40px; height: 34px; padding: 0 11px;
  border: 1px solid var(--line2); border-radius: 17px;
  background: var(--card); color: var(--fg2);
  font-size: 13px; font-family: inherit; font-weight: 600;
}
.accent.sm { min-width: 34px; height: 30px; padding: 0 9px; font-size: 12px; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.card.center { text-align: center; }
.ttl { font-size: 14px; font-weight: 700; margin-bottom: 12px; }
.note { font-size: 12px; color: var(--fg3); line-height: 1.6; margin-top: 8px; }

/* ---------- 进度 ---------- */
.prog-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 9px; }
.prog-top b { font-size: 15px; }
.prog-top span { font-size: 13px; color: var(--fg2); }
.prog-sub { font-size: 12.5px; color: var(--fg2); margin-top: 9px; }
.prog-sub b.g { color: var(--ok); }
.prog-sub b.a { color: var(--warn); }
.prog-sub b.r { color: var(--bad); }

.pbar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.pbar i { display: block; height: 100%; background: var(--brand); border-radius: 4px; transition: width .3s ease; }
.pbar.sm { height: 7px; }
.pbar.sm i { background: var(--ok); }
.pbar.sm2 i { background: var(--brand); }
.pbar.mini { height: 5px; width: 72px; display: inline-block; vertical-align: middle; }

.mrow { display: flex; align-items: center; gap: 10px; margin-bottom: 9px; }
.mrow > span { font-size: 13px; color: var(--fg2); width: 62px; flex-shrink: 0; }
.mrow .pbar { flex: 1; }
.mrow > b { font-size: 13px; font-weight: 700; width: 42px; text-align: right; }

/* ---------- 按钮 ---------- */
.big {
  width: 100%; padding: 15px; border-radius: var(--radius);
  font-size: 16px; font-weight: 700; font-family: inherit;
  border: none; margin-bottom: 14px;
}
.big.primary, .primary {
  background: var(--brand); color: #fff;
  border: none; padding: 13px 18px; border-radius: var(--radius);
  font-size: 15px; font-weight: 700; font-family: inherit;
}
.big.primary:active, .primary:active { background: var(--brand-d); }
.primary.full { width: 100%; margin-top: 10px; }
.primary.sm { padding: 10px 16px; font-size: 14px; }

.ghost {
  background: var(--card); color: var(--fg2);
  border: 1px solid var(--line2); border-radius: 10px;
  padding: 10px 14px; font-size: 13.5px; font-family: inherit;
}

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.quick {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; text-align: left; font-family: inherit;
}
.quick b { display: block; font-size: 14.5px; color: var(--fg); }
.quick span { display: block; font-size: 12px; color: var(--fg3); margin-top: 3px; }

.foot { text-align: center; font-size: 11.5px; color: var(--fg3); padding: 8px 0 4px; }

/* ---------- 练习页顶栏 ---------- */
.qbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 0 12px; margin-bottom: 6px;
}
.qb-l { display: flex; align-items: center; gap: 9px; }
.qn { font-size: 13px; color: var(--fg2); font-variant-numeric: tabular-nums; }
.qb-r { display: flex; align-items: center; gap: 8px; }
.combo {
  padding: 4px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700;
  background: var(--warn-bg); color: var(--warn);
}
.combo.c5 { background: var(--purple-bg); color: var(--purple); }
.combo.c8 { background: var(--purple-bg); color: var(--purple); }
.combo.c10 { background: #fef2f2; color: #dc2626; }
.combo.c15 { background: #fefce8; color: #ca8a04; }

/* ---------- 题面 ---------- */
.qhead { text-align: center; font-size: 13px; color: var(--fg3); margin-bottom: 12px; }
.wordrow { display: flex; align-items: center; justify-content: center; gap: 11px; margin-bottom: 6px; }
.word {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 30px; font-weight: 700; letter-spacing: 0.3px;
  word-break: break-word; text-align: center;
}
.word.sp { font-family: inherit; font-size: 21px; font-weight: 600; }
/* ★ 同义词词条：显示完整释义（否则拼 plane / airplane 都算对）→ 字号收小 */
.word.sp.full { font-size: 15.5px; font-weight: 600; line-height: 1.55; }
.ipa { text-align: center; font-size: 15px; color: var(--fg2); margin-bottom: 18px; }
.ipa .acc { font-size: 11px; color: var(--fg3); margin-left: 7px; }

.say {
  width: 40px; height: 40px; flex-shrink: 0;
  border-radius: 50%; border: 1px solid var(--line2);
  background: var(--card); color: var(--brand);
  font-size: 18px; display: inline-flex; align-items: center; justify-content: center;
}
.say.sm { width: 34px; height: 34px; font-size: 15px; }
.say.big {
  width: auto; min-width: 108px; height: 42px;
  border-radius: 21px; padding: 0 18px;
  font-size: 14.5px; font-weight: 600; white-space: nowrap;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  flex-shrink: 0;
}
.say.big > span, .say.big .lab { white-space: nowrap; }
.say.inline { width: 30px; height: 30px; font-size: 14px; vertical-align: middle; }
.saywrap { display: flex; justify-content: center; margin: 4px 0 6px; }

/* ---------- 选项 ---------- */
.opts { display: flex; flex-direction: column; gap: 9px; }
.opt {
  display: flex; align-items: flex-start; gap: 11px;
  width: 100%; text-align: left;
  background: var(--card); border: 1.5px solid var(--line);
  border-radius: var(--radius); padding: 14px;
  font-size: 15.5px; color: var(--fg); font-family: inherit;
  line-height: 1.5; min-height: 52px;
}
.opt .k {
  flex-shrink: 0; width: 22px; height: 22px; border-radius: 50%;
  background: var(--bg); color: var(--fg3);
  font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.opt .v { flex: 1; }
.opt.right { border-color: var(--ok); background: var(--ok-bg); }
.opt.right .k { background: var(--ok); color: #fff; }
.opt.wrong { border-color: var(--bad); background: var(--bad-bg); animation: shake .3s; }
.opt.wrong .k { background: var(--bad); color: #fff; }
.opt.dim { opacity: .45; }

@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.hintbtn {
  width: 100%; margin-top: 14px; padding: 12px;
  background: transparent; border: 1px dashed var(--line2); border-radius: var(--radius);
  color: var(--fg2); font-size: 14px; font-family: inherit;
}

/* ---------- 提示框 ---------- */
.hintbox { margin-top: 12px; }
.hintbox.show {
  background: var(--warn-bg); border: 1px solid #fcd34d;
  border-radius: var(--radius); padding: 13px 14px;
  font-size: 13.5px; line-height: 1.65; color: #92400e;
}
@media (prefers-color-scheme: dark) {
  .hintbox.show { border-color: #78500a; color: #fcd34d; }
}
.hintbox .note { color: inherit; opacity: .78; margin-top: 5px; }
.ipab { font-family: Georgia, serif; font-weight: 700; font-size: 16px; }
.ipab.big { font-size: 19px; letter-spacing: 1px; }
.fb { font-weight: 700; margin-bottom: 8px; }
.good { color: var(--ok); }

/* ---------- 拼写：砖块 ---------- */
.slots {
  display: flex; flex-wrap: wrap; gap: 9px; justify-content: center;
  margin: 16px 0 22px; min-height: 52px;
}

/* ===== 拼写区：撑满剩余高度并垂直居中 =====
   问题：长单词拼写题底部空 45% 屏幕（按钮栏下面一片空白）
   方案：.spellwrap 吃掉剩余高度 → 空位与砖块在中间居中分布 */
#app.flexcol {
  display: flex; flex-direction: column;
}
#app.flexcol .spellwrap {
  flex: 1 1 auto;
  display: flex; flex-direction: column;
  justify-content: space-evenly;   /* ★ 空白均匀分布：长词不挤、短词不空旷 */
  min-height: 0;
}
#app.flexcol .spellwrap .slots { margin-top: 0; margin-bottom: 0; }
#app.flexcol .spellwrap .tiles { margin-top: 0; margin-bottom: 0; }
#app.flexcol .tilebar { margin-top: auto; }
.slot {
  width: 36px; height: 50px;
  border: 1.5px dashed var(--line2); border-radius: 9px;
  background: rgba(0, 0, 0, .03);
  display: flex; align-items: center; justify-content: center;
  font-family: Georgia, serif; font-size: 26px; font-weight: 700;
  color: var(--fg);
}
.slot.filled {
  border-style: solid; border-color: var(--brand);
  background: rgba(224, 31, 38, .06);
  color: var(--brand);
}

.tiles {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--tmin, 54px), 1fr));
  gap: var(--tgap, 12px); margin-bottom: 18px;
}
.tile {
  height: var(--th, 62px); border-radius: 13px;
  border: 1.5px solid var(--line2); background: var(--card);
  color: var(--fg); font-size: 24px; font-weight: 700; font-family: Georgia, serif;
}
.tile:active { background: var(--bg); transform: scale(.96); }

.spellinput {
  width: 100%; padding: 15px 16px; margin: 14px 0 4px;
  border: 1.5px solid var(--line2); border-radius: var(--radius);
  background: var(--card); color: var(--fg);
  font-size: 19px; font-family: Georgia, "Times New Roman", serif;
  letter-spacing: 1.5px;
}
.spellinput:focus { outline: none; border-color: var(--brand); }

.tilebar { display: flex; gap: 9px; align-items: center; margin-top: 12px; }
.tilebar .primary { flex: 2; }
.tilebar .ghost { flex: 1; }

.spdiff { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0; }
.spdiff span {
  width: 24px; height: 30px; border-radius: 5px;
  display: flex; align-items: center; justify-content: center;
  font-family: Georgia, serif; font-weight: 700; font-size: 16px;
}
.spdiff span.ok { background: var(--ok-bg); color: var(--ok); }
.spdiff span.bad { background: var(--bad-bg); color: var(--bad); }

/* 软键盘弹起：隐藏多余留白、收紧间距 */
body.kb-open #app { padding-bottom: 12px; }
body.kb-open .foot { display: none; }

/* ===== 顶栏右侧按钮组 ===== */
.hd-r { display: flex; align-items: center; gap: 8px; }
/* ★ 全屏按钮：改用文字，⛶ 图标太隐蔽，用户找不到 */
.iconbtn {
  height: 34px; flex-shrink: 0;
  border-radius: 17px; border: 1px solid var(--brand);
  background: var(--brand); color: #fff;
  font-size: 13px; font-weight: 700; font-family: inherit;
  padding: 0 13px; letter-spacing: .5px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.iconbtn:active { transform: scale(.94); }
.iconbtn.off { background: var(--card); color: var(--brand); }

/* ===== 首屏全屏引导条（仅浏览器模式显示）===== */
.fsguide {
  display: flex; align-items: center; gap: 10px;
  margin: 0 0 12px; padding: 11px 13px;
  background: linear-gradient(135deg, #fff5f5, #ffecec);
  border: 1px solid #f7c9c9; border-radius: 14px;
}
.fsguide .t { flex: 1; font-size: 13px; line-height: 1.55; color: #7F1D1D; }
.fsguide .t b { color: #B91C1C; }
.fsguide button {
  flex-shrink: 0; height: 34px; padding: 0 14px;
  border-radius: 17px; border: 1px solid var(--brand);
  background: var(--brand); color: #fff;
  font-size: 13px; font-weight: 700; font-family: inherit; cursor: pointer;
}
.fsguide button:active { transform: scale(.95); }

/* ===== 安装引导（仅浏览器模式显示）===== */
.install-tip {
  margin: 0 0 14px; padding: 12px 14px;
  background: linear-gradient(135deg, #fff5f5, #ffecec);
  border: 1px solid #f7c9c9; border-radius: 14px;
}
.install-tip b {
  display: block; font-size: 14px; color: #B91C1C; margin-bottom: 4px;
}
.install-tip span {
  display: block; font-size: 13px; line-height: 1.6; color: #7F1D1D;
}
.install-tip span b { display: inline; color: #B91C1C; }

/* ---------- 奖励层 ---------- */
#fx {
  position: fixed; inset: 0; pointer-events: none;
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.reward {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  animation: pop .9s ease-out forwards;
}
.reward .em { font-size: 58px; line-height: 1; }
.reward .tx {
  font-size: 17px; font-weight: 800; color: var(--fg);
  background: var(--card); padding: 6px 15px; border-radius: 999px;
  box-shadow: 0 3px 14px rgba(0,0,0,.14);
}
.reward.lv1 .em { color: var(--ok); }
.reward.lv3 .em { color: var(--warn); animation: pop .7s ease-out, wiggle .4s .2s; }
.reward.lv5 .em { color: var(--purple); }
.reward.lv8 .em { color: var(--brand); }
.reward.lv10 .em { color: #dc2626; animation: pop .8s ease-out, wiggle .5s; }
.reward.lv15 .em { color: #ca8a04; animation: pop .9s ease-out, wiggle .6s; }

@keyframes pop {
  0% { transform: scale(.3); opacity: 0; }
  35% { transform: scale(1.15); opacity: 1; }
  65% { transform: scale(1); opacity: 1; }
  100% { transform: scale(1); opacity: 0; }
}
@keyframes wiggle {
  0%,100% { transform: rotate(0); }
  30% { transform: rotate(-12deg); }
  70% { transform: rotate(12deg); }
}

.spark {
  position: absolute; width: 8px; height: 8px; border-radius: 50%;
  background: var(--warn); opacity: 0;
  animation: spark .7s ease-out forwards;
  animation-delay: var(--dl, 0s);
}
@keyframes spark {
  0% { transform: translate(0,0) scale(1); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(0); opacity: 0; }
}

.confetti {
  position: absolute; top: -12px; width: 9px; height: 14px; border-radius: 2px;
  opacity: 0; animation: fall 1.3s ease-in forwards;
  animation-delay: var(--dl, 0s);
}
@keyframes fall {
  0% { transform: translateY(0) rotate(0); opacity: 1; }
  100% { transform: translateY(78vh) rotate(var(--rot, 360deg)); opacity: .1; }
}

/* ---------- 完成页 ---------- */
.bigem { font-size: 54px; color: var(--warn); line-height: 1; margin-bottom: 8px; }
.card h2 { font-size: 18px; margin: 0 0 12px; }
.statrow { display: flex; justify-content: space-around; margin: 14px 0 6px; }
.statrow > div { text-align: center; }
.statrow b { display: block; font-size: 26px; font-weight: 800; }
.statrow span { font-size: 12px; color: var(--fg3); }

/* ---------- 统计 / 列表 ---------- */
.dist { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; }
.dist .d b { display: block; font-size: 22px; font-weight: 800; }
.dist .d span { font-size: 11.5px; color: var(--fg3); }
.dist b.g { color: var(--ok); }
.dist b.a { color: var(--warn); }
.dist b.r { color: var(--bad); }
.dist b.t { color: var(--teal); }

.wrow {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 0; border-bottom: 1px solid var(--line);
}
.wrow:last-child { border-bottom: none; }
.wl { flex: 1; min-width: 0; }
.wl b { font-family: Georgia, serif; font-size: 15.5px; }
.wl .ip { font-size: 12px; color: var(--fg3); margin-left: 7px; }
.wl .cn { display: block; font-size: 12.5px; color: var(--fg2); margin-top: 2px; }
.badge { font-size: 11px; padding: 3px 8px; border-radius: 999px; flex-shrink: 0; }
.badge.r { background: var(--bad-bg); color: var(--bad); }
.badge.a { background: var(--warn-bg); color: var(--warn); }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 78px);
  transform: translateX(-50%);
  background: rgba(26,29,33,.92); color: #fff;
  padding: 10px 18px; border-radius: 999px;
  font-size: 13.5px; opacity: 0; transition: opacity .25s;
  pointer-events: none; z-index: 90; max-width: 86vw; text-align: center;
}

/* ---------- 动效降级 ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  .reward { opacity: 1; }
}

/* ---------- 横屏 / 平板 ---------- */
@media (min-width: 700px) {
  #app { max-width: 560px; }
}
