/* ==========================================================================
   CET-4 趣味練習 App — styles.css
   單頁式 / 完全離線 / 深色優先（body.light 為淺色覆寫）
   無任何外部資源：無 @import、無 CDN、無字型檔、無圖片檔（圖示皆為 emoji 或 CSS 繪製）
   --------------------------------------------------------------------------
   0.  主題變數（:root / body.light）
   1.  Reset 與基礎
   2.  版面骨架 #app-shell / #topbar / #xp-bar / .view
   3.  首頁模式卡 .mode-card（CSS Grid）
   4.  作答區 #view-quiz（.q-card / MCQ / cloze / 長篇匹配）
   5.  寫作與翻譯（.writing-box / .analysis-list / .pattern-item）
   6.  通用元件（.btn / .chip / .badge / .progress-ring / .stat-grid / .combo / .timer）
   7.  結果、單字本、統計頁
   8.  回饋層 #toast / #fx / #modal
   9.  動畫 keyframes
   10. 響應式 media queries
   11. 列印樣式 @media print
   ========================================================================== */

/* ==========================================================================
   0. 主題變數
   ========================================================================== */

:root {
  /* 表面 */
  --bg: #0d1017;
  --bg-soft: #141924;
  --card: #171d29;
  --card-2: #1d2533;
  --card-hover: #222b3b;
  --line: #28324a;
  --line-strong: #3b4763;

  /* 文字 */
  --text: #eef2f9;
  --muted: #9aa6bd;
  --muted-2: #7c879e;

  /* 主題色 */
  --accent: #6d8cff;
  --accent-2: #a97bff;
  --accent-soft: rgba(109, 140, 255, 0.16);
  --accent-line: rgba(109, 140, 255, 0.42);
  --accent-text: #ffffff;

  /* 語意色 */
  --ok: #3bc98a;
  --bad: #ff6b7f;
  --warn: #f6c453;
  --ok-soft: rgba(59, 201, 138, 0.18);
  --bad-soft: rgba(255, 107, 127, 0.18);
  --warn-soft: rgba(246, 196, 83, 0.18);

  /* 形狀與陰影 */
  --radius: 16px;
  --radius-lg: 22px;
  --radius-sm: 10px;
  --radius-pill: 999px;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.38);
  --shadow-sm: 0 4px 14px rgba(0, 0, 0, 0.28);
  --shadow-ring: 0 0 0 3px rgba(109, 140, 255, 0.35);

  /* 漸層 */
  --grad-top: linear-gradient(120deg, #1b2333 0%, #171d29 55%, #1a1f2e 100%);
  --grad-accent: linear-gradient(90deg, #6d8cff 0%, #a97bff 100%);
  --grad-ok: linear-gradient(90deg, #2fae77 0%, #4dd39a 100%);

  /* 版面 */
  --topbar-h: 58px;
  --shell-max: 1040px;
  --gap: 16px;
  --z-topbar: 40;
  --z-fx: 60;
  --z-toast: 70;
  --z-modal: 80;
}

body.light {
  --bg: #f2f5fb;
  --bg-soft: #e9eef8;
  --card: #ffffff;
  --card-2: #f4f7fd;
  --card-hover: #eef3ff;
  --line: #dde4f0;
  --line-strong: #c3cee0;

  --text: #172033;
  --muted: #5d6a80;
  --muted-2: #7b879c;

  --accent: #3f63f0;
  --accent-2: #8a4ff0;
  --accent-soft: rgba(63, 99, 240, 0.12);
  --accent-line: rgba(63, 99, 240, 0.38);
  --accent-text: #ffffff;

  --ok: #159c62;
  --bad: #d93b52;
  --warn: #b8801a;
  --ok-soft: rgba(21, 156, 98, 0.14);
  --bad-soft: rgba(217, 59, 82, 0.14);
  --warn-soft: rgba(184, 128, 26, 0.16);

  --shadow: 0 12px 28px rgba(28, 45, 82, 0.14);
  --shadow-sm: 0 4px 14px rgba(28, 45, 82, 0.10);
  --shadow-ring: 0 0 0 3px rgba(63, 99, 240, 0.28);

  --grad-top: linear-gradient(120deg, #ffffff 0%, #f3f7ff 60%, #eef2fb 100%);
  --grad-accent: linear-gradient(90deg, #3f63f0 0%, #8a4ff0 100%);
  --grad-ok: linear-gradient(90deg, #159c62 0%, #3ec98d 100%);
}

/* ==========================================================================
   1. Reset 與基礎
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, "Segoe UI", "Microsoft JhengHei", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background-color: var(--bg);
  background-image:
    radial-gradient(900px 520px at 12% -10%, var(--accent-soft), transparent 70%),
    radial-gradient(760px 460px at 100% 0%, rgba(169, 123, 255, 0.10), transparent 72%);
  background-repeat: no-repeat;
  background-attachment: fixed;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}

h1, h2, h3, h4 {
  margin: 0 0 8px;
  line-height: 1.3;
  font-weight: 700;
  letter-spacing: 0.01em;
}

p { margin: 0 0 10px; }
ul, ol { margin: 0 0 10px; padding-left: 1.25em; }
small { font-size: 0.82rem; }
strong { font-weight: 700; }
em { font-style: normal; color: var(--accent); }

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 16px 0;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button { cursor: pointer; }

/* 全站清楚的焦點框（鍵盤操作） */
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* 捲軸（漸進增強，不影響其他瀏覽器） */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: var(--radius-pill);
  border: 2px solid transparent;
  background-clip: content-box;
}

/* ==========================================================================
   2. 版面骨架
   ========================================================================== */

#app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  width: 100%;
  max-width: var(--shell-max);
  margin: 0 auto;
  padding: 0 16px calc(28px + env(safe-area-inset-bottom, 0px));
  position: relative;
}

/* ---------- #topbar ---------- */

#topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-topbar);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  min-height: var(--topbar-h);
  margin: 0 -16px 14px;
  padding: 10px 16px;
  background: var(--grad-top);
  border-bottom: 1px solid var(--line);
  backdrop-filter: saturate(140%) blur(10px);
  -webkit-backdrop-filter: saturate(140%) blur(10px);
}

/* 三區塊：左（首頁鈕＋品牌）／中（標題＋副標）／右（統計與工具鈕） */
#topbar .topbar-left,
#topbar .topbar-mid,
#topbar .topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

#topbar .topbar-left { flex: 0 0 auto; }
#topbar .topbar-mid {
  flex: 1 1 auto;
  flex-direction: column;
  align-items: flex-start;
  gap: 0;
  min-width: 0;
  overflow: hidden;
}
#topbar .topbar-right { flex: 0 0 auto; flex-wrap: wrap; justify-content: flex-end; }

#topbar h1,
#topbar #app-title,
#topbar .app-title,
#topbar > strong {
  font-size: 1.02rem;
  font-weight: 700;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* 副標（長說明）在小螢幕可省略 */
#topbar #tagline,
#topbar .tagline {
  margin: 0;
  font-size: 0.74rem;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

#topbar .brand {
  display: inline-flex;
  align-items: center;
  height: 30px;
  padding: 0 10px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--accent-text);
  background: var(--grad-accent);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-sm);
  white-space: nowrap;
}

