/* ==========================================================================
   Poetry: the shelf (/library/poetry/) and the reader (book.html).
   The page with the most soul: the serif, generous margins, and the gold
   used a little more freely than anywhere else. Tokens only.
   Markup: library/poetry/index.html, book.html and assets/scripts/poetry.js.
   ========================================================================== */

.poetry .page-title h1 em { font-style: italic; color: var(--gold-ink); }

/* The shelf ---------------------------------------------------------------- */
.shelf-section { padding-bottom: var(--space-8); }
.shelf {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 13rem), 1fr));
  gap: var(--space-8) var(--space-6);
  margin: 0;
  padding: 0;
  list-style: none;
}
.shelf .book { display: grid; gap: var(--space-4); align-content: start; }

/* Each cover stands on a plank: a hairline that runs the width of its
   column, so a row reads as one quiet shelf. */
.book__cover-wrap {
  position: relative;
  padding: 0 12% var(--space-2);
}
.book__cover-wrap::after {
  content: "";
  position: absolute;
  left: calc(var(--space-6) / -2);
  right: calc(var(--space-6) / -2);
  bottom: 0;
  height: 2px;
  background: var(--line-strong);
  opacity: 0.6;
}
.cover {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  aspect-ratio: 2 / 3;
  padding: 14% 12% 14% 18%;
  overflow: hidden;
  border-radius: var(--radius-sm) var(--radius) var(--radius) var(--radius-sm);
  background: var(--cloth-ink);
  color: var(--cloth-text);
  text-align: center;
  box-shadow: 0 1px 1px var(--page-shade), 0 14px 22px -14px var(--page-shade);
  transition: transform var(--dur-slow) var(--ease), box-shadow var(--dur-slow) var(--ease);
}
.cover--green { background: var(--cloth-green); }
.cover--umber { background: var(--cloth-umber); }
/* The spine: a darker band and a hinge line on the left edge. */
.cover::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 9%;
  background: linear-gradient(to right, var(--page-shade), transparent);
  border-right: 1px solid color-mix(in srgb, var(--cloth-text) 14%, transparent);
  z-index: 1;
}
.cover--art { padding: 0; }
.cover--art img { width: 100%; height: 100%; object-fit: cover; }
.cover__title {
  font-family: var(--font-serif);
  font-size: var(--step-2);
  line-height: var(--leading-tight);
  text-wrap: balance;
}
.cover__rule { width: 2.5rem; height: 1px; background: var(--gold); }
.cover__author {
  font-family: var(--font-mono);
  font-size: var(--step-n2);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  opacity: 0.85;
}
.shelf .book:hover .cover,
.shelf .book:focus-within .cover {
  transform: translateY(calc(var(--rise) * -1.5));
  box-shadow: 0 1px 1px var(--page-shade), 0 22px 28px -16px var(--page-shade);
}

.book__body { display: grid; gap: var(--space-2); }
.book__title { font-size: var(--step-2); }
.book__title a { color: var(--ink); text-decoration: none; }
.book__title a::before { content: ""; position: absolute; inset: 0; }
.shelf .book { position: relative; }
.shelf .book:hover .book__title a { color: var(--accent); }
.book__desc {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  color: var(--ink-2);
  font-family: var(--font-serif);
  font-size: var(--step-0);
}
.book__meta { display: flex; gap: var(--space-3); color: var(--gold-ink); }
.shelf__note { margin-top: var(--space-5); color: var(--ink-3); }

.shelf-close { padding-bottom: var(--space-section); }
.shelf-close .kuba { width: 10rem; margin: 0 0 var(--space-7); }

/* The reader ---------------------------------------------------------------- */
.poetry--reader main { display: flex; flex-direction: column; }
.reader { flex: 1; display: flex; flex-direction: column; padding-bottom: var(--space-6); }

