/* Load after body.css. Inline-only editorial emphasis; no layout ownership.
 * Optional JS hook: observe `.em-key.em-draw`, add `em-on` on first viewport
 * entry and immediately unobserve. Keep em-on attached; do not toggle it.
 * Without JS, every signature underline is already fully visible.
 * Any other dark container can opt in with data-em-tone="dark" (or em-dark).
 */
:root {
  --em-accent: #a83f13;
  --em-line: rgba(168, 63, 19, .55);
  --em-secondary-line: rgba(80, 67, 57, .4);
}

.lvb-dark,
.em-dark,
[data-em-tone="dark"] {
  --em-accent: #ff985d;
  --em-line: rgba(255, 152, 93, .7);
  --em-secondary-line: rgba(226, 212, 196, .5);
}

.em-key {
  color: var(--em-accent, #a83f13);
  font-weight: 800;
  font-size: 1.025em;
  /* Preserve Japanese line breaking: never make a phrase inline-block/nowrap. */
  white-space: normal;
  word-break: inherit;
  overflow-wrap: inherit;
  line-height: inherit;
}

/* Contrast is a quieter reading cue, not a second orange/highlighter layer. */
.em-contrast {
  color: inherit;
  font-weight: 650;
  font-size: 1em;
  text-decoration-line: underline;
  text-decoration-style: dotted;
  text-decoration-color: var(--em-secondary-line);
  text-decoration-thickness: 1px;
  text-underline-offset: .2em;
}

/* Background underline fragments follow wrapped text without changing its box.
 * No block-level pseudo-element crossing line breaks and no hidden text state.
 */
.em-key.em-draw {
  background-image: linear-gradient(var(--em-line), var(--em-line));
  background-position: left 96%;
  background-repeat: no-repeat;
  background-size: 100% 2px;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}

@media (prefers-reduced-motion: no-preference) {
  .em-key.em-draw.em-on {
    animation: em-underline-entry 720ms cubic-bezier(.22, .61, .36, 1) 1 both;
  }
}

@keyframes em-underline-entry {
  from { background-size: 0% 2px; }
  to { background-size: 100% 2px; }
}

/* Respect existing heading / list-title type scales rather than enlarging them.
 * Only the selected inline phrase changes color, never the complete heading.
 */
:is(h1, h2, h3, h4, h5, h6, .lvb-sequence-title, .lvb-callout) .em-key {
  font-size: 1em;
  line-height: inherit;
  letter-spacing: inherit;
}

@media (max-width: 640px) {
  .em-key { font-size: 1em; }
}

@media (prefers-reduced-motion: reduce) {
  .em-key.em-draw.em-on {
    animation: none;
    background-size: 100% 2px;
  }
}

@media (forced-colors: active) {
  .em-key { color: CanvasText; }
  .em-key.em-draw {
    background: none;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: .2em;
    animation: none;
  }
  .em-contrast { text-decoration-color: CanvasText; }
}

@media print {
  .em-key { color: inherit; }
  .em-key.em-draw {
    background: none;
    animation: none;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: .2em;
  }
}

/* Optical emphasis: keep long Japanese phrases inline and let them wrap. */
.lvb-body .lvb-p .em-key, .lvb-body .lvb-list .em-key { font-size: 1.085em; }
.lvb-body .lvb-callout .em-key { font-size: 1.12em; }
.lvb-body .lvb-heading .em-key, .lvb-body .lvb-sequence-title .em-key { font-size: 1.065em; }
@media (max-width: 640px) {
  .lvb-body .lvb-p .em-key, .lvb-body .lvb-list .em-key { font-size: 1.065em; }
  .lvb-body .lvb-callout .em-key { font-size: 1.09em; }
}
