/* ============================================
   英語學習 PoC — 整合工作台 style.css
   延續原 PoC 視覺風格：accent #2563eb、卡片式、system-ui
   Mobile-first：先寫窄螢幕樣式，再用 min-width media query 加強桌機
   ============================================ */

/* IPA 音標專用字型：Noto Sans 子集（僅含 Basic Latin + Latin-1 + IPA Extensions +
   Spacing Modifier Letters + Combining Diacritical Marks + Greek θ + Latin Ext-A/B）。
   目的是讓音標字元（含重音符 ˈˌ、長音 ː 等）使用同一套字型繪製，避免瀏覽器逐字回退到
   不同系統字型造成大小/粗細/基線不一致。授權見 app/static/fonts/OFL.txt（SIL OFL 1.1）。 */
@font-face {
  font-family: "IPA";
  src: url("../fonts/NotoSansIPA-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --bg: #f8fafc;
  --card: #fff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --ok: #16a34a;
  --ok-bg: #f0fdf4;
  --phrase: #7c3aed;
  --phrasal: #0d9488;
  --relclause: #ea580c;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tab-bar-height: 60px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Noto Sans TC", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body { padding-bottom: calc(var(--tab-bar-height) + 16px + var(--safe-bottom)); }

a { color: var(--accent); }

.mt { margin-top: 12px; }

/* -------- Header / Nav -------- */
header.app-header {
  background: var(--accent);
  color: #fff;
  padding: calc(14px + var(--safe-top)) 16px 14px;
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
header.app-header h1 {
  margin: 0;
  font-size: 1.05rem;
  white-space: nowrap;
}

.top-nav { display: none; }
@media (min-width: 860px) {
  /* 不用 nowrap：英文標籤較長，1280px 寬時整列會超出視口，把語言切換器與「Login」擠出畫面
     （review-perception P-21）。讓 nav 需要時換行到第二列，切換器永遠留在畫面內。 */
  .top-nav { display: flex; gap: 4px; flex: 1; justify-content: flex-end; flex-wrap: wrap; min-width: 0; }
  .top-nav-item {
    display: flex; align-items: center; gap: 5px;
    color: rgba(255,255,255,.85); text-decoration: none;
    padding: 8px 12px; border-radius: 8px; font-size: .86rem; white-space: nowrap;
  }
  .top-nav-item .nav-icon { font-size: .95rem; }
  .top-nav-item:hover { background: rgba(255,255,255,.12); color: #fff; }
  .top-nav-item.active { background: rgba(255,255,255,.22); color: #fff; font-weight: 600; }
}

.tab-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 50;
  background: #fff;
  border-top: 1px solid var(--border);
  display: flex;
  padding-bottom: var(--safe-bottom);
  overflow-x: auto;
}
.tab-item {
  flex: 1 0 auto;
  min-width: 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 8px 4px 6px;
  text-decoration: none;
  color: var(--muted);
  font-size: .65rem;
}
.tab-item .nav-icon { font-size: 1.25rem; line-height: 1; }
.tab-item.active { color: var(--accent); font-weight: 600; }
@media (min-width: 860px) {
  .tab-bar { display: none; }
  body { padding-bottom: 16px; }
}

main#view {
  max-width: 780px;
  margin: 0 auto;
  padding: 14px 12px 24px;
}

.app-footer {
  max-width: 780px;
  margin: 0 auto;
  padding: 8px 16px 4px;
  color: var(--muted);
  font-size: .72rem;
  text-align: center;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 14px;
}
.card h2 { margin: 0 0 10px; font-size: 1rem; }
.card h3 { margin: 0 0 8px; font-size: .92rem; }
.card h3.mt { margin-top: 16px; }

.muted { color: var(--muted); font-size: .85rem; }
.warn-text { color: #b45309; font-size: .78rem; }

label.field-label {
  display: block;
  font-size: .82rem;
  color: var(--muted);
  margin-bottom: 4px;
  font-weight: 600;
}

input[type="text"], textarea, select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 1rem;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
input[type="text"]:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
textarea { min-height: 180px; resize: vertical; line-height: 1.6; }

.field { margin-bottom: 12px; }
.char-count { font-size: .75rem; color: var(--muted); text-align: right; margin-top: 3px; }
.char-count.warn { color: var(--danger); }

/* 偏好設定：勾選列（帳號頁「顯示 KK 音標對照」等） */
.field-check-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: .95rem;
}
.field-check-label input[type="checkbox"] { width: 20px; height: 20px; cursor: pointer; flex: 0 0 auto; }
.field-help { margin-top: 4px; margin-left: 28px; font-size: .8rem; line-height: 1.5; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 9px;
  padding: 11px 18px;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  touch-action: manipulation;
  text-decoration: none;
}
.btn:hover { background: var(--accent-dark); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.block { width: 100%; }
.btn.secondary {
  background: #fff;
  color: var(--accent);
  border: 1px solid var(--accent);
}
.btn.small { padding: 6px 12px; font-size: .82rem; min-height: 34px; }

.spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}
.spinner.dark {
  border-color: rgba(37,99,235,.25);
  border-top-color: var(--accent);
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 24px 8px;
  color: var(--muted);
  font-size: .9rem;
  justify-content: center;
}

.error-bar {
  background: var(--danger-bg);
  border: 1px solid #fecaca;
  color: var(--danger);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: .88rem;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.error-bar button {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 1rem;
  cursor: pointer;
  margin-left: auto;
  line-height: 1;
  padding: 0 2px;
}

.article-list-item, .vocab-item, .word-list-item {
  border-bottom: 1px solid var(--border);
  padding: 12px 2px;
  display: block;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}
.list-card { padding: 6px 16px; }
.article-list-item:last-child, .vocab-item:last-child, .word-list-item:last-child { border-bottom: none; }
.article-list-item .title { font-weight: 600; margin-bottom: 2px; }
.article-list-item .excerpt {
  color: var(--muted);
  font-size: .85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.article-list-item .meta, .word-list-item .meta { font-size: .75rem; color: var(--muted); margin-top: 4px; }

.badge { display: inline-block; border-radius: 99px; padding: 1px 9px; font-size: .72rem; }
.badge.pending { background: #fef9c3; color: #a16207; }
.badge.analyzed { background: var(--ok-bg); color: var(--ok); }
.badge.failed { background: var(--danger-bg); color: var(--danger); }

.pos-badge { display: inline-block; background: #eff6ff; color: var(--accent); border-radius: 99px; padding: 1px 9px; font-size: .75rem; margin-right: 4px; }
.pos-badge.lg { font-size: .82rem; padding: 3px 12px; }
.ipa { font-family: "IPA", "Segoe UI", "Arial", sans-serif; font-style: normal; font-size: 1em; letter-spacing: 0.02em; color: #0f766e; }
.source-badge { display: inline-block; background: #f1f5f9; color: var(--muted); border-radius: 99px; padding: 1px 8px; font-size: .7rem; margin-left: 4px; }
.het-flag { margin-right: 4px; }

/* KK 音標對照：muted 色、跟 .ipa 同字型堆疊，視覺上明顯次要於主要 IPA（見任務規格） */
.kk-note {
  font-family: "IPA", "Segoe UI", "Arial", sans-serif;
  font-style: normal;
  font-size: .88em;
  letter-spacing: 0.02em;
  color: var(--muted);
  margin-left: .4em;
  white-space: nowrap;
}
.kk-note .kk-tag { font-weight: 700; font-size: .82em; opacity: .8; margin-right: .15em; }
.kk-toggle-chip { min-height: 28px; padding: 3px 10px; font-size: .72rem; font-weight: 600; }

/* -------- 🔊 TTS 按鈕 -------- */
.tts-btn {
  background: #eff6ff;
  color: var(--accent);
  border: 1px solid #dbeafe;
  border-radius: 99px;
  width: 30px; height: 30px;
  min-height: 0;
  padding: 0;
  font-size: .95rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.tts-btn:hover { background: #dbeafe; }
.tts-btn:disabled { opacity: .4; cursor: not-allowed; }
.tts-btn.tiny { width: 24px; height: 24px; font-size: .8rem; margin-left: 4px; }

/* -------- 閱讀畫面：文章渲染 -------- */
.reader-content {
  font-size: 1.08rem;
  line-height: 2.15;
  white-space: pre-wrap;
  word-break: break-word;
}

/* 閱讀畫面預設「乾淨模式」：word 外觀如一般文章，hover/tap 才浮現標注
   （使用者需求 2026-07-19）；容器加 .marks-on 時切回全標注模式 */
.tok {
  border-radius: 3px;
  padding: 0 1px;
  cursor: pointer;
}
.tok.has-entry:hover, .tok.has-entry.active { background: rgba(37,99,235,.22); }
.tok.no-entry:hover, .tok.no-entry.active {
  background: rgba(100,116,139,.12);
  border-bottom: 1px dashed rgba(100,116,139,.55);
}
.marks-on .tok.has-entry { background: rgba(37,99,235,.10); }
.marks-on .tok.no-entry { border-bottom: 1px dashed rgba(100,116,139,.55); }

.span-el {
  cursor: pointer;
  padding-bottom: 1px;
}
/* hover / active / linked-hover（分離式兩段同步）時浮現底線與底色 */
.span-el.span-phrase:hover,
.span-el.span-phrase.active,
.span-el.span-phrase.span-linked-hover {
  background: rgba(124,58,237,.10);
  border-bottom: 3px double var(--phrase);
}
.span-el.span-relative_clause:hover,
.span-el.span-relative_clause.active,
.span-el.span-relative_clause.span-linked-hover {
  background: rgba(234,88,12,.10);
  border-bottom: 2px wavy var(--relclause);
}
/* 分離式片語動詞（turn ... on）：與 phrase 的紫色雙底線區隔，用青色虛線 */
.span-el.span-phrasal_verb:hover,
.span-el.span-phrasal_verb.active,
.span-el.span-phrasal_verb.span-linked-hover {
  background: rgba(13,148,136,.14);
  border-bottom: 2px dashed var(--phrasal);
}
/* 文法組塊（be going to…）：琥珀色點線 */
.span-el.span-grammar_chunk:hover,
.span-el.span-grammar_chunk.active,
.span-el.span-grammar_chunk.span-linked-hover {
  background: rgba(217,119,6,.12);
  border-bottom: 2px dotted #d97706;
}
/* 全標注模式：底線常駐 */
.marks-on .span-el.span-phrase { border-bottom: 3px double var(--phrase); }
.marks-on .span-el.span-relative_clause { border-bottom: 2px wavy var(--relclause); }
.marks-on .span-el.span-phrasal_verb { border-bottom: 2px dashed var(--phrasal); }
.marks-on .span-el.span-grammar_chunk { border-bottom: 2px dotted #d97706; }
.span-el .tok { pointer-events: none; }

.reader-tools {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 8px;
}

/* -------- Tooltip（桌機浮動卡片） -------- */
.tooltip {
  position: fixed;
  z-index: 100;
  max-width: 320px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(15,23,42,.18);
  padding: 14px 16px;
  font-size: .9rem;
  display: none;
}
.tooltip.show { display: block; }
.tooltip .tt-word { font-size: 1.1rem; font-weight: 700; margin-right: 6px; }
.tooltip .tt-row { margin-top: 6px; }
.tooltip .tt-def { margin-top: 8px; line-height: 1.55; }
.tooltip .tt-def.zh { color: var(--text); font-weight: 600; }
.tooltip .tt-def.en { color: var(--muted); }
.tooltip .tt-example { margin-top: 8px; font-style: italic; color: var(--muted); border-left: 2px solid var(--border); padding-left: 8px; }
.tooltip .tt-example .zh { font-style: normal; margin-top: 2px; }
.tooltip .tt-warn, .tt-warn {
  margin-top: 8px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
  border-radius: 8px;
  padding: 6px 9px;
  font-size: .78rem;
}
.tooltip .tt-rule, .tt-rule {
  margin-top: 6px;
  background: #ecfeff;
  border: 1px solid #a5f3fc;
  color: #155e75;
  border-radius: 8px;
  padding: 5px 9px;
  font-size: .78rem;
}
.tooltip .tt-chips, .tt-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tooltip .tt-chip, .chip-link {
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 99px;
  padding: 3px 10px;
  font-size: .8rem;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  display: inline-block;
}
.tooltip .tt-chip:hover, .chip-link:hover { border-color: var(--accent); color: var(--accent); }
.tooltip .tt-actions, .tt-actions { margin-top: 10px; display: flex; gap: 8px; }
.tooltip .tt-close {
  position: absolute;
  top: 8px; right: 10px;
  border: none; background: none;
  font-size: 1.1rem; color: var(--muted);
  cursor: pointer; display: none;
  line-height: 1; padding: 4px;
}

@media (hover: none), (pointer: coarse) {
  .tooltip {
    position: fixed;
    left: 0; right: 0; bottom: 0; top: auto;
    max-width: none;
    width: 100%;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -6px 24px rgba(15,23,42,.22);
    padding: 18px 18px calc(18px + var(--safe-bottom));
    max-height: 60vh;
    overflow-y: auto;
  }
  .tooltip .tt-close { display: block; }
}

.tt-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.35);
  z-index: 90;
  display: none;
}
.tt-backdrop.show { display: block; }
@media (hover: hover) and (pointer: fine) {
  .tt-backdrop { display: none !important; }
}

/* -------- Toast -------- */
#toast-root {
  position: fixed;
  bottom: calc(var(--tab-bar-height) + 16px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  width: 100%;
  pointer-events: none;
  padding: 0 16px;
}
.toast {
  background: #1e293b;
  color: #fff;
  padding: 10px 16px;
  border-radius: 99px;
  font-size: .85rem;
  box-shadow: 0 6px 16px rgba(0,0,0,.25);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .18s ease, transform .18s ease;
  max-width: 90vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.err { background: var(--danger); }

/* -------- 生字本 -------- */
.vocab-item .word-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.vocab-item .word, .word-list-item .word, .quiz-word { font-weight: 700; font-size: 1.05rem; }
.vocab-item .zh-def { margin-top: 4px; color: var(--text); }
.vocab-item .context { margin-top: 6px; font-size: .85rem; color: var(--muted); font-style: italic; }
.vocab-item .context mark {
  background: rgba(37,99,235,.18);
  color: var(--accent-dark);
  border-radius: 3px;
  padding: 0 2px;
  font-style: normal;
  font-weight: 600;
}

/* -------- 生字本：單筆移除「−」+ 編輯模式多選（vocab.js，
   見 docs/feature-vocab-management.md §3.1/§3.2） -------- */
.vocab-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 20px 0 8px; flex-wrap: wrap; }
.vocab-header .section-title { margin: 0; }
.vocab-header-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.vocab-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.vocab-item-body { flex: 1; min-width: 0; }

/* 樂觀移除：淡出 + 收合高度（vocab.js 用 JS 量測實際高度後改 inline style 做過場動畫，
   避免固定 max-height 裁切較長的內容），DELETE 成功後才真的移除 DOM 節點；失敗則復原 */
.vocab-item-removing {
  overflow: hidden;
  pointer-events: none;
  transition: opacity .2s ease, max-height .25s ease, padding .25s ease, margin .25s ease;
}

.vocab-remove-btn {
  margin-left: auto;
  flex: 0 0 auto;
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--danger);
  border-radius: 99px;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.vocab-remove-btn:hover { background: var(--danger-bg); border-color: var(--danger); }

.vocab-select-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  min-width: 44px;
  min-height: 44px;
}
.vocab-select-cb { width: 20px; height: 20px; cursor: pointer; }
.vocab-item.editing { cursor: pointer; }

.vocab-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 12px;
  font-size: .85rem;
}
.vocab-select-all { display: flex; align-items: center; gap: 6px; cursor: pointer; min-height: 44px; }
.vocab-select-all input { width: 18px; height: 18px; cursor: pointer; }
.vocab-selected-count { color: var(--muted); flex: 1 1 auto; }

/* -------- Undo toast（showUndoToast，vocab.js 移除單字/多字用） -------- */
.toast-undo { display: flex; align-items: center; gap: 12px; pointer-events: auto; }
.toast-undo-btn {
  background: none;
  border: none;
  color: #93c5fd;
  font-weight: 700;
  font-size: .85rem;
  cursor: pointer;
  padding: 4px 6px;
  min-height: 32px;
  text-decoration: underline;
  flex: 0 0 auto;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 30px 10px;
  font-size: .9rem;
}

.section-title {
  font-size: .8rem;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .02em;
  margin: 20px 0 8px;
}

.back-link { display: inline-block; margin-bottom: 10px; font-size: .88rem; text-decoration: none; }

/* -------- 總覽（home） -------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 4px;
}
.stat-tile {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 8px;
  text-align: center;
}
.stat-value { font-size: 1.35rem; font-weight: 700; color: var(--accent); }
.stat-label { font-size: .72rem; color: var(--muted); margin-top: 2px; }

.heteronym-row { border-bottom: 1px solid var(--border); padding: 10px 2px; }
.heteronym-row:last-child { border-bottom: none; }
.het-word { font-weight: 700; text-decoration: none; display: block; margin-bottom: 6px; }
.het-prons { display: flex; flex-wrap: wrap; gap: 10px; }
.pron-chip { display: inline-flex; align-items: center; gap: 4px; background: var(--bg); border-radius: 99px; padding: 4px 8px 4px 10px; }

.entry-cards { display: grid; grid-template-columns: 1fr; gap: 10px; }
.entry-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  text-decoration: none;
  color: inherit;
  display: flex;
  align-items: center;
  gap: 12px;
}
.entry-card:hover { border-color: var(--accent); }
.entry-icon { font-size: 1.6rem; }
.entry-title { font-weight: 700; }
.entry-desc { font-size: .8rem; color: var(--muted); margin-top: 2px; }
@media (min-width: 640px) {
  .entry-cards { grid-template-columns: repeat(3, 1fr); }
  .entry-card { flex-direction: column; align-items: flex-start; }
}

/* -------- 單字庫 -------- */
.pager { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 10px 2px 20px; }
.pager-info { font-size: .8rem; color: var(--muted); }
.def-card .word-row { margin-bottom: 8px; }
.word-title { font-size: 1.4rem; }
.attribution { margin-top: 10px; font-size: .72rem; color: var(--muted); }

/* -------- 片語 -------- */
.phrase-card .word-row { align-items: center; gap: 8px; }

/* -------- 複習與練習 -------- */
.due-row { border-bottom: 1px solid var(--border); padding: 10px 2px; }
.due-row:last-child { border-bottom: none; }
.due-row.due .word { color: var(--danger); }
.due-row.upcoming .word { color: var(--ok); }
.stars { letter-spacing: 1px; color: #f59e0b; font-size: .95rem; }

.mode-cards { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 640px) { .mode-cards { grid-template-columns: repeat(3, 1fr); } }
.mode-card h3 { margin-bottom: 4px; }
.mode-actions { display: flex; gap: 8px; margin-top: 12px; }
.count-select { width: auto; flex: 0 0 auto; }
.mode-actions .btn { flex: 1; }

.quiz-progress { font-size: .78rem; color: var(--muted); margin-bottom: 10px; }
.quiz-prompt { margin-bottom: 14px; }
.quiz-def { font-size: 1.05rem; margin-top: 6px; line-height: 1.6; }
.quiz-word { display: flex; align-items: center; gap: 6px; font-size: 1.3rem; }
.quiz-choices { display: flex; flex-direction: column; gap: 8px; }
.quiz-choice { text-align: left; justify-content: flex-start; }
.quiz-choice.correct { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); font-weight: 700; }
.quiz-choice.wrong { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); font-weight: 700; }
.quiz-spelling { display: flex; flex-direction: column; gap: 10px; }
.quiz-spelling input { font-size: 1.1rem; text-align: center; letter-spacing: 1px; }

.feedback { margin-top: 16px; border-radius: 10px; padding: 14px; border: 1px solid var(--border); }
.feedback.ok { background: var(--ok-bg); border-color: #bbf7d0; }
.feedback.bad { background: var(--danger-bg); border-color: #fecaca; }
.feedback-headline { font-weight: 700; margin-bottom: 8px; }
.explain-card { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin: 10px 0; }
.mastery-change { margin-top: 8px; font-size: .92rem; }

.summary-stat { font-size: 1.05rem; margin-bottom: 12px; }
.table-scroll { overflow-x: auto; }
.summary-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.summary-table th, .summary-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.summary-table th { color: var(--muted); font-weight: 600; }

/* -------- 關於 -------- */
.feature-row { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); align-items: flex-start; }
.feature-row:last-child { border-bottom: none; }
.feature-icon { font-size: 1.4rem; line-height: 1.3; }
.feature-title { font-weight: 700; }
.migration-list { margin: 6px 0 0; padding-left: 18px; font-size: .82rem; color: var(--muted); }

/* -------- 生字本 split-button + 清單選擇器（vocab-picker.js） -------- */
.vocab-picker { position: relative; display: inline-block; }
.vp-split { display: flex; gap: 4px; }
.vp-main { white-space: nowrap; }
.vp-caret { padding: 6px 10px; }
.vp-panel {
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  padding: 6px;
  min-width: 220px;
  max-width: 100%;
}
.vp-list-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  background: none;
  border: none;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: .85rem;
  text-align: left;
  cursor: pointer;
  color: var(--text);
}
.vp-list-row:hover { background: #fff; }
.vp-list-name { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.vp-list-count { color: var(--muted); font-size: .75rem; white-space: nowrap; margin-left: 8px; }
.vp-new-row {
  display: flex;
  gap: 6px;
  padding: 8px 6px 4px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}
.vp-new-input { flex: 1; min-width: 0; padding: 6px 8px; font-size: .85rem; }
.vp-panel-error { color: var(--danger); font-size: .78rem; padding: 4px 8px; }

.chip-badge {
  display: inline-block;
  background: var(--ok-bg);
  color: var(--ok);
  border-radius: 99px;
  padding: 0 6px;
  font-size: .68rem;
  font-weight: 600;
}

/* -------- 生字本頁：清單切換 chips（vocab.js） -------- */
.list-switch { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin: 0 0 12px; }
.list-chip {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 6px 12px;
  font-size: .82rem;
  cursor: pointer;
  color: var(--text);
  white-space: nowrap;
}
.list-chip.active { border-color: var(--accent); color: var(--accent); background: #eff6ff; font-weight: 600; }
.list-chip .chip-count { color: var(--muted); font-size: .72rem; }

/* 「＋ 新建」清單 chip（見 §8）：預設樣式同一般 chip，虛線邊框略作區隔；
   點擊後原地變行內輸入框（不新增樣式規則，沿用 input[type=text] 全域樣式 + 尺寸微調） */
.list-chip.new-list-chip { border-style: dashed; color: var(--muted); }
.list-chip.new-list-chip:hover { border-color: var(--accent); color: var(--accent); }
.list-chip.new-list-chip-input { padding: 0; border: none; background: none; }
.list-chip.new-list-chip-input input {
  width: 140px;
  max-width: 40vw;
  padding: 6px 12px;
  font-size: .82rem;
  border-radius: 99px;
}

/* -------- 生字本頁：批次輸入單字面板（vocab.js，見 §8） -------- */
.vocab-batch-panel { margin: 0 0 14px; }
.vocab-batch-panel textarea { min-height: 120px; margin-bottom: 10px; }
.vocab-batch-actions { display: flex; gap: 8px; }
.vocab-batch-summary { margin-top: 12px; }
.vocab-batch-notfound { margin-top: 8px; }
.vocab-batch-notfound-title { font-weight: 600; margin-bottom: 4px; }
.vocab-batch-notfound ul { margin: 0; padding-left: 18px; }
.vocab-batch-notfound li { line-height: 1.6; }

/* -------- 帳號 / 登入 -------- */
.auth-tabs { display: flex; gap: 4px; margin-bottom: 14px; border-bottom: 1px solid var(--border); }
.auth-tab {
  flex: 1;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 4px;
  font-size: .9rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.auth-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.profile-static {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  font-size: .95rem;
}
.badge.unverified { background: #fef9c3; color: #a16207; }
.password-card { margin-top: 4px; }

@media (min-width: 640px) {
  main#view { padding: 24px 16px 32px; }
  header.app-header { padding: 16px 24px; }
  .card { padding: 20px 22px; }
}

/* -------- IPA 聽辨訓練器（#/perception，views/perception.js） -------- */
.perc-topbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}
.perc-accent-toggle, .perc-mode-tabs {
  display: flex;
  gap: 6px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
}
.perc-accent-btn, .perc-mode-tab {
  flex: 1;
  background: none;
  border: none;
  border-radius: 8px;
  padding: 9px 6px;
  font-size: .85rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  min-height: 40px;
}
.perc-accent-btn.active, .perc-mode-tab.active { background: var(--accent); color: #fff; }
@media (min-width: 640px) {
  .perc-topbar { flex-direction: row; justify-content: space-between; }
  .perc-accent-toggle { flex: 0 0 auto; }
  .perc-mode-tabs { flex: 0 0 auto; }
}

.perc-speaker-bar {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 12px;
  font-size: .85rem;
}
.perc-speaker-label { color: var(--muted); margin-right: 8px; }
.perc-speaker-modes { display: inline-flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip-toggle {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 99px;
  padding: 6px 12px;
  font-size: .8rem;
  cursor: pointer;
  color: var(--text);
  min-height: 40px; /* 觸控目標 ≥40px（spec item 12），原 32px 太小 */
}
.chip-toggle.active { border-color: var(--accent); background: #eff6ff; color: var(--accent); font-weight: 600; }
.perc-speaker-note { margin-top: 6px; }

/* IPA 鍵盤：三區塊（單母音/雙母音/子音），鍵 = 大符號 + 例詞小字，觸控目標 ≥44px */
.ipa-keyboard { margin-bottom: 14px; }
.ipa-kb-section { margin-bottom: 12px; }
.ipa-kb-title {
  font-size: .78rem;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .02em;
  margin-bottom: 6px;
}
.ipa-kb-grid, .ipa-kb-consonant-rows {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.ipa-kb-row { display: flex; gap: 8px; }
.ipa-key {
  min-width: 56px;
  min-height: 52px;
  flex: 0 0 auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
}
.ipa-key:hover { border-color: var(--accent); }
.ipa-key.active { border-color: var(--accent); background: #eff6ff; }
.ipa-key.correct { background: var(--ok-bg); border-color: var(--ok); }
.ipa-key.wrong { background: var(--danger-bg); border-color: var(--danger); }
.ipa-key:disabled { cursor: default; opacity: .85; }
.ipa-key-symbol { font-size: 1.15rem; line-height: 1.1; }
.ipa-key-word { font-size: .68rem; color: #475569; white-space: nowrap; } /* 比 --muted 深：小字在 #eff6ff/ok-bg 上 axe 對比度不足（P-23） */

/* 探索模式：資訊卡 */
.perc-info-empty { text-align: center; padding: 24px 10px; }
.perc-info-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.perc-info-symbol { font-size: 1.6rem; }
.perc-info-kk-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: -4px 0 8px; }
.perc-info-kk-row .kk-note { margin-left: 0; font-size: 1em; }
.perc-tip { font-size: .9rem; line-height: 1.6; margin-bottom: 10px; }

/* 孤立音模式（isolated）：探索模式資訊卡上的播放列（在例詞列表之上）+ 測驗設定頁呈現方式選擇器 */
.perc-isolated-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.perc-isolated-note { font-size: .78rem; }

/* 例詞真人錄音 manifest 有上線但缺這個字（gate 沒過）→ 靜默 fallback TTS 時的小提示，
   貼在例詞按鈕/對立詞 chip 的字後面（見 perception.js ttsFallbackHintHtml）。 */
.perc-tts-hint {
  color: var(--muted);
  font-size: .62em;
  font-weight: 700;
  margin-left: 2px;
  vertical-align: super;
  letter-spacing: .02em;
  cursor: help;
}
.perc-presentation-modes { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.chip-toggle:disabled { opacity: .45; cursor: not-allowed; }
.chip-toggle:disabled:hover { border-color: var(--border); }
.perc-examples-label, .perc-confusable-label {
  font-size: .78rem; color: var(--muted); font-weight: 700; margin: 10px 0 6px;
}
.perc-examples { display: flex; flex-wrap: wrap; gap: 8px; }
.perc-example-btn {
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: .92rem;
  cursor: pointer;
  min-height: 40px;
  color: var(--text);
}
.perc-example-btn mark {
  background: rgba(37,99,235,.2);
  color: var(--accent-dark);
  border-radius: 3px;
  padding: 0 1px;
  font-weight: 700;
}
.perc-confusable-list { display: flex; flex-direction: column; gap: 8px; }
.perc-confusable-item { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.perc-confusable-sym { min-width: 34px; font-size: 1.05rem; }

/* 對立詞清單：每個混淆鄰居底下一整排可點的例詞對 chip，讓使用者自己挑一組聽，
   不必只靠隨機的 🔁 循環對比（spec：探索模式資訊卡，一次多顯示幾組）。 */
.perc-pair-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 6px 42px; }
.perc-pair-chip {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: .82rem;
  cursor: pointer;
  min-height: 40px;
  max-width: 100%;
  color: var(--text);
}
.perc-pair-chip mark {
  background: rgba(37,99,235,.2);
  color: var(--accent-dark);
  border-radius: 3px;
  padding: 0 1px;
  font-weight: 700;
}
.perc-pair-chip-ipa { color: var(--muted); }
.perc-pair-chip b { color: var(--accent-dark); }
.perc-pair-chip-arrow { color: var(--muted); }
.perc-pair-chip.playing { border-color: var(--accent); background: #eff6ff; }
.perc-pair-chip .playing-side { color: var(--accent-dark); font-weight: 700; }
.perc-pairs-toggle {
  border: none;
  background: none;
  color: var(--accent);
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 40px;
  padding: 6px 4px;
}
@media (max-width: 480px) {
  .perc-pair-chips { margin-left: 0; }
}

/* 例詞對比（最小對立詞）：顯示兩詞並高亮差異音字母 */
.perc-pair-display {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
}
.perc-pair-word mark {
  background: rgba(37,99,235,.2);
  color: var(--accent-dark);
  border-radius: 3px;
  padding: 0 1px;
  font-weight: 700;
}
.perc-pair-arrow { color: var(--muted); }
.perc-pair-near { font-size: .75rem; }
.chip-badge-btn {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 99px;
  padding: 6px 12px;
  font-size: .82rem;
  cursor: pointer;
  min-height: 40px; /* 觸控目標 ≥40px（spec item 12），原 36px 太小 */
  color: var(--text);
}
.chip-badge-btn.active { border-color: var(--danger); color: var(--danger); background: var(--danger-bg); font-weight: 600; }

/* 測驗模式 */
.perc-quiz-play-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.perc-replay-count { font-size: .78rem; }
/* 作答紀錄儲存失敗提示（spec item 1）：一次性的登入提示用一般 muted 灰字即可；
   連續失敗的持續性提示要更顯眼一點，借用既有的 danger 色調（跟 .feedback.bad 同一色系）。 */
.perc-quiz-notice:empty { display: none; }
.perc-quiz-notice { margin-bottom: 8px; }
.perc-quiz-notice.bad {
  color: var(--danger);
  background: var(--danger-bg);
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: .82rem;
}

/* 統計模式 */
.perc-stats-total { margin-bottom: 10px; }
.perc-phoneme-cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 4px; }
@media (min-width: 640px) { .perc-phoneme-cards { grid-template-columns: repeat(4, 1fr); } }
.perc-phoneme-card { padding: 12px 10px; text-align: center; }
.perc-phoneme-symbol { font-size: 1.15rem; margin-bottom: 4px; }
.perc-phoneme-accuracy { font-weight: 700; margin-top: 2px; }
.perc-recent { font-size: .72rem; }
.perc-weak-list, .perc-reco-list { display: flex; flex-wrap: wrap; gap: 8px; }
.perc-reco-item { flex: 1 1 220px; }

.perc-heatmap { border-collapse: collapse; font-size: .82rem; }
.perc-heatmap th, .perc-heatmap td {
  border: 1px solid var(--border);
  padding: 6px 8px;
  text-align: center;
  min-width: 34px;
}
.perc-heatmap thead th { background: var(--bg); }
.perc-heat-cell.diag { font-weight: 700; }

/* 弱點音標 chip +「去練發音」連結（perception.js 統計頁，接到 #/production） */
.perc-weak-chip { display: inline-flex; align-items: center; gap: 6px; }
.chip-badge-link {
  border: none;
  background: none;
  color: var(--accent);
  font-size: .74rem;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 0;
}
.chip-badge-link:hover { text-decoration: underline; }

/* -------- 發音訓練器（#/production，views/production.js） -------- */
.prod-unsupported { text-align: center; }
.prod-cal-status { font-weight: 600; }
.prod-cal-card { text-align: center; }
.prod-cal-live {
  min-height: 1.4em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .85rem;
  margin: 10px 0;
}
.prod-nav-wrap { display: flex; flex-direction: column; gap: 12px; }
.prod-nav-header { display: flex; flex-direction: column; gap: 8px; }
.prod-target-keyboard, .prod-pair-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.prod-chart-card { text-align: center; padding: 12px 10px 16px; }
.prod-vowel-svg {
  width: 100%;
  max-width: 420px;
  height: auto;
  background: var(--bg);
  border-radius: 10px;
  touch-action: none;
}
.prod-axis-label { font-size: 10px; fill: var(--muted); }
.prod-target-ellipse {
  fill: rgba(37, 99, 235, .08);
  stroke: rgba(37, 99, 235, .35);
  stroke-width: 1;
}
.prod-target-ellipse.active { fill: rgba(37, 99, 235, .18); stroke: var(--accent); stroke-width: 2; }
.prod-target-label { font-size: 11px; fill: var(--muted); pointer-events: none; }
.prod-target-label.active { fill: var(--accent-dark); font-weight: 700; }
.prod-zh-anchor { fill: rgba(124, 58, 237, .35); stroke: none; }
.prod-zh-anchor.personal { fill: rgba(124, 58, 237, .8); }
.prod-zh-label { font-size: 10px; fill: var(--phrase); pointer-events: none; }
.prod-live-dot { fill: var(--danger); stroke: #fff; stroke-width: 1.5; transition: cx .08s linear, cy .08s linear; }
.prod-hint-row { min-height: 1.6em; font-weight: 600; margin-top: 8px; }
.prod-hold-bar {
  height: 6px;
  border-radius: 3px;
  background: var(--border);
  overflow: hidden;
  margin-top: 6px;
}
.prod-hold-fill { height: 100%; width: 0; background: var(--ok); transition: width .08s linear; }
.prod-recipe-card { padding: 10px 14px; }
.prod-recipe-label { font-size: .74rem; color: var(--muted); margin-bottom: 4px; }
.prod-recipe-text { font-size: .92rem; line-height: 1.5; }
.prod-pair-progress { text-align: center; }
.prod-stats-total { margin-bottom: 10px; }

/* R2 三種練習模式（4.2 模仿-判定 / 4.3 最小對立 / 4.4 分離度）共用 UI */
.prod-mode-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.prod-disclaimer { font-size: .78rem; line-height: 1.5; }
.prod-imitate-card, .prod-mp-card, .prod-contrast-card { text-align: center; }
.prod-streak { margin: 8px 0; font-weight: 600; }
.prod-feedback { margin-top: 12px; }
.prod-judge-verdict { font-weight: 700; padding: 8px 10px; border-radius: 8px; margin-bottom: 8px; }
.prod-judge-verdict.hit { background: rgba(22, 163, 74, .12); color: var(--ok, #16a34a); }
.prod-judge-verdict.miss { background: rgba(220, 38, 38, .1); color: var(--danger, #dc2626); }
.prod-judge-dist { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.prod-judge-row { display: flex; align-items: center; gap: 8px; }
.prod-judge-bar {
  flex: 1;
  height: 10px;
  border-radius: 5px;
  background: var(--border);
  overflow: hidden;
}
.prod-judge-fill { height: 100%; background: var(--accent); }
.prod-judge-pct { min-width: 3em; text-align: right; font-variant-numeric: tabular-nums; }
.prod-mini-svg {
  width: 100%;
  max-width: 260px;
  height: auto;
  background: var(--bg);
  border-radius: 10px;
}
.prod-mini-dot { fill: var(--danger); stroke: #fff; stroke-width: 1.5; }
.prod-mini-dot.cluster-a { fill: #2563eb; }
.prod-mini-dot.cluster-b { fill: #db2777; }
.prod-mp-words { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin: 10px 0; }
.prod-mp-word { padding: 6px 10px; border-radius: 8px; background: var(--border); }
.prod-mp-word.target { background: rgba(37, 99, 235, .18); font-weight: 700; }
.prod-blind-toggle { display: block; margin: 8px 0; font-size: .9rem; }
.prod-contrast-progress { margin: 8px 0; }
.prod-contrast-turn { font-weight: 600; }
.prod-contrast-verdict { font-weight: 600; margin-bottom: 8px; }

/* 介面語言切換器（i18n） */
.lang-switcher {
  margin-left: auto;
  background: rgba(255,255,255,.15);
  color: #fff;
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: .82rem;
  cursor: pointer;
}
.lang-switcher option { color: #1e293b; }

/* KK 對照開關：單字頁標題卡片內，與 meta 列拉開一點距離 */
.kk-chip-row { margin-top: 10px; }
