/* =========================================================
   library.css — Library page, Story detail, Chapter reader
   ========================================================= */

/* --- Library Layout --- */
.library-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: var(--space-xl);
  padding-top: var(--space-xl);
  padding-bottom: var(--space-3xl);
  align-items: start;
}

/* --- Sidebar --- */
.library-sidebar {
  position: sticky;
  top: calc(var(--nav-height) + var(--space-lg));
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  padding: var(--space-lg);
}

.sidebar-heading {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-style: italic;
  font-weight: 400;
  color: var(--text);
  margin-bottom: var(--space-lg);
  padding-bottom: var(--space-md);
  border-bottom: 1px solid var(--border);
}

.sidebar-section {
  margin-bottom: var(--space-lg);
}

.sidebar-section-label {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: var(--space-sm);
  display: block;
}

/* Filter Pills */
.filter-pills {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
}

.filter-pill {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-mid);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: all var(--duration) var(--ease);
  white-space: nowrap;
}

.filter-pill:hover {
  color: var(--text);
  border-color: var(--accent);
}

.filter-pill.active {
  background: var(--accent-glow);
  border-color: var(--accent);
  color: var(--accent-light);
}

/* Sort Select */
.sort-select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-mid);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-family: var(--font-body);
  font-size: 0.82rem;
  padding: 6px 10px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%234a4740' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
  transition: border-color var(--duration) var(--ease), color var(--duration) var(--ease);
}
.sort-select:hover, .sort-select:focus {
  border-color: var(--accent);
  color: var(--text);
  outline: none;
}
.sort-select option { background: var(--bg-card); color: var(--text); }

/* Tag cloud */
.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
}

/* --- Main Grid --- */
.library-main {
  min-height: 60vh;
}

.library-results-info {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  letter-spacing: 0.1em;
  margin-bottom: var(--space-lg);
  text-transform: uppercase;
}

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: var(--space-lg);
}

/* Book card */
.book-card {
  position: relative;
  cursor: pointer;
  transition: transform var(--duration) var(--ease);
}
.book-card:hover { transform: translateY(-4px); }

.book-cover {
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  aspect-ratio: 2/3;
  margin-bottom: var(--space-sm);
}

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

.book-cover .cover-placeholder {
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
  font-size: clamp(0.9rem, 1.5vw, 1.1rem);
}

/* Hover overlay */
.book-cover-overlay {
  position: absolute;
  inset: 0;
  background: rgba(14, 13, 11, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-md);
  opacity: 0;
  transition: opacity var(--duration) var(--ease);
}
.book-card:hover .book-cover-overlay { opacity: 1; }
.book-cover-overlay p {
  font-size: 0.8rem;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.5;
  margin: 0;
}

.book-title {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 2px;
  line-height: 1.3;
}

.book-byline {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: var(--space-xs);
}

.book-meta {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  flex-wrap: wrap;
}

.book-date {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-muted);
}

/* Empty state */
.library-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: var(--space-3xl) var(--space-xl);
  color: var(--text-muted);
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1.2rem;
}

/* --- Story Detail Page --- */
.story-detail {
  padding-top: var(--space-xl);
  padding-bottom: var(--space-3xl);
}

.story-hero {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: var(--space-xl);
  margin-bottom: var(--space-2xl);
  padding-bottom: var(--space-2xl);
  border-bottom: 1px solid var(--border);
}

.story-cover-wrap {
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border);
}

.story-cover-wrap .cover-placeholder {
  aspect-ratio: 2/3;
}

.story-meta-block {}

.story-title {
  font-size: clamp(2.2rem, 5vw, 3.8rem);
  font-style: italic;
  margin-bottom: var(--space-sm);
}

.story-tagline {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1.1rem;
  color: var(--text-dim);
  margin-bottom: var(--space-lg);
  line-height: 1.55;
}

.story-tags {
  display: flex;
  gap: var(--space-xs);
  flex-wrap: wrap;
  margin-bottom: var(--space-md);
}

.story-stats {
  display: flex;
  gap: var(--space-lg);
  margin-bottom: var(--space-lg);
}

.story-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.story-stat-label {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.story-stat-value {
  font-family: var(--font-display);
  font-size: 1.1rem;
  color: var(--text);
}

.story-synopsis {
  font-size: 0.95rem;
  color: var(--text-dim);
  line-height: 1.7;
  max-width: 560px;
  margin-bottom: var(--space-xl);
}

.story-actions {
  display: flex;
  gap: var(--space-md);
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--duration) var(--ease);
}

