:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #1b1f27;
  --muted: #6b7380;
  --line: #e2e6ee;
  --brand: #1261d9;
  --brand-soft: #e6efff;
  --ok: #138a43;
  --ok-soft: #e3f6ea;
  --bad: #d23a3a;
  --bad-soft: #fdeaea;
  --shadow: 0 1px 3px rgba(20, 30, 50, .08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101318;
    --card: #1a1f27;
    --text: #e8ebf0;
    --muted: #98a1ae;
    --line: #2b323d;
    --brand: #5b9bff;
    --brand-soft: #1d2b45;
    --ok: #4cc77d;
    --ok-soft: #183526;
    --bad: #ff6b6b;
    --bad-soft: #3d1f22;
    --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 17px/1.6 -apple-system, BlinkMacSystemFont, "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", sans-serif;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
[hidden] { display: none !important; }
sub, sup { font-size: .7em; line-height: 0; }

.screen { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.wrap { width: 100%; max-width: 720px; margin: 0 auto; padding: 12px 16px 24px; flex: 1; }

.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 10px;
  background: var(--bg);
}
.bar h1 { font-size: 22px; margin: 0 4px; }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; }
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn:active { background: var(--line); }
.text-btn { padding: 8px 12px; border-radius: 10px; color: var(--brand); font-weight: 600; }
.text-btn:active { background: var(--brand-soft); }

/* 首頁 */
.cats { display: grid; gap: 12px; }
.cat {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  padding: 18px; border-radius: 18px; background: var(--card); box-shadow: var(--shadow);
}
.cat:active { transform: scale(.98); }
.cat .ic { width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center; font-size: 28px; background: var(--brand-soft); flex: none; }
.cat .body { flex: 1; min-width: 0; }
.cat b { display: block; font-size: 20px; }
.cat small { color: var(--muted); font-size: 14px; }
.cat .go { color: var(--brand); font-weight: 700; flex: none; }
.cat-wrap { background: var(--card); border-radius: 18px; box-shadow: var(--shadow); overflow: hidden; }
.cat-wrap .cat { box-shadow: none; border-radius: 0; }
.prac {
  display: block; width: 100%; padding: 12px 18px; text-align: center;
  border-top: 1px solid var(--line); color: var(--bad); font-weight: 600; font-size: 15px;
}
.prac:active { background: var(--bad-soft); }
.resume {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; margin-bottom: 12px;
  padding: 14px 18px; border-radius: 18px; background: var(--brand); color: #fff; box-shadow: var(--shadow);
}
.resume b { font-size: 18px; display: block; }
.resume small { opacity: .85; font-size: 14px; }
.resume .body { flex: 1; }
.sec-title { font-size: 15px; color: var(--muted); font-weight: 600; margin: 24px 4px 8px; }
.hist { list-style: none; margin: 0; padding: 0; background: var(--card); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; }
.hist li + li { border-top: 1px solid var(--line); }
.hist button { width: 100%; display: flex; align-items: center; gap: 12px; padding: 12px 16px; text-align: left; }
.hist button:active { background: var(--line); }
.hist .when { flex: 1; font-size: 15px; }
.hist .when small { display: block; color: var(--muted); font-size: 13px; }
.hist .pts { font-size: 20px; font-weight: 700; }
.pass { color: var(--ok); }
.fail { color: var(--bad); }

