/* NovelVerse — Clean Reader-First UI (Light / Sepia / Dark) */
:root {
  --bg: #f7f8fc;
  --surface: #ffffff;
  --surface-2: #f1f3f9;
  --text: #111827;
  --text-muted: #64748b;
  --border: #e5e7eb;
  --accent: #6d5df6;
  --accent-hover: #5b4be3;
  --accent-soft: rgba(109, 93, 246, 0.11);
  --success: #059669;
  --success-soft: rgba(5, 150, 105, 0.12);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 10px 28px rgba(15, 23, 42, 0.07);
  --radius: 14px;
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-serif: "Newsreader", Georgia, "Times New Roman", serif;
  --reader-size: 18px;
}

html[data-theme="sepia"] {
  --bg: #f6efe2;
  --surface: #fbf6ec;
  --surface-2: #efe5d3;
  --text: #35291c;
  --text-muted: #786552;
  --border: #e3d6c0;
  --accent: #9a5b25;
  --accent-hover: #7f491c;
  --accent-soft: rgba(154, 91, 37, 0.13);
}

html[data-theme="dark"] {
  --bg: #0c0e14;
  --surface: #141822;
  --surface-2: #1c2230;
  --text: #e6e9f2;
  --text-muted: #94a0b8;
  --border: #242c3d;
  --accent: #8b7bff;
  --accent-hover: #7a68ff;
  --accent-soft: rgba(139, 123, 255, 0.16);
  --shadow-md: 0 12px 30px rgba(0, 0, 0, 0.35);
}

*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  min-height: 100%;
  transition: background 0.2s ease, color 0.2s ease;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
img { display: block; max-width: 100%; }
.hidden { display: none !important; }

/* Progress bar */
.read-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0;
  background: var(--accent);
  z-index: 90;
  transition: width 0.08s linear;
}

/* Top Nav */
.top-nav {
  position: sticky;
  top: 0;
  z-index: 40;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  border-bottom: 1px solid var(--border);
}
.nav-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
  flex-shrink: 0;
}
.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: 0 4px 12px color-mix(in srgb, var(--accent) 35%, transparent);
}
.search-wrap {
  flex: 1;
  max-width: 460px;
  margin-left: auto;
  position: relative;
  display: flex;
  align-items: center;
}
.search-icon {
  position: absolute;
  left: 12px;
  color: var(--text-muted);
  pointer-events: none;
}
.search-wrap input {
  width: 100%;
  padding: 9px 34px 9px 36px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.search-wrap input:focus {
  border-color: var(--accent);
  background: var(--surface);
}
#search-clear {
  position: absolute;
  right: 8px;
  padding: 4px;
  color: var(--text-muted);
}
.icon-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.85rem;
  font-weight: 500;
  transition: border-color 0.15s, background 0.15s;
}
.icon-pill:hover { border-color: var(--accent); }
.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  color: var(--text-muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* Main Container */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 22px 18px 64px;
}

