@font-face {
  font-family: 'Library Display';
  src: url('/fonts/eb-garamond-regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Library Display';
  src: url('/fonts/eb-garamond-bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Library Sans';
  src: url('/fonts/merriweather-sans-regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Library Sans';
  src: url('/fonts/merriweather-sans-bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* === PAGE THEME === */

.library-page {
  --library-paper: oklch(0.94 0.02 85);
  --library-ink: oklch(0.23 0.03 260);
  --library-ink-soft: oklch(0.4 0.03 250);
  --library-shadow: oklch(0.17 0.02 260 / 0.48);
  --library-border: oklch(0.73 0.04 82 / 0.24);
  --library-cta-bg: linear-gradient(135deg, #fae99b 0%, #ecce6d 50%, #bc9300 100%);
  --library-cta-bg-hover: linear-gradient(
    135deg,
    #fff4c8 0%,
    #fae99b 32%,
    #ecce6d 62%,
    #bc9300 100%
  );
  --library-cta-bg-active: linear-gradient(135deg, #fae99b 0%, #ecce6d 42%, #bc9300 100%);
  --library-cta-border: #bc9300;
  --library-cta-text: #0b0b0b;
  --library-cta-shadow: 0 4px 14px rgb(188 147 0 / 0.24);
  --library-cta-shadow-hover:
    0 8px 18px rgb(188 147 0 / 0.35), inset 0 1px 0 rgb(255 255 255 / 0.45);
  background:
    radial-gradient(circle at top left, oklch(0.52 0.08 76 / 0.18), transparent 28rem),
    radial-gradient(circle at 85% 12%, oklch(0.62 0.05 240 / 0.12), transparent 20rem),
    linear-gradient(180deg, oklch(0.12 0.02 255) 0%, oklch(0.09 0.015 250) 100%);
  color: var(--library-paper);
}

.library-author-drawer-open {
  overflow: hidden;
}

.library-page p,
.library-page li,
.library-page a,
.library-page button,
.library-page input,
.library-page select,
.library-page label {
  font-family: 'Library Sans', 'Raleway', sans-serif;
}

.library-page h1,
.library-page h2,
.library-page h3 {
  font-family: 'Library Display', 'Cinzel', serif;
  letter-spacing: 0.01em;
  text-transform: none;
}

.library-page .logo-text {
  font-family: 'Cinzel', 'Library Display', serif;
}

.library-page header {
  background: linear-gradient(
    180deg,
    oklch(0.1 0.02 255 / 0.96) 0%,
    oklch(0.1 0.02 255 / 0.84) 100%
  );
  border-bottom: 1px solid oklch(0.74 0.03 82 / 0.16);
}

.library-page .nav-links a {
  color: oklch(0.9 0.02 82);
}

.library-main {
  position: relative;
}

/* === PAGE HEADER === */

.lib-header {
  padding: clamp(5.5rem, 9vw, 7rem) 1.25rem 1.5rem;
  border-bottom: 1px solid oklch(0.73 0.04 82 / 0.14);
}

.lib-header__inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 1.25rem 2rem;
  justify-content: space-between;
}

.lib-header__copy h1 {
  font-size: clamp(1.9rem, 4vw, 2.8rem);
  line-height: 1;
  margin-bottom: 0.4rem;
  color: var(--library-paper);
}

.lib-header__copy p {
  font-size: 0.9rem;
  color: oklch(0.82 0.03 82 / 0.82);
  margin: 0;
}

.lib-header__controls {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
}

/* === DROPDOWNS === */

.lib-select {
  appearance: none;
  border: 1px solid oklch(0.78 0.05 82 / 0.22);
  border-radius: 999px;
  padding: 0.6rem 2.4rem 0.6rem 1rem;
  background: oklch(0.18 0.03 255 / 0.9)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='7' viewBox='0 0 12 7'%3E%3Cpath fill='%23c8b464' d='M6 7 0 .9 1.1 0 6 4.7 10.9 0 12 .9z'/%3E%3C/svg%3E")
    no-repeat right 0.9rem center / 0.7rem auto;
  color: oklch(0.92 0.04 84);
  font-family: 'Library Sans', sans-serif;
  font-size: 0.88rem;
  cursor: pointer;
  min-width: 9rem;
  transition: border-color 180ms ease;
}

.lib-select:focus-visible {
  outline: 2px solid oklch(0.68 0.09 82);
  outline-offset: 2px;
}

.lib-select:hover {
  border-color: oklch(0.78 0.07 82 / 0.44);
}

/* === SHELF & GRID === */

.lib-shelf {
  padding: 0.3rem 1.25rem 5rem;
}

/* Collapse when empty (status cleared after stories load) */
.library-status:empty {
  display: none;
}

.lib-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
  max-width: 1200px;
  margin: 0 auto;
}

@media (min-width: 560px) {
  .lib-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1024px) {
  .lib-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* === STORY CARD === */

.lib-card {
  display: flex;
  flex-direction: column;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--library-border);
  box-shadow: 0 24px 60px -40px var(--library-shadow);
  background: linear-gradient(
    180deg,
    oklch(0.19 0.03 258 / 0.96) 0%,
    oklch(0.16 0.03 255 / 0.97) 100%
  );
  transition:
    transform 200ms ease,
    box-shadow 200ms ease;
}

.lib-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 32px 72px -36px var(--library-shadow);
}

/* --- Poster (artwork area) --- */

.lib-card__poster {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background:
    radial-gradient(circle at top left, oklch(0.7 0.06 82 / 0.1), transparent 60%),
    linear-gradient(160deg, oklch(0.28 0.04 254) 0%, oklch(0.14 0.03 256) 100%);
  flex-shrink: 0;
}

.lib-card__img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  z-index: 1;
}

.lib-card__poster-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  padding: 0.9rem 1rem;
  pointer-events: none;
  z-index: 0;
}

.lib-card__poster-fallback span {
  font-family: 'Library Display', serif;
  font-size: clamp(1rem, 2.5vw, 1.6rem);
  line-height: 1.1;
  color: oklch(0.92 0.04 84 / 0.6);
  text-wrap: balance;
  max-width: 85%;
}

/* --- Card body --- */

.lib-card__body {
  display: grid;
  gap: 0.3rem;
  padding: 0.85rem 1rem 1rem;
  flex: 1;
}

.lib-card__title {
  font-family: 'Library Display', serif;
  font-size: clamp(1rem, 1.8vw, 1.2rem);
  font-weight: 700;
  line-height: 1.2;
  color: oklch(0.95 0.02 84);
  text-wrap: balance;
  margin: 0;
}

/* Author — plain text fallback */
.lib-card__author-text {
  font-size: 0.82rem;
  color: oklch(0.74 0.07 80);
  margin: 0;
}

/* Author — trigger button (opens drawer) */
.lib-card__author-btn {
  appearance: none;
  border: none;
  padding: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  font-size: 0.82rem;
  color: oklch(0.74 0.07 80);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.15em;
  transition: color 160ms ease;
}

.lib-card__author-btn:hover,
.lib-card__author-btn:focus-visible {
  color: oklch(0.9 0.08 82);
  outline: none;
}

.lib-author-dot {
  display: inline-block;
  width: 0.38em;
  height: 0.38em;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.5;
  vertical-align: middle;
  margin-right: 0.3em;
  margin-bottom: 0.06em;
}

/* --- Play button row --- */

.lib-card__foot {
  display: flex;
  justify-content: stretch;
  padding-top: 0.65rem;
  margin-top: auto;
}

.lib-card__play {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 3rem;
  padding: 0.75rem 1.5rem;
  border: 1px solid var(--library-cta-border);
  border-radius: 8px;
  background: var(--library-cta-bg);
  color: var(--library-cta-text);
  font-family: 'Library Sans', sans-serif;
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.03em;
  line-height: 1.2;
  text-decoration: none;
  box-shadow: var(--library-cta-shadow);
  transition:
    transform 180ms ease,
    box-shadow 180ms ease,
    background 180ms ease;
}

.lib-card__play:hover,
.lib-card__play:focus-visible {
  background: var(--library-cta-bg-hover);
  box-shadow: var(--library-cta-shadow-hover);
  transform: translateY(-2px);
  outline: none;
}

.lib-card__play:active {
  background: var(--library-cta-bg-active);
  box-shadow: 0 6px 16px rgb(188 147 0 / 0.3);
  transform: translateY(0);
}

/* === STATUS PANELS (loading / error / empty) === */

.library-status {
  min-height: 18rem;
  max-width: 1200px;
  margin: 0 auto;
}

.library-status__panel {
  display: grid;
  gap: 1.25rem;
  padding: clamp(1.6rem, 4vw, 2.25rem);
  border-radius: 1.6rem;
  background: linear-gradient(
    180deg,
    oklch(0.18 0.03 257 / 0.94) 0%,
    oklch(0.15 0.03 253 / 0.98) 100%
  );
  border: 1px solid oklch(0.8 0.04 82 / 0.15);
  box-shadow: 0 32px 90px -56px var(--library-shadow);
}

.library-status__title {
  font-size: clamp(2rem, 4vw, 2.9rem);
  color: var(--library-paper);
}

.library-status__body {
  max-width: 38rem;
  font-size: 1.02rem;
  line-height: 1.85;
  color: oklch(0.82 0.02 82 / 0.9);
}

.library-status__button {
  justify-self: start;
}

/* === LOADING SKELETON === */

.library-loading-shelf {
  display: grid;
  gap: 1.25rem;
  max-width: 1200px;
  margin: 0 auto;
}

.library-skeleton,
.library-skeleton-line {
  position: relative;
  overflow: hidden;
  background: linear-gradient(
    90deg,
    oklch(0.24 0.02 255 / 0.84) 0%,
    oklch(0.28 0.03 252 / 0.96) 50%,
    oklch(0.24 0.02 255 / 0.84) 100%
  );
}

.library-skeleton::after,
.library-skeleton-line::after {
  content: '';
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(
    90deg,
    transparent 0%,
    oklch(0.92 0.02 82 / 0.12) 50%,
    transparent 100%
  );
  animation: library-shimmer 1.5s ease infinite;
}

.library-skeleton-feature {
  display: grid;
  grid-template-columns: 1fr;
  gap: clamp(1.25rem, 2vw, 1.8rem);
  padding: clamp(1.25rem, 2vw, 1.7rem);
  border-radius: 1.8rem;
  background: linear-gradient(180deg, oklch(0.19 0.03 256 / 0.92), oklch(0.16 0.03 253 / 0.98));
}

.library-skeleton-poster {
  min-height: 18rem;
  border-radius: 1.3rem;
}

.library-skeleton-copy {
  display: grid;
  align-content: center;
  gap: 0.9rem;
}

.library-skeleton-line {
  height: 0.9rem;
  border-radius: 999px;
}

.library-skeleton-line.is-short {
  width: 40%;
}

.library-skeleton-line.is-medium {
  width: 65%;
}

.library-skeleton-line.is-long {
  width: 92%;
}

.library-skeleton-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: clamp(1rem, 2vw, 1.35rem);
}

.library-skeleton-card {
  min-height: 18rem;
  border-radius: 1.4rem;
}

/* === HIDDEN STATES === */

.library-content[hidden] {
  display: none;
}

.library-author-drawer[hidden] {
  display: none;
}

/* === AUTHOR DRAWER === */

.library-author-drawer {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  grid-template-columns: 1fr auto;
}

.library-author-drawer__overlay {
  width: 100%;
  height: 100%;
  border: none;
  padding: 0;
  background: oklch(0.1 0.02 255 / 0.62);
  cursor: pointer;
}

.library-author-drawer__panel {
  width: clamp(300px, 88vw, 420px);
  height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding: 2rem 1.75rem 3rem;
  background:
    linear-gradient(135deg, oklch(0.86 0.05 82 / 0.08), transparent 30%),
    linear-gradient(180deg, oklch(0.18 0.03 257 / 0.98) 0%, oklch(0.14 0.03 253 / 1) 100%);
  border-left: 1px solid oklch(0.78 0.05 82 / 0.18);
  box-shadow: -24px 0 60px -20px oklch(0.08 0.02 255 / 0.7);
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.library-author-drawer:not([hidden]) .library-author-drawer__panel {
  transform: translateX(0);
}

.library-author-drawer__close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 2.2rem;
  height: 2.2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid oklch(0.78 0.05 82 / 0.2);
  border-radius: 999px;
  background: oklch(0.2 0.03 252 / 0.65);
  color: oklch(0.95 0.03 84);
  cursor: pointer;
  font-size: 1.3rem;
  line-height: 1;
}

.library-author-drawer__close:hover,
.library-author-drawer__close:focus-visible {
  background: oklch(0.28 0.04 252 / 0.82);
  outline: none;
}

.library-author-drawer__header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding-right: 2.5rem;
}

