/* Library / Landing page — dark sci-fi theme */

.library {
  min-height: 100vh;
  min-height: 100dvh;
  background: #141820;
  color: #e0ddd8;
  position: relative;
  overflow: hidden;
  padding: 1.5rem 1.5rem;
}

/* ---- STARFIELD + NEBULA ---- */

.starfield {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

.library-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}

.nebula {
  position: absolute;
  border-radius: 50%;
  filter: blur(100px);
  animation: drift-nebula 30s infinite ease-in-out;
}

.nebula-1 {
  width: 650px;
  height: 500px;
  background: radial-gradient(ellipse, rgba(60, 50, 80, 0.22), transparent 70%);
  top: -8%;
  left: -12%;
  animation-delay: 0s;
}

.nebula-2 {
  width: 600px;
  height: 450px;
  background: radial-gradient(ellipse, rgba(40, 60, 80, 0.18), transparent 70%);
  bottom: -8%;
  right: -12%;
  animation-delay: -15s;
}

.nebula-3 {
  width: 500px;
  height: 400px;
  background: radial-gradient(ellipse, rgba(100, 60, 40, 0.14), transparent 70%);
  top: 40%;
  left: 50%;
  transform: translateX(-50%);
  animation-delay: -8s;
}

@keyframes drift-nebula {
  0%, 100% {
    transform: translate(0, 0) scale(1);
    opacity: 0.7;
  }
  33% {
    transform: translate(30px, -20px) scale(1.05);
    opacity: 1;
  }
  66% {
    transform: translate(-20px, 15px) scale(0.95);
    opacity: 0.6;
  }
}

/* ---- HEADER ---- */

.library-header {
  text-align: center;
  margin-bottom: 1.5rem;
  position: relative;
  z-index: 1;
  animation: fade-in-up 0.6s ease-out both;
}

.library-title {
  font-size: 2rem;
  font-weight: normal;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #e8e4de;
  margin-bottom: 0.3rem;
  line-height: 1.15;
}

.library-tagline {
  font-size: 0.84rem;
  letter-spacing: 0.12em;
  color: #8a857e;
  font-style: italic;
  margin-bottom: 1rem;
}

.library-divider {
  width: 60px;
  height: 1px;
  background: rgba(200, 195, 188, 0.2);
  margin: 0 auto;
}

/* ---- COVER GRID ---- */

.book-grid {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 1.5rem;
  flex-wrap: wrap;
  max-width: 960px;
  margin: 0 auto 3rem;
  position: relative;
  z-index: 1;
}

/* Each item is a flex row: cover left, detail right */
.book-cover-item {
  display: flex;
  align-items: stretch;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  transition: background 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
  padding: 0.6rem;
  animation: fade-in-up 0.6s ease-out both;
}

.book-cover-item:nth-child(1) { animation-delay: 0.1s; }
.book-cover-item:nth-child(2) { animation-delay: 0.2s; }
.book-cover-item:nth-child(3) { animation-delay: 0.3s; }
.book-cover-item:nth-child(4) { animation-delay: 0.4s; }
.book-cover-item:nth-child(5) { animation-delay: 0.5s; }

/* Expanded: card wraps cover + detail together */
.book-cover-item.expanded {
  background: rgba(20, 24, 32, 0.65);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-color: rgba(var(--cover-accent-rgb, 160, 151, 142), 0.15);
  box-shadow:
    0 4px 24px rgba(0, 0, 0, 0.25),
    0 0 40px rgba(var(--cover-accent-rgb, 160, 151, 142), 0.06);
  align-self: flex-start;
}

/* ---- COVER BUTTON ---- */

.book-cover-btn {
  flex-shrink: 0;
  width: 180px;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  position: relative;
  display: block;
}

/* Lock all covers to 2:3 so they line up */
.book-cover-img-wrap {
  position: relative;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  aspect-ratio: 2 / 3;
}

.book-cover-btn:hover .book-cover-img-wrap {
  transform: scale(1.04);
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.5),
    0 0 40px rgba(var(--cover-accent-rgb, 160, 151, 142), 0.12);
}

/* No hover scale when already expanded */
.expanded .book-cover-btn:hover .book-cover-img-wrap {
  transform: none;
}

.book-cover-img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ---- COVER PROGRESS BAR (3px at bottom edge) ---- */

.book-cover-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: rgba(0, 0, 0, 0.3);
}

