:root {
  color-scheme: light;
  --bg: #f6f5f0;
  --surface: #ffffff;
  --surface-2: #eeede6;
  --text: #1c2526;
  --muted: #55605f;
  --border: #d5d4ca;
  --control-border: #7c8583;
  --primary: #0b5f5b;
  --primary-strong: #084643;
  --on-primary: #ffffff;
  --primary-soft: #dcedea;
  --ok: #17673a;
  --ok-soft: #dff1e5;
  --bad: #a4261d;
  --bad-soft: #f9e3e0;
  --warn-soft: #f8eccb;
  --warn-text: #5c4300;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(20 30 30 / .08);
  --font: "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", system-ui, sans-serif;
  --font-en: "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", Arial, sans-serif;
  --nav-h: 62px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #151b1b;
    --surface: #1f2727;
    --surface-2: #2a3333;
    --text: #edf1ef;
    --muted: #aeb9b6;
    --border: #3b4645;
    --control-border: #84908d;
    --primary: #6fd0c7;
    --primary-strong: #93e0d9;
    --on-primary: #06302d;
    --primary-soft: #1e3f3d;
    --ok: #79d59c;
    --ok-soft: #1c3c2a;
    --bad: #ffa79f;
    --bad-soft: #4b2522;
    --warn-soft: #443714;
    --warn-text: #f4dd9b;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #151b1b;
  --surface: #1f2727;
  --surface-2: #2a3333;
  --text: #edf1ef;
  --muted: #aeb9b6;
  --border: #3b4645;
  --control-border: #84908d;
  --primary: #6fd0c7;
  --primary-strong: #93e0d9;
  --on-primary: #06302d;
  --primary-soft: #1e3f3d;
  --ok: #79d59c;
  --ok-soft: #1c3c2a;
  --bad: #ffa79f;
  --bad-soft: #4b2522;
  --warn-soft: #443714;
  --warn-text: #f4dd9b;
  --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 1rem/1.6 var(--font);
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}
[lang="en"] { font-family: var(--font-en); }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.5rem; line-height: 1.3; }
h2 { font-size: 1.125rem; line-height: 1.4; }
a { color: var(--primary); }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; border-radius: 4px; }
[tabindex="-1"]:focus { outline: none; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.skip-link { position: absolute; left: 8px; top: -60px; z-index: 30; background: var(--surface); padding: 10px 14px; border-radius: 8px; }
.skip-link:focus { top: 8px; }

/* 頁首與導覽：手機為底部導覽，平板以上移到頂部 */
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); }
.site-header__inner { max-width: 1040px; margin: auto; padding: 0 16px; }
.brand { display: block; padding: 11px 0; font-weight: 700; color: var(--text); text-decoration: none; }
.brand-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-width: 0; }
.member-link {
  display: block; max-width: 12em; min-height: 44px; line-height: 44px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: .94rem; font-weight: 600;
}
.member-link[hidden] { display: none; }
.logged-out .site-nav { display: none; }
.login { width: 100%; max-width: 440px; margin: 16px auto; }
.login__error { color: var(--bad); font-size: .94rem; font-weight: 600; }
.login__error:empty { display: none; }
.login__teacher summary { padding: 10px 0; cursor: pointer; font-weight: 600; }
.stack { display: grid; gap: 12px; }
.check { display: flex; gap: 10px; align-items: flex-start; min-height: 44px; font-size: .94rem; cursor: pointer; }
.check input { flex: none; width: 22px; height: 22px; margin: 2px 0 0; }
.plain-list { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.join-code { font: 700 1.25rem/1.4 var(--font-en); letter-spacing: .08em; }
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; min-width: 560px; border-collapse: collapse; font-size: .94rem; }
.data-table th, .data-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; font-variant-numeric: tabular-nums; }
.data-table thead th { font-size: .875rem; color: var(--muted); white-space: nowrap; }
.data-table__actions { white-space: nowrap; }
.data-table__actions .btn + .btn { margin-left: 6px; }
.btn--small { min-height: 44px; padding: 6px 12px; font-size: .875rem; }
.common-wrong { margin: 0; padding-left: 24px; display: grid; gap: 8px; }
.common-wrong li > * { margin-right: 10px; }
.site-nav {
  position: fixed; inset: auto 0 0 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.site-nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: var(--nav-h); font-size: .78rem; color: var(--muted); text-decoration: none;
}
.site-nav svg { width: 22px; height: 22px; fill: currentColor; }
.site-nav a[aria-current="page"] { color: var(--primary); font-weight: 700; box-shadow: inset 0 3px 0 var(--primary); }

