/* hidden 屬性要贏過下面的 display:flex（.chips、.pick），不然藏不起來 */
[hidden] { display: none !important; }
:root {
  color-scheme: light dark;
  --fg: #1a1a1a; --bg: #ffffff; --muted: #767676; --line: #e3e3e3; --accent: #c0392b;
}
@media (prefers-color-scheme: dark) {
  :root { --fg: #ececec; --bg: #111111; --muted: #9a9a9a; --line: #2a2a2a; }
}
html, body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 16px/1.5 -apple-system, "Segoe UI", "Noto Sans Thai", "Leelawadee UI", Thonburi, Loma, sans-serif;
}
body:not(.page) { min-height: 100vh; display: grid; place-items: center; }
#card { text-align: center; padding: 2rem 1.25rem 5rem; max-width: 46rem; width: 100%; box-sizing: border-box; }
#word { font-size: clamp(3rem, 14vw, 9rem); font-weight: 400; line-height: 1.3; margin: .15em 0 .1em; }
.reading { font-size: 1.25rem; color: var(--muted); margin: 0; }
.meaning { font-size: 1.6rem; margin: .4em 0 .8em; }
.examples p { margin: .35em 0; }
.ex { display: block; font-size: 1.3rem; }
.exm { display: block; font-size: 1rem; color: var(--muted); }
.rate { display: flex; gap: .6rem; justify-content: center; flex-wrap: wrap; margin-top: 1.8rem; }
.rate button {
  font: inherit; color: inherit; background: transparent; border: 1px solid currentColor; border-radius: 999px;
  padding: .5em 1.2em; min-width: 6.5rem; cursor: pointer; opacity: .8;
  display: flex; flex-direction: column; align-items: center; gap: .1em;
}
.rate button small { font-size: .75rem; color: var(--muted); }
.rate button:hover, .rate button:focus-visible { opacity: 1; }
.rate button.again { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hint { font-size: .8rem; margin-top: 1.2rem; }
footer { position: fixed; right: 1rem; bottom: 1rem; display: flex; gap: .9rem; align-items: center; }
footer a { text-decoration: none; font-size: 1.4rem; }
#empty { text-align: center; padding: 1rem; }
/* v0.7.1：設定頁與學習頁整體放大兩倍（根字級 16→32px，rem 全跟著變）；新分頁不受影響 */
html:has(body.page) { font-size: 32px; }
body.page { font-size: 1rem; }  /* body 原本寫死 16px，內文要跟著根字級走 */
.page select, .page input, .page button, .page textarea { font: inherit; }  /* 下拉、按鈕也要跟著變大 */
.page { max-width: 42rem; margin: 0 auto; padding: 1.2rem 1rem 3rem; }
.page input[type="checkbox"], .page input[type="radio"] { width: 1em; height: 1em; vertical-align: -.1em; }
.page h1 { margin-top: 0; }
.box { border: 1px solid var(--line); border-radius: 10px; padding: 1rem 1.25rem; margin: 1rem 0; }
.box h2 { font-size: 1.05rem; margin: 0 0 .6rem; }
.box label { margin-right: 1rem; }
.disabled { opacity: .5; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .4rem .3rem; border-bottom: 1px solid var(--line); }
td button { font: inherit; font-size: .85rem; margin-right: .4rem; }
code { font-family: ui-monospace, Menlo, monospace; font-size: .9em; }
#status.bad { color: var(--accent); }
input[type="text"] { font: inherit; padding: .25em .5em; min-width: 14rem; }
button { font: inherit; }

/* v0.2：分類標籤、底部兩個下拉、今天額度用完 */
.chips { display: flex; flex-wrap: wrap; gap: .35rem; justify-content: center; margin: -.2em 0 .6em; }
.chip { font-size: .72rem; letter-spacing: .02em; padding: .12em .6em; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.chip.cat { border-color: transparent; background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--fg); }
.chip.rank { font-variant-numeric: tabular-nums; }
footer { left: 1rem; right: 1rem; justify-content: flex-end; flex-wrap: wrap; row-gap: .4rem; }
.pick { font-size: .85rem; color: var(--muted); display: inline-flex; align-items: center; gap: .35rem; margin-right: auto; }
.pick + .pick { margin-right: auto; }
.pick select { font: inherit; font-size: .85rem; max-width: 14rem; }
#done { text-align: center; padding: 1rem; max-width: 30rem; }
#done .actions { display: flex; gap: .6rem; justify-content: center; flex-wrap: wrap; }

/* v0.3：英文開關（設定頁；關著就不畫英文意思與例句翻譯；按住字偷看） */
html.no-en:not(.peek) #meaning, html.no-en:not(.peek) .exm-en { display: none; }
/* v0.5：國語意思是主線；兩個語言都開著時英文退成副線 */
html.no-zh:not(.peek) #meaningZh, html.no-zh:not(.peek) .exm-zh { display: none; }
.meaning-zh { font-size: 1.7rem; margin: .35em 0 .15em; }
html:not(.no-zh) #meaningZh:not([hidden]) + #meaning { font-size: 1.15rem; color: var(--muted); margin-top: 0; }
.exm-zh { color: var(--fg); font-size: 1.05rem; }
/* v0.4：翻卡模式 —— 先只露出勾的部分，空白鍵（或點卡片）翻開 */
#card.quiz:not(.revealed) #chips, #card.quiz:not(.revealed) #examples, #card.quiz:not(.revealed) #rate { display: none; }
#card.quiz:not(.revealed):not(.first-word) #word { display: none; }
#card.quiz:not(.revealed):not(.first-reading) #reading { display: none; }
#card.quiz:not(.revealed):not(.first-meaning) #meaning { display: none; }
#card.quiz:not(.revealed):not(.first-mandarin) #meaningZh { display: none; }
#card.quiz:not(.revealed) { cursor: pointer; }
kbd { font: inherit; font-size: .85em; border: 1px solid var(--line); border-radius: 4px; padding: 0 .3em; }
.parts { display: flex; flex-wrap: wrap; gap: .3rem 1rem; align-items: center; }
#word { user-select: none; -webkit-user-select: none; }
html.no-en #word { cursor: help; }
#done button { font: inherit; padding: .5em 1.2em; border-radius: 999px; border: 1px solid currentColor; background: transparent; color: inherit; cursor: pointer; }

/* v0.7：AI 例句區塊（在例句下面；右鍵或 ↻ 重新生成） */
.ai { position: relative; margin: .8em auto 0; padding: .6em 2.2em .6em 1em; max-width: 34rem; border-left: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); text-align: left; }
.ai p { margin: .2em 0; font-size: 1.05rem; }
.ai p[lang="th"] { font-size: 1.35rem; }
.ai.loading, .ai.bad { color: var(--muted); font-size: .9rem; }
.ai.bad { color: var(--accent); }
.ai-again { position: absolute; right: .3em; top: .4em; font: inherit; font-size: .9rem; border: 1px solid var(--line); border-radius: 999px; background: transparent; color: var(--muted); cursor: pointer; width: 1.7em; height: 1.7em; line-height: 1; }
.ai-again:hover { color: var(--fg); }
#card.quiz:not(.revealed) #ai { display: none; }
#aiSettings textarea { width: 100%; max-width: 40rem; font: inherit; font-size: .9rem; box-sizing: border-box; }
.keyRow { margin: .4rem 0; display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.keyRow input[type="password"] { font: inherit; padding: .25em .5em; min-width: 18rem; }
.vars code { margin-right: .4em; }

/* v0.6：學習頁（文章＋小遊戲） */
.learn { max-width: 56rem; }
.toc { display: flex; flex-wrap: wrap; gap: .5rem; margin: 0 0 1rem; }
.toc a { text-decoration: none; border: 1px solid var(--line); border-radius: 999px; padding: .25em .9em; color: var(--fg); font-size: .9rem; }
.toc a.active { border-color: currentColor; }
.art-title { font-size: 1.6rem; margin: .5rem 0; }
.prose h2 { font-size: 1.1rem; margin: 1.2rem 0 .4rem; }
.prose p, .prose li { max-width: 46rem; }
.learn-links { margin: .2rem 0 .6rem; padding-left: 1.2rem; }
.learn-links li { margin: .2em 0; }
/* 學習頁的表格：不撐滿、欄位靠緊、字母格不吃寬度 */
.learn table { width: auto; }
.cls-table { margin: .6rem 0 1rem; }
.cls-table th, .cls-table td { padding: .15rem .7rem; vertical-align: middle; }
.cls-table th:first-child { font-size: 1rem; white-space: nowrap; }
.th-letter { font-size: 2.4rem; line-height: 1; width: 1%; white-space: nowrap; }  /* 根字級已加倍 → 等於原本的三倍 */
.learn .prose td[lang="th"], .learn .tone-list td:nth-child(2) { font-size: 1.15em; }
.tone-list td, .tone-list th { padding: .3rem .5rem; }
.toggles { display: flex; flex-wrap: wrap; gap: .4rem 1.2rem; }
.toggle-line { font-size: .9rem; }
.game { outline: none; }
.game:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
.game-q { margin: 0 0 .6rem; color: var(--muted); font-size: .9rem; }
.game-stage { text-align: center; min-height: 7rem; }
.game-stage .big { font-size: clamp(4.5rem, 14vw, 8rem); line-height: 1.25; }
.opts { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; margin: .6rem 0; }
.opts button { font: inherit; color: inherit; background: transparent; border: 1px solid currentColor; border-radius: 999px; padding: .5em 1.1em; min-width: 5.5rem; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: .1em; }
.opts button small { font-size: .7rem; color: var(--muted); }
.opts button.ok { background: color-mix(in srgb, #2e7d32 18%, transparent); border-color: #2e7d32; }
.opts button.bad { background: color-mix(in srgb, var(--accent) 18%, transparent); border-color: var(--accent); }
.opts button:disabled { cursor: default; }
.game-fb { min-height: 1.6em; text-align: center; margin: .4rem 0; }
.game-fb.ok strong { color: #2e7d32; }
.game-fb.bad strong { color: var(--accent); }
.game-next { display: block; margin: .3rem auto; font: inherit; padding: .4em 1.1em; border-radius: 999px; border: 1px solid currentColor; background: transparent; color: inherit; cursor: pointer; }
.game-score { text-align: center; margin: .4rem 0 0; }
.tone-layout { display: grid; grid-template-columns: minmax(0, 1fr) 24rem; gap: 1.2rem; align-items: start; }
.rule-side { position: sticky; top: 1rem; margin: 2.6rem 0 0; }
.rule-table { font-size: .85rem; }
.rule-table th, .rule-table td { padding: .3rem .25rem; text-align: center; }
.rule-table th small { font-weight: 400; color: var(--muted); }
.rule-table tbody th { text-align: left; white-space: nowrap; }
.rule-table td.hit { outline: 2px solid var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); font-weight: 600; }
@media (max-width: 60rem) { .tone-layout { grid-template-columns: 1fr; } .rule-side { position: static; margin: 0; } }
