@import url('https://fonts.googleapis.com/css2?family=Bebas+Neue&family=Space+Mono:ital,wght@0,400;0,700;1,400&display=swap');

/* ═══════════════════════════════════════
   DESIGN TOKENS
═══════════════════════════════════════ */
:root {
  --bg:        #0D0D0D;
  --accent:    #FFD60A;
  --border:    #FFFFFF;
  --cream:     #F5EDD6;
  --ink:       #000000;

  --shadow-sm: 3px 3px 0 var(--accent);
  --shadow-md: 5px 5px 0 var(--accent);
  --shadow-lg: 7px 7px 0 var(--accent);

  --border-rule: 3px solid var(--border);

  --mono: 'Space Mono', 'Courier New', Courier, monospace;
  --display: 'Bebas Neue', 'Arial Black', Arial, sans-serif;
}

/* ═══════════════════════════════════════
   RESET + BASE
═══════════════════════════════════════ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background: #0D0D0D;
  background-image: radial-gradient(ellipse 85% 55% at 50% 52%, #1e1308 0%, #0D0D0D 68%);
  color: var(--border);
  font-family: var(--mono);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  user-select: none;
}

/* Film grain */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 9998;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='250' height='250'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='250' height='250' filter='url(%23n)'/%3E%3C/svg%3E");
  opacity: 0.045;
  mix-blend-mode: overlay;
}

/* Vignette */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 9997;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 38%, rgba(0, 0, 0, 0.50) 100%);
}

/* ═══════════════════════════════════════
   HEADER
═══════════════════════════════════════ */
.header {
  margin-bottom: 20px;
  text-align: center;
}

.header-box {
  display: inline-block;
  background: var(--accent);
  border: var(--border-rule);
  box-shadow: var(--shadow-lg);
  padding: 6px 20px 2px;
}

.header h1 {
  font-family: var(--display);
  font-size: clamp(26px, 4.5vw, 44px);
  font-weight: 400;
  letter-spacing: 10px;
  text-transform: uppercase;
  color: var(--ink);
  line-height: 1;
}

.header-sub {
  margin-top: 14px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 5px;
  color: rgba(255, 255, 255, 0.55);
  text-transform: uppercase;
}

/* ═══════════════════════════════════════
   SHELF — PILE OF BOOK SPINES
═══════════════════════════════════════ */

/* Outer wrapper clips the scaled active book so it doesn't overflow */
.shelf-outer {
  position: relative;
  width: min(380px, 94vw);
  overflow: hidden;
}

/* Candlelight glow down the centre of the pile */
.shelf-outer::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 300px;
  height: 100%;
  background: radial-gradient(ellipse, rgba(255, 190, 30, 0.13) 0%, transparent 68%);
  pointer-events: none;
  z-index: 0;
}

.shelf-track {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  overflow-y: scroll;
  overflow-x: visible;
  scroll-snap-type: y proximity;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  /* Takes most of the screen height */
  height: clamp(300px, 64vh, 540px);
  /* Equal top+bottom padding so first AND last book can reach the centre */
  padding: clamp(140px, 32vh, 260px) 20px;
}

.shelf-track::-webkit-scrollbar {
  display: none;
}

/* ═══════════════════════════════════════
   BOOK — SPINE SLAB
═══════════════════════════════════════ */
.book {
  flex-shrink: 0;
  scroll-snap-align: center;
  cursor: pointer;
  transform-origin: center center;
  filter: brightness(0.42) saturate(0.55);
  transition:
    transform 0.3s cubic-bezier(0.34, 1.4, 0.64, 1),
    filter 0.3s ease;
  width: min(280px, 82%);
}

.book.near {
  filter: brightness(0.78) saturate(0.88);
  transform: scale(1.06);
  z-index: 4;
}

.book.active {
  filter: brightness(1) saturate(1.15);
  transform: scale(1.22);
  z-index: 10;
}

/* The slab itself: fixed width, height driven by book thickness */
.spine-slab {
  width: 100%;
  /* --thick = frontmatter `width` (spine thickness).  × 1.9 keeps slabs compact so
     the pile shows ~8-10 books in the viewport at once. */
  height: calc(var(--thick) * 1.9px);
  min-height: 26px;
  display: flex;
  align-items: center;
  border: var(--border-rule);
  overflow: hidden;
  transition: box-shadow 0.3s ease;
}

.book.active .spine-slab {
  box-shadow: 5px 5px 0 var(--accent), 0 8px 24px rgba(0, 0, 0, 0.65);
}

