/* Kakejiku. Each contact portrait is mounted as a hanging scroll, built from the
   parts of a real one:
   - a cord from a nail, and a hanging bar (hasso) at the head
   - the upper cloth (ten) with its two hanging strips (futai)
   - an inner mount of paper around the picture (nakamawashi)
   - a strip of brass foil directly above and below the picture (ichimonji)
   - the lower cloth (chi), shorter than the upper
   - a roller (jikugi) at the foot with a brass knob at each end (jikusaki)
   The side margin leaves room for the knobs, the top margin for the cord. */

/* The scroll hangs clear of the wall, so it casts the paper shadow (the values of
   --shadow-paper). The shadow is a filter on this wrapper, not a box shadow on
   the mount, so it follows the cord, the knobs, and the scroll's edge while it
   unrolls. The wrapper also turns about the nail when the scroll sways. */
.hanging {
  display: block;
  transform-origin: 50% 7px;
  filter: drop-shadow(0 1px 2px rgb(36 40 36 / 0.06)) drop-shadow(0 12px 32px rgb(36 40 36 / 0.08));
}

/* A fine pale line just inside each long edge, where the cloth is turned over
   and pasted down. */
.mount {
  position: relative;
  display: block;
  margin: 30px 8px 26px;
  padding: 0 6% 13%;
  background-image:
    linear-gradient(rgb(245 241 232 / 0.55), rgb(245 241 232 / 0.55)),
    linear-gradient(rgb(245 241 232 / 0.55), rgb(245 241 232 / 0.55)),
    var(--grain-on-light);
  background-size: 1px 100%, 1px 100%, var(--grain-size);
  background-position: 3px 0, calc(100% - 3px) 0, 0 0;
  background-repeat: no-repeat, no-repeat, repeat;
}
.mount::before,
.mount::after {
  content: "";
  position: absolute;
}
.mount::before { top: 0; left: 0; right: 0; height: 3px; background: var(--ink); }
.mount::after {
  top: calc(100% - 5px);
  left: -8px;
  right: -8px;
  height: 10px;
  border-radius: 2px;
  /* Knob, knob, a line of light along the top of the round roller, the roller. */
  background:
    var(--brass-foil) left / 9px 100% no-repeat,
    var(--brass-foil) right / 9px 100% no-repeat,
    linear-gradient(rgb(245 241 232 / 0.3), rgb(245 241 232 / 0.3)) center 3px / calc(100% - 22px) 1px no-repeat,
    linear-gradient(var(--ink), var(--ink)) center / calc(100% - 18px) 6px no-repeat;
}

.mount-ten {
  position: relative;
  display: block;
  aspect-ratio: 11 / 3;
  /* Two brass rings where the cord is tied to the bar, then the two strips. */
  background:
    radial-gradient(circle, var(--brass) 0 2px, transparent 2.5px) 18% -1px / 6px 6px no-repeat,
    radial-gradient(circle, var(--brass) 0 2px, transparent 2.5px) 82% -1px / 6px 6px no-repeat,
    linear-gradient(var(--ivory), var(--ivory)) 29% 3px / 5px 100% no-repeat,
    linear-gradient(var(--ivory), var(--ivory)) 71% 3px / 5px 100% no-repeat;
}
/* The cord: a shallow triangle from the bar up to the nail. */
.mount-ten::before,
.mount-ten::after {
  content: "";
  position: absolute;
  left: 50%;
  background: var(--ink);
}
.mount-ten::before {
  bottom: 100%;
  width: 64%;
  height: 22px;
  translate: -50% 0;
  clip-path: polygon(0 100%, 50% 0, 100% 100%, calc(100% - 4px) 100%, 50% 1.5px, 4px 100%);
}
.mount-ten::after {
  bottom: calc(100% + 19px);
  width: 5px;
  height: 5px;
  border-radius: 50%;
  translate: -50% 0;
}

.mount-inner { display: block; padding: 10% 6% 7%; }

/* The foil strips are drawn three times wider than they show, so the light band
   can cross them when the scroll is pointed at. */
.mount picture {
  display: block;
  padding: 4px 0;
  background: var(--brass-foil) 100% 0 / 300% 100%;
  transition: background-position 1.4s ease;
}
.person:hover .mount picture,
.person:focus-visible .mount picture { background-position: 0 0; }

/* A hanging scroll is kept rolled and let down for the guest. Each mount starts
   as its cord, bar, and roller, and the roller descends once, the first time
   the scroll comes into view: slow to start, quicker through the middle,
   settled at the end. portraits.js marks the moment. Without it, or under
   reduced motion, the scrolls hang open. Run on a clock, not on scroll
   position, so a scroll is never left half open. The clip reaches above the
   mount so the cord stays in view. */
@keyframes unroll {
  from { clip-path: inset(-32px -8px calc(100% - 9px) -8px); }
  to   { clip-path: inset(-32px -8px -6px -8px); }
}
@keyframes roller-down { from { top: -2px; } }

/* Touched, a hanging scroll swings from its nail and comes to rest: each swing
   smaller than the last. portraits.js starts it on hover or keyboard focus and
   lets it finish even if the pointer has already left. */
@keyframes sway {
  18%  { rotate: 1.1deg; }
  42%  { rotate: -0.7deg; }
  64%  { rotate: 0.4deg; }
  82%  { rotate: -0.15deg; }
}

@media (prefers-reduced-motion: no-preference) {
  .scrolls-ready .mount:not(.is-hung) { clip-path: inset(-32px -8px calc(100% - 9px) -8px); }
  .scrolls-ready .mount:not(.is-hung)::after { top: -2px; }
  .hanging.is-swaying { animation: sway 2.6s ease-in-out; }
  .mount.is-hung { animation: unroll 1.7s cubic-bezier(0.6, 0, 0.2, 1) both; }
  .mount.is-hung::after { animation: roller-down 1.7s cubic-bezier(0.6, 0, 0.2, 1) both; }
  .people li:nth-child(2) .mount,
  .people li:nth-child(2) .mount::after { animation-delay: 0.2s; }
  .people li:nth-child(3) .mount,
  .people li:nth-child(3) .mount::after { animation-delay: 0.4s; }
}
@media (prefers-reduced-motion: reduce) {
  .mount picture { transition: none; }
}
