/* App 模式（iOS／Android）的版型與元件。docs/PLAN-app.md 第 6.2–6.5、6.7、6.8 節。
 *
 * 每一條選擇器都以 html.is-app 開頭：網站也載入這個檔，但 <html> 沒有 is-app，
 * 所以一條都不會生效。只用 design.css 的 token，不新增色碼
 * （半透明遮罩用的是 --navy-deep 的 RGB，和 screens.css 的 toast 陰影同一個值）。
 *
 * 版型依「視窗寬度」切換，不看裝置種類（6.1：iPad 分割畫面 1/3 寬只有 320，要用手機版型）：
 *   compact   < 600     底部分頁列 56 + 安全區域；單欄，左右邊距 16
 *   medium    600–1023  左側導覽欄 80；單欄最寬 720 置中，部分畫面雙欄
 *   expanded  ≥ 1024    左側導覽欄 240；雙欄（清單 360–400 ＋ 內容）
 *
 * 安全區域一律走 --sa-t／r／b／l：預設是 env(safe-area-inset-*)；原生層（或本機測試的假原生層）
 * 給了 MMNative.insets 時，platform.js 會直接把數值寫在 <html> 的 style 上蓋過去。
 *
 * html 上的狀態 class（platform.js 與 app.js 的 AppUI 設的）：
 *   is-app is-ios／is-android   App 模式
 *   app-nonav                    全螢幕畫面（作答、練習、登入），分頁列與導覽欄收起
 *   app-notop                    沒有頂部欄（作答、載入中、版本過舊）
 *   app-large／app-scrolled      根畫面的大標題；捲動後頂部欄中間換成小標題
 *   app-offline                  離線
 *   app-sheet-open               底部 sheet 開著
 *   data-view="quiz"…            目前的畫面；data-fs="l"／"xl" 字級
 */

/* ═══════════════════════════ 基礎 ═══════════════════════════ */

html.is-app {
  --sa-t0: env(safe-area-inset-top, 0px);      /* 系統的上方安全區域（platform.js 有原生數值時會蓋過它） */
  --sa-t: calc(var(--sa-t0) + var(--ad-t));    /* 頂部橫幅的下緣：有橫幅時所有「頂端往下排」的東西都從這裡開始 */
  --sa-r: env(safe-area-inset-right, 0px);
  --sa-b: env(safe-area-inset-bottom, 0px);
  --sa-l: env(safe-area-inset-left, 0px);
  --app-tab-h: 56px;
  --app-top-h: 44px;
  --app-rail-w: 0px;          /* 導覽欄寬度：compact 0、medium 80、expanded 240 */
  --app-nav-b: calc(var(--app-tab-h) + var(--sa-b));   /* 底部被分頁列佔掉的高度 */
  --app-gutter: 16px;
  --app-fs: 1;                /* 「我的 → 字級」：標準／大／特大 */
  --app-base: 1;              /* 手機 16、平板 17 */
  font-size: calc(100% * var(--app-fs) * var(--app-base));
  -webkit-tap-highlight-color: transparent;
}
html.is-app[data-fs="l"] { --app-fs: 1.125; }
html.is-app[data-fs="xl"] { --app-fs: 1.25; }
html.is-app.app-nonav { --app-nav-b: var(--sa-b); }

/* 橫幅廣告（1.1 版）：廣告是原生的 View，固定在螢幕「頂部」（狀態列／瀏海下方），全部畫面共用同一個。
 * platform.js 收到它的高度（adheight）就設 --ad-h 並加上 html.has-ad；沒有廣告（還沒載入、載入失敗、離線、
 * 訂閱中、年齡畫面還沒回答）時全部是 0，版面和以前一樣。
 * 有廣告時 --ad-t = --ad-h，--sa-t（頂端安全區域）跟著加高，所以頂部欄、作答列、sheet、側欄都自動從橫幅下面開始排。
 * 底部不受影響：分頁列、作答操作列、toast 一律貼最底（--ad-b 永遠是 0，只留著讓舊的算式不用全改）。 */
html.is-app { --ad-h: 0px; --ad-t: 0px; --ad-b: 0px; }
html.is-app.has-ad { --ad-t: var(--ad-h); }

html.is-app body {
  min-height: 100vh;
  padding-left: calc(var(--app-rail-w) + var(--sa-l));
  padding-right: var(--sa-r);
  padding-bottom: calc(var(--app-nav-b) + var(--ad-b));
  overscroll-behavior-y: none;
}
html.is-app.app-nonav body { padding-left: var(--sa-l); }

/* 網站的頂部欄、頁尾、方案頁、首頁的型錄與廣告訪客內容：App 不顯示（5.5、6.3） */
html.is-app #topbar,
html.is-app .footer,
html.is-app #view-plans,
html.is-app #land-plans,
html.is-app #btn-print,
html.is-app #view-home > :not(#app-home) { display: none !important; }
/* 版面上的「插圖待補」佔位框：網站拿來對設計稿，App 不放 */
html.is-app .img-slot.is-empty { display: none !important; }
/* 錯題本在 App 是獨立的分頁（A7），分析頁不重複放 */
html.is-app #an-body .wrong-book { display: none; }

