/* 國中英語精熟 — 單字與文法，同一頁。

   本來是兩頁（/junior-high-words/ 和 /junior-high-grammar/），2026-08-21 合成
   一頁：學生只要拿一個網址，而且切單字／文法不換頁，年級、模式、語音設定、
   另一半正在做到一半的小考都留著。舊的兩個網址還在，會轉進來。

   設計上的取捨：

   - **配色跟著半邊換。** 單字是青、文法是紫，掛在 body 的 data-section 上。
     兩頁時代這是為了「同一台筆電上開著的頁不該只能靠標題分辨」；合成一頁之後
     理由變了，但結論一樣：換色是最快讓人知道自己在哪一半的訊號，而且切換是
     使用者自己按的，不會突然變。兩個顏色都刻意離紅和綠夠遠，因為文法的常見
     錯誤要用紅表示錯、綠表示對。

   - **兩半共用外殼，不共用內容區塊。** 頂端列、年級頁籤、側欄、設定面板、
     列印都是同一份；單字的字表和文法的單元各有自己的區塊樣式。

   - **遮字用色塊不用 blur。** blur 還讀得出字長和形狀，而且一遮一露版面會抖；
     色塊把文字設成 transparent、背景鋪一條底色，寬度完全一樣。

   - **單字表是 grid 不是 table**，手機上要疊成卡片、列印時要像講義的表格。

   - 淺色單一主題，可列印。字級照國中生自己拿手機看的距離設。 */


:root {
  --paper: #f6f7f4;
  --card: #ffffff;
  --ink: #1b2530;
  --ink-soft: #58636f;
  --ink-faint: #8a939d;

  /* --brand is set per section, just below. Everything else is shared. */

  --gold: #8f6410;
  --gold-soft: #fcf3de;
  --gold-line: #edc86a;

  --good: #2c7a58;
  --good-soft: #e4f2ea;
  --good-line: #a8d6be;

  --bad: #a6402f;
  --bad-soft: #fbeae6;

  --line: #e2e2da;
  --rule: #cbcbc1;
  --mask: #dfe4e2;

  --font-en: "Iowan Old Style", "Palatino Linotype", Palatino, Charter, Georgia, "Times New Roman", serif;
  --font-zh: "PingFang TC", "Heiti TC", "Noto Sans TC", "Microsoft JhengHei", "Hiragino Sans CNS", sans-serif;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-kk: "Lucida Sans Unicode", "Segoe UI", "Doulos SIL", "Charis SIL", sans-serif;

  --bar-h: 54px;
  --nav-w: 250px;
}


/* The two halves' skins. Set on <body> so every chip, tab and rule that reads
   var(--brand) follows the switch without a single extra selector. */
body[data-section="words"] {
  --brand: #14655c;
  --brand-soft: #e4f0ed;
  --brand-line: #a8ccc5;
  --paper: #f6f7f4;
  --line: #e2e2da;
  --rule: #cbcbc1;
  --mask: #dfe4e2;
}
body[data-section="grammar"] {
  --brand: #4b3a99;
  --brand-soft: #ece9f8;
  --brand-line: #b9b0e0;
  --paper: #f7f6fb;
  --line: #e3e1ec;
  --rule: #c9c6d6;
  --mask: #dedbea;
}


* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: calc(var(--bar-h) + 62px); }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-zh);
  font-size: 17px;
  line-height: 1.65;
  -webkit-text-size-adjust: 100%;
}

.skip {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 60;
  padding: 10px 16px;
  background: var(--brand);
  color: #fff;
  font-family: var(--font-ui);
  border-radius: 0 0 8px 0;
}
.skip:focus { left: 0; }

:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ---------------- top bar ---------------- */

.bar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--bar-h);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  background: rgba(246, 247, 244, .93);
  backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--line);
}