/* 任何未特別指名的頂部列按鈕（如 #btn-book / #btn-stats）比照膠囊樣式 */
#topbar button {
  flex: 0 0 auto;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 14px;
  font-size: 0.86rem;
  font-weight: 600;
  white-space: nowrap;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-sm);
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

#topbar button:hover {
  transform: translateY(-1px);
  background: var(--card-hover);
  border-color: var(--accent-line);
}

#topbar button:active { transform: scale(0.97); }
#topbar button[aria-pressed="false"] { color: var(--muted); opacity: 0.82; }

#btn-home {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: auto;
  min-width: 40px;
  min-height: 38px;
  padding: 0 12px;
  font-size: 1.05rem;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-sm);
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}
#btn-home:hover {
  transform: translateY(-1px);
  background: var(--card-hover);
  border-color: var(--accent-line);
}
#btn-home:active { transform: translateY(0) scale(0.96); }

/* 回到「學習練習站」入口頁（跨站連結，用虛線框與 App 內部按鈕區分） */
#btn-site-home, #btn-campaign {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 12px;
  font-size: 0.86rem;
  font-weight: 600;
  white-space: nowrap;
  color: var(--muted);
  background: var(--card);
  border: 1px dashed var(--line);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-sm);
  text-decoration: none;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease, color 0.18s ease;
}
#btn-site-home:hover, #btn-campaign:hover {
  transform: translateY(-1px);
  color: var(--text);
  background: var(--card-hover);
  border-color: var(--accent-line);
}
#btn-site-home:active, #btn-campaign:active { transform: translateY(0) scale(0.96); }

/* 闖關版入口：用實線+主題色，與練習版區分 */
#btn-campaign { border-style: solid; border-color: var(--accent-line); color: var(--text); }
#btn-campaign:hover { background: var(--card-hover); }

/* ---------- 中文輔助區塊（看不懂英文時可展開對照） ---------- */
.q-zh { margin: 6px 0 10px; }
.q-zh-head { display: flex; gap: 8px; align-items: center; }
.q-zh-toggle { font-size: 0.86rem; font-weight: 600; }
.q-zh-body {
  margin-top: 8px;
  padding: 12px 14px;
  background: var(--card);
  border: 1px dashed var(--accent-line, var(--line));
  border-radius: 10px;
}
.q-zh-sec + .q-zh-sec { margin-top: 12px; }
.q-zh-h {
  margin: 0 0 4px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.06em;
}
.q-zh-p { margin: 0; font-size: 0.93rem; line-height: 1.75; }
.q-zh-list,
.q-zh-vocab { margin: 0; padding-left: 1.25em; font-size: 0.9rem; line-height: 1.75; }
.q-zh-list li,
.q-zh-vocab li { margin: 3px 0; }
.q-zh-pos { color: var(--muted); font-size: 0.82rem; }
.q-zh-sent { margin: 0; padding-left: 1.4em; font-size: 0.9rem; line-height: 1.7; }
.q-zh-sent li { margin: 8px 0; }
.q-zh-en { display: block; color: var(--muted); font-size: 0.86rem; }
.q-zh-zh { display: block; margin-top: 2px; }

