/* Library page. Two views of the same books:
   "library": a 3D library behind the page text (library.js draws it);
   "list": a plain contents list, also used when WebGL is not available.
   The <html> element's data-view attribute says which one is showing. */

/* ---------- The bar under the title: genres, the view switch and the search ---------- */

.shelf-bar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--line) 3ch;
}

.genre-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0 2.5ch;
  font-family: var(--font-caps);
  letter-spacing: 0.06em;
  text-transform: lowercase;
}

.genre-nav a {
  text-decoration: none;
}

.genre-nav a:hover {
  text-decoration: underline;
  opacity: 1;
}

.genre-nav a[aria-current] {
  text-decoration: underline;
}

.count {
  margin-left: 0.6ch;
  font-family: var(--font-text);
  font-size: 0.875rem;
  letter-spacing: 0;
  text-transform: none;
  opacity: 0.5;
}

/* The view switch and the search: icons on the right of the bar, level
   with its first line. */
.shelf-tools {
  display: flex;
  flex: none;
  align-self: flex-start;
  align-items: center;
  gap: 1.75ch;
  height: var(--line);
}

.icon-button {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 0.7ch;
  height: var(--line);
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  opacity: 0.6;
  cursor: pointer;
  transition: opacity 160ms ease;
}

/* The view switch is hidden where the space cannot be drawn. */
.icon-button[hidden] {
  display: none;
}

.icon-button:hover {
  opacity: 1;
}

.icon {
  width: 1.125rem;
  height: 1.125rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon .dot {
  fill: currentColor;
  stroke: none;
}

.icon-button:focus-visible,
.genre-nav a:focus-visible,
.library-label:focus-visible,
.book-card button:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 3px;
}

/* ---------- Library view ---------- */

.library-stage,
.library-caption,
.library-hint,
.book-card {
  display: none;
}

:root[data-view="library"] {
  overflow: hidden;
}

:root[data-view="library"] body {
  overflow: hidden;
  height: 100svh;
}

:root[data-view="library"] .page-shell {
  position: relative;
  z-index: 1;
  padding-bottom: 0;
  pointer-events: none;
}

:root[data-view="library"] .site-header,
:root[data-view="library"] .shelf-bar {
  pointer-events: auto;
}

:root[data-view="library"] .page-header {
  margin-bottom: var(--line);
}

:root[data-view="library"] .book-list {
  display: none;
}

:root[data-view="library"] .library-stage {
  display: block;
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  /* The page fades in once the first frame is drawn. */
  opacity: 0;
  transition: opacity 1200ms ease;
}

:root[data-view="library"] .library-stage.is-ready {
  opacity: 1;
}

.library-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: default;
}

.library-canvas.is-pointing {
  cursor: pointer;
}

.library-canvas.is-dragging {
  cursor: grabbing;
}

/* The header and title stay readable over the scene. */
.library-scrim {
  position: absolute;
  inset: 0 0 auto;
  height: 15rem;
  background: linear-gradient(
    to bottom,
    var(--background) 0,
    color-mix(in srgb, var(--background) 92%, transparent) var(--solid, 40%),
    transparent 100%
  );
  pointer-events: none;
}

/* Words that float in the scene: genre names over each bookcase,
   and a subgenre name at the start of each shelf. */
.library-labels {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.library-label {
  position: absolute;
  top: 0;
  left: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--text);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 500ms ease;
  will-change: transform;
  /* The words stand on whatever the space shows behind them, at times its
     brightest streaks. A halo in the page's own dark, dense around each
     letter (the tightest shadows are doubled to make it so) and fading out
     from it, keeps them legible there, as the names on a map are over its
     picture; on the dark it does not show. Fainter words are dimmed by their
     colour rather than their opacity, so their halo stays whole. */
  text-shadow:
    0 0 1px var(--background),
    0 0 1px var(--background),
    0 0 2px var(--background),
    0 0 2px var(--background),
    0 0 4px var(--background),
    0 0 8px var(--background),
    0 0 16px var(--background),
    0 0 28px color-mix(in srgb, var(--background) 60%, transparent);
}

.library-label .count {
  color: color-mix(in srgb, var(--text) 55%, var(--background));
  opacity: 1;
}

.library-label.is-visible {
  opacity: 1;
  pointer-events: auto;
  cursor: pointer;
}

.library-label.genre-label {
  font-family: var(--font-caps);
  font-size: 1.125rem;
  letter-spacing: 0.075em;
  text-transform: lowercase;
}

/* A shelf's name is small, italic and thin-stroked, the hardest to read
   over a bright streak. It is set in the full colour of the text, and a
   soft patch of the page's dark, fading out at its edges, lies behind it
   besides its halo. */