/* 畫面容器 */
html.is-app .view { padding: 12px var(--app-gutter) 32px; }
html.is-app .view-wide { max-width: none; }
html.is-app .view-full { padding: 0; }
html.is-app .page-head h1 { font-size: 1.5rem; }
/* App 的大標題已經寫了畫面名稱，畫面裡重複的 h1 拿掉 */
html.is-app #view-analysis .page-head h1,
html.is-app #view-history .page-head h1 { display: none; }

/* 觸控目標至少 48（6.1） */
html.is-app .btn,
html.is-app .seg-btn { min-height: 48px; }
html.is-app .btn.primary.btn-lg { min-height: 52px; }
html.is-app .btn.small,
html.is-app .btn-sm { min-height: 44px; }
html.is-app .chip { min-height: 40px; }
html.is-app .linklike { padding: 6px 2px; }
html.is-app .btn.danger { border: none; background: var(--red-deep); color: var(--surface); box-shadow: 0 4px 0 var(--navy-deep); }

/* 字級（6.2）：題幹 18／20、選項 17／18、行高 1.6 */
html.is-app #quiz-card .stem,
html.is-app #practice-body .stem { font-size: 1.125rem; line-height: 1.6; }
html.is-app .opt-body { font-size: 1.0625rem; line-height: 1.6; }

/* 減少動態效果（6.8） */
@media (prefers-reduced-motion: reduce) {
  html.is-app .app-sheet,
  html.is-app .app-sheet-scrim,
  html.is-app .app-top-title,
  html.is-app .view { transition: none !important; animation: none !important; }
}

/* ═══════════════════════════ 頂部欄（6.5）═══════════════════════════ */

html.is-app .app-top {
  position: sticky; top: 0; z-index: 40;
  padding-top: var(--sa-t);
  background: var(--surface);
  border-bottom: 1px solid var(--border-lite);
}
html.is-app.app-large:not(.app-scrolled) .app-top { border-bottom-color: transparent; }
html.is-app.app-notop .app-top,
html.is-app.app-notop .app-ltitle { display: none; }
html.is-app.app-notop:not([data-view="quiz"]) #app { padding-top: var(--sa-t); }
html.is-app .app-top-bar {
  height: var(--app-top-h);
  display: grid; grid-template-columns: minmax(88px, 1fr) auto minmax(88px, 1fr); align-items: center;
  padding: 0 8px;
}
html.is-app .app-top-back {
  justify-self: start; min-height: 44px; min-width: 44px; padding: 0 8px;
  border: none; background: none; color: var(--navy);
  font: inherit; font-weight: 800; font-size: 1rem; cursor: pointer;
}
html.is-app .app-top-back span[aria-hidden] { font-size: 1.5rem; line-height: 1; vertical-align: -2px; }
html.is-app .app-top-title {
  grid-column: 2; justify-self: center; max-width: 60vw;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-weight: 900; font-size: 1.0625rem; color: var(--navy);
  transition: opacity .18s;
}
html.is-app.app-large:not(.app-scrolled) .app-top-title { opacity: 0; }
html.is-app .app-top-actions { grid-column: 3; justify-self: end; display: flex; gap: 8px; align-items: center; }
html.is-app .app-top-avatar { width: 36px; height: 36px; padding: 0; cursor: pointer; font-family: inherit; }
html.is-app .app-top-avatar::before { content: ''; position: absolute; inset: -4px; }
html.is-app .app-top-avatar { position: relative; }

/* 大標題：根畫面在頂部欄下方放 28pt 粗體，捲上去之後頂部欄中間換成小標題 */
html.is-app .app-ltitle { display: none; padding: 4px var(--app-gutter) 4px; }
html.is-app.app-large .app-ltitle { display: block; }
html.is-app .app-ltitle h1 { font-size: 1.75rem; line-height: 1.25; }

/* 橫幅：離線、信箱未驗證（6.5、6.7） */
html.is-app .app-offline-banner { display: none; }
html.is-app.app-offline .app-offline-banner {
  display: block; padding: 10px var(--app-gutter);
  background: var(--amber-tint); color: var(--orange-deep); border-bottom: 1px solid var(--amber-bd);
  font-size: 0.875rem; font-weight: 800; text-align: center;
}
html.is-app.app-notop .app-offline-banner { padding-top: calc(var(--sa-t) + 10px); }
html.is-app[data-view="quiz"] .app-offline-banner { display: none; }
html.is-app .mail-banner { font-size: 0.875rem; }

/* 「需要連線」：離線時放在按鈕旁邊，不跳錯誤對話框（6.7） */
html.is-app .app-net-note { display: none; margin: 4px 0 0; text-align: center; font-size: 0.875rem; font-weight: 800; color: var(--orange-deep); }
html.is-app.app-offline .app-net-note { display: block; }
html.is-app.app-offline #auth-submit,
html.is-app.app-offline .app-buy,
html.is-app.app-offline #app-del-go,
html.is-app.app-offline [data-tutor-send],
html.is-app.app-offline #report-aud .seg-btn { opacity: .5; pointer-events: none; }

/* ═══════════════════════════ 分頁列（compact）═══════════════════════════ */