.bar-title {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: .01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bar-title span {
  margin-left: 8px;
  font-family: var(--font-ui);
  font-size: .74rem;
  font-weight: 600;
  color: var(--ink-faint);
}

.bar-btn {
  flex: none;
  padding: 7px 11px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font-family: var(--font-zh);
  font-size: .82rem;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
}
.bar-btn:hover { border-color: var(--brand-line); }
.bar-btn-quiet { padding: 7px 9px; font-size: 1rem; }
.bar-btn[aria-expanded="true"] { background: var(--brand-soft); border-color: var(--brand-line); }

/* The mode switch: one control, two halves, so it reads as a position rather
   than as two independent buttons. */
.mode {
  flex: none;
  display: flex;
  padding: 2px;
  background: #eceee9;
  border: 1px solid var(--line);
  border-radius: 9px;
}
.mode-btn {
  padding: 5px 10px;
  background: none;
  border: 0;
  border-radius: 7px;
  color: var(--ink-soft);
  font-family: var(--font-zh);
  font-size: .8rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.mode-btn.is-on {
  background: var(--card);
  color: var(--brand);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .08);
}

/* ---------------- grade tabs ---------------- */

.grades {
  position: sticky;
  top: var(--bar-h);
  z-index: 35;
  display: flex;
  gap: 6px;
  padding: 8px 14px;
  overflow-x: auto;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

.grade-tab {
  flex: none;
  padding: 7px 15px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink-soft);
  font-family: var(--font-zh);
  font-size: .86rem;
  font-weight: 600;
  cursor: pointer;
}
.grade-tab b { font-weight: 700; }
.grade-tab i {
  margin-left: 6px;
  font-family: var(--font-ui);
  font-style: normal;
  font-size: .74rem;
  font-weight: 600;
  color: var(--ink-faint);
}
.grade-tab.is-on {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.grade-tab.is-on i { color: rgba(255, 255, 255, .72); }
.grade-tab.is-soon { border-style: dashed; color: var(--ink-faint); }

/* ---------------- search ---------------- */

.search {
  position: sticky;
  top: calc(var(--bar-h) + 46px);
  z-index: 34;
  padding: 12px 14px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

#searchInput {
  width: 100%;
  max-width: 34rem;
  padding: 9px 13px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 9px;
  color: var(--ink);
  font-family: var(--font-zh);
  font-size: 1rem;
}

.search-count {
  margin: 8px 0 0;
  font-family: var(--font-ui);
  font-size: .76rem;
  color: var(--ink-faint);
}

.search-hits {
  max-height: 46vh;
  margin-top: 6px;
  overflow-y: auto;
}

.hit {
  display: block;
  width: 100%;
  padding: 8px 10px;
  background: none;
  border: 0;
  border-top: 1px solid var(--line);
  color: inherit;
  font-family: var(--font-zh);
  font-size: .9rem;
  text-align: left;
  cursor: pointer;
}
.hit:hover { background: var(--brand-soft); }
.hit b { font-family: var(--font-en); font-size: 1.05rem; }
.hit span { margin-left: 8px; color: var(--ink-soft); }
.hit i {
  float: right;
  font-family: var(--font-ui);
  font-style: normal;
  font-size: .72rem;
  color: var(--ink-faint);
}

/* ---------------- shell and side nav ---------------- */

.shell {
  display: flex;
  align-items: flex-start;
  gap: 26px;
  max-width: 68rem;
  margin: 0 auto;
  padding: 0 18px;
}

#nav {
  position: sticky;
  top: calc(var(--bar-h) + 58px);
  flex: none;
  width: var(--nav-w);
  max-height: calc(100vh - var(--bar-h) - 76px);
  padding: 18px 0 30px;
  overflow-y: auto;
}

.nav-book {
  margin: 16px 0 6px;
  font-family: var(--font-ui);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.nav-book:first-child { margin-top: 0; }

.nav-link {
  display: flex;
  align-items: baseline;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  background: none;
  border: 0;
  border-radius: 8px;
  color: var(--ink-soft);
  font-family: var(--font-zh);
  font-size: .86rem;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.nav-link:hover { background: var(--brand-soft); color: var(--ink); }
.nav-link.is-here { background: var(--brand-soft); color: var(--brand); font-weight: 700; }
.nav-link em {
  flex: none;
  width: 3.1em;
  font-family: var(--font-ui);
  font-style: normal;
  font-size: .72rem;
  font-weight: 700;
  color: var(--brand);
}
.nav-link span { flex: 1; min-width: 0; }
.nav-link i {
  flex: none;
  font-family: var(--font-ui);
  font-style: normal;
  font-size: .7rem;
  color: var(--ink-faint);
}

.nav-scrim { display: none; }

#doc {
  flex: 1;
  min-width: 0;
  padding: 20px 0 40px;
}

/* ---------------- grade intro ---------------- */

.intro {
  margin: 0 0 26px;
  padding: 18px 20px;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--brand);
  border-radius: 4px 10px 10px 4px;
}
.intro h1 {
  margin: 0 0 4px;
  font-size: 1.35rem;
  letter-spacing: .01em;
}
.intro h1 span {
  margin-left: 9px;
  font-family: var(--font-ui);
  font-size: .8rem;
  font-weight: 600;
  color: var(--ink-faint);
}
.intro p { margin: 0; font-size: .88rem; color: var(--ink-soft); }
.intro .how {
  margin-top: 12px;
  padding-top: 11px;
  border-top: 1px dashed var(--line);
  font-size: .84rem;
}
.intro .how b { color: var(--brand); }

/* A grade whose PDF has not arrived yet. */
.soon {
  margin: 40px 0;
  padding: 34px 24px;
  background: var(--card);
  border: 1px dashed var(--rule);
  border-radius: 12px;
  text-align: center;
}
.soon h1 { margin: 0 0 8px; font-size: 1.2rem; }
.soon p { margin: 0 auto; max-width: 26rem; font-size: .9rem; color: var(--ink-soft); }



/* The section switch — the same control shape as the mode switch beside it, so
   the bar reads as two settings rather than as buttons that do something. */
.section-switch {
  flex: none;
  display: flex;
  padding: 2px;
  background: #eceee9;
  border: 1px solid var(--line);
  border-radius: 9px;
}
body[data-section="grammar"] .section-switch { background: #eae8f1; }
.section-btn {
  padding: 5px 11px;
  background: none;
  border: 0;
  border-radius: 7px;
  color: var(--ink-soft);
  font-family: var(--font-zh);
  font-size: .82rem;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}
.section-btn.is-on {
  background: var(--card);
  color: var(--brand);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .08);
}

/* Only the half you are looking at is in the document flow. */
body[data-section="words"] #doc > .sec-grammar,
body[data-section="grammar"] #doc > .sec-words,
body[data-section="words"] #nav > .sec-grammar,
body[data-section="grammar"] #nav > .sec-words { display: none; }


/* ---------------- a lesson ---------------- */

.lesson { margin: 0 0 34px; scroll-margin-top: calc(var(--bar-h) + 64px); }

.lesson-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px 12px;
  padding: 0 2px 9px;
  border-bottom: 2px solid var(--brand);
}