.page { max-width: 1040px; margin: auto; padding: 20px 16px 32px; display: grid; gap: 18px; }
.page__head { display: grid; gap: 4px; }
.lead { color: var(--muted); }
.loading { padding: 40px 0; text-align: center; color: var(--muted); }
.notice { max-width: 1040px; margin: 10px auto 0; padding: 10px 16px; background: var(--warn-soft); color: var(--warn-text); font-size: .94rem; }
@media (min-width: 1072px) { .notice { border-radius: 8px; } }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); display: grid; gap: 12px; }
.note { font-size: .875rem; color: var(--muted); }

/* 按鈕與表單 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 8px 18px; border-radius: 10px; border: 1px solid var(--control-border);
  background: var(--surface); color: var(--text); font-weight: 600; text-decoration: none; cursor: pointer;
  touch-action: manipulation;
}
.btn:hover { background: var(--surface-2); }
.btn--primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn--primary:hover { background: var(--primary-strong); border-color: var(--primary-strong); }
.btn--ok { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.btn--bad { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.btn--ok:hover { background: var(--ok-soft); }
.btn--bad:hover { background: var(--bad-soft); }
.btn--ghost { border-color: transparent; background: transparent; color: var(--primary); }
.btn--ghost:hover { background: var(--primary-soft); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }
.btn-row--fill > * { flex: 1 1 140px; }

.field { display: grid; gap: 4px; min-width: 0; }
.field > label, .field > .field__label { font-size: .875rem; font-weight: 600; }
.field select, .field input {
  width: 100%; min-height: 46px; padding: 8px 10px;
  border: 1px solid var(--control-border); border-radius: 10px; background: var(--surface);
}
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.field--wide { grid-column: 1 / -1; }
@media (min-width: 768px) { .field-grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

/* 單字卡片（列表） */
.word-list { display: grid; gap: 12px; }
@media (min-width: 900px) { .word-list { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; } }
.word-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); display: grid; gap: 8px; min-width: 0; }
.word-card__head { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 10px; }
.speak-btn {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 4px 8px; margin-left: -8px;
  background: none; border: 0; border-radius: 8px; cursor: pointer; text-align: left; color: inherit; touch-action: manipulation;
}
@media (hover: hover) { .speak-btn:hover { background: var(--primary-soft); } }
.speak-btn svg { flex: none; width: 20px; height: 20px; fill: var(--primary); }
.speak-btn.is-speaking { background: var(--primary-soft); }
.word-btn { font-size: 1.375rem; font-weight: 700; line-height: 1.25; }
.word-btn--large { font-size: 2.125rem; margin: 0; }
.word-btn--large svg { width: 26px; height: 26px; }
.kk { color: var(--muted); font-family: "Segoe UI", "Lucida Sans Unicode", "Noto Sans", "Arial Unicode MS", sans-serif; overflow-wrap: anywhere; }
.senses { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.pos { display: inline-block; min-width: 2.4em; margin-right: 4px; color: var(--primary); font-weight: 600; font-size: .875rem; font-family: var(--font-en); }
.example { border-left: 3px solid var(--primary-soft); padding-left: 10px; display: grid; gap: 0; }
.example-btn { font-size: 1rem; margin-left: -8px; padding: 6px 8px; align-items: flex-start; }
.example-btn svg { margin-top: 3px; width: 18px; height: 18px; }
.example__zh { color: var(--muted); font-size: .94rem; }
.tags { display: flex; flex-wrap: wrap; gap: 4px 6px; font-size: .78rem; color: var(--muted); }
.tag { background: var(--surface-2); border-radius: 6px; padding: 1px 7px; }
.tag--warn { background: var(--warn-soft); color: var(--warn-text); }
.tag--ok { background: var(--ok-soft); color: var(--ok); }
.tag--bad { background: var(--bad-soft); color: var(--bad); }
.result-count { font-size: .94rem; color: var(--muted); }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); }

/* 首頁 */
.stat-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 10px; text-align: center; }
.stat b { display: block; font-size: 1.5rem; line-height: 1.2; }
.stat span { font-size: .82rem; color: var(--muted); }
.entry-grid { display: grid; gap: 10px; }
@media (min-width: 768px) { .entry-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.entry { display: grid; gap: 2px; padding: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); text-decoration: none; min-height: 84px; }
.entry:hover { border-color: var(--primary); }
.entry b { font-size: 1.0625rem; color: var(--primary); }
.entry span { font-size: .9rem; color: var(--muted); }