html.is-app .app-tabbar {
  position: fixed; left: 0; right: 0; bottom: var(--ad-b); z-index: 45;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: var(--app-nav-b);
  padding: 0 var(--sa-r) var(--sa-b) var(--sa-l);
  background: var(--surface); border-top: 1px solid var(--border);
}
html.is-app .app-tab {
  position: relative; min-width: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: none; background: none; cursor: pointer; padding: 4px 0;
  /* 6.5 寫 --ink-faint，但它在白底只有約 2.9:1，不到 6.8 要求的 4.5:1，改用 --ink-muted */
  color: var(--ink-muted);
  font: inherit; font-size: 0.6875rem; font-weight: 800; line-height: 1.2;
}
html.is-app .app-tab[aria-current="page"] { color: var(--navy); }
html.is-app .app-tab .app-ic { width: 24px; height: 24px; }
html.is-app .app-tab[aria-current="page"] .app-ic { stroke-width: 2.3; }
html.is-app .app-badge {
  position: absolute; top: 3px; left: calc(50% + 6px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  /* --red 配白字只有約 3.9:1，徽章的字很小，用 --red-deep */
  background: var(--red-deep); color: var(--surface);
  font-size: 0.6875rem; font-weight: 900; line-height: 18px; text-align: center;
}
html.is-app .app-rail { display: none; }
html.is-app.app-nonav .app-tabbar,
html.is-app.app-nonav .app-rail { display: none !important; }

/* ═══════════════════════════ 左側導覽欄（medium／expanded）═══════════════════════════ */

@media (min-width: 600px) {
  html.is-app { --app-base: 1.0625; --app-rail-w: 80px; --app-nav-b: var(--sa-b); --app-gutter: 24px; }
  html.is-app .app-tabbar { display: none; }
  html.is-app .app-rail {
    position: fixed; top: 0; bottom: var(--ad-b); left: 0; z-index: 45;      /* 有橫幅時導覽欄停在橫幅上方 */
    width: calc(var(--app-rail-w) + var(--sa-l));
    padding: calc(var(--sa-t) + 12px) 8px calc(var(--sa-b) + 12px) calc(var(--sa-l) + 8px);
    display: flex; flex-direction: column; align-items: stretch; gap: 6px;
    background: var(--surface); border-right: 1px solid var(--border);
    overflow-y: auto;
  }
  html.is-app .app-rail-brand {
    width: 44px; height: 44px; margin: 0 auto 10px; border-radius: var(--r-xs);
    display: grid; place-items: center; background: var(--navy); color: var(--surface);
    font-weight: 900; font-size: 1.25rem;
  }
  html.is-app .app-rail-btn {
    position: relative; min-height: 56px;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    border: none; border-radius: var(--r-sm); background: none; cursor: pointer;
    color: var(--ink-muted); font: inherit; font-size: 0.75rem; font-weight: 800;
  }
  html.is-app .app-rail-btn[aria-current="page"] { background: var(--blue-tint); color: var(--navy); }
  html.is-app .app-rail-btn .app-badge { top: 4px; left: calc(50% + 8px); }
  html.is-app .app-rail-acct {
    margin-top: auto; display: flex; align-items: center; justify-content: center; gap: 10px;
    min-height: 56px; border: none; background: none; cursor: pointer; padding: 6px; border-radius: var(--r-sm);
    font: inherit; color: var(--navy);
  }
  html.is-app .app-rail-acct-t { display: none; }
  html.is-app .app-top-bar { padding: 0 16px; }
  html.is-app .view { max-width: 720px; margin: 0 auto; }
  html.is-app #view-scope,
  html.is-app #view-analysis,
  html.is-app #view-history,
  html.is-app #view-wrong,
  html.is-app #view-me { max-width: 960px; }
}

@media (min-width: 1024px) {
  html.is-app { --app-rail-w: 240px; }
  html.is-app .app-rail { padding-left: calc(var(--sa-l) + 12px); padding-right: 12px; }
  html.is-app .app-rail-brand { margin: 0 0 14px 8px; }
  html.is-app .app-rail-btn {
    flex-direction: row; justify-content: flex-start; gap: 14px;
    min-height: 52px; padding: 0 16px; font-size: 1rem;
  }
  html.is-app .app-rail-btn .app-badge { position: static; margin-left: auto; }
  html.is-app .app-rail-acct { justify-content: flex-start; padding: 10px 12px; border-top: 1px solid var(--border-lite); border-radius: 0; }
  html.is-app .app-rail-acct-t { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; text-align: left; }
  html.is-app .app-rail-acct-t > span:first-child { font-weight: 900; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  html.is-app .app-rail-acct-t .small { color: var(--ink-muted); }
  html.is-app .view { max-width: 1120px; }
  html.is-app #view-setup,
  html.is-app #view-practice { max-width: 760px; }
}

/* ═══════════════════════════ Toast（6.5）═══════════════════════════ */

html.is-app .toast {
  left: calc(50% + (var(--app-rail-w) + var(--sa-l)) / 2);
  bottom: calc(var(--app-nav-b) + var(--ad-b) + 12px);
  max-width: min(calc(100vw - var(--app-rail-w) - 32px), 520px);
}
html.is-app[data-view="quiz"] .toast { bottom: calc(var(--sa-b) + var(--ad-b) + 84px); }
html.is-app.app-sheet-open .toast { z-index: 90; }

/* ═══════════════════════════ 底部 sheet（6.5）═══════════════════════════ */

html.is-app .app-sheet-wrap {
  position: fixed; inset: 0; z-index: 80;
  display: flex; align-items: flex-end; justify-content: center;
}
html.is-app .app-sheet-scrim {
  position: absolute; inset: 0; background: rgba(15, 37, 72, .4);
  opacity: 0; transition: opacity .2s;
}
html.is-app .app-sheet-wrap.is-on .app-sheet-scrim { opacity: 1; }
html.is-app .app-sheet {
  position: relative; width: 100%;
  max-height: calc(100% - var(--sa-t) - 16px); overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface); border-radius: var(--r-xl) var(--r-xl) 0 0;
  padding: 10px calc(var(--sa-r) + 20px) calc(var(--sa-b) + var(--ad-b) + 24px) calc(var(--sa-l) + 20px);
  transform: translateY(100%); transition: transform .26s cubic-bezier(.2, .8, .2, 1);
  outline: none;
}
html.is-app .app-sheet-wrap.is-on .app-sheet { transform: none; }
html.is-app .app-sheet-grab { width: 40px; height: 5px; margin: 0 auto 12px; border-radius: 3px; background: var(--border); }
html.is-app .app-sheet-x {
  position: absolute; top: 8px; right: calc(var(--sa-r) + 8px);
  width: 44px; height: 44px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--surface-3); color: var(--navy); font-size: 1rem; font-weight: 900;
}
html.is-app .app-sheet-title { font-size: 1.375rem; margin: 6px 52px 12px 0; }
html.is-app .app-sheet-body > p { margin: 0 0 12px; line-height: 1.7; }
@media (min-width: 600px) {
  /* 平板：置中的對話框，寬度上限 560 */
  html.is-app .app-sheet-wrap { align-items: center; padding: calc(var(--sa-t) + 24px) 24px calc(var(--sa-b) + 24px); }
  html.is-app .app-sheet {
    max-width: 560px; max-height: 100%; border-radius: var(--r-xl);
    padding: 20px 28px 28px; transform: translateY(24px); opacity: 0;
    transition: transform .22s, opacity .22s;
  }
  html.is-app .app-sheet-wrap.is-on .app-sheet { opacity: 1; }
  html.is-app .app-sheet-grab { display: none; }
}

