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

:root {
  --bg: #0C0A09;
  --bg-elevated: #1A1816;
  --surface: #231F1D;
  --text-primary: #E7E5E4;
  --text-secondary: #A8A29E;
  --text-tertiary: #78716C;
  --accent: #D4A574;
  --accent-hover: #E8C49A;
  --accent-light: rgba(212, 165, 116, 0.1);
  --border: rgba(255, 255, 255, 0.08);
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  --font-display: 'DM Serif Display', Georgia, serif;
  --font-body: 'DM Sans', system-ui, sans-serif;

  --reader-font: Charter, 'Iowan Old Style', Georgia, serif;
  --reader-size: 18px;
  --reader-line-height: 1.8;
  --reader-paragraph-spacing: 24px;
  --reader-max-width: 680px;
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  opacity: 0.028;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 256px 256px;
}

/* ── Focus styles ── */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button:focus-visible, .size-btn:focus-visible, .font-option:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── Browse Header ── */
.browse-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(12, 10, 9, 0.8);
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text-primary);
}

.logo-icon {
  width: 30px;
  height: 30px;
  background: #D4A574;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo-icon svg { width: 16px; height: 16px; }
.logo-icon--sm { width: 28px; height: 28px; border-radius: 6px; }
.logo-icon--sm svg { width: 15px; height: 15px; }

.logo-text {
  font-family: var(--font-display);
  font-size: 20px;
  letter-spacing: -0.01em;
}

.logo-text--sm { font-size: 16px; }

.header-nav {
  display: flex;
  align-items: center;
  gap: 24px;
}

.header-nav a {
  font-size: 14px;
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.15s;
}

.header-nav a:hover { color: var(--text-primary); }
.header-nav a.active { color: var(--accent); }

.app-badges { display: flex; gap: 8px; }

.app-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: var(--accent);
  color: var(--bg);
  border-radius: 100px;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  transition: opacity 0.15s;
}

.app-badge:hover { opacity: 0.85; }
.app-badge svg { width: 14px; height: 14px; }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--accent);
  text-decoration: none;
  transition: opacity 0.15s;
}

.back-link:hover { opacity: 0.7; }
.back-link svg { width: 16px; height: 16px; }

/* ── Footer ── */
footer {
  border-top: 1px solid var(--border);
  padding: 32px 24px;
}

.footer-inner {
  max-width: 1080px;
  margin: 0 auto;
  font-size: 13px;
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.footer-inner a {
  color: var(--text-secondary);
  text-decoration: none;
}

.footer-inner a:hover { color: var(--text-primary); }

.footer-links {
  display: flex;
  align-items: center;
  gap: 16px;
}

.footer-sep { color: var(--text-tertiary); }

/* ── Main container ── */
.main-browse {
  max-width: 1080px;
  margin: 0 auto;
  padding: 48px 24px 96px;
}

.main-detail {
  max-width: 760px;
  margin: 0 auto;
  padding: 48px 24px 96px;
}

/* ── Catalog hero ── */
.catalog-hero {
  text-align: center;
  margin-bottom: 48px;
}

.catalog-hero h1 {
  font-family: var(--font-display);
  font-size: 36px;
  font-weight: 400;
  letter-spacing: -0.01em;
  margin-bottom: 12px;
}

.catalog-hero p {
  font-size: 16px;
  color: var(--text-secondary);
  max-width: 480px;
  margin: 0 auto;
  line-height: 1.6;
}

/* ── Genre chips ── */
.genre-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-bottom: 40px;
}

.genre-chip {
  padding: 7px 16px;
  border-radius: 100px;
  font-size: 13px;
  font-weight: 500;
  background: var(--surface);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
}

.genre-chip:hover {
  border-color: var(--text-tertiary);
  color: var(--text-primary);
}

.genre-chip.active {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
  font-weight: 600;
}

/* ── Section label ── */
.section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  margin-bottom: 16px;
}

.section-label .book-count {
  font-weight: 500;
  color: var(--text-tertiary);
}

/* ── Load more ── */
.load-more-btn {
  grid-column: 1 / -1;
  padding: 14px 32px;
  background: var(--surface);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.load-more-btn:hover {
  border-color: var(--text-tertiary);
  color: var(--text-primary);
}

.load-more-btn.htmx-request {
  opacity: 0.6;
  pointer-events: none;
}

/* ── Book grid ── */
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 32px 24px;
}

.book-card {
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
}

.book-cover {
  aspect-ratio: 2 / 3;
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: relative;
  margin-bottom: 12px;
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.3),
    0 8px 24px rgba(0, 0, 0, 0.2);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1),
              box-shadow 0.3s ease;
}

.book-card:hover .book-cover {
  transform: translateY(-6px) scale(1.02);
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.3),
    0 16px 48px rgba(0, 0, 0, 0.25),
    0 0 40px rgba(212, 165, 116, 0.08);
}