/* 單字卡（翻面） */
.deck-status { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: .94rem; color: var(--muted); }
progress { width: 100%; height: 8px; accent-color: var(--primary); }
.flip { perspective: 1400px; max-width: 640px; width: 100%; margin: auto; }
.flip__inner { display: grid; transform-style: preserve-3d; transition: transform .35s ease; }
.flip.is-flipped .flip__inner { transform: rotateY(180deg); }
.face {
  grid-area: 1 / 1; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow);
  padding: 22px 18px; min-height: 320px; display: flex; flex-direction: column; gap: 12px; cursor: pointer; min-width: 0;
}
.face--front { align-items: center; justify-content: center; text-align: center; }
.face--back { transform: rotateY(180deg); justify-content: center; }
.face__hint { color: var(--muted); font-size: .875rem; }
.deck-actions { max-width: 640px; width: 100%; margin: auto; display: grid; gap: 10px; }
.deck-actions__marks { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
kbd { font: .78rem var(--font-en); border: 1px solid var(--control-border); border-radius: 4px; padding: 0 4px; }
.kbd-hint { display: none; text-align: center; font-size: .82rem; color: var(--muted); }
@media (hover: hover) and (min-width: 768px) { .kbd-hint { display: block; } }

/* 測驗 */
.mode-list { display: grid; gap: 8px; border: 0; margin: 0; padding: 0; }
.mode-list legend { font-size: .875rem; font-weight: 600; margin-bottom: 4px; padding: 0; }
@media (min-width: 768px) { .mode-list { grid-template-columns: repeat(3, minmax(0, 1fr)); } .mode-list legend { grid-column: 1 / -1; } }
.mode { display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 8px 12px; border: 1px solid var(--control-border); border-radius: 10px; cursor: pointer; background: var(--surface); }
.mode:has(input:checked) { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); background: var(--primary-soft); }
.mode input { width: 18px; height: 18px; accent-color: var(--primary); margin: 0; flex: none; }
.mode small { display: block; color: var(--muted); }
.quiz-wrap { max-width: 640px; width: 100%; margin: auto; display: grid; gap: 14px; }
.quiz-prompt { text-align: center; padding: 18px 12px; display: grid; justify-items: center; gap: 6px; }
.quiz-prompt__zh { font-size: 1.375rem; font-weight: 700; line-height: 1.4; }
.options { display: grid; gap: 10px; list-style: none; margin: 0; padding: 0; }
.option {
  width: 100%; min-height: 54px; padding: 10px 14px; display: flex; align-items: center; gap: 10px; text-align: left;
  background: var(--surface); border: 1px solid var(--control-border); border-radius: 10px; cursor: pointer; touch-action: manipulation;
}
.option:hover:not([disabled]) { background: var(--surface-2); }
.option[disabled] { cursor: default; opacity: 1; color: var(--text); }
.option__no { flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; font-size: .82rem; font-weight: 600; }
.option__mark { margin-left: auto; font-weight: 700; flex: none; }
.option.is-correct { background: var(--ok-soft); border-color: var(--ok); box-shadow: inset 0 0 0 1px var(--ok); }
.option.is-correct .option__mark { color: var(--ok); }
.option.is-wrong { background: var(--bad-soft); border-color: var(--bad); box-shadow: inset 0 0 0 1px var(--bad); }
.option.is-wrong .option__mark { color: var(--bad); }
.spell-form { display: grid; gap: 10px; }
.spell-input { font-size: 1.25rem; text-align: center; }
.feedback { font-weight: 700; }
.feedback--ok { color: var(--ok); }
.feedback--bad { color: var(--bad); }
.score { text-align: center; display: grid; gap: 2px; padding: 8px 0; }
.score b { font-size: 3rem; line-height: 1.1; color: var(--primary); }

/* 進度 */
.meter-list { display: grid; gap: 14px; }
.meter__label { display: flex; justify-content: space-between; gap: 12px; font-size: .94rem; }
.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: .94rem; }
.history li { display: flex; justify-content: space-between; gap: 12px; }
dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 18px; width: min(420px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(0 0 0 / .5); }
dialog form { display: grid; gap: 14px; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(var(--nav-h) + 12px + env(safe-area-inset-bottom)); z-index: 40;
  max-width: 480px; margin: auto; padding: 10px 14px; border-radius: 10px;
  background: var(--text); color: var(--bg); text-align: center; font-size: .94rem;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.toast.is-visible { opacity: 1; }

@media (min-width: 768px) {
  body { padding-bottom: 0; }
  .site-header { position: sticky; top: 0; z-index: 20; }
  .site-header__inner { display: flex; align-items: center; justify-content: space-between; gap: 24px; }
  .site-nav { position: static; display: flex; gap: 4px; border: 0; padding: 0; background: none; }
  .site-nav a { flex-direction: row; gap: 6px; min-height: 52px; padding: 0 12px; font-size: .94rem; }
  .site-nav svg { width: 18px; height: 18px; }
  .site-nav a[aria-current="page"] { box-shadow: inset 0 -3px 0 var(--primary); }
  .toast { bottom: 24px; }
  h1 { font-size: 1.75rem; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
