:root {
  --bg: #0f1419;
  --bg-soft: #1a212b;
  --bg-card: #1e2733;
  --border: #2c3744;
  --text: #e6edf3;
  --text-dim: #9aa7b4;
  --accent: #4f9eff;
  --accent-dim: #2d5a8c;
  --green: #3fb950;
  --green-bg: #14301a;
  --red: #f85149;
  --red-bg: #3a1416;
  --amber: #d29922;
  --radius: 12px;
  --shadow: 0 4px 20px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "Segoe UI", "PingFang TC", "Microsoft JhengHei", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.app { max-width: 920px; margin: 0 auto; padding: 0 16px 80px; }

/* Header */
header {
  position: sticky; top: 0; z-index: 20;
  background: rgba(15,20,25,.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  margin: 0 -16px 20px; padding: 12px 16px;
}
.header-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.brand-logo { height: 32px; width: auto; flex-shrink: 0; }
.brand { font-weight: 700; font-size: 18px; letter-spacing: .5px; }
.brand .tag { color: var(--accent); }
.spacer { flex: 1; }
select, button, input[type="text"] {
  font: inherit; color: var(--text);
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 11px; cursor: pointer;
}
select:focus, input:focus, button:focus { outline: 2px solid var(--accent-dim); }
input[type="text"] { cursor: text; min-width: 160px; }

.stats-bar { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 10px; font-size: 13px; color: var(--text-dim); }
.stats-bar b { color: var(--text); }
.progress-track { height: 6px; background: var(--bg-soft); border-radius: 4px; margin-top: 10px; overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent-dim), var(--accent)); width: 0; transition: width .3s; }

/* Toolbar */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.tabs { display: flex; gap: 4px; background: var(--bg-soft); padding: 4px; border-radius: 10px; }
.tab { border: none; background: transparent; padding: 6px 12px; border-radius: 7px; color: var(--text-dim); font-size: 14px; }
.tab.active { background: var(--accent); color: #fff; font-weight: 600; }
.tab .count { font-size: 11px; opacity: .8; margin-left: 4px; }

/* Card */
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow);
}
.q-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; font-size: 12px; }
.chip { background: var(--bg-soft); border: 1px solid var(--border); border-radius: 999px; padding: 2px 10px; color: var(--text-dim); }
.chip.cat { background: var(--accent-dim); color: #cfe4ff; border-color: transparent; }
.chip.src { font-family: ui-monospace, monospace; }
.chip.wrong { background: var(--red-bg); color: var(--red); border-color: transparent; }
.chip.study-badge { background: var(--green-bg); color: var(--green); border-color: transparent; }
.chip.att { font-variant-numeric: tabular-nums; }

.q-text { font-size: 17px; margin: 0 0 8px; }
.q-trans { color: var(--text-dim); font-size: 15px; border-left: 3px solid var(--accent-dim); padding-left: 12px; margin: 10px 0 18px; white-space: pre-wrap; }
.q-trans.hidden { display: none; }

/* Options */
.options { display: flex; flex-direction: column; gap: 10px; }
.opt {
  display: flex; gap: 12px; align-items: flex-start; text-align: left;
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; transition: border-color .15s, background .15s; width: 100%;
}
.opt:hover:not(:disabled) { border-color: var(--accent); }
.opt:disabled { cursor: default; }
.opt .letter { font-weight: 700; color: var(--accent); flex-shrink: 0; width: 20px; }
.opt .otext { flex: 1; }
.opt .otext .zh { display: block; color: var(--text-dim); font-size: 13px; margin-top: 3px; }
.options.hide-zh .otext .zh { display: none; }   /* 練習模式：未按「先看翻譯」前不顯示選項中文 */
.opt.correct { background: var(--green-bg); border-color: var(--green); }
.opt.correct .letter { color: var(--green); }
.opt.chosen-wrong { background: var(--red-bg); border-color: var(--red); }
.opt.chosen-wrong .letter { color: var(--red); }
.opt .mark { margin-left: auto; font-weight: 700; }

/* Explanation */
.explain { margin-top: 18px; border-top: 1px dashed var(--border); padding-top: 16px; }
.explain.hidden { display: none; }
.explain h4 { margin: 0 0 6px; font-size: 14px; color: var(--accent); }
.explain .concept { background: var(--bg-soft); border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; border-left: 3px solid var(--amber); }
.explain .concept .lbl { color: var(--amber); font-weight: 600; font-size: 12px; display: block; margin-bottom: 2px; }
.explain .body { white-space: pre-wrap; font-size: 14.5px; }
.verdict { font-weight: 700; margin-bottom: 12px; }
.verdict.ok { color: var(--green); }
.verdict.no { color: var(--red); }
.prev-note { font-size: 13px; color: var(--text-dim); background: var(--bg-soft); border-left: 3px solid var(--accent-dim); border-radius: 6px; padding: 7px 11px; margin-bottom: 12px; }

/* Nav */
.nav { display: flex; gap: 10px; align-items: center; margin-top: 20px; }
.nav button { background: var(--accent); color: #fff; border: none; font-weight: 600; padding: 9px 18px; }
.nav button.ghost { background: var(--bg-soft); color: var(--text); border: 1px solid var(--border); }
.nav button:disabled { opacity: .4; cursor: default; }
.nav .pos { color: var(--text-dim); font-size: 13px; }
.jump-in {
  width: 3.6em; text-align: center; font-size: 13px; padding: 3px 4px;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg-soft); color: var(--text); -moz-appearance: textfield;
}
.jump-in::-webkit-outer-spin-button, .jump-in::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.jump-in:focus { outline: 2px solid var(--accent-dim); border-color: var(--accent); }

/* category list view */
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px,1fr)); gap: 10px; }
.cat-tile { background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; padding: 14px; text-align: left; }
.cat-tile:hover { border-color: var(--accent); }
.cat-tile .name { font-weight: 600; margin-bottom: 6px; }
.cat-tile .bar { height: 5px; background: var(--bg-soft); border-radius: 3px; overflow: hidden; margin-top: 8px; }
.cat-tile .bar > div { height: 100%; background: var(--green); }
.cat-tile .nums { font-size: 12px; color: var(--text-dim); margin-top: 6px; }

