/* Khối nội dung mở rộng — dùng CHUNG cho trang blog và trình soạn thảo.
 *
 * Vì sao một file riêng: cùng một khối phải trông giống hệt nhau ở hai nơi
 * (lúc soạn và lúc đăng). Trước đây CSS khối nằm rải ở blog/post.html và
 * css/editor.css nên hai bên lệch nhau dần. File này là nguồn duy nhất.
 *
 * Quy ước selector: mọi thứ nằm dưới .post-content (trang blog) hoặc
 * .ed-content .ProseMirror (trình soạn thảo).
 */

/* ---------- Căn lề ---------- */
.post-content .ed-align-center,
.ed-content .ProseMirror .ed-align-center { text-align: center; }
.post-content .ed-align-right,
.ed-content .ProseMirror .ed-align-right { text-align: right; }
.post-content .ed-align-justify,
.ed-content .ProseMirror .ed-align-justify { text-align: justify; text-justify: inter-word; }

/* figure căn lề thì đẩy cả khối, không chỉ chữ bên trong */
.post-content figure.ed-align-center,
.ed-content .ProseMirror figure.ed-align-center { margin-left: auto; margin-right: auto; }
.post-content figure.ed-align-right,
.ed-content .ProseMirror figure.ed-align-right { margin-left: auto; margin-right: 0; }

/* ---------- Biến đổi chữ ---------- */
.ed-tf-upper { text-transform: uppercase; letter-spacing: .04em; }
.ed-tf-lower { text-transform: lowercase; }
.ed-tf-smallcaps { font-variant-caps: small-caps; letter-spacing: .03em; }

.post-content mark,
.ed-content .ProseMirror mark {
  background: color-mix(in srgb, var(--secondary-color) 35%, transparent);
  padding: .05em .2em;
  border-radius: 3px;
}

/* ---------- Làm mờ: ảnh NSFW / spoiler ---------- */
.post-content figure.ed-blur,
.ed-content .ProseMirror figure.ed-blur { position: relative; }

.post-content figure.ed-blur img,
.ed-content .ProseMirror figure.ed-blur img {
  filter: blur(22px);
  transform: scale(1.02);          /* che viền ảnh bị blur làm lộ mép */
  transition: filter .25s ease;
  cursor: pointer;
}
.post-content figure.ed-blur.is-revealed img,
.ed-content .ProseMirror figure.ed-blur.is-revealed img {
  filter: none;
  transform: none;
}

.post-content .ed-blur-note,
.ed-content .ProseMirror .ed-blur-note {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  max-width: 85%;
  text-align: center;
  background: rgba(20, 20, 20, .82);
  color: #fff;
  font-size: .85rem;
  line-height: 1.45;
  padding: .6rem .9rem;
  border-radius: 8px;
  pointer-events: none;
  z-index: 2;
}
.post-content figure.ed-blur.is-revealed .ed-blur-note,
.ed-content .ProseMirror figure.ed-blur.is-revealed .ed-blur-note { display: none; }

