/* The Stoa shelf (SPEC-SHELF): spines on flat stone ledges, plain pilasters from 1024 px. Restrained and typographic:
   no texture, no ornament, no skeuomorphic shadow; the colour comes from the books. Fonts and ink are the library's
   --lib-* properties, which each site maps; the stone is the shelf's own two tokens (§1). */

.sh {
  --stone: #dcdfe3;
  --stone-edge: #c4c8ce;
  --sh-h: 188px; /* spine height (176 left 63 of 2,337 catalog surnames broken mid-word in Public Sans) */
  --sh-foot: 76px; /* the surname band, hairline to bottom */
  --sh-ledge: 10px;
  --sh-gap: 32px; /* ledge to the next shelf */
  --sh-row: calc(var(--sh-h) + var(--sh-ledge) + var(--sh-gap));
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .sh {
    --stone: #2b2e34;
    --stone-edge: #3d4046;
  }
}

:root[data-theme='dark'] .sh {
  --stone: #2b2e34;
  --stone-edge: #3d4046;
}

@media (min-width: 1024px) {
  .sh {
    --sh-h: 208px;
    --sh-foot: 76px;
  }
}

/* ---- A run of spines: rows wrap left to right, each standing on a 10 px ledge (§3) ---- */
.sh-bay {
  position: relative;
}

.sh-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: calc(var(--sh-ledge) + var(--sh-gap)) 4px;
  margin: 0;
  padding: 0 0 var(--sh-ledge);
  list-style: none;
  /* One ledge under every row: the stone top, then its 1 px front edge, then the gap to the next shelf. */
  background: repeating-linear-gradient(
    to bottom,
    transparent 0 var(--sh-h),
    var(--stone) var(--sh-h) calc(var(--sh-h) + var(--sh-ledge) - 1px),
    var(--stone-edge) calc(var(--sh-h) + var(--sh-ledge) - 1px) calc(var(--sh-h) + var(--sh-ledge)),
    transparent calc(var(--sh-h) + var(--sh-ledge)) var(--sh-row)
  );
}

.sh-i {
  display: flex;
}

/* The bookend: where the group ends, so a half-full row reads as finished (§3). It never wraps to a row of its own: when
   the last row runs to the edge, the edge is the end and the bookend is left out (.sh-end-off, Juno on #382). */
.sh-end {
  width: 10px;
  height: 40px;
  margin-left: 4px;
  background: var(--stone);
  box-shadow: inset 0 0 0 1px var(--stone-edge);
}

.sh-end.sh-end-off {
  display: none;
}

.sh-row-empty {
  /* No books: the row is the bookend's height on its ledge, not a spine's, so no blank band sits over it (Juno, #381). */
  --sh-h: 40px;
  box-sizing: content-box;
  height: var(--sh-h);
  align-content: flex-end;
}

.sh-row-empty .sh-end {
  margin-left: 0;
}

/* ---- A spine (§3): a column of the favourite dot, the title (taking the room left), then the foot ---- */
.sh-sp {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-sizing: border-box;
  width: var(--sh-w, 48px);
  min-width: 44px;
  height: var(--sh-h);
  margin: 0;
  padding: 12px 0 8px;
  overflow: hidden;
  color: #fff;
  text-align: left;
  background: #2b2b38;
  border: 0;
  border-radius: 2px;
  box-shadow: inset 1px 0 0 rgb(255 255 255 / 0.08);
  cursor: pointer;
  transition: transform 120ms ease-out;
}

.sh-sp:focus {
  outline: none;
}

.sh-sp:focus-visible {
  outline: 2px solid var(--lib-ink);
  outline-offset: 2px;
}

.sh-sp.sh-up {
  transform: translateY(-8px);
}

/* The 13 subject tones, the same as the typeset covers' (cover-box.css), so title and foot keep their AA pairs. */
.sh-t-history {
  background: #3a3f5a;
}
.sh-t-lives {
  background: #4a3c52;
}
.sh-t-society {
  background: #2f4a4a;
}
.sh-t-politics {
  background: #44303d;
}
.sh-t-economics {
  background: #2c4a3b;
}
.sh-t-business {
  background: #3a4651;
}
.sh-t-nature {
  background: #34492f;
}
.sh-t-science {
  background: #234059;
}
.sh-t-technology {
  background: #333a44;
}
.sh-t-health {
  background: #2d4c55;
}
.sh-t-mind {
  background: #3e3d5e;
}
.sh-t-philosophy {
  background: #2b2b38;
}
.sh-t-arts {
  background: #4a3838;
}
.sh-t-none {
  background: #2b2b38;
}

/* Tones that arrive after the shelf's first draw (my-books.js drawLate) ease in from the plain one, not all at once
   (Juno, speed-app). Only then: a first draw has its tones from the start. */
.lib-late .sh-sp {
  transition:
    transform 120ms ease-out,
    background-color 300ms ease-out;
}
@starting-style {
  .lib-late .sh-sp {
    background-color: #2b2b38;
  }
}

