:root {
  /* S-29 版面第 1 批（2026-10-20）：Owner 定案不自帶字型，用各平台內建繁中字；數學式維持 KaTeX 字型。 */
  --font-sans: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Heiti TC", system-ui, sans-serif;
  /* 五級字級：畫面標題／區塊小標／學習內文／註記／題目框。一般頁面內文 16px，Owner／Staff 區 15px。 */
  --fs-title: 24px;
  --fs-section: 18px;
  --fs-body: 17px;
  --fs-note: 14px;
  --fs-question: 20px;
  /* 顏色（2-1）：一個底色、一個主要深色、一個主色；狀態色只用在通過／要改／系統問題／提示。 */
  --ground: #f3f6fb;      /* 頁面底色 */
  --surface: #ffffff;     /* 面板 */
  --raised: #f8fafd;      /* 面板裡的淺底區塊 */
  --line: #e3e8ef;        /* 面板、分隔線（白底約 1.2:1） */
  --control-line: #acb9cd;/* 輸入框外框 */
  --ink: #172033;         /* 主要文字 */
  --muted: #556179;       /* 次要說明：白底 6.2:1、提示底 5.7:1（原 #66738a 在 #f4f7fc 只有 4.46:1） */
  --primary: #2458b8;     /* 主色：主要按鈕、進行中、連結 */
  --primary-strong: #1d4a9e;
  --primary-tint: #e8eef8;
  --primary-tint-ink: #24406e;
  --info-bg: #f1f5fb;     /* 一般提示 */
  --ok-bg: #dcfae5;   --ok-ink: #04250e;   --ok-line: #9fdcb4;   /* 通過 */
  --bad-bg: #ffedea;  --bad-ink: #831c1e;  --bad-line: #f1b5ae;  /* 要改／錯誤 */
  --sys-bg: #fffbeb;  --sys-ink: #92400e;  --sys-line: #fde68a;  /* 系統問題、不是你的錯 */
  color: var(--ink);
  background: var(--ground);
  font-family: var(--font-sans);
  font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; font-size: 16px; line-height: 1.6; }
button, input, textarea, select { font: inherit; }
h1, h2, h3, h4, h5, h6 { line-height: 1.35; }
h2 { font-size: 20px; font-weight: 700; }
h3 { font-size: var(--fs-section); font-weight: 650; }
h4, h5, h6 { font-size: 16px; font-weight: 650; }
/* 畫面標題：學習畫面目前這一步、Owner／Staff 控制區 */
#learning-title, #owner-home > h3, #staff-home > h3 { font-size: var(--fs-title); font-weight: 700; }
.learning-content h4, #owner-home .question-panel > h4 { font-size: var(--fs-section); }
#owner-home, #staff-home { font-size: 15px; }

.shell {
  width: min(960px, calc(100% - 32px));
  margin: 0 auto;
  padding: 56px 0 80px;
}