.reader__bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: var(--space-4);
  padding-block: var(--space-4);
}
.reader__back {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  justify-self: start;
  color: var(--ink-3);
  font-size: var(--step-n1);
  text-decoration: none;
}
.reader__back:hover { color: var(--ink); }
.reader__back-icon { width: 1em; height: 1em; transform: rotate(180deg); }
.reader__where {
  font-size: var(--step-1);
  letter-spacing: 0;
  text-align: center;
  font-style: italic;
}
.reader__tools { display: flex; align-items: center; justify-self: end; gap: var(--space-2); }
.reader__full {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  border: var(--hairline) solid var(--line-strong);
  border-radius: var(--radius);
  background: none;
  color: var(--ink-2);
  font: inherit;
  font-size: var(--step-n1);
  cursor: pointer;
}
.reader__full[hidden] { display: none; }
.reader__full:hover { color: var(--ink); border-color: var(--ink); }
.reader__full-off, .reader--full .reader__full-on { display: none; }
.reader--full .reader__full-off { display: inline; }
@media (max-width: 47.99rem) { .reader__full span { display: none; } }
.reader__contents {
  padding: var(--space-1) var(--space-3);
  border: var(--hairline) solid var(--line-strong);
  border-radius: var(--radius);
  background: none;
  color: var(--ink-2);
  font: inherit;
  font-size: var(--step-n1);
  cursor: pointer;
}
.reader__contents:hover { color: var(--ink); border-color: var(--ink); }

/* No-JS summary: every collection, or only the one named in the URL hash. */
.reader__fallback { padding-block: var(--space-6) var(--space-8); }
.reader__fallback[hidden] { display: none; }
.reader__fallback:has(.summary:target) .summary:not(:target) { display: none; }
.summary { max-width: var(--measure); padding-block: var(--space-6); border-bottom: var(--hairline) solid var(--line); }
.summary__status:empty { display: none; }
.summary__status { color: var(--ink-3); }
.summary__kicker,
.titlepage__kicker,
.poem__from {
  font-family: var(--font-mono);
  font-size: var(--step-n2);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--gold-ink);
}
.summary__title { margin: var(--space-2) 0; font-size: var(--step-4); }
.summary__meta { color: var(--ink-3); }
.summary__desc { margin-block: var(--space-4); font-family: var(--font-serif); font-size: var(--step-1); color: var(--ink-2); }
.summary__h { margin-top: var(--space-5); font-size: var(--step-1); }
.summary__note { margin-top: var(--space-4); color: var(--ink-3); font-size: var(--step-n1); }
.summary__back { margin-top: var(--space-6); }

/* The room: turn buttons either side of the book on wide screens. */
.reader__room {
  flex: 1;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-4);
  width: 100%;
  max-width: calc(var(--wrap-wide) + 2 * var(--gutter));
  margin-inline: auto;
  padding: var(--space-2) var(--gutter) 0;
}
.reader__room[hidden] { display: none; }

.turn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: var(--hairline) solid var(--line-strong);
  border-radius: var(--radius-round);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.turn svg { width: 18px; height: 18px; }
.turn--prev svg { transform: rotate(180deg); }
.turn:hover:not(:disabled) { border-color: var(--gold); color: var(--gold-ink); }
.turn:disabled { opacity: 0.35; cursor: default; }
.turn--side { visibility: hidden; }
.reader--spread .turn--side { visibility: visible; }

/* The book. Pages have a fixed size so poems can be set into them. */
.reader .book {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  width: min(100%, 28rem);
  height: min(calc(100svh - 15rem), 40rem);
  min-height: 26rem;
  margin-inline: auto;
  perspective: 2400px;
  font-family: var(--font-serif);
  color: var(--ink);
}
.reader .book--spread {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  width: min(100%, 64rem);
  height: min(calc(100svh - 14rem), 44rem);
  perspective: 3600px;
}
.book__page { position: relative; min-width: 0; height: 100%; }
.book__page--right { display: none; }
.book--spread .book__page--right { display: block; }
.book__measure {
  position: absolute;
  top: 0;
  left: 0;
  visibility: hidden;
  pointer-events: none;
}