.library-label.shelf-label {
  font-family: var(--font-text);
  font-size: 0.9375rem;
  font-style: italic;
}

.library-label.shelf-label::before {
  content: "";
  position: absolute;
  inset: -0.45em -1.1em;
  z-index: -1;
  background: radial-gradient(
    closest-side,
    color-mix(in srgb, var(--background) 80%, transparent) 45%,
    transparent
  );
  pointer-events: none;
}

/* The layers of a bookcase with more rows than it is tall, numbered at the
   top right of its first row. The one in front is lit; choosing another
   steps through to it. Only its numerals take clicks. */
.library-label.layer-label {
  display: flex;
  gap: 0.6ch;
  font-family: var(--font-caps);
  font-size: 1rem;
  letter-spacing: 0.075em;
  pointer-events: none;
}

.library-label.layer-label.is-visible {
  cursor: default;
}

.library-label.layer-label:hover {
  text-decoration: none;
}

.layer-label button {
  padding: 0 0.2ch;
  border: 0;
  background: none;
  color: color-mix(in srgb, var(--text) 45%, var(--background));
  font: inherit;
  letter-spacing: inherit;
  text-shadow: inherit;
  cursor: pointer;
  transition: color 300ms ease;
}

.layer-label.is-visible button {
  pointer-events: auto;
}

.layer-label button:hover,
.layer-label button.is-current {
  color: var(--text);
}