/* 右上統計膠囊：#level / #score / #streak / 音效鈕 / #btn-theme */
#level,
#score,
#streak,
#btn-sound,
#btn-theme {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 34px;
  padding: 4px 12px;
  font-size: 0.86rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-sm);
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

#level { color: var(--accent); border-color: var(--accent-line); }
#score { color: var(--warn); }
#streak { color: var(--bad); }

#btn-sound,
#btn-theme {
  width: auto;
  min-width: 40px;
  padding: 0 12px;
  font-size: 1.02rem;
  cursor: pointer;
}
#btn-sound:hover,
#btn-theme:hover {
  transform: translateY(-1px);
  background: var(--card-hover);
  border-color: var(--accent-line);
}
#btn-sound:active,
#btn-theme:active { transform: scale(0.96); }

/* 音效關閉時（JS 可切換 .muted / .off / aria-pressed） */
#btn-sound.muted,
#btn-sound.off,
#btn-theme.off,
[aria-pressed="false"]#btn-sound {
  color: var(--muted);
  opacity: 0.72;
}

/* 深色模式鈕可顯示目前狀態 */
body.light #btn-theme { color: var(--warn); border-color: rgba(184, 128, 26, 0.4); }

/* ---------- #xp-bar ---------- */

#xp-bar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin: 2px 0 18px;
  padding: 8px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

#xp-fill {
  height: 12px;
  width: 0%;
  min-width: 0;
  border-radius: var(--radius-pill);
  background: var(--grad-accent);
  background-size: 200% 100%;
  box-shadow: 0 0 14px var(--accent-soft);
  transition: width 0.3s ease;
  position: relative;
  z-index: 1;
}

#xp-fill::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.35), transparent);
  opacity: 0.5;
}

#xp-text {
  flex: 0 0 auto;
  margin-left: auto;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  z-index: 2;
}

/* 若 JS 把 #xp-text 放進 #xp-bar 內當唯一子元素，仍能呈現進度感 */
#xp-bar > #xp-fill:last-child { flex: 1 1 auto; }

/* ---------- .view ---------- */

.view {
  display: block;
  width: 100%;
  animation: viewIn 0.25s ease both;
}

[hidden],
.view[hidden],
.hidden {
  display: none !important;
}

#view-container {
  display: block;
  width: 100%;
}

#app-foot {
  margin-top: 28px;
  padding: 16px 4px 0;
  border-top: 1px solid var(--line);
  text-align: center;
  font-size: 0.78rem;
  color: var(--muted-2);
}

#app-foot p { margin: 0; }

.view > h2,
#view-home > h2 {
  font-size: 1.15rem;
  margin-bottom: 12px;
}

.view-sub,
.hint {
  color: var(--muted);
  font-size: 0.9rem;
}

/* ==========================================================================
   3. 首頁模式卡 .mode-card（桌面 4 欄 / 平板 2 欄 / 手機 1 欄）
   ========================================================================== */

#view-home {
  display: block;
  width: 100%;
}

#view-home > h2 { margin-bottom: 14px; }

/* 模式卡網格：桌面 4 欄 */
.mode-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--gap);
  align-items: stretch;
  width: 100%;
}

/* 若 JS 直接以 #view-home 當容器（無 .mode-grid 包裹），仍維持網格 */
#view-home:not(:has(.mode-grid)) {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--gap);
  align-items: start;
}

#view-home:not(:has(.mode-grid)) > h1,
#view-home:not(:has(.mode-grid)) > h2,
#view-home:not(:has(.mode-grid)) > .view-sub,
#view-home:not(:has(.mode-grid)) > .hint,
#view-home:not(:has(.mode-grid)) > p {
  grid-column: 1 / -1;
}

/* 無 :has() 支援時（舊瀏覽器）仍以 4 欄顯示卡片 */
@supports not (selector(:has(*))) {
  #view-home {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: var(--gap);
    align-items: start;
  }
  #view-home > h1,
  #view-home > h2,
  #view-home > .view-sub,
  #view-home > .hint,
  #view-home > p { grid-column: 1 / -1; }
}

.mode-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  width: 100%;
  min-height: 132px;
  padding: 16px;
  text-align: left;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition: transform 0.18s ease, box-shadow 0.2s ease,
              border-color 0.2s ease, background 0.2s ease;
}

.mode-card:hover {
  transform: translateY(-4px);
  background: var(--card-hover);
  border-color: var(--accent-line);
  box-shadow: var(--shadow);
}

