/* ============================================================
   CSS Custom Properties
   ============================================================ */
:root {
  --page-bg: #f4f0e8;
  --desk-bg: #2c2016;
  --text: #3c2415;
  --text-muted: #6b5344;
  --accent: #8b1a1a;
  --gold: #8b7635;
  --border: #c4b5a0;
  --font-heading: 'Playfair Display', Georgia, 'Times New Roman', serif;
  --font-heading-sc: 'Playfair Display SC', Georgia, 'Times New Roman', serif;
  --font-body: 'Libre Baskerville', Georgia, 'Times New Roman', serif;
}

/* ============================================================
   Reset & Base
   ============================================================ */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  background: var(--desk-bg);
  color: var(--text);
  line-height: 1.75;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.2s;
}

a:hover {
  color: var(--text);
}

img {
  max-width: 100%;
  display: block;
}

/* ============================================================
   Book Desk & Page
   ============================================================ */
.book-desk {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 2rem 1rem;
}

.book-page {
  position: relative;
  width: 100%;
  max-width: 780px;
  background: var(--page-bg);
  background-image:
    repeating-linear-gradient(0deg,
      transparent,
      transparent 50px,
      rgba(139, 118, 53, 0.03) 50px,
      rgba(139, 118, 53, 0.03) 51px);
  box-shadow:
    0 0 15px rgba(0, 0, 0, 0.3),
    0 0 60px rgba(0, 0, 0, 0.15),
    inset 0 0 80px rgba(139, 118, 53, 0.04);
  padding: 4rem 5rem;
}

/* ============================================================
   Bookmark Ribbons
   ============================================================ */
.bookmarks {
  position: absolute;
  top: 0;
  right: -42px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 10;
}

.bookmark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 90px;
  background: var(--ribbon-color, #8b1a1a);
  color: #f4f0e8;
  text-decoration: none;
  font-family: var(--font-heading-sc);
  font-size: 0.65rem;
  letter-spacing: 0.05em;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  clip-path: polygon(0 0, 100% 0, 100% 85%, 50% 100%, 0 85%);
  transition: width 0.2s, height 0.2s, opacity 0.2s;
  opacity: 0.8;
  overflow: hidden;
}