/* sheet 裡共用的小元件 */
html.is-app .app-stack { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
html.is-app .app-msg {
  margin: 10px 0; padding: 12px 14px; border-radius: var(--r-sm);
  font-weight: 800; line-height: 1.6; font-size: 0.9375rem;
  background: var(--blue-tint); color: var(--navy);
}
html.is-app .app-msg.is-ok { background: var(--green-tint); color: var(--green-deep); }
html.is-app .app-msg.is-wait { background: var(--amber-tint); color: var(--orange-deep); }
html.is-app .app-msg.is-bad { background: var(--red-tint); color: var(--red-deep); }
html.is-app .app-msg .linklike { color: inherit; font-weight: 900; }

/* ═══════════════════════════ A10 方案頁 ═══════════════════════════ */

html.is-app .app-benefits { list-style: none; margin: 4px 0 16px; padding: 0; display: grid; gap: 8px; }
html.is-app .app-benefits li { display: flex; gap: 10px; align-items: baseline; font-weight: 800; color: var(--navy); }
html.is-app .app-check { color: var(--green-deep); font-weight: 900; }
html.is-app .app-plans { display: grid; gap: 10px; margin-bottom: 14px; }
html.is-app .app-plan {
  display: grid; gap: 2px; text-align: left; cursor: pointer;
  min-height: 72px; padding: 14px 16px; border-radius: var(--r-md);
  border: 2px solid var(--border); background: var(--surface); color: var(--ink); font: inherit;
}
html.is-app .app-plan.is-on { border-color: var(--navy); background: var(--blue-tint); }
html.is-app .app-plan-name { display: flex; align-items: center; gap: 8px; font-weight: 900; color: var(--navy); }
html.is-app .app-plan-tag {
  padding: 1px 8px; border-radius: var(--r-pill); background: var(--cta-tint); color: var(--cta-deep);
  font-size: 0.75rem; font-weight: 900;
}
html.is-app .app-plan-price { font-size: 1.25rem; font-weight: 900; color: var(--navy); }
html.is-app .app-renew { margin: 10px 0 0; line-height: 1.6; }
html.is-app .app-plan-links { display: flex; flex-wrap: wrap; gap: 4px 10px; justify-content: center; align-items: center; margin: 14px 0 0; color: var(--ink-muted); }
html.is-app .app-plan-status { padding: 16px; margin-top: 8px; }
html.is-app .app-plan-status .btn { margin-top: 10px; }
html.is-app .app-plan-loading { display: grid; place-items: center; gap: 8px; padding: 24px 0; }

/* ═══════════════════════════ A1 首頁 ═══════════════════════════ */

html.is-app #app-home { display: flex; flex-direction: column; gap: 14px; }
html.is-app #app-home-body { display: flex; flex-direction: column; gap: 14px; }
html.is-app #app-home .card { margin: 0; }
html.is-app .app-welcome { padding: 20px; }
html.is-app .app-welcome h2 { font-size: 1.375rem; }
html.is-app .app-welcome p { margin: 8px 0 0; }
html.is-app .app-grid2 { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
html.is-app .app-grid2.app-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
html.is-app .app-row-card {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 2px 10px;
  text-align: left; cursor: pointer; padding: 14px 16px; font: inherit; color: var(--ink);
}
html.is-app .app-row-eyebrow { grid-column: 1; font-size: 0.8125rem; font-weight: 900; color: var(--orange-deep); }
html.is-app .app-row-main { grid-column: 1; font-weight: 900; color: var(--navy); }
html.is-app .app-row-card .intent-arrow { grid-column: 2; grid-row: 1 / span 2; color: var(--navy); }
html.is-app .app-cta { display: flex; flex-direction: column; gap: 12px; padding: 18px 20px; }
html.is-app .app-cta h2 { font-size: 1.25rem; }
html.is-app .app-cta p { margin: 4px 0 0; }
html.is-app .app-tile { display: grid; gap: 4px; text-align: left; cursor: pointer; padding: 16px; font: inherit; color: var(--navy); }
html.is-app .app-tile b { font-size: 1.0625rem; }
html.is-app .app-last h3,
html.is-app .app-fams h3 { font-size: 1rem; margin-bottom: 6px; }
html.is-app .app-last p { margin: 0 0 4px; }
html.is-app .app-chips { display: flex; flex-wrap: wrap; gap: 8px; }
html.is-app .app-fam { gap: 6px; }
html.is-app .app-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; background: var(--orange); }
html.is-app .app-dot.is-weak { background: var(--red); }
html.is-app #quick-grade-ask { margin: 0; }
@media (min-width: 600px) {
  html.is-app .app-grid2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  html.is-app .app-cta { flex-direction: row; align-items: center; }
  html.is-app .app-cta .btn { min-width: 160px; }
}

/* ═══════════════════════════ A2 題庫、A3 出題設定 ═══════════════════════════ */

html.is-app .browse { gap: 16px; }
html.is-app .browse-side { position: static; max-width: none; flex-basis: 100%; padding: 16px; gap: 14px; }
html.is-app .browse-side .side-block-grow { display: none; }          /* 章節時間軸：手機上清單本身就是目錄 */
html.is-app #topic-filter { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
html.is-app #topic-filter .chip { flex: none; }
html.is-app .browse-banner { display: block; padding: 16px; }
html.is-app .browse-banner h1 { font-size: 1.375rem; }
html.is-app .chsec-head { gap: 12px; }
html.is-app .chsec h2 { font-size: 1.125rem; }
html.is-app .scope-bar {
  position: sticky; bottom: calc(var(--app-nav-b) + var(--ad-b)); z-index: 20; flex-wrap: nowrap;
  margin: 0 calc(-1 * var(--app-gutter)); padding: 8px var(--app-gutter);
  background: var(--surface); border-top: 1px solid var(--border); border-radius: 0;
}
html.is-app #scope-summary { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (min-width: 600px) {
  html.is-app .scope-bar { margin: 0; border: 1px solid var(--border); border-radius: var(--r-md); bottom: calc(var(--sa-b) + var(--ad-b) + 12px); }
}
html.is-app #btn-scope-next { flex: none; }
@media (max-width: 599px) {
  html.is-app .unit-row2 { grid-template-columns: 40px minmax(0, 1fr) auto; }
  html.is-app .unit-row2 .u-bar { grid-column: 1 / -1; }
  html.is-app .unit-row2 .pill-mastery { display: none; }
  html.is-app .mix-card { padding: 16px; }
}
@media (min-width: 1024px) {
  /* 左欄版本、冊次、主題；右欄章節與小節（A2 平板） */
  html.is-app .browse { flex-wrap: nowrap; }
  html.is-app .browse-side { flex: 0 0 300px; position: sticky; top: calc(var(--sa-t) + var(--app-top-h) + 12px);
    max-height: calc(100vh - var(--sa-t) - var(--app-top-h) - var(--sa-b) - 24px); overflow-y: auto; }
  html.is-app .browse-side .side-block-grow { display: flex; }
  html.is-app #topic-filter { flex-wrap: wrap; }
}
html.is-app .setup { grid-template-columns: minmax(0, 1fr); gap: 14px; }
html.is-app #view-setup .crumb { display: none; }
@media (min-width: 600px) {
  html.is-app #view-setup .setup { max-width: 560px; margin: 0 auto; }
}