.mode-card:active { transform: translateY(-1px) scale(0.99); }

.mode-card:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.mode-card .mode-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  font-size: 1.5rem;
  line-height: 1;
  border-radius: 14px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
}

.mode-card .mode-title {
  font-size: 1.02rem;
  font-weight: 700;
}

.mode-card .mode-desc {
  font-size: 0.86rem;
  color: var(--muted);
  line-height: 1.5;
}

/* 各模式一點色彩暗示（讓卡片牆更好辨識） */
.mode-card[data-mode="daily"] .mode-icon { background: var(--accent-soft); border-color: var(--accent-line); }
.mode-card[data-mode="listening"] .mode-icon { background: var(--warn-soft); border-color: rgba(246, 196, 83, 0.42); }
.mode-card[data-mode="reading-cloze"] .mode-icon,
.mode-card[data-mode="reading-match"] .mode-icon,
.mode-card[data-mode="reading-careful"] .mode-icon { background: var(--ok-soft); border-color: rgba(59, 201, 138, 0.42); }
.mode-card[data-mode="writing"] .mode-icon,
.mode-card[data-mode="translation"] .mode-icon { background: var(--bad-soft); border-color: rgba(255, 107, 127, 0.42); }
.mode-card[data-mode="review"] .mode-icon { background: rgba(169, 123, 255, 0.16); border-color: rgba(169, 123, 255, 0.42); }

/* 完成狀態（JS 可加 .done / [data-done="1"]） */
.mode-card.done,
.mode-card[data-done="1"] { border-color: var(--ok); }
.mode-card.done .mode-title::after,
.mode-card[data-done="1"] .mode-title::after {
  content: "✓";
  margin-left: 6px;
  color: var(--ok);
}

/* ==========================================================================
   4. 作答區
   ========================================================================== */

#view-quiz {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

#quiz-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

#quiz-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 120px;
}

#quiz-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
  padding-top: 4px;
  border-top: 1px solid var(--line);
  margin-top: 4px;
  padding-top: 14px;
}

#quiz-foot .btn-primary { min-width: 132px; }

/* ---------- 題目卡 ---------- */

.q-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.q-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--muted);
}

.q-stem {
  font-size: 1.06rem;
  font-weight: 600;
  line-height: 1.65;
}

.q-stem .blank-inline,
.q-stem u {
  text-decoration: none;
  border-bottom: 2px dashed var(--accent-line);
  padding: 0 4px;
}

/* ---------- MCQ 選項 ---------- */

.q-options {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.opt {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  padding: 12px 14px;
  text-align: left;
  font-size: 0.98rem;
  line-height: 1.55;
  color: var(--text);
  background: var(--card-2);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  transition: transform 0.16s ease, border-color 0.18s ease,
              background 0.18s ease, box-shadow 0.18s ease;
}

.opt:hover {
  transform: translateY(-2px);
  background: var(--card-hover);
  border-color: var(--accent-line);
  box-shadow: var(--shadow-sm);
}

.opt:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.opt::before {
  content: counter(opt-item, upper-alpha);
  counter-increment: opt-item;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
}

.q-options { counter-reset: opt-item; }

.opt.correct {
  background: var(--ok-soft);
  border-color: var(--ok);
  color: var(--text);
}
.opt.correct::before {
  content: "✓";
  counter-increment: none;
  color: #fff;
  background: var(--ok);
  border-color: var(--ok);
}

.opt.wrong {
  background: var(--bad-soft);
  border-color: var(--bad);
  animation: shake 0.36s ease;
}
.opt.wrong::before {
  content: "✕";
  counter-increment: none;
  color: #fff;
  background: var(--bad);
  border-color: var(--bad);
}

.opt.disabled,
.opt[disabled],
.opt[aria-disabled="true"] {
  pointer-events: none;
  opacity: 0.62;
}
.opt.disabled.correct,
.opt.disabled.wrong { opacity: 1; }

/* ---------- 解析 ---------- */

.q-explain {
  padding: 12px 14px;
  font-size: 0.92rem;
  line-height: 1.7;
  color: var(--text);
  background: var(--card-2);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm);
}

.q-explain b,
.q-explain strong { color: var(--accent); }

/* ==========================================================================
   4b. 選詞填空
   ========================================================================== */

.cloze-passage {
  padding: 16px 18px;
  font-size: 1.02rem;
  line-height: 2.15;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  letter-spacing: 0.01em;
}

.blank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 92px;
  min-height: 34px;
  margin: 0 4px;
  padding: 2px 10px;
  font-size: 0.95rem;
  font-weight: 600;
  vertical-align: baseline;
  color: var(--muted);
  background: var(--card);
  border: 2px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  transition: background 0.18s ease, border-color 0.18s ease,
              color 0.18s ease, transform 0.16s ease;
}

.blank:hover {
  transform: translateY(-1px);
  color: var(--text);
  border-color: var(--accent-line);
  background: var(--card-hover);
}

