/* the writing shelf (#writing, js/shelf.js): a short shelf of little books. each spine
   and cover is an svg drawn from the essay; hover or focus one and it slides out and turns
   to show its cover. js/shelf-fx.js lays a three.js effects canvas over the top. */

.shelf-sec { padding-top: clamp(36px, 6vh, 72px); padding-bottom: clamp(16px, 3vh, 32px); }
.shelf-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px 22px; }
.shelf-head .label i { background: var(--dot); }
.shelf-more { display: flex; gap: 18px; font: 400 13px/1 var(--mono); color: var(--ink-3); }
.shelf-more a { color: var(--ink-2); text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 4px; }
.shelf-more a:hover { text-decoration-color: var(--c2); }

.shelf-stage { --u: 1.3px; position: relative; width: fit-content; min-width: min(100%, 420px); margin-top: 4px; padding-top: 96px; } /* the room above is where the effects rise */
.shelf-fx { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 3; }

/* no js: a plain list */
.shelf-books { list-style: none; margin: 0; padding: 0; }
.shelf-books a { color: var(--ink); }
.shelf-plain span { display: block; color: var(--ink-3); font-size: 14px; }

.built .shelf-books { display: flex; align-items: flex-end; gap: 3px; padding: 0 0 0 22px; min-height: calc(220 * var(--u)); }
/* a forgiving hover: the hit area reaches up to where the book rises, and down to the plank */
.book::before { content: ""; position: absolute; left: -2px; right: -2px; top: -34px; bottom: -10px; }
.book {
  --w: calc(var(--wf) * var(--u)); --h: calc(var(--hf) * var(--u)); --cw: calc(150 * var(--u));
  position: relative; flex: none; width: var(--w); height: var(--h);
  perspective: 900px;
  transform: rotate(var(--tilt, 0deg)); transform-origin: 50% 100%; transition: transform .4s ease;
}
.book:hover, .book:focus-within { z-index: 2; }
/* the shadow it leaves on the plank */
.book::after { content: ""; position: absolute; left: -3px; right: -3px; bottom: -3px; height: 6px; border-radius: 50%; background: rgba(30, 16, 0, .35); filter: blur(3px); z-index: -1; }
.book a {
  position: absolute; inset: 0; display: block; transform-style: preserve-3d;
  transform-origin: 50% 100% calc(var(--cw) * -0.5);
  transition: transform .7s cubic-bezier(.2, .9, .25, 1.05) .14s; /* the delay: brushing past an edge doesn't snap it shut */
  outline: none;
}
.book-face { position: absolute; top: 0; height: 100%; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.book-face svg { display: block; text-rendering: geometricPrecision; }
.book-spine { left: 0; width: var(--w); border-radius: 2px 3px 3px 2px; overflow: hidden; box-shadow: 0 1px 0 rgba(0, 0, 0, .25); }
/* round the spine: light on its left, a roll into shadow on its right */
.book-spine::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(90deg, rgba(0, 0, 0, .28), rgba(255, 255, 255, .16) 14%, rgba(255, 255, 255, 0) 38%, rgba(0, 0, 0, .12) 78%, rgba(0, 0, 0, .38));
}
/* foil catches the light as it comes out */
.book-spine::after {
  content: ""; position: absolute; inset: -20% -60%; pointer-events: none; mix-blend-mode: soft-light;
  background: linear-gradient(105deg, transparent 40%, rgba(255, 255, 255, .85) 50%, transparent 60%);
  transform: translateY(110%); transition: transform 0s;
}
.book-cover { left: var(--w); width: var(--cw); transform-origin: 0 50%; transform: rotateY(90deg); box-shadow: inset 6px 0 10px -4px rgba(0, 0, 0, .45); }
.book-top { left: 0; width: var(--w); height: var(--cw); top: 0; transform-origin: 0 0; transform: rotateX(-90deg); background: repeating-linear-gradient(90deg, #f4ecd8 0 2px, #e2d6bb 2px 3px); }

/* out of the row and turned all the way, so the cover faces you flat; its left edge lines up with the spine's */
.book:hover, .book:focus-within { --tilt: 0deg; }
.book:hover a, .book a:focus-visible { transition-delay: 0s; transform: translateX(calc((var(--cw) - var(--w)) / 2)) translateY(-18px) translateZ(calc(var(--cw) / 2)) rotateY(-90deg); }
.book:hover .book-spine::after, .book a:focus-visible .book-spine::after { transform: translateY(-110%); transition: transform .9s ease .15s; }
.book a:focus-visible .book-spine { box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--c0); }

/* the ones still being written */
.book.ghost .book-spine {
  display: grid; place-items: center; border-radius: 3px;
  background: color-mix(in srgb, var(--ink) 4%, transparent);
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--ink) 18%, transparent);
  background-image: repeating-linear-gradient(-45deg, transparent 0 6px, color-mix(in srgb, var(--ink) 5%, transparent) 6px 7px);
}
.book.ghost .book-spine::before, .book.ghost .book-spine::after, .book.ghost::after { display: none; }
.book.ghost i { writing-mode: vertical-rl; font: 400 11px/1 var(--mono); font-style: normal; letter-spacing: .14em; color: var(--ink-3); }

/* the little guy who keeps the books upright, standing at the end of the row */
.shelf-row { display: flex; align-items: flex-end; gap: 14px; padding-right: 48px; }
.g-shelf { position: relative; flex: none; margin-bottom: -2px; z-index: 4; }
html:not(.js) .g-shelf, .no-grunts .g-shelf { display: none; }

.shelf-plank {
  position: relative; height: 15px; border-radius: 2px 2px 4px 4px;
  background: linear-gradient(#d6aa72, #b4834a 45%, #8c5f2e);
  box-shadow: 0 16px 24px -14px rgba(40, 20, 0, .6), inset 0 1px 0 rgba(255, 255, 255, .4);
}
.shelf-plank::after { content: ""; position: absolute; left: 0; right: 0; top: 100%; height: 5px; border-radius: 0 0 3px 3px; background: linear-gradient(#6d4620, rgba(109, 70, 32, 0)); }

.shelf-cap { min-height: 3.4em; margin-top: 20px; max-width: 680px; font: 400 14px/1.5 var(--mono); color: var(--ink-3); }
.shelf-cap b { display: block; font: 600 19px/1.35 var(--sans); color: var(--ink); letter-spacing: -0.01em; }

@media (prefers-color-scheme: dark) {
  .shelf-plank { background: linear-gradient(#8a6542, #6a4826 45%, #4c3219); box-shadow: 0 16px 28px -12px rgba(0, 0, 0, .9), inset 0 1px 0 rgba(255, 255, 255, .18); }
  .shelf-plank::after { background: linear-gradient(#3a2512, rgba(58, 37, 18, 0)); }
  .book::after { background: rgba(0, 0, 0, .6); }
}
@media (max-width: 700px) {
  .shelf-stage { --u: 1px; padding-top: 72px; }
  .built .shelf-books { padding-left: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  .book a, .book-spine::after { transition: none !important; }
  .book:hover a, .book a:focus-visible { transform: translateY(-10px); }
}
.shelf-head .label a { color: inherit; text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 4px; }
.shelf-head .label a:hover { color: var(--ink); text-decoration-color: var(--c2); }