/* Làm mờ chữ (spoiler trong dòng) */
.ed-blur-text {
  background: var(--text-color, #333);
  color: transparent;
  border-radius: 3px;
  padding: 0 .15em;
  cursor: pointer;
  transition: color .2s ease, background .2s ease;
  user-select: none;
}
.ed-blur-text.is-revealed {
  background: color-mix(in srgb, var(--secondary-color) 25%, transparent);
  color: inherit;
  user-select: auto;
}

/* ---------- Giải nghĩa từ ---------- */
.ed-term {
  border-bottom: 1.5px dotted var(--primary-color);
  cursor: help;
  padding-bottom: 1px;
}
.ed-term:hover,
.ed-term:focus-visible { background: color-mix(in srgb, var(--primary-color) 12%, transparent); outline: none; }

.ed-term-pop {
  position: absolute;
  z-index: 60;
  max-width: min(320px, calc(100vw - 24px));
  background: #fff;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  box-shadow: 0 8px 28px -10px rgba(0, 0, 0, .3);
  padding: .7rem .85rem;
  font-size: .9rem;
  line-height: 1.55;
  color: var(--text-color);
}
.ed-term-pop .t { font-weight: 600; color: var(--primary-color); }
.ed-term-pop .r { color: var(--text-muted); font-style: italic; margin-left: .3rem; }
.ed-term-pop .d { margin-top: .25rem; }
.ed-term-pop .n { display: block; margin-top: .35rem; color: var(--text-muted); font-size: .84rem; }
.ed-term-pop .l { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .45rem; }
.ed-term-pop .l span {
  background: var(--paper); border: 1px solid var(--border-color);
  border-radius: 999px; padding: .1rem .5rem; font-size: .8rem;
}
.ed-term-pop .l b { color: var(--primary-color); font-weight: 600; margin-right: .25rem; text-transform: uppercase; font-size: .72rem; }

/* Bảng giải nghĩa cuối bài */
.post-content .ed-glossary,
.ed-content .ProseMirror .ed-glossary {
  margin: 2.5rem 0 1rem;
  padding: 1.1rem 1.25rem;
  background: var(--paper);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg, 12px);
}
.ed-glossary-title {
  font-family: var(--font-display, inherit);
  font-size: 1.05rem;
  margin: 0 0 .75rem;
  color: var(--primary-color);
}
.ed-gloss-list { margin: 0; }
.ed-gloss-item { padding: .5rem 0; border-top: 1px solid var(--border-color); }
.ed-gloss-item:first-child { border-top: 0; padding-top: 0; }
.ed-gloss-term { font-weight: 600; margin: 0; }
.ed-gloss-reading { font-weight: 400; font-style: italic; color: var(--text-muted); font-size: .9rem; }
.ed-gloss-def { margin: .15rem 0 0; color: var(--text-light, inherit); font-size: .95rem; }
.ed-gloss-note { display: block; color: var(--text-muted); font-size: .87rem; margin-top: .2rem; }
.ed-gloss-langs { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .4rem; }
.ed-gloss-lang {
  background: #fff; border: 1px solid var(--border-color);
  border-radius: 999px; padding: .1rem .55rem; font-size: .82rem;
}
.ed-gloss-lang b { color: var(--primary-color); text-transform: uppercase; font-size: .72rem; margin-right: .25rem; }

/* ---------- Thu gọn ---------- */
.post-content .ed-collapse,
.ed-content .ProseMirror .ed-collapse {
  margin: 1.4rem 0;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius, 8px);
  background: var(--paper);
  overflow: hidden;
}
.ed-collapse-summary {
  cursor: pointer;
  padding: .7rem 1rem;
  font-weight: 600;
  list-style: none;
  display: flex;
  align-items: center;
  gap: .5rem;
  user-select: none;
}
.ed-collapse-summary::-webkit-details-marker { display: none; }
.ed-collapse-summary::before {
  content: '';
  width: 0; height: 0;
  border-left: 6px solid var(--primary-color);
  border-top: 4.5px solid transparent;
  border-bottom: 4.5px solid transparent;
  transition: transform .18s ease;
  flex: 0 0 auto;
}
.ed-collapse[open] > .ed-collapse-summary::before { transform: rotate(90deg); }
.ed-collapse-summary:hover { background: color-mix(in srgb, var(--primary-color) 8%, transparent); }
.ed-collapse-body { padding: 0 1rem 1rem; }
.ed-collapse-body > :first-child { margin-top: 0; }
.ed-collapse-body > :last-child { margin-bottom: 0; }

/* ---------- Callout ---------- */
.post-content .ed-callout,
.ed-content .ProseMirror .ed-callout {
  margin: 1.4rem 0;
  padding: .9rem 1.1rem;
  border-left: 4px solid var(--cl, var(--primary-color));
  border-radius: 0 var(--border-radius, 8px) var(--border-radius, 8px) 0;
  background: color-mix(in srgb, var(--cl, var(--primary-color)) 9%, transparent);
}
/* Hai màu riêng cho mỗi loại:
 *   --cl   màu vạch bên và nền mờ, được phép nhạt
 *   --cl-t màu CHỮ tiêu đề, phải đủ đậm để đọc trên nền kem
 * Trước đây tiêu đề dùng chung --cl nên loại note (#8a8a8a) chìm nghỉm vô nền. */