.layer-label button:hover {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.library-label:hover {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.library-caption,
.library-hint {
  position: fixed;
  left: 50%;
  z-index: 2;
  max-width: calc(100vw - 6ch);
  margin: 0;
  transform: translateX(-50%);
  text-align: center;
  pointer-events: none;
}

:root[data-view="library"] .library-caption,
:root[data-view="library"] .library-hint {
  display: block;
}

.library-caption {
  bottom: calc(var(--line) * 2.5);
  padding: 0.2rem 1.5ch;
  border-radius: 999px;
  background: color-mix(in srgb, var(--background) 80%, transparent);
  font-style: italic;
  opacity: 0;
  transition: opacity 200ms ease;
}

.library-caption.is-visible {
  opacity: 1;
}

.library-caption .who {
  font-family: var(--font-caps);
  font-style: normal;
  letter-spacing: 0.05em;
  text-transform: lowercase;
}

.library-hint {
  bottom: var(--line);
  font-size: 0.8125rem;
  font-style: italic;
  opacity: 0.4;
  transition: opacity 600ms ease;
}

/* The card for the book that has been pulled from the shelf. */
:root[data-view="library"] .book-card:not([hidden]) {
  display: block;
}

.book-card {
  position: fixed;
  top: 50%;
  right: max(3ch, calc((100vw - 72ch) / 2 - 12ch));
  z-index: 3;
  width: min(32ch, 40vw);
  max-height: 70svh;
  overflow-y: auto;
  padding: var(--line) 3ch;
  background: color-mix(in srgb, var(--background) 88%, transparent);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  transform: translateY(-50%);
  animation: card-in 500ms ease both;
  scrollbar-width: thin;
}

@keyframes card-in {
  from { opacity: 0; transform: translate(1.5ch, -50%); }
  to { opacity: 1; transform: translate(0, -50%); }
}

.book-card-close {
  position: absolute;
  top: calc(var(--line) * 0.6);
  right: 1.5ch;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: 1.5rem/1 var(--font-text);
  opacity: 0.5;
  cursor: pointer;
}

.book-card-close:hover {
  opacity: 1;
}

.book-card-shelf {
  font-family: var(--font-caps);
  font-size: 0.875rem;
  letter-spacing: 0.075em;
  text-transform: lowercase;
  opacity: 0.55;
}

.book-card p + p {
  margin-top: 0;
}

.book-card-title {
  margin-top: calc(var(--line) / 2);
  padding-right: 2ch;
  font-size: 1.5rem;
  font-style: italic;
  line-height: calc(var(--line) * 1.35);
  text-wrap: balance;
}

.book-card-title.is-story {
  font-style: normal;
}

.book-card-meta {
  margin-top: calc(var(--line) / 3);
}

.book-card-meta .who {
  font-family: var(--font-caps);
  letter-spacing: 0.05em;
  text-transform: lowercase;
}

.book-card-meta .year {
  opacity: 0.6;
}

/* The link to a recording: small capitals, like the card's other labels. */
.book-card-meta .listen {
  display: inline-block;
  margin-top: calc(var(--line) / 3);
  font-family: var(--font-caps);
  letter-spacing: 0.05em;
}

/* In the list, a piece's title links to its recording. The underline is
   faint, so the list still reads as a table of contents. */
.contents a.recording {
  text-decoration-color: color-mix(in srgb, currentColor 28%, transparent);
}

.contents a.recording:hover {
  opacity: 1;
  text-decoration-color: currentColor;
}

.book-card-series {
  margin-top: var(--line);
}

.book-card-series:empty {
  display: none;
}

.book-card-series .series-name {
  font-size: 0.9375rem;
  opacity: 0.6;
}

.book-card-series ol {
  margin: calc(var(--line) / 4) 0 0;
  padding: 0;
  list-style: none;
  counter-reset: volume;
  font-size: 0.9375rem;
}

.book-card-series li {
  display: flex;
  gap: 1ch;
  counter-increment: volume;
}

.book-card-series li::before {
  content: counter(volume, lower-roman);
  flex: none;
  width: 3.5ch;
  font-size: 0.8125rem;
  text-align: right;
  opacity: 0.45;
}

.book-card-series button {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: italic 0.9375rem/var(--line) var(--font-text);
  text-align: left;
  opacity: 0.6;
  cursor: pointer;
}

.book-card-series button:hover,
.book-card-series li[aria-current] button {
  opacity: 1;
}

.book-card-series li[aria-current] button {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

@media (max-width: 720px) {
  .book-card {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: auto;
    max-height: 45svh;
    padding: var(--line) 3ch calc(var(--line) * 1.5);
    transform: none;
    animation-name: card-up;
  }

  @keyframes card-up {
    from { opacity: 0; transform: translateY(1.5rem); }
    to { opacity: 1; transform: none; }
  }

  .shelf-bar {
    flex-direction: column;
    gap: calc(var(--line) / 2);
  }
}

@media (prefers-reduced-motion: reduce) {
  .library-stage,
  .library-label,
  .library-caption,
  .library-hint {
    transition: none !important;
  }

  .book-card {
    animation: none;
  }
}

/* ---------- Search ---------- */

/* The key that opens the search, after its icon: a key cap with the space
   symbol (␣). Space opens the search only in the space, and only where
   there is a keyboard. */
.search-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  height: 0.95rem;
  padding: 0 0.3rem;
  border: 1px solid color-mix(in srgb, var(--text) 40%, transparent);
  border-radius: 3px;
}

.search-key svg {
  width: 0.75rem;
  height: 0.45rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

:root[data-view="list"] .search-key {
  display: none;
}

@media (pointer: coarse), (hover: none) {
  .search-key {
    display: none;
  }
}

/* The panel: a rounded card near the top of the screen, over the dimmed
   page. It settles in, and fades out a little faster. */
.search {
  width: min(56ch, calc(100vw - 4ch));
  max-width: none;
  max-height: calc(100svh - min(18svh, 9rem) - var(--line) * 2);
  margin: min(18svh, 9rem) auto auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--text) 11%, transparent);
  border-radius: 16px;
  background: color-mix(in srgb, var(--background) 86%, transparent);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  backdrop-filter: blur(16px) saturate(1.2);
  color: var(--text);
  box-shadow:
    0 0.5rem 1.5rem rgb(0 0 0 / 0.25),
    0 2rem 5rem rgb(0 0 0 / 0.45);
  transform-origin: 50% 0;
}

.search::backdrop {
  background: rgb(0 0 0 / 0.4);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

.search[open] {
  display: flex;
  flex-direction: column;
  animation: search-in 320ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.search[open]::backdrop {
  animation: fade-in 320ms ease both;
}

/* Closing: search.js adds is-closing, and closes the panel when search-out
   ends. */
.search.is-closing {
  animation: search-out 180ms cubic-bezier(0.4, 0, 1, 1) both;
}

.search.is-closing::backdrop {
  animation: fade-out 180ms ease both;
}

@keyframes search-in {
  from { opacity: 0; transform: translateY(-0.75rem) scale(0.97); }
  to { opacity: 1; transform: none; }
}

@keyframes search-out {
  from { opacity: 1; transform: none; }
  to { opacity: 0; transform: translateY(-0.4rem) scale(0.98); }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* The field: a magnifying glass, then what is typed. */
.search-field {
  display: flex;
  flex: none;
  align-items: center;
  gap: 1.25ch;
  padding: 0 2.5ch;
  border-bottom: 1px solid color-mix(in srgb, var(--text) 11%, transparent);
}

.search-field .icon {
  flex: none;
  opacity: 0.5;
}

.search-input {
  flex: 1;
  min-width: 0;
  box-sizing: border-box;
  padding: calc(var(--line) * 0.75) 0;
  border: 0;
  background: none;
  color: inherit;
  font: italic 1.25rem/1.4 var(--font-text);
}

.search-input::placeholder {
  color: inherit;
  opacity: 0.4;
}

.search-input:focus {
  outline: none;
}

.search-results {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0.4rem;
  scrollbar-width: thin;
}

.search-results:empty {
  display: none;
}

/* Each result is a rounded row, lit when chosen with the keys or the pointer. */
.search-result {
  padding: calc(var(--line) / 4) calc(2.5ch - 0.4rem);
  border-radius: 10px;
  cursor: pointer;
  transition: background-color 120ms ease;
}

.search-result::before {
  content: none;
}

.search-result[aria-selected="true"] {
  background: color-mix(in srgb, var(--text) 8%, transparent);
}

.search-title {
  display: block;
  font-style: italic;
}

.search-title.is-roman {
  font-style: normal;
}

/* A shelf or a bookcase, in small capitals, as the bookcases' names are. */
.search-title.is-place {
  font-family: var(--font-caps);
  font-style: normal;
  letter-spacing: 0.04em;
}

.search-title .year {
  margin-left: 0.6ch;
  font-size: 0.8125rem;
  font-style: normal;
  opacity: 0.5;
}

.search-meta {
  display: block;
  font-size: 0.875rem;
  opacity: 0.6;
}

.search-meta .who {
  font-family: var(--font-caps);
  letter-spacing: 0.05em;
  text-transform: lowercase;
}

/* The letters that matched what was typed. */
.search mark {
  background: none;
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.search-note {
  margin: 0;
  padding: calc(var(--line) / 3) 2.5ch calc(var(--line) / 2);
  font-size: 0.8125rem;
  font-style: italic;
  opacity: 0.45;
}

.search-note:empty {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  .search[open],
  .search[open]::backdrop,
  .search.is-closing,
  .search.is-closing::backdrop {
    animation: none;
  }
}

/* ---------- List view ---------- */

:root[data-view="list"] .shelf-bar {
  margin-bottom: calc(var(--line) * 2);
}

/* A bookcase or a shelf with nothing on it yet. */
.book-list .shelf-empty {
  margin: 0;
  font-size: 0.875rem;
  font-style: italic;
  opacity: 0.4;
}

/* A work, shelf or bookcase chosen in the search lights up for a moment. */
.book-list .is-found {
  animation: found 2.6s ease both;
}

@keyframes found {
  0%, 35% { background: color-mix(in srgb, var(--text) 14%, transparent); }
  100% { background: transparent; }
}

.book-list h2 .count {
  font-size: 0.9375rem;
}

/* A shelf inside a genre, e.g. "Romantasy". */
.book-list .shelf-name {
  margin: calc(var(--line) * 1.5) 0 calc(var(--line) / 2);
  font-style: italic;
  opacity: 0.6;
}

.book-list h2 + .shelf-name {
  margin-top: 0;
}

.book-list .year {
  margin-left: 0.6ch;
  font-size: 0.8125rem;
  opacity: 0.5;
}

.now-mark {
  margin-left: 0.15ch;
  font-size: 0.75em;
  vertical-align: 0.35em;
}

.book-list .key {
  margin-top: var(--line);
  font-size: 0.875rem;
  opacity: 0.55;
}

/* Series rows open to show their volumes. */
.contents li.series {
  display: block;
}

.contents summary {
  display: flex;
  align-items: baseline;
  gap: 1ch;
  list-style: none;
  cursor: pointer;
}

.contents summary::-webkit-details-marker {
  display: none;
}

.contents .vols {
  font-size: 0.875rem;
  opacity: 0.5;
  white-space: nowrap;
}

.contents summary:hover .vols,
.contents details[open] .vols {
  opacity: 0.9;
}

.contents .vol-list {
  margin: calc(var(--line) / 4) 0 calc(var(--line) / 2) 3ch;
  padding: 0;
  columns: 2;
  column-gap: 3ch;
  list-style: lower-roman inside;
  font-size: 0.9375rem;
  opacity: 0.75;
}

.contents .vol-list li {
  display: list-item;
  break-inside: avoid;
}

.contents .vol-list li::before {
  content: none;
}

.contents .vol-list li::marker {
  font-size: 0.8125rem;
}

@media (max-width: 480px) {
  .contents summary {
    flex-wrap: wrap;
    row-gap: 0;
  }

  .contents summary .work {
    flex-basis: 100%;
  }

  .contents summary .leader {
    margin-left: 2ch;
  }

  .contents .vol-list {
    columns: 1;
  }
}