.cover-gradient {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.cover-initial {
  font-family: var(--font-display);
  font-size: 48px;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.9);
  position: relative;
  z-index: 1;
}

.cover-spine {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: rgba(0, 0, 0, 0.12);
}

.book-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
  margin-bottom: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.book-author { font-size: 13px; color: var(--text-secondary); }

.book-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-tertiary);
}

.book-meta .dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--text-tertiary);
}

/* ── Continue reading ── */
.continue-section { margin-bottom: 48px; }

.continue-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.continue-card {
  display: flex;
  gap: 16px;
  padding: 16px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.continue-card:hover {
  border-color: var(--text-tertiary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.continue-cover {
  width: 48px;
  height: 72px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.continue-cover .cover-initial { font-size: 20px; }

.continue-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.continue-title {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.continue-chapter {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.progress-bar-sm {
  margin-top: 8px;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.progress-bar-sm .fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
}

/* ── Book detail ── */
.book-header {
  display: flex;
  gap: 32px;
  margin-bottom: 40px;
}

.book-cover-large {
  width: 160px;
  flex-shrink: 0;
  aspect-ratio: 2 / 3;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow:
    0 4px 16px rgba(0, 0, 0, 0.4),
    0 16px 48px rgba(0, 0, 0, 0.3);
}

.book-cover-large .cover-initial { font-size: 56px; }

.book-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.book-info h1 {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 400;
  line-height: 1.25;
  margin-bottom: 8px;
}

.book-info .book-author {
  font-size: 16px;
  margin-bottom: 16px;
}

.book-meta-row {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--text-tertiary);
}

.meta-item {
  display: flex;
  align-items: center;
  gap: 5px;
}

.meta-item svg { width: 14px; height: 14px; }

.genre-tag {
  padding: 4px 12px;
  border-radius: 100px;
  font-size: 12px;
  font-weight: 500;
  background: var(--accent-light);
  color: var(--accent);
}

.book-genres {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 20px;
}

.read-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 28px;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s, box-shadow 0.2s;
  text-decoration: none;
  align-self: flex-start;
}

.read-btn:hover {
  background: var(--accent-hover);
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(212, 165, 116, 0.25);
}
.read-btn svg { width: 16px; height: 16px; }

.book-description {
  padding: 24px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin-bottom: 32px;
}

.book-description p {
  font-size: 15px;
  line-height: 1.7;
  color: var(--text-secondary);
}

/* ── Progress section ── */
.progress-section {
  margin-bottom: 32px;
  padding: 20px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.progress-bar .fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
}

/* ── Chapters ── */
.chapters-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.chapters-header h2 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
}

.chapters-header span {
  font-size: 13px;
  color: var(--text-tertiary);
}

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

.chapter-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px;
  margin: 0 -12px;
  border-radius: var(--radius-md);
  text-decoration: none;
  color: inherit;
  transition: background 0.15s;
}

.chapter-row + .chapter-row,
li + li .chapter-row {
  border-top: 1px solid var(--border);
}

.chapter-row:hover {
  background: var(--surface);
}

.chapter-number {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}

.chapter-number--completed { background: var(--accent); color: var(--bg); }
.chapter-number--current { background: var(--accent-light); color: var(--accent); border: 2px solid var(--accent); }
.chapter-number--upcoming { background: var(--border); color: var(--text-tertiary); }

.chapter-info { flex: 1; min-width: 0; }

.chapter-title { font-size: 15px; font-weight: 500; }
.chapter-row--current .chapter-title { color: var(--accent); }

.chapter-time { font-size: 12px; color: var(--text-tertiary); margin-top: 2px; }

.chapter-status { font-size: 12px; font-weight: 500; flex-shrink: 0; }
.chapter-status--completed { color: var(--accent); }
.chapter-status--current { color: var(--accent); }

.chapter-arrow { color: var(--text-tertiary); flex-shrink: 0; }
.chapter-arrow svg { width: 16px; height: 16px; }

/* ── Reader chrome ── */
.reader-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(12, 10, 9, 0.9);
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  border-bottom: 1px solid var(--border);
}

.reader-header-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.reader-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.close-btn, .icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  text-decoration: none;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.close-btn:hover, .icon-btn:hover {
  border-color: var(--text-tertiary);
  color: var(--text-primary);
}

.close-btn svg, .icon-btn svg { width: 16px; height: 16px; }

.reader-book-title { font-size: 13px; color: var(--text-tertiary); }
.reader-chapter-title { font-size: 14px; font-weight: 600; color: var(--text-primary); }

.reader-header-right { display: flex; align-items: center; gap: 8px; position: relative; }

.reader-progress {
  position: sticky;
  top: 61px;
  z-index: 49;
  height: 3px;
  background: var(--border);
}

.reader-progress .fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.3s ease;
}