.blank:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.blank.active {
  color: var(--text);
  background: var(--accent-soft);
  border-color: var(--accent);
  border-style: solid;
  box-shadow: var(--shadow-ring);
  animation: blankPulse 1.3s ease-in-out infinite;
}

.blank.filled {
  color: var(--text);
  background: var(--card-hover);
  border-style: solid;
  border-color: var(--accent-line);
}

.blank.correct {
  color: #ffffff;
  background: var(--ok);
  border-style: solid;
  border-color: var(--ok);
  animation: pop 0.28s ease;
}

.blank.wrong {
  color: #ffffff;
  background: var(--bad);
  border-style: solid;
  border-color: var(--bad);
  animation: shake 0.4s ease;
}

.blank.correct:focus-visible,
.blank.wrong:focus-visible { outline: 3px solid var(--text); }

/* ---------- 詞庫 ---------- */

.word-bank {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 14px;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  min-height: 62px;
}

.word-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 0.94rem;
  font-weight: 600;
  color: var(--text);
  background: var(--card);
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-sm);
  transition: transform 0.16s ease, background 0.18s ease,
              border-color 0.18s ease, opacity 0.2s ease;
}

.word-chip:hover {
  transform: translateY(-2px);
  background: var(--card-hover);
  border-color: var(--accent);
}

.word-chip:active { transform: translateY(0) scale(0.97); }
.word-chip:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.word-chip.used,
.word-chip[disabled] {
  opacity: 0.42;
  color: var(--muted);
  background: var(--card-2);
  border-color: var(--line);
  box-shadow: none;
  pointer-events: none;
  text-decoration: line-through;
  transform: none;
}

/* ==========================================================================
   4c. 長篇匹配
   ========================================================================== */

.para-list,
.stmt-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.para {
  padding: 14px 16px;
  font-size: 0.96rem;
  line-height: 1.75;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--line-strong);
  border-radius: var(--radius-sm);
}

.para-label {
  display: inline-block;
  margin-right: 8px;
  padding: 1px 9px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  border-radius: var(--radius-pill);
}

.stmt {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px 14px;
  font-size: 0.96rem;
  line-height: 1.6;
  background: var(--card-2);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  transition: border-color 0.18s ease, background 0.18s ease;
}

.stmt:hover { border-color: var(--accent-line); background: var(--card-hover); }

.stmt.correct { border-color: var(--ok); background: var(--ok-soft); }
.stmt.wrong { border-color: var(--bad); background: var(--bad-soft); }

.stmt-select {
  flex: 0 0 auto;
  margin-left: auto;
  min-width: 84px;
  padding: 7px 12px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  background: var(--card);
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color 0.18s ease, background 0.18s ease;
}

.stmt-select:hover { border-color: var(--accent); background: var(--card-hover); }
.stmt-select:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.stmt-select option { color: #172033; background: #ffffff; }

/* ==========================================================================
   5. 寫作與翻譯
   ========================================================================== */

.writing-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.writing-area {
  width: 100%;
  min-height: 200px;
  padding: 14px 16px;
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.85;
  color: var(--text);
  background: var(--card-2);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  resize: vertical;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.writing-area::placeholder { color: var(--muted-2); }

.writing-area:hover { border-color: var(--line-strong); }

.writing-area:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--card);
  box-shadow: var(--shadow-ring);
}

.word-count {
  align-self: flex-end;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.word-count.ok { color: var(--ok); }
.word-count.warn { color: var(--warn); }
.word-count.over { color: var(--bad); }

.model-answer {
  padding: 14px 16px;
  font-size: 0.95rem;
  line-height: 1.85;
  color: var(--text);
  background: var(--ok-soft);
  border: 1px solid var(--ok);
  border-radius: var(--radius);
  white-space: pre-wrap;
}

.model-answer::before {
  content: "範文 / Model Answer";
  display: block;
  margin-bottom: 8px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ok);
}

.analysis-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: analysis-item;
}

.analysis-list > li {
  position: relative;
  padding: 10px 12px 10px 40px;
  font-size: 0.92rem;
  line-height: 1.7;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  counter-increment: analysis-item;
}

.analysis-list > li::before {
  content: counter(analysis-item);
  position: absolute;
  left: 10px;
  top: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  font-size: 0.72rem;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  border-radius: var(--radius-pill);
}

.pattern-item {
  padding: 12px 14px;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent-2);
  border-radius: var(--radius-sm);
}

.pattern-item .pattern-en,
.pattern-item b,
.pattern-item strong {
  display: block;
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--accent);
}

.pattern-item .pattern-zh,
.pattern-item span {
  display: block;
  margin-top: 4px;
  font-size: 0.88rem;
  color: var(--muted);
}