.lesson-head h2 { margin: 0; font-size: 1.12rem; letter-spacing: .01em; }

.lesson-code {
  flex: none;
  padding: 3px 9px;
  background: var(--brand);
  border-radius: 6px;
  color: #fff;
  font-family: var(--font-ui);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .06em;
}

.lesson-count {
  margin-left: auto;
  margin-right: 2px;
  font-family: var(--font-ui);
  font-size: .74rem;
  color: var(--ink-faint);
}

/* The link across to the same 課 on the grammar half, and the 📚 課次 chips
   going the other way. Same shape, so the join reads the same in both
   directions. */
.gram-link {
  flex: none;
  padding: 3px 9px;
  background: var(--card);
  border: 1px solid var(--brand-line);
  border-radius: 6px;
  color: var(--brand);
  font-family: var(--font-zh);
  font-size: .72rem;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}
.gram-link:hover { background: var(--brand-soft); }

.lesson-gram {
  margin: 10px 0 14px;
  padding: 8px 13px;
  background: var(--gold-soft);
  border-left: 3px solid var(--gold-line);
  border-radius: 3px 8px 8px 3px;
  font-size: .85rem;
  color: var(--ink-soft);
}

.lesson-gram b {
  margin-right: 8px;
  color: var(--gold);
  font-size: .78rem;
  letter-spacing: .04em;
}

/* ---------------- the word rows ----------------

   One grid per word. Wide: number / word block / meaning / example. Narrow:
   everything stacks under the word. The mark button is absolutely placed so
   neither layout has to reserve a column for it. */

.words {
  margin: 0;
  padding: 0;
  list-style: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: var(--card);
}

.word {
  position: relative;
  display: grid;
  grid-template-columns: 2.3rem minmax(9.5rem, 15rem) minmax(7rem, 12rem) 1fr;
  gap: 2px 14px;
  /* The right padding is the clearance for the ✓ mark / 中 chip, which are
     absolutely placed there — without it a long example runs under them. */
  padding: 11px 44px 11px 12px;
  border-top: 1px solid var(--line);
}

.word:first-child { border-top: 0; }