/* A page: warm paper, generous margins, a running head and a folio. */
.page {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: clamp(1.5rem, 1rem + 2.5vw, 3.25rem) clamp(1.25rem, 0.75rem + 2.5vw, 3rem) var(--space-5);
  background: color-mix(in srgb, var(--gold) 7%, var(--paper));
  box-shadow: 0 16px 36px -22px var(--page-shade);
  overflow: hidden;
}
.page--single { border-radius: var(--radius-sm) var(--radius) var(--radius) var(--radius-sm); box-shadow: inset 14px 0 18px -16px var(--page-shade), 0 16px 36px -22px var(--page-shade); }
.page--verso { border-radius: var(--radius) 0 0 var(--radius); box-shadow: inset -26px 0 26px -24px var(--page-shade), 0 16px 36px -22px var(--page-shade); }
.page--recto { border-radius: 0 var(--radius) var(--radius) 0; box-shadow: inset 26px 0 26px -24px var(--page-shade), 0 16px 36px -22px var(--page-shade); }
.page--blank { background: color-mix(in srgb, var(--gold) 7%, var(--paper)); }
.page__head {
  margin-bottom: var(--space-4);
  font-size: var(--step-n1);
  font-style: italic;
  color: var(--ink-3);
  text-align: center;
}
.page__body { flex: 1; min-height: 0; overflow: hidden; }
.page__folio {
  margin-top: var(--space-3);
  font-family: var(--font-mono);
  font-size: var(--step-n2);
  color: var(--ink-3);
  text-align: center;
}

/* A small raffia-gold lozenge between title and verse. */
.ornament {
  display: block;
  width: 7px;
  height: 7px;
  margin: var(--space-4) auto;
  background: var(--gold);
  transform: rotate(45deg);
}

.titlepage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: 100%;
  text-align: center;
}
/* The cover above the title (one page at a time) gives way first: it
   shrinks to the room the words leave, so nothing runs off the page. */
.titlepage > * { flex-shrink: 0; }
.titlepage > .titlepage__art { display: flex; justify-content: center; flex: 0 1 auto; min-height: 0; width: 58%; margin-bottom: var(--space-4); }
.titlepage__art img { width: auto; max-width: 100%; height: auto; max-height: 100%; object-fit: contain; border-radius: var(--radius-sm); }
.titlepage__title { font-size: var(--step-4); line-height: var(--leading-tight); text-wrap: balance; }
.titlepage__sub { max-width: 30ch; color: var(--ink-2); font-style: italic; }
.titlepage__author { margin-top: var(--space-4); font-size: var(--step-0); color: var(--ink-2); }
.titlepage__year { display: block; font-family: var(--font-mono); font-size: var(--step-n2); color: var(--ink-3); }

.front-heading { margin: var(--space-2) 0 var(--space-5); font-size: var(--step-2); text-align: center; letter-spacing: 0; }
.preface p { font-size: var(--step-0); line-height: var(--leading-verse); color: var(--ink-2); }
.preface p + p { margin-top: var(--space-4); }

.toc { margin: 0; padding: 0; list-style: none; }
.toc li + li { margin-top: var(--space-3); }
.toc a,
.toc--static li { display: flex; align-items: baseline; gap: var(--space-2); color: var(--ink); text-decoration: none; }
.toc a:hover .toc__title { color: var(--accent); }
.toc__title { font-size: var(--step-0); }
.toc__lead { flex: 1; border-bottom: 1px dotted var(--line-strong); transform: translateY(-0.3em); }
.toc__page { font-family: var(--font-mono); font-size: var(--step-n1); color: var(--ink-3); }
.toc--static { counter-reset: poem; }
.toc--static li::before { counter-increment: poem; content: counter(poem) "."; width: 1.5rem; flex: none; font-family: var(--font-mono); font-size: var(--step-n1); color: var(--ink-3); }

/* The picture fits the page whatever its shape: the first row takes the
   height the caption leaves, and the image scales down inside it. */
.plate { display: grid; grid-template-rows: minmax(0, 1fr) auto; place-items: center; height: 100%; gap: var(--space-3); }
.plate img { max-width: 100%; max-height: 100%; width: auto; height: auto; object-fit: contain; border-radius: var(--radius-sm); }
.plate figcaption { font-size: var(--step-n1); font-style: italic; color: var(--ink-3); text-align: center; }