.book-cover-progress-fill {
  height: 100%;
  background: var(--cover-accent, #a39890);
  transition: width 0.6s ease-out;
}

/* ---- CAUGHT-UP CHECKMARK ---- */

.book-cover-caught-up::after {
  content: '\2713';
  position: absolute;
  bottom: 10px;
  right: 10px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(30, 180, 90, 0.9);
  color: #fff;
  font-size: 14px;
  line-height: 24px;
  text-align: center;
  z-index: 2;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

/* ---- PLACEHOLDER (no cover image) ---- */

.book-cover-placeholder {
  width: 100%;
  height: 100%;
  background: linear-gradient(
    135deg,
    rgba(var(--cover-accent-rgb, 160, 151, 142), 0.2),
    rgba(var(--cover-accent-rgb, 160, 151, 142), 0.05)
  );
  border: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: rgba(var(--cover-accent-rgb, 160, 151, 142), 0.5);
}

/* ---- BADGE (Coming Soon) ---- */

.book-cover-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  font-family: var(--font-ui);
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #c0bbb5;
  background: rgba(20, 24, 32, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 3px;
  padding: 2px 7px;
  z-index: 2;
}

/* ---- DETAIL PANEL (slides open beside cover) ---- */

.book-detail {
  max-width: 0;
  height: 0;
  opacity: 0;
  overflow: hidden;
  visibility: hidden;
  transition:
    max-width 0.4s cubic-bezier(0.4, 0, 0.2, 1),
    opacity 0.15s ease,
    visibility 0s 0.4s;
}

.expanded .book-detail {
  max-width: 280px;
  height: auto;
  opacity: 1;
  visibility: visible;
  transition:
    max-width 0.4s cubic-bezier(0.4, 0, 0.2, 1),
    opacity 0.3s ease 0.1s,
    visibility 0s 0s;
}

/* Fixed inner width prevents content reflow during max-width animation.
   overflow-y clips content that exceeds cover height. */
.book-detail-inner {
  min-width: 250px;
  padding: 0.25rem 0.5rem 0.5rem 0.75rem;
  display: flex;
  flex-direction: column;
  height: 100%;
  box-sizing: border-box;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.08) transparent;
}

.book-detail-subtitle {
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #9a9590;
  margin-bottom: 0.4rem;
}

.book-detail-description {
  font-size: 0.8rem;
  font-style: italic;
  color: #9a9590;
  line-height: 1.55;
  margin-bottom: 0.75rem;
}

/* ---- CHAPTER LIST (in detail panel) ---- */

.book-detail-chapters {
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  padding-top: 0.4rem;
  flex: 1;
  min-height: 0;
}

.book-detail-continue {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0;
  text-decoration: none;
  font-family: var(--font-ui);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--cover-accent, #a39890);
  transition: color 0.15s;
}

.book-detail-continue:hover {
  color: #f0ece8;
}

.book-detail-chapter-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.book-detail-chapter-list li + li {
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.book-detail-chapter-item {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.3rem 0;
  color: #8a857e;
  font-size: 0.72rem;
}

.book-detail-chapter-label {
  font-family: var(--font-ui);
  font-size: 0.6rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  flex-shrink: 0;
}

.book-detail-chapter-title {
  font-style: italic;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #9a9590;
}

/* ---- READING PROGRESS INDICATORS ---- */

.book-detail-chapter-current .book-detail-chapter-label {
  color: var(--cover-accent, #a39890);
}

.book-detail-chapter-current .book-detail-chapter-title {
  color: #d0cdc8;
}

.book-detail-chapter-new .book-detail-chapter-item::after {
  content: 'NEW';
  font-family: var(--font-ui);
  font-size: 0.5rem;
  font-style: normal;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--cover-accent, #a39890);
  border: 1px solid rgba(var(--cover-accent-rgb, 160, 151, 142), 0.35);
  border-radius: 2px;
  padding: 0 4px;
  flex-shrink: 0;
  line-height: 1.6;
}

/* ---- DETAIL PROGRESS BAR ---- */

.book-detail-progress-bar {
  height: 2px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 1px;
  margin-top: auto;
  flex-shrink: 0;
}

.book-detail-progress-fill {
  height: 100%;
  background: var(--cover-accent, #a39890);
  border-radius: 1px;
  transition: width 0.6s ease-out;
}

/* ---- ENTRANCE ANIMATIONS ---- */

@keyframes fade-in-up {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .library-header,
  .book-cover-item {
    animation: none;
  }
}

/* ---- LIBRARY FOOTER ---- */

.library-footer {
  text-align: center;
  padding-top: 2rem;
  font-family: var(--font-ui);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  color: #5a5550;
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1.5rem;
}

.library-footer-link {
  color: #5a5550;
  text-decoration: none;
  transition: color 0.15s;
}

.library-footer-link:hover {
  color: #a89f96;
}

/* ---- NOTIFICATION SIGNUP SECTION ---- */

.library-notify {
  position: relative;
  z-index: 1;
  max-width: 800px;
  margin: 0 auto 3rem;
}

/* ---- RESPONSIVE ---- */

@media (max-width: 680px) {
  .library {
    padding: 1.25rem 1rem;
  }

  .library-header {
    margin-bottom: 1.25rem;
  }

  .library-title {
    font-size: 1.6rem;
    letter-spacing: 0.15em;
  }

  .book-grid {
    gap: 1.25rem;
    margin-bottom: 2.5rem;
  }

  .book-cover-btn {
    width: 150px;
  }

  .expanded .book-detail {
    max-width: 240px;
  }

  .book-detail-inner {
    min-width: 210px;
    padding: 0.2rem 0.4rem 0.4rem 0.6rem;
  }
}

/* Mobile: column layout, detail drops below cover */
@media (max-width: 480px) {
  .library {
    padding: 1rem 0.75rem;
  }

  .library-header {
    margin-bottom: 1rem;
  }

  .library-title {
    font-size: 1.3rem;
    letter-spacing: 0.18em;
  }

  .book-grid {
    gap: 1rem;
  }

  .book-cover-btn {
    width: 120px;
  }

  /* Switch to column: cover on top, detail below */
  .book-cover-item {
    flex-direction: column;
    align-items: center;
  }

  /* Expanded item takes the full row */
  .book-cover-item.expanded {
    flex-basis: 100%;
  }

  /* Keep cover centered when expanded */
  .expanded .book-cover-btn {
    align-self: center;
  }

  /* Detail stretches full width and animates via max-height */
  .book-detail {
    max-width: none;
    max-height: 0;
    width: 100%;
    transition:
      max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1),
      opacity 0.15s ease,
      visibility 0s 0.4s;
  }

  .expanded .book-detail {
    max-width: none;
    max-height: 500px;
    height: auto;
    align-self: stretch;
    transition:
      max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1),
      opacity 0.3s ease 0.1s,
      visibility 0s 0s;
  }

  .book-detail-inner {
    min-width: 0;
    width: auto;
    height: auto;
    padding: 0.75rem 0.25rem 0.5rem;
    overflow-y: visible;
  }
}
