:root {
  --bg: #f3f5f7;
  --surface: #ffffff;
  --ink: #27313f;
  --muted: #7a8492;
  --sub: #60758b;
  --line: #dde2e8;
  --soft: #f1f4f7;
  --primary: #34495e;
  --primary-hover: #25384a;
  --danger: #bd4c3f;
  --success: #2e8051;
  --accent: #b4523d;
  --shadow: 0 18px 50px rgba(35, 47, 61, .08);
}

* { box-sizing: border-box; }
html { min-width: 320px; }
body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 88% 12%, rgba(74, 108, 134, .08), transparent 24rem),
    var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.site-header { border-bottom: 1px solid var(--line); background: rgba(255, 255, 255, .9); }
.header-inner {
  display: flex;
  width: min(1120px, calc(100% - 32px));
  min-height: 66px;
  margin: auto;
  align-items: center;
  justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand-logo {
  display: block;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
}
.brand strong, .brand small { display: block; }
.brand strong { font-size: 18px; font-weight: bold; letter-spacing: -.01em; }
.brand small { margin-top: 1px; color: #60758b; font-size: 10px; }
.header-inner nav { display: flex; gap: 24px; align-self: stretch; }
.header-inner nav a {
  position: relative;
  display: flex;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
}
.header-inner nav a:hover, .header-inner nav a.active { color: var(--primary); }
.header-inner nav a.active::after {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 2px;
  background: var(--primary);
  content: "";
}

.page-shell { width: min(1120px, calc(100% - 32px)); margin: 0 auto; padding: 34px 0 70px; }
.back-link { display: inline-block; margin-bottom: 20px; color: var(--muted); font-size: 11px; font-weight: 700; text-decoration: none; }
.back-link:hover { color: var(--primary); }
.table-heading { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-bottom: 22px; }
.table-toolbar {
  min-height: 62px;
  padding: 10px;
  border: 1px solid #e0e5eb;
  border-radius: 13px;
  background: rgba(255, 255, 255, .96);
  box-shadow: 0 10px 28px rgba(35, 47, 61, .07);
}
.table-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.table-actions .button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 8px 13px;
  border: 1px solid transparent;
  border-radius: 9px;
  font-size: 12px;
  font-weight: 750;
  line-height: 1.2;
  box-shadow: 0 1px 2px rgba(26, 36, 48, .03);
  transition: border-color .16s, background .16s, color .16s, box-shadow .16s, transform .16s;
}
.table-actions .button.primary { border-color: #1a1a2e; background: #1a1a2e; color: #fff; }
.table-actions .button.primary:hover:not(:disabled) { border-color: #303047; background: #303047; box-shadow: 0 5px 14px rgba(26, 26, 46, .18); transform: translateY(-1px); }
.table-actions .button.secondary { border-color: #e0e5ec; background: #fff; color: #1a1a2e; }
.table-actions .button.secondary:hover:not(:disabled) { border-color: #bcc6d2; background: #f6f7f9; box-shadow: 0 4px 12px rgba(35, 47, 61, .08); transform: translateY(-1px); }
.table-actions .button.secondary.spelling-action { border-color: #3fa399; color: #3fa399; }
.table-actions .button.secondary.spelling-action:hover:not(:disabled) { border-color: #3fa399; background: #f0f9f8; color: #3fa399; }
.table-actions .button.secondary.import-action { border-color: #c7d1dc; color: #52687e; }
.table-actions .button.secondary.import-action:hover:not(:disabled) { border-color: #9eafbf; color: #34495e; background: #f4f7fa; }
.toolbar-action .lucide-icon { flex: 0 0 auto; }
.action-count {
  display: inline-grid;
  min-width: 20px;
  height: 20px;
  place-items: center;
  padding: 0 6px;
  border-radius: 999px;
  color: #687789;
  background: #edf1f5;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
}
.table-actions .button.primary .action-count { color: #1a1a2e; background: rgba(255, 255, 255, .9); }
.table-actions .spelling-action .action-count { color: #277f76; background: #e4f4f1; }
.table-actions .button:disabled .action-count { opacity: .72; }
.book-picker {
  position: relative;
  display: flex;
  min-width: 190px;
  height: 40px;
  align-items: center;
  border: 1px solid #dce3e9;
  border-radius: 9px;
  background: #f7f9fb;
}
.book-picker::after {
  position: absolute;
  top: 50%;
  right: 10px;
  width: 5px;
  height: 5px;
  border-right: 1.5px solid #60758b;
  border-bottom: 1.5px solid #60758b;
  content: "";
  pointer-events: none;
  transform: translateY(-75%) rotate(45deg);
}
.book-picker:focus-within {
  border-color: #7893a7;
  box-shadow: 0 0 0 3px rgba(71, 105, 132, .2);
}
.book-picker-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding-left: 12px;
  color: #8b96a3;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .04em;
  text-transform: uppercase;
  white-space: nowrap;
}
.book-picker-label::after {
  color: #b4bdc7;
  content: "·";
  font-size: 14px;
  line-height: 1;
}
.book-select {
  width: 100%;
  height: 100%;
  min-width: 120px;
  padding: 0 34px 0 8px;
  border: 0;
  border-radius: 9px;
  color: #34495e;
  background: transparent;
  font-size: 11px;
  font-weight: 750;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}
.book-select:focus-visible { outline: 0; }
.page-size-picker {
  position: relative;
  display: flex;
  width: 62px;
  height: 31px;
  border: 1px solid #cbd6df;
  border-radius: 7px;
  background: white;
}
.page-size-picker::after {
  position: absolute;
  top: 50%;
  right: 10px;
  width: 5px;
  height: 5px;
  border-right: 1.5px solid #60758b;
  border-bottom: 1.5px solid #60758b;
  content: "";
  pointer-events: none;
  transform: translateY(-75%) rotate(45deg);
}
.page-size-picker:focus-within {
  border-color: #7893a7;
  box-shadow: 0 0 0 3px rgba(71, 105, 132, .2);
}
.page-size-select {
  width: 100%;
  height: 100%;
  padding: 0 25px 0 8px;
  border: 0;
  border-radius: 7px;
  color: #405b72;
  background: transparent;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}
.page-size-select:focus-visible { outline: 0; }
.ai-settings-button {
  display: grid;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  place-items: center;
  padding: 0;
  border: 1px solid #e1e6eb;
  border-radius: 9px;
  color: #97a2ae;
  background: #fff;
  cursor: pointer;
}
.ai-settings-button svg {
  width: 16px;
  height: 16px;
}
.ai-settings-button:hover,
.ai-settings-button:focus-visible { border-color: #bdc8d2; color: var(--ink); background: #f7f9fb; outline: 0; }
.table-title { display: flex; align-items: center; justify-content: flex-end; gap: 9px; text-align: right; }
.table-title .eyebrow { display: block; margin-bottom: 7px; color: var(--accent); font-size: 9px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.table-title h1 { margin: 0; font-size: clamp(28px, 4vw, 44px); letter-spacing: -.045em; line-height: 1; }
.table-title p { margin: 7px 0 0; color: var(--muted); font-family: Georgia, "Songti SC", serif; font-size: 12px; }
.table-title p span { color: var(--sub); font-size: 16px; }

.button {
  min-height: 38px;
  padding: 0 15px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  background: white;
  font-size: 11px;
  font-weight: 800;
  transition: border-color .15s, background .15s, color .15s, opacity .15s;
}
.button.primary { border-color: var(--primary); color: white; background: var(--primary); }
.button.primary:hover:not(:disabled) { border-color: var(--primary-hover); background: var(--primary-hover); }
.button.secondary { border-color: #cbd6df; color: #405b72; background: #f1f6fa; }
.button.secondary:hover:not(:disabled) { border-color: #9eb2c2; background: #e7f0f6; }
.button.ghost { color: var(--muted); background: transparent; }
.button:disabled { opacity: .4; cursor: not-allowed; }
.button:focus-visible, button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, a:focus-visible {
  outline: 3px solid rgba(71, 105, 132, .2);
  outline-offset: 2px;
}

.surface { border: 1px solid var(--line); border-radius: 10px; background: var(--surface); box-shadow: var(--shadow); }
.error-banner { margin-bottom: 15px; padding: 12px 15px; border: 1px solid #e3b7b0; border-radius: 8px; color: #8c3e33; background: #fff4f2; font-size: 12px; }
.table-card { overflow: hidden; }
.table-scroll { position: relative; min-height: 300px; overflow: auto; }
table { width: 100%; min-width: 900px; border-collapse: collapse; table-layout: fixed; }
thead { position: sticky; top: 0; z-index: 2; background: #f1f3f6; }
th {
  height: 42px;
  padding: 0 13px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 9px;
  letter-spacing: .07em;
  text-align: left;
  text-transform: uppercase;
}
td {
  height: 52px;
  padding: 7px 13px;
  border-right: 1px solid #edf0f3;
  border-bottom: 1px solid #edf0f3;
  color: #505967;
  font-size: 12px;
}
tr:hover td { background: #fafbfc; }
tr.selected td { background: #f0f5fa; }
th:last-child, td:last-child { border-right: 0; }
.check-cell { width: 48px; text-align: center; }
.check-cell input, .row-checkbox { width: 15px; height: 15px; accent-color: var(--primary); cursor: pointer; }
.id-cell { width: 64px; text-align: center; }
.row-id { cursor: pointer; user-select: none; }
.character-cell { width: 155px; }
.known-cell { width: 105px; }
.pinyin-cell { width: 180px; text-align: center; }
.row-id { color: #a2a9b2; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 10px; text-align: center; }
.word-button, .known-button, .phonetic-button { border: 0; background: transparent; cursor: pointer; }
.word-button {
  color: var(--ink);
  font-family: "Noto Serif SC", "Songti SC", SimSun, serif;
  font-size: 24px;
  font-weight: 700;
}
.word-button:hover { color: var(--accent); }
.word-cell-inner { display: flex; align-items: center; justify-content: space-between; gap: 7px; }
.word-ai-button {
  display: grid;
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  place-items: center;
  border: 0;
  border-radius: 999px;
  color: #c0c7d0;
  background: transparent;
  cursor: pointer;
  opacity: 0;
  transform: translateX(-3px);
  transition: opacity .18s, transform .18s, background-color .18s, color .18s;
}
.word-ai-button:hover, .word-ai-button:focus-visible { color: #3478c7; background: #eaf4ff; outline: none; }
.word-cell-inner:hover .word-ai-button, .word-cell-inner:focus-within .word-ai-button { opacity: 1; transform: none; }
.known-button { padding: 5px 8px; border-radius: 7px; color: var(--muted); font-size: 10px; }
.known-button:hover { background: var(--soft); }
.known-button.active { color: var(--success); background: #edf7f0; }
.meaning-cell { font-family: Georgia, "Times New Roman", serif; line-height: 1.55; }
.meaning-cell.known { color: #b8c0c9; filter: blur(3px); }
.phonetic-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: var(--sub);
  font-family: "Noto Sans", "Segoe UI", sans-serif;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: .03em;
  transition: background-color .18s, color .18s;
}
.phonetic-button:hover { color: #526171; background: #f5f8fb; }
.phonetic-button .lucide-icon { flex: none; color: #b2bac5; transition: color .18s; }
.phonetic-button:hover .lucide-icon, .phonetic-button.playing .lucide-icon { color: #38a7d8; }
.phonetic-button.playing { color: #4e6675; background: #f1f9fd; }

.pagination-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
  background: #fafbfc;
  color: var(--muted);
  font-size: 10px;
}
.pagination-bar label { display: flex; align-items: center; gap: 7px; }
.page-jump input { height: 31px; padding: 0 8px; border: 1px solid var(--line); border-radius: 6px; background: white; }
.pagination { display: flex; justify-content: center; gap: 4px; }
.pagination #pageButtons { display: flex; gap: 4px; }
.pagination button, .page-jump button {
  min-width: 31px;
  height: 31px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  background: white;
}
.pagination button.active { border-color: var(--ink); color: white; background: var(--ink); }
.pagination button:disabled, .page-jump button:disabled { opacity: .35; cursor: not-allowed; }
.page-jump { display: flex; justify-content: flex-end; gap: 5px; }
.page-jump input { width: 55px; }
.table-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 22px;
  padding: 10px 18px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .04em;
}

.dialog {
  width: min(480px, calc(100vw - 28px));
  padding: 34px 32px 30px;
  overflow: visible;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--ink);
  background: white;
  box-shadow: 0 28px 90px rgba(21, 32, 45, .28);
}
html.web-modal-open, html.web-modal-open body { overflow: hidden; }
.web-dialog[hidden] { display: none !important; }
.web-dialog {
  position: fixed;
  inset: 0;
  z-index: var(--web-dialog-z, 11);
  height: fit-content;
  max-height: calc(100dvh - 28px);
  margin: auto;
  overflow: auto;
  overscroll-behavior: contain;
}
.web-dialog:focus { outline: none; }
.web-dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--web-dialog-backdrop-z, 10);
  background: rgba(28, 38, 49, .52);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
.web-dialog-backdrop.battle-backdrop { background: rgba(20, 24, 36, .36); }
.dialog-close {
  position: absolute;
  top: 12px;
  right: 13px;
  display: grid;
  width: 29px;
  height: 29px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  color: #8b949f;
  background: #f1f3f6;
  font-size: 18px;
  line-height: 1;
}
.dialog-close:hover { color: var(--ink); background: #e7ebef; }

.detail-dialog { text-align: center; }
.detail-index, .study-progress, .spelling-progress {
  display: inline-block;
  margin-bottom: 12px;
  color: var(--accent);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.study-progress { color: #1a1a2e; }
.spelling-progress { color: #1a1a2e; }
.detail-character, .study-character {
  margin: 0;
  font-family: "Noto Serif SC", "Songti SC", SimSun, serif;
  font-size: 54px;
  font-weight: 700;
  line-height: 1.1;
}
.detail-pinyin { margin: 10px 0 0; color: var(--sub); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; }
.detail-meaning { margin: 24px 0 0; padding: 18px; border-left: 3px solid var(--sub); background: var(--soft); font-family: Georgia, serif; font-size: 14px; line-height: 1.75; text-align: left; }
.detail-context { margin: 16px 0 0; color: var(--muted); font-family: "Noto Serif SC", "Songti SC", SimSun, serif; font-size: 16px; letter-spacing: .12em; }
.detail-context mark { padding: 2px 4px; color: var(--accent); background: #fff1ed; }

.ai-settings-dialog { width: min(560px, calc(100vw - 28px)); padding: 26px 28px 24px; }
.ai-settings-heading { display: grid; grid-template-columns: 42px 1fr; align-items: center; gap: 13px; padding-right: 32px; margin-bottom: 24px; }
.ai-settings-mark { display: grid; width: 42px; height: 42px; place-items: center; border-radius: 11px; color: #58748f; background: #eef5fb; font-size: 12px; font-weight: 800; }
.ai-settings-heading h2 { margin: 0; font-size: 19px; letter-spacing: -.02em; }
.ai-settings-heading p { margin: 4px 0 0; color: var(--muted); font-size: 11px; line-height: 1.55; }
.ai-settings-form { display: grid; gap: 17px; }
.ai-field { display: grid; gap: 7px; color: var(--sub); font-size: 12px; font-weight: 750; }
.ai-field-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.ai-field code { padding: 2px 6px; border-radius: 5px; color: #54708b; background: #eef2f6; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 10px; }
.ai-field input, .ai-field textarea { width: 100%; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); background: #fff; }
.ai-field input { height: 41px; padding: 0 11px; }
.ai-field textarea { min-height: 132px; margin: 0; padding: 11px 12px; resize: vertical; line-height: 1.65; }
.ai-switch-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 13px 14px; border: 1px solid var(--line); border-radius: 10px; background: #fafbfc; cursor: pointer; }
.ai-switch-row strong, .ai-switch-row small { display: block; }
.ai-switch-row strong { font-size: 12px; }
.ai-switch-row small { margin-top: 3px; color: var(--muted); font-size: 10px; }
.ai-switch-row input { position: relative; width: 38px; height: 22px; flex: 0 0 auto; margin: 0; border: 0; border-radius: 999px; background: #c7cdd5; appearance: none; cursor: pointer; }
.ai-switch-row input::after { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(20, 24, 36, .25); content: ""; transition: transform .18s; }
.ai-switch-row input:checked { background: #607b96; }
.ai-switch-row input:checked::after { transform: translateX(16px); }
.ai-settings-actions { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 8px; padding-top: 4px; }

.import-dialog { width: min(540px, calc(100vw - 28px)); padding: 27px 28px 25px; }
.import-heading { display: grid; grid-template-columns: 42px 1fr; align-items: center; gap: 13px; padding-right: 32px; margin-bottom: 22px; }
.import-mark { display: grid; width: 42px; height: 42px; place-items: center; border-radius: 11px; color: #287f77; background: #eaf7f5; font-family: "Noto Serif SC", "Songti SC", SimSun, serif; font-size: 19px; font-weight: 800; }
.import-heading h2 { margin: 0; font-size: 19px; letter-spacing: -.02em; }
.import-heading p { margin: 4px 0 0; color: var(--muted); font-size: 11px; line-height: 1.55; }
.import-form { display: grid; gap: 10px; }
.import-field { display: grid; gap: 7px; color: var(--sub); font-size: 12px; font-weight: 750; }
.import-field textarea {
  width: 100%;
  min-height: 158px;
  margin: 0;
  padding: 13px 14px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--ink);
  background: #fff;
  font-family: "Noto Serif SC", "Songti SC", SimSun, serif;
  font-size: 22px;
  line-height: 1.65;
}
#importCharacters:focus, #importCharacters:focus-visible { outline: none; box-shadow: none; }
.import-field textarea[aria-invalid="true"] { border-color: #d47b70; box-shadow: 0 0 0 3px rgba(189, 76, 63, .08); }
.import-meta { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; color: var(--muted); line-height: 1.45; }
.import-count { flex: 0 0 auto; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-weight: 750; }
.import-count.invalid, .import-error { color: var(--danger); }
.import-error { min-height: 18px; margin: 0; font-size: 11px; }
.import-submit { width: 100%; margin-top: 2px; }

.study-dialog { text-align: center; }
.study-dialog #studyBody { display: flex; flex-direction: column; align-items: center; }
.study-character { font-size: clamp(50px, 10vw, 70px); }
.study-pinyin-button { display: inline-flex; align-items: center; gap: 8px; margin-top: 12px; padding: 7px 12px; border: 1px solid transparent; border-radius: 999px; color: var(--sub); background: transparent; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
.study-pinyin-button:hover { border-color: #dbe4ec; background: #f5f8fb; }
.meaning-reveal {
  position: relative;
  width: 100%;
  min-height: 126px;
  margin: 28px 0 23px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--soft);
  cursor: pointer;
  outline: none;
}
.study-meaning { display: grid; min-height: 124px; padding: 20px; place-items: center; font-family: Georgia, serif; font-size: 14px; line-height: 1.75; }
.meaning-cover {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  color: #718096;
  background: rgba(241, 244, 247, .7);
  backdrop-filter: blur(14px);
  font-size: 11px;
  font-weight: 700;
  transition: opacity .2s, visibility .2s, backdrop-filter .2s;
}
.meaning-reveal:hover .meaning-cover, .meaning-reveal:focus .meaning-cover, .meaning-reveal.revealed .meaning-cover {
  visibility: hidden;
  opacity: 0;
  backdrop-filter: blur(0);
}
.study-next { width: 100%; }

.spelling-game-fallback {
  display: grid;
  min-height: 300px;
  place-items: center;
  color: var(--danger);
  font-size: 12px;
}
.spelling-header { display: flex; align-items: center; justify-content: space-between; margin: -12px 0 0; }
.spelling-prompt { text-align: center; }
.spelling-character { padding-top: 10px; font-family: "Noto Serif SC", "Songti SC", SimSun, serif; font-size: 50px; font-weight: 700; line-height: 1.1; }
.spelling-meaning { min-height: 44px; margin: 15px auto 28px; color: #5e6875; font-family: Georgia, serif; font-size: 14px; line-height: 1.55; }
.spelling-field { display: block; }
.spelling-field > span { display: block; margin-bottom: 8px; color: var(--muted); font-size: 9px; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }
.spelling-input {
  width: 100%;
  height: 52px;
  padding: 0 15px;
  border: 1px solid #cfd6dd;
  border-radius: 8px;
  color: var(--ink);
  background: white;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 18px;
  text-align: center;
}
.spelling-input:focus, .spelling-input:focus-visible { outline: none; box-shadow: none; }
.spelling-input::placeholder { font-size: 12px; }
.spelling-input.correct { border-color: #72aa88; color: var(--success); background: #f2faf5; box-shadow: 0 0 0 3px rgba(46, 128, 81, .08); }
.spelling-input.error { border-color: #d47b70; color: var(--danger); background: #fff6f5; animation: shake .22s linear; }
.spelling-hint { margin: 9px 0 0; color: #9ba2aa; font-size: 9px; text-align: center; }
.spelling-answer { min-height: 21px; margin: 12px 0 0; color: var(--success); font-family: Georgia, serif; font-size: 12px; font-style: italic; text-align: center; }
.spelling-tools { display: flex; justify-content: space-between; margin-top: 18px; padding-top: 13px; border-top: 1px solid var(--line); }
.text-button { padding: 4px 0; border: 0; color: var(--muted); background: transparent; font-size: 10px; font-weight: 700; text-decoration: underline; text-decoration-color: #c8cdd3; text-underline-offset: 4px; }
.text-button:hover { color: var(--primary); }
.complete-card { padding: 12px 0 4px; text-align: center; }
.spelling-dialog.spelling-focus-mode #spellingBody.spelling-complete-body {
  grid-template-rows: minmax(0, 1fr);
  place-items: center;
}
.spelling-complete-body .complete-card { width: 100%; }
.complete-mark { display: grid; width: 64px; height: 64px; margin: 0 auto 20px; place-items: center; border-radius: 50%; color: white; background: var(--success); font-size: 28px; }
.complete-card h2 { margin: 0; font-size: 28px; letter-spacing: -.03em; }
.complete-card p { margin: 10px 0 24px; color: var(--muted); font-family: Georgia, serif; font-size: 13px; }
.complete-card .button { min-width: 160px; }

/* Keep the pinyin practice UI structurally identical to wordtable.ejs. */
.spelling-dialog:not(.spelling-focus-mode) {
  width: min(560px, calc(100vw - 28px));
  max-width: 560px;
  height: calc(100dvh - 24px);
  max-height: none;
  padding: 22px 24px 24px;
  overflow: hidden;
  border-radius: 18px;
}
.spelling-battle-controls .spelling-meaning {
  display: grid;
  height: 52px;
  min-height: 52px;
  margin: 0;
  padding: 14px 18px;
  place-items: center;
  border-color: #dfe5eb;
  color: var(--ink);
  background: #f5f7f9;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.65;
  text-align: center;
}
.spelling-battle-controls .spelling-meaning span {
  display: block;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.spelling-battle-controls .spelling-field { display: grid; gap: 9px; margin-top: 12px; }
.spelling-battle-controls .spelling-field > span { margin-bottom: 0; }
.spelling-enemy-dialog {
  width: min(430px, calc(100vw - 32px));
  padding: 28px;
}
.spelling-enemy-dialog .button {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  padding: 8px 15px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 750;
  line-height: 1.2;
}
.spelling-enemy-dialog .button.primary { border-color: var(--ink); color: #fff; background: var(--ink); }
.spelling-enemy-dialog .button.primary:hover:not(:disabled) { background: #303047; transform: translateY(-1px); }
.spelling-enemy-dialog .button.secondary { border-color: var(--line); color: var(--ink); background: #fff; }
.spelling-enemy-dialog .button.secondary:hover:not(:disabled) { border-color: #bcc6d2; background: var(--soft); }
.spelling-enemy-dialog .button.ghost { border-color: transparent; color: var(--muted); background: transparent; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 20;
  max-width: min(340px, calc(100vw - 32px));
  padding: 11px 14px;
  border-radius: 8px;
  color: white;
  background: var(--primary);
  box-shadow: 0 12px 35px rgba(24, 35, 47, .22);
  font-size: 11px;
  transform: translate(-50%, 18px);
  visibility: hidden;
  opacity: 0;
  transition: opacity .18s, transform .18s, visibility .18s;
}
.toast.show { visibility: visible; opacity: 1; transform: translate(-50%, 0); }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

@keyframes pulse { from { transform: scale(.92); } to { transform: scale(1.1); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 30% { transform: translateX(-5px); } 70% { transform: translateX(5px); } }

@media (max-width: 680px) {
  .header-inner, .page-shell { width: calc(100% - 22px); }
  .brand small { display: none; }
  .header-inner nav { gap: 16px; }
  .page-shell { padding-top: 25px; }
  .table-heading { align-items: stretch; flex-direction: column; }
  .table-toolbar { gap: 9px; padding: 9px; }
  .table-actions {
    display: grid;
    width: 100%;
    grid-template-columns: .85fr 1.35fr .95fr;
    gap: 7px;
  }
  .table-title { width: 100%; justify-content: flex-start; text-align: left; }
  .table-actions .button {
    min-width: 0;
    gap: 6px;
    padding: 8px;
    font-size: 11px;
    white-space: nowrap;
  }
  .table-actions .action-count { min-width: 18px; height: 18px; padding: 0 5px; font-size: 9px; }
  .book-picker { flex: 1; }
  .book-select { width: 100%; }
  .pagination-bar { grid-template-columns: 1fr auto; }
  .page-jump { display: none; }
  .table-summary { gap: 10px 18px; }
  .dialog:not(.spelling-dialog) { padding: 31px 21px 23px; }
  .ai-settings-dialog { padding: 24px 20px 21px; }
  .import-dialog { padding: 24px 20px 21px; }
  .import-meta { align-items: flex-end; }
  .ai-settings-actions { grid-template-columns: auto 1fr; }
  .ai-settings-actions > span { display: none; }
  .ai-settings-actions .button.primary { grid-column: 2; grid-row: 2; }
  .ai-settings-actions .button.secondary { grid-column: 1; grid-row: 2; }
  .ai-settings-actions .button.ghost { grid-column: 1 / -1; justify-self: start; }
}

@media (max-width: 520px) {
  .spelling-dialog:not(.spelling-focus-mode) {
    width: calc(100vw - 16px);
    max-width: none;
    height: calc(100dvh - 12px);
    padding: 18px 14px 16px;
    border-radius: 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}
.spelling-dialog .dialog-close,
.spelling-enemy-dialog .dialog-close {
  top: 10px;
  right: 8px;
  z-index: 8;
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  padding: 0;
  border: 0;
  background: transparent;
}

.spelling-dialog .dialog-close svg,
.spelling-enemy-dialog .dialog-close svg {
  width: 13px;
  height: 13px;
  pointer-events: none;
}

.spelling-dialog .dialog-close:hover,
.spelling-enemy-dialog .dialog-close:hover {
  color: var(--ink);
  background: #e7ebef;
}