/* 找題頁 */
.find-lead { color: var(--text-dim); font-size: 14px; line-height: 1.6; margin: 0 0 14px; }
.find-controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.find-controls #fSearch { flex: 1 1 240px; }
.find-summary { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 14px; color: var(--text-dim); margin: 4px 0 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.find-summary b { color: var(--text); }
.find-summary button { background: var(--accent); color: #fff; border: none; font-weight: 600; padding: 8px 16px; border-radius: 8px; }
.find-summary button.ghost { background: var(--bg-soft); color: var(--text); border: 1px solid var(--border); }
.find-list { display: flex; flex-direction: column; gap: 6px; max-height: 60vh; overflow-y: auto; }
.find-item { display: flex; align-items: center; gap: 10px; text-align: left; background: var(--bg-soft); border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px; cursor: pointer; }
.find-item:hover { border-color: var(--accent); }
.find-item .fi-num { color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums; flex-shrink: 0; min-width: 34px; }
.find-item .fi-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.find-item .fi-q { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.find-item .fi-cat { font-size: 12px; color: var(--text-dim); }
.find-item .fi-ok { color: var(--green); font-weight: 700; }
.find-item .fi-no { color: var(--red); font-weight: 700; }
.find-more { text-align: center; color: var(--text-dim); font-size: 12.5px; padding: 8px; }

/* Home / 說明 */
.home-title { margin: 0 0 8px; font-size: 24px; }
.home-lead { color: var(--text-dim); font-size: 15.5px; margin: 0 0 20px; }
.home-lead b { color: var(--text); }
.home-cta { display: flex; align-items: center; gap: 14px; margin-bottom: 26px; flex-wrap: wrap; }
.home-cta button { background: var(--accent); color: #fff; border: none; font-weight: 700; font-size: 16px; padding: 12px 26px; border-radius: 10px; cursor: pointer; }
.home-cta button:hover { filter: brightness(1.1); }
.home-cta button.cta-ghost { background: var(--bg-soft); color: var(--text); border: 1px solid var(--border); }
.home-cta button:disabled { opacity: .4; cursor: not-allowed; filter: none; }
/* 從頭/繼續 四顆按鈕：桌機 2×2、手機單欄 */
.home-cta-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 0; }
.home-cta-grid button { width: 100%; }
@media (max-width: 560px) { .home-cta-grid { grid-template-columns: 1fr; } }
.home-lastpos { font-size: 13.5px; color: var(--text-dim); margin: 0 0 8px; }
/* 🔀 打亂題號開關 */
.numshuf-box { margin-top: 16px; border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px; background: var(--bg-soft); transition: border-color .2s, background .2s; }
.numshuf-box.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--bg-soft)); }
.numshuf-row { display: flex; align-items: flex-start; gap: 14px; }
.numshuf-switch { flex: 0 0 auto; width: 50px; height: 28px; border-radius: 999px; border: none;
  background: var(--border); cursor: pointer; position: relative; padding: 0; transition: background .2s; margin-top: 2px; }
