/* Split text. js/core/split-text.js wraps headings in spans: words (.motion-word > .motion-glyph,
   then .kinetic-char per letter) for the chapter titles, single letters (.motion-letter) for the hero
   word and the character names. The JS writes the transforms, this file sets up the 3D space. */

.motion-word {
  display: inline-block;
  white-space: nowrap; /* letters are inline-blocks too, so without this a word could break mid-word */
  vertical-align: baseline;
  /* padding out, negative margin back: the word's box grows so accents and descenders aren't cut */
  padding: 0.11em 0.05em 0.15em;
  margin: -0.11em -0.05em -0.15em;
  overflow: visible;
  overflow-clip-margin: 0.15em;
  perspective: 900px;
}
.motion-glyph {
  display: inline-block;
  transform-origin: 0 60%;
  transform-style: preserve-3d;
}
.motion-letter {
  display: inline-block;
  transform: translate3d(0, var(--letter-y, 0px), 0) rotateX(var(--letter-r, 0deg));
  transform-origin: 50% 100%;
}
.kinetic-heading {
  perspective: 1100px;
  transform-style: preserve-3d;
}
.kinetic-char {
  display: inline-block;
  transform-origin: 50% 95%;
  backface-visibility: hidden;
}

/* Per-chapter treatments (the numbers live in js/core/kinetic-headings.js) */
[data-type-treatment="world"] .motion-glyph {
  transform-origin: 0 100%; /* words swing open from their bottom-left corner */
}
[data-type-treatment="revenants"] .motion-word {
  overflow: clip; /* words flip up from behind a mask */
}
[data-type-treatment="arts"] .motion-word {
  overflow: clip;
  overflow-clip-margin: 0.2em;
}
[data-type-treatment="districts"] {
  --fill: var(--paper);
}
[data-type-treatment="districts"] .accent {
  --fill: var(--shu);
}
[data-type-treatment="districts"] .kinetic-char {
  /* outlined letters that fill with ink from the bottom: a background clipped to the text */
  background: linear-gradient(var(--fill), var(--fill)) 0 100% / 100% var(--type-fill, 100%) no-repeat;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  -webkit-text-stroke: 0.6px #ebe5d355;
}
[data-type-treatment="begin"] .motion-glyph {
  transform-origin: 0 50%;
}

@media (max-width: 760px) {
  .hero-title .motion-letter,
  .character-info h3 .motion-letter {
    transform: none;
  }
}

/* Reduced motion: every letter in place */
html:is(.reduced, .compact-layout) main :is(.motion-glyph, .motion-letter, .kinetic-char) {
  transform: none !important;
  opacity: 1 !important;
}
html:is(.reduced, .compact-layout) [data-type-treatment="districts"] :is(.motion-glyph, .kinetic-char) {
  color: var(--fill);
  -webkit-text-fill-color: var(--fill);
  -webkit-text-stroke: 0;
}
@media (prefers-reduced-motion: reduce) {
  .kinetic-char {
    transform: none !important;
    opacity: 1 !important;
  }
}