.library-author-drawer__avatar {
  flex-shrink: 0;
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: 'Library Display', serif;
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1;
  background: linear-gradient(
    135deg,
    oklch(0.72 0.09 83 / 0.36) 0%,
    oklch(0.32 0.04 254 / 0.64) 100%
  );
  border: 1px solid oklch(0.78 0.06 82 / 0.3);
  color: oklch(0.96 0.03 84);
}

.library-author-drawer__eyebrow {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: oklch(0.86 0.05 83 / 0.8);
}

.library-author-drawer__name {
  margin: 0;
  font-size: clamp(1.5rem, 2.5vw, 2rem);
  line-height: 1.05;
}

.library-author-drawer__bio {
  margin: 0;
  font-size: 1rem;
  line-height: 1.85;
  color: oklch(0.86 0.02 82 / 0.92);
}

.library-author-drawer__support {
  display: grid;
  gap: 0.8rem;
  padding-top: 0.25rem;
  border-top: 1px solid oklch(0.78 0.05 82 / 0.12);
}

.library-author-drawer__support-title {
  margin: 0;
  font-size: 0.9rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: oklch(0.83 0.06 82);
}

.library-author-drawer__links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.library-author-drawer__link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.55rem;
  padding: 0.5rem 1rem;
  border-radius: 999px;
  border: 1px solid oklch(0.82 0.06 82 / 0.32);
  color: oklch(0.92 0.02 82);
  text-decoration: none;
  background: linear-gradient(135deg, oklch(0.72 0.08 82 / 0.2), oklch(0.24 0.03 252 / 0.3));
  transition:
    border-color 180ms ease,
    transform 180ms ease;
}