/* ═══════════════════════════ A4 作答 ═══════════════════════════ */

html.is-app .quizbar { margin: 0; padding: var(--sa-t) 0 0; top: 0; background: var(--surface); backdrop-filter: none; }
html.is-app .quizbar-in { flex-wrap: nowrap; gap: 10px; padding: 8px var(--app-gutter); }
html.is-app #quiz-tags,
html.is-app #btn-submit,
html.is-app .quiz-side h3,
html.is-app .quiz-side .img-slot { display: none !important; }
html.is-app .quizbar-prog { min-width: 0; cursor: pointer; }
html.is-app .quizbar-meta { justify-content: center; font-size: 0.9375rem; }
html.is-app #btn-abandon { flex: none; }
html.is-app .quiz-timer { flex: none; font-size: 1rem; padding: 6px 10px; }
html.is-app .app-qcard-btn { flex: none; }
html.is-app .quiz-body { padding: 12px var(--app-gutter) calc(var(--sa-b) + var(--ad-b) + 96px); gap: 16px; }
html.is-app .quiz-body .question { padding: 18px; border-radius: var(--r-lg); }
html.is-app .opt { min-height: 56px; border-radius: var(--r-md); }
html.is-app .opt.is-on { border: 2px solid var(--navy); background: var(--blue-tint); }
html.is-app .opt.is-on .opt-key { background: var(--navy); border-color: var(--navy); color: var(--surface); }
/* 對錯不能只靠顏色（6.8、A6）：加上 ✓／✗ */
html.is-app .opt.right::after,
html.is-app .opt.wrong::after {
  flex: none; align-self: center; margin-left: 8px;
  font-weight: 900; font-size: 1.25rem; line-height: 1;
}
html.is-app .opt.right::after { content: '✓'; color: var(--green-deep); }
html.is-app .opt.wrong::after { content: '✗'; color: var(--red-deep); }

