/* The contents (contents.js): three sage lines in the top left corner, and the card of chapters they
   open. 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 lines. */

.contents__toggle {
  --weight: 1.5px;
  --gap: 5px;
  position: fixed;
  top: max(1rem, env(safe-area-inset-top));
  left: max(1rem, env(safe-area-inset-left));
  z-index: 5;
  display: grid;
  place-items: center;
  width: 2.75rem; /* 44px: a comfortable tap */
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 50%;
  /* A soft clearing of ivory behind the lines: unseen on bare paper, it lifts them off the ivy once
     the corner has grown in beneath them. */
  background: radial-gradient(closest-side, color-mix(in srgb, var(--ivory) 94%, transparent) 60%, transparent);
  cursor: pointer;
  transition: opacity 1.5s ease 2.7s;
}

.contents__lines { display: grid; gap: var(--gap); width: 1.35rem; }

.contents__lines i {
  display: block;
  height: var(--weight);
  border-radius: var(--weight);
  background: var(--sage);
  transform-origin: 0 50%;
  transition: translate .5s var(--ease-out), rotate .5s var(--ease-out), scale .5s var(--ease-out), opacity .3s ease;
}

.contents__lines i:nth-child(1),
.contents__lines i:nth-child(3) { transform-origin: 50% 50%; }

/* They arrive with the date beneath the monogram, not before. */
.is-enhanced .contents__toggle { opacity: 0; pointer-events: none; }
.is-loaded .contents__toggle { opacity: 1; pointer-events: auto; }

/* Under the pointer, the middle line draws in a little, as if about to be turned. */
@media (hover: hover) {
  .contents__toggle:hover .contents__lines i:nth-child(2) { scale: .6 1; }
}

/* While the card is open the lines fold into a cross, to close it by. */
.contents:has(:popover-open) .contents__lines i:nth-child(1) { translate: 0 calc(var(--gap) + var(--weight)); rotate: 45deg; }
.contents:has(:popover-open) .contents__lines i:nth-child(2) { opacity: 0; scale: 0 1; }
.contents:has(:popover-open) .contents__lines i:nth-child(3) { translate: 0 calc(-1 * (var(--gap) + var(--weight))); rotate: -45deg; }

.contents__card {
  position: fixed;
  inset: auto;
  top: calc(max(1rem, env(safe-area-inset-top)) + 3.4rem);
  left: max(1rem, env(safe-area-inset-left));
  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: 1.4rem -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; }
}