.btn-primary {
  background: var(--accent);
  color: var(--text);
  border-color: var(--accent);
}
.btn-primary:hover {
  background: var(--accent-light);
  color: var(--text);
  border-color: var(--accent-light);
}

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border-color: var(--border-mid);
}
.btn-ghost:hover {
  color: var(--text);
  border-color: var(--accent);
}

/* Chapter list */
.chapter-list-section {
  margin-bottom: var(--space-2xl);
}

.chapter-list-heading {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 400;
  margin-bottom: var(--space-lg);
  padding-bottom: var(--space-md);
  border-bottom: 1px solid var(--border);
}

.chapter-list {
  list-style: none;
}

.chapter-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md) 0;
  border-bottom: 1px solid var(--border);
  transition: all var(--duration) var(--ease);
  cursor: pointer;
}
.chapter-item:last-child { border-bottom: none; }
.chapter-item:hover .chapter-item-title { color: var(--accent-light); }

.chapter-num {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  width: 32px;
  flex-shrink: 0;
}

.chapter-item-info { flex: 1; }

.chapter-item-title {
  font-family: var(--font-display);
  font-size: 1.05rem;
  color: var(--text);
  transition: color var(--duration) var(--ease);
}

.chapter-item-subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 1px;
}

.chapter-item-meta {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-muted);
  text-align: right;
}

/* Wiki link */
.story-wiki-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  border: 1px solid var(--border-mid);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  color: var(--text-dim);
  font-size: 0.88rem;
  text-decoration: none;
  transition: all var(--duration) var(--ease);
}
.story-wiki-link:hover {
  border-color: var(--accent);
  color: var(--accent-light);
}
.story-wiki-link svg {
  width: 16px; height: 16px;
  stroke: currentColor; fill: none; stroke-width: 1.75;
}

/* --- Chapter Reader --- */
.chapter-reader {
  max-width: 720px;
  margin: 0 auto;
  padding: var(--space-2xl) var(--space-xl) var(--space-3xl);
}

.chapter-back {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: 0.8rem;
  color: var(--text-muted);
  text-decoration: none;
  letter-spacing: 0.06em;
  margin-bottom: var(--space-xl);
  transition: color var(--duration) var(--ease);
}
.chapter-back:hover { color: var(--text); }
.chapter-back svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2; }

.chapter-header {
  margin-bottom: var(--space-2xl);
}

.chapter-story-link {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-muted);
  text-decoration: none;
}
.chapter-story-link:hover { color: var(--accent-light); }

.chapter-number {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-muted);
  letter-spacing: 0.1em;
  margin-top: var(--space-sm);
  margin-bottom: var(--space-xs);
}

.chapter-title {
  font-size: clamp(2rem, 4vw, 3rem);
  font-style: italic;
  margin-bottom: var(--space-md);
}

.chapter-meta {
  display: flex;
  gap: var(--space-lg);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
}

.chapter-body {
  font-family: var(--font-display);
  font-size: 1.15rem;
  line-height: 1.85;
  color: var(--text);
}

.chapter-body p { margin-bottom: 1.5em; }
.chapter-body h2 { font-size: 1.6rem; margin: 2em 0 0.8em; }
.chapter-body h3 { font-size: 1.3rem; margin: 1.6em 0 0.6em; }

.chapter-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: var(--space-3xl);
  padding-top: var(--space-xl);
  border-top: 1px solid var(--border);
}

.chapter-nav-link {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  gap: 2px;
  max-width: 220px;
}
.chapter-nav-link:last-child { text-align: right; }
.chapter-nav-direction {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.chapter-nav-title {
  font-family: var(--font-display);
  font-size: 1rem;
  color: var(--text-dim);
  transition: color var(--duration) var(--ease);
}
.chapter-nav-link:hover .chapter-nav-title { color: var(--accent-light); }

/* --- Responsive --- */
@media (max-width: 1024px) {
  .library-layout { grid-template-columns: 220px 1fr; }
  .story-hero { grid-template-columns: 160px 1fr; }
}

@media (max-width: 768px) {
  .library-layout {
    grid-template-columns: 1fr;
    padding-top: var(--space-lg);
  }

  .library-sidebar {
    position: static;
  }

  .story-hero {
    grid-template-columns: 1fr;
  }

  .story-cover-wrap {
    max-width: 160px;
  }

  .chapter-reader {
    padding: var(--space-xl) var(--space-md) var(--space-2xl);
  }
}