/* The title: the main title, set top to bottom, the largest of 15/13/11 px in two lines (three on a wider spine). */
.sh-ti {
  display: block;
  flex: 1 1 auto;
  min-height: 0;
  width: calc(var(--sh-lines, 2) * var(--sh-fs, 15px) * 1.15);
  max-width: calc(100% - 8px);
  overflow: hidden;
  font: 500 var(--sh-fs, 15px) / 1.15 var(--lib-display, Georgia, serif);
  writing-mode: vertical-rl;
  overflow-wrap: normal;
  word-break: normal;
  hyphens: manual; /* only at a morpheme break on file (TITLE_BREAKS), drawn with a hyphen */
}

/* The foot: a fixed band under every spine's hairline (64 px from the bottom, 72 from 1024), so the hairlines line
   up along a row. The surname sits on the title's axis, anchored to the bottom, and drops to 10 px if it doesn't
   fit (§3, Juno's ruling Nov 10). The hairline is the title's colour at 40%, the spine's width less 16. */
.sh-au {
  display: flex;
  flex: none;
  flex-direction: column;
  align-self: stretch;
  align-items: center;
  justify-content: flex-end;
  box-sizing: border-box;
  height: calc(var(--sh-foot) - 8px);
  margin: 8px 8px 0;
  padding-top: 6px;
  overflow: hidden;
  border-top: 1px solid rgb(255 255 255 / 0.4);
}

.sh-au-t {
  display: block;
  font: 600 11px / 12px var(--lib-font, system-ui, sans-serif);
  white-space: nowrap;
  writing-mode: vertical-rl;
}

.sh-au-t.sh-au-s {
  font-size: 10px;
}

/* The last step for a long surname: two columns at 10 px, broken at its own hyphen or a set syllable break (Juno, #381). */
.sh-au-t.sh-au-2 {
  font-size: 10px;
  white-space: normal;
  hyphens: manual; /* breaks only after a real hyphen: the name's own, or one set from a break on file */
}

.sh-end[hidden] {
  display: none;
}

/* A favourite: one filled 8 px dot at the top (§3). */
.sh-fav {
  flex: none;
  width: 8px;
  height: 8px;
  margin: -4px 0 6px;
  background: var(--lib-accent-on-tone, #f2c14e);
  border-radius: 50%;
}

/* ---- Group headings (Year, Subject, Rating), as M2's ---- */
.sh-gh {
  margin: 2rem 0 1rem;
  font: 500 1.25rem / 1.625rem var(--lib-display, Georgia, serif);
}

.sh-gh:first-child {
  margin-top: 0;
}

.sh-gn {
  color: var(--lib-mut);
}

/* ---- The empty shelf (§7) ---- */
.sh-empty {
  margin: 1rem 0 0;
  color: var(--lib-mut);
  font: 400 0.9375rem / 1.25rem var(--lib-font, system-ui, sans-serif);
}

/* UX-18: below 1024 px there are no pilasters, so an empty ledge with its bookend reads as a stray bar. A phone shows
   only the line and the way to add a book; from 1024 px the ledge stands between its pilasters as bookends. */
@media (max-width: 1023.98px) {
  .sh-bay:has(> .sh-row-empty) {
    display: none;
  }

  .sh-bay:has(> .sh-row-empty) + .sh-empty {
    margin-top: 0;
  }
}

.sh-add {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0;
  color: var(--lib-ink);
  font: inherit;
  background: none;
  border: 0;
  text-decoration: underline;
  text-underline-offset: 0.2em;
  cursor: pointer;
}

/* ---- The colonnade: from 1024 px each group stands between two plain pilasters (§3) ---- */
.sh-pil {
  display: none;
}

@media (min-width: 1024px) {
  /* The capitals' outer edges sit on the column's edges; the ledges run between the shafts. */
  .sh-bay {
    padding-inline: 28px;
  }

  .sh-pil {
    position: absolute;
    top: 6px;
    bottom: 6px;
    display: block;
    width: 16px;
    background: var(--stone);
    box-shadow: inset 0 0 0 1px var(--stone-edge);
  }

  .sh-pil-l {
    left: 4px;
  }

  .sh-pil-r {
    right: 4px;
  }

  /* Capital and base: 24×6, centred on the shaft. */
  .sh-pil::before,
  .sh-pil::after {
    position: absolute;
    left: -4px;
    width: 24px;
    height: 6px;
    background: var(--stone);
    box-shadow: inset 0 0 0 1px var(--stone-edge);
    content: '';
  }

  .sh-pil::before {
    top: -6px;
  }

  .sh-pil::after {
    bottom: -6px;
  }
}

/* ---- Filling the shelf (§6): a new spine slides onto the ledge once ---- */
.sh-new {
  animation: sh-in 320ms cubic-bezier(0.2, 0, 0, 1) both;
}

@keyframes sh-in {
  from {
    opacity: 0;
    transform: translateX(24px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .sh-sp,
  .lib-late .sh-sp {
    transition: none;
  }

  .sh-sp.sh-up {
    transform: none;
  }

  .sh-new {
    animation: sh-fade 150ms linear both;
  }

  @keyframes sh-fade {
    from {
      opacity: 0;
    }
  }
}