.ed-callout-info   { --cl: #4a90d9; --cl-t: #1d5fa8; }
.ed-callout-tip    { --cl: var(--primary-color); --cl-t: #9c3a26; }
.ed-callout-note   { --cl: #8a7d6e; --cl-t: #4a4038; }
.ed-callout-warn   { --cl: #d97706; --cl-t: #8a4a04; }
.ed-callout-danger { --cl: var(--accent-color, #c84b4b); --cl-t: #97302f; }

.ed-callout-title {
  font-weight: 700;
  margin: 0 0 .45rem;
  color: var(--cl-t, var(--cl));
  font-size: 1.02em;
  line-height: 1.4;
}
.ed-callout-body { color: var(--text-color); }
.ed-callout > :last-child { margin-bottom: 0; }

@media (max-width: 560px) {
  .post-content .ed-callout,
  .ed-content .ProseMirror .ed-callout {
    padding: .8rem .9rem;
    margin: 1.1rem -.2rem;
    border-left-width: 5px;
  }
  .ed-callout-title { font-size: 1em; }
}

/* ---------- Trích dẫn có nguồn ---------- */
.ed-quote-cite {
  display: block;
  margin-top: .5rem;
  font-size: .87rem;
  font-style: normal;
  color: var(--text-muted);
}
.ed-quote-cite::before { content: '- '; }

/* ---------- Ảnh bọc link ---------- */
.ed-img-link { display: block; }
.ed-img-link img { display: block; }

/* ---------- Mobile ---------- */
@media (max-width: 640px) {
  .post-content .ed-align-justify { text-align: left; }   /* justify trên màn hẹp tạo khe chữ xấu */
  .ed-term-pop { max-width: calc(100vw - 24px); }
  .ed-glossary { padding: .9rem 1rem; }
}

/* ========== Giải nghĩa từ: phiên âm, ví dụ, nút chép / nghe / nhảy ========== */

.ed-gloss-term {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .35rem .5rem;
  font-weight: 700;
  color: var(--text-color);
}

/* Chính chữ của từ là nút bấm để chép. Trông như chữ thường, chỉ đổi khi rê vô. */
.ed-gloss-copy {
  border: 0; background: none; padding: 0;
  font: inherit; color: inherit; cursor: pointer;
  border-bottom: 2px dotted var(--primary-color);
}
.ed-gloss-copy:hover { color: var(--primary-color); }
.ed-gloss-copy.da-chep { color: #2d7a2d; border-bottom-color: #2d7a2d; }

/* Phiên âm quốc tế và cách đọc kiểu Việt là HAI thứ khác nhau, để tách ra */
.ed-gloss-ipa {
  font-weight: 400;
  color: var(--text-light);
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: .88rem;
}
.ed-gloss-reading {
  font-weight: 400; font-style: italic;
  color: var(--text-muted); font-size: .88rem;
}

.ed-gloss-speak {
  border: 1px solid var(--border-color); background: #fff;
  border-radius: 999px; width: 26px; height: 26px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: .82rem; cursor: pointer; padding: 0; line-height: 1;
}
.ed-gloss-speak:hover { border-color: var(--primary-color); }
.ed-gloss-speak[hidden] { display: none; }
.ed-gloss-speak.dang-doc { background: var(--primary-color); border-color: var(--primary-color); }

/* --- dãy nút nhảy tới chỗ dùng trong bài --- */
.ed-gloss-jumps {
  display: inline-flex; align-items: center; gap: .25rem;
  max-width: 100%; overflow-x: auto; padding-bottom: 2px;
  scrollbar-width: thin;
}
.ed-gloss-jump, .ed-gloss-more {
  flex: 0 0 auto;
  min-width: 24px; height: 24px; padding: 0 .35rem;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border-color); border-radius: 7px;
  background: #fff; color: var(--text-light);
  font-size: .78rem; font-weight: 600; font-family: inherit;
  text-decoration: none; cursor: pointer;
}
.ed-gloss-jump:hover, .ed-gloss-more:hover {
  border-color: var(--primary-color); color: var(--primary-color);
}
.ed-gloss-rest[hidden] { display: none; }
.ed-gloss-rest { display: inline-flex; gap: .25rem; }

/* Nhảy tới nơi thì nháy sáng cho biết đang ở đâu */
.ed-term.dang-toi {
  background: color-mix(in srgb, var(--primary-color) 26%, transparent);
  border-radius: 4px;
  animation: ed-nhay 1.6s ease-out;
  scroll-margin-top: 120px;
}
@keyframes ed-nhay {
  0%, 45% { background: color-mix(in srgb, var(--primary-color) 42%, transparent); }
  100%    { background: color-mix(in srgb, var(--primary-color) 12%, transparent); }
}
.ed-term { scroll-margin-top: 120px; }

/* --- ví dụ dùng từ --- */
.ed-gloss-ex {
  margin-top: .5rem;
  border-left: 3px solid color-mix(in srgb, var(--primary-color) 35%, transparent);
  padding-left: .7rem;
}
.ed-gloss-ex-item + .ed-gloss-ex-item { margin-top: .45rem; }
.ed-gloss-ex-src {
  margin: 0; font-style: italic;
  color: var(--text-color); font-size: .92rem; line-height: 1.55;
}
.ed-gloss-ex-vi {
  margin: .1rem 0 0; color: var(--text-muted);
  font-size: .89rem; line-height: 1.55;
}

/* --- ghi nguồn ảnh, tách khỏi lời mô tả --- */
.ed-figcredit {
  display: block; margin-top: .2rem;
  font-size: .8rem; font-style: normal; color: var(--text-muted);
}
.ed-figcredit a { color: var(--text-muted); text-decoration: underline; }
.ed-figcredit a:hover { color: var(--primary-color); }

/* --- hộp nghĩa hiện lên khi bấm vô từ --- */
.ed-term-pop .ipa {
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: .84rem; color: var(--text-light); margin-left: .3rem;
}
.ed-term-pop .ex { margin-top: .4rem; padding-top: .4rem; border-top: 1px dashed var(--border-color); }
.ed-term-pop .ex i { display: block; font-size: .84rem; line-height: 1.5; }
.ed-term-pop .ex u { display: block; font-size: .82rem; color: var(--text-muted); text-decoration: none; }
.ed-term-pop .spk {
  border: 0; background: none; cursor: pointer;
  font-size: .9rem; padding: 0 0 0 .3rem;
}

/* ========== Điện thoại ========== */
@media (max-width: 560px) {
  .post-content .ed-glossary,
  .ed-content .ProseMirror .ed-glossary { padding: .9rem .85rem; }
  .ed-glossary-title { font-size: 1.02rem; }
  .ed-gloss-item { padding: .7rem 0; }
  .ed-gloss-term { gap: .3rem .4rem; font-size: 1.02rem; }
  .ed-gloss-ipa, .ed-gloss-reading { font-size: .84rem; width: 100%; }
  .ed-gloss-def { font-size: .95rem; line-height: 1.65; }
  /* Ngón tay to hơn con trỏ chuột, nút phải đủ lớn để bấm không trượt */
  .ed-gloss-jump, .ed-gloss-more { min-width: 30px; height: 30px; font-size: .82rem; }
  .ed-gloss-speak { width: 30px; height: 30px; }
  .ed-term-pop { max-width: calc(100vw - 24px); }
}

/* Hộp nghĩa phải "bắt" được chuột thì mới bấm nút bên trong được.
 * Lúc ghim thì viền đậm hơn để biết nó đang đứng yên chờ mình thao tác. */
.ed-term-pop { pointer-events: auto; }
.ed-term-pop.ghim {
  border-color: var(--primary-color);
  box-shadow: 0 6px 22px rgba(31, 24, 18, .16);
}
.ed-term-pop .spk:hover { transform: scale(1.15); }