/* ── Reader content ── */
.reader-content {
  max-width: var(--reader-max-width);
  margin: 0 auto;
  padding: 64px 24px 120px;
}

.chapter-heading {
  font-family: var(--reader-font);
  font-size: calc(var(--reader-size) + 10px);
  font-weight: 400;
  line-height: 1.3;
  margin-bottom: 48px;
  text-align: center;
  color: var(--text-primary);
}

.chapter-heading::after {
  content: '';
  display: block;
  width: 40px;
  height: 2px;
  background: var(--border);
  margin: 24px auto 0;
}

.reader-text p {
  font-family: var(--reader-font);
  font-size: var(--reader-size);
  line-height: var(--reader-line-height);
  color: #D6D3D1;
  margin-bottom: var(--reader-paragraph-spacing);
}

.reader-text hr {
  border: none;
  text-align: center;
  margin: 40px 0;
}

.reader-text hr::before {
  content: '* * *';
  font-family: var(--reader-font);
  font-size: 14px;
  letter-spacing: 0.3em;
  color: var(--text-tertiary);
}

.reader-text em { font-style: italic; }
.reader-text strong { font-weight: 600; }

/* ── Chapter end card ── */
.chapter-end {
  margin-top: 48px;
  padding: 24px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  text-align: center;
}

.chapter-end-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  margin-bottom: 8px;
}

.chapter-end-title {
  font-family: var(--reader-font);
  font-size: 20px;
  font-weight: 400;
  margin-bottom: 24px;
}

.chapter-end-nav {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  transition: all 0.15s;
}

.nav-btn svg { width: 16px; height: 16px; }

.nav-btn--primary { background: var(--accent); color: var(--bg); font-weight: 700; }
.nav-btn--primary:hover { background: var(--accent-hover); }

.nav-btn--secondary {
  background: var(--surface);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.nav-btn--secondary:hover {
  border-color: var(--text-tertiary);
  color: var(--text-primary);
}

/* ── Reader footer ── */
.reader-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(12, 10, 9, 0.9);
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  border-top: 1px solid var(--border);
  z-index: 50;
}

.reader-footer-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.footer-chapter-nav {
  display: flex;
  align-items: center;
  gap: 12px;
}

.footer-nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  text-decoration: none;
  transition: border-color 0.15s, color 0.15s;
}

.footer-nav-btn:hover {
  border-color: var(--text-tertiary);
  color: var(--text-primary);
}

.footer-nav-btn.disabled { opacity: 0.3; pointer-events: none; }
.footer-nav-btn svg { width: 14px; height: 14px; }

.footer-chapter-label { font-size: 13px; color: var(--text-secondary); }
.footer-chapter-label strong { color: var(--text-primary); font-weight: 600; }

.footer-position { font-size: 13px; color: var(--text-tertiary); }

/* ── Settings panel ── */
.settings-panel {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 260px;
  padding: 20px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  z-index: 60;
}

.settings-panel.show { display: block; }

.setting-row { margin-bottom: 20px; }
.setting-row:last-child { margin-bottom: 0; }

.setting-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-tertiary);
  margin-bottom: 8px;
}

.setting-control { display: flex; align-items: center; gap: 8px; }

.size-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}

.size-btn:hover { border-color: var(--text-tertiary); }

.size-value { flex: 1; text-align: center; font-size: 14px; font-weight: 500; }

.font-options { display: flex; gap: 6px; }

.font-option {
  flex: 1;
  padding: 8px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  text-align: center;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}

.font-option:hover { border-color: var(--text-tertiary); }

.font-option.active {
  border-color: var(--accent);
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 600;
}

.font-option--charter { font-family: Charter, Georgia, serif; }
.font-option--system { font-family: -apple-system, sans-serif; }
.font-option--mono { font-family: 'SF Mono', Menlo, monospace; font-size: 12px; }

/* ── Responsive ── */
@media (max-width: 640px) {
  .catalog-hero h1 { font-size: 28px; }
  .header-nav { gap: 16px; }
  .app-badge span { display: none; }
  .footer-inner { flex-direction: column; gap: 8px; text-align: center; }
  .footer-links { flex-wrap: wrap; justify-content: center; }
  .book-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 24px 16px;
  }
  .main-browse { padding: 32px 16px 64px; }
  .main-detail { padding: 32px 16px 64px; }
  .book-header {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 24px;
  }
  .book-cover-large { width: 140px; }
  .book-info { align-items: center; }
  .book-info h1 { font-size: 24px; }
  .book-genres { justify-content: center; }
  .reader-content { padding: 40px 20px 100px; }
  .chapter-heading { font-size: calc(var(--reader-size) + 6px); }
  .reader-book-title { display: none; }
  .settings-panel { right: 12px; left: 12px; width: auto; }
}