/* Verse. .verse (site.css) sets the serif and the long line height. */
.page .verse { max-width: none; font-size: var(--step-0); }
.poem__from { text-align: center; }
.poem__title { margin-top: var(--space-2); font-size: var(--step-2); text-align: center; letter-spacing: 0; }
.poem__epigraph { margin-bottom: var(--space-5); font-size: var(--step-0); font-style: italic; color: var(--ink-3); text-align: center; }
.stanza + .stanza { margin-top: 1.1em; }
.line { display: block; padding-left: 1.5em; text-indent: -1.5em; }

.fin { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; text-align: center; }
.fin__word { font-size: var(--step-2); }
.fin__sign { margin-top: var(--space-4); font-style: italic; color: var(--ink-2); }
.fin__sign span { display: block; font-size: var(--step-2); font-style: normal; color: var(--ink); }
.fin__links { display: grid; gap: var(--space-2); margin: var(--space-7) 0 0; padding: 0; list-style: none; font-family: var(--font-sans); font-size: var(--step-n1); }

/* Endpapers: the Kuba lattice, in gold, very quietly. */
.endpaper { position: absolute; inset: 0; }
.endpaper:not(.endpaper--art):not(.endpaper--cover)::before {
  content: "";
  position: absolute;
  inset: 0;
  background-color: var(--gold);
  opacity: 0.22;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 48 48'%3E%3Cg fill='none' stroke='%23000' stroke-width='1.25'%3E%3Cpath d='M0 24 24 0 48 24 24 48Z'/%3E%3Cpath d='M12 24 24 12 36 24 24 36Z'/%3E%3C/g%3E%3Crect x='21' y='21' width='6' height='6' transform='rotate(45 24 24)'/%3E%3C/svg%3E") repeat 0 0 / 48px 48px;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 48 48'%3E%3Cg fill='none' stroke='%23000' stroke-width='1.25'%3E%3Cpath d='M0 24 24 0 48 24 24 48Z'/%3E%3Cpath d='M12 24 24 12 36 24 24 36Z'/%3E%3C/g%3E%3Crect x='21' y='21' width='6' height='6' transform='rotate(45 24 24)'/%3E%3C/svg%3E") repeat 0 0 / 48px 48px;
}
.endpaper--art .plate { padding: var(--space-6); }
/* No cover picture: the cloth cover from the shelf, as large as the page allows. */
.endpaper--cover { display: grid; place-items: center; padding: var(--space-6); }
.endpaper--cover .cover { height: 100%; width: auto; max-width: 100%; aspect-ratio: 2 / 3; }
.endpaper--cover .cover__title { font-size: var(--step-3); }
.endpaper--cover .cover__author { font-size: var(--step-n1); }

/* The turning leaf ----------------------------------------------------------- */
.leaf {
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 3;
  transform-style: preserve-3d;
  will-change: transform;
  pointer-events: none;
}
.leaf--right { left: 50%; width: 50%; transform-origin: left center; }
.leaf--left { left: 0; width: 50%; transform-origin: right center; }
.leaf--single { left: 0; width: 100%; transform-origin: left center; }
.leaf__face {
  position: absolute;
  inset: 0;
  -webkit-backface-visibility: hidden;
          backface-visibility: hidden;
}
.leaf__face--back { transform: rotateY(180deg); }
.leaf__shade {
  position: absolute;
  inset: 0;
  z-index: 2;
  opacity: 0;
  pointer-events: none;
}
.leaf--right .leaf__face--front .leaf__shade,
.leaf--single .leaf__face--front .leaf__shade { background: linear-gradient(to left, var(--page-shade), transparent 70%); }
.leaf--right .leaf__face--back .leaf__shade { background: linear-gradient(to right, var(--page-shade), transparent 70%); }
.leaf--left .leaf__face--front .leaf__shade { background: linear-gradient(to right, var(--page-shade), transparent 70%); }
.leaf--left .leaf__face--back .leaf__shade { background: linear-gradient(to left, var(--page-shade), transparent 70%); }

.book__cast { position: absolute; inset: 0; z-index: 2; pointer-events: none; opacity: 0; }
.book__page--right .book__cast,
.reader .book:not(.book--spread) .book__page--left .book__cast { background: linear-gradient(to right, var(--page-shade), transparent 55%); }
.book--spread .book__page--left .book__cast { background: linear-gradient(to left, var(--page-shade), transparent 55%); }

.book__ghost {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  pointer-events: none;
}
.book__ghost--spread { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }

/* The foot: count, progress, and the turn buttons on small screens. */
.reader__foot {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  max-width: 44rem;
  margin: var(--space-5) auto 0;
}
.reader__foot[hidden] { display: none; }
.reader__count { flex: none; color: var(--ink-3); }
.reader__progress {
  flex: 1;
  height: 2px;
  overflow: hidden;
  border-radius: var(--radius-round);
  background: var(--line);
}
.reader__progress span {
  display: block;
  height: 100%;
  background: var(--gold);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform var(--dur-slow) var(--ease);
}
.reader__keys { flex: none; color: var(--ink-3); font-size: var(--step-n2); }
.reader__keys kbd {
  padding: 0 var(--space-1);
  border: var(--hairline) solid var(--line-strong);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: var(--step-n2);
}
.reader--spread .reader__foot .turn { display: none; }
@media (max-width: 47.99rem) {
  .reader__keys { display: none; }
  .reader__room { padding-inline: var(--gutter); grid-template-columns: minmax(0, 1fr); }
  .turn--side { display: none; }
  .reader .book { height: min(calc(100svh - 13rem), 38rem); }
}

/* Full screen on a phone ------------------------------------------------------
   poetry.js adds .reader--immersive once a book is open on a narrow screen:
   the page fills the display, and the bars (back, title, contents above;
   count and progress below) float over it, shown by a tap in the middle
   (.reader--chrome) and hidden again by a turn or after a few seconds. */
html.reading-immersive,
html.reading-immersive body { overflow: hidden; overscroll-behavior: none; }
.reader--immersive {
  position: fixed;
  inset: 0;
  z-index: 100;
  padding: 0;
  background: color-mix(in srgb, var(--gold) 7%, var(--paper));
  -webkit-user-select: none;
          user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.reader--immersive .reader__room {
  display: block;
  flex: 1;
  min-height: 0;
  max-width: none;
  padding: 0;
}
.reader--immersive .book {
  width: 100%;
  height: 100%;
  min-height: 0;
}
.reader--immersive .page {
  border-radius: 0;
  box-shadow: none;
  padding: calc(env(safe-area-inset-top, 0px) + var(--space-7)) var(--space-5) calc(env(safe-area-inset-bottom, 0px) + var(--space-4));
}
.reader--immersive .book__cast { display: none; }

.reader--immersive .reader__bar,
.reader--immersive .reader__foot {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 5;
  max-width: none;
  margin: 0;
  background: color-mix(in srgb, var(--paper) 94%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
          backdrop-filter: saturate(1.4) blur(12px);
  transition: opacity var(--dur-slow) var(--ease), transform var(--dur-slow) var(--ease);
}
.reader--immersive .reader__bar {
  top: 0;
  padding: calc(env(safe-area-inset-top, 0px) + var(--space-2)) var(--space-4) var(--space-2);
  border-bottom: var(--hairline) solid var(--line);
}
.reader--immersive .reader__where { font-size: var(--step-0); }
.reader--immersive .reader__foot {
  bottom: 0;
  padding: var(--space-3) var(--space-4) calc(env(safe-area-inset-bottom, 0px) + var(--space-3));
  border-top: var(--hairline) solid var(--line);
}
.reader--immersive:not(.reader--chrome) .reader__bar { opacity: 0; transform: translateY(-100%); pointer-events: none; }
.reader--immersive:not(.reader--chrome) .reader__foot { opacity: 0; transform: translateY(100%); pointer-events: none; }

/* Browser full screen ----------------------------------------------------------
   The reader alone fills the screen: the room behind the book takes the
   page's paper colour and the book grows to use the height. */
.reader--full {
  overflow: auto;
  padding-bottom: var(--space-4);
  background: var(--paper);
}
.reader--full .reader__bar { padding-block: var(--space-3); }
.reader--full:not(.reader--immersive) .book { height: calc(100vh - 9rem); max-height: none; width: min(100%, calc((100vh - 9rem) * 0.72)); }
.reader--full:not(.reader--immersive) .book--spread { width: min(100%, calc((100vh - 9rem) * 1.44)); }
.reader--full .reader__foot { margin-top: var(--space-3); }