.library-author-drawer__link:hover,
.library-author-drawer__link:focus-visible {
  border-color: oklch(0.86 0.08 82 / 0.56);
  transform: translateY(-1px);
  outline: none;
}

.library-author-drawer__fallback {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.75;
  color: oklch(0.78 0.02 82 / 0.82);
  font-style: italic;
}

.library-author-drawer__stories {
  display: grid;
  gap: 0.7rem;
  padding-top: 0.25rem;
  border-top: 1px solid oklch(0.78 0.05 82 / 0.12);
}

.library-author-drawer__stories-title {
  margin: 0;
  font-size: 0.9rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: oklch(0.83 0.06 82);
}

.library-author-drawer__stories-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.5rem;
}

.library-author-drawer__story-item {
  font-size: 0.95rem;
}

.library-author-drawer__story-link {
  color: oklch(0.88 0.04 82);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.14em;
}

.library-author-drawer__story-link:hover,
.library-author-drawer__story-link:focus-visible {
  color: oklch(0.96 0.06 82);
  outline: none;
}

/* === ANIMATIONS === */

@keyframes library-shimmer {
  to {
    transform: translateX(100%);
  }
}

/* === RESPONSIVE === */

@media (min-width: 640px) {
  .library-skeleton-feature {
    grid-template-columns: minmax(14rem, 18rem) minmax(0, 1fr);
  }

  .library-skeleton-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 639px) {
  .library-author-drawer {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
    align-items: end;
  }

  .library-author-drawer__overlay {
    grid-row: 1;
  }

  .library-author-drawer__panel {
    grid-row: 2;
    width: 100%;
    height: auto;
    max-height: 82vh;
    border-left: none;
    border-top: 1px solid oklch(0.78 0.05 82 / 0.18);
    border-radius: 1.25rem 1.25rem 0 0;
    box-shadow: 0 -16px 48px -12px oklch(0.08 0.02 255 / 0.6);
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
  }

  .library-author-drawer:not([hidden]) .library-author-drawer__panel {
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .lib-card,
  .lib-card__play,
  .lib-select,
  .library-author-drawer__link,
  .library-author-drawer__panel,
  .library-skeleton::after,
  .library-skeleton-line::after {
    animation: none;
    transition: none;
    transform: none;
  }

  .library-author-drawer:not([hidden]) .library-author-drawer__panel {
    transform: none;
  }
}
