/* =========================================================
   TOKENS
   ========================================================= */
:root {
  --void: #0b0908;
  --wood-dark:  #1c130d;
  --wood-mid:   #3c2a1e;
  --wood-light: #6b4a34;
  --candle:     #464a5c;
  --ink:        #bebdc7;
  --blood:      #7a1118;

  --card-w: 128px;
  --card-h: 184px;
  --gap: 14px;
}

* { box-sizing: border-box; }

/* =========================================================
   BASE / ATMOSPHERE
   ========================================================= */
body.library {
  margin: 0;
  min-height: 100vh;
  background: var(--void);
  font-family: "Inconsolata", monospace;
  overflow-x: hidden;
  transition: opacity 0.5s ease;
}

body.library.fade-out { opacity: 0; }

.return-link {
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 9999;
  color: var(--ink);
  opacity: 0.5;
  font-family: "Inconsolata", monospace;
  font-size: 13px;
  letter-spacing: 0.5px;
  text-decoration: none;
  transition: opacity 0.25s ease;
}
.return-link:hover { opacity: 0.9; }

#libraryBG {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 50% 15%, rgba(201,168,118,0.07), transparent 55%),
    radial-gradient(circle at 85% 80%, rgba(122,17,24,0.06), transparent 50%),
    radial-gradient(ellipse at 50% 50%, transparent 40%, rgba(0,0,0,0.65) 100%);
}

/* faint film-grain / dust, drawn purely with CSS (SVG turbulence) */
#grain {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0.05;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* =========================================================
   HEADER
   ========================================================= */
#libraryHeader {
  position: relative;
  z-index: 2;
  text-align: center;
  padding: 56px 20px 20px;
}

#libraryHeader h1 {
  margin: 0;
  color: var(--candle);
  font-family: "UnifrakturMaguntia", cursive;
  font-size: 54px;
  font-weight: 400;
  text-shadow: 0 0 18px rgba(201,168,118,0.25), 0 2px 0 rgba(0,0,0,0.6);
  letter-spacing: 1px;
}

#libraryTag {
  margin: 6px 0 0;
  color: rgba(232,222,208,0.4);
  font-family: "IM Fell English SC", serif;
  font-size: 14px;
  letter-spacing: 2px;
  font-style: italic;
}

/* =========================================================
   SHELVES CONTAINER
   ========================================================= */
#shelves {
  position: relative;
  z-index: 2;
  max-width: 1100px;
  margin: 10px auto 80px;
  padding: 10px clamp(16px, 5vw, 40px) 30px;
}

.shelf-title {
  text-transform: uppercase;
  text-align: left;
  color: var(--candle);
  font-family: "IM Fell English SC", serif;
  font-size: 20px;
  letter-spacing: 3px;
  margin: 34px 4px 10px;
  opacity: 0.85;
}
.shelf-title:first-child { margin-top: 4px; }

/* =========================================================
   INDIVIDUAL SHELF (the timber plank)
   ========================================================= */
.shelf {
  position: relative;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: var(--card-w);
  gap: var(--gap);
  align-items: end;

  padding: 20px 16px 26px;

  background:
    repeating-linear-gradient(
      90deg,
      rgba(0,0,0,0.12) 0px,
      rgba(0,0,0,0.12) 1px,
      transparent 1px,
      transparent 7px
    ),
    radial-gradient(ellipse at 20% 30%, rgba(0,0,0,0.25) 0%, transparent 45%),
    radial-gradient(ellipse at 75% 60%, rgba(0,0,0,0.2) 0%, transparent 40%),
    linear-gradient(180deg, var(--wood-light) 0%, var(--wood-mid) 55%, var(--wood-dark) 100%);

  border-top: 3px solid rgba(255,255,255,0.05);
  box-shadow:
    inset 0 12px 18px -12px rgba(0,0,0,0.6),
    0 18px 14px -10px rgba(0,0,0,0.55);

  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--blood) transparent;
}

/* the thick lower "lip" of the shelf plank, for depth */
.shelf::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -10px;
  height: 10px;
  background: linear-gradient(180deg, var(--wood-dark), #100b08);
  box-shadow: 0 6px 10px rgba(0,0,0,0.5);
}

.shelf::-webkit-scrollbar { height: 6px; }
.shelf::-webkit-scrollbar-track { background: transparent; }
.shelf::-webkit-scrollbar-thumb {
  background: rgba(122,17,24,0.55);
  border-radius: 10px;
}

/* =========================================================
   BOOKS — fixed, equal size; title hidden until hover/focus
   ========================================================= */
.book {
  position: relative;
  width: var(--card-w);
  height: var(--card-h);
  overflow: hidden;

  border-radius: 2px;
  border: 1px solid rgba(0,0,0,0.5);
  box-shadow:
    0 10px 16px -6px rgba(0,0,0,0.7),
    0 0 0 1px rgba(255,255,255,0.03);

  cursor: pointer;
  transition: transform 0.28s ease, box-shadow 0.28s ease;
}

.book img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  filter: sepia(0.35) saturate(0.7) brightness(0.85) contrast(1.05);
  transition: filter 0.35s ease, transform 0.35s ease;
}

/* subtle vignette on every cover so mismatched source images read as one set */
.book::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  box-shadow: inset 0 0 22px rgba(0,0,0,0.55);
  background: linear-gradient(180deg, rgba(0,0,0,0.1), transparent 30%, transparent 60%, rgba(0,0,0,0.35));
}

.book:hover,
.book:focus-visible {
  transform: translateY(-8px);
  box-shadow:
    0 18px 24px -8px rgba(0,0,0,0.8),
    0 0 16px rgba(122,17,24,0.35);
  outline: none;
}

.book:hover img,
.book:focus-visible img {
  filter: sepia(0.05) saturate(1) brightness(1) contrast(1.02);
  transform: scale(1.04);
}

/* the title — sits hidden below the frame, slides up like a library card */
.book .label {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  z-index: 2;

  padding: 8px 6px 7px;
  background: linear-gradient(0deg, rgba(6,4,3,0.95) 40%, rgba(6,4,3,0.75) 80%, transparent);

  color: var(--candle);
  font-family: "Inconsolata", monospace;
  font-size: 11px;
  font-weight: 600;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  line-height: 1.3;

  transform: translateY(100%);
  transition: transform 0.3s ease;
}

.book:hover .label,
.book:focus-visible .label {
  transform: translateY(0);
}

/* =========================================================
   RESPONSIVE
   ========================================================= */
@media (max-width: 560px) {
  :root {
    --card-w: 104px;
    --card-h: 152px;
    --gap: 10px;
  }
  #libraryHeader h1 { font-size: 40px; }
  .shelf { padding: 16px 12px 22px; }
}

/* respect reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  .book, .book img, .book .label, body.library {
    transition: none !important;
  }
}