/* ==========================================================================
   6. 通用元件
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 9px 18px;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.2;
  color: var(--text);
  background: var(--card-2);
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-sm);
  transition: transform 0.16s ease, background 0.18s ease,
              border-color 0.18s ease, box-shadow 0.18s ease, opacity 0.18s ease;
}

.btn:hover {
  transform: translateY(-2px);
  background: var(--card-hover);
  border-color: var(--accent-line);
}

.btn:active { transform: translateY(0) scale(0.98); }
.btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.btn[disabled],
.btn.disabled,
.btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
  pointer-events: none;
}

.btn-primary {
  color: var(--accent-text);
  background: var(--grad-accent);
  border-color: transparent;
  box-shadow: 0 8px 20px var(--accent-soft);
}

.btn-primary:hover {
  color: var(--accent-text);
  background: var(--grad-accent);
  border-color: transparent;
  filter: brightness(1.06);
  box-shadow: 0 10px 26px var(--accent-soft);
}

.btn-ghost {
  color: var(--muted);
  background: transparent;
  border-color: var(--line);
  box-shadow: none;
}

.btn-ghost:hover {
  color: var(--text);
  background: var(--accent-soft);
  border-color: var(--accent-line);
}

/* 小尺寸按鈕（JS 可搭配 .btn.btn-sm 使用） */
.btn.btn-sm {
  min-height: 34px;
  padding: 5px 12px;
  font-size: 0.84rem;
}

.btn-row,
.row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  white-space: nowrap;
}

.chip.accent,
.chip.on {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent-line);
}

.chip.ok { color: var(--ok); background: var(--ok-soft); border-color: var(--ok); }
.chip.warn { color: var(--warn); background: var(--warn-soft); border-color: var(--warn); }
.chip.bad { color: var(--bad); background: var(--bad-soft); border-color: var(--bad); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition: transform 0.18s ease, border-color 0.18s ease;
}

.badge:hover { transform: translateY(-2px); border-color: var(--accent-line); }

.badge-locked,
.badge.locked {
  color: var(--muted);
  background: var(--card-2);
  border-style: dashed;
  box-shadow: none;
  filter: grayscale(0.6);
}

.badge-locked::before,
.badge.locked::before {
  content: "🔒";
  font-size: 0.95rem;
}

.badge::before { font-size: 1.05rem; }

.progress-ring {
  --pct: 0;
  --ring-size: 84px;
  --ring-width: 8px;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--ring-size);
  height: var(--ring-size);
  border-radius: 50%;
  flex: 0 0 auto;
  background:
    conic-gradient(var(--accent) calc(var(--pct) * 1%), var(--card-2) 0);
  transition: background 0.3s ease;
}

.progress-ring::before {
  content: "";
  position: absolute;
  inset: var(--ring-width);
  border-radius: 50%;
  background: var(--card);
}

.progress-ring > * {
  position: relative;
  z-index: 1;
  font-size: 0.9rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  width: 100%;
}

.stat-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px;
  text-align: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.stat-cell .stat-value,
.stat-cell b,
.stat-cell strong {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.stat-cell .stat-label,
.stat-cell span,
.stat-cell small {
  font-size: 0.8rem;
  color: var(--muted);
}

.combo {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  padding: 4px 14px;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: #fff;
  background: linear-gradient(120deg, var(--warn), #ff8a4c);
  border-radius: var(--radius-pill);
  box-shadow: 0 8px 22px var(--warn-soft);
  transform-origin: center;
  animation: comboPop 0.42s cubic-bezier(0.22, 1.4, 0.36, 1) both;
}

.combo small { font-size: 0.72rem; font-weight: 700; opacity: 0.92; }

.timer {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--text);
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  font-variant-numeric: tabular-nums;
}

.timer::before { content: "⏱"; font-size: 0.9rem; }

.timer.warn { color: var(--warn); background: var(--warn-soft); border-color: var(--warn); }
.timer.danger,
.timer.bad {
  color: var(--bad);
  background: var(--bad-soft);
  border-color: var(--bad);
  animation: pulseSoft 1s ease-in-out infinite;
}

/* ==========================================================================
   7. 結果 / 單字本 / 統計
   ========================================================================== */

#view-result,
#view-book,
#view-stats {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

#result-body,
#book-body,
#stats-body,
#badges-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

#result-body > .card,
#book-body > .card,
#stats-body > .card {
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.result-score,
.result-headline {
  font-size: 2rem;
  font-weight: 800;
  text-align: center;
  background: var(--grad-accent);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* 結果頁可用的評語色 */
.result-headline.good { color: var(--ok); -webkit-text-fill-color: var(--ok); background: none; }
.result-headline.mid { color: var(--warn); -webkit-text-fill-color: var(--warn); background: none; }
.result-headline.low { color: var(--bad); -webkit-text-fill-color: var(--bad); background: none; }

/* 單字本條目（JS 產生 .word-item） */
.word-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  transition: border-color 0.18s ease, transform 0.18s ease;
}

.word-item:hover { transform: translateY(-2px); border-color: var(--accent-line); }

.word-item .word-en { font-size: 1rem; font-weight: 700; color: var(--accent); }
.word-item .word-zh { font-size: 0.88rem; color: var(--muted); }

/* ==========================================================================
   8. 回饋層：#toast / #fx / #modal
   ========================================================================== */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  z-index: var(--z-toast);
  max-width: min(88vw, 460px);
  padding: 11px 20px;
  font-size: 0.92rem;
  font-weight: 600;
  text-align: center;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow);
  transform: translate(-50%, 12px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

#toast.show,
#toast.visible,
#toast.on {
  opacity: 1;
  transform: translate(-50%, 0);
}

