/* 學測數學練習 [touhou_gsatmath]（版面沿用會考數學練習）
 * 全部規則只作用在 #tgm（練習本體）與 #tgm-zoom（點圖放大的全螢幕層，掛在 body 底下）。
 * 前半段是「防主題干擾」的重設：主題對 button / img / a / h1 / p / ol 等元素下的樣式，
 * 只要我們沒有明講同一個屬性就會滲進來，所以把會被動到的屬性先在 #tgm 裡講死。 */

/* ---------- 防主題干擾 ---------- */
#tgm, #tgm *, #tgm *::before, #tgm *::after { box-sizing: border-box; }
#tgm * {
  font-family: inherit; letter-spacing: normal; text-transform: none; text-shadow: none;
  word-spacing: normal; text-indent: 0; float: none;
}
#tgm div, #tgm span, #tgm p, #tgm li, #tgm b, #tgm small, #tgm label { line-height: inherit; }
#tgm p, #tgm ol, #tgm ul, #tgm li, #tgm details, #tgm summary, #tgm picture { font-size: inherit; }
#tgm img { max-width: 100%; height: auto; border: 0; border-radius: 0; box-shadow: none; padding: 0; margin: 0; opacity: 1; filter: none; }
#tgm a { text-decoration: underline; text-underline-offset: 2px; box-shadow: none; background: none; border: 0; }
#tgm button, #tgm select {
  text-transform: none; letter-spacing: normal; box-shadow: none; text-shadow: none;
  line-height: 1.3; width: auto; height: auto; margin: 0; outline-offset: 2px;
  background-image: none; transform: none; transition: background-color .15s, border-color .15s;
}
#tgm button:focus-visible, #tgm select:focus-visible, #tgm .qimg:focus-visible { outline: 2px solid #2A5A87; }
#tgm ol, #tgm ul { list-style-position: outside; }
#tgm ol { list-style-type: decimal; }
#tgm ul { list-style-type: disc; }
#tgm details { display: block; }
#tgm summary { display: list-item; }
#tgm svg.i { display: inline-block; vertical-align: middle; max-width: none; }
#tgm .card, #tgm .msg, #tgm .weak, #tgm .progress, #tgm .qimg, #tgm .tgm-loading, #tgm .sol { display: block; }
#tgm .opt, #tgm .chip, #tgm .qlist button { text-align: center; }
#tgm .btn { justify-content: center; text-align: center; }
#tgm h1::before, #tgm h1::after, #tgm h2::before, #tgm h2::after, #tgm h3::before, #tgm h3::after { content: none; }

/* ---------- 版面 ---------- */
#tgm {
  --bg:#F6F1E9; --card:#FFFDF9; --ink:#16233d; --ink2:#4a5468; --line:#E4DACB;
  --brand:#a8705c; --brand-dk:#8F5B48; --brand-soft:#F1E4DC;
  --ok:#2F6B45; --ok-bg:#E9F0EA; --err:#C0392B; --err-bg:#F8E9E5;
  --info:#2A5A87; --info-bg:#E8EEF3; --warn:#8A6100; --warn-bg:#F3ECDD;
  font-family: "Noto Sans TC", system-ui, -apple-system, "PingFang TC", "Microsoft JhengHei", sans-serif;
  color: var(--ink); background: var(--bg);
  line-height: 1.65; font-size: 16px; font-weight: 400; text-align: left; -webkit-text-size-adjust: 100%;
  max-width: 760px; width: 100%; margin: 0 auto; padding: 20px 16px 48px; border-radius: 16px;
  min-height: 360px;
}
#tgm .tgm-loading { color: var(--ink2); padding: 40px 0; text-align: center; }
#tgm h1, #tgm h2, #tgm h3 { font-family: "Noto Serif TC", "Songti TC", serif; color: var(--ink); line-height: 1.35; margin: 0; padding: 0; font-weight: 600; border: 0; background: none; }
#tgm h1 { font-size: 26px; } #tgm h2 { font-size: 20px; } #tgm h3 { font-size: 17px; }
#tgm p { margin: .4em 0; padding: 0; color: inherit; }
#tgm .muted { color: var(--ink2); font-size: 14px; }
#tgm .card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px; margin: 14px 0; }
#tgm .btn { appearance: none; -webkit-appearance: none; border: 1.5px solid var(--brand); background: var(--brand); color: #fff; font: inherit; font-size: 16px; font-weight: 500;
  border-radius: 10px; padding: 11px 18px; min-height: 46px; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; text-decoration: none; }
