/* Story Land — My Books / Library magical experience */

#screen-library {
  padding-bottom: var(--home-nav-height, 96px);
  overflow-x: clip;
  flex-direction: column;
}

/* ── Header with Story Land branding ── */
.library-header {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 14px 20px 0;
  max-width: 1140px;
  margin: 0 auto;
  width: 100%;
  gap: 8px;
}

.library-back svg {
  width: 44px;
  height: 44px;
  padding: 10px;
  background: var(--purple);
  border-radius: 50%;
  color: #fff;
  box-shadow: 0 5px 18px rgba(90, 45, 145, 0.38);
  transition: transform 0.2s, box-shadow 0.2s;
}

.library-back:hover svg {
  transform: scale(1.06);
  box-shadow: 0 6px 22px rgba(90, 45, 145, 0.48);
}

.library-back span {
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

.logo-block--library {
  flex: 1;
  text-align: center;
}

.logo-block--library .logo-cloud {
  padding: 8px 24px 12px;
}

.logo-block--library .logo-text {
  font-size: clamp(1.35rem, 3.8vw, 2rem);
}

.logo-block--library .logo-banner {
  font-size: 0.72rem;
  padding: 5px 22px;
}

.library-header-spacer {
  width: 44px;
  flex-shrink: 0;
}

/* ── Intro / page title ── */
.library-main {
  position: relative;
  z-index: 5;
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px 20px 28px;
  max-width: 1140px;
  margin: 0 auto;
  width: 100%;
}

.library-intro {
  text-align: center;
  margin-bottom: 20px;
}

.library-page-title {
  font-family: var(--font-display);
  font-size: clamp(1.4rem, 4vw, 1.85rem);
  color: #fff;
  text-shadow:
    0 2px 8px rgba(90, 45, 145, 0.5),
    0 1px 2px rgba(0, 0, 0, 0.2);
  margin-bottom: 6px;
}

.library-subtitle {
  font-size: 0.95rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.92);
  text-shadow: 0 1px 6px rgba(90, 45, 145, 0.4);
}

/* ── Meadow path atmosphere ── */
.library-meadow {
  position: relative;
  flex: 1;
  padding: 8px 0 16px;
}

.library-meadow::before {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(320px, 70%);
  height: 60%;
  background: radial-gradient(ellipse at center bottom, rgba(255, 213, 79, 0.15) 0%, transparent 70%);
  pointer-events: none;
}

/* ── Book grid — cover-forward, compact cards ── */
#screen-library .library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 22px 18px;
  padding: 8px 4px 20px;
  position: relative;
  z-index: 1;
}

#screen-library .book-card {
  width: auto;
  padding: 0;
  animation: library-enter 0.55s cubic-bezier(0.34, 1.3, 0.64, 1) backwards;
}

#screen-library .book-card:nth-child(1) { animation-delay: 0.04s; }
#screen-library .book-card:nth-child(2) { animation-delay: 0.1s; }
#screen-library .book-card:nth-child(3) { animation-delay: 0.16s; }
#screen-library .book-card:nth-child(4) { animation-delay: 0.22s; }
#screen-library .book-card:nth-child(5) { animation-delay: 0.28s; }
#screen-library .book-card:nth-child(6) { animation-delay: 0.34s; }
#screen-library .book-card:nth-child(n+7) { animation-delay: 0.4s; }

@keyframes library-enter {
  from {
    opacity: 0;
    transform: translateY(24px) scale(0.92);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Compact shelf — cover dominates, minimal empty space */
#screen-library .book-card-inner {
  padding: 5px 5px 6px;
  border-radius: 18px;
  background: linear-gradient(165deg, rgba(255, 252, 245, 0.97) 0%, rgba(255, 248, 235, 0.95) 100%);
  border: 2px solid rgba(255, 255, 255, 0.8);
  box-shadow:
    0 8px 28px rgba(90, 45, 145, 0.2),
    0 3px 8px rgba(0, 0, 0, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.95);
  transition:
    transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1),
    box-shadow 0.35s ease;
}

#screen-library .book-card:hover .book-card-inner {
  transform: translateY(-12px) scale(1.05);
  box-shadow:
    0 20px 52px rgba(123, 79, 191, 0.42),
    0 0 0 4px rgba(255, 213, 79, 0.55),
    0 0 32px rgba(255, 213, 79, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 1);
  animation: library-bounce 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#screen-library .book-card:active .book-card-inner {
  transform: translateY(-4px) scale(0.98);
}