#toast.ok { border-color: var(--ok); color: var(--ok); }
#toast.bad { border-color: var(--bad); color: var(--bad); }
#toast.warn { border-color: var(--warn); color: var(--warn); }

/* canvas 特效層：全螢幕、不吃事件、高於內容但低於 #modal */
#fx {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: var(--z-fx);
  pointer-events: none;
  display: block;
  object-fit: contain;
}

#modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(6, 9, 15, 0.62);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fadeIn 0.2s ease both;
}

#modal[hidden] { display: none !important; }

#modal-body {
  width: 100%;
  max-width: 520px;
  max-height: 86vh;
  overflow-y: auto;
  padding: 20px;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  animation: modalIn 0.26s cubic-bezier(0.22, 1.2, 0.36, 1) both;
}

#modal-body h2,
#modal-body h3 { margin-top: 0; }

#modal-body .modal-actions,
#modal-body .btn-row {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

/* 外層 .modal-panel 結構（index.html 實機標記） */
.modal-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow: hidden;
  padding: 18px 20px 20px;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  animation: modalIn 0.26s cubic-bezier(0.22, 1.2, 0.36, 1) both;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.modal-head h2,
.modal-head h3 { margin: 0; font-size: 1.05rem; }

#modal-close {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  font-size: 0.95rem;
  color: var(--muted);
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  transition: transform 0.16s ease, color 0.18s ease, border-color 0.18s ease;
}

#modal-close:hover { transform: rotate(90deg); color: var(--bad); border-color: var(--bad); }

/* 面板內本文可滾動，標題列固定 */
.modal-panel > #modal-body { overflow-y: auto; }

/* ==========================================================================
   9. 動畫 keyframes
   ========================================================================== */

@keyframes viewIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(14px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-5px); }
  30% { transform: translateX(5px); }
  45% { transform: translateX(-4px); }
  60% { transform: translateX(4px); }
  80% { transform: translateX(-2px); }
}

@keyframes pop {
  0% { transform: scale(0.9); }
  60% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

@keyframes comboPop {
  0% { transform: scale(0.5) rotate(-6deg); opacity: 0; }
  60% { transform: scale(1.22) rotate(2deg); opacity: 1; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

@keyframes blankPulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(109, 140, 255, 0.22); }
  50% { box-shadow: 0 0 0 6px rgba(109, 140, 255, 0.10); }
}

@keyframes pulseSoft {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.62; }
}

@keyframes xpShine {
  from { background-position: 0% 50%; }
  to { background-position: 100% 50%; }
}

/* 過場 / 進場動畫 */
.fade-in {
  animation: fadeInUp 0.25s ease both;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* 交錯進場（卡片牆）：JS 可加 .stagger 或內嵌 --i */
.stagger > * {
  animation: fadeInUp 0.25s ease both;
  animation-delay: calc(var(--i, 0) * 40ms);
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ==========================================================================
   10. 響應式
   ========================================================================== */

/* 平板：模式卡 2 欄 */
@media (max-width: 960px) {
  .mode-grid,
  #view-home:not(:has(.mode-grid)),
  #view-home { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  #topbar #tagline,
  #topbar .tagline { display: none; }

  #topbar .brand { display: none; }

  .q-options { grid-template-columns: 1fr; }

  :root { --shell-max: 100%; }
}

/* 桌機加大時，選項可雙欄（字少時更緊湊） */
@media (min-width: 961px) {
  .q-options.two-col,
  .q-options.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* 手機：模式卡 1 欄、字級略降、頂部列縮小 */
@media (max-width: 640px) {
  body { font-size: 15px; }

  :root {
    --gap: 12px;
    --radius: 14px;
    --radius-lg: 18px;
    --topbar-h: 50px;
  }

  #app-shell { padding: 0 12px calc(24px + env(safe-area-inset-bottom, 0px)); }

  #topbar {
    gap: 6px;
    margin: 0 -12px 12px;
    padding: 8px 12px;
  }

  #topbar h1,
  #topbar .app-title,
  #topbar > strong { font-size: 0.95rem; }

  #btn-home {
    width: auto;
    min-width: 36px;
    min-height: 34px;
    padding: 0 10px;
    font-size: 0.98rem;
  }

  #level,
  #score,
  #streak {
    min-height: 30px;
    padding: 3px 10px;
    font-size: 0.78rem;
  }

  #btn-sound,
  #btn-theme {
    width: auto;
    min-width: 36px;
    min-height: 34px;
    padding: 0 10px;
    font-size: 0.95rem;
  }

  #xp-bar { padding: 7px 12px; margin-bottom: 14px; }
  #xp-fill { height: 10px; }
  #xp-text { font-size: 0.74rem; }

  .mode-grid,
  #view-home:not(:has(.mode-grid)),
  #view-home { grid-template-columns: 1fr; }

  #topbar .topbar-mid { flex: 1 1 100%; }
  #topbar .topbar-right { width: 100%; justify-content: flex-start; gap: 6px; }
  #topbar button { min-height: 32px; padding: 4px 10px; font-size: 0.78rem; }
  #topbar h1,
  #topbar #app-title,
  #topbar .app-title { font-size: 0.95rem; }

  .mode-card { min-height: 0; padding: 14px; }

  .q-card { padding: 14px; }
  .q-stem { font-size: 1rem; }
  .cloze-passage { padding: 14px; font-size: 0.98rem; line-height: 2; }
  .blank { min-width: 72px; min-height: 32px; padding: 2px 8px; font-size: 0.9rem; }
  .word-chip { padding: 7px 12px; font-size: 0.9rem; }
  .writing-area { min-height: 170px; font-size: 0.98rem; }

  #quiz-foot { justify-content: stretch; }
  #quiz-foot .btn { flex: 1 1 auto; }

  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }

  #toast { max-width: 92vw; font-size: 0.88rem; padding: 10px 16px; }
  #modal { padding: 14px; }
  #modal-body { padding: 16px; max-height: 88vh; }
}