#tgm .btn:hover, #tgm .btn:focus { background: var(--brand-dk); border-color: var(--brand-dk); color: #fff; }
#tgm .btn.ghost { background: transparent; color: var(--brand-dk); }
#tgm .btn.ghost:hover, #tgm .btn.ghost:focus { background: var(--brand-soft); color: var(--brand-dk); }
#tgm .btn.small { min-height: 38px; padding: 7px 13px; font-size: 15px; }
#tgm .btn[disabled] { opacity: .45; cursor: default; }
#tgm .row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
#tgm .chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
#tgm .chip { appearance: none; -webkit-appearance: none; border: 1.5px solid var(--line); background: #fff; color: var(--ink); border-radius: 999px; padding: 8px 14px; font: inherit; font-size: 15px; font-weight: 400; cursor: pointer; min-height: 42px; }
#tgm .chip:hover, #tgm .chip:focus { border-color: var(--brand); background: #fff; color: var(--ink); }
#tgm .chip b { color: var(--brand-dk); font-weight: 500; margin-left: 4px; }
#tgm .chip.on, #tgm .chip.on:hover, #tgm .chip.on:focus { border-color: var(--brand); background: var(--brand); color: #fff; }
#tgm .chip.on b { color: #fff; }
#tgm select { appearance: auto; -webkit-appearance: menulist; font: inherit; font-size: 16px; padding: 10px; border-radius: 10px; border: 1.5px solid var(--line); background: #fff; color: var(--ink); max-width: 100%; min-height: 46px; }
#tgm svg.i { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* 題目 */
#tgm .qhead { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 6px; }
#tgm .progress { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin: 6px 0 12px; }
#tgm .progress i { display: block; height: 100%; background: var(--brand); }
#tgm .qimg { display: block; margin: 0 -8px; cursor: zoom-in; position: relative; }
#tgm .qimg img { display: block; width: 100%; height: auto; background: #fff; border-radius: 8px; min-height: 40px; }
#tgm .qimg .zoomtip { display: flex; justify-content: flex-end; gap: 4px; align-items: center; color: var(--ink2); font-size: 13px; margin-top: 4px; }
#tgm .qimg .zoomtip svg { width: 14px; height: 14px; }
#tgm details.passage { border: 1px dashed var(--line); border-radius: 10px; padding: 8px 10px; margin: 0 0 12px; background: #fff; }
#tgm details.passage summary { cursor: pointer; color: var(--brand-dk); font-weight: 500; }
#tgm .opts { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-top: 14px; }
#tgm .opt { appearance: none; -webkit-appearance: none; font: inherit; font-size: 20px; font-weight: 700; min-height: 56px; padding: 0 4px; border-radius: 12px; border: 2px solid var(--line); background: #fff; color: var(--ink); cursor: pointer; }
#tgm .opt:hover:not([disabled]), #tgm .opt:focus:not([disabled]) { border-color: var(--brand); background: #fff; color: var(--ink); }
#tgm .opt.pick-wrong, #tgm .opt.pick-wrong:hover, #tgm .opt.pick-wrong:focus { border-color: var(--err); background: var(--err-bg); color: var(--err); }
#tgm .opt.pick-right, #tgm .opt.pick-right:hover, #tgm .opt.pick-right:focus { border-color: var(--ok); background: var(--ok-bg); color: var(--ok); }
#tgm .opt.is-answer { border-color: var(--ok); box-shadow: inset 0 0 0 2px var(--ok); }
#tgm .opt[disabled] { cursor: default; opacity: 1; }
#tgm .msg { border-left: 4px solid var(--info); background: var(--info-bg); padding: 10px 12px; border-radius: 6px; margin-top: 12px; color: var(--ink); }
#tgm .msg.ok { border-color: var(--ok); background: var(--ok-bg); }
#tgm .msg.err { border-color: var(--err); background: var(--err-bg); }
#tgm .msg.warn { border-color: var(--warn); background: var(--warn-bg); }
#tgm .msg .t { font-weight: 700; display: flex; gap: 6px; align-items: center; }
#tgm .msg .t svg { width: 18px; height: 18px; }
#tgm .sol ol { margin: 6px 0 0; padding: 0 0 0 1.4em; }
#tgm .sol ul { margin: 4px 0; padding: 0 0 0 1.3em; }
#tgm .sol li { margin: 3px 0; padding: 0; }
#tgm .tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
#tgm .tag { font-size: 13px; border-radius: 6px; padding: 2px 8px; background: var(--brand-soft); color: var(--brand-dk); }
#tgm .tag.navy { background: #E6E9EF; color: var(--ink); }
#tgm .actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
#tgm .lk { color: var(--brand-dk); font-weight: 500; }
#tgm .lk:hover { color: var(--ink); }