/* Left edge — simulates the physical spine binding crease */
.slab-edge {
  width: 14px;
  min-width: 14px;
  align-self: stretch;
  background: rgba(0, 0, 0, 0.28);
  border-right: 2px solid rgba(255, 255, 255, 0.22);
  flex-shrink: 0;
}

/* Right edge — cream pages visible from the side */
.slab-pages {
  width: 11px;
  min-width: 11px;
  flex-shrink: 0;
  align-self: stretch;
  margin-left: auto;
  background: repeating-linear-gradient(
    to bottom,
    #f0e4c2 0px,
    #f0e4c2 1.5px,
    #c8b57a 1.5px,
    #c8b57a 2.5px
  );
  border-left: 2px solid rgba(0, 0, 0, 0.45);
}

.slab-text {
  flex: 1;
  padding: 4px 10px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  overflow: hidden;
  min-height: 0;
}

.slab-title {
  font-family: var(--display);
  font-size: 12px;
  letter-spacing: 1.5px;
  color: #fff;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.65);
  text-transform: uppercase;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1;
}

.slab-author {
  font-family: var(--mono);
  font-size: 6.5px;
  letter-spacing: 1.5px;
  color: rgba(255, 255, 255, 0.65);
  text-transform: uppercase;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1;
}

/* ═══════════════════════════════════════
   INFO BAR
═══════════════════════════════════════ */
.info-bar {
  margin-top: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  min-height: 56px;
}