/* 超窄機（iPhone SE 等） */
@media (max-width: 360px) {
  #topbar > h1,
  #topbar .app-title { font-size: 0.88rem; }
  .mode-card .mode-icon { width: 38px; height: 38px; font-size: 1.3rem; }
  .stat-grid { grid-template-columns: 1fr; }
}

/* 橫向矮螢幕：減少垂直留白 */
@media (max-height: 480px) and (orientation: landscape) {
  #topbar { position: static; }
  .mode-card { min-height: 0; }
  .writing-area { min-height: 130px; }
}

/* ==========================================================================
   11. 列印：只留題目內容
   ========================================================================== */

@media print {
  :root,
  body.light {
    --bg: #ffffff;
    --card: #ffffff;
    --card-2: #ffffff;
    --card-hover: #ffffff;
    --text: #000000;
    --muted: #333333;
    --muted-2: #444444;
    --line: #bbbbbb;
    --line-strong: #999999;
    --shadow: none;
    --shadow-sm: none;
    --shadow-ring: none;
    --grad-top: none;
    --grad-accent: none;
    --grad-ok: none;
  }

  @page { margin: 14mm; }

  html,
  body {
    background: #ffffff !important;
    background-image: none !important;
    color: #000000;
    font-size: 12pt;
  }

  #topbar,
  #xp-bar,
  #fx,
  #toast,
  #modal,
  #modal-close,
  #app-foot,
  .btn,
  .mode-card,
  .mode-grid,
  #view-home,
  #quiz-foot {
    display: none !important;
  }

  #app-shell {
    max-width: none;
    padding: 0;
    margin: 0;
  }

  .view { display: block !important; animation: none !important; }

  .q-card,
  .writing-box,
  .cloze-passage,
  .word-bank,
  .para,
  .stmt,
  .q-explain,
  .model-answer,
  .analysis-list > li,
  .pattern-item {
    background: #ffffff !important;
    border: 1px solid #999999 !important;
    box-shadow: none !important;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .q-card,
  #quiz-body { box-shadow: none !important; }

  .opt {
    background: #ffffff !important;
    border: 1px solid #999999 !important;
    box-shadow: none !important;
    break-inside: avoid;
  }

  .opt.correct,
  .blank.correct { background: #e6f7ee !important; border-color: #157a4d !important; color: #000000 !important; }

  .opt.wrong,
  .blank.wrong { background: #fdeaee !important; border-color: #b02033 !important; color: #000000 !important; }

  .blank {
    border: 1px solid #666666 !important;
    background: #ffffff !important;
    color: #000000 !important;
    animation: none !important;
    box-shadow: none !important;
  }

  .word-chip,
  .chip,
  .badge {
    background: #ffffff !important;
    border: 1px solid #999999 !important;
    color: #000000 !important;
    box-shadow: none !important;
  }

  .combo,
  .timer { animation: none !important; }

  .progress-ring { background: none !important; }
  .progress-ring::before { background: #ffffff !important; }

  a { color: #000000; text-decoration: underline; }

  .fade-in,
  .stagger > *,
  .view { animation: none !important; }
}

/* ---------- 手機：頂欄連結較多，375px 會橫向溢出（2026-10-17 修） ---------- */
@media (max-width: 560px) {
  #topbar { flex-wrap: wrap; }
  #topbar .topbar-left { flex: 1 1 100%; flex-wrap: wrap; row-gap: 6px; }
  #topbar .topbar-left > a,
  #topbar .topbar-left > button { font-size: .78rem; padding: 4px 8px; }
  #topbar .brand { display: none; }
}