/* 結果 */
#tgm .score { font-family: "Noto Serif TC", "Songti TC", serif; font-size: 44px; font-weight: 600; color: var(--ink); line-height: 1; }
#tgm .score small { font-size: 20px; color: var(--ink2); }
#tgm .meter { display: grid; grid-template-columns: 8.2em 1fr 4.2em; gap: 10px; align-items: center; margin: 8px 0; font-size: 15px; }
#tgm .meter .bar { height: 12px; background: var(--line); border-radius: 6px; overflow: hidden; display: block; }
#tgm .meter .bar i { display: block; height: 100%; background: var(--ink); }
#tgm .meter .bar i.low { background: var(--brand); }
#tgm .meter .v { text-align: right; font-variant-numeric: tabular-nums; }
#tgm .weak { border-left: 4px solid var(--brand); padding: 8px 12px; margin: 10px 0; background: var(--brand-soft); border-radius: 6px; }
#tgm .weak a { color: var(--brand-dk); font-weight: 500; }
#tgm .qlist { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-top: 10px; }
#tgm .qlist button { appearance: none; -webkit-appearance: none; font: inherit; font-size: 14px; min-height: 44px; padding: 0 2px; border-radius: 8px; border: 1.5px solid var(--line); background: #fff; cursor: pointer; color: var(--ink); }
#tgm .qlist button.r, #tgm .qlist button.r:hover, #tgm .qlist button.r:focus { border-color: var(--ok); color: var(--ok); background: #fff; }
#tgm .qlist button.w, #tgm .qlist button.w:hover, #tgm .qlist button.w:focus { border-color: var(--err); color: var(--err); background: #fff; }

/* 點圖放大（掛在 body 底下，避免祖先元素的 transform 讓 position:fixed 失效） */
#tgm-zoom { position: fixed; inset: 0; background: rgba(22,35,61,.92); z-index: 999999; display: none; overflow: auto; -webkit-overflow-scrolling: touch; }
#tgm-zoom.on { display: block; }
#tgm-zoom img { display: block; background: #fff; margin: 56px auto 24px; max-width: none; height: auto; border: 0; border-radius: 0; box-shadow: none; padding: 0; }
#tgm-zoom button { appearance: none; -webkit-appearance: none; position: fixed; top: 10px; right: 10px; font: 16px/1.3 "Noto Sans TC", system-ui, sans-serif; text-transform: none; letter-spacing: normal;
  border: 0; border-radius: 10px; padding: 9px 14px; margin: 0; min-height: 0; width: auto; background: #fff; color: #16233d; cursor: pointer; box-shadow: none; }
