/* The bookcase: the library as a real shelf of spines, shared by the home
   page and /player. assets/bookcase.js builds it; this file is everything
   it looks like. Needs the design tokens from site.css or player.css. */

/* An old library bookcase in dark weathered oak. Textures in /assets/tex
   are photographic scans (Poly Haven, CC0) toned in processing: oak-*.jpg
   the frame and shelves, back.jpg the back wall, grain.jpg the pebbled
   cloth of the spines. The gradients only add light and shadow. */
.bookcase {
  position: relative; padding: 0 30px; border-radius: 2px;
  background:
    linear-gradient(90deg, rgba(0,0,0,0.5) 0, rgba(255,220,180,0.08) 8px, rgba(0,0,0,0.0) 18px, rgba(0,0,0,0.65) 30px,
                           transparent 30px, transparent calc(100% - 30px),
                           rgba(0,0,0,0.65) calc(100% - 30px), rgba(0,0,0,0) calc(100% - 18px), rgba(255,220,180,0.08) calc(100% - 8px), rgba(0,0,0,0.5) 100%),
    url(/assets/tex/oak-v.jpg) 0 0 / 450px 450px,
    #3a2618;
  box-shadow: 0 34px 50px -10px rgba(30, 16, 6, 0.55), 0 10px 18px rgba(30, 16, 6, 0.3);
}
.bookcase .crown, .bookcase .plinth { position: relative; margin: 0 -6px; }
.bookcase .crown {
  height: 34px; z-index: 2; border-radius: 2px 2px 0 0;
  background:
    linear-gradient(180deg, rgba(255,225,190,0.16) 0, transparent 6px, transparent 26px, rgba(0,0,0,0.6) 100%),
    url(/assets/tex/oak-h.jpg) 0 0 / 600px 600px,
    #3a2618;
  box-shadow: 0 8px 12px rgba(0,0,0,0.55);
}
.bookcase .plinth {
  height: 30px; border-radius: 0 0 2px 2px;
  background:
    linear-gradient(180deg, rgba(255,225,190,0.14) 0, transparent 5px, rgba(0,0,0,0.55) 100%),
    url(/assets/tex/oak-h.jpg) 0 -200px / 600px 600px,
    #3a2618;
}
.bays { position: relative; }
.bay {
  position: relative; display: flex; align-items: flex-end; justify-content: center; gap: 2px;
  padding: 20px 10px 0; min-height: 120px;
  background:
    linear-gradient(180deg, rgba(0,0,0,0.8) 0, rgba(0,0,0,0.35) 22px, transparent 60px),
    linear-gradient(90deg, rgba(0,0,0,0.7) 0, transparent 24px, transparent calc(100% - 24px), rgba(0,0,0,0.7) 100%),
    url(/assets/tex/back.jpg) 0 0 / 420px 420px,
    #170d07;
}
.bay::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 2;
  background:
    linear-gradient(180deg, rgba(10,5,2,0.55) 0, rgba(10,5,2,0.18) 70px, transparent 140px),
    linear-gradient(90deg, rgba(10,5,2,0.35) 0, transparent 60px, transparent calc(100% - 60px), rgba(10,5,2,0.35) 100%);
}
.plank {
  position: relative; z-index: 1; height: 30px;
  background:
    linear-gradient(180deg, rgba(255,225,190,0.24) 0, rgba(255,225,190,0.06) 4px, rgba(0,0,0,0.45) 5px,
                            rgba(255,225,190,0.08) 7px, transparent 11px, transparent 20px, rgba(0,0,0,0.6) 100%),
    url(/assets/tex/oak-h.jpg) 0 -120px / 600px 600px,
    #3a2618;
  box-shadow: 0 8px 10px rgba(0,0,0,0.6), 0 1px 0 rgba(0,0,0,0.6);
}