.bookmark span {
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

.bookmark:hover {
  width: 42px;
  height: 100px;
  opacity: 1;
  color: #f4f0e8;
}

.bookmark:hover span {
  opacity: 1;
}

.bookmark.active {
  width: 42px;
  height: 105px;
  opacity: 1;
}

.bookmark.active span {
  opacity: 1;
}

/* ============================================================
   Mobile Navigation
   ============================================================ */
.mobile-nav-toggle {
  display: none;
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 200;
  background: var(--accent);
  color: var(--page-bg);
  border: none;
  font-size: 1.4rem;
  width: 44px;
  height: 44px;
  border-radius: 4px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.mobile-nav {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 150;
  background: var(--page-bg);
  border-bottom: 2px solid var(--border);
  padding: 1rem;
  padding-top: 4rem;
  flex-direction: column;
  gap: 0.25rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.mobile-nav.open {
  display: flex;
}

.mobile-nav-link {
  display: block;
  padding: 0.6rem 1rem;
  font-family: var(--font-heading);
  font-size: 1rem;
  color: var(--text);
  border-radius: 4px;
  transition: background 0.15s;
}

.mobile-nav-link:hover {
  background: rgba(139, 118, 53, 0.1);
  color: var(--text);
}

.mobile-nav-link.active {
  color: var(--accent);
  font-weight: 700;
}

/* ============================================================
   Sections
   ============================================================ */
.book-section {
  display: none;
}

.book-section.active {
  display: block;
}

/* ============================================================
   Cover Page
   ============================================================ */
.cover-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 70vh;
  text-align: center;
}

.cover-ornament {
  font-size: 2.5rem;
  color: var(--gold);
  line-height: 1;
  margin: 1.5rem 0;
}

.cover-frame {
  border: 3px double var(--gold);
  padding: 3rem 2.5rem;
  max-width: 100%;
}

.cover-subtitle {
  font-family: var(--font-heading);
  font-size: 1rem;
  font-style: italic;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  letter-spacing: 0.05em;
}

.cover-title {
  font-family: var(--font-heading);
  font-size: clamp(2rem, 5vw, 3.2rem);
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
  margin-bottom: 1.25rem;
}

.cover-role {
  font-family: var(--font-body);
  font-size: 1.1rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.cover-tagline {
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: var(--text-muted);
  line-height: 1.7;
  max-width: 400px;
  margin: 0 auto;
}

/* Cover CTAs */
.cover-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 1.5rem;
}

.cover-btn {
  display: inline-block;
  font-family: var(--font-heading-sc);
  font-size: 0.9rem;
  letter-spacing: 0.08em;
  padding: 0.75rem 2rem;
  border: 2px solid var(--gold);
  color: var(--page-bg);
  background: var(--accent);
  cursor: pointer;
  transition: background 0.25s, color 0.25s, border-color 0.25s, transform 0.15s;
  text-decoration: none;
}

.cover-btn:hover {
  background: var(--text);
  border-color: var(--text);
  color: var(--page-bg);
  transform: translateY(-1px);
}

.cover-btn-secondary {
  background: transparent;
  color: var(--text);
}

.cover-btn-secondary:hover {
  background: var(--gold);
  border-color: var(--gold);
  color: var(--page-bg);
}

.cover-imprint {
  font-family: var(--font-heading-sc);
  font-size: 0.85rem;
  color: var(--gold);
  letter-spacing: 0.1em;
  margin-top: 2rem;
}

/* ============================================================
   Ornamental Rules
   ============================================================ */
.ornamental-rule {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 2rem 0;
  color: var(--gold);
}

.ornamental-rule::before,
.ornamental-rule::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--gold);
  opacity: 0.5;
}

.ornamental-rule::before {
  background: linear-gradient(to right, transparent, var(--gold));
}

.ornamental-rule::after {
  background: linear-gradient(to left, transparent, var(--gold));
}

.entry-rule {
  border: none;
  border-bottom: 1px dotted var(--border);
  margin: 1.5rem 0;
}

/* ============================================================
   Section Headings
   ============================================================ */
.section-heading-sc {
  font-family: var(--font-heading-sc);
  font-size: 1.6rem;
  font-weight: 400;
  color: var(--text);
  text-align: center;
  margin-bottom: 2rem;
  letter-spacing: 0.08em;
}

.section-heading-italic {
  font-family: var(--font-heading);
  font-size: 1.4rem;
  font-weight: 400;
  font-style: italic;
  color: var(--text);
  margin-bottom: 1.5rem;
}

/* Chapter Headers */
.chapter-header {
  text-align: center;
  margin-bottom: 0.5rem;
}

.chapter-number {
  font-family: var(--font-heading-sc);
  font-size: 1rem;
  color: var(--text-muted);
  letter-spacing: 0.12em;
  margin-bottom: 0.25rem;
}

.chapter-title {
  font-family: var(--font-heading);
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
}

.subsection-heading {
  font-family: var(--font-heading-sc);
  font-size: 1.15rem;
  font-weight: 400;
  color: var(--text);
  letter-spacing: 0.08em;
  margin-top: 2.5rem;
  margin-bottom: 1.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

/* ============================================================
   Typography
   ============================================================ */
.book-paragraph {
  font-family: var(--font-body);
  font-size: 0.95rem;
  line-height: 1.8;
  color: var(--text);
  text-align: justify;
  text-indent: 1.5em;
  margin-bottom: 0.75rem;
}

.book-paragraph:first-child {
  text-indent: 0;
}

/* Drop Caps */
.drop-cap-block>p:first-child::first-letter {
  float: left;
  font-family: var(--font-heading);
  font-size: 3.8em;
  line-height: 0.8;
  padding-right: 0.08em;
  padding-top: 0.05em;
  color: var(--accent);
  font-weight: 700;
}

/* ============================================================
   Profile / Flyleaf
   ============================================================ */
.author-block {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
  margin-bottom: 1.5rem;
}

.author-avatar-wrap {
  flex-shrink: 0;
}

.author-avatar {
  width: 130px;
  height: 130px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--border);
  filter: sepia(20%);
}