#tgm-zoom button:hover, #tgm-zoom button:focus { background: #F1E4DC; color: #16233d; }
#tgm-zoom .z { position: fixed; top: 10px; left: 10px; display: flex; gap: 8px; }
#tgm-zoom .z button { position: static; }
body.tgm-noscroll { overflow: hidden; }

/* 手機上網站右下角有小助教浮動鈕（約 100px 高），底部多留白，最後一排按鈕與 LINE 連結才不會被蓋住 */
@media (max-width: 520px) {
  #tgm { padding: 14px 12px 104px; border-radius: 12px; }
  #tgm h1 { font-size: 23px; }
  #tgm .card { padding: 14px 12px; }
  #tgm .qimg { margin: 0 -6px; }
  #tgm .opts { gap: 8px; }
}

/* ---------- 學測版新增：多選、選填、非選、KaTeX ---------- */
#tgm .opt.sel, #tgm .opt.sel:hover, #tgm .opt.sel:focus { border-color: var(--info); background: var(--info-bg); color: var(--info); }
#tgm .opt.missed { border-style: dashed; border-color: var(--ok); color: var(--ok); }
#tgm .qtype { display: inline-block; font-size: 13px; border-radius: 6px; padding: 1px 8px; margin-left: 6px; background: #E6E9EF; color: var(--ink); vertical-align: 1px; }
#tgm .howto { font-size: 14px; color: var(--ink2); margin: 12px 0 0; }
#tgm .cells { display: flex; flex-wrap: wrap; gap: 10px 14px; margin-top: 14px; }
#tgm .cell { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 14px; color: var(--ink2); }
#tgm .cell select { min-width: 64px; min-height: 52px; font-size: 20px; font-weight: 700; text-align: center; padding: 6px; }
#tgm .cell.right select { border-color: var(--ok); background: var(--ok-bg); color: var(--ok); }
#tgm .cell.wrong select { border-color: var(--err); background: var(--err-bg); color: var(--err); }
#tgm .rubric { border-left: 4px solid var(--ink); background: #EEF0F4; padding: 10px 12px; border-radius: 6px; margin-top: 12px; }
#tgm .rubric .t { font-weight: 700; }
#tgm .rubric ul { margin: 6px 0 0; padding: 0 0 0 1.3em; }
#tgm .credit { font-size: 13px; color: var(--ink2); margin: 6px 0 0; }
#tgm .katex { font-size: 1.08em; }
#tgm .sol li, #tgm .msg p, #tgm .rubric li { overflow-wrap: anywhere; }
#tgm .katex-display { margin: .4em 0; }
@media (max-width: 520px) {
  #tgm .opt { font-size: 18px; min-height: 52px; }
  #tgm .cell select { min-width: 58px; }
}

/* 數A／數B 切換（頁面最上方） */
#tgm .subj { display: inline-flex; gap: 0; margin: 12px 0 4px; border: 1.5px solid var(--brand); border-radius: 12px; overflow: hidden; }
#tgm .subjbtn { appearance: none; -webkit-appearance: none; font: inherit; font-size: 16px; font-weight: 500; min-height: 44px; padding: 8px 22px; border: 0; border-radius: 0; background: #fff; color: var(--brand-dk); cursor: pointer; }
#tgm .subjbtn + .subjbtn { border-left: 1.5px solid var(--brand); }
#tgm .subjbtn:hover, #tgm .subjbtn:focus { background: var(--brand-soft); color: var(--brand-dk); }
#tgm .subjbtn.on, #tgm .subjbtn.on:hover, #tgm .subjbtn.on:focus { background: var(--brand); color: #fff; }