/* Continue Reading Banner */
.continue-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  margin-bottom: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.continue-meta { min-width: 0; }
.continue-kicker {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  margin-bottom: 3px;
}
.continue-title {
  font-weight: 600;
  font-size: 0.98rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.continue-sub {
  font-size: 0.84rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Catalog Header & Filters */
.catalog-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.stats-strip {
  font-size: 0.86rem;
  color: var(--text-muted);
}
.stats-strip strong { color: var(--text); font-weight: 600; }

.status-pills {
  display: inline-flex;
  background: var(--surface-2);
  padding: 3px;
  border-radius: 999px;
  border: 1px solid var(--border);
}
.status-pill {
  padding: 5px 13px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
}
.status-pill.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.tag-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 18px;
  scrollbar-width: none;
}
.tag-row::-webkit-scrollbar { display: none; }
.tag-chip {
  flex-shrink: 0;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: all 0.15s;
}
.tag-chip:hover { border-color: var(--accent); color: var(--text); }
.tag-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Novel Grid */
.novel-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
@media (min-width: 640px) { .novel-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 900px) { .novel-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (min-width: 1120px) { .novel-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 18px; } }

.novel-card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}
.novel-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
}
.cover-box {
  position: relative;
  aspect-ratio: 2 / 3;
  background: linear-gradient(135deg, #3b3578 0%, #6d5df6 100%);
  overflow: hidden;
}
.cover-box img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.cover-fallback {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  color: rgba(255, 255, 255, 0.9);
  font-size: 2.2rem;
  font-weight: 700;
  letter-spacing: -0.04em;
  padding: 16px;
  text-align: center;
}
.cover-badges {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  display: flex;
  justify-content: space-between;
  gap: 6px;
  pointer-events: none;
}
.badge {
  font-size: 0.69rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  backdrop-filter: blur(8px);
  background: rgba(15, 23, 42, 0.72);
  color: #fff;
}
.badge.completed { background: rgba(5, 150, 105, 0.88); }
.badge.epub { background: rgba(109, 93, 246, 0.88); }

.card-body {
  padding: 11px 12px 13px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}
.card-title {
  font-weight: 600;
  font-size: 0.92rem;
  line-height: 1.32;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-author {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-foot {
  margin-top: auto;
  padding-top: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 11px;
  font-weight: 600;
  font-size: 0.9rem;
  transition: transform 0.1s, background 0.15s, border-color 0.15s;
}
.btn:active { transform: scale(0.98); }
.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 30%, transparent);
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-secondary:hover { border-color: var(--accent); }
.btn-sm { padding: 7px 13px; font-size: 0.83rem; border-radius: 9px; }

.load-more-wrap {
  display: flex;
  justify-content: center;
  margin-top: 28px;
}

/* Detail View */
.back-row { margin-bottom: 16px; }
.detail-hero {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
@media (min-width: 720px) {
  .detail-hero { grid-template-columns: 220px 1fr; padding: 26px; gap: 28px; }
}
.detail-cover {
  max-width: 220px;
  width: 100%;
  margin: 0 auto;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow-md);
}
.detail-title {
  margin: 0 0 6px;
  font-size: clamp(1.35rem, 2.5vw, 1.85rem);
  letter-spacing: -0.02em;
  line-height: 1.22;
}
.detail-author {
  color: var(--text-muted);
  font-size: 0.94rem;
  margin-bottom: 12px;
}
.meta-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}
.meta-pill {
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
}
.meta-pill.accent { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.meta-pill.green { background: var(--success-soft); border-color: transparent; color: var(--success); }

.detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 18px;
}
.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.section-card {
  margin-top: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.section-card h2 {
  margin: 0 0 12px;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}
.synopsis-text {
  color: var(--text);
  line-height: 1.7;
  font-size: 0.95rem;
  white-space: pre-line;
}

.chapter-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}
.chapter-toolbar input {
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.86rem;
  min-width: 210px;
  outline: none;
}
.chapter-toolbar input:focus { border-color: var(--accent); }

.chapter-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  max-height: 540px;
  overflow-y: auto;
  padding-right: 4px;
}
@media (min-width: 720px) { .chapter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.chapter-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 13px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 0.87rem;
  transition: border-color 0.14s, background 0.14s;
}
.chapter-item:hover { border-color: var(--accent); background: var(--surface); }
.chapter-item.is-last {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.chapter-item-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chapter-num-tag {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* Reader View */
.reader-shell {
  max-width: 740px;
  margin: 0 auto;
}
.reader-bar {
  position: sticky;
  top: 62px;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  margin-bottom: 24px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-sm);
}
.reader-bar-title {
  min-width: 0;
  flex: 1;
}
.reader-bar-novel {
  font-size: 0.76rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reader-bar-ch {
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reader-tools { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }

.reader-article {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: clamp(22px, 4vw, 44px);
  box-shadow: var(--shadow-sm);
}
.reader-chapter-heading {
  margin: 0 0 24px;
  font-size: clamp(1.3rem, 2.4vw, 1.75rem);
  line-height: 1.3;
  letter-spacing: -0.02em;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.reader-content {
  font-size: var(--reader-size);
  line-height: 1.85;
  font-family: var(--font-serif);
  word-break: break-word;
}
.reader-content.font-sans { font-family: var(--font-sans); line-height: 1.78; }
.reader-content p { margin: 0 0 1.15em; }
.reader-content h1, .reader-content h2, .reader-content h3 {
  font-family: var(--font-sans);
  margin: 1.5em 0 0.6em;
  line-height: 1.3;
}
.reader-content blockquote {
  margin: 1.2em 0;
  padding: 10px 16px;
  border-left: 3px solid var(--accent);
  background: var(--surface-2);
  border-radius: 0 10px 10px 0;
}

.reader-nav-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 22px;
}
.reader-nav-foot .btn { flex: 1; max-width: 210px; }
.reader-nav-foot .btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Settings Popover */
.popover {
  position: fixed;
  top: 126px;
  right: 18px;
  width: 270px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  box-shadow: var(--shadow-md);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.popover-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.popover-label { font-size: 0.82rem; font-weight: 600; color: var(--text-muted); }
.seg-group, .size-controls {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--surface-2);
  padding: 3px;
  border-radius: 10px;
}
.seg-btn {
  padding: 5px 10px;
  border-radius: 7px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
}
.seg-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}
.size-readout { font-size: 0.8rem; font-weight: 600; min-width: 38px; text-align: center; }

/* Chapter Drawer */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(3px);
  z-index: 70;
  display: flex;
  justify-content: flex-end;
}
.drawer-panel {
  width: min(380px, 92vw);
  height: 100%;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.drawer-head h3 { margin: 0; font-size: 1rem; }
.drawer-search { padding: 10px 14px; border-bottom: 1px solid var(--border); }
.drawer-search input {
  width: 100%;
  padding: 8px 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.86rem;
  outline: none;
}
.drawer-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px 14px 24px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Empty & Loading States */
.empty-state {
  text-align: center;
  padding: 56px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
}
.empty-state h3 { margin: 0 0 6px; font-size: 1.08rem; }
.empty-state p { margin: 0; color: var(--text-muted); font-size: 0.9rem; }

.skeleton-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
@media (min-width: 640px) { .skeleton-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 900px) { .skeleton-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (min-width: 1120px) { .skeleton-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.skeleton-card {
  aspect-ratio: 2 / 3.4;
  border-radius: var(--radius);
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

@media (max-width: 560px) {
  .hide-sm { display: none; }
  .nav-inner { padding: 10px 12px; gap: 10px; }
  .container { padding: 16px 12px 54px; }
}