.author-avatar-placeholder {
  width: 130px;
  height: 130px;
  border-radius: 50%;
  background: rgba(139, 118, 53, 0.1);
  border: 3px solid var(--border);
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-family: var(--font-heading);
  color: var(--text-muted);
}

.bio-paragraph {
  font-family: var(--font-body);
  font-size: 0.95rem;
  line-height: 1.8;
  color: var(--text);
  text-align: justify;
  text-indent: 1.5em;
  margin-bottom: 0.75rem;
}

.social-links {
  text-align: center;
  margin: 1.5rem 0;
  font-family: var(--font-body);
  font-size: 0.9rem;
}

.social-link {
  color: var(--accent);
}

.social-link:hover {
  color: var(--text);
}

.middot {
  color: var(--text-muted);
  margin: 0 0.4rem;
}

/* ============================================================
   Table of Contents
   ============================================================ */
.toc {
  max-width: 500px;
  margin: 0 auto;
}

.toc-entry {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.6rem 0;
  color: var(--text);
  text-decoration: none;
  transition: color 0.2s;
}

.toc-entry:hover {
  color: var(--accent);
}

.toc-chapter {
  font-family: var(--font-heading-sc);
  font-size: 0.85rem;
  letter-spacing: 0.05em;
  white-space: nowrap;
  color: var(--text-muted);
}

.toc-title {
  font-family: var(--font-heading);
  font-size: 1.05rem;
  white-space: nowrap;
}

.toc-leader {
  flex: 1;
  border-bottom: 2px dotted var(--border);
  min-width: 2rem;
  margin-bottom: 0.25em;
}

