/* ===== POPUP TRA TỪ DÙNG CHUNG (static/js/dict_popup.js, window.JiFishDictPopup) =====
   Dùng ở Ghi chú, Shorts, Bài tập mới và các trang cũ. Bố cục + số đo GIỐNG hộp tra từ của trang
   Đọc PDF mới (css/pages/reader.css, .rd-pop-*; bản vẽ RD_2 / RD_4 / RD_M2) — sửa thì sửa cả hai.
   Tự đủ (không dựa vào .btn/.tag của base.css) vì các trang cũ không nạp base.css; chỉ cần tokens.css. */
.dict-popup {
  position: fixed; z-index: 500; display: flex; flex-direction: column;
  width: min(380px, calc(100vw - 32px)); max-width: none; max-height: 70vh; overflow: hidden; padding: 0;
  border-radius: 10px; border: 1px solid var(--line); background: var(--bg);
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.16);
  font-family: var(--font, inherit); font-size: 14px; line-height: 1.45; color: var(--ink); text-align: left;
  opacity: 0; transform: translateY(8px); transition: opacity 0.2s, transform 0.2s; pointer-events: none;
}
/* display: flex nhắc lại ở .show: css/reading.css (trang cũ) đặt .dict-popup.show { display: block } */
.dict-popup.show { display: flex; opacity: 1; transform: translateY(0); pointer-events: auto; animation: none; }
.dict-popup *, .dict-popup *::before, .dict-popup *::after { box-sizing: border-box; }
.dict-popup p { margin: 0; }
.dict-popup .icon { flex-shrink: 0; }
.dict-popup :lang(ja) { font-family: var(--font-jp); }

/* Đầu (chữ to + cách đọc + nhãn) — đứng yên; thân cuộn; chân (nút) đứng yên. */
.dp-head { display: flex; align-items: flex-start; gap: 8px; flex-shrink: 0; padding: 12px 12px 6px 16px; }
.dp-head.is-row { align-items: center; padding-bottom: 8px; }
.dp-head.is-row > .icon { color: var(--accent); }
.dp-headmain { flex-grow: 1; min-width: 0; }
.dp-wordline { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.dp-word { font-size: 28px; font-weight: 700; color: var(--ink); line-height: 1.3; word-break: break-word; }
.dp-reading { font-size: 15px; color: var(--muted); }
.dp-tags { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.dp-tag {
  display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: var(--r-sm);
  font-size: 13px; white-space: nowrap; background: var(--bg-soft); color: var(--text);
}
.dp-tag-ai { padding: 0 7px; font-size: 12px; background: var(--violet-bg); color: var(--violet); }
.dp-title { font-size: 15px; font-weight: 600; }
.dp-grow { flex-grow: 1; }
.dp-muted { color: var(--muted); }

.dp-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 4px 16px 12px; -webkit-overflow-scrolling: touch; }
.dp-meaning { margin: 0 0 10px !important; font-size: 16px; line-height: 1.5; font-weight: 500; }
.dp-tr { display: flex; gap: 10px; align-items: baseline; min-height: 26px; font-size: 14px; color: var(--text); }
.dp-lang { width: 26px; flex-shrink: 0; font-size: 11px; font-weight: 600; color: var(--faint); }
.dp-sub { margin: 12px 0 6px !important; font-size: 12px; font-weight: 600; color: var(--muted); }
.dp-ex { padding: 10px 12px; border-radius: var(--r); background: var(--bg-side); }
.dp-ex-main { font-size: 15px; color: var(--ink); }
.dp-ex-alt { margin-top: 4px !important; font-size: 13px; color: var(--muted); }
.dp-ex-main + .dp-ex-main { margin-top: 4px !important; }
/* Cách đọc câu ví dụ (pinyin / hiragana) nằm dòng riêng ngay dưới câu */
.dp-ex-read { display: block; margin-top: 2px; font-size: 13px; line-height: 1.5; color: var(--muted); }
.dp-ex-alt .dp-ex-read { font-size: 12px; }
.dp-quote {
  margin: 0 0 10px !important; padding: 10px 12px; border-left: 3px solid var(--accent);
  border-radius: 0 var(--r) var(--r) 0; background: var(--bg-side); font-size: 14px; line-height: 1.6;
}
.dp-subrow { display: flex; align-items: center; gap: 8px; }
.dp-subrow .dp-sub { margin: 0 0 2px !important; flex-grow: 1; }
.dp-vrow { display: flex; align-items: center; gap: 10px; min-height: 40px; border-top: 1px solid var(--line); }
.dp-vword { font-size: 15px; font-weight: 600; }
.dp-vread { font-size: 12px; color: var(--muted); }
.dp-vmean { flex-grow: 1; min-width: 0; font-size: 13px; color: var(--text); }
.dp-vmean small { display: block; font-size: 11px; }

.dp-foot { flex-shrink: 0; border-top: 1px solid var(--line); background: var(--bg); }
.dp-actions { display: flex; gap: 8px; padding: 12px 16px; }
.dp-hint { margin: -4px 0 0 !important; padding: 0 16px 12px; font-size: 12px; color: var(--muted); }
.dp-hint a { color: var(--accent); text-decoration: none; }
.dp-hint a:hover { text-decoration: underline; }
.dp-class { display: flex; gap: 6px; padding: 0 16px 12px; }

/* Nút (giống .btn / .btn-primary / .rd-ico của giao diện mới) */
.dp-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border: 1px solid var(--line); border-radius: var(--r);
  background: var(--bg); color: var(--text); font: inherit; font-size: 13px; font-weight: 500;
  white-space: nowrap; cursor: pointer;
}
.dp-btn:hover { border-color: var(--faint); color: var(--ink); }
.dp-btn:disabled { cursor: default; opacity: 0.6; }
.dp-btn-primary { flex-grow: 1; border-color: var(--accent); background: var(--accent); color: var(--on-accent); font-weight: 600; }
.dp-btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--on-accent); }
.dp-btn.is-saved { background: var(--green-bg); color: var(--green); border-color: var(--green-tag); cursor: default; opacity: 1; }
.dp-btn.is-done { color: var(--green); border-color: var(--green-tag); }
.dp-class .dp-btn { height: 32px; }
.dp-ico {
  width: 34px; height: 34px; flex-shrink: 0; padding: 0; border: 0; border-radius: var(--r);
  background: none; color: var(--muted); display: grid; place-items: center; cursor: pointer;
}
.dp-ico:hover { background: var(--bg-soft); color: var(--ink); }
.dp-ico:disabled { cursor: default; }
.dp-ico.is-done { color: var(--green); }
.dp-vrow .dp-ico { width: 32px; height: 32px; }
.dp-select {
  min-width: 0; flex-grow: 1; height: 32px; padding: 0 8px; border: 1px solid var(--line); border-radius: var(--r);
  font: inherit; font-size: 13px; color: var(--text); background: var(--bg);
}
.dp-subrow .dp-select { flex-grow: 0; max-width: 55%; height: 28px; font-size: 12px; }