/* 作答 */
.quiz-bar { justify-content: space-between; }
.quiz-title { flex: 1; text-align: center; font-size: 15px; color: var(--muted); }
.quiz-title b { color: var(--text); margin-left: 6px; font-size: 17px; }
.quiz-title small { margin-left: 8px; font-variant-numeric: tabular-nums; }
.practice #submitTop, .practice #gridBtn { visibility: hidden; }
.progress { height: 4px; background: var(--line); }
.progress i { display: block; height: 100%; width: 0; background: var(--brand); transition: width .2s; }
.qcard { background: var(--card); border-radius: 18px; padding: 16px 18px; box-shadow: var(--shadow); }
.tag { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.qtext { font-size: 18px; font-weight: 600; white-space: pre-wrap; overflow-wrap: anywhere; }
/* 題目圖是 150dpi 轉出來的，用一半寬度顯示≈原本 12pt 字大小；比螢幕寬就左右滑 */
.qimg-wrap { overflow-x: auto; margin-top: 10px; border-radius: 10px; background: #fff; -webkit-overflow-scrolling: touch; }
.qimg { display: block; max-width: none; height: auto; }
.opts { display: grid; gap: 10px; margin-top: 14px; }
.opt {
  display: flex; gap: 10px; align-items: flex-start; width: 100%; text-align: left;
  padding: 14px 16px; border-radius: 14px; background: var(--card); border: 2px solid var(--line);
  overflow-wrap: anywhere;
}
.opt .no { font-weight: 700; color: var(--brand); flex: none; }
.opt.only { justify-content: center; font-size: 22px; }
.opt.sel { border-color: var(--brand); background: var(--brand-soft); }
.opt.right { border-color: var(--ok); background: var(--ok-soft); color: var(--ok); font-weight: 600; }
.opt.right .no { color: var(--ok); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); color: var(--bad); }
.opt.wrong .no { color: var(--bad); }
.opt.dim { opacity: .55; }
.opt:active { transform: scale(.99); }
.nav {
  position: sticky; bottom: 0; display: flex; gap: 8px;
  padding: 10px 12px calc(env(safe-area-inset-bottom) + 10px);
  background: var(--bg); border-top: 1px solid var(--line);
}
.nav-btn { flex: 1; padding: 12px 8px; border-radius: 12px; background: var(--card); font-weight: 600; box-shadow: var(--shadow); }
.nav-btn:disabled { opacity: .35; }
.nav-btn.primary { background: var(--brand); color: #fff; }
.grid-btn { flex: .9; color: var(--muted); }

.sheet { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .4); display: flex; align-items: flex-end; }
.sheet-panel {
  width: 100%; max-width: 720px; margin: 0 auto; max-height: 85vh; overflow: auto;
  background: var(--bg); border-radius: 20px 20px 0 0; padding: 12px 16px calc(env(safe-area-inset-bottom) + 16px);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: 8px; }
.grid button { aspect-ratio: 1; border-radius: 10px; background: var(--card); border: 1.5px solid var(--line); font-size: 15px; }
.grid button.done { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); font-weight: 700; }
.grid button.cur { outline: 2.5px solid var(--text); outline-offset: 1px; }
.big-btn { display: block; width: 100%; margin-top: 16px; padding: 14px; border-radius: 14px; background: var(--brand); color: #fff; font-weight: 700; font-size: 17px; }

/* 成績 */
.score-card { background: var(--card); border-radius: 20px; padding: 20px; text-align: center; box-shadow: var(--shadow); }
.score b { font-size: 64px; line-height: 1.1; }
.score span { font-size: 20px; margin-left: 4px; }
.meta { color: var(--muted); }
.row .big-btn { margin-top: 14px; }
.wq { background: var(--card); border-radius: 16px; padding: 14px 16px; margin-bottom: 12px; box-shadow: var(--shadow); }
.wq .qtext { font-size: 16px; }
.wq ul { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; }
.wq li { padding: 8px 12px; border-radius: 10px; display: flex; gap: 8px; font-size: 15px; overflow-wrap: anywhere; }
.wq li .no { flex: none; font-weight: 700; }
.wq li.right { background: var(--ok-soft); color: var(--ok); font-weight: 600; }
.wq li.wrong { background: var(--bad-soft); color: var(--bad); text-decoration: line-through; }
.wq .skip { margin-top: 8px; font-size: 14px; color: var(--bad); }
.all-ok { text-align: center; color: var(--ok); font-size: 18px; padding: 24px 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 90px); transform: translateX(-50%);
  background: rgba(20, 24, 30, .92); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 15px; z-index: 30;
  max-width: calc(100% - 32px);
}
