/* One material language: paper yields, wax answers to pressure, candlelight fades. */
:root {
  --ease-release: cubic-bezier(.19,.72,.23,1);
  --ease-gather: cubic-bezier(.35,.04,.65,1);
}
:is(.relationship-read,.envelope-back,.seal-link,.fold,.wish-entry,.wish-back,.wish-mic) {
  -webkit-tap-highlight-color: transparent;
}
.relationship-read:is(:active,[data-tap]) { color: #52212c; }
.relationship-read:is(:active,[data-tap]) span { text-decoration-color: currentColor; }
.envelope-back:is(:active,[data-tap]), #words .fold:is(:active,[data-tap]),
.wish-back:is(:active,[data-tap]), .wish-mic:is(:active,[data-tap]) {
  color: #fff8ee;
  text-decoration: underline;
  text-underline-offset: .24em;
}
#envelope .seal-link:is(:active,[data-tap]) span {
  color: #fff9eb;
  text-decoration: underline;
  text-underline-offset: .3em;
}
.reading-help { margin: 1.5rem; color: #f1dfcf; }

@media (prefers-reduced-motion: no-preference) {
  :is(.relationship-read,.envelope-back,.wish-back,.wish-mic),
  #words :is(.fold,.wish-entry) {
    transition: translate .13s var(--ease-release), color .13s ease, background-color .13s ease;
  }
  :is(.relationship-read,.envelope-back,.wish-back,.wish-mic):is(:active,[data-tap]),
  #words :is(.fold,.wish-entry):is(:active,[data-tap]) { translate: 0 1px; }
  #envelope .seal-link span { transition: translate .14s var(--ease-release), color .13s ease; }
  #envelope .seal-link:is(:active,[data-tap]) span { translate: 0 2px; }

  .rime-touch {
    position: absolute;
    z-index: 3;
    left: var(--touch-x);
    top: var(--touch-y);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: radial-gradient(circle, #eff8f536 0%, #e3f1ee28 28%, transparent 69%);
    box-shadow: inset 0 0 0 1px #e9f7f446;
    pointer-events: none;
    animation: glass-touch .55s var(--ease-release) both;
  }
  @keyframes glass-touch {
    0% { opacity: 0; transform: translate(-50%,-50%) scale(.38); }
    26% { opacity: .82; }
    100% { opacity: 0; transform: translate(-50%,-50%) scale(1.5); }
  }

  /* Press feedback must also read on a static paper image without WebGL. */
  .relationship-paper { transition: scale .15s var(--ease-release); }
  #days[data-held] .relationship-paper { scale: .99; }
  #envelope .tabletop picture img { transition: translate .16s var(--ease-release); }
  #envelope[data-held] .tabletop picture img,
  body[data-leaving="envelope-letter"] #envelope .tabletop picture img { translate: 0 clamp(3px,1.35vw,7px); }
  #envelope .seal-touch {
    position: absolute;
    left: calc(var(--mx) - var(--envelope) * .014);
    top: calc(var(--my) + var(--envelope) * .047);
    width: calc(var(--envelope) * .10);
    aspect-ratio: 1;
    transform: translate(-50%,-50%);
    opacity: 0;
    background: radial-gradient(ellipse at 42% 50%, #ffe6bb3b, #eaa36a14 48%, transparent 69%);
    transition: opacity .13s ease;
    pointer-events: none;
  }
  #envelope .tabletop:not([data-relief]) .seal-touch { display: block; }
  #envelope .tabletop[data-relief] .seal-touch { display: none; }
  #envelope[data-held] .seal-touch, body[data-leaving="envelope-letter"] .seal-touch { opacity: 1; }

  /* Only the short outgoing beat gates the route. The destination can be used during its arrival. */
  body[data-leaf="days"][data-leaving] .relationship-paper {
    animation: slip-away var(--leave-time) var(--ease-gather) both;
  }
  @keyframes slip-away {
    from { opacity: 1; transform: none; }
    to { opacity: .84; transform: translate(-5px,5px) rotate(-.55deg) scale(.992); }
  }
  body[data-arrival$="-days"]:not([data-arrival="cover-days"]) .relationship-paper {
    animation: slip-home .44s var(--ease-release) both;
  }
  @keyframes slip-home {
    from { opacity: .76; transform: translate(-6px,5px) rotate(-.55deg); }
    to { opacity: 1; transform: none; }
  }
  body[data-leaf="envelope"][data-leaving] #envelope :is(.cover-copy,header) {
    animation: ink-away var(--leave-time) ease-out both;
  }
  @keyframes ink-away { to { opacity: .76; } }
  body[data-arrival$="-envelope"] #envelope :is(.cover-copy,header) {
    animation: textile-in .32s var(--ease-release) both;
  }
  @keyframes textile-in { from { opacity: .76; } to { opacity: 1; } }

  /* Animate only explicitly entered content. Clearing data-arrival must not start a second animation. */
  body[data-arrival="envelope-letter"] #words[open] .letter-sheet {
    animation: draw-letter .34s var(--ease-release) both;
  }
  @keyframes draw-letter {
    from { transform: translateY(12px) rotate(-.35deg); }
    to { transform: none; }
  }
  /* The room stays opaque, including while the letter scroll position is restored. */
  body[data-leaf="letter"][data-leaving] #words[open] .reader-stage {
    animation: reader-light-out var(--leave-time) ease-in both;
  }
  @keyframes reader-light-out { to { opacity: .86; } }

  body[data-arrival$="-wish"] .wish-stage {
    animation: candle-settle .38s var(--ease-release) both;
  }
  body[data-leaf="wish"][data-leaving] .wish-stage {
    animation: room-light-out var(--leave-time) ease-in both;
  }
  @keyframes room-light-out { to { opacity: .84; } }
  @keyframes candle-settle {
    from { opacity: .84; transform: translateY(5px); }
    to { opacity: 1; transform: none; }
  }

  #wish-model.is-3d { transition: scale .18s var(--ease-release); }
  #wish-model.is-3d:active:not(.turning) { scale: .992; }
}
