:root {
  --bg: #111815;
  --surface: #18221d;
  --surface-hover: #212e27;
  --text: #e2ece6;
  --muted: #93a89b;
  --accent: #52b788;
  --border: #28372f;
}

[data-theme="light"] {
  --bg: #f8f6f2;
  --surface: #ffffff;
  --surface-hover: #f0ede6;
  --text: #1c211e;
  --muted: #5f6b64;
  --accent: #2d6a4f;
  --border: #ded9ce;
}

[data-theme="forest"] {
  --bg: #111815;
  --surface: #18221d;
  --surface-hover: #212e27;
  --text: #e2ece6;
  --muted: #93a89b;
  --accent: #52b788;
  --border: #28372f;
}

[data-theme="dark"] {
  --bg: #0f0f10;
  --surface: #18181b;
  --surface-hover: #242429;
  --text: #e4e4e7;
  --muted: #a1a1aa;
  --accent: #60a5fa;
  --border: #27272a;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.6;
  transition: background-color 0.25s, color 0.25s;
}

.hidden {
  display: none !important;
}

/* Top Navigation Bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.7rem 1.25rem;
  background-color: var(--surface);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.book-meta h1 {
  font-size: 0.98rem;
  font-weight: 600;
}

.subtitle {
  font-size: 0.78rem;
  color: var(--muted);
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.4rem 0.7rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.88rem;
  transition: all 0.2s;
  white-space: nowrap;
}

.icon-btn:hover, .icon-btn.active-state {
  border-color: var(--accent);
  color: var(--accent);
}

.icon-btn.accent-outline {
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.icon-btn.accent-outline:hover {
  background-color: var(--accent);
  color: #111;
}

/* Settings Dropdown */
.settings-panel {
  position: fixed;
  top: 58px;
  right: 1.25rem;
  z-index: 40;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  width: 260px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.setting-group label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.4rem;
}

.theme-options, .font-size-controls {
  display: flex;
  gap: 0.5rem;
}

.theme-btn, .small-btn {
  flex: 1;
  padding: 0.4rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
}

.theme-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

select {
  width: 100%;
  padding: 0.45rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
}

/* Sidebar Drawer */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 310px;
  z-index: 50;
  background-color: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}

.reading-stats {
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
  color: var(--accent);
  background-color: var(--bg);
  border-bottom: 1px solid var(--border);
}

.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  flex: 1;
  padding: 0.6rem;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
}

.tab-btn.active {
  color: var(--accent);
  border-bottom: 2px solid var(--accent);
  font-weight: 600;
}

.chapter-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
}

.chapter-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 0.9rem;
}

.chapter-list li:hover, .chapter-list li.active {
  background-color: var(--bg);
  color: var(--accent);
}

.chapter-list li.is-read .chap-item-title {
  opacity: 0.65;
}

.chap-status-icon {
  font-size: 0.85rem;
  color: var(--accent);
  flex-shrink: 0;
}

/* Hero Landing Section (twatf.pages.dev inspired) */
.hero-section {
  position: relative;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
  padding: 3rem 1.5rem;
}

.hero-bg {
  position: absolute;
  inset: -20px;
  background-image: url('cover.jpg');
  background-size: cover;
  background-position: center 20%;
  filter: blur(18px) brightness(0.35);
  transform: scale(1.06);
  z-index: 0;
}

[data-theme="light"] .hero-bg {
  filter: blur(18px) opacity(0.18);
}

.hero-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(17, 24, 21, 0.55), var(--bg));
  z-index: 1;
}

[data-theme="light"] .hero-overlay {
  background: linear-gradient(to bottom, rgba(248, 246, 242, 0.65), var(--bg));
}

.hero-content {
  position: relative;
  z-index: 2;
  max-width: 1020px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 230px 1fr;
  gap: 2.25rem;
  align-items: start;
}

.cover-card {
  width: 230px;
  aspect-ratio: 2 / 3;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.5);
  background-color: var(--surface);
}