@keyframes library-bounce {
  0%   { transform: translateY(0) scale(1); }
  45%  { transform: translateY(-14px) scale(1.06); }
  75%  { transform: translateY(-10px) scale(1.04); }
  100% { transform: translateY(-12px) scale(1.05); }
}

/* Large covers */
#screen-library .book-cover-wrap {
  border-radius: 14px;
  aspect-ratio: 3 / 4.1;
  box-shadow:
    0 10px 26px rgba(0, 0, 0, 0.24),
    inset 0 -2px 6px rgba(0, 0, 0, 0.06);
}

#screen-library .book-cover-wrap img {
  object-fit: cover;
  object-position: center top;
}

#screen-library .book-card:hover .book-cover-wrap img {
  transform: scale(1.06);
}

#screen-library .book-star-corner {
  width: 24px;
  height: 24px;
  font-size: 0.7rem;
  top: 6px;
  right: 6px;
}

#screen-library .book-badge {
  top: 6px;
  left: 6px;
  font-size: 0.6rem;
  padding: 2px 8px;
}

/* Title snug under cover */
#screen-library .book-title-label {
  margin-top: 5px;
  padding: 4px 6px;
  min-height: unset;
  font-size: clamp(0.7rem, 2.2vw, 0.8rem);
  line-height: 1.2;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: none;
}

/* ── Empty state ── */
.library-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 40px 24px;
  background: rgba(255, 252, 245, 0.92);
  border-radius: 24px;
  border: 2px solid rgba(255, 213, 79, 0.5);
  box-shadow: 0 12px 40px rgba(90, 45, 145, 0.18);
}

.library-empty-icon {
  font-size: 3rem;
  display: block;
  margin-bottom: 12px;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.15));
}

.library-empty p {
  font-family: var(--font-display);
  font-size: 1.1rem;
  color: #5A2D91;
  margin-bottom: 16px;
}

.library-empty .btn-magic {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 12px 24px;
  background: linear-gradient(180deg, #9B6FD4 0%, #6B3FA0 100%);
  color: #fff;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.9rem;
  border-radius: var(--radius-pill);
  box-shadow: 0 6px 20px rgba(107, 63, 160, 0.4);
  border: 2px solid rgba(255, 255, 255, 0.2);
  transition: transform 0.2s;
}

.library-empty .btn-magic:hover {
  transform: scale(1.04);
}

/* ── Bottom nav (reuse home premium shell) ── */
#screen-library .bottom-nav-shell .nav-item {
  position: relative;
  z-index: 1;
  flex: 1;
  padding: 11px 8px;
  font-size: 0.7rem;
  font-weight: 800;
  color: rgba(255, 255, 255, 0.8);
  border-radius: 22px;
  transition: all 0.25s cubic-bezier(0.34, 1.2, 0.64, 1);
}

#screen-library .bottom-nav-shell .nav-item svg {
  width: 26px;
  height: 26px;
}

#screen-library .bottom-nav-shell .nav-item.active {
  background: linear-gradient(180deg, #fff 0%, #F8F0FF 100%);
  color: #6B3FA0;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.16);
}

#screen-library .bottom-nav-shell .nav-item:not(.active):hover {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
}

/* ── Desktop ── */
@media (min-width: 960px) {
  #screen-library .library-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 28px 24px;
    max-width: 960px;
    margin: 0 auto;
    padding: 12px 8px 24px;
  }

  #screen-library .book-cover-wrap {
    aspect-ratio: 3 / 4.15;
  }
}

@media (min-width: 640px) and (max-width: 959px) {
  #screen-library .library-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 24px 20px;
  }
}

/* ── Mobile ── */
@media (max-width: 639px) {
  .library-header {
    padding: 12px 14px 0;
  }

  .library-main {
    padding: 12px 14px 24px;
  }

  #screen-library .library-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px 14px;
  }

  .logo-block--library .logo-text {
    font-size: 1.25rem;
  }

  .logo-block--library .logo-banner {
    font-size: 0.65rem;
    padding: 4px 16px;
  }
}

/* Parent tab inline grid — keep simple catalog style */
#screen-parent .library-grid.inline {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 16px;
  padding: 0;
}

#screen-parent .library-grid.inline .book-card-inner {
  padding: 10px;
}