/* 手機與窄平板：底部操作列（加上安全區域），答題卡用 sheet */
@media (max-width: 799px) {
  html.is-app .quiz-side {
    position: fixed; left: 0; right: 0; top: auto; bottom: var(--ad-b); z-index: 30; max-width: none;
    padding: 8px calc(var(--sa-r) + var(--app-gutter)) calc(var(--sa-b) + 8px) calc(var(--sa-l) + var(--app-gutter));
    background: var(--surface); border: none; border-top: 1px solid var(--border); border-radius: 0;
  }
  html.is-app .quiz-side .qnav,
  html.is-app .quiz-side .qnav-legend,
  html.is-app #btn-report { display: none !important; }
  html.is-app .quiz-side-actions { flex-direction: row; gap: 8px; }
  html.is-app .quiz-side-actions .btn { flex: 1 1 0; min-width: 0; min-height: 48px; padding-left: 6px; padding-right: 6px; white-space: nowrap; }
  html.is-app #btn-mark { order: 0; }
  html.is-app #btn-prev { order: 1; }
  html.is-app #btn-next { order: 2; }
  html.is-app #btn-submit-bar { order: 3; }
  /* 鍵盤開著時隱藏底部操作列（6.5）：只有非選擇題要打字（「寫過程」暫停中） */
  html.is-app .quiz-body:has(.work-input:focus) .quiz-side { display: none; }
}
@media (max-width: 599px) {
  html.is-app .app-qcard-btn { display: none; }      /* 手機：點「第 3 題」那段打開答題卡 */
  html.is-app #btn-abandon { padding-left: 12px; padding-right: 12px; }
}
/* 平板（≥ 800）：右欄 300 寬放答題卡與按鈕，題目欄最寬 760 */
@media (min-width: 800px) {
  html.is-app .app-qcard-btn { display: none; }
  html.is-app .quiz-body { display: grid; grid-template-columns: minmax(0, 760px) 300px; justify-content: center; align-items: start; padding-bottom: calc(var(--sa-b) + var(--ad-b) + 32px); }
  html.is-app .quiz-side { position: sticky; top: calc(var(--sa-t) + 84px); max-width: none;
    max-height: calc(100vh - var(--sa-t) - var(--sa-b) - 100px); overflow-y: auto; }
  html.is-app .quiz-side .qnav { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
  html.is-app .quiz-side .dot { width: 100%; height: auto; aspect-ratio: 1; margin: 0; }
  html.is-app #quiz-card.app-opts-2 .options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  html.is-app #quiz-card.app-opts-2 .opt { margin: 0; }
}

/* 答題卡（sheet） */
html.is-app .app-qnav { display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); gap: 8px; margin: 4px 0 12px; }
html.is-app .app-qnav .dot { width: 100%; height: 48px; margin: 0; position: relative; }
html.is-app .app-qlegend { flex-direction: row; flex-wrap: wrap; gap: 8px 16px; border-top: none; padding-top: 0; }

/* ═══════════════════════════ A5 結果、A6 練習 ═══════════════════════════ */

html.is-app #view-result .row.no-print,
html.is-app #view-practice .row.no-print { gap: 10px; }
@media (min-width: 1024px) {
  /* 左欄結論與卡住的觀念，右欄其他發現、各單元表現、逐題檢討（A5 平板） */
  html.is-app #result-body { display: grid; grid-template-columns: minmax(340px, 400px) minmax(0, 1fr); gap: 20px; align-items: start; }
  html.is-app .app-res-main { display: flex; flex-direction: column; gap: 14px; }
  html.is-app .app-res-main .verdict { flex-direction: column; align-items: flex-start; }
  html.is-app .app-res-side { min-width: 0; display: flex; flex-direction: column; gap: 14px; }
  html.is-app .app-res-side details.fold:last-child { order: -1; }    /* 逐題檢討排在右欄最上面 */
  html.is-app .app-res-main > *,
  html.is-app .app-res-side > * { margin: 0; }
}
html.is-app .practice-head h1 { font-size: 1.25rem !important; }