.word:nth-child(even) { background: #fbfbf9; }

.word.is-known { background: var(--good-soft); }

.word.is-hidden { display: none; }

.w-n {
  grid-column: 1;
  padding-top: .18em;
  font-family: var(--font-ui);
  font-size: .74rem;
  color: var(--ink-faint);
  text-align: right;
}

.w-main { grid-column: 2; }

.w-word {
  font-family: var(--font-en);
  font-size: 1.24rem;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: .005em;
}

.w-kk {
  font-family: var(--font-kk);
  font-size: .78rem;
  color: var(--ink-faint);
  letter-spacing: .01em;
}

.w-pos {
  display: inline-block;
  margin-left: 7px;
  padding: 1px 6px;
  background: var(--brand-soft);
  border-radius: 4px;
  font-family: var(--font-ui);
  font-size: .68rem;
  font-weight: 700;
  color: var(--brand);
  vertical-align: 2px;
  white-space: nowrap;
}

.w-zh {
  grid-column: 3;
  padding-top: .12em;
  font-size: .95rem;
  color: var(--ink);
}

.w-ex { grid-column: 4; padding-top: .1em; }

.w-en {
  font-family: var(--font-en);
  font-size: .98rem;
  line-height: 1.45;
  color: var(--ink-soft);
}

.w-zhex {
  font-size: .82rem;
  line-height: 1.6;
  color: var(--ink-faint);
}

/* 🔊 — small, quiet, and never in the way of the word itself. */

.say {
  margin-left: 6px;
  padding: 1px 4px;
  background: none;
  border: 0;
  border-radius: 5px;
  font-size: .82em;
  line-height: 1;
  opacity: .42;
  cursor: pointer;
  vertical-align: 1px;
}

.say:hover { opacity: 1; background: var(--brand-soft); }

.say.is-on { opacity: 1; }

/* The 會了 mark. Study mode only. */

.mark {
  position: absolute;
  top: 9px;
  right: 9px;
  width: 26px;
  height: 26px;
  padding: 0;
  background: none;
  border: 1.5px solid var(--line);
  border-radius: 50%;
  color: transparent;
  font-size: .8rem;
  line-height: 1;
  cursor: pointer;
}

.mark:hover { border-color: var(--good-line); color: var(--good-line); }

.mark[aria-pressed="true"] {
  background: var(--good);
  border-color: var(--good);
  color: #fff;
}

body.mode-class .mark { display: none; }

/* ---------------- the Chinese layer, and the masks ----------------

   Two different mechanisms that must not fight each other:

   - 教學模式 hides every .zh behind a 中 chip, the same way the adult pages do.
   - 自學模式 shows them, but 遮字 can blank either side for self-testing.

   Both end up hiding the same elements, so the reveal is one shared class
   (.shown) set on the word row. */

/* The chip is taken out of flow for the same reason the ✓ mark is: .word is a
   grid, so an in-flow child would claim a whole new grid row of its own rather
   than sitting beside anything. The two share the top-right slot and are never
   visible at the same time — the mark is study-only, the chip is class-only. */

.zh-chip {
  display: none;
  position: absolute;
  top: 9px;
  right: 9px;
  padding: 2px 7px;
  background: var(--card);
  border: 1px solid var(--brand-line);
  border-radius: 6px;
  color: var(--brand);
  font-family: var(--font-zh);
  font-size: .72rem;
  font-weight: 700;
  line-height: 1.5;
  cursor: pointer;
}

.zh-chip:hover { background: var(--brand-soft); }

body.mode-class .word .w-zh,
body.mode-class .word .w-zhex { display: none; }

body.mode-class .zh-chip { display: inline-block; }

body.mode-class .word.shown .w-zh,
body.mode-class .word.shown .w-zhex { display: block; }

body.mode-class .word.shown .zh-chip { display: none; }

body.zh-all .word .w-zh,
body.zh-all .word .w-zhex { display: block !important; }

body.zh-all .zh-chip { display: none !important; }

/* The mask: same width, no text. Clicking the row reveals it. */

.masked {
  background: var(--mask);
  border-radius: 4px;
  color: transparent !important;
  cursor: pointer;
  user-select: none;
}

.masked * { color: transparent !important; }

.masked .say, .masked .w-pos { visibility: hidden; }

/* ---------------- the quiz ---------------- */

/* A wrong answer wobbles and invites another go — it never ends the question. */

@keyframes wobble {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  45% { transform: translateX(5px); }
  70% { transform: translateX(-3px); }
}

/* ---------------- one unit ---------------- */

.unit { margin: 0 0 40px; scroll-margin-top: calc(var(--bar-h) + 64px); }

.unit.is-hidden { display: none; }

.unit-head {
  position: relative;
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px 12px;
  padding: 0 44px 9px 2px;
  border-bottom: 2px solid var(--brand);
}

.unit-head h2 { margin: 0; font-size: 1.2rem; letter-spacing: .01em; }

.unit-code {
  flex: none;
  padding: 3px 9px;
  background: var(--brand);
  border-radius: 6px;
  color: #fff;
  font-family: var(--font-ui);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .06em;
}

/* 對應課次 — the link to the same 課 on the word list. */

.unit-refs { display: flex; gap: 6px; margin-left: auto; }

.ref {
  padding: 3px 9px;
  background: var(--card);
  border: 1px solid var(--brand-line);
  border-radius: 6px;
  color: var(--brand);
  font-family: var(--font-ui);
  font-size: .7rem;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.ref:hover { background: var(--brand-soft); }

.ref::before { content: '📖 '; }

/* 一句話重點 — the line the whole unit is trying to leave behind, so it sits
   at the top under the heading rather than buried at the foot as in the PDF. */

.unit-key {
  margin: 12px 0 20px;
  padding: 12px 16px;
  background: var(--gold-soft);
  border-left: 4px solid var(--gold-line);
  border-radius: 3px 9px 9px 3px;
  font-size: .96rem;
  font-weight: 600;
  line-height: 1.7;
}

.unit-key b {
  margin-right: 9px;
  color: var(--gold);
  font-size: .74rem;
  font-weight: 700;
  letter-spacing: .06em;
  vertical-align: 1px;
}

.sec-head {
  margin: 22px 0 10px;
  font-family: var(--font-ui);
  font-size: .76rem;
  font-weight: 700;
  letter-spacing: .12em;
  color: var(--ink-faint);
  text-transform: none;
}

.sec-head span {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--brand-line);
  vertical-align: 2px;
}

/* 核心規則 */

.rules { margin: 0; padding: 0; list-style: none; }

.rules li {
  position: relative;
  padding: 7px 0 7px 20px;
  font-size: .95rem;
  line-height: 1.8;
}

.rules li::before {
  content: '';
  position: absolute;
  top: 1.05em;
  left: 3px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--brand);
}

