/* The contents (contents.js): a small wax seal in the top right corner, and the card of chapters it
   opens. The card is set like the envelopes: white paper warming to cream, with a gilt hairline
   inset from its edge. It is a popover, so it opens, and closes on Escape or a tap outside, even
   without JavaScript; browsers without popovers simply don't show the seal. */

.contents__seal {
  position: fixed;
  top: max(1rem, env(safe-area-inset-top));
  right: max(1rem, env(safe-area-inset-right));
  z-index: 5;
  padding: .3rem;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: pointer;
  transition: opacity 1.5s ease 2.7s, translate .4s var(--ease-out), rotate .7s var(--ease-out), scale .3s ease;
}

.contents__seal .wax { width: 2.6rem; }

/* It arrives with the date beneath the monogram, not before. */
.is-enhanced .contents__seal { opacity: 0; pointer-events: none; }
.is-loaded .contents__seal { opacity: .92; pointer-events: auto; }

@media (hover: hover) {
  .contents__seal:hover { translate: 0 -2px; rotate: -8deg; }
}

/* While the card is open the seal is pressed down, turned a little. */
.contents:has(:popover-open) .contents__seal { scale: .9; rotate: -20deg; translate: none; }

.contents__card {
  position: fixed;
  inset: auto;
  top: calc(max(1rem, env(safe-area-inset-top)) + 3.8rem);
  right: max(1rem, env(safe-area-inset-right));
  width: min(17.5rem, calc(100vw - 2rem));
  max-height: calc(100svh - 6rem);
  overflow: auto;
  margin: 0;
  padding: 1.5rem 1.6rem 1.4rem;
  border: 0;
  border-radius: 6px;
  color: var(--sage);
  background: linear-gradient(160deg, var(--white), var(--cream));
  box-shadow:
    0 24px 44px -18px color-mix(in srgb, var(--ink) 30%, transparent),
    inset 0 0 0 7px var(--white),
    inset 0 0 0 8px color-mix(in srgb, var(--sage) 55%, transparent);
  font-family: var(--serif);
  transform-origin: calc(100% - 1.6rem) -1.5rem;
  opacity: 0;
  scale: .94;
  translate: 0 -8px;
  filter: blur(4px);
  transition:
    opacity .35s ease, scale .6s var(--ease-out), translate .6s var(--ease-out), filter .35s ease,
    overlay .6s allow-discrete, display .6s allow-discrete;
}

.contents__card:popover-open { opacity: 1; scale: none; translate: none; filter: none; }
.contents__card::backdrop { background: transparent; }

@starting-style {
  .contents__card:popover-open { opacity: 0; scale: .94; translate: 0 -8px; filter: blur(4px); }
}

.contents__list { display: grid; margin: 0; padding: 0; list-style: none; }

.contents__list a {
  display: grid;
  grid-template-columns: 2.2rem 1fr auto;
  align-items: baseline;
  padding: .55rem 0;
  color: var(--sage);
  font-size: .8rem;
  letter-spacing: .2em;
  text-transform: uppercase;
  text-decoration: none;
  transition: color .3s ease;
}

/* Fingers get rows a comfortable 44px tall. */
@media (pointer: coarse) {
  .contents__list a { padding-block: .8rem; }
}

.contents__numeral {
  font-size: .95rem;
  font-style: italic;
  letter-spacing: .04em;
  color: var(--sage-light);
}

/* The chapter you're in wears a drop of wax. */
.contents__list a[aria-current]::after {
  content: '';
  width: .36rem;
  aspect-ratio: 1;
  align-self: center;
  border-radius: 50%;
  background: var(--sage);
}

.contents__list a:hover, .contents__invite:hover { color: var(--sage-deep); }

.contents__invite {
  display: block;
  margin-top: .8rem;
  padding: .95rem 0 .2rem 2.2rem;
  border-top: 1px solid color-mix(in srgb, var(--sage) 28%, transparent);
  color: var(--sage);
  font-size: 1.05rem;
  font-style: italic;
  letter-spacing: .03em;
  text-decoration: none;
  transition: color .3s ease;
}

/* The chapters are written in one after another as the card opens. */
.contents__list li, .contents__invite {
  transition: opacity .5s ease calc(var(--i) * 45ms + 90ms), translate .8s var(--ease-out) calc(var(--i) * 45ms + 90ms), color .3s ease;
}

@starting-style {
  .contents__card:popover-open li, .contents__card:popover-open .contents__invite { opacity: 0; translate: 0 6px; }
}

/* A jump hands focus to the chapter's heading (contents.js) so keyboard users read on from there;
   the title itself needs no focus ring. */
:is(h1, h2)[tabindex="-1"]:focus { outline: none; }

@supports not selector(:popover-open) {
  .contents { display: none; }
}