.cover-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.cover-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 1rem;
  font-weight: 700;
  color: var(--accent);
  background: radial-gradient(circle at top, var(--surface-hover), var(--surface));
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.meta-badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  background-color: var(--surface);
  border: 1px solid var(--border);
  color: var(--accent);
}

.hero-info h2 {
  font-size: 2.1rem;
  line-height: 1.2;
  margin-bottom: 0.25rem;
}

.alt-title {
  font-size: 1rem;
  color: var(--muted);
  margin-bottom: 1rem;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.4rem 1.25rem;
  font-size: 0.88rem;
  color: var(--muted);
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.meta-grid strong {
  color: var(--text);
}

.synopsis-box {
  font-size: 0.95rem;
  color: var(--text);
  margin-bottom: 1.5rem;
}

.synopsis-box p {
  margin-bottom: 0.9rem;
}

.story-quote {
  border-left: 3px solid var(--accent);
  padding: 0.65rem 1rem;
  background-color: rgba(0, 0, 0, 0.2);
  border-radius: 0 6px 6px 0;
  font-style: italic;
  color: var(--muted);
}

[data-theme="light"] .story-quote {
  background-color: rgba(0, 0, 0, 0.04);
}

.progress-summary {
  max-width: 440px;
  margin-bottom: 1.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.progress-bar-bg {
  width: 100%;
  height: 7px;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 0.4rem;
}

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

.welcome-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.primary-btn, .nav-btn {
  background-color: var(--accent);
  color: #111;
  border: none;
  padding: 0.72rem 1.4rem;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.95rem;
}

.secondary-btn {
  background-color: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.68rem 1.15rem;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
}

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

/* Homepage Chapter Directory */
.home-chapters-section {
  max-width: 1020px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

.home-chapters-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.home-filter-pills {
  display: flex;
  gap: 0.45rem;
}

.pill-btn {
  background-color: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  font-size: 0.82rem;
  cursor: pointer;
}

.pill-btn.active, .pill-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.home-chapter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 0.75rem;
}

.home-chap-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.15s;
}

.home-chap-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.home-chap-card.is-read .home-chap-name {
  opacity: 0.68;
}

.home-chap-card.is-last-read {
  border-color: var(--accent);
}

.home-chap-num {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent);
  display: block;
}

.home-chap-name {
  font-size: 0.92rem;
  font-weight: 500;
}

.home-chap-badges {
  font-size: 0.85rem;
  color: var(--accent);
  flex-shrink: 0;
}

/* Reader View */
.reader-container {
  max-width: 740px;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
}

.nav-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.chapter-header {
  margin-bottom: 2rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 1rem;
}

.chapter-header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chapter-tag {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
}

.read-badge {
  font-size: 0.75rem;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
}

.chapter-header h2 {
  font-size: 1.75rem;
  margin-top: 0.25rem;
}

.chapter-content {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 20px;
  line-height: 1.8;
}

.chapter-content p {
  margin-bottom: 1.35em;
  text-align: justify;
}

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

.nav-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
}

.progress-text {
  font-size: 0.85rem;
  color: var(--muted);
}

@media (max-width: 720px) {
  .hero-content {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
  }
  .cover-card {
    width: 180px;
  }
  .badge-row, .welcome-actions {
    justify-content: center;
  }
  .story-quote {
    text-align: left;
  }
  .book-meta {
    display: none;
  }
}


/* Search Inputs & Pagination for 823-Chapter Directory */
.sidebar-search {
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background-color: var(--surface);
}

.sidebar-search input,
.search-input {
  width: 100%;
  padding: 0.45rem 0.75rem;
  background-color: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.2s;
}

.sidebar-search input:focus,
.search-input:focus {
  border-color: var(--accent);
}

.home-chapters-title-wrap {
  display: flex;
  align-items: baseline;
  gap: 0.65rem;
}

.home-controls-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
}

.home-controls-right .search-input {
  width: 220px;
}

.home-pagination {
  display: flex;
  justify-content: center;
  margin-top: 1.5rem;
}
