/* Mandarin Stack — CJK annotation styles. */

ruby.cjk-word {
  /* Custom layout: flex column with pinyin on top, base below.  Native
     <ruby> column-pairing would stretch multi-char words; this keeps each
     word as one compact unit. */
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: baseline;
  cursor: pointer;
  border-radius: 4px;
  padding: 0 2px;
  /* Visible whitespace between segmented words so readers can pick out
     word boundaries at a glance. */
  margin-inline-end: 0.5em;
  transition: background-color .12s ease;
}
ruby.cjk-word:hover {
  background-color: rgba(40, 88, 211, 0.10);
}
/* Pull punctuation runs flush against the preceding word so the inter-word
   gap doesn't visually separate "你好" from "！", etc. */
ruby.cjk-word + .cjk-trail {
  margin-inline-start: -0.5em;
}
ruby.cjk-word .cjk-base {
  font-family: var(--font-cn, 'PingFang SC', 'Noto Sans CJK SC', sans-serif);
  letter-spacing: 0;
  white-space: nowrap;
  line-height: 1.4;
}
ruby.cjk-word .cjk-rt {
  display: block;
  font-size: 0.65em;
  font-weight: 500;
  color: var(--color-primary, #2858d3);
  letter-spacing: 0.02em;
  line-height: 1.15;
  font-family: var(--font-sans, system-ui, sans-serif);
  white-space: nowrap;
  text-align: center;
  margin-bottom: 1px;
}

/* Global toggle for ruby visibility — fully collapses the rt row so the
   words pack tightly. Line-height shifts slightly when toggled, which is
   the trade-off for a clean off-state. */
body.cjk-hide-pinyin ruby.cjk-word .cjk-rt {
  display: none;
}

/* Floating tooltip / popover */
.cjk-tooltip {
  position: absolute;
  z-index: 2000;
  max-width: 360px;
  min-width: 220px;
  background: var(--color-surface, #fff);
  color: var(--color-ink, #1b2540);
  border: 1px solid var(--color-border, #e4e7ec);
  border-radius: 12px;
  box-shadow: 0 12px 32px -10px rgba(20, 33, 61, 0.25);
  font-size: 0.9rem;
  line-height: 1.45;
  overflow: hidden;
  padding: 0;
}
.cjk-tooltip-head {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.7rem 0.9rem 0.5rem;
  border-bottom: 1px solid var(--color-border, #e4e7ec);
  background: linear-gradient(180deg, var(--color-primary-100, #e6edfb) 0%, transparent 100%);
}
.cjk-tooltip-word {
  font-family: var(--font-cn, sans-serif);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-ink, #1b2540);
  line-height: 1.1;
}
.cjk-tooltip-pinyin {
  flex: 1;
  font-size: 0.95rem;
  color: var(--color-primary, #2858d3);
  font-weight: 500;
}
.cjk-tooltip-close {
  background: transparent;
  border: none;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  color: var(--color-muted, #5c6373);
  padding: 0 0.25rem;
  border-radius: 6px;
}
.cjk-tooltip-close:hover { background: rgba(0, 0, 0, 0.05); }

.cjk-tooltip-body {
  padding: 0.6rem 0.9rem 0.85rem;
  max-height: 50vh;
  overflow-y: auto;
}
.cjk-reading + .cjk-reading {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px dashed var(--color-border, #e4e7ec);
}
.cjk-reading-pinyin {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--color-primary, #2858d3);
  margin-bottom: 0.25rem;
}
.cjk-defs {
  margin: 0;
  padding-left: 1.25rem;
  list-style: decimal;
  color: var(--color-ink-2, #3a4561);
}
.cjk-defs li { margin: 0.1rem 0; }
.cjk-empty {
  color: var(--color-muted, #5c6373);
  font-style: italic;
}

/* Action row at the bottom of the popover */
.cjk-tooltip-actions {
  display: flex;
  gap: 0.4rem;
  padding: 0.55rem 0.9rem 0.85rem;
  border-top: 1px solid var(--color-border, #e4e7ec);
  background: var(--color-surface-2, #f5f7fb);
}
.cjk-tooltip-actions > * {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.45rem 0.5rem;
  border-radius: 8px;
  border: 1px solid var(--color-border-strong, #cdd3dc);
  background: var(--color-surface, #fff);
  color: var(--color-ink-2, #3a4561);
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: border-color .12s ease, background .12s ease, color .12s ease, transform .1s ease;
}
.cjk-tooltip-actions > *:hover,
.cjk-tooltip-actions > *:focus {
  border-color: var(--color-primary, #2858d3);
  color: var(--color-primary, #2858d3);
  text-decoration: none;
  outline: none;
  transform: translateY(-1px);
}
.cjk-tooltip-actions i { font-size: 1rem; }
.cjk-action-label { white-space: nowrap; }

/* Inline confirmation toast (appended to the popover footer area) */
.cjk-tooltip-toast {
  margin: 0;
  padding: 0.45rem 0.9rem;
  font-size: 0.78rem;
  font-weight: 600;
  text-align: center;
  border-top: 1px solid transparent;
}
.cjk-tooltip-toast.is-added {
  background: #d1e7dd;
  color: #0f5132;
}
.cjk-tooltip-toast.is-noop {
  background: var(--color-surface-2, #f5f7fb);
  color: var(--color-muted, #5c6373);
}

/* Hide labels on the tiniest tooltips so the buttons stay readable */
@media (max-width: 380px) {
  .cjk-action-label { display: none; }
}
