/* ============================================================
   THE STUDY LIBRARY - bookshelf stylesheet
   Warm library / old-world-study aesthetic
   ============================================================ */

:root {
  --wall:       #2a1f18;
  --wall-lite:  #3a2d22;
  --wood:       #6b4423;
  --wood-dark:  #3d2611;
  --wood-lite:  #8b5a2b;
  --cream:      #f4ecd8;
  --parchment:  #e8dcc0;
  --ink:        #1a1410;
  --gold:       #c9a574;
  --gold-dim:   #8a7249;
  --accent:     #8b3a3a;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: 'Crimson Pro', Georgia, serif;
  color: var(--cream);
  min-height: 100vh;
  background:
    radial-gradient(ellipse at 30% 10%, rgba(201,165,116,.08), transparent 50%),
    radial-gradient(ellipse at 70% 90%, rgba(139,58,58,.06), transparent 50%),
    linear-gradient(180deg, var(--wall) 0%, var(--wall-lite) 100%);
  background-attachment: fixed;
  line-height: 1.6;
  overflow-x: hidden;
}

/* subtle noise texture overlay */
body::before {
  content: '';
  position: fixed; inset: 0;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='120' height='120'><filter id='n'><feTurbulence baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .25 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  pointer-events: none;
  opacity: .35;
  mix-blend-mode: overlay;
  z-index: 1;
}

/* ============================================================
   HEADER
   ============================================================ */
.library-header {
  position: relative;
  text-align: center;
  padding: 64px 24px 40px;
  border-bottom: 1px solid rgba(201,165,116,.15);
  z-index: 2;
}
.header-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.ornament {
  color: var(--gold);
  font-size: 22px;
  letter-spacing: .5em;
  opacity: .7;
}
.library-header h1 {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 600;
  font-size: clamp(2.4rem, 6vw, 4rem);
  color: var(--cream);
  letter-spacing: .02em;
  line-height: 1.1;
  text-shadow: 0 2px 20px rgba(0,0,0,.4);
}
.library-header .tagline {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 1.1rem;
  color: var(--gold);
  opacity: .85;
  max-width: 520px;
}
.admin-link {
  position: absolute;
  top: 20px; right: 24px;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  color: var(--gold-dim);
  font-size: 20px;
  text-decoration: none;
  border-radius: 50%;
  transition: all .3s ease;
  border: 1px solid rgba(201,165,116,.15);
}
.admin-link:hover {
  color: var(--gold);
  border-color: var(--gold);
  transform: rotate(45deg);
}

/* ============================================================
   LIBRARY / SHELVES
   ============================================================ */
.library {
  position: relative;
  max-width: 1280px;
  margin: 40px auto;
  padding: 0 32px 80px;
  z-index: 2;
}

.shelf-section { margin-bottom: 72px; }

.shelf-title {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 400;
  font-style: italic;
  font-size: 1.8rem;
  color: var(--gold);
  text-align: center;
  margin-bottom: 24px;
  position: relative;
  letter-spacing: .05em;
}
.shelf-title span {
  background:
    linear-gradient(180deg, var(--wall), var(--wall-lite));
  padding: 0 28px;
  position: relative;
  z-index: 1;
}
.shelf-title::before {
  content: '';
  position: absolute;
  top: 50%; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-dim), transparent);
}

/* The shelf itself */
.shelf {
  position: relative;
  padding-top: 40px;
}
.books-row {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px;
  padding: 0 28px;
  min-height: 230px;
}

/* The wooden shelf plank */
.shelf-plank {
  height: 28px;
  margin-top: -2px;
  background:
    linear-gradient(180deg,
      var(--wood-lite) 0%,
      var(--wood) 18%,
      var(--wood-dark) 100%);
  border-radius: 2px;
  box-shadow:
    inset 0 2px 4px rgba(255,220,180,.15),
    inset 0 -4px 8px rgba(0,0,0,.5),
    0 8px 20px rgba(0,0,0,.5),
    0 18px 30px -10px rgba(0,0,0,.6);
  position: relative;
}
.shelf-plank::before {
  content: '';
  position: absolute; inset: 0;
  background-image:
    repeating-linear-gradient(90deg,
      transparent 0 40px,
      rgba(0,0,0,.08) 40px 41px,
      transparent 41px 80px);
  border-radius: inherit;
  opacity: .5;
}