/* An English fragment inside a Chinese rule — dog → dogs, I → am. */

.rules code, .pat-en code {
  font-family: var(--font-en);
  font-size: 1.02em;
  font-weight: 600;
  color: var(--brand);
  background: none;
}

/* 句型對照 */

.pats {
  margin: 0;
  padding: 0;
  list-style: none;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.pat {
  position: relative;
  display: grid;
  grid-template-columns: 6.5rem 1fr 13rem;
  gap: 2px 14px;
  padding: 11px 14px;
  border-top: 1px solid var(--line);
}

.pat:first-child { border-top: 0; }

.pat:nth-child(even) { background: #fbfbfd; }

.pat-label {
  font-family: var(--font-ui);
  font-size: .76rem;
  font-weight: 700;
  color: var(--brand);
  padding-top: .22em;
}

.pat-en { font-family: var(--font-en); font-size: 1.06rem; line-height: 1.45; }

.pat-zh { font-size: .88rem; color: var(--ink-soft); padding-top: .12em; }

/* 常見錯誤 — the block this page exists for. */

.mistakes { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }

.mis {
  padding: 12px 15px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.mis-line { display: flex; align-items: baseline; gap: 9px; padding: 2px 0; }

.mis-mark {
  flex: none;
  width: 1.2em;
  font-family: var(--font-ui);
  font-size: .95rem;
  font-weight: 700;
  text-align: center;
}

.mis-bad .mis-mark { color: var(--bad); }

.mis-good .mis-mark { color: var(--good); }

.mis-text { font-family: var(--font-en); font-size: 1.06rem; line-height: 1.5; }

/* Struck through rather than red: the strike survives a black-and-white
   printout, where red is just dark grey. */

.mis-bad .mis-text { color: var(--ink-faint); text-decoration: line-through; }

.mis-good .mis-text { color: var(--good); font-weight: 600; }

.mis-why {
  margin: 7px 0 0;
  padding: 7px 0 0 calc(1.2em + 9px);
  border-top: 1px dashed var(--line);
  font-size: .85rem;
  line-height: 1.7;
  color: var(--ink-soft);
}

/* ---------------- what gets hidden, and how ----------------

   Two mechanisms over the same elements, exactly as on the word list:
   教學 hides the answers behind a chip, 自學 can blank them for self-testing.
   Chinese *explanation* — 核心規則, 為什麼 — is never hidden by either: it is
   the textbook's own voice, not something the student is meant to produce. */

.reveal {
  display: none;
  margin-left: 8px;
  padding: 2px 8px;
  background: var(--card);
  border: 1px solid var(--brand-line);
  border-radius: 6px;
  color: var(--brand);
  font-family: var(--font-zh);
  font-size: .7rem;
  font-weight: 700;
  line-height: 1.5;
  cursor: pointer;
  vertical-align: 1px;
}

.reveal:hover { background: var(--brand-soft); }

body.mode-class .pat .pat-zh,
body.mode-class .mis .mis-good,
body.mode-class .mis .mis-why { display: none; }

body.mode-class .reveal { display: inline-block; }

body.mode-class .shown .pat-zh,
body.mode-class .shown .mis-why { display: block; }

/* flex, not block — the ✓ and the sentence sit on one line. */
body.mode-class .shown .mis-good { display: flex; }

body.mode-class .shown .reveal { display: none; }

body.reveal-all .pat .pat-zh,
body.reveal-all .mis .mis-why { display: block !important; }

body.reveal-all .mis .mis-good { display: flex !important; }

body.reveal-all .reveal { display: none !important; }

/* ---------------- the drill ---------------- */

.drill-open {
  display: block;
  width: 100%;
  margin-top: 18px;
  padding: 11px;
  background: var(--gold-soft);
  border: 1px solid var(--gold-line);
  border-radius: 10px;
  color: var(--gold);
  font-family: var(--font-zh);
  font-size: .9rem;
  font-weight: 700;
  cursor: pointer;
}

.drill-open:hover { background: #fbedcf; }

.drill {
  margin-top: 12px;
  padding: 18px;
  background: var(--card);
  border: 1px solid var(--gold-line);
  border-radius: 10px;
}

.drill-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  font-family: var(--font-ui);
  font-size: .76rem;
  color: var(--ink-faint);
}

.drill-bar .track { flex: 1; height: 5px; background: var(--line); border-radius: 3px; overflow: hidden; }

.drill-bar .fill { height: 100%; background: var(--gold-line); transition: width .25s; }

.drill-x {
  padding: 3px 8px;
  background: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink-faint);
  font-family: var(--font-zh);
  font-size: .74rem;
  cursor: pointer;
}

.q-ask {
  margin: 0 0 6px;
  font-family: var(--font-ui);
  font-size: .76rem;
  font-weight: 700;
  letter-spacing: .05em;
  color: var(--gold);
}

.q-prompt { margin: 0 0 15px; font-size: 1.22rem; font-weight: 600; line-height: 1.5; }

/* No default face on a prompt or an option: one half asks in English and the
   other in Chinese, so every one of them says which it is. */
.q-prompt.en { font-family: var(--font-en); }
.q-prompt.zh { font-family: var(--font-zh); }

.q-prompt.bad {
  color: var(--ink-faint);
  text-decoration: line-through;
  text-decoration-color: var(--bad);
}

.q-opts { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }

.opt {
  display: block;
  width: 100%;
  padding: 11px 14px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 9px;
  color: var(--ink);
  font-size: 1.02rem;
  text-align: left;
  cursor: pointer;
}

.opt.en { font-family: var(--font-en); }
.opt.zh { font-family: var(--font-zh); }

.opt:hover { border-color: var(--brand); background: var(--brand-soft); }

.opt.is-right { background: var(--good-soft); border-color: var(--good); color: var(--good); font-weight: 700; }

.opt.is-wrong { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); animation: wobble .38s; }

.opt:disabled { cursor: default; }

/* A wrong answer wobbles and invites another go — it never ends the question. */

.q-after {
  margin: 14px 0 0;
  padding: 11px 14px;
  background: var(--good-soft);
  border-left: 3px solid var(--good-line);
  border-radius: 3px 8px 8px 3px;
  font-size: .88rem;
  line-height: 1.7;
  color: var(--ink-soft);
}

.q-after b { font-family: var(--font-en); color: var(--good); }

.q-done { text-align: center; }

.q-done h3 { margin: 0 0 6px; font-size: 1.1rem; }

.q-done > p { margin: 0 0 16px; font-size: .88rem; color: var(--ink-soft); }

.q-again {
  padding: 10px 20px;
  background: var(--brand);
  border: 0;
  border-radius: 9px;
  color: #fff;
  font-family: var(--font-zh);
  font-size: .92rem;
  font-weight: 700;
  cursor: pointer;
}

.q-review { margin: 0 0 16px; padding: 13px 16px; background: var(--gold-soft); border-radius: 9px; text-align: left; }

.q-review p {
  margin: 0 0 7px;
  font-family: var(--font-ui);
  font-size: .76rem;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--gold);
}

