/* ==========================================================================
   國語子系統 — 共用樣式
   ========================================================================== */

/* ---- Profile 切換器（右上角） ---- */
.profile-switcher {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 14px;
  cursor: pointer;
}
.profile-switcher:hover { background: rgba(255,255,255,0.25); }
.profile-switcher .arrow { font-size: 10px; opacity: 0.8; }

.profile-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: #fff;
  color: #1f2937;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  min-width: 180px;
  padding: 4px 0;
  z-index: 100;
}
.profile-menu.is-hidden { display: none; }
.profile-menu button {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  padding: 10px 16px;
  font-size: 15px;
  color: #1f2937;
}
.profile-menu button:hover { background: #f3f4f6; }
.profile-menu button.is-active { background: #dbeafe; font-weight: 600; }
.profile-menu .divider { border-top: 1px solid #e5e7eb; margin: 4px 0; }

/* ---- Profile 選擇 modal（第一次進入） ---- */
.profile-modal-bg {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.profile-modal {
  background: #fff; border-radius: 16px; padding: 32px;
  max-width: 400px; width: 90%; text-align: center;
}
.profile-modal h2 { margin: 0 0 16px; }
.profile-modal .options { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.profile-modal button {
  padding: 16px 32px; font-size: 18px; border-radius: 12px;
  border: 2px solid #2563eb; background: #fff; color: #2563eb;
  font-weight: 600;
}
.profile-modal button:hover { background: #2563eb; color: #fff; }

/* ---- 同步狀態橫條 ---- */
.sync-banner {
  position: fixed; top: 0; left: 0; right: 0;
  background: #dc2626; color: #fff;
  padding: 8px 16px; text-align: center;
  font-size: 14px; z-index: 500;
  display: none;
}
.sync-banner.is-visible { display: block; }
.sync-banner button {
  margin-left: 12px; background: #fff; color: #dc2626;
  border: none; border-radius: 4px; padding: 4px 10px;
  font-size: 13px; font-weight: 600;
}

/* ---- 國語列表頁 ---- */
.chinese-list-container { max-width: 980px; margin: 0 auto; padding: 24px; }
.chinese-list-toolbar {
  display: flex; gap: 12px; flex-wrap: wrap;
  margin-bottom: 16px; align-items: center;
}
.chinese-list-toolbar select {
  padding: 8px 12px; font-size: 14px;
  border: 1px solid #d1d5db; border-radius: 6px;
}
.chinese-list-toolbar .quiz-btn {
  margin-left: auto; background: #2563eb; color: #fff;
  border: none; padding: 10px 20px; border-radius: 8px;
  font-size: 16px; font-weight: 600;
}
.chinese-list-toolbar .quiz-btn:hover { background: #1d4ed8; }

.idiom-row {
  background: #fff; border: 1px solid #e5e7eb; border-radius: 8px;
  padding: 16px; margin-bottom: 8px;
  display: grid; grid-template-columns: auto 1fr auto; gap: 16px;
  align-items: center; cursor: pointer;
}
.idiom-row:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.06); }
.idiom-row .status-icon { font-size: 24px; }
.idiom-row .term { font-size: 20px; font-weight: 700; }
.idiom-row .pinyin { font-size: 13px; color: #6b7280; margin-left: 8px; }
.idiom-row .meaning { color: #4b5563; font-size: 14px; margin-top: 4px; }
.idiom-row .actions { display: flex; gap: 8px; }
.idiom-row .actions button {
  padding: 6px 12px; font-size: 13px; border-radius: 6px;
  border: 1px solid #d1d5db; background: #fff;
}
.idiom-row .actions .btn-up { color: #16a34a; border-color: #86efac; }
.idiom-row .actions .btn-up:hover { background: #f0fdf4; }
.idiom-row .actions .btn-down { color: #dc2626; border-color: #fca5a5; }
.idiom-row .actions .btn-down:hover { background: #fef2f2; }

.idiom-detail {
  grid-column: 1 / -1; background: #f9fafb;
  border-top: 1px solid #e5e7eb; margin-top: 12px; padding-top: 12px;
  font-size: 14px;
}
.idiom-detail .detail-block { margin-bottom: 12px; }
.idiom-detail .section-label {
  font-weight: 700; color: #1e3a8a; font-size: 13px;
  margin-bottom: 4px; letter-spacing: 0.5px;
}
.idiom-detail .example {
  font-style: italic; color: #4b5563;
  padding: 4px 0 4px 12px; border-left: 3px solid #e5e7eb;
  margin-bottom: 4px;
}
.idiom-detail .origin-text {
  background: #fffbeb; border-left: 3px solid #f59e0b;
  padding: 8px 12px; line-height: 1.7; color: #1f2937;
  white-space: pre-wrap;
}
.idiom-detail .related-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.idiom-detail .related-tag {
  display: inline-block; padding: 4px 10px;
  border-radius: 999px; font-size: 13px; font-weight: 500;
}
.idiom-detail .related-tag--similar {
  background: #dcfce7; color: #166534; border: 1px solid #86efac;
}
.idiom-detail .related-tag--opposite {
  background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5;
}
.idiom-detail .meta { color: #6b7280; margin-top: 8px; font-size: 12px; }
.idiom-detail img { max-width: 240px; border-radius: 8px; margin-top: 8px; }

/* 手機：actions 改放下方一整列，避免擠壓中間欄（成語/改錯字/破音字共用） */
@media (max-width: 767px) {
  .chinese-list-container { padding: 16px; }
  .idiom-row {
    grid-template-columns: auto 1fr;
    gap: 12px;
  }
  .idiom-row .actions {
    grid-column: 1 / -1;
    justify-content: flex-end;
    margin-top: 8px;
  }
}

/* ---- 抽考頁 ---- */
.quiz-container { max-width: 760px; margin: 0 auto; padding: 24px; }
.quiz-candidates {
  display: flex; gap: 8px; flex-wrap: wrap;
  background: #fef3c7; padding: 16px; border-radius: 12px;
  margin-bottom: 24px;
}
.quiz-candidate {
  background: #fff; border: 2px solid #f59e0b;
  border-radius: 8px; padding: 8px 16px;
  font-size: 18px; font-weight: 600; cursor: pointer;
  user-select: none;
}
.quiz-candidate.is-used { opacity: 0.3; pointer-events: none; }

.quiz-question {
  background: #fff; border: 1px solid #e5e7eb;
  border-radius: 8px; padding: 16px; margin-bottom: 12px;
  font-size: 18px; line-height: 2;
}
.quiz-blank {
  display: inline-block; min-width: 80px; padding: 2px 12px;
  border: 2px dashed #9ca3af; border-radius: 6px;
  text-align: center; cursor: pointer;
}
.quiz-blank.is-filled { border-style: solid; border-color: #2563eb; background: #dbeafe; }
.quiz-blank.is-correct { border-color: #16a34a; background: #f0fdf4; }
.quiz-blank.is-wrong { border-color: #dc2626; background: #fef2f2; }

.quiz-question .meaning-after {
  display: block; font-size: 14px; color: #6b7280;
  border-top: 1px dashed #e5e7eb; margin-top: 8px; padding-top: 8px;
}

.quiz-submit, .quiz-mark-wrong {
  display: block; margin: 24px auto;
  padding: 12px 32px; font-size: 18px;
  background: #2563eb; color: #fff; border: none;
  border-radius: 8px; font-weight: 600;
}
.quiz-submit:hover, .quiz-mark-wrong:hover { background: #1d4ed8; }

/* ==========================================================================
   改錯字抽考
   ========================================================================== */

.wc-question {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 16px;
  font-size: 20px;
  line-height: 1.9;
}
.wc-sentence {
  margin-bottom: 12px;
}
.wc-char {
  display: inline-block;
  padding: 2px 4px;
  margin: 0 1px;
  cursor: pointer;
  border-radius: 4px;
  border: 2px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}
.wc-char:hover { background: #fef3c7; }
.wc-char.is-picked { border-color: #f59e0b; background: #fef3c7; }
.wc-char.is-correct { border-color: #16a34a; background: #d1fae5; }
.wc-char.is-wrong { border-color: #dc2626; background: #fee2e2; }
.wc-char.is-locked { cursor: default; }
.wc-char.is-locked:hover { background: transparent; }
.wc-char.is-locked.is-picked { background: #fef3c7; }
.wc-char.is-locked.is-correct { background: #d1fae5; }
.wc-char.is-locked.is-wrong { background: #fee2e2; }

.wc-noerror-btn {
  display: inline-block;
  padding: 6px 14px;
  font-size: 14px;
  background: #f3f4f6;
  border: 2px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  margin-left: 8px;
}
.wc-noerror-btn.is-picked { border-color: #f59e0b; background: #fef3c7; }
.wc-noerror-btn.is-correct { border-color: #16a34a; background: #d1fae5; }
.wc-noerror-btn.is-wrong { border-color: #dc2626; background: #fee2e2; }

.wc-feedback {
  margin-top: 8px;
  font-size: 15px;
  color: #6b7280;
}

/* ==========================================================================
   範圍選擇器 modal
   ========================================================================== */

.scope-modal-bg {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.scope-modal {
  background: #fff; border-radius: 12px; padding: 24px;
  width: 460px; max-width: 92%;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.scope-modal h2 { margin: 0 0 16px; font-size: 18px; }
.scope-mode {
  display: block;
  padding: 10px 12px;
  margin-bottom: 6px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  cursor: pointer;
}
.scope-mode.is-active { border-color: #2563eb; background: #eff6ff; }
.scope-mode > input[type="radio"] { margin-right: 8px; }
.scope-mode .controls {
  display: none;
  margin-top: 8px;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}
.scope-mode.is-active .controls { display: flex; }
.scope-mode select {
  padding: 4px 8px; font-size: 14px;
  border: 1px solid #d1d5db; border-radius: 6px; background: #fff;
}
.scope-modal .actions {
  display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px;
}
.scope-modal .actions button {
  padding: 8px 18px; font-size: 15px; border-radius: 8px; border: none; cursor: pointer;
}
.scope-modal .btn-cancel { background: #f3f4f6; color: #1f2937; }
.scope-modal .btn-go { background: #2563eb; color: #fff; font-weight: 600; }
.scope-modal .btn-go:disabled { background: #9ca3af; cursor: not-allowed; }
.scope-modal .warning { color: #dc2626; font-size: 13px; margin-top: 8px; }

/* 破音字專用 */
.hetero-char {
  font-size: 32px;
  font-weight: 700;
  color: #1e3a8a;
}
.hetero-char-inline {
  font-size: 20px;
  font-weight: 700;
  color: #1e3a8a;
  margin-right: 8px;
}
.hetero-bopomofo {
  font-size: 18px;
  color: #b91c1c;
  font-weight: 600;
  letter-spacing: 1px;
}
.hetero-sense { margin: 6px 0 12px; padding-left: 8px; border-left: 3px solid #93c5fd; }
.hetero-sense-head {
  font-size: 14px;
  color: #1f2937;
  font-weight: 600;
  margin-bottom: 4px;
}
.hetero-sense .related-tags { margin: 4px 0; }
.hetero-sense .example {
  font-size: 14px;
  color: #4b5563;
  margin: 2px 0 2px 8px;
}
.hetero-sense .example b { color: #1e3a8a; }

/* 破音字 ruby 注音 */
.hetero-ruby {
  font-size: 26px;
  ruby-align: center;
}
.hetero-ruby rb { font-weight: 700; color: #1e3a8a; }
.hetero-ruby rt {
  font-size: 14px;
  color: #b91c1c;
  font-weight: 600;
  letter-spacing: 0.5px;
}

/* 破音字抽考 */
.hq-question {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 16px 18px;
  margin-bottom: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.hq-num { font-size: 13px; color: #6b7280; margin-bottom: 6px; }
.hq-prompt { font-size: 16px; color: #1f2937; margin-bottom: 8px; }
.hq-target-inline {
  display: inline-block;
  background: #fef3c7;
  border: 1px solid #fbbf24;
  padding: 0 4px;
  border-radius: 4px;
  font-weight: 700;
  color: #92400e;
}
.hq-sentence {
  font-size: 20px;
  line-height: 1.8;
  color: #111827;
  margin: 8px 0;
  padding: 8px 12px;
  background: #f9fafb;
  border-radius: 6px;
}
.hq-sentence .hq-target {
  background: #fef3c7;
  border: 1px solid #fbbf24;
  border-radius: 4px;
  padding: 0 4px;
  margin: 0 1px;
  color: #92400e;
  font-weight: 700;
}
.hq-word { font-size: 13px; color: #6b7280; margin-bottom: 12px; }
.hq-options {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.hq-opt {
  padding: 12px 14px;
  font-size: 18px;
  background: #fff;
  border: 2px solid #d1d5db;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  color: #1f2937;
  letter-spacing: 1px;
  transition: all 0.15s;
}
.hq-opt:hover:not(.is-locked) { border-color: #2563eb; background: #eff6ff; }
.hq-opt.is-picked { border-color: #2563eb; background: #dbeafe; }
.hq-opt.is-locked { cursor: not-allowed; }
.hq-opt.is-correct { border-color: #16a34a; background: #dcfce7; color: #166534; }
.hq-opt.is-wrong   { border-color: #dc2626; background: #fee2e2; color: #991b1b; }
.hq-feedback {
  margin-top: 10px;
  padding: 10px 12px;
  background: #f3f4f6;
  border-radius: 6px;
  font-size: 14px;
  color: #374151;
}

/* 點擊回饋 — 我會了 / 還不熟 按鈕短閃 */
.idiom-row .actions button { transition: all 0.15s ease; }
.idiom-row .actions .btn-up.btn-flash {
  background: #16a34a !important;
  border-color: #16a34a !important;
  color: #fff !important;
  transform: scale(1.08);
  box-shadow: 0 0 0 4px rgba(22,163,74,0.2);
}
.idiom-row .actions .btn-down.btn-flash {
  background: #dc2626 !important;
  border-color: #dc2626 !important;
  color: #fff !important;
  transform: scale(1.08);
  box-shadow: 0 0 0 4px rgba(220,38,38,0.2);
}

/* 底部 toast — 狀態變更確認 */
.cli-toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #1f2937;
  color: #fff;
  padding: 12px 22px;
  border-radius: 999px;
  font-size: 16px;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  opacity: 0;
  pointer-events: none;
  z-index: 9999;
  transition: opacity 0.2s ease, transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: flex; align-items: center; gap: 8px;
}
.cli-toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}
.cli-toast[data-dir="up"]   { background: #16a34a; }
.cli-toast[data-dir="down"] { background: #dc2626; }
.cli-toast .cli-toast-icon { font-size: 20px; }

/* 狀態 icon 切換時稍微彈一下 */
.status-icon {
  display: inline-block;
  transition: transform 0.2s;
}

/* ========== 抽考頁工具列（螢幕顯示） ========== */
.quiz-toolbar {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 16px; padding: 10px 14px;
  background: #f0f9ff; border: 1px solid #bae6fd;
  border-radius: 8px;
}
.quiz-toolbar .quiz-print {
  padding: 8px 16px; font-size: 15px; font-weight: 600;
  background: #0284c7; color: #fff; border: none;
  border-radius: 6px; cursor: pointer;
}
.quiz-toolbar .quiz-print:hover { background: #0369a1; }
.quiz-toolbar .quiz-print-hint { font-size: 13px; color: #475569; }

/* 列印時的標頭（螢幕隱藏） */
.print-header { display: none; }

/* 抽考範圍 modal — 題數選擇 */
.scope-count-row {
  margin-top: 12px; padding-top: 12px;
  border-top: 1px dashed #d1d5db;
}
.scope-count-row label { font-size: 15px; color: #1f2937; }
.scope-count-row select {
  margin-left: 8px; padding: 4px 10px; font-size: 15px;
  border: 1px solid #d1d5db; border-radius: 6px; background: #fff;
}

/* ========== 列印樣式 ========== */
@media print {
  /* 全頁基準：16px、行距窄、字距正常、白底黑字 */
  @page { margin: 12mm 14mm; }
  html, body {
    background: #fff !important; color: #000 !important;
    font-size: 16px !important;
    line-height: 1.3 !important;
    letter-spacing: normal !important;
  }

  /* 隱藏所有非考卷元素 */
  .site-header, .quiz-toolbar, .quiz-submit,
  .cli-toast, .sync-banner,
  .hq-feedback, .wc-feedback,
  .actions, .meaning-after,
  #profile-mount {
    display: none !important;
  }
  .quiz-container { padding: 0 !important; max-width: 100% !important; margin: 0 !important; }

  /* 列印標頭 */
  .print-header {
    display: block !important;
    border-bottom: 1.5px solid #000;
    padding-bottom: 6px;
    margin-bottom: 10px;
  }
  .print-title { font-size: 18px; font-weight: 700; margin-bottom: 2px; }
  .print-instruction { font-size: 13px; margin: 2px 0; color: #333; }
  .print-meta { font-size: 13px; margin-top: 4px; }

  /* ==== 破音字題目（緊湊：題號+句子+例詞同行；選項另一行） ==== */
  body { counter-reset: hq-counter wc-counter qz-counter; }
  .hq-question {
    counter-increment: hq-counter;
    page-break-inside: avoid;
    border: none !important; box-shadow: none !important;
    padding: 0 !important; margin: 0 0 6px 0 !important;
  }
  .hq-num, .hq-prompt { display: none !important; }
  .hq-sentence {
    display: inline !important;
    background: #fff !important;
    padding: 0 !important; margin: 0 !important;
    font-size: 16px !important;
    line-height: 1.3 !important;
  }
  .hq-sentence::before {
    content: counter(hq-counter) ". ";
    font-weight: 700;
  }
  .hq-sentence .hq-target {
    background: #fff !important; border: none !important;
    color: #000 !important; font-weight: 700;
    padding: 0 !important;
  }
  .hq-sentence .hq-target::before { content: "「"; }
  .hq-sentence .hq-target::after  { content: "」"; }
  .hq-word {
    display: inline !important;
    font-size: 13px !important; color: #555 !important;
    margin: 0 0 0 6px !important;
  }
  .hq-options {
    display: flex !important;
    grid-template-columns: none !important;
    gap: 14px !important;
    margin: 1px 0 0 18px !important;
    flex-wrap: wrap;
  }
  .hq-opt {
    background: transparent !important; border: none !important;
    color: #000 !important; box-shadow: none !important;
    padding: 0 !important; margin: 0 !important;
    font-size: 16px !important; font-weight: 500 !important;
    letter-spacing: 0 !important;
  }
  .hq-opt::before { content: "○ "; font-size: 14px; }

  /* ==== 改錯字題目 ==== */
  .wc-question {
    counter-increment: wc-counter;
    page-break-inside: avoid;
    margin: 0 0 6px 0 !important;
  }
  .wc-sentence {
    font-size: 16px !important;
    background: #fff !important;
    line-height: 1.4 !important;
    padding: 0 !important; margin: 0 !important;
  }
  .wc-sentence::before {
    content: counter(wc-counter) ". ";
    font-weight: 700;
  }
  .wc-char { background: #fff !important; padding: 0 !important; }
  .wc-noerror-btn {
    display: inline-block !important;
    border: 1px solid #555 !important;
    background: #fff !important; color: #000 !important;
    padding: 1px 8px !important;
    font-size: 13px !important;
    margin-left: 8px !important;
  }

  /* ==== 成語題目 ==== */
  .quiz-candidates {
    border: 1px solid #555; padding: 6px 8px;
    margin: 0 0 8px 0 !important;
    display: flex !important; flex-wrap: wrap; gap: 6px;
  }
  .quiz-candidate {
    background: #fff !important; border: 1px solid #555 !important;
    color: #000 !important; font-size: 15px !important;
    padding: 2px 8px !important;
  }
  .quiz-question {
    counter-increment: qz-counter;
    page-break-inside: avoid;
    margin: 0 0 6px 0 !important;
    font-size: 16px !important;
    line-height: 1.4 !important;
  }
  .quiz-question::before {
    content: counter(qz-counter) ". ";
    font-weight: 700;
  }
  .quiz-blank {
    border-bottom: 1.5px solid #000; min-width: 70px;
    display: inline-block; padding: 0 4px;
  }
}

/* ==========================================================================
   編輯模式 — 鎖按鈕 + 編輯按鈕
   ========================================================================== */

/* toolbar 中的編輯模式鎖按鈕 */
.chinese-list-toolbar .lock-btn {
  padding: 8px 12px;
  font-size: 14px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #f9fafb;
  color: #4b5563;
  cursor: pointer;
}
.chinese-list-toolbar .lock-btn:hover { background: #f3f4f6; }
body.edit-unlocked .chinese-list-toolbar .lock-btn {
  background: #fef3c7;
  border-color: #f59e0b;
  color: #92400e;
  font-weight: 600;
}

/* row 內的編輯按鈕 — 預設隱藏，解鎖後顯示 */
.idiom-row .edit-btn {
  display: none;
  margin-left: 8px;
  padding: 6px 10px;
  font-size: 16px;
  background: #fef3c7;
  border: 1px solid #f59e0b;
  border-radius: 6px;
  cursor: pointer;
  align-self: flex-start;
}
.idiom-row .edit-btn:hover { background: #fde68a; }
body.edit-unlocked .idiom-row .edit-btn { display: inline-block; }

/* ==========================================================================
   編輯 Modal — 共用樣式（成語 / 改錯字 / 破音字 各 editor 共用）
   ========================================================================== */
.edit-modal-bg {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1100;
  padding: 16px;
}
.edit-modal {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.edit-modal-head {
  padding: 16px 20px;
  border-bottom: 1px solid #e5e7eb;
  background: #f9fafb;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.edit-modal-head h2 {
  margin: 0;
  font-size: 18px;
  color: #1f2937;
}
.edit-modal-head .close-btn {
  background: none; border: none;
  font-size: 22px; cursor: pointer; color: #6b7280;
  padding: 0 4px;
}
.edit-modal-body {
  padding: 16px 20px;
  overflow-y: auto;
  flex: 1;
}
.edit-modal-foot {
  padding: 12px 20px;
  border-top: 1px solid #e5e7eb;
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  background: #f9fafb;
}
.edit-modal-foot button {
  padding: 8px 18px;
  font-size: 15px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
}
.edit-modal-foot .btn-cancel {
  background: #fff;
  border: 1px solid #d1d5db;
  color: #4b5563;
}
.edit-modal-foot .btn-save {
  background: #2563eb;
  border: 1px solid #2563eb;
  color: #fff;
}
.edit-modal-foot .btn-save:disabled {
  background: #9ca3af; border-color: #9ca3af; cursor: wait;
}

/* 表單欄位 */
.edit-field {
  margin-bottom: 14px;
}
.edit-field-label {
  font-size: 13px;
  color: #4b5563;
  font-weight: 600;
  margin-bottom: 4px;
}
.edit-field-label .req { color: #dc2626; margin-left: 4px; }
.edit-field-hint {
  font-size: 12px;
  color: #9ca3af;
  margin-top: 2px;
}
.edit-field input[type="text"],
.edit-field input[type="number"],
.edit-field select,
.edit-field textarea {
  width: 100%;
  padding: 8px 10px;
  font-size: 14px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-family: inherit;
  box-sizing: border-box;
}
.edit-field textarea { min-height: 60px; resize: vertical; }
.edit-field input[readonly],
.edit-field input:disabled {
  background: #f3f4f6;
  color: #6b7280;
}

/* meta（grade/sem/lesson/publisher）一排顯示 */
.edit-field-row {
  display: flex; gap: 12px; flex-wrap: wrap;
}
.edit-field-row .edit-field { flex: 1; min-width: 120px; margin-bottom: 0; }

/* 動態陣列：每行 input + 刪除按鈕 */
.edit-array { border: 1px solid #e5e7eb; border-radius: 6px; padding: 8px; background: #fafafa; }
.edit-array-row {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
  align-items: flex-start;
}
.edit-array-row:last-child { margin-bottom: 0; }
.edit-array-row input,
.edit-array-row textarea {
  flex: 1;
  padding: 6px 8px;
  font-size: 14px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  font-family: inherit;
}
.edit-array-row textarea { min-height: 36px; resize: vertical; }
.edit-array-row .btn-del {
  background: #fef2f2;
  border: 1px solid #fca5a5;
  color: #dc2626;
  padding: 0 8px;
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
  flex-shrink: 0;
}
.edit-array-row .btn-del:hover { background: #fecaca; }
.edit-array-add {
  background: #eff6ff;
  border: 1px dashed #93c5fd;
  color: #2563eb;
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  margin-top: 4px;
  width: 100%;
}
.edit-array-add:hover { background: #dbeafe; }

/* 警告／訊息 */
.edit-banner {
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 12px;
}
.edit-banner.is-info { background: #eff6ff; color: #1e40af; border: 1px solid #93c5fd; }
.edit-banner.is-error { background: #fef2f2; color: #991b1b; border: 1px solid #fca5a5; }

/* 巢狀 group（破音字 readings/senses 用） */
.edit-group {
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
  background: #fafafa;
}
.edit-group-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
  font-weight: 600;
  color: #374151;
  font-size: 14px;
}
.edit-group .edit-group {
  background: #fff;
}

/* 改錯字句子預覽：點字標紅 */
.wc-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px;
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  min-height: 36px;
  font-size: 18px;
  line-height: 1.6;
  color: #1f2937;
}
.wc-preview:empty::before {
  content: '（請先輸入句子）';
  color: #9ca3af;
  font-size: 14px;
}
.wc-char {
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid transparent;
  transition: background 0.1s;
}
.wc-char:hover {
  background: #f3f4f6;
  border-color: #d1d5db;
}
.wc-char.is-wrong {
  background: #fee2e2;
  color: #dc2626;
  border-color: #dc2626;
  font-weight: 700;
}

/* ==========================================================================
   詩 — 單頁版型 + 索引頁
   ========================================================================== */

/* ---- 詩單頁 ---- */
.poem-page {
  max-width: 760px;
  margin: 0 auto;
  padding: 24px 20px 80px;
}
.poem-head {
  text-align: center;
  margin: 8px 0 24px;
}
.poem-title {
  font-size: 36px;
  font-weight: 700;
  letter-spacing: 4px;
  margin: 0 0 4px;
  color: #1f2937;
}
.poem-byline {
  font-size: 16px;
  color: #6b7280;
  margin: 0;
  letter-spacing: 2px;
}

.poem-figure {
  margin: 0 0 24px;
  text-align: center;
}
.poem-figure img {
  max-width: 100%;
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  cursor: zoom-in;
}

/* 直書原文 */
.poem-original-wrap {
  display: flex;
  justify-content: center;
  margin: 24px 0 32px;
  padding: 24px 16px;
  background: #fffaf2;
  border: 1px solid #f5e9d4;
  border-radius: 12px;
  overflow-x: auto;
}
.poem-original {
  writing-mode: vertical-rl;
  text-orientation: upright;
  font-family: "Noto Serif TC", "Source Han Serif TC", "PMingLiU", "新細明體", serif;
  font-size: 30px;
  line-height: 2.4;
  letter-spacing: 0.2em;
  color: #1f2937;
  max-height: 420px;
}
.poem-original p {
  margin: 0 18px 0 0;
  padding: 0;
}

/* 行動裝置：< 768px 退化為橫書避免太擠 */
@media (max-width: 767px) {
  .poem-original {
    writing-mode: horizontal-tb;
    text-orientation: mixed;
    font-size: 22px;
    line-height: 1.9;
    text-align: center;
    max-height: none;
  }
  .poem-original p {
    margin: 0 0 8px 0;
  }
}

/* 詩本文 ruby 注音（直書） */
.poem-original ruby {
  /* 注音排在主字右邊獨立一欄（不擠主字行高），台灣注音標準排版 */
  ruby-position: inter-character;
}
.poem-original ruby rt {
  font-size: 11px;
  color: #b91c1c;
  font-weight: 600;
  letter-spacing: -4px;  /* 直書下這收緊上下間距 */
  line-height: 0.7;
  writing-mode: vertical-rl;
  text-orientation: upright;
}
/* 包住「最後一字+聲調」當錨點：用 inline-block 確保在直書下能正確當 containing block */
.poem-original ruby rt .bpm-last-with-tone {
  position: relative;
  display: inline-block;
}
/* 一二三四聲（ˊˇˋ）絕對定位到「最後一字」的物理右側，無論單/多字都正確 */
.poem-original ruby rt .bpm-tone-side {
  position: absolute;
  top: 50%;          /* 對齊最後一字垂直中央 */
  left: 100%;        /* 落到該字物理右側 */
  transform: translateY(-50%);
  margin-left: -2px;
  writing-mode: horizontal-tb;
  text-orientation: mixed;
  font-size: 0.9em;
  line-height: 1;
}
/* 輕聲（˙）在頂端 */
.poem-original ruby rt .bpm-tone-top {
  display: inline-block;
  margin-bottom: -0.4em;
}

@media (max-width: 767px) {
  /* 手機橫書還原 */
  .poem-original ruby { ruby-position: over; }
  .poem-original ruby rt {
    font-size: 12px;
    writing-mode: horizontal-tb;
    text-orientation: mixed;
  }
  .poem-original ruby rt .bpm-last-with-tone,
  .poem-original ruby rt .bpm-tone-side,
  .poem-original ruby rt .bpm-tone-top {
    position: static;
    display: inline;
    margin: 0;
    writing-mode: horizontal-tb;
    text-orientation: mixed;
    font-size: 1em;
  }
}
body.bopomofo-off .poem-original ruby rt { display: none; }

/* 注音切換按鈕 */
.bopomofo-toggle {
  display: inline-block;
  background: #f3f4f6;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 14px;
  cursor: pointer;
  margin: 0 0 8px;
  user-select: none;
}
.bopomofo-toggle:hover { background: #e5e7eb; }
.bopomofo-toggle[aria-pressed="false"] { background: #fff; color: #6b7280; }

/* 各區塊 */
.poem-section {
  margin: 24px 0;
  padding: 16px 20px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
}
.poem-section h2 {
  margin: 0 0 12px;
  font-size: 18px;
  color: #1e3a8a;
  border-bottom: 1px solid #e5e7eb;
  padding-bottom: 8px;
}
.poem-section p {
  font-size: 16px;
  line-height: 1.9;
  color: #1f2937;
  margin: 0 0 8px;
}

/* 注釋 */
.poem-glossary {
  margin: 0;
}
.poem-glossary dt {
  font-weight: 700;
  color: #1e3a8a;
  margin-top: 8px;
}
.poem-glossary dt:first-child { margin-top: 0; }
.poem-glossary dd {
  margin: 2px 0 0 16px;
  font-size: 15px;
  line-height: 1.7;
  color: #374151;
}

/* 賞析 */
.poem-analysis .analysis-intro {
  font-style: italic;
  color: #4b5563;
  border-left: 3px solid #93c5fd;
  padding-left: 12px;
}
.poem-analysis article {
  margin: 16px 0;
  padding: 12px 16px;
  background: #f9fafb;
  border-radius: 8px;
}
.poem-analysis article h3 {
  margin: 0 0 6px;
  font-size: 15px;
  color: #1e3a8a;
}
.poem-analysis .analysis-summary {
  font-weight: 600;
  color: #1f2937;
  background: #fef3c7;
  border-left: 3px solid #f59e0b;
  padding: 10px 14px;
  margin: 16px 0 0;
  border-radius: 0 8px 8px 0;
}

/* ---- 詩索引頁 ---- */
.poems-index-container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
}
.poems-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
  padding: 12px 14px;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
}
.poems-toolbar input[type="text"],
.poems-toolbar select {
  padding: 6px 10px;
  font-size: 14px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
}
.poems-toolbar input[type="text"] { flex: 1; min-width: 180px; }
.poems-toolbar .poems-stats {
  margin-left: auto;
  font-size: 14px;
  color: #6b7280;
}

.poems-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.poem-card {
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  transition: box-shadow 0.15s, transform 0.15s;
}
.poem-card:hover {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  transform: translateY(-2px);
}
.poem-card .thumb {
  height: 140px;
  background: linear-gradient(135deg, #fde68a 0%, #fbbf24 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
  color: #fff;
}
.poem-card .thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.poem-card .body {
  padding: 12px 14px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.poem-card .title {
  font-size: 18px;
  font-weight: 700;
  color: #1f2937;
  letter-spacing: 1px;
}
.poem-card .meta {
  font-size: 13px;
  color: #6b7280;
}
.poem-card .tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}
.poem-card .tag {
  background: #f3f4f6;
  color: #4b5563;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
}
.poems-empty {
  text-align: center;
  padding: 48px 16px;
  color: #6b7280;
}