/* ============================================================
   BOOK
   ============================================================ */
.book {
  position: relative;
  width: 46px;
  height: 210px;
  perspective: 1200px;
  cursor: pointer;
  transition: transform .5s cubic-bezier(.2,.8,.2,1),
              margin .5s cubic-bezier(.2,.8,.2,1);
  transform-style: preserve-3d;
  flex-shrink: 0;
}
.book:nth-child(3n)   { height: 218px; }
.book:nth-child(4n+1) { height: 205px; width: 52px; }
.book:nth-child(5n+2) { height: 224px; width: 44px; }
.book:nth-child(7n+3) { height: 200px; width: 48px; }

.book:hover {
  transform: translateY(-14px);
  margin: 0 6px;
  z-index: 5;
}

/* The spine - what you see by default */
.book-spine {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg,
      rgba(0,0,0,.35) 0%,
      rgba(0,0,0,0) 12%,
      rgba(255,255,255,.08) 50%,
      rgba(0,0,0,0) 88%,
      rgba(0,0,0,.4) 100%),
    var(--spine, #8B4513);
  border-radius: 2px 1px 1px 2px;
  box-shadow:
    inset 1px 0 0 rgba(255,255,255,.15),
    inset -1px 0 0 rgba(0,0,0,.35),
    inset 0 2px 0 rgba(255,255,255,.08),
    inset 0 -2px 0 rgba(0,0,0,.3),
    0 4px 10px rgba(0,0,0,.4);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 14px 4px;
  overflow: hidden;
  transition: all .4s ease;
}

/* decorative bands top & bottom of spine */
.book-spine::before,
.book-spine::after {
  content: '';
  position: absolute;
  left: 4px; right: 4px;
  height: 8px;
  border-top: 1px solid rgba(255,255,255,.18);
  border-bottom: 1px solid rgba(0,0,0,.25);
}
.book-spine::before { top: 10px; }
.book-spine::after  { bottom: 10px; }

.book-spine-title {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-family: 'Cormorant Garamond', serif;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: .05em;
  color: rgba(255,245,220,.95);
  text-shadow: 0 1px 2px rgba(0,0,0,.6);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-height: 150px;
  flex: 1;
  display: flex;
  align-items: center;
}
.book-spine-author {
  font-family: 'Crimson Pro', serif;
  font-size: 8px;
  letter-spacing: .15em;
  text-transform: uppercase;
  color: rgba(255,245,220,.7);
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  white-space: nowrap;
}