.book-tag {
  display: inline-block;
  background: var(--accent);
  color: var(--ink);
  border: var(--border-rule);
  box-shadow: var(--shadow-sm);
  padding: 3px 16px 0;
  font-family: var(--display);
  font-size: 22px;
  font-weight: 400;
  letter-spacing: 3px;
  text-transform: uppercase;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.2s, transform 0.2s;
  white-space: nowrap;
  min-width: 80px;
  text-align: center;
  max-width: min(340px, 90vw);
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-tag.visible {
  opacity: 1;
  transform: translateY(0);
}

.book-meta {
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 3px;
  color: rgba(255, 255, 255, 0.62);
  text-transform: uppercase;
  opacity: 0;
  transition: opacity 0.2s 0.06s;
  text-align: center;
}

.book-meta.visible {
  opacity: 1;
}

.scroll-hint {
  margin-top: 20px;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 5px;
  color: rgba(255, 255, 255, 0.45);
  text-transform: uppercase;
}

/* ═══════════════════════════════════════
   BOOK SPIN — slab flips away on open/close
═══════════════════════════════════════ */

/* Book slab shrinks to edge (like a coin flip) then disappears */
@keyframes bookFlipOut {
  0%   { transform: scale(1.22) scaleX(1);     filter: brightness(1) saturate(1.15); }
  40%  { transform: scale(1.28) scaleX(0.06);  filter: brightness(2.2) saturate(0); }
  100% { transform: scale(1.28) scaleX(0);     opacity: 0; }
}

/* Reverse: book slab reappears from edge on close */
@keyframes bookFlipIn {
  0%   { transform: scale(1.28) scaleX(0);     opacity: 0; }
  45%  { transform: scale(1.28) scaleX(0.06);  filter: brightness(2.2) saturate(0); }
  100% { transform: scale(1.22) scaleX(1);     filter: brightness(1) saturate(1.15); }
}

.book.is-opening {
  animation: bookFlipOut 0.36s cubic-bezier(0.55, 0.055, 0.675, 0.19) forwards;
  z-index: 20;
  pointer-events: none;
}

.book.is-closing {
  animation: bookFlipIn 0.38s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  z-index: 20;
}

/* ═══════════════════════════════════════
   OPEN BOOK — OVERLAY ENTRANCE
═══════════════════════════════════════ */

/* The whole book sweeps in as if rotating open from the spine */
@keyframes bookOpen {
  0%   { opacity: 0; transform: perspective(1000px) rotateY(-65deg) scale(0.78); }
  55%  {             transform: perspective(1000px) rotateY(4deg)   scale(1.02); }
  100% { opacity: 1; transform: perspective(1000px) rotateY(0deg)   scale(1);    }
}

/* Cover page falls open from top */
@keyframes coverFall {
  0%   { opacity: 0; transform: perspective(700px) rotateX(-70deg) translateY(-16px); }
  65%  {             transform: perspective(700px) rotateX(5deg); }
  100% { opacity: 1; transform: perspective(700px) rotateX(0deg); }
}

/* Review page unfurls downward */
@keyframes reviewUnfurl {
  0%   { opacity: 0; clip-path: inset(0 0 100% 0); }
  100% { opacity: 1; clip-path: inset(0 0 0%   0); }
}

/* ═══════════════════════════════════════
   OVERLAY
═══════════════════════════════════════ */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.overlay.open {
  opacity: 1;
  pointer-events: all;
}

/* Always vertical: cover on top, review below */
.open-book {
  display: flex;
  flex-direction: column;
  max-width: 480px;
  width: 92%;
  max-height: 88vh;
  border: var(--border-rule);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.open-book.book-opening {
  animation: bookOpen 0.52s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.open-book.book-opening .book-cover-page {
  transform-origin: top center;
  animation: coverFall 0.5s 0.05s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.open-book.book-opening .book-review-page {
  animation: reviewUnfurl 0.55s 0.22s ease-out both;
}

/* Horizontal spine crease between cover and review pages */
.book-gutter {
  height: 14px;
  min-height: 14px;
  flex-shrink: 0;
  background: #111;
  border-top: 3px solid var(--border);
  border-bottom: 3px solid var(--border);
  box-shadow: inset 0 4px 12px rgba(0, 0, 0, 0.88),
              inset 0 -4px 12px rgba(0, 0, 0, 0.88);
}

.book-cover-page {
  min-height: 220px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px 28px;
  position: relative;
}

.cover-title {
  font-family: var(--display);
  font-size: clamp(22px, 5vw, 34px);
  font-weight: 400;
  letter-spacing: 4px;
  text-transform: uppercase;
  color: #fff;
  text-align: center;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.5);
  margin-bottom: 10px;
  line-height: 1.1;
}

.cover-author {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 2px;
  color: rgba(255, 255, 255, 0.6);
  text-transform: uppercase;
  text-align: center;
}

.cover-badge {
  margin-top: 18px;
  background: rgba(0, 0, 0, 0.35);
  border: 2px solid rgba(255, 255, 255, 0.3);
  padding: 4px 12px;
  font-family: var(--mono);
  font-size: 8px;
  letter-spacing: 3px;
  color: rgba(255, 255, 255, 0.6);
  text-transform: uppercase;
}

.book-review-page {
  flex: 1;
  background: var(--cream);
  background-image: repeating-linear-gradient(
    transparent, transparent 27px,
    #d4c5a9 27px, #d4c5a9 28px
  );
  padding: 28px 24px 24px;
  position: relative;
  font-family: Georgia, serif;
  min-height: 180px;
  overflow-y: auto;
  max-height: 45vh;
}

.book-review-page::before {
  content: '';
  position: absolute;
  left: 44px;
  top: 0;
  bottom: 0;
  width: 1px;
  background: rgba(200, 70, 50, 0.4);
  pointer-events: none;
}

.review-title {
  font-size: 13px;
  font-weight: 700;
  color: #1a0f00;
  padding-left: 32px;
  line-height: 28px;
}

.review-stars {
  color: #c4821a;
  font-size: 14px;
  padding-left: 32px;
  line-height: 28px;
}

.review-stars:empty {
  display: none;
}

.review-date {
  font-size: 9px;
  letter-spacing: 2px;
  color: #8a7560;
  text-transform: uppercase;
  padding-left: 32px;
  line-height: 28px;
}

.review-body {
  padding-left: 32px;
  font-size: 12px;
  line-height: 28px;
  color: #3a2f1e;
}

.review-body p {
  margin: 0;
}

.open-book {
  position: relative;
}

.close-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 36px;
  height: 36px;
  background: var(--accent);
  border: var(--border-rule);
  box-shadow: var(--shadow-sm);
  font-family: var(--display);
  font-size: 18px;
  font-weight: 400;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 20;
  transition: background 0.1s, box-shadow 0.08s, transform 0.08s;
}

.close-btn:hover {
  background: #fff;
}

.close-btn:active {
  box-shadow: 1px 1px 0 var(--border);
  transform: translate(2px, 2px);
}

/* ═══════════════════════════════════════
   MOBILE SCROLL HINT
═══════════════════════════════════════ */
.mobile-hint {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  pointer-events: none;
  opacity: 0;
}

@media (hover: none) and (pointer: coarse) {
  .mobile-hint.visible {
    opacity: 1;
  }
}

.mobile-hint-arrow {
  display: block;
  font-size: 32px;
  color: var(--accent);
  text-shadow: 2px 2px 0 var(--border);
  animation: hint-pulse 1.2s ease-in-out infinite;
}

@keyframes hint-pulse {
  0%, 100% { transform: translateY(0);   opacity: 0.9; }
  50%       { transform: translateY(7px); opacity: 0.4; }
}
