/* Library: interactive bookshelf with covers, filters, and a book detail view. */
:root {
  --ink: #10110f;
  --panel: #171914;
  --paper: #141611;
  --cream: #f6f0e4;
  --lime: #c8ff31;
  --muted: #9da195;
  --line: rgba(246, 240, 228, .13);
  --soft: rgba(246, 240, 228, .62);
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-height: 100vh; background: var(--ink); color: var(--cream); font-family: "Space Grotesk", system-ui, sans-serif; -webkit-font-smoothing: antialiased; }
body.dialog-open { overflow: hidden; }
img { max-width: 100%; }
button { font: inherit; color: inherit; }

.lib { width: min(1180px, calc(100% - 48px)); margin-inline: auto; }
.eyebrow { margin: 0 0 16px; color: var(--lime); font: 500 11px/1.4 var(--mono); letter-spacing: .2em; text-transform: uppercase; }

/* Hero */
.lib-hero { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 440px); gap: clamp(32px, 6vw, 80px); align-items: center; padding: 72px 0 56px; }
.lib-hero h1 { margin: 0; max-width: 680px; font-size: clamp(44px, 6.6vw, 84px); line-height: .96; letter-spacing: -.045em; }
.lib-hero .lede { max-width: 600px; margin: 26px 0 30px; color: var(--soft); font-size: clamp(17px, 1.9vw, 19px); line-height: 1.65; }
.hero-stats { display: flex; flex-wrap: wrap; gap: 10px; margin: 0; padding: 0; list-style: none; }
.hero-stats li { padding: 12px 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); }
.hero-stats strong { display: block; font-size: 24px; letter-spacing: -.03em; }
.hero-stats span { color: var(--muted); font: 500 9px/1.4 var(--mono); letter-spacing: .14em; text-transform: uppercase; }

.hero-stack { position: relative; height: clamp(300px, 34vw, 420px); perspective: 1600px; }
.hero-stack .book-btn { position: absolute; top: 50%; left: 50%; width: clamp(120px, 13vw, 168px); transition: transform .6s cubic-bezier(.2,.8,.2,1); }
.hero-stack .book-btn:nth-child(1) { transform: translate(-150%, -50%) rotate(-14deg) translateY(18px); z-index: 1; }
.hero-stack .book-btn:nth-child(2) { transform: translate(-108%, -50%) rotate(-7deg) translateY(4px); z-index: 2; }
.hero-stack .book-btn:nth-child(3) { transform: translate(-50%, -50%); z-index: 5; }
.hero-stack .book-btn:nth-child(4) { transform: translate(8%, -50%) rotate(7deg) translateY(4px); z-index: 2; }
.hero-stack .book-btn:nth-child(5) { transform: translate(50%, -50%) rotate(14deg) translateY(18px); z-index: 1; }
.hero-stack:hover .book-btn:nth-child(1) { transform: translate(-178%, -50%) rotate(-18deg) translateY(26px); }
.hero-stack:hover .book-btn:nth-child(2) { transform: translate(-122%, -50%) rotate(-9deg) translateY(6px); }
.hero-stack:hover .book-btn:nth-child(4) { transform: translate(22%, -50%) rotate(9deg) translateY(6px); }
.hero-stack:hover .book-btn:nth-child(5) { transform: translate(78%, -50%) rotate(18deg) translateY(26px); }
.hero-stack .book-btn:hover { z-index: 9; }
.hero-stack .book-meta { display: none; }
.hero-stack::before { content: ""; position: absolute; inset: 12% 10%; border-radius: 50%; background: radial-gradient(circle, rgba(200,255,49,.18), transparent 65%); filter: blur(20px); pointer-events: none; }