.q-review ul { margin: 0; padding: 0; list-style: none; }

.q-review li { font-size: .9rem; line-height: 1.8; }

.q-review b { margin-right: 8px; font-family: var(--font-en); color: var(--good); }

.q-review s { color: var(--ink-faint); }

/* 🔊 — small, quiet, and never in the way of the sentence itself. */

/* The 會了 mark, one per unit. Study mode only. */

/* ---------------- settings panel ---------------- */

.panel {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 60;
  width: min(23rem, 92vw);
  height: 100%;
  padding: 20px 22px 40px;
  overflow-y: auto;
  background: var(--card);
  border-left: 1px solid var(--line);
  box-shadow: -14px 0 40px rgba(20, 30, 40, .1);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.panel-head h2 { margin: 0; font-size: 1.05rem; }
.panel-head span {
  margin-left: 7px;
  font-family: var(--font-ui);
  font-size: .74rem;
  font-weight: 600;
  color: var(--ink-faint);
}
.panel-x {
  padding: 5px 9px;
  background: none;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink-soft);
  font-size: .9rem;
  cursor: pointer;
}

.panel .row {
  padding: 14px 0;
  border-top: 1px solid var(--line);
}
.panel .row > label {
  display: block;
  margin-bottom: 6px;
  font-size: .86rem;
  font-weight: 700;
}
.row-check { display: flex; align-items: center; gap: 9px; cursor: pointer; font-size: .88rem; }
.row-check input { width: 17px; height: 17px; accent-color: var(--brand); }
.row-check em {
  display: block;
  font-family: var(--font-ui);
  font-style: normal;
  font-size: .72rem;
  color: var(--ink-faint);
}
.panel select {
  width: 100%;
  padding: 8px 10px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 8px;
  font-family: var(--font-zh);
  font-size: .88rem;
}
.panel-btn {
  width: 100%;
  padding: 9px;
  background: var(--brand);
  border: 0;
  border-radius: 8px;
  color: #fff;
  font-family: var(--font-zh);
  font-size: .88rem;
  font-weight: 700;
  cursor: pointer;
}
.panel-btn-quiet {
  background: var(--card);
  border: 1px solid var(--rule);
  color: var(--ink-soft);
}
.row-note {
  margin: 7px 0 0;
  font-size: .76rem;
  line-height: 1.65;
  color: var(--ink-faint);
}