/* ═══════════════════════════ A7 錯題本 ═══════════════════════════ */

html.is-app .app-split { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
html.is-app .app-split-detail { display: none; }
html.is-app .app-wb-head h2 { font-size: 1.25rem; }
html.is-app .app-wb-head p { margin: 6px 0 12px; }
html.is-app .app-wfilter { margin: 0; }
html.is-app .app-wrows { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
html.is-app .app-wrow {
  display: grid; gap: 4px; text-align: left; cursor: pointer; font: inherit;
  min-height: 64px; padding: 12px 14px; border-radius: var(--r-md);
  border: 1px solid var(--border); background: var(--surface); color: var(--ink);
}
html.is-app .app-wrow.is-on { border: 2px solid var(--navy); background: var(--blue-tint); }
html.is-app .app-wrow-t { font-weight: 800; color: var(--navy); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
html.is-app .app-wd .review { margin: 8px 0 14px; }
html.is-app .app-wd .review summary .rv-more { display: none; }
html.is-app .app-empty { text-align: center; padding: 28px 20px; }
html.is-app .app-empty h2 { margin: 8px 0; }
@media (min-width: 1024px) {
  html.is-app .app-split { grid-template-columns: minmax(360px, 400px) minmax(0, 1fr); align-items: start; }
  /* 黏在上方的欄比畫面高時，下半部會永遠捲不到：限制高度，欄內自己捲 */
  html.is-app .app-split-detail {
    display: block; position: sticky; top: calc(var(--sa-t) + var(--app-top-h) + 12px); min-height: 240px;
    max-height: calc(100vh - var(--sa-t) - var(--app-top-h) - var(--sa-b) - 24px); overflow-y: auto; overscroll-behavior: contain;
  }
}

/* ═══════════════════════════ A8 分析 ═══════════════════════════ */

html.is-app .app-an-seg { margin: 0 0 14px; }
html.is-app #view-analysis .page-head,
html.is-app #view-history .page-head { margin-bottom: 12px; }
@media (min-width: 600px) {
  /* 手機上一張張往下排的卡，平板改成 2 欄（medium）或 3 欄（expanded） */
  html.is-app #an-body { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; align-items: start; }
  html.is-app #an-body > * { margin: 0; min-width: 0; }
  html.is-app #an-body > .an-stats,
  html.is-app #an-body > .an-card:has(.lm-group),
  html.is-app #an-body > :not(.card) { grid-column: 1 / -1; }
}
@media (min-width: 1024px) {
  html.is-app #an-body { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ═══════════════════════════ A9 我的 ═══════════════════════════ */

html.is-app .app-me { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
html.is-app .app-me-nav { display: none; }
html.is-app .app-me-body { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
html.is-app .app-group-h { font-size: 0.875rem; color: var(--ink-muted); margin: 14px 4px 8px; }
html.is-app .app-me-group:first-child .app-group-h { margin-top: 0; }
html.is-app .app-acct { display: flex; align-items: center; gap: 14px; padding: 16px; margin: 0 0 10px; }
html.is-app .app-acct h2 { font-size: 1.125rem; overflow-wrap: anywhere; }
html.is-app .app-acct p { margin: 2px 0 0; }
html.is-app .app-acct-av { width: 48px; height: 48px; font-size: 1.25rem; }
html.is-app .app-acct .btn { flex: none; white-space: nowrap; }
html.is-app .app-acct-btns { margin: 0 0 10px; }
html.is-app .app-list { padding: 4px 0; margin: 0 0 10px; overflow: hidden; }
html.is-app .app-set-row,
html.is-app .app-link-row,
html.is-app .app-ai-row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  min-height: 56px; padding: 10px 16px; border: none; background: none; font: inherit; color: var(--ink); text-align: left;
}
html.is-app .app-set-row + .app-set-row,
html.is-app .app-link-row + .app-link-row,
html.is-app .app-ai-row + .app-ai-row { border-top: 1px solid var(--border-lite); }
html.is-app .app-link-row { cursor: pointer; font-weight: 800; color: var(--navy); }
html.is-app .app-link-row.is-danger { color: var(--red-deep); }
html.is-app .app-link-row.is-on { background: var(--blue-tint); }
html.is-app .app-set-label { display: block; font-weight: 800; color: var(--navy); }
html.is-app .app-set-row .muted { display: block; }
html.is-app .app-ai-row { display: grid; grid-template-columns: 5.5em minmax(0, 1fr) auto; }
html.is-app .app-time { min-height: 44px; padding: 6px 10px; border-radius: var(--r-xs); border: 2px solid var(--border); font: inherit; color: var(--navy); }
html.is-app .app-fs { flex-wrap: nowrap; }
html.is-app .app-fs .seg-btn { padding: 6px 12px; }
html.is-app .app-ver { text-align: center; margin: 18px 0 0; }
/* 開關（role=switch）：開是海軍藍，關是灰；狀態也寫在 aria-checked，不只靠顏色 */
html.is-app .app-switch {
  flex: none; position: relative; width: 52px; height: 32px; border-radius: 16px; cursor: pointer;
  border: 2px solid var(--ink-faint); background: var(--surface-4);
}
html.is-app .app-switch::before {
  content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--surface); box-shadow: 0 1px 3px rgba(15, 37, 72, .3); transition: left .15s;
}
html.is-app .app-switch[aria-checked="true"] { background: var(--navy); border-color: var(--navy); }
html.is-app .app-switch[aria-checked="true"]::before { left: 23px; }
html.is-app .app-switch::after { content: ''; position: absolute; inset: -8px; }
@media (min-width: 1024px) {
  /* iPad 設定的版型：左欄群組，右欄內容 */
  html.is-app .app-me { grid-template-columns: 280px minmax(0, 1fr); align-items: start; }
  html.is-app .app-me-nav { display: block; padding: 4px 0; position: sticky; top: calc(var(--sa-t) + var(--app-top-h) + 12px); }
  html.is-app .app-me-group:not(.is-on) { display: none; }
  html.is-app .app-me-group .app-group-h { margin-top: 0; }
}

/* ═══════════════════════════ A11 登入、A12 刪除帳號、A13 更新 ═══════════════════════════ */

html.is-app .auth-split { min-height: 0; grid-template-columns: minmax(0, 1fr); background: transparent; }
html.is-app .auth-aside { display: none; }
html.is-app .auth-main { padding: 16px var(--app-gutter) 32px; place-items: start center; }
html.is-app .auth-form-wrap h2 { font-size: 1.5rem; }
@media (min-width: 1024px) {
  html.is-app .auth-split { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  html.is-app .auth-aside { display: flex; border-radius: var(--radius); margin: 16px; }
}
html.is-app .app-del-list { margin: 0 0 10px; padding-left: 1.2em; line-height: 1.8; }

html.is-app #view-update { max-width: 560px; }
html.is-app .app-update { min-height: 70vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; text-align: center; }
html.is-app .app-update h1 { font-size: 1.5rem; }
html.is-app .app-update-mark {
  width: 88px; height: 88px; border-radius: 24px; display: grid; place-items: center;
  background: var(--navy); color: var(--surface); font-size: 2.75rem; font-weight: 900;
}

/* 載入中 */
html.is-app #view-boot .card { margin-top: 24px; }

/* 回報問題的對話框：手機上寬度貼齊、避開安全區域 */
html.is-app .dlg { max-width: calc(100vw - 32px - var(--sa-l) - var(--sa-r)); max-height: calc(100vh - var(--sa-t) - var(--sa-b) - 32px); }

/* 跨裝置同步的說明（底部表單；docs/PLAN-app.md 7.3） */
html.is-app .app-sync-ask .dlg-note p { margin: 0 0 8px; }

/* ═══════════════════════════ 年齡篩選（1.1 版）═══════════════════════════ */

html.is-app .app-age { display: grid; gap: 10px; margin: 14px 0 6px; }
html.is-app .app-age-opt {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 52px; padding: 10px 16px; text-align: left; font: inherit; font-weight: 800; color: var(--ink);
  background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--r-md); cursor: pointer;
}
html.is-app .app-age-opt[aria-pressed="true"] { border-color: var(--navy); background: var(--blue-tint, #eef3fb); }
html.is-app .app-age-opt[aria-pressed="true"]::after { content: '✓'; color: var(--navy); }
html.is-app .app-age-opt:focus-visible { outline: 3px solid var(--navy); outline-offset: 2px; }
/* 年齡畫面不能被滑掉或點背景關掉：選項裡有「不想回答」，所以一定出得去 */
html.is-app .app-sheet-wrap.is-modal .app-sheet-x { display: none; }

/* 還沒登入時頭像裡的人像圖示：比 24px 的分頁圖示小一點，置中在圓裡 */
html.is-app .avatar .app-ic-p { width: 60%; height: 60%; stroke-width: 2; }

/* 手機：分頁列、作答操作列貼最底（橫幅在頂部，不推它們）；放在最後面，才蓋得過上面各處原本的 bottom／padding-bottom */
@media (max-width: 599px) {
  html.is-app body { padding-bottom: max(var(--app-nav-b), calc(var(--sa-b) + var(--ad-b) + 8px)); }      
  html.is-app .app-tabbar { bottom: 0; }
  html.is-app .toast { bottom: calc(max(var(--app-nav-b), calc(var(--sa-b) + var(--ad-b))) + 12px); }
  html.is-app[data-view="quiz"] .toast { bottom: calc(var(--sa-b) + max(var(--ad-b), 56px) + 12px); }
  html.is-app .quiz-side { bottom: 0; padding-top: 6px; padding-bottom: calc(var(--sa-b) + 5px); }
  html.is-app .quiz-side-actions .btn { min-height: 44px; }      /* 操作列收緊：加上上下 6px、5px 和 1px 框線剛好 56px，和分頁列同高 */
  html.is-app .scope-bar { bottom: max(var(--app-nav-b), calc(var(--sa-b) + var(--ad-b))); }
}

/* 進場動畫 rise 用 fill-mode both，結束後 transform 還是「有效」的，會讓畫面裡 position: fixed 的東西
 * （作答的操作列）改以這個區塊為基準，而不是螢幕：題目短、區塊比螢幕矮時，操作列就浮在半空、底下留一片空白。
 * App 裡改成只在開始前套用（backwards），結束後不留 transform。 */
html.is-app .view { animation-fill-mode: backwards; }