/* 3D book object */
.book-btn { display: block; width: 100%; padding: 0; border: 0; background: none; text-align: left; cursor: pointer; perspective: 1100px; }
.book-btn:focus-visible { outline: none; }
.book-btn:focus-visible .book-face { outline: 2px solid var(--lime); outline-offset: 4px; }
.book { position: relative; display: block; aspect-ratio: 2 / 3; transform-style: preserve-3d; transform: rotateY(0deg); transition: transform .55s cubic-bezier(.2,.8,.2,1); }
.book-btn:hover .book, .book-btn:focus-visible .book { transform: rotateY(-26deg) translateY(-8px); }
.book-face { position: absolute; inset: 0; overflow: hidden; border-radius: 2px 6px 6px 2px; background: #22251e; transform: translateZ(9px); box-shadow: 0 22px 34px -14px rgba(0,0,0,.85), 0 2px 6px rgba(0,0,0,.4); }
.book-face img { display: block; width: 100%; height: 100%; object-fit: cover; }
.book-face::after { content: ""; position: absolute; inset: 0; pointer-events: none; background:
  linear-gradient(90deg, rgba(0,0,0,.42) 0, rgba(255,255,255,.22) 2.6%, rgba(0,0,0,.16) 4.5%, rgba(255,255,255,.06) 7%, transparent 11%),
  linear-gradient(115deg, rgba(255,255,255,.12), transparent 38%); }
.book-pages { position: absolute; top: 1.5%; right: -9px; width: 18px; height: 97%; transform: rotateY(90deg); background: repeating-linear-gradient(90deg, #f3eee2 0 1px, #cfc8b7 1px 2px); }
.book-back { position: absolute; inset: 0; border-radius: 6px 2px 2px 6px; background: #1b1d17; transform: translateZ(-9px); }

/* Generated cover when no artwork exists */
.gen-cover { display: flex; flex-direction: column; justify-content: space-between; height: 100%; padding: 14% 12% 11% 16%; background: var(--gen, #2a3a22); }
.gen-cover strong { font-size: clamp(12px, 1.25vw, 17px); line-height: 1.08; letter-spacing: -.02em; overflow-wrap: anywhere; }
.gen-cover span { color: rgba(255,255,255,.66); font: 500 8px/1.3 var(--mono); letter-spacing: .14em; text-transform: uppercase; }
.gen-cover i { width: 28%; height: 3px; background: rgba(255,255,255,.7); }

.book-meta { display: block; margin-top: 14px; }
.book-meta strong { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: 14px; line-height: 1.25; letter-spacing: -.01em; }
.book-meta small { display: block; margin-top: 4px; overflow: hidden; color: var(--muted); font-size: 12px; white-space: nowrap; text-overflow: ellipsis; }
.take-badge { position: absolute; top: 8px; right: 8px; z-index: 3; transform: translateZ(10px); display: inline-flex; align-items: center; gap: 5px; padding: 4px 7px; border-radius: 999px; background: var(--lime); color: var(--ink); font: 600 8px/1 var(--mono); letter-spacing: .1em; text-transform: uppercase; box-shadow: 0 4px 12px rgba(0,0,0,.4); }

/* Top 10 shelf */
.section-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 18px; margin-bottom: 28px; }
.section-head h2 { margin: 0; font-size: clamp(28px, 3.6vw, 44px); line-height: 1.02; letter-spacing: -.035em; }
.section-head p { max-width: 440px; margin: 0; color: var(--soft); font-size: 15px; line-height: 1.6; }
.top-shelf { padding: 56px 0 26px; border-top: 1px solid var(--line); }
.shelf-track { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(170px, 196px); gap: 38px; overflow-x: auto; padding: 40px 4px 34px 18px; scroll-snap-type: x mandatory; scrollbar-width: thin; scrollbar-color: rgba(246,240,228,.25) transparent; }
.shelf-item { position: relative; scroll-snap-align: start; }
.shelf-rank { position: absolute; top: -30px; left: -16px; z-index: 4; color: var(--lime); font: 700 54px/1 "Space Grotesk", sans-serif; letter-spacing: -.06em; text-shadow: 0 6px 18px rgba(0,0,0,.7); pointer-events: none; }
.shelf-item .book-meta small { white-space: normal; }
.shelf-why { margin: 10px 0 0; color: var(--soft); font-size: 13px; line-height: 1.5; }
.shelf-item .take-badge { display: none; }
.shelf-floor { height: 14px; margin-top: -40px; border-radius: 3px; background: linear-gradient(180deg, #2a2d24, #171914); box-shadow: 0 18px 30px -12px rgba(0,0,0,.9); }

/* Filters */
.browse { padding: 64px 0 40px; }
.filters { position: sticky; top: 0; z-index: 20; margin: 0 -12px 34px; padding: 14px 12px; border-bottom: 1px solid var(--line); background: rgba(16,17,15,.88); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
.filter-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.search { flex: 1 1 260px; display: flex; align-items: center; gap: 10px; min-height: 46px; padding: 0 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); }
.search:focus-within { border-color: var(--lime); }
.search svg { flex: none; color: var(--muted); }
.search input { width: 100%; border: 0; outline: 0; background: none; color: var(--cream); font: inherit; font-size: 15px; }
.search input::placeholder { color: rgba(246,240,228,.38); }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; display: inline-flex; align-items: center; gap: 8px; min-height: 38px; padding: 0 13px; border: 1px solid var(--line); border-radius: 999px; background: transparent; color: rgba(246,240,228,.75); font-size: 13px; font-weight: 600; cursor: pointer; transition: border-color .15s, background .15s, color .15s; }
.chip:hover { border-color: rgba(246,240,228,.4); color: var(--cream); }
.chip[aria-pressed="true"] { border-color: var(--lime); background: var(--lime); color: var(--ink); }
.chip em { font: 500 10px/1 var(--mono); font-style: normal; opacity: .6; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.lane-row { margin-top: 12px; }
.lane-detail { margin: 12px 0 0; color: var(--muted); font-size: 13px; }
.genre-row { margin-top: 10px; }
.genre-row .chip { min-height: 30px; padding: 0 11px; font-size: 12px; font-weight: 500; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 46px 30px; }
.empty { padding: 60px 0; color: var(--muted); text-align: center; }
.more-wrap { display: flex; justify-content: center; padding: 56px 0 0; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 20px; border: 1px solid rgba(246,240,228,.22); border-radius: 10px; background: transparent; font-size: 14px; font-weight: 700; text-decoration: none; cursor: pointer; transition: transform .18s, border-color .18s; }
.btn:hover { transform: translateY(-2px); border-color: var(--lime); }
.btn.primary { border-color: var(--lime); background: var(--lime); color: var(--ink); }

.grid .book-btn { opacity: 0; transform: translateY(14px); animation: rise .5s cubic-bezier(.2,.8,.2,1) forwards; animation-delay: calc(var(--i, 0) * 18ms); }
@keyframes rise { to { opacity: 1; transform: none; } }

/* Book detail dialog: fixed height on desktop so flipping books never resizes it; the text column scrolls. */
.book-dialog { width: min(1040px, calc(100% - 32px)); height: min(760px, calc(100dvh - 48px)); max-height: none; margin: auto; padding: 0; border: 1px solid var(--line); border-radius: 18px; background: #13150f; color: var(--cream); box-shadow: 0 40px 120px rgba(0,0,0,.7); overflow: hidden; }
.book-dialog::backdrop { background: rgba(6,7,5,.86); }
.book-dialog[open] { animation: pop .35s cubic-bezier(.2,.8,.2,1); }
@keyframes pop { from { opacity: 0; transform: translateY(18px) scale(.98); } }
.dialog-inner { display: grid; grid-template-columns: minmax(260px, 37%) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); height: 100%; }

.dialog-stage { position: relative; display: grid; place-items: center; padding: 48px 40px; overflow: hidden; border-right: 1px solid var(--line); background: radial-gradient(120% 70% at 50% 42%, var(--stage, rgba(200,255,49,.16)), transparent 68%), linear-gradient(180deg, #0f100d, #0b0c09); perspective: 1400px; }
.stage-book { position: relative; width: min(250px, 72%); }
.stage-book .book { animation: turn .9s cubic-bezier(.2,.8,.2,1) both; transform: rotateY(-20deg); }
.stage-book:hover .book { transform: rotateY(-30deg) translateY(-6px); }
.stage-book .take-badge { display: none; }
.stage-floor { position: absolute; left: 6%; right: 2%; bottom: -26px; height: 26px; border-radius: 50%; background: radial-gradient(closest-side, rgba(0,0,0,.65), transparent); filter: blur(4px); }
@keyframes turn { from { transform: rotateY(-70deg) translateX(-16px); opacity: 0; } to { transform: rotateY(-20deg); opacity: 1; } }

.dialog-controls { position: absolute; top: 16px; right: 16px; z-index: 5; display: flex; gap: 8px; }
.icon-btn { display: grid; place-items: center; width: 40px; height: 40px; padding: 0; border: 1px solid var(--line); border-radius: 999px; background: rgba(19,21,15,.85); color: var(--cream); cursor: pointer; transition: border-color .15s, background .15s; }
.icon-btn:hover { border-color: var(--lime); }
.icon-btn[disabled] { opacity: .3; pointer-events: none; }
.icon-btn:focus-visible { outline: 2px solid var(--lime); outline-offset: 2px; }

.dialog-body { min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 0 44px 40px; scrollbar-width: thin; scrollbar-color: rgba(246,240,228,.2) transparent; }
.dialog-body > * { max-width: 600px; }
.dialog-body > .meta-line { max-width: none; }
.meta-line { position: sticky; top: 0; z-index: 2; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; min-height: 72px; margin: 0 -44px 18px; padding: 16px 150px 14px 44px; border-bottom: 1px solid transparent; background: #13150f; transition: border-color .2s; }
.book-dialog.scrolled .meta-line { border-bottom-color: var(--line); }
.tag { display: inline-flex; align-items: center; min-height: 26px; padding: 0 10px; border: 1px solid var(--line); border-radius: 999px; color: var(--soft); font: 500 10px/1 var(--mono); letter-spacing: .08em; text-transform: uppercase; }
.tag.lime { border-color: rgba(200,255,49,.45); color: var(--lime); }
.dialog-body h2 { margin: 0; font-size: clamp(28px, 3.2vw, 40px); line-height: 1.05; letter-spacing: -.035em; }
.dialog-sub { margin: 8px 0 0; color: var(--soft); font-size: 16px; line-height: 1.5; }
.dialog-author { margin: 12px 0 0; color: var(--muted); font-size: 14px; }
.hook { margin: 28px 0 0; padding-left: 16px; border-left: 3px solid var(--lime); font-size: 19px; font-weight: 600; line-height: 1.45; letter-spacing: -.015em; }
.summary { margin: 20px 0 0; color: rgba(246,240,228,.78); font-size: 16px; line-height: 1.75; }
.block-label { margin: 34px 0 14px; color: var(--muted); font: 500 10px/1.4 var(--mono); letter-spacing: .18em; text-transform: uppercase; }
.ideas { display: grid; gap: 0; margin: 0; padding: 0; list-style: none; counter-reset: idea; border-top: 1px solid var(--line); }
.ideas li { display: grid; grid-template-columns: 34px 1fr; gap: 8px; align-items: baseline; padding: 13px 0; border-bottom: 1px solid var(--line); font-size: 15px; line-height: 1.5; counter-increment: idea; }
.ideas li::before { content: "0" counter(idea); color: var(--lime); font: 500 11px/1 var(--mono); }
.take { margin-top: 34px; padding: 22px 22px 20px; border: 1px solid rgba(200,255,49,.3); border-radius: 14px; background: linear-gradient(135deg, rgba(200,255,49,.09), rgba(200,255,49,.02)); }
.take-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.take-head img { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; }
.take-head strong { display: block; font-size: 14px; }
.take-head span { color: var(--lime); font: 500 9px/1.4 var(--mono); letter-spacing: .16em; text-transform: uppercase; }
.take p { margin: 0; font-size: 16px; line-height: 1.65; }
.take p + p { margin-top: 12px; }
.related-row { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 16px; }
.related-row .book-meta { margin-top: 8px; }
.related-row .book-meta strong { font-size: 12px; }
.related-row .book-meta small, .related-row .take-badge { display: none; }
.dialog-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 36px; padding-top: 24px; border-top: 1px solid var(--line); }
.nav-card { display: grid; gap: 4px; min-width: 0; padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; background: transparent; text-align: left; cursor: pointer; transition: border-color .15s, transform .15s; }
.nav-card:hover { border-color: var(--lime); transform: translateY(-2px); }
.nav-card.next { text-align: right; }
.nav-card span { color: var(--muted); font: 500 10px/1.4 var(--mono); letter-spacing: .14em; text-transform: uppercase; }
.nav-card strong { overflow: hidden; font-size: 14px; white-space: nowrap; text-overflow: ellipsis; }
.nav-card[disabled] { visibility: hidden; }

@media (max-width: 900px) {
  .lib-hero { grid-template-columns: 1fr; padding-top: 48px; }
  .hero-stack { order: -1; height: 280px; }
  .hero-stack .book-btn { width: 118px; }
}

@media (max-width: 480px) {
  .hero-stack { height: 230px; }
  .hero-stack .book-btn { width: 96px; }
}

@media (max-width: 720px) {
  .lib { width: calc(100% - 32px); }
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 30px 14px; }
  .book-meta { margin-top: 10px; }
  .book-meta strong { font-size: 12px; }
  .book-meta small { font-size: 11px; }
  .book-btn:hover .book { transform: none; }
  .take-badge { top: 5px; right: 5px; padding: 3px 5px; font-size: 7px; }
  .take-badge b { display: none; }
  .shelf-track { grid-auto-columns: 140px; gap: 26px; }
  .shelf-rank { font-size: 42px; }
  .filters { margin-inline: -16px; padding-inline: 16px; }
  .book-dialog { width: 100%; max-width: 100%; height: 100%; max-height: 100%; margin: 0; border: 0; border-radius: 0; }
  .dialog-inner { display: block; height: 100%; overflow-y: auto; overscroll-behavior: contain; }
  .dialog-stage { padding: 68px 20px 44px; border-right: 0; border-bottom: 1px solid var(--line); }
  .stage-book { width: 148px; }
  .dialog-controls { position: fixed; top: 0; left: 0; right: 0; justify-content: flex-end; padding: 12px; border-bottom: 1px solid transparent; transition: background .2s, border-color .2s; }
  .book-dialog.scrolled .dialog-controls { background: rgba(19,21,15,.97); border-bottom-color: var(--line); }
  .dialog-body { overflow: visible; padding: 0 20px 48px; }
  .meta-line { position: static; min-height: 0; margin: 0 0 16px; padding: 22px 0 0; border: 0; background: none; }
  .related-row .book-meta strong { font-size: 11px; overflow-wrap: anywhere; }
  .hook { font-size: 18px; }
  .related-row { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
  .related-row > :nth-child(5) { display: none; }
  .nav-card { padding: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .grid .book-btn { opacity: 1; transform: none; }
}