.spine {
  --c: var(--cloth);
  position: relative; display: flex; flex-direction: column; align-items: center;
  width: var(--w, 50px); height: var(--h, 250px);
  padding: 18px 5px 20px; border-radius: 2px 2px 1px 1px;
  background:
    linear-gradient(90deg, rgba(0,0,0,0.45) 0, rgba(0,0,0,0.08) 5%, rgba(255,235,210,0.05) 30%, rgba(0,0,0,0) 60%, rgba(0,0,0,0.12) 92%, rgba(0,0,0,0.5) 100%),
    linear-gradient(180deg, rgba(255,235,210,0.06), rgba(0,0,0,0.12)),
    url(/assets/tex/grain.jpg) var(--lx, 0) var(--ly, 0) / 220px 220px,
    var(--c);
  background-blend-mode: normal, normal, overlay, normal;
  color: #d2b06a; text-decoration: none;
  transition: transform 0.2s ease, box-shadow 0.2s;
  box-shadow: 1px 0 0 rgba(0,0,0,0.6), 3px 0 4px rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,235,210,0.08);
}
.spine:hover, .spine:focus-visible { transform: translateY(-12px); box-shadow: 4px 10px 16px rgba(0,0,0,0.55); outline: none; z-index: 3; }
/* crisp double gilt rules near the head and tail */
.spine .band {
  flex: none; align-self: stretch; height: 5px; margin: 0 2px;
  border-top: 1px solid #c9a55a; border-bottom: 1px solid #c9a55a; opacity: 0.85;
}
.spine .t {
  writing-mode: vertical-rl; transform: rotate(180deg);
  font-family: var(--display); font-size: var(--fs, 0.95rem); line-height: 1.1; letter-spacing: 0.01em;
  flex: 1 1 auto; min-height: 0; padding: 16px 0; text-align: center;
  overflow: hidden; overflow-wrap: anywhere;
  text-shadow: 0 1px 0 rgba(0,0,0,0.45);
}
.spine .a {
  flex: none; margin: 4px 0 14px; font-size: 0.6rem; letter-spacing: 0.1em; text-transform: uppercase;
  writing-mode: vertical-rl; transform: rotate(180deg); max-height: 70px; overflow: hidden; white-space: nowrap;
  text-shadow: 0 1px 0 rgba(0,0,0,0.45);
}
.spine .free {
  position: absolute; top: -10px; left: 50%; transform: translateX(-50%);
  background: var(--gold); color: var(--cloth); font-size: 0.6rem; letter-spacing: 0.08em;
  text-transform: uppercase; padding: 1px 6px; border-radius: 3px; white-space: nowrap;
  box-shadow: 0 2px 4px rgba(0,0,0,0.4); z-index: 4;
}
.spine .free { pointer-events: none; }
.spine.bc-found { animation: bc-found 1.6s ease; z-index: 3; }
@keyframes bc-found {
  0%, 100% { transform: none; }
  20%, 70% { transform: translateY(-14px); box-shadow: 4px 10px 16px rgba(0,0,0,0.55), 0 0 0 2px #e2c27a; }
}

/* A brass label plate on the front of each plank, like a library bay. */
.plank .plate {
  position: absolute; left: 50%; top: 7px; transform: translateX(-50%);
  height: 15px; padding: 0 10px; border-radius: 1px;
  display: flex; align-items: center; white-space: nowrap;
  font-family: var(--text); font-size: 0.6rem; letter-spacing: 0.16em; text-transform: uppercase;
  color: #3a2410; text-shadow: 0 1px 0 rgba(255,240,200,0.45);
  background: linear-gradient(180deg, #ecd28f 0, #c9a55a 45%, #a9853f 100%);
  box-shadow: 0 1px 2px rgba(0,0,0,0.6), inset 0 0 0 1px rgba(90,60,20,0.35);
}
.plank .plate::before, .plank .plate::after {
  content: ""; width: 3px; height: 3px; border-radius: 50%; background: #6d5022;
  box-shadow: inset 0 0 0 1px rgba(255,240,200,0.3);
}
.plank .plate::before { margin-right: 8px; }
.plank .plate::after { margin-left: 8px; }

.bay .bc-empty { align-self: center; color: #d8c3a0; padding: 3rem 1rem; text-align: center; position: relative; z-index: 3; }
.bay .bc-empty a { color: #ecd28f; }

/* ── controls ── */
.bc-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.8rem 1.2rem; margin-bottom: 0.9rem; }
.bc-seg { display: inline-flex; flex-wrap: wrap; gap: 0; border: 1px solid var(--rule); border-radius: 999px; padding: 3px; background: rgba(255,255,255,0.25); }
.bc-seg button {
  font: inherit; font-size: 0.86rem; color: var(--ink-soft); background: none; border: 0; cursor: pointer;
  padding: 0.38rem 0.95rem; border-radius: 999px; white-space: nowrap;
}
.bc-seg button:hover { color: var(--ink); }
.bc-seg button[aria-pressed="true"] { background: var(--cloth); color: var(--cloth-ink); }
.bc-seg button:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
.bc-genres { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1.6rem; }
.bc-genres button {
  font: inherit; font-size: 0.82rem; color: var(--ink); cursor: pointer;
  background: transparent; border: 1px solid var(--rule); border-radius: 3px; padding: 0.24rem 0.65rem;
}
.bc-genres button .n { color: var(--ink-soft); font-size: 0.74rem; margin-left: 0.3rem; }
.bc-genres button:hover { border-color: var(--gold); }
.bc-genres button[aria-pressed="true"] { background: rgba(200,164,90,0.2); border-color: var(--gold); }
.bc-genres button:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }

/* ── the case and its letter index ── */
.bc-body { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0 10px; }
.bc-body.no-index { grid-template-columns: minmax(0, 1fr); }
/* A thin oak strip of gilt index letters beside the case. */
.bc-index {
  display: flex; flex-direction: column; justify-content: space-between; align-items: stretch;
  width: 30px; padding: 40px 0 36px; border-radius: 2px;
  /* Sticky and no taller than the window, so on a long case the letters
     stay in reach; bookcase.js sets --rail-h. */
  position: sticky; top: 84px; align-self: start; height: var(--rail-h, auto); box-sizing: border-box;
  background:
    linear-gradient(90deg, rgba(0,0,0,0.55), rgba(255,220,180,0.06) 40%, rgba(0,0,0,0.5)),
    url(/assets/tex/oak-v.jpg) 0 0 / 450px 450px, #3a2618;
  box-shadow: 0 20px 30px -10px rgba(30,16,6,0.5);
}
.bc-index button {
  font-family: var(--display); font-size: 0.78rem; line-height: 1; color: #d9b96f; text-shadow: 0 1px 0 rgba(0,0,0,0.6);
  background: none; border: 0; padding: 2px 0; cursor: pointer; flex: 1 1 0; min-height: 0; max-height: 34px;
}
.bc-index button:hover, .bc-index button:focus-visible { color: #fff0c8; outline: none; }
.bc-index button:disabled { color: rgba(217,185,111,0.22); cursor: default; }
.bc-index[hidden] { display: none; }

/* ── the list: plain text, a line a book ── */
.bc-list { min-width: 0; border-top: 1px solid var(--rule); }
.bc-list[hidden], .bookcase[hidden] { display: none; }
.bc-list-letter {
  font-family: var(--display); font-weight: 500; font-size: 1.05rem; color: var(--accent, var(--ribbon));
  margin: 1.1rem 0 0.2rem; padding-bottom: 0.2rem; border-bottom: 1px solid var(--rule); scroll-margin-top: 90px;
}
.bc-row {
  display: grid; grid-template-columns: minmax(0, 2.2fr) minmax(0, 1.4fr) 6.5rem; align-items: baseline; gap: 0 1rem;
  padding: 0.55rem 0.4rem; border-bottom: 1px solid var(--rule); color: var(--ink); text-decoration: none;
  scroll-margin-top: 90px;
}
.bc-row:hover, .bc-row:focus-visible { background: rgba(200,164,90,0.12); outline: none; }
.bc-row-t { font-family: var(--display); font-size: 1.02rem; }
.bc-row-a { color: var(--ink-soft); font-style: italic; font-size: 0.92rem; }
.bc-row-m { color: var(--ink-soft); font-size: 0.82rem; text-align: right; font-variant-numeric: tabular-nums; }
.bc-row-free {
  grid-column: 1; justify-self: start; margin-top: 0.2rem;
  font-size: 0.64rem; letter-spacing: 0.08em; text-transform: uppercase; color: #7b5d1d;
  border: 1px solid rgba(200,164,90,0.7); background: rgba(200,164,90,0.14); border-radius: 999px; padding: 0 0.45rem;
}
.bc-row.bc-found { animation: bc-row-found 1.6s ease; }
@keyframes bc-row-found { 0%, 100% { background: transparent; } 20%, 70% { background: rgba(200,164,90,0.3); } }
.bc-list-empty { color: var(--ink-soft); padding: 2rem 0; }

.bc-foot { display: flex; justify-content: center; margin-top: 1.4rem; }
.bc-more {
  font: inherit; font-size: 0.95rem; color: var(--ink); cursor: pointer;
  background: transparent; border: 1px solid var(--ink); border-radius: 999px; padding: 0.55rem 1.4rem;
}
.bc-more:hover { background: var(--cloth); border-color: var(--cloth); color: var(--cloth-ink); }
.bc-more[hidden] { display: none; }
.bc-covers[hidden], .bc-body[hidden] { display: none; }

@media (max-width: 720px) {
  .bc-seg { display: grid; grid-template-columns: 1fr 1fr; width: 100%; border-radius: 14px; }
  .bc-seg button { padding: 0.42rem 0.5rem; font-size: 0.82rem; }
  .bc-seg.bc-views { grid-template-columns: repeat(3, 1fr); }
  .bc-genres { flex-wrap: nowrap; overflow-x: auto; margin-left: -16px; margin-right: -16px; padding: 0 16px 4px; scrollbar-width: none; }
  .bc-genres button { flex: none; }
  /* The index runs across the top of the case instead of down its side. */
  .bc-body { grid-template-columns: minmax(0, 1fr); }
  .bc-index {
    order: -1; flex-direction: row; width: auto; padding: 0 6px; height: 30px; margin-bottom: 6px; top: 64px; z-index: 4;
    overflow-x: auto; scrollbar-width: none;
  }
  .bc-index button { flex: 1 0 12px; max-height: none; padding: 0; font-size: 0.72rem; }
  .plank .plate { font-size: 0.55rem; letter-spacing: 0.1em; }
  .bc-row { grid-template-columns: minmax(0, 1fr) auto; }
  .bc-row-a { grid-column: 1; grid-row: 2; font-size: 0.84rem; }
  .bc-row-m { grid-column: 2; grid-row: 1 / span 2; align-self: center; }
  .bc-row-free { grid-row: 3; }
}

/* /player night mode is pure red on black. */
:root[data-theme="night"] .bc-seg button[aria-pressed="true"] { background: var(--accent); color: #000; }
:root[data-theme="night"] .bc-genres button[aria-pressed="true"] { background: var(--paper-3); border-color: var(--accent); }
:root[data-theme="night"] .bc-more:hover { background: var(--accent); border-color: var(--accent); color: #000; }
/* The case itself: render it in grey and
   multiply red over it, so not a pixel of it leaves the red channel. */
:root[data-theme="night"] .bc-body > :not(.bc-list) { filter: grayscale(1) brightness(0.8); }
:root[data-theme="night"] .bc-body::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 5;
  background: #ff0000; mix-blend-mode: multiply;
}

/* Each line carries a ribbon of its book's cloth, the colour of its spine. */
.bc-row { position: relative; padding-left: 0.95rem; }
.bc-row::before {
  content: ""; position: absolute; left: 0.2rem; top: 0.55rem; bottom: 0.55rem; width: 4px;
  border-radius: 1px; background: var(--c, transparent);
}
:root[data-theme="dark"] .bc-row::before { background: color-mix(in srgb, var(--c, transparent) 45%, #ece4d2); }
:root[data-theme="night"] .bc-row::before { background: var(--ink-soft); }