.toc-page {
  font-family: var(--font-body);
  font-style: italic;
  font-size: 0.9rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ============================================================
   History Entries
   ============================================================ */
.history-entry {
  padding-bottom: 1.5rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px dotted var(--border);
}

.history-entry:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.history-period {
  font-family: var(--font-body);
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.history-role {
  font-family: var(--font-heading);
  font-size: 1.05rem;
  margin-bottom: 0.5rem;
}

/* ============================================================
   Blog Entries
   ============================================================ */
.blog-entry {
  margin-bottom: 0.5rem;
}

.blog-title {
  font-family: var(--font-heading);
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.blog-title a {
  color: var(--accent);
}

.blog-title a:hover {
  color: var(--text);
}

.blog-date {
  font-family: var(--font-body);
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

/* ============================================================
   Project Entries
   ============================================================ */
.project-entry {
  margin-bottom: 0.5rem;
}

.project-title {
  font-family: var(--font-heading);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.25rem;
}

.project-tech {
  font-family: var(--font-body);
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.project-links {
  font-family: var(--font-body);
  font-size: 0.9rem;
  margin-top: 0.5rem;
}

.project-links a {
  color: var(--accent);
}

.project-links a:hover {
  color: var(--text);
}

/* ============================================================
   Page Turner Navigation
   ============================================================ */
.page-turner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.page-turner-btn {
  font-family: var(--font-heading-sc);
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 0.5rem 1.25rem;
  border: 1px solid var(--border);
  transition: color 0.2s, border-color 0.2s;
  text-decoration: none;
}

.page-turner-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.page-turner-spacer {
  flex: 1;
}

/* ============================================================
   Collapsed Timeline
   ============================================================ */
.timeline-details summary {
  font-family: var(--font-heading-sc);
  font-size: 0.9rem;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.75rem 0;
  border-bottom: 1px dotted var(--border);
  margin-bottom: 1.5rem;
  list-style: none;
}

.timeline-details summary::-webkit-details-marker {
  display: none;
}

.timeline-details summary::after {
  content: ' ↓';
}

.timeline-details[open] summary::after {
  content: ' ↑';
}

.timeline-details[open] summary {
  color: var(--accent);
}

/* ============================================================
   History Epigraph
   ============================================================ */
.epigraph {
  margin: 2rem auto;
  max-width: 420px;
  text-align: center;
  padding: 1rem 0;
}

.epigraph p {
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-style: italic;
  color: var(--text-muted);
  line-height: 1.7;
}

.epigraph cite {
  display: block;
  margin-top: 0.5rem;
  font-family: var(--font-heading-sc);
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  font-style: normal;
  color: var(--text-muted);
}

/* ============================================================
   Colophon (Footer)
   ============================================================ */
.colophon {
  text-align: center;
  padding-top: 1rem;
}

.colophon p {
  font-family: var(--font-body);
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
}

/* ============================================================
   Responsive — Tablet (601–900px)
   ============================================================ */
@media (max-width: 900px) {
  .bookmarks {
    display: none;
  }

  .mobile-nav-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .book-page {
    max-width: 100%;
    padding: 3rem 3rem;
  }

  .book-desk {
    padding: 0;
  }

  .toc-entry {
    flex-wrap: wrap;
  }

  .toc-title {
    white-space: normal;
  }
}

/* ============================================================
   Responsive — Mobile (≤600px)
   ============================================================ */
@media (max-width: 600px) {
  .book-page {
    padding: 2rem 1.5rem;
    box-shadow: none;
  }

  .cover-frame {
    padding: 2rem 1.5rem;
  }

  .cover-title {
    font-size: 1.8rem;
  }

  .chapter-title {
    font-size: 1.6rem;
  }

  .drop-cap-block>p:first-child::first-letter {
    font-size: 2.8em;
  }

  .author-block {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }

  .author-avatar,
  .author-avatar-placeholder {
    width: 100px;
    height: 100px;
  }

  .bio-paragraph,
  .book-paragraph {
    text-align: left;
    text-indent: 0;
  }

  .section-heading-sc {
    font-size: 1.3rem;
  }

  .toc {
    max-width: 100%;
  }

  .toc-leader {
    display: none;
  }

  .toc-entry {
    gap: 0.25rem;
  }
}
/* ============================================================
   Library Entries (Simplified)
   ============================================================ */
.library-controls {
  margin: 1.5rem 0;
  display: flex;
  justify-content: flex-end;
}

.sort-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.styled-select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.25rem 0.5rem;
  font-family: inherit;
  font-size: inherit;
  border-radius: 4px;
  cursor: pointer;
}

.library-list-container {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  margin-top: 1rem;
}

.simple-book-entry {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
  transition: background 0.2s;
}

.book-main-info {
  flex: 1;
}

.book-title-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.book-name {
  font-family: 'Playfair Display', serif;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  margin: 0;
}

.book-author-name {
  font-style: italic;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.book-metadata-tags {
  display: none; /* Hidden metadata */
}

.book-side-info {
  text-align: right;
  min-width: 120px;
}

.book-date-label {
  font-family: 'Inter', sans-serif;
  font-size: 0.8rem;
  color: var(--text-muted);
  display: block;
}

.book-rating-stars {
  color: var(--accent);
  font-size: 0.85rem;
  letter-spacing: 1px;
}

.loading-text {
  text-align: center;
  color: var(--text-muted);
  font-style: italic;
}

/* ============================================================
   End Cover
   ============================================================ */
.endcover-page {
  text-align: center;
}

.endcover-title {
  font-family: 'Playfair Display', serif;
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
  margin: 0.5rem 0;
  letter-spacing: 0.05em;
}

.endcover-links {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

.endcover-actions {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-top: 2rem;
  flex-wrap: wrap;
}