/* The flat cover that shows on hover */
.book-cover {
  position: absolute;
  top: 0; left: 0;
  width: 140px;
  height: 100%;
  background: var(--spine, #8B4513);
  border-radius: 2px 4px 4px 2px;
  transform-origin: left center;
  transform: rotateY(-88deg);
  opacity: 0;
  box-shadow:
    4px 4px 20px rgba(0,0,0,.55),
    inset 0 0 40px rgba(0,0,0,.3);
  transition: all .5s cubic-bezier(.2,.8,.2,1);
  overflow: hidden;
  pointer-events: none;
}
.book:hover .book-cover {
  transform: rotateY(-20deg) translateX(4px);
  opacity: 1;
}
.book-cover img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.book-cover-text {
  width: 100%; height: 100%;
  display: flex; flex-direction: column;
  justify-content: center; align-items: center;
  padding: 16px 12px;
  text-align: center;
  background:
    linear-gradient(135deg, rgba(255,255,255,.08), transparent 50%),
    var(--spine);
  border: 6px double rgba(255,245,220,.25);
}
.cover-title {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 700;
  font-size: 13px;
  color: var(--cream);
  line-height: 1.2;
  margin-bottom: 8px;
  text-shadow: 0 1px 3px rgba(0,0,0,.5);
}
.cover-author {
  font-family: 'Crimson Pro', serif;
  font-style: italic;
  font-size: 10px;
  color: rgba(255,245,220,.75);
}

/* ============================================================
   MODAL
   ============================================================ */
.modal {
  position: fixed; inset: 0;
  z-index: 1000;
  display: none;
  align-items: center; justify-content: center;
  padding: 24px;
}
.modal.open { display: flex; animation: fadeIn .3s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(10,6,4,.85);
  backdrop-filter: blur(6px);
}
.modal-card {
  position: relative;
  background: var(--parchment);
  color: var(--ink);
  max-width: 640px;
  width: 100%;
  border-radius: 4px;
  box-shadow:
    0 30px 80px rgba(0,0,0,.7),
    0 0 0 1px rgba(201,165,116,.3);
  overflow: hidden;
  animation: slideUp .4s cubic-bezier(.2,.8,.2,1);
}
@keyframes slideUp {
  from { transform: translateY(30px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
.modal-close {
  position: absolute; top: 12px; right: 16px;
  width: 32px; height: 32px;
  border: none; background: transparent;
  font-size: 28px; color: var(--ink);
  cursor: pointer;
  opacity: .5;
  transition: all .2s ease;
  z-index: 2;
}
.modal-close:hover { opacity: 1; transform: rotate(90deg); }

.modal-body {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 28px;
  padding: 36px;
}
.modal-cover {
  aspect-ratio: 2/3;
  background: var(--wood-dark);
  border-radius: 3px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0,0,0,.3);
}
.modal-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.modal-cover img[src=""] { display: none; }
.modal-placeholder {
  width: 100%; height: 100%;
  background:
    linear-gradient(135deg, var(--wood-lite), var(--wood-dark));
  display: none;
  align-items: center; justify-content: center;
  font-family: 'Cormorant Garamond', serif;
  font-size: 48px;
  color: var(--gold);
  opacity: .5;
}
.modal-cover img[src=""] + .modal-placeholder { display: flex; }

.modal-info h3 {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 700;
  font-size: 1.9rem;
  line-height: 1.1;
  margin-bottom: 4px;
  color: var(--ink);
}
.modal-author {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 1.1rem;
  color: var(--accent);
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(107,68,35,.2);
}
.modal-desc {
  font-family: 'Crimson Pro', serif;
  font-size: 1.02rem;
  color: var(--ink);
  opacity: .88;
  margin-bottom: 24px;
  line-height: 1.7;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn-primary {
  display: inline-block;
  padding: 11px 24px;
  background: var(--ink);
  color: var(--parchment);
  font-family: 'Crimson Pro', serif;
  font-size: 1rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  text-decoration: none;
  border: 1px solid var(--ink);
  border-radius: 2px;
  cursor: pointer;
  transition: all .3s ease;
  position: relative;
  overflow: hidden;
}
.btn-primary:hover {
  background: var(--accent);
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(139,58,58,.4);
}

/* ============================================================
   EMPTY STATE & FOOTER
   ============================================================ */
.empty-state {
  text-align: center;
  padding: 80px 24px;
}
.empty-state p {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 1.4rem;
  color: var(--gold);
  margin-bottom: 24px;
  opacity: .7;
}

.library-footer {
  text-align: center;
  padding: 32px 24px;
  border-top: 1px solid rgba(201,165,116,.15);
  color: var(--gold-dim);
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: .95rem;
  position: relative;
  z-index: 2;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
  .library { padding: 0 12px 60px; margin-top: 24px; }
  .library-header { padding: 40px 16px 28px; }
  .books-row { padding: 0 12px; gap: 3px; min-height: 180px; }
  .book { width: 38px; height: 170px; }
  .book:nth-child(3n)   { height: 175px; }
  .book:nth-child(4n+1) { height: 165px; width: 42px; }
  .book:nth-child(5n+2) { height: 180px; width: 36px; }
  .book-spine-title { font-size: 11px; }
  .book-cover { width: 110px; }
  .modal-body { grid-template-columns: 1fr; padding: 24px; gap: 20px; }
  .modal-cover { max-width: 180px; margin: 0 auto; }
  .modal-info h3 { font-size: 1.5rem; }
  .shelf-title { font-size: 1.4rem; }
}
