/* Book shelf tile (work/js/bookshelf.js) and its reader (work/js/flipbook.js). */

/* the caption is set like the reference: Newsreader for the title, Inter Tight for the
   small capitals, the site's deep lavender for the honours (Laura, 2026-11-19: the one
   accent, so the shelf matches the rest of lauragao.design) */
.tile--books {
  --paper: #edebe6; --cobalt: #6d47d1; --lavender: #cdbaff; --lavender-2: #b8a0ff; --ink-2: #141414;
  --serif: 'Newsreader', Georgia, serif; --tight: 'Inter Tight', 'Figtree', system-ui, sans-serif;
  background: var(--paper); container-type: inline-size;
}

/* paper grain, on the paper only: over the books it greyed their colours (Laura, 2026-11-19) */
.tile--books::before, .reader::after {
  content: ''; position: absolute; inset: 0; z-index: 0; pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .45 0 0 0 0 .42 0 0 0 0 .38 0 0 0 .22 0'/%3E%3C/filter%3E%3Crect width='220' height='220' filter='url(%23n)'/%3E%3C/svg%3E");
  opacity: .55;
}

.shelf { position: absolute; inset: 0; z-index: 1; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.shelf__view { position: absolute; inset: 0; }
.shelf__stage { position: absolute; left: 50%; width: 0; height: 0; transform-style: preserve-3d; }
/* each book's soft contact shadow on the shelf */
.shelf__shadow {
  position: absolute; left: 0; top: 0; pointer-events: none;
  background: radial-gradient(closest-side, rgb(40 28 14 / .42), rgb(40 28 14 / .14) 60%, transparent);
  opacity: var(--sh, .9);
}

.bk {
  position: absolute; left: 0; top: 0; width: 0; height: 0;
  transform-style: preserve-3d; will-change: transform;
}
.shelf { cursor: grab; }
.shelf.is-over-spine { cursor: pointer; }
.shelf.is-turning { cursor: grabbing; }
.bk:focus { outline: none; }
.bk:focus-visible .bk__spine, .bk.is-open:focus-visible .bk__cover { outline: 2px solid var(--ink-2); outline-offset: 3px; }
/* the faces are Laura's photos of the books, worn like well-read paperbacks */
.bk__face {
  position: absolute; top: calc(var(--H) / -2); height: var(--H);
  background: center / 100% 100% no-repeat;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border-radius: 3px;
}
.bk__face::after {
  content: ''; position: absolute; inset: 0; border-radius: inherit; background: #000; pointer-events: none;
}
/* the spine: the front of the box as it stands on the shelf */
.bk__spine {
  width: var(--ws); left: calc(var(--ws) / -2);
  transform: translateZ(calc(var(--d) / 2));
  border-radius: 4px;
  /* the rounded spine catches the light down its middle */
  box-shadow: inset 2px 0 2px rgb(255 255 255 / .18), inset -2px 0 3px rgb(0 0 0 / .22);
}
.bk__spine::after { opacity: var(--spine-shade, 0); }
/* the front cover: the right side of the box, turned out when the book is open */
.bk__cover {
  width: var(--d); left: calc(var(--d) / -2);
  transform: rotateY(90deg) translateZ(calc(var(--ws) / 2));
  box-shadow: 0 calc(var(--H) * .07) calc(var(--H) * .14) calc(var(--H) * -.065) rgb(20 16 10 / .5);
}
/* the back cover: the left side, seen when the book is turned over */
.bk__back {
  width: var(--d); left: calc(var(--d) / -2);
  transform: rotateY(-90deg) translateZ(calc(var(--ws) / 2));
  box-shadow: 0 calc(var(--H) * .07) calc(var(--H) * .14) calc(var(--H) * -.065) rgb(20 16 10 / .5);
}
.bk__cover::after, .bk__back::after { opacity: var(--cover-shade, 0); }
/* the jacket's gloss: a soft band of light that slides as the book tilts */
.bk__cover::before, .bk__back::before {
  content: ''; position: absolute; inset: 0; z-index: 1; border-radius: inherit; pointer-events: none;
  background: linear-gradient(105deg, transparent 40%, rgb(255 255 255 / .08) 48%, rgb(255 255 255 / .02) 54%, transparent 60%) var(--sheen, 50%) 0 / 260% 100% no-repeat;
}
/* the pages: the fore-edge opposite the spine, and the top of the book, both from Laura's
   photos of the page block between the boards (seen as the book is turned round) */
.bk__fore {
  width: var(--ws); left: calc(var(--ws) / -2);
  transform: rotateY(180deg) translateZ(calc(var(--d) / 2));
  border-radius: 3px;
}
.bk__fore::after { opacity: .12; }
.bk__top {
  width: var(--ws); height: var(--d); left: calc(var(--ws) / -2); top: calc(var(--d) / -2);
  transform: rotateX(90deg) translateZ(calc(var(--H) / 2));
  border-radius: 2px;
}
.bk__top::after { opacity: 0; }

/* phones: one column, so the shelf can be square and the books bigger */
@media (max-width: 809.98px) {
  .tile--books { aspect-ratio: 1 / 1 !important; }
}

/* caption under the shelf: each line slides through its own mask */
.shelf__cap {
  position: absolute; left: 14px; right: 14px; top: 75%;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  text-align: center; pointer-events: none; z-index: 3;
}
.shelf__mask { position: relative; overflow: hidden; width: 100%; }
.shelf__mask > span { display: block; }
.shelf__mask > span + span { position: absolute; inset: 0; }
.shelf__mask--title {
  font-family: var(--serif); font-weight: 400; font-optical-sizing: auto;
  font-size: clamp(18px, 4.6cqw, 27px); line-height: 1.12; letter-spacing: -0.01em; color: var(--ink-2);
}
.shelf__mask--sub {
  font-family: var(--tight); font-weight: 500; font-size: 10px; line-height: 1.35;
  letter-spacing: .09em; text-transform: uppercase; color: var(--cobalt);
}
.shelf__mask--year {
  font-family: var(--tight); font-weight: 500; font-size: 11px; line-height: 1.2;
  letter-spacing: .08em; color: var(--ink-2);
}

/* ---------- reader ---------- */

.reader {
  position: fixed; inset: 0; z-index: 60;
  background: #f4f2ed; color: var(--ink, #0d0c0a);
  display: grid; grid-template-rows: 64px 1fr 64px;
  font-family: var(--sans, 'Figtree', system-ui, sans-serif);
  overscroll-behavior: contain; touch-action: pinch-zoom; /* one finger turns pages; two still zoom in to read */
}
.reader[hidden] { display: none; }
.reader:focus { outline: none; }
/* in the reader the grain stays on the paper, under the pages, so they read sharp */
.reader::after { position: fixed; z-index: 0; }
.reader > * { position: relative; z-index: 1; }
html.has-reader, html.has-reader body { overflow: hidden; }

.reader__bar {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 0 20px; gap: 12px; overflow: hidden;
}
.reader__nav { display: flex; align-items: center; justify-content: center; gap: 18px; overflow: hidden; }
.reader__bar > *, .reader__links > *, .reader__nav > * { will-change: transform; }
.reader__close, .reader__arrow {
  all: unset; cursor: pointer; box-sizing: border-box;
  min-height: 44px; min-width: 44px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 999px; transition: background-color .25s ease;
}
.reader__close { justify-self: start; padding: 0 16px; font-size: 15px; font-weight: 600; }
.reader__close:hover, .reader__arrow:hover:not(:disabled) { background: rgb(0 0 0 / .06); }
.reader__close:focus-visible, .reader__arrow:focus-visible, .reader__more:focus-visible, .reader__buy:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }
.reader__title { font-size: 15px; font-weight: 600; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 46vw; }
.reader__links { justify-self: end; display: flex; align-items: center; gap: 14px; }
.reader__more { font-size: 15px; font-weight: 500; color: var(--muted, #6f6c66); text-decoration: underline; text-underline-offset: 3px; padding: 10px 2px; }
.reader__more:hover { color: var(--ink, #0d0c0a); }
/* buy: to the book's page at HarperCollins */
.reader__buy {
  display: inline-flex; align-items: center; min-height: 40px; padding: 0 18px; border-radius: 999px;
  background: var(--lavender, #cdbaff); color: #16140f; font-size: 15px; font-weight: 600; white-space: nowrap;
  transition: background-color .25s ease;
}
.reader__buy:hover { background: var(--lavender-2, #b8a0ff); }

.reader__stage { position: relative; min-height: 0; cursor: grab; }
.reader__stage:active { cursor: grabbing; }
.reader__pages, .reader__ink { position: absolute; inset: 0; width: 100%; height: 100%; }
.reader__ink { z-index: 4; pointer-events: none; }
.reader__ink[hidden] { display: none; }

/* the end page's links, over where the page draws them */
.reader__endlinks[hidden], .reader__next[hidden] { display: none; }
.reader__nextwrap:has(.reader__next[hidden]) { display: none; }
.reader__endlink {
  position: absolute; z-index: 5; color: transparent; overflow: hidden; white-space: nowrap;
  border-radius: 4px;
}
.reader__endlink:hover { background: rgb(31 63 176 / .06); }
.reader__endlink:focus-visible { outline: 2px solid #6d47d1; outline-offset: 2px; }
/* at the end, the other book: in the bottom bar's right end, beside the arrows, so it never
   lands on the pages (Laura, 2026-11-19); one line, the title cut short if it must be */
.reader__nav { position: relative; }
.reader__nextwrap {
  position: absolute; right: 16px; top: 50%; transform: translateY(-50%);
  max-width: calc(50% - 190px); overflow: hidden; padding: 4px;
}
.reader__next {
  all: unset; cursor: pointer; box-sizing: border-box; max-width: 100%;
  display: flex; align-items: baseline; gap: 10px; min-height: 44px; padding: 0 12px 0 14px; border-radius: 999px;
  transition: background-color .25s ease;
}
.reader__next:hover { background: rgb(0 0 0 / .05); }
.reader__next:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }
.reader__next-label {
  flex: none; font-family: 'Inter Tight', 'Figtree', sans-serif; font-weight: 500; font-size: 11px;
  letter-spacing: .09em; text-transform: uppercase; color: #6d47d1; align-self: center;
}
.reader__next-title {
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: 'Newsreader', Georgia, serif; font-size: 18px; line-height: 44px; color: #141414;
}
.reader__next-chev { flex: none; align-self: center; color: #141414; transition: transform .35s cubic-bezier(.2,.8,.2,1); }
.reader__next:hover .reader__next-chev { transform: translateX(3px); }

.reader__arrow { width: 44px; }
/* at the end of a book the next arrow names where it goes */
.reader__arrow-label { display: none; }
.reader__arrow.is-book { width: auto; padding: 0 14px; gap: 10px; font-size: 14px; font-weight: 600; }
.reader__arrow.is-book .reader__arrow-label { display: inline; }
.reader__arrow:disabled { cursor: default; color: rgb(0 0 0 / .25); }
.reader__count { font-size: 14px; font-weight: 500; color: var(--muted, #6f6c66); min-width: 150px; text-align: center; font-variant-numeric: tabular-nums; }

@media (max-width: 600px) {
  .reader__bar { padding: 0 8px; grid-template-columns: auto 1fr; }
  .reader__title, .reader__more { display: none; }
}
/* one page at a time the page fills the width: the next book sits under it, by the arrows */
/* one page at a time the page fills the width, so the arrow does it alone */
@media (max-width: 759.98px), (orientation: portrait) and (max-width: 1100px) {
  .reader__nextwrap { display: none; }
}