/* Đang tra / lỗi */
.dp-state { display: flex; align-items: center; gap: 10px; padding: 16px; font-size: 14px; color: var(--text); }
.dp-state > span { flex-grow: 1; }
.dp-state.is-error > .icon:first-child { color: var(--red); }
.dp-spin { animation: dp-spin 0.9s linear infinite; color: var(--accent); }
@keyframes dp-spin { to { transform: rotate(360deg); } }

/* Điện thoại: tấm trượt từ dưới lên như trang Đọc (RD_M2). Shorts tự đặt chỗ riêng (.sh-dict). */
@media (max-width: 860px) {
  .dict-popup:not(.sh-dict) {
    left: 0 !important; right: 0; top: auto !important; bottom: 0; width: auto; max-height: 72vh;
    padding-top: 14px; border: 0; border-radius: 14px 14px 0 0; box-shadow: 0 -8px 28px rgba(15, 23, 42, 0.18);
  }
  .dict-popup:not(.sh-dict)::before {
    content: ""; position: absolute; top: 8px; left: 50%; width: 40px; height: 4px; margin-left: -20px;
    border-radius: 2px; background: var(--line);
  }
  .dict-popup .dp-ico { width: 44px; height: 44px; }
  .dict-popup .dp-actions .dp-btn { height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  .dict-popup { transition: none; }
  .dp-spin { animation: none; }
}

/* Thông báo nổi thay cho alert() (dict_popup.js toast) */
.dict-popup-toast {
  position: fixed; z-index: 100000; left: 50%; bottom: 24px; transform: translateX(-50%);
  max-width: calc(100vw - 32px); padding: 10px 14px; border-radius: var(--r-md);
  background: var(--dark); color: #ffffff; font-size: 14px; box-shadow: var(--shadow-pop);
}

/* Câu ví dụ "cách đọc TRÊN TỪNG TỪ" (giống chế độ Đọc) — trùng css/base.css cho các trang cũ không nạp base.css */
.jf-ruby { line-height: 2.25; }
.jf-u { white-space: nowrap; margin-right: 0.22em; }
.jf-ruby.is-zh .jf-u { margin-right: 0.55em; }   /* tiếng Trung: các từ cách quãng rõ (13/10/2026) */
.jf-w { display: inline-block; white-space: nowrap; margin-right: 0.5em; }
.jf-w:last-child { margin-right: 0; }
.jf-ruby ruby { ruby-align: center; }
.jf-ruby rt { font-size: max(10.5px, 0.6em); font-weight: 400; line-height: 1; color: var(--muted); letter-spacing: 0;
  padding: 0 0.15em; user-select: none; -webkit-user-select: none; }