.numshuf-switch.on { background: var(--accent); }
.numshuf-switch .knob { position: absolute; top: 3px; left: 3px; width: 22px; height: 22px;
  border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.4); }
.numshuf-switch.on .knob { transform: translateX(22px); }
.numshuf-text { font-size: 13.5px; line-height: 1.5; }
.numshuf-text b { display: block; font-size: 15px; margin-bottom: 3px; color: var(--text); }
.numshuf-text span { color: var(--text-dim); }
.home-h { font-size: 16px; margin: 24px 0 12px; border-left: 3px solid var(--accent); padding-left: 10px; }
.howto { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px,1fr)); gap: 12px; }
.howto-item { display: flex; gap: 12px; background: var(--bg-soft); border: 1px solid var(--border); border-radius: 10px; padding: 14px; font-size: 14px; line-height: 1.55; }
.howto-item .ic { font-size: 22px; flex-shrink: 0; }
.howto-item b { color: var(--accent); }
.home-tips { color: var(--text-dim); font-size: 14px; line-height: 1.8; margin: 0; padding-left: 20px; }
.home-tips b { color: var(--text); }

.empty { text-align: center; color: var(--text-dim); padding: 60px 20px; }
/* 進站密碼閘 */
.gate { min-height: 85vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.gate-box { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 30px 26px; width: 100%; max-width: 340px; text-align: center; }
.gate-logo { width: 120px; height: auto; display: block; margin: 0 auto 6px; filter: drop-shadow(0 4px 10px rgba(0,0,0,.4)); }
.gate-title { font-size: 22px; font-weight: 700; }
.gate-sub { color: var(--text-dim); font-size: 14px; margin: 6px 0 20px; }
.gate-box input { width: 100%; text-align: center; font-size: 16px; padding: 12px; margin-bottom: 12px; }
.gate-box button { width: 100%; background: var(--accent); color: #fff; border: none; font-weight: 700; font-size: 16px; padding: 12px; border-radius: 8px; cursor: pointer; }
.gate-box button:hover { filter: brightness(1.1); }
.gate-err { color: var(--red); font-size: 13px; min-height: 18px; margin-top: 10px; }

.audit-note { border-radius: 8px; padding: 10px 12px; margin: 10px 0 14px; font-size: 13.5px; line-height: 1.6; }
.audit-note.corrected { background: var(--green-bg); border: 1px solid var(--green); }
.audit-note.disputed { background: #2e2410; border: 1px solid var(--amber); }
.audit-note b { color: var(--text); }
.audit-note .ar { color: var(--text-dim); font-size: 12.5px; }

.app-loading { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 70px 20px; color: var(--text-dim); }
.boot-spinner { width: 42px; height: 42px; border-radius: 50%; border: 4px solid var(--border); border-top-color: var(--accent); animation: boot-spin .8s linear infinite; }
@keyframes boot-spin { to { transform: rotate(360deg); } }
.toggle-link { background: none; border: none; color: var(--accent); padding: 0; font-size: 13px; text-decoration: underline; cursor: pointer; }
.star { background: none; border: none; cursor: pointer; font-size: 20px; line-height: 1; color: var(--text-dim); padding: 0 4px; }
.star.on { color: var(--amber); }
.shuf-btn.on { background: var(--accent); color: #fff; border-color: transparent; }
.danger-link { background: none; border: none; color: var(--red); font-size: 13px; text-decoration: underline; cursor: pointer; margin-left: auto; padding: 0; }
.wrongbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; background: var(--red-bg); border: 1px solid var(--red); border-radius: 8px; padding: 9px 12px; margin-bottom: 14px; font-size: 13.5px; color: var(--text); }
.wrongbar b { color: var(--red); }
.hidden { display: none; }
footer { text-align: center; color: var(--text-dim); font-size: 12px; margin-top: 30px; }

/* 模擬考 / 篩選按鈕 */
.exam-btn { background: var(--amber); color: #1a1206; border-color: transparent; font-weight: 600; }
.exam-btn:hover { filter: brightness(1.08); }
.shuf-btn.on { background: var(--accent); color: #fff; border-color: transparent; }

/* 模擬考進行中：隱藏工具列的「模擬考」鈕（已在考試中） */
.toolbar.exam-mode #examBtn { display: none; }

/* 模擬考：作答中 */
.exam-bar {
  position: sticky; top: 64px; z-index: 15;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: 10px;
  padding: 9px 14px; margin-bottom: 14px; font-size: 14px; color: var(--text-dim);
}
.exam-bar b { color: var(--text); font-variant-numeric: tabular-nums; }
.exam-submit { background: var(--red); color: #fff; border: none; font-weight: 700; padding: 7px 16px; }
.exam-abandon { background: transparent; color: var(--text-dim); border: 1px solid var(--border); padding: 7px 14px; }
.exam-abandon:hover { color: var(--red); border-color: var(--red); }
.opt.picked { background: var(--accent-dim); border-color: var(--accent); }
.opt.picked .letter { color: #cfe4ff; }

.exam-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 6px; margin-top: 16px; border-top: 1px dashed var(--border); padding-top: 14px; }
.gcell { padding: 8px 0; font-size: 13px; border: 1px solid var(--border); background: var(--bg-soft); color: var(--text-dim); border-radius: 6px; font-variant-numeric: tabular-nums; }
.gcell.done { background: var(--accent-dim); color: #cfe4ff; border-color: transparent; }
.gcell.flag { box-shadow: inset 0 0 0 2px var(--amber); }
.gcell.cur { outline: 2px solid var(--accent); }

/* 模擬考：設定頁 */
.exam-opts { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.chipbtn { padding: 8px 16px; border: 1px solid var(--border); background: var(--bg-soft); color: var(--text); border-radius: 8px; }
.chipbtn.on { background: var(--accent); color: #fff; border-color: transparent; font-weight: 600; }
.exam-check { display: flex; align-items: center; gap: 8px; margin: 14px 0 4px; font-size: 14px; color: var(--text-dim); cursor: pointer; }
.exam-check input { width: 16px; height: 16px; }

/* 模擬考：結果頁 */
.exam-score { text-align: center; border-radius: 12px; padding: 20px; margin-bottom: 18px; }
.exam-score.pass { background: var(--green-bg); border: 1px solid var(--green); }
.exam-score.fail { background: var(--red-bg); border: 1px solid var(--red); }
.exam-score .big { font-size: 46px; font-weight: 800; line-height: 1; }
.exam-score.pass .big { color: var(--green); }
.exam-score.fail .big { color: var(--red); }
.exam-score .lbl { margin-top: 8px; font-size: 14px; color: var(--text-dim); }
.exam-review { display: flex; flex-direction: column; gap: 12px; }
.rev-item { border: 1px solid var(--border); border-left-width: 3px; border-radius: 8px; padding: 12px 14px; background: var(--bg-soft); }
.rev-item.ok { border-left-color: var(--green); }
.rev-item.no { border-left-color: var(--red); }
.rev-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: 13px; color: var(--text-dim); margin-bottom: 6px; }
.rev-item.ok .rev-head b { color: var(--green); }
.rev-item.no .rev-head b { color: var(--red); }
.rev-q { font-size: 14.5px; margin-bottom: 6px; }
.rev-trans { color: var(--text-dim); font-size: 13px; border-left: 3px solid var(--accent-dim); padding-left: 10px; margin-bottom: 10px; white-space: pre-wrap; }
.rev-opts { display: flex; flex-direction: column; gap: 5px; font-size: 13.5px; margin-bottom: 8px; }
.ro { color: var(--text-dim); }
.ro .ro-zh { display: block; font-size: 12.5px; opacity: .8; margin: 1px 0 0 18px; }
.ro.c { color: var(--green); }
.ro.w { color: var(--red); }
.rev-exp { font-size: 13.5px; white-space: pre-wrap; border-top: 1px dashed var(--border); padding-top: 8px; }

/* 分頁列在窄螢幕可橫向滑動，不擠壓 */
.tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; max-width: 100%; }
.tabs::-webkit-scrollbar { display: none; }
.tab { white-space: nowrap; }

/* ---------- 手機 / 平板 RWD ---------- */
@media (max-width: 640px) {
  .app { padding: 0 10px 96px; }
  header { margin: 0 -10px 16px; padding: 10px 12px; }
  .brand { font-size: 16px; }
  .brand-logo { height: 26px; }
  #bankSel { max-width: 56vw; }
  .stats-bar { gap: 10px; font-size: 12px; }

  /* 工具列：分頁占一行，模擬考鈕同列 */
  .toolbar { flex-wrap: wrap; align-items: stretch; gap: 8px; }
  .toolbar .spacer { display: none; }
  .tabs { order: -1; flex: 1 1 100%; }
  #examBtn { flex: 1 1 auto; }
  /* 找題頁控制項手機換行 */
  .find-controls #fSearch { flex: 1 1 100%; }
  .find-controls #fCat, .find-controls #fStatus { flex: 1 1 44%; }
  .exam-bar { top: 56px; }

  /* 觸控放大：所有可點元件至少 ~44px 高、16px 字（避免 iOS 自動縮放） */
  select, button, input[type="text"] { font-size: 16px; padding: 11px 12px; }
  .tab { padding: 9px 14px; font-size: 15px; }

  .card { padding: 16px 14px; border-radius: 10px; }
  .q-text { font-size: 16.5px; }
  .q-meta { gap: 6px; }

  .opt { padding: 14px; gap: 10px; }
  .opt .otext { font-size: 15.5px; }
  .opt .otext .zh { font-size: 13.5px; }

  /* 上一題/下一題吸附在畫面底部，單手好按 */
  .nav {
    position: sticky; bottom: 0; z-index: 10;
    display: flex; flex-wrap: wrap; align-items: center;
    background: var(--bg-card);
    margin: 18px -14px -16px; padding: 12px 14px; gap: 8px;
    border-top: 1px solid var(--border);
  }
  .nav .spacer { display: none; }
  .nav button { flex: 1 1 0; padding: 13px 10px; font-size: 15px; }   /* 上一題/下一題 同列均分 */
  .nav .pos { flex: 1 1 100%; order: 3; text-align: center; margin: 2px 0 0; }  /* 進度自成一列 */
  #resetBtn { flex: 1 1 100%; order: 4; }                              /* 重做此題自成一列 */

  .cat-grid { grid-template-columns: 1fr; }
  .howto { grid-template-columns: 1fr; }
  .home-title { font-size: 21px; }
  .home-cta button { width: 100%; }
}