.hero { max-width: 720px; margin-bottom: 28px; }
/* h1 是站名（app 畫面要有名字）；登入頁的大字句改成 .hero-lead，從 58px 降到 28～34px。 */
.hero .site-name { margin: 0; font-size: 20px; font-weight: 700; color: var(--primary); }
.hero .hero-lead { margin: 8px 0 12px; font-size: clamp(1.75rem, 4vw, 2.125rem); font-weight: 700; line-height: 1.25; }
.hero p:last-child { color: var(--muted); font-size: 1.08rem; line-height: 1.7; }
/* 登入後收起登入頁大字句與說明，只留站名和講義連結（:has 不支援的舊瀏覽器維持原樣，不會壞）。 */
body:has(#signed-in:not([hidden])) .hero .hero-lead,
body:has(#signed-in:not([hidden])) .hero .hero-intro { display: none; }
body:has(#signed-in:not([hidden])) .hero { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 16px; max-width: none; margin-bottom: 16px; }
body:has(#signed-in:not([hidden])) .hero p:last-child { margin: 0; font-size: 1rem; }
.account-state { margin: 4px 0 0; color: var(--muted); font-size: var(--fs-note); }
.learning-stage { margin: 0 0 4px; color: var(--muted); font-size: var(--fs-note); font-weight: 650; overflow-wrap: anywhere; }

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 24px;
}
.card h2 { margin-top: 0; }
label { display: block; font-weight: 650; margin: 18px 0 7px; }
input, select {
  width: 100%;
  border: 1px solid var(--control-line);
  border-radius: 8px;
  padding: 12px 13px;
  background: #fff;
}
textarea {
  width: 100%; min-height: 116px; resize: vertical; border: 1px solid var(--control-line);
  border-radius: 8px; padding: 12px 13px; background: #fff; line-height: 1.55;
}
textarea:focus { outline: 3px solid rgb(45 102 200 / 22%); border-color: #2d66c8; }
input:focus { outline: 3px solid rgb(45 102 200 / 22%); border-color: #2d66c8; }
select:focus { outline: 3px solid rgb(45 102 200 / 22%); border-color: #2d66c8; }
.password-field { display: flex; align-items: stretch; gap: 8px; }
.password-field input { min-width: 0; }
.password-toggle { flex: 0 0 auto; margin: 0; white-space: nowrap; }
button {
  border: 0;
  border-radius: 8px;
  margin-top: 22px;
  padding: 12px 18px;
  background: var(--primary);
  color: #fff;
  font-weight: 650;
  cursor: pointer;
}
button:disabled { cursor: wait; opacity: .62; }
a { color: var(--primary); text-underline-offset: .2em; }
a:hover { color: var(--primary-strong); }
button.secondary { background: var(--primary-tint); color: var(--primary-tint-ink); margin: 0; }
/* 5-3：相鄰按鈕統一隔 8px（本身用 gap 排版的按鈕列不重複加）；危險動作用紅色外框的次要按鈕。 */
:is(button, a.button-link) + :is(button, a.button-link) { margin-left: 8px; }
:is(.learning-actions, .learning-heading-actions, .password-field, .chapter-history-toolbar, .learning-media-actions, .chapter-list, .owner-ai-grant-row) > :is(button, a.button-link) + :is(button, a.button-link) { margin-left: 0; }
button.danger { background: var(--surface); color: var(--bad-ink); border: 1px solid var(--bad-line); }
button.danger:hover { background: var(--bad-bg); }
.muted { color: var(--muted); line-height: 1.55; }
.notice {
  border-radius: 12px;
  margin: 0 0 20px;
  padding: 13px 16px;
  background: var(--sys-bg);
  border: 1px solid var(--sys-line);
  color: var(--sys-ink);
  overflow-wrap: anywhere;
}
.notice.error { background: var(--bad-bg); border-color: var(--bad-line); color: var(--bad-ink); }
.account-row { align-items: flex-start; display: flex; justify-content: space-between; gap: 24px; }
.status-box { background: var(--info-bg); border-radius: 8px; color: var(--ink); padding: 14px; overflow-wrap: anywhere; }
/* 4-2：四種狀態樣式（淡底深字）：通過、要改、系統問題（不是你的錯）；一般提示就是 .status-box 本身。 */
.status-box.is-ok { background: var(--ok-bg); border: 1px solid var(--ok-line); color: var(--ok-ink); }
.status-box.is-wrong, .status-box.error { background: var(--bad-bg); border: 1px solid var(--bad-line); color: var(--bad-ink); }
.status-box.is-system { background: var(--sys-bg); border: 1px solid var(--sys-line); color: var(--sys-ink); }
.reminder-list { padding-left: 1.25rem; }
.reminder-list li { margin: .65rem 0; line-height: 1.45; }
.learning-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.learning-heading h3 { margin-bottom: 4px; }
.learning-heading-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; align-items: center; }
a.button-link { display: inline-block; border-radius: 8px; padding: 12px 18px; background: var(--primary-tint); color: var(--primary-tint-ink); font-weight: 650; text-decoration: none; white-space: nowrap; }
a.button-link:hover, a.button-link:focus-visible { background: #d9e4f5; color: var(--primary-tint-ink); }
.tools-exam-note { flex-basis: 100%; text-align: right; font-size: var(--fs-note); color: var(--muted); }
/* 限時評量開始前的作答規則（S-12，Owner 2026-10-15 定稿文字） */
.timed-tool-rules { margin: 10px 0 4px; padding: 12px 14px; border: 1px solid #f0c36d; background: #fff8e6; border-radius: 8px; line-height: 1.65; }
.timed-tool-rules > strong { display: block; color: #8a4b00; margin-bottom: 4px; }
.timed-tool-rules p { margin: 6px 0; }
.timed-tool-ack { display: flex; gap: 8px; align-items: center; font-weight: 700; margin-top: 8px; cursor: pointer; }
.timed-tool-ack input { width: 18px; height: 18px; margin: 0; }
.chapter-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; margin-top: 18px; }
.chapter-button { text-align: left; margin: 0; min-height: 88px; background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.chapter-button:hover { border-color: var(--primary); }
#course-progress-list .chapter-button { border-left: 4px solid var(--primary); }
.chapter-button span { display: block; font-size: var(--fs-note); font-weight: 400; color: var(--muted); margin-top: 6px; }
.chapter-group-title { margin: 22px 0 0; }
.topic-chapter-panel { background: var(--raised); border: 1px solid var(--line); border-radius: 8px; margin-top: 18px; padding: 18px; }
.topic-chapter-panel > h4 { margin: 0 0 4px; }
.topic-chapter-panel .muted { margin: 0; }
.topic-chapter-fields { display: grid; grid-template-columns: minmax(0, 180px) minmax(0, 1fr); gap: 12px; }
.topic-chapter-fields label { margin-top: 14px; }
.topic-chapter-form button { margin-top: 14px; min-height: 48px; }
.topic-chapter-panel .status-box { margin-top: 14px; overflow-wrap: anywhere; }
.topic-chapter-panel .status-box button { margin: 10px 10px 0 0; }
.chapter-button.generated { border-left: 4px solid #1f6b5c; }
.chapter-button.fresh { outline: 3px solid #f0b43c; outline-offset: 2px; }
/* 2026-10-13 學習區：課程列表／自訂主題分頁、課程卡、等待提示 */
.learning-tabs { display: flex; gap: 8px; margin-top: 18px; border-bottom: 2px solid var(--line); flex-wrap: wrap; }
.learning-tab { background: transparent; color: var(--muted); border-radius: 8px 8px 0 0; margin: 0 0 -2px; border: 2px solid transparent; padding: 10px 16px; }
.learning-tab.active { background: var(--surface); color: var(--ink); border-color: var(--line) var(--line) #fff; font-weight: 700; }
.learning-tab:not(.active):hover { background: var(--info-bg); }
#learning-tab-topic { font-size: var(--fs-note); opacity: .85; }
.course-search { margin-top: 16px; display: grid; gap: 6px; max-width: 520px; }
.course-list { margin-top: 12px; display: grid; gap: 10px; }
.course-grade { border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 4px 14px; }
.course-grade > summary { cursor: pointer; font-weight: 700; padding: 10px 0; }
.course-unit h5 { margin: 14px 0 0; color: var(--muted); }
.course-unit .chapter-list { margin-top: 8px; }
.course-card { display: flex; flex-direction: column; gap: 4px; }
.course-card .chapter-button { width: 100%; }
.course-lesson { font-size: var(--fs-note); align-self: flex-start; }
.course-summary { font-size: var(--fs-note); color: var(--muted); margin: 0; line-height: 1.5; overflow-wrap: anywhere; }
.learning-content .course-lesson { display: inline-block; margin: 4px 0 10px; }
.learning-content .course-tool { display: block; margin-top: 0; }
.learning-content .qa-pair { border-left: 3px solid #9db4d6; padding: 2px 0 2px 10px; margin: 6px 0 10px; }
.learning-content .qa-pair p { margin: 4px 0; }
.learning-content .qa-question { font-weight: 600; }
.learning-error-inline { background: var(--bad-bg); color: var(--bad-ink); border: 1px solid var(--bad-line); margin: 10px 0; overflow-wrap: anywhere; }
/* 4-4：出題沒過品質檢查不是學生的錯，用系統問題的黃框，不用紅框。 */
.learning-error-inline.is-system { background: var(--sys-bg); color: var(--sys-ink); border-color: var(--sys-line); }
.learning-wait { background: #fff8e6; border: 1px solid #e0c36a; border-radius: 8px; color: #4d3b0b; padding: 14px; margin-top: 14px; overflow-wrap: anywhere; }
.learning-wait p { margin: 8px 0 0; }
.learning-wait a { display: inline-block; margin-top: 8px; }
.learning-wait-inline { width: 100%; min-width: 0; max-width: 100%; margin-bottom: 10px; }
.learning-wait-steps { display: grid; gap: 4px; min-width: 0; }
.learning-wait-current { font-weight: 700; }
.learning-session { border-top: 1px solid var(--line); margin-top: 24px; padding-top: 24px; font-size: var(--fs-body); }
/* 學習內文行高 1.8、一行約 40 個中文字（不再拉滿 912px）。 */
.learning-content { color: var(--ink); line-height: 1.8; max-width: 40em; }
.learning-content p, .question-result p, .records-detail p { white-space: pre-wrap; overflow-wrap: anywhere; }
.katex { white-space: normal; }
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; max-width: 100%; }
.records-detail pre { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 28rem; overflow-y: auto; }
.learning-content .question { background: var(--info-bg); border-left: 4px solid var(--primary); border-radius: 8px; font-size: var(--fs-question); padding: 16px; }
.learning-content ul, .learning-content ol { padding-left: 1.4rem; }
.learning-form { margin-top: 18px; max-width: 40em; }
/* 3-2：點章節卡後程式會把焦點移到學習畫面；滑鼠點選不畫焦點框，鍵盤操作才畫。 */
#learning-session:focus:not(:focus-visible), #learning-title:focus:not(:focus-visible) { outline: none; }
#learning-session:focus-visible { outline: 2px solid var(--primary); outline-offset: 4px; border-radius: 8px; }
.learning-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.learning-actions button { margin-top: 12px; }
.learning-actions .secondary { margin-top: 12px; }
.learning-meta { color: var(--muted); font-size: var(--fs-note); }
/* S-24：錯因、補教、訂正頁「你原本的答案／理由」醒目框（原本是灰色小字）。 */
.your-answer { background: #fff7e0; border-left: 4px solid #d99a00; border-radius: 8px; color: #3d3000; margin: 12px 0; padding: 10px 14px; overflow-wrap: anywhere; }
.your-answer p { margin: 4px 0; }
.choice-options { border: 1px solid var(--line); border-radius: 8px; margin: 18px 0 0; min-width: 0; padding: 8px 16px 14px; }
.choice-options legend { color: var(--muted); font-weight: 650; padding: 0 6px; }
.choice-option { align-items: baseline; cursor: pointer; display: flex; font-weight: 500; gap: 10px; margin: 10px 0 0; overflow-wrap: anywhere; }
.choice-option input { flex: 0 0 auto; margin: 0; width: auto; }
.choice-option b { flex: 0 0 auto; white-space: nowrap; }
.choice-option span { min-width: 0; }
.question-panel { border-top: 1px solid var(--line); margin-top: 30px; padding-top: 24px; }
.question-panel form { margin-top: 12px; }
.question-result { background: var(--info-bg); border-left: 4px solid var(--primary); border-radius: 8px; margin-top: 20px; padding: 16px 18px; }
.question-result h4 { margin-top: 0; }
.question-result p, .question-result li { line-height: 1.65; }
/* 5-4：一位學生一列：左邊名字與數字，右邊「調整額度」「暫停／恢復學生登入」；展開的表單占整列。 */
.owner-ai-students { display: grid; margin-top: 20px; border-top: 1px solid var(--line); }
.owner-ai-student-card { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; column-gap: 8px; align-items: start; padding: 12px 0; border-bottom: 1px solid var(--line); }
.owner-ai-student-card > * { grid-column: 1; }
.owner-ai-student-card > h5 { margin: 0; }
.owner-ai-student-card > p, .owner-ai-student-card > .owner-adjust-summary { margin: 2px 0; }
.owner-ai-student-card > button { grid-column: 2; grid-row: 1; margin: 0 0 0 8px; justify-self: end; }
.owner-ai-student-card > button.danger, .owner-ai-student-card > button.secondary { grid-column: 3; margin-left: 0; }
.owner-ai-student-card > form { grid-column: 1 / -1; }
.owner-ai-grant-row { align-items: center; display: flex; gap: 12px; justify-content: space-between; }
.owner-ai-grant-row button { flex: 0 0 auto; }
.records-list { display: grid; gap: 12px; margin-top: 16px; }
.record-session-card, .record-entry {
  border: 1px solid var(--line); border-radius: 8px; padding: 14px;
}
.record-session-card .chapter-button { width: 100%; }
.record-session-card > .secondary { margin-top: 10px; }
.records-detail {
  background: var(--raised); border: 1px solid var(--line); border-radius: 8px;
  line-height: 1.6; margin-top: 18px; padding: 18px;
}
.records-detail > h4 { margin-top: 0; }
.records-detail h5 { margin-bottom: 6px; }
.records-detail ul { padding-left: 1.3rem; }
.record-entry + .record-entry { margin-top: 12px; }
.record-entry p { overflow-wrap: anywhere; }
.compact-icon { width:44px; height:44px; min-width:44px; padding:6px; display:inline-flex; align-items:center; justify-content:center; font-size:1.2rem; }
.chapter-history-toolbar { display:flex; flex-wrap:wrap; gap:8px; align-items:center; margin-block:8px; }
.chapter-history-list { display:grid; gap:6px; }
.chapter-history-entry { text-align:left; overflow-wrap:anywhere; min-height:44px; }
.chapter-history-detail { margin-top:16px; min-width:0; }
.chapter-history-detail h6 { margin-block:16px 6px; }
.chapter-history-text { white-space:pre-wrap; overflow-wrap:anywhere; }
.chapter-history-text .katex-display { max-width:100%; overflow-x:auto; overflow-y:hidden; }
[hidden] { display: none !important; }

#private-exam-fields { border: 1px solid var(--line); border-radius: 8px; padding: 16px; min-width: 0; }
.exam-selection-row { display: flex; gap: 12px; align-items: center; overflow-wrap: anywhere; }
.exam-selection-row label { flex: 1; min-width: 0; }
.exam-selection-row input { max-width: 100px; }
.private-exam-preview { display: block; max-width: 100%; max-height: 80vh; object-fit: contain; margin: 12px auto; }
#private-exam-list .secondary { margin: 4px; }

@media (max-width: 720px) {
  /* 3-3：手機上卡片貼齊螢幕左右、內距 16px，內容寬度從 310px 增加到 358px（390 寬）。 */
  .shell { width: 100%; padding-top: 16px; }
  .hero, #notice { margin-left: 16px; margin-right: 16px; }
  .card { padding: 16px; border-radius: 0; border-left: 0; border-right: 0; }
  .grid { gap: 12px; }
  .learning-heading { flex-direction: column; gap: 4px; }
  .learning-heading-actions { justify-content: flex-start; }
  .tools-exam-note { text-align: left; }
  .grid { grid-template-columns: 1fr; }
  .account-row { flex-direction: column; }
  .topic-chapter-fields { grid-template-columns: 1fr; }
  .topic-chapter-form button { width: 100%; }
  .topic-chapter-panel { padding: 14px; }
}
.learning-media, .learning-ink-board, .learning-step-rows { min-width: 0; max-width: 100%; }
.learning-media-actions, .learning-media-thumbs { display: flex; flex-wrap: wrap; gap: .5rem; margin: .5rem 0; }
.learning-media-thumb { width: 8rem; max-width: 100%; }
.learning-media-thumb img { width: 100%; height: 6rem; object-fit: contain; background: #fff; }
.learning-media-thumb button { width: 100%; }
.learning-ink-board canvas { display: block; width: 100%; max-width: 900px; height: auto; aspect-ratio: 3 / 2; touch-action: none; background: #fff; border: 1px solid #64748b; box-sizing: border-box; }
.learning-step-row { margin: .75rem 0; }
.learning-step-row textarea { display: block; width: 100%; max-width: 100%; box-sizing: border-box; }

/* S-15：會用額度的動作就地標示成本（2026-10-17） */
.learning-cost-note { margin: 10px 0 0; font-size: var(--fs-note); color: var(--muted); }
.learning-actions + .learning-cost-note { margin-top: 16px; padding-bottom: 4px; }
.learning-cost-note .quota-left { margin-left: 6px; font-weight: 650; color: var(--primary); }

/* S-16a：按鈕說明（電腦滑鼠停留、手機平板長按；元件 tooltip.js）與使用須知（2026-10-17） */
.tip-bubble { position: absolute; z-index: 20; max-width: min(280px, calc(100vw - 16px)); padding: 8px 10px; border-radius: 8px;
  background: #172033; color: #f3f6fb; font-size: var(--fs-note); line-height: 1.55; box-shadow: 0 4px 14px rgb(0 0 0 / .18); pointer-events: none; }
.tip-bubble::after { content: ""; position: absolute; left: 50%; bottom: -5px; width: 10px; height: 10px; background: #172033; transform: translateX(-50%) rotate(45deg); }
.tip-bubble.below::after { bottom: auto; top: -5px; }
[data-tip] { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
.tip-howto { font-size: var(--fs-note); margin-top: 4px; }
.tip-howto .for-touch { display: none; }
@media (hover: none) { .tip-howto .for-hover { display: none; } .tip-howto .for-touch { display: inline; } }
@media (prefers-reduced-motion: no-preference) { .tip-bubble:not([hidden]) { animation: tip-in .12s ease-out; } @keyframes tip-in { from { opacity: 0; } to { opacity: 1; } } }
.usage-notes { margin: 10px 0 12px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.usage-notes > summary { cursor: pointer; font-weight: 650; }
.usage-notes ul { margin: 8px 0 4px; padding-left: 1.2rem; line-height: 1.7; color: var(--ink); }
.learning-rest-reminder { border-left: 4px solid var(--primary); }

/* 3-6：Owner 控制區頂部捷徑（S-29） */
.owner-jump { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 16px; }
.owner-jump a { padding: 6px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); font-weight: 650; text-decoration: none; }
.owner-jump a:hover { border-color: var(--primary); }
#owner-home .question-panel > h4[id] { scroll-margin-top: 16px; }

/* S-18：Owner 全站額度控制（2026-10-18） */
.owner-site-cap { margin: 10px 0 14px; }
.owner-site-cap #owner-site-today { white-space: pre-line; }
.owner-site-cap form { margin: 10px 0; }
.owner-advanced > summary { cursor: pointer; margin: 8px 0; color: var(--muted); }
#owner-site-panel input[type="checkbox"] { width: auto; padding: 0; margin: 0 6px 0 0; vertical-align: middle; }

/* S-19：學生卡片「調整額度」（2026-10-18） */
.owner-adjust-summary { margin: 4px 0; }
.owner-adjust-form { margin-top: 10px; padding: 10px 12px; border: 1px dashed #b9c6dc; border-radius: 8px; background: var(--raised); }
.owner-adjust-form label { margin-top: 10px; }
.owner-adjust-form button { margin-top: 10px; }

/* S-16c：學生申請額外點數（2026-10-20） */
.unit-request-text { white-space: pre-line; }
/* S-29 追加 6-1：入口是一行灰色小字；展開後表單照常。 */
.extra-units-panel { margin-top: 20px; }
.extra-units-panel > summary { cursor: pointer; margin: 8px 0; color: var(--muted); font-size: var(--fs-note); font-weight: 400; }
.extra-units-panel[open] > summary { color: var(--ink); font-weight: 650; }
button.rest-extra-units { margin-top: 4px; }
.learning-stage:empty { display: none; }
.extra-units-panel form label { margin-top: 10px; }

/* S-21：錯因勾選（2026-10-18） */
/* 5-1（S-29）：一列一句：左邊學生原句、右邊判定小標籤；說明與「改成：…」在下一行。 */
.line-feedback { margin: 0.25rem 0 0.75rem; padding: 0; list-style: none; counter-reset: line; border-top: 1px solid var(--line); }
.learning-content .line-feedback { padding: 0; }
.line-feedback li { counter-increment: line; position: relative; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin: 0; padding: 10px 0 10px 2em; border-bottom: 1px solid var(--line); }
.line-feedback li::before { content: counter(line) "."; position: absolute; left: 0; top: 10px; color: var(--muted); font-variant-numeric: tabular-nums; }
.line-feedback li > * { flex-basis: 100%; min-width: 0; }
.line-feedback li > .line-quote { flex: 1 1 12em; font-weight: 500; overflow-wrap: anywhere; }
.line-feedback li > .line-mark { flex: none; }
.line-mark { display: inline-block; padding: 1px 8px; border-radius: 4px; border: 1px solid transparent; font-size: var(--fs-note); font-weight: 650; line-height: 1.6; white-space: nowrap; }
.line-ok { background: var(--ok-bg); border-color: var(--ok-line); color: var(--ok-ink); }
.line-wrong { background: var(--bad-bg); border-color: var(--bad-line); color: var(--bad-ink); }
.line-nonstandard { background: var(--sys-bg); border-color: var(--sys-line); color: var(--sys-ink); }
.line-note, .line-fix { font-size: 0.95em; }
.line-fix { padding-left: 0.75em; border-left: 3px solid var(--bad-line); color: var(--bad-ink); }
.line-section { font-size: var(--fs-note); color: var(--muted); }
.error-example { margin: 0.25rem 0 0.75rem; padding: 0.5rem 0.75rem; border-left: 3px solid #8a5a00; background: #fbf7ef; }
.error-example p { margin: 0.3rem 0; }
.reference-solution { margin: 0.5rem 0; }
.reference-solution summary { cursor: pointer; }
/* 5-2（S-29）：整列可點、每列至少 44px 高；選到的那列用主色外框。 */
.cause-options { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 14em), 1fr)); gap: 8px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px 12px; margin: 10px 0; min-width: 0; }
.cause-options legend { font-weight: 650; padding: 0 4px; }
.cause-options label { display: flex; align-items: center; gap: 10px; min-height: 44px; margin: 0; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); font-weight: 500; cursor: pointer; }
.cause-options label:hover { border-color: var(--primary); }
.cause-options label:has(input:checked) { border-color: var(--primary); background: var(--primary-tint); }
.cause-options input[type="radio"] { flex: none; width: 18px; height: 18px; margin: 0; padding: 0; }

/* 4-1：空的狀態框收成 0 高度，不再掛一條空灰條；仍留在頁面上，之後有內容時朗讀照常。 */
.status-box:empty { padding: 0; margin: 0; border: 0; background: none; min-height: 0; }

/* S-29 5-4：手機上學生列的按鈕排在資料下方（放檔尾，才能蓋過上面的桌機規則）。 */
@media (max-width: 720px) {
  .owner-ai-student-card { grid-template-columns: auto auto minmax(0, 1fr); }
  .owner-ai-student-card > * { grid-column: 1 / -1; }
  .owner-ai-student-card > button { grid-row: auto; grid-column: 1; margin: 8px 0 0; }
  .owner-ai-student-card > button.danger, .owner-ai-student-card > button.secondary { grid-row: auto; grid-column: 2; margin: 8px 0 0 8px; }
}

/* S-31（2026-10-20）：講解、補教、訂正附的系統圖（伺服器排好的 SVG 圖元）。顏色都寫在這裡，SVG 不帶 style 屬性。 */
.learning-diagram { margin: 12px 0 16px; padding: 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); max-width: 40em; }
.learning-diagram .diagram-svg { display: block; width: 100%; height: auto; color: var(--ink); }
.learning-diagram figcaption { margin: 4px 4px 0; color: var(--muted); font-size: var(--fs-note); line-height: 1.5; }
.diagram-grid { stroke: #e6ebf2; stroke-width: 1; }
.diagram-axis { stroke: #4b5568; stroke-width: 1.8; }
.diagram-line, .diagram-polygon { stroke: #33405a; stroke-width: 2.2; fill: none; }
.diagram-function { stroke: var(--primary); stroke-width: 3; fill: none; }
.diagram-guide { stroke: #b4541a; stroke-width: 2; stroke-dasharray: 8 6; fill: none; }
.diagram-highlight { stroke: #b4541a; stroke-width: 5; stroke-linecap: round; opacity: .55; }
.diagram-projection, .diagram-asymptote { stroke: #7a8496; stroke-width: 1.5; stroke-dasharray: 6 5; }
.diagram-region { stroke: #6b7a94; stroke-width: 1.5; fill: #e8eef8; }
.diagram-point, .diagram-endpoint, .diagram-feature { stroke: var(--ink); stroke-width: 2; color: var(--ink); }
.diagram-mark { stroke: #b4541a; stroke-width: 2.2; fill: none; }
.diagram-tick { stroke: #4b5568; stroke-width: 1.4; }
.diagram-label, .diagram-axis-label, .diagram-function-label { fill: var(--ink); font: 15px var(--font-sans); paint-order: stroke; stroke: #fff; stroke-width: 4px; stroke-linejoin: round; }
.diagram-function-label { font-weight: 650; }
.diagram-arrow { fill: #33405a; }
/* 手機上整張圖縮小約一半，SVG 內的字放大，縮小後約 11px。 */
@media (max-width: 600px) {
  .learning-diagram { padding: 4px; }
  .diagram-label, .diagram-axis-label, .diagram-function-label { font-size: 19px; stroke-width: 5px; }
}

/* ── A 批路由殼（2026-10-20）：同一個 /v2/，用 #/路徑 切換頁面容器（app.js applyAppRoute 寫 #signed-in 的 data-role／data-route）。 ── */
/* 學生只在「我的」與限時測驗頁顯示帳號列（名字、登出）；限時測驗面板只在測驗頁。Owner／Staff 照舊。 */
#signed-in[data-role="STUDENT"]:not([data-route="me"]):not([data-route="exam"]) > .account-row { display: none; }
#signed-in[data-role="STUDENT"]:not([data-route="exam"]) > #timed-assessment-panel { display: none; }
#signed-in[data-role="STUDENT"][data-route="exam"] > #timed-assessment-panel { border-top: 0; margin-top: 8px; padding-top: 0; }
/* 學習頁是專注模式：頁首（站名、講義連結）收起，只留頂端列與學習畫面。 */
body:has(#signed-in[data-route="learn"]:not([hidden])) .hero { display: none; }
.route-page:not(#page-me) > .question-panel:first-child { border-top: 0; margin-top: 0; padding-top: 0; }
.route-page > .usage-notes { margin-top: 24px; }

/* 學生 5 格導覽：電腦在卡片頂端，手機固定在畫面底部（見下方 720px）。 */
.student-nav { display: flex; flex-wrap: wrap; gap: 4px; margin: -8px 0 20px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.student-nav a { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px; border-radius: 8px; color: var(--muted); font-weight: 650; text-decoration: none; }
.student-nav a:hover { background: var(--info-bg); color: var(--ink); }
.student-nav a[aria-current="page"] { background: var(--primary-tint); color: var(--primary-tint-ink); }
.student-nav svg { width: 20px; height: 20px; flex: none; }

/* 學習頁頂端列：← 回今天｜章節・步驟｜剩餘額度。捲動時固定在畫面頂端。 */
.learn-bar { position: sticky; top: 0; z-index: 5; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 4px 16px;
  min-height: 56px; margin: -8px 0 8px; padding: 4px 0; background: var(--surface); border-bottom: 1px solid var(--line); }
.learn-back { grid-column: 1; grid-row: 1; display: inline-flex; align-items: center; min-height: 44px; font-weight: 650; text-decoration: none; white-space: nowrap; }
.learn-bar .learning-stage { grid-column: 2; grid-row: 1; margin: 0; color: var(--ink); font-size: 15px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.learn-bar-quota { grid-column: 3; grid-row: 1; margin: 0; color: var(--muted); font-size: var(--fs-note); white-space: nowrap; }
#page-learn .learning-session { border-top: 0; margin-top: 0; padding-top: 12px; scroll-margin-top: 72px; }
#learning-title { margin: 12px 0 14px; line-height: 1.35; }

/* 「今天」頁 */
.today-page > h2 { margin: 0; font-size: var(--fs-title); }
.today-date { margin: 2px 0 16px; color: var(--muted); font-size: var(--fs-note); }
.today-resume { padding: 24px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.today-resume > :first-child { margin-top: 0; }
.today-eyebrow { margin: 0; color: var(--muted); font-size: var(--fs-note); font-weight: 650; }
.today-resume h3 { margin: 4px 0 2px; font-size: 22px; font-weight: 700; overflow-wrap: anywhere; }
.today-resume-meta { margin: 0; color: var(--muted); font-size: 15px; }
.today-resume-button { min-width: 200px; min-height: 52px; margin-top: 18px; font-size: 17px; }
a.today-start { display: inline-block; margin-top: 12px; padding: 12px 18px; border-radius: 8px; background: var(--primary); color: #fff; font-weight: 650; text-decoration: none; }
a.today-start:hover { background: var(--primary-strong); color: #fff; }
.today-banner { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; margin-top: 16px; padding: 14px 16px; border-radius: 12px; background: var(--info-bg); }
.today-banner p { flex: 1 1 200px; margin: 0; }
.today-recent { margin-top: 16px; padding: 8px 20px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.today-recent-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.today-recent-head h3 { margin: 10px 0 4px; }
.today-recent-head a { font-weight: 650; }
.today-recent-list { margin: 0; padding: 0; list-style: none; }
.today-recent-list li + li { border-top: 1px solid var(--line); }
.today-recent-item { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; margin: 0; padding: 10px 0; border-radius: 0;
  background: transparent; color: var(--ink); font-weight: 400; text-align: left; }
.today-recent-item:hover .today-recent-text strong { color: var(--primary); }
.today-recent-text { flex: 1; min-width: 0; }
.today-recent-text strong { display: block; font-weight: 650; overflow-wrap: anywhere; }
.today-recent-sub { display: block; color: var(--muted); font-size: var(--fs-note); }
.today-pill { flex: none; padding: 1px 8px; border: 1px solid var(--line); border-radius: 4px; background: var(--raised); color: var(--ink); font-size: var(--fs-note); white-space: nowrap; }
.today-pill.is-done { background: var(--ok-bg); border-color: var(--ok-line); color: var(--ok-ink); }
.today-recent-empty { padding: 12px 0; }
.today-quota { margin: 16px 0 0; color: var(--muted); font-size: var(--fs-note); }

/* 7：另開新分頁的入口都標明（工具頁、講義站不能嵌進平台）。學習畫面與等待提示裡的連結文字本來就寫了「另開新頁」，不重複。 */
a[target="_blank"]:not(.learning-content a):not(.learning-wait a)::after { content: "（另開新分頁）"; display: inline-block; margin-left: 2px; font-size: .85em; font-weight: 400; }

@media (max-width: 720px) {
  .student-nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 15; display: grid; grid-template-columns: repeat(5, 1fr); gap: 0;
    margin: 0; padding: 0 0 env(safe-area-inset-bottom); background: var(--surface); border-top: 1px solid var(--line); border-bottom: 0; }
  .student-nav a { flex-direction: column; justify-content: center; gap: 2px; min-height: 58px; padding: 6px 0 4px; border-radius: 0; font-size: 13px; line-height: 1.2; }
  .student-nav a[aria-current="page"] { background: transparent; color: var(--ink); }
  .student-nav a[aria-current="page"] svg { color: var(--primary); }
  body:has(#student-nav:not([hidden])) .shell { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
  .learn-bar { grid-template-columns: auto minmax(0, 1fr); margin-top: -4px; }
  .learn-bar-quota { grid-column: 2; justify-self: end; }
  .learn-bar .learning-stage { grid-column: 1 / -1; grid-row: 2; padding-bottom: 6px; text-align: left; white-space: normal; line-height: 1.4; }
  #page-learn .learning-session { scroll-margin-top: 104px; }
  .today-resume { padding: 20px 16px; }
  .today-resume-button, a.today-start { width: 100%; text-align: center; }
  .today-recent { padding: 4px 16px; }
}

/* S-32a 限時測驗手寫作答（2026-10-20）：手寫板、讀取提示、收卷後原圖。canvas 的 touch-action:none 讓手機能用手指寫、不捲動頁面。 */
.timed-media-rule { margin: 8px 0; padding: 10px 12px; background: var(--info-bg); border-radius: 8px; line-height: 1.65; }
.timed-media { margin: 14px 0; padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--raised); min-width: 0; max-width: 100%; }
.timed-media h5 { margin: 0 0 6px; font-size: var(--fs-section); }
.timed-media-cost { font-weight: 700; color: var(--primary-tint-ink); margin: 6px 0; }
.timed-media-board { margin: 10px 0; min-width: 0; max-width: 100%; }
.timed-media-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin: .5rem 0; }
.timed-media-actions button[aria-pressed="true"] { background: var(--primary); color: #fff; }
.timed-media-board canvas { display: block; width: 100%; max-width: 900px; height: auto; aspect-ratio: 3 / 2; touch-action: none; background: #fff; border: 1px solid var(--control-line); border-radius: 6px; box-sizing: border-box; }
.timed-media-status { margin: 8px 0 0; color: var(--ink); overflow-wrap: anywhere; }
.timed-media-banner { margin: 10px 0; padding: 12px 14px; background: var(--sys-bg); border: 2px solid var(--sys-line); color: var(--sys-ink); border-radius: 8px; font-weight: 700; }
.timed-media-review { margin: 12px 0; }
.timed-media-review-item { margin: 8px 0; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.timed-media-image { display: block; width: 100%; max-width: 600px; height: auto; background: #fff; border: 1px solid var(--line); border-radius: 6px; margin: 6px 0; }
.timed-media-flag { margin: 6px 0; padding: 8px 10px; background: var(--sys-bg); border: 1px solid var(--sys-line); color: var(--sys-ink); border-radius: 6px; }