body.mode-study .panel .row[data-mode="class"],
body.mode-class .panel .row[data-mode="study"] { display: none; }


/* ---------------- narrow screens ---------------- */

@media (max-width: 900px) {
  .word { grid-template-columns: 2.1rem 1fr; gap: 3px 10px; }
  .w-main, .w-zh, .w-ex { grid-column: 2; }
  .w-zh { padding-top: 2px; }
  .w-ex { padding-top: 5px; }

  .pat { grid-template-columns: 5.5rem 1fr; }
  .pat-zh { grid-column: 2; padding-top: 3px; }
}

@media (max-width: 780px) {
  body { font-size: 16px; }

  .bar { gap: 5px; padding: 0 8px; }
  .bar-title { display: none; }        /* the section switch says where you are */
  .mode-btn, .section-btn { padding: 5px 9px; font-size: .82rem; }

  /* Five controls do not fit a phone bar with their words on. The emoji stay
     and the words go — each button keeps its aria-label, so nothing is lost to
     a screen reader. Measured: with the words on, ⚙ sat 25px off a 375px
     screen. */
  .bar .lbl { display: none; }
  .bar-btn { padding: 7px 9px; }

  /* The side nav becomes a drawer. */
  #nav {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 55;
    width: min(17rem, 82vw);
    height: 100%;
    max-height: none;
    padding: 18px 14px 40px;
    background: var(--card);
    border-right: 1px solid var(--line);
    box-shadow: 14px 0 40px rgba(20, 30, 40, .1);
    transform: translateX(-102%);
    transition: transform .2s;
  }
  body.nav-open #nav { transform: none; }
  body.nav-open .nav-scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(20, 25, 40, .3);
  }

  .shell { gap: 0; padding: 0 13px; }
  .search { top: calc(var(--bar-h) + 45px); }

  .unit-head { padding-right: 38px; }
  .unit-refs { margin-left: 0; width: 100%; flex-wrap: wrap; }
}

/* ---------------- print ----------------

   A handout of whichever half is on screen: everything open, nothing
   interactive. The masks and the practice blocks go away entirely rather than
   printing blank — a printed sheet with grey bars on it is not a study sheet. */

@media print {
  body { font-size: 10.5pt; background: #fff; }

  .bar, .grades, .search, #nav, .nav-scrim, .panel, .say, .mark,
  .zh-chip, .reveal, .drill, .drill-open, .intro .how { display: none !important; }

  .shell { display: block; max-width: none; padding: 0; }
  #doc { padding: 0; }

  .masked { background: none !important; color: inherit !important; }
  .masked * { color: inherit !important; }

  /* Everything the two modes hide is opened for the page. */
  .word .w-zh, .word .w-zhex, .pat .pat-zh, .mis .mis-why { display: block !important; }
  .mis .mis-good { display: flex !important; }

  /* 只看還沒打勾的 is ignored on paper: a handout prints whole. */
  .word.is-hidden { display: grid; }
  .unit.is-hidden { display: block; }

  .lesson, .unit { break-inside: auto; margin-bottom: 20pt; }
  .lesson-head, .unit-head, .sec-head { break-after: avoid; }
  .word, .pat, .mis, .rules li { break-inside: avoid; }
  .word { padding: 5pt 0; }
  .words, .pats { border-radius: 0; border-left: 0; border-right: 0; }
  .word:nth-child(even), .word.is-known, .pat:nth-child(even) { background: none; }
  .intro { border-radius: 0; }
}


/* ---------------- shared site footer ----------------

   Copied verbatim onto every page in the repo, palette tokens and all, so a
   page missing a token still shows a readable link. */

.site-foot {
  max-width: 46rem;
  margin: 0 auto;
  padding: 26px 20px 40px;
  border-top: 1px solid var(--line, #e3e0d8);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px 14px;
  text-align: center;
  font-family: var(--font-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif);
  font-size: .8rem;
  line-height: 1.7;
  color: var(--ink-faint, var(--ink-soft, #7a8290));
}
.site-foot p { margin: 0; }

.site-foot .site-mark {
  flex: none;
  margin: 0;
  padding: 0;
  border: 0;
  line-height: 0;
  border-radius: 50%;
  transition: opacity .12s;
}
.site-foot .site-mark img { display: block; width: 34px; height: 34px; }
.site-foot .site-mark:hover { opacity: .78; }

.site-foot p a {
  margin-left: 7px;
  padding-bottom: 1px;
  color: var(--brand, var(--navy, #1d3f6e));
  font-weight: 600;
  text-decoration: none;
  border-bottom: 1px solid currentColor;
}
.site-foot p a:hover { opacity: .7; }

@media print { .site-foot { display: none; } }


/* ---------------- touch targets ----------------

   🔊 and 中 are the most-tapped controls on the page, but inline in running
   text they render at about 23×19px — under the 24×24 CSS px floor of WCAG 2.2
   AA (2.5.8 Target Size (Minimum)).

   They cannot simply be drawn bigger. Measured on a 375px screen, the gap to
   the next control is 7–10px and the line box is only 24px tall, so a larger
   chip would collide with its neighbours — and two overlapping hit areas are
   worse than one small one, because the loser becomes untappable.

   So the visible chip is left exactly as it was and an invisible hit area is
   centred on it: at least 24×24, never smaller than the chip itself. Nothing
   on the page moves; the finger just gets something bigger to aim at. */

.say, .zh-chip { position: relative; }

.say::after,
.zh-chip::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: max(100%, 24px);
  height: max(100%, 24px);
  transform: translate(-50%, -50%);
}
