/* ============================================================
   Truyện Hay Novel — giao diện theo bộ thiết kế Novel
   (index.html / novel-detail.html / chapter-reader.html)
   ============================================================ */

/* ===== Design Tokens ===== */
:root {
  --bg: #fcfcfa;
  --surface: #ffffff;
  --surface-alt: #f8f6f4;
  --fg: #201a17;
  --muted: #6b625a;
  --caption: #8a827a;
  --brand: #7a5120;
  --accent: #ff6a00;
  --accent-hover: #ff7900;
  --gold: #d08700;
  --gold-light: #fbd38f;
  --border: #e4ded8;
  --border-light: #ebe6e0;
  --info: #105ad0;
  --success: #0b8a4a;
  --danger: #d4380d;
  --font-sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-serif: Georgia, "Noto Serif", serif;
  --radius: 8px;
  --radius-sm: 4px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --reader-font-size: 18px;
  --reader-line-height: 1.9;
  --reader-max-width: 720px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #1a1a1c;
  --surface: #242426;
  --surface-alt: #2a2a2c;
  --fg: #f0ede8;
  --muted: #a49a91;
  --caption: #8a827a;
  --brand: #f1d28a;
  --border: rgba(255,255,255,0.08);
  --border-light: rgba(255,255,255,0.05);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.4);
  color-scheme: dark;
}
:root[data-theme="sepia"] {
  --bg: #f5f0e6;
  --surface: #faf6ed;
  --surface-alt: #ebe5d8;
  --fg: #3d3426;
  --muted: #6b5d4a;
  --border: #ddd5c5;
  --border-light: #e6dfd0;
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a { color: inherit; text-decoration: none; }
img { max-width: 100%; height: auto; display: block; }
button { font: inherit; color: inherit; cursor: pointer; border: none; background: none; }
input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
ul, ol { list-style: none; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.muted { color: var(--muted); }
.empty-note { color: var(--muted); font-size: 14px; padding: 16px 0; }

/* ===== Layout ===== */
.container { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 768px) { .container { padding: 0 24px; } }
@media (min-width: 1280px) { .container { padding: 0 32px; } }
.main { padding: 24px 0 48px; }
@media (min-width: 768px) { .main { padding: 32px 0 64px; } }

/* ===== Header ===== */
.header {
  position: sticky; top: 0; z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.admin-bar .header { top: 32px; }
@media (max-width: 782px) { .admin-bar .header { top: 0; } }
.header-inner { display: flex; align-items: center; gap: 12px; padding: 12px 16px; }
@media (min-width: 768px) { .header-inner { padding: 14px 24px; gap: 16px; } }

.logo { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.logo-icon {
  width: 36px; height: 36px; border-radius: 6px;
  background: linear-gradient(135deg, var(--gold) 0%, var(--brand) 100%);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 13px;
}
:root[data-theme="dark"] .logo-icon { background: linear-gradient(135deg, var(--gold) 0%, #7a5120 100%); }
.logo-img { width: 36px; height: 36px; border-radius: 6px; object-fit: cover; }
@media (min-width: 768px) {
  .logo-icon, .logo-img { width: 40px; height: 40px; font-size: 14px; }
}
.logo-text { display: none; flex-direction: column; }
@media (min-width: 640px) { .logo-text { display: flex; } }
.logo-title { font-size: 18px; font-weight: 700; color: var(--brand); line-height: 1.2; letter-spacing: -0.01em; }
.logo-subtitle { font-size: 11px; color: var(--muted); line-height: 1.2; }

.search { flex: 1; min-width: 0; max-width: 400px; position: relative; }
.search-input {
  width: 100%; height: 38px; padding: 0 40px 0 14px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); color: var(--fg); font-size: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none; appearance: none;
}
.search-input::-webkit-search-cancel-button { display: none; }
.search-input::placeholder { color: var(--muted); }
.search-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,106,0,0.1); }
.search-icon {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
  color: var(--muted);
}
.search-icon svg { width: 18px; height: 18px; }

.header-actions { display: flex; align-items: center; gap: 4px; margin-left: auto; }
@media (min-width: 768px) { .header-actions { gap: 8px; } }
.icon-btn {
  display: flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: var(--radius);
  color: var(--muted); transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--surface-alt); color: var(--fg); }
.icon-btn svg { width: 20px; height: 20px; }
.theme-toggle span { display: flex; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: flex; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

.login-btn {
  display: none; align-items: center; gap: 6px;
  padding: 8px 16px; background: var(--accent); color: #fff;
  font-size: 14px; font-weight: 500; border-radius: var(--radius);
  transition: background 0.15s; white-space: nowrap;
}
.login-btn svg { width: 16px; height: 16px; }
.login-btn:hover { background: var(--accent-hover); }
@media (min-width: 640px) { .login-btn { display: flex; } .login-icon { display: none; } }

/* ===== Section Header ===== */
.section-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.section-title { font-size: 16px; font-weight: 700; color: var(--fg); letter-spacing: -0.01em; }
@media (min-width: 768px) { .section-title { font-size: 18px; } }
.section-link { font-size: 13px; color: var(--accent); font-weight: 500; white-space: nowrap; transition: color 0.15s; }
.section-link:hover { color: var(--accent-hover); text-decoration: underline; }

/* ===== Ảnh bìa dùng chung ===== */
.featured-cover, .top-featured-cover, .update-cover, .completed-cover, .related-cover, .novel-cover {
  position: relative; overflow: hidden;
  background: linear-gradient(135deg, var(--surface-alt) 0%, var(--border) 100%);
}
.featured-cover img, .top-featured-cover img, .update-cover img,
.completed-cover img, .related-cover img, .novel-cover img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
}
.cover-placeholder {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 32px; color: var(--muted); opacity: 0.4;
}

/* ===== Carousel ===== */
.carousel-section { margin-bottom: 32px; }
@media (min-width: 768px) { .carousel-section { margin-bottom: 40px; } }
.carousel {
  display: flex; gap: 12px;
  overflow-x: auto; scroll-snap-type: x mandatory;
  scrollbar-width: none; -ms-overflow-style: none;
  padding-bottom: 8px; margin: 0 -16px; padding-left: 16px; padding-right: 16px;
}
.carousel::-webkit-scrollbar { display: none; }
@media (min-width: 768px) { .carousel { gap: 16px; margin: 0; padding-left: 0; padding-right: 0; } }

.library-card {
  flex-shrink: 0; scroll-snap-align: start;
  width: 280px; height: 160px;
  border-radius: var(--radius); overflow: hidden; position: relative; display: block;
  background: linear-gradient(135deg, var(--surface-alt) 0%, var(--border) 100%);
}
@media (min-width: 768px) { .library-card { width: 320px; height: 180px; } }
@media (min-width: 1024px) { .library-card { width: 360px; height: 200px; } }
.library-card-img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: center 25%;
  transition: transform 0.3s;
}
.library-card:hover .library-card-img { transform: scale(1.04); }
.library-card-bg { position: absolute; inset: 0; background: linear-gradient(to bottom, transparent 40%, rgba(0,0,0,0.8) 100%); }
.library-card-content { position: absolute; bottom: 0; left: 0; right: 0; padding: 16px; color: #fff; display: block; }
.library-card-title {
  font-size: 15px; font-weight: 600; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
@media (min-width: 768px) { .library-card-title { font-size: 16px; } }
.library-card-meta { display: block; font-size: 12px; color: rgba(255,255,255,0.7); margin-top: 4px; }

.featured-card { flex-shrink: 0; scroll-snap-align: start; width: 120px; display: block; }
@media (min-width: 768px) { .featured-card { width: 140px; } }
.featured-cover { display: block; width: 100%; aspect-ratio: 3/4; border-radius: var(--radius-sm); margin-bottom: 8px; }
.featured-title {
  font-size: 13px; font-weight: 500; color: var(--fg); line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  transition: color 0.15s;
}
.featured-card:hover .featured-title { color: var(--accent); }

/* ===== Two Column / Ranking ===== */
.two-col { display: grid; grid-template-columns: minmax(0, 1fr); gap: 24px; margin-bottom: 32px; }
@media (min-width: 768px) { .two-col { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 32px; margin-bottom: 40px; } }
.ranking-section { background: var(--surface); border-radius: var(--radius); padding: 16px; }
@media (min-width: 768px) { .ranking-section { padding: 20px; } }
.ranking-list { display: flex; flex-direction: column; }
.ranking-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--border-light);
}
.ranking-item:last-child { border-bottom: none; padding-bottom: 0; }
.ranking-item:first-child { padding-top: 0; }
.ranking-number {
  width: 24px; height: 24px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.ranking-number.gold { background: linear-gradient(135deg, #ffd700, #ffb800); color: #7a5120; }
.ranking-number.silver { background: linear-gradient(135deg, #e8e8e8, #c0c0c0); color: #555; }
.ranking-number.bronze { background: linear-gradient(135deg, #ffcc99, #cd7f32); color: #5d3a1a; }
.ranking-number.default { background: var(--surface-alt); color: var(--muted); }
.ranking-info { flex: 1; min-width: 0; display: block; }
.ranking-title {
  display: block; font-size: 14px; font-weight: 500; color: var(--fg);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: color 0.15s;
}
.ranking-item:hover .ranking-title { color: var(--accent); }
.ranking-stats { display: block; font-size: 12px; color: var(--caption); margin-top: 2px; }

.top-featured-item { display: flex; gap: 12px; padding: 0 0 12px; border-bottom: 1px solid var(--border-light); }
.top-featured-item + .ranking-item { padding-top: 10px; }
.top-featured-cover { width: 64px; height: 85px; border-radius: var(--radius-sm); flex-shrink: 0; }
.top-featured-cover .cover-placeholder { font-size: 20px; }
.top-featured-info { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; }
.top-featured-rank { font-size: 11px; color: var(--gold); font-weight: 600; margin-bottom: 4px; }
.top-featured-title {
  font-size: 14px; font-weight: 500; color: var(--fg); line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  transition: color 0.15s;
}
.top-featured-item:hover .top-featured-title { color: var(--accent); }
.top-featured-views { font-size: 12px; color: var(--caption); margin-top: 4px; }

/* ===== Vừa Lên Chương ===== */
.updates-section { margin-bottom: 32px; }
@media (min-width: 768px) { .updates-section { margin-bottom: 40px; } }
.updates-list { background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.update-item {
  display: flex; gap: 12px; padding: 14px 16px;
  border-bottom: 1px solid var(--border-light); transition: background 0.15s;
}
.update-item:hover { background: var(--surface-alt); }
.update-item:last-child { border-bottom: none; }
.update-cover { display: block; width: 48px; height: 64px; border-radius: var(--radius-sm); flex-shrink: 0; }
.update-cover .cover-placeholder { font-size: 16px; }
.update-info { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; }
.update-title {
  font-size: 14px; font-weight: 500; color: var(--fg); line-height: 1.4; margin-bottom: 4px;
  display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden;
}
.update-title a:hover { color: var(--accent); }
.update-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12px; color: var(--caption); }
.update-author { color: var(--muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.update-genre { padding: 2px 6px; background: var(--surface-alt); border-radius: 3px; font-size: 11px; }
.update-item:hover .update-genre { background: var(--bg); }
.update-right {
  display: flex; flex-direction: column; align-items: flex-end; justify-content: center;
  flex-shrink: 0; text-align: right; max-width: 40%;
}
.update-chapter {
  font-size: 13px; font-weight: 500; color: var(--accent);
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.update-right:hover .update-chapter { text-decoration: underline; }
.update-time { font-size: 11px; color: var(--caption); margin-top: 4px; }

/* ===== Lưới truyện (Mới hoàn thành, danh sách, tìm kiếm) ===== */
.completed-section { margin-bottom: 32px; }
.completed-grid, .cover-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px;
}
@media (min-width: 640px) { .completed-grid, .cover-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; } }
@media (min-width: 1024px) { .completed-grid, .cover-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.completed-card { display: block; background: var(--surface); border-radius: var(--radius); overflow: hidden; transition: box-shadow 0.15s; }
.completed-card:hover { box-shadow: var(--shadow-md); }
.completed-cover { display: block; width: 100%; aspect-ratio: 3/4; }
.completed-badge {
  position: absolute; top: 8px; left: 8px; z-index: 1;
  padding: 3px 8px; background: var(--success); color: #fff;
  font-size: 10px; font-weight: 600; border-radius: 3px;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.completed-info { display: block; padding: 12px; }
.completed-title {
  font-size: 13px; font-weight: 500; color: var(--fg); line-height: 1.4; margin-bottom: 4px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.completed-card:hover .completed-title { color: var(--accent); }
.completed-chapters { font-size: 12px; color: var(--caption); }

/* ===== Footer ===== */
.footer { background: var(--surface); border-top: 1px solid var(--border); padding: 40px 0 24px; }
.footer-about { text-align: center; max-width: 700px; margin: 0 auto 24px; }
.footer-about p { font-size: 14px; color: var(--muted); line-height: 1.7; }
.footer-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 16px 24px; margin-bottom: 24px; }
.footer-link { font-size: 14px; color: var(--muted); transition: color 0.15s; }
.footer-link:hover { color: var(--fg); text-decoration: underline; }
.footer-bottom { text-align: center; padding-top: 24px; border-top: 1px solid var(--border-light); }
.footer-copyright { font-size: 14px; color: var(--caption); }

/* ===== Nút ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 24px; border-radius: var(--radius);
  font-size: 15px; font-weight: 500; line-height: 1.2; transition: all 0.15s;
}
.btn svg { width: 18px; height: 18px; flex-shrink: 0; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary, .btn--primary, .btn--accent { background: var(--accent); color: #fff; }
.btn-primary:hover, .btn--primary:hover, .btn--accent:hover { background: var(--accent-hover); }
.btn-secondary, .btn--outline, .btn--accent-soft {
  background: var(--surface); color: var(--fg); border: 1px solid var(--border);
}
.btn-secondary:hover, .btn--outline:hover, .btn--accent-soft:hover { background: var(--surface-alt); }
.btn-secondary.is-saved { color: var(--accent); border-color: var(--accent); }
.btn-sm { padding: 8px 16px; font-size: 14px; }
.btn--block { width: 100%; }

/* ===== Trang truyện ===== */
.breadcrumb {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 16px 0; font-size: 13px; color: var(--muted);
}
.breadcrumb a:hover { color: var(--accent); }
.breadcrumb-sep { color: var(--caption); }

.novel-detail { padding-bottom: 48px; }
.novel-hero { display: grid; grid-template-columns: minmax(0, 1fr); gap: 24px; padding: 24px 0; }
@media (min-width: 768px) { .novel-hero { grid-template-columns: 200px minmax(0, 1fr); gap: 32px; } }
.novel-cover {
  width: 160px; aspect-ratio: 3/4; margin: 0 auto;
  border-radius: var(--radius); box-shadow: var(--shadow-md);
}
.novel-cover .cover-placeholder { font-size: 48px; }
@media (min-width: 768px) { .novel-cover { width: 100%; margin: 0; } }
.novel-info { text-align: center; }
@media (min-width: 768px) { .novel-info { text-align: left; } }
.novel-title { font-size: 24px; font-weight: 700; color: var(--fg); line-height: 1.3; margin-bottom: 8px; }
@media (min-width: 768px) { .novel-title { font-size: 28px; } }
.novel-author { font-size: 15px; color: var(--muted); margin-bottom: 16px; }
.novel-author a { color: var(--accent); }
.novel-author a:hover { text-decoration: underline; }
.novel-meta { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-bottom: 20px; }
@media (min-width: 768px) { .novel-meta { justify-content: flex-start; } }
.meta-item { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.meta-item svg { width: 16px; height: 16px; }
a.meta-item:hover { color: var(--accent); }
.meta-item.status { color: var(--success); font-weight: 500; }
.meta-item.status.ongoing { color: var(--accent); }
.novel-tags { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 24px; }
@media (min-width: 768px) { .novel-tags { justify-content: flex-start; } }
.tag {
  display: inline-block; padding: 6px 12px; background: var(--surface-alt);
  border-radius: 20px; font-size: 13px; color: var(--muted);
  transition: background 0.15s, color 0.15s;
}
.tag:hover { background: var(--accent); color: #fff; }
.tag--pink { background: rgba(255,106,0,0.12); color: var(--accent); }
.novel-actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }
@media (min-width: 768px) { .novel-actions { justify-content: flex-start; } }

.section { margin-bottom: 32px; }
.section > .section-title {
  margin-bottom: 16px; padding-bottom: 12px; border-bottom: 2px solid var(--border);
}
.synopsis { font-size: 15px; line-height: 1.8; color: var(--muted); position: relative; }
.synopsis p { margin-bottom: 16px; }
.synopsis p:last-child { margin-bottom: 0; }
.synopsis.is-collapsed { max-height: 220px; overflow: hidden; }
.synopsis.is-collapsed::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 64px;
  background: linear-gradient(to bottom, transparent, var(--bg));
}
.synopsis-toggle { margin-top: 8px; font-size: 14px; font-weight: 500; color: var(--accent); }
.synopsis-toggle:hover { text-decoration: underline; }

.chapter-header {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px; margin-bottom: 16px;
  padding-bottom: 12px; border-bottom: 2px solid var(--border);
}
.chapter-header .section-title { margin-right: auto; }
.chapter-count { font-size: 14px; color: var(--muted); }
.chapter-sort { display: flex; gap: 8px; }
.sort-btn {
  padding: 6px 12px; border-radius: var(--radius-sm);
  font-size: 13px; color: var(--muted);
  border: 1px solid var(--border); background: var(--surface); transition: all 0.15s;
}
.sort-btn:hover, .sort-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.chapter-list {
  background: var(--surface); border-radius: var(--radius);
  border: 1px solid var(--border); overflow: hidden; scroll-margin-top: 90px;
}
.chapter-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border-light); transition: background 0.15s;
}
.chapter-item:last-child { border-bottom: none; }
.chapter-item:hover { background: var(--surface-alt); }
.chapter-name {
  font-size: 14px; color: var(--fg); min-width: 0;
  display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden;
}
.chapter-item:hover .chapter-name { color: var(--accent); }
.chapter-time { font-size: 12px; color: var(--caption); flex-shrink: 0; margin-left: 16px; }

.pagination { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 8px; margin-top: 24px; }
.pagination:empty { display: none; }
.page-btn, .pagination .page-numbers {
  min-width: 36px; height: 36px; padding: 0 12px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm); font-size: 14px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--muted); transition: all 0.15s;
}
.page-btn:hover:not(:disabled), .page-btn.active,
.pagination a.page-numbers:hover, .pagination .page-numbers.current {
  background: var(--accent); color: #fff; border-color: var(--accent);
}
.page-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.pagination .page-numbers.dots { border-color: transparent; background: none; }

.related-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
@media (min-width: 640px) { .related-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1024px) { .related-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.related-card { display: block; transition: transform 0.15s; }
.related-card:hover { transform: translateY(-4px); }
.related-cover { display: block; width: 100%; aspect-ratio: 3/4; border-radius: var(--radius-sm); margin-bottom: 8px; }
.related-title {
  font-size: 13px; font-weight: 500; color: var(--fg); line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

/* Đánh giá */
.rate-box {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px;
}
.rate-summary { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.rate-avg { font-size: 28px; font-weight: 700; color: var(--fg); line-height: 1; }
.rate-stars-display { color: var(--gold); font-size: 18px; letter-spacing: 2px; }
.rate-count { font-size: 13px; color: var(--muted); }
.rate-mine { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 14px; color: var(--muted); }
.rate-mine strong { color: var(--gold); }
.rate-stars { display: inline-flex; gap: 2px; }
.rate-star { font-size: 24px; line-height: 1; color: var(--border); transition: color 0.1s, transform 0.1s; padding: 2px; }
.rate-star.is-on { color: var(--gold); }
.rate-star:hover { transform: scale(1.15); }
.rate-hint { font-size: 12px; color: var(--caption); }

/* ===== Trang đọc ===== */
.reader-header {
  position: sticky; top: 0; z-index: 100;
  background: var(--surface); border-bottom: 1px solid var(--border);
  transition: transform 0.3s;
}
.admin-bar .reader-header { top: 32px; }
@media (max-width: 782px) { .admin-bar .reader-header { top: 0; } }
.reader-header.hidden { transform: translateY(-100%); }
.admin-bar .reader-header.hidden { transform: translateY(calc(-100% - 32px)); }
.reader-header-inner { display: flex; align-items: center; gap: 12px; padding: 10px 16px; max-width: 1200px; margin: 0 auto; }
@media (min-width: 768px) { .reader-header-inner { padding: 12px 24px; } }
.back-btn {
  display: flex; align-items: center; gap: 6px; flex-shrink: 0;
  padding: 8px 12px; border-radius: var(--radius); color: var(--muted); font-size: 14px; transition: all 0.15s;
}
.back-btn:hover { background: var(--surface-alt); color: var(--fg); }
.back-btn svg { width: 18px; height: 18px; }
.reader-title {
  flex: 1; min-width: 0; text-align: center;
  font-size: 14px; font-weight: 500; color: var(--fg);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.reader-content { max-width: var(--reader-max-width); margin: 0 auto; padding: 32px 20px 96px; }
@media (min-width: 768px) { .reader-content { padding: 48px 24px 100px; } }
.reader-content > .chapter-header {
  display: block; text-align: center;
  padding-bottom: 32px; margin-bottom: 32px; border-bottom: 1px solid var(--border-light);
}
.chapter-novel { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.chapter-novel a { color: var(--accent); }
.chapter-novel a:hover { text-decoration: underline; }
.chapter-title { font-size: 22px; font-weight: 700; color: var(--fg); line-height: 1.4; }
@media (min-width: 768px) { .chapter-title { font-size: 26px; } }

.reading-area {
  font-family: var(--font-serif);
  font-size: var(--reader-font-size);
  line-height: var(--reader-line-height);
  color: var(--fg);
  overflow-wrap: break-word;
}
.reading-area p { margin-bottom: 1.5em; text-align: justify; text-indent: 2em; }
.reading-area p:empty { display: none; }
.reading-area img { width: 100%; height: auto; margin: 0 auto; }
.reading-area .empty-note { text-indent: 0; text-align: center; }

.chapter-nav {
  display: none; gap: 12px; justify-content: center; flex-wrap: wrap;
  padding: 32px 0; margin-top: 48px; border-top: 1px solid var(--border-light);
}
@media (min-width: 768px) { .chapter-nav { display: flex; } }
.nav-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 24px; border-radius: var(--radius); font-size: 15px; font-weight: 500; transition: all 0.15s;
}
.nav-btn svg { width: 18px; height: 18px; }
.nav-btn.primary { background: var(--accent); color: #fff; }
.nav-btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.nav-btn.secondary { background: var(--surface); color: var(--fg); border: 1px solid var(--border); }
.nav-btn.secondary:hover:not(:disabled) { background: var(--surface-alt); }
.nav-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.reader-bookmark { display: flex; justify-content: center; margin: 32px 0; }
@media (min-width: 768px) { .reader-bookmark { margin-top: 0; } }

.settings-overlay {
  position: fixed; inset: 0; z-index: 200; background: rgba(0,0,0,0.5);
  opacity: 0; visibility: hidden; transition: all 0.2s;
}
.settings-overlay.active { opacity: 1; visibility: visible; }
.settings-panel {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 201;
  background: var(--surface); color: var(--fg);
  border-radius: 16px 16px 0 0; padding: 24px 20px 32px;
  transform: translateY(100%); transition: transform 0.3s; visibility: hidden;
}
.settings-panel.active { transform: translateY(0); visibility: visible; }
@media (min-width: 640px) {
  .settings-panel { left: 50%; width: 400px; transform: translateX(-50%) translateY(100%); }
  .settings-panel.active { transform: translateX(-50%) translateY(0); }
}
.settings-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.settings-title { font-size: 18px; font-weight: 600; color: var(--fg); }
.close-btn { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.close-btn:hover { background: var(--surface-alt); }
.close-btn svg { width: 20px; height: 20px; }
.setting-group { margin-bottom: 24px; }
.setting-group:last-child { margin-bottom: 0; }
.setting-label { font-size: 13px; font-weight: 500; color: var(--muted); margin-bottom: 12px; text-transform: uppercase; letter-spacing: 0.05em; }
.theme-options { display: flex; gap: 12px; }
.theme-btn { flex: 1; padding: 12px; border-radius: var(--radius); border: 2px solid var(--border); font-size: 13px; font-weight: 500; }
.theme-btn.active { border-color: var(--accent); }
.theme-btn.light { background: #fcfcfa; color: #201a17; }
.theme-btn.dark-theme { background: #1a1a1c; color: #e8e5e0; }
.theme-btn.sepia-theme { background: #f5f0e6; color: #3d3426; }
.font-size-control { display: flex; align-items: center; gap: 16px; }
.font-btn {
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface);
  font-size: 15px; font-weight: 600; color: var(--muted);
}
.font-btn:hover { border-color: var(--accent); color: var(--accent); }
.font-size-display { flex: 1; text-align: center; font-size: 16px; font-weight: 500; }

.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom, 0px));
}
.bottom-nav-inner { display: flex; justify-content: space-around; max-width: 400px; margin: 0 auto; }
.bottom-btn { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 16px; color: var(--muted); font-size: 11px; }
.bottom-btn:hover { color: var(--accent); }
.bottom-btn svg { width: 22px; height: 22px; }
.bottom-btn.disabled { opacity: 0.4; pointer-events: none; }
@media (min-width: 768px) { .mobile-only { display: none !important; } }
@media (max-width: 767px) { .desktop-only { display: none !important; } }
/* Keep the CMS ad overlay above the chapter navigation on phones. */
@media (max-width: 767px) { body.reader-page { --kht-ad-overlay-bottom: calc(76px + env(safe-area-inset-bottom, 0px)); } }

/* Bình luận */
.comment-card { margin-top: 16px; padding-top: 32px; border-top: 1px solid var(--border-light); }
.comment-card__title { font-size: 18px; font-weight: 700; margin-bottom: 16px; }
.comment-form { display: grid; gap: 10px; margin-bottom: 20px; }
.comment-form input, .comment-form textarea, .auth-form input, .filter-bar select {
  width: 100%; padding: 10px 14px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--fg); font-size: 14px;
}
.comment-form textarea { resize: vertical; min-height: 84px; }
.comment-form input:focus, .comment-form textarea:focus, .auth-form input:focus, .filter-bar select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,106,0,0.1);
}
.comment-form .btn { justify-self: end; }
.comment-login { font-size: 14px; color: var(--muted); margin-bottom: 20px; }
.comment-login a { color: var(--accent); font-weight: 500; }
.comment-list { display: flex; flex-direction: column; }
.comment-item { display: flex; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--border-light); }
.comment-item:last-child { border-bottom: none; }
.comment-item__avatar {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--gold) 0%, #7a5120 100%); color: #fff; font-weight: 700; font-size: 14px;
}
.comment-item__name { font-size: 14px; font-weight: 600; }
.comment-item__time { font-size: 12px; color: var(--caption); }
.comment-item__text { font-size: 14px; color: var(--muted); margin-top: 4px; white-space: pre-line; overflow-wrap: anywhere; }
.comment-empty { font-size: 14px; color: var(--caption); padding: 8px 0; }

/* ===== Trang phụ: danh sách, tìm kiếm, tủ truyện, tài khoản ===== */
main.container { padding-top: 24px; padding-bottom: 48px; }
@media (min-width: 768px) { main.container { padding-top: 32px; padding-bottom: 64px; } }
.page-head { margin-bottom: 20px; }
.page-head__title { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
@media (min-width: 768px) { .page-head__title { font-size: 26px; } }
.page-head__sub { font-size: 14px; color: var(--muted); margin-top: 4px; }
.page-head__sub:empty { display: none; }
.filter-bar {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px;
  background: var(--surface); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 20px;
}
.filter-bar__field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); min-width: 160px; }
.filter-bar__count { margin-left: auto; font-size: 13px; color: var(--caption); padding-bottom: 10px; }

.empty-state {
  text-align: center; background: var(--surface); border-radius: var(--radius);
  padding: 40px 20px; display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.empty-state__icon { font-size: 36px; }
.empty-state__title { font-size: 17px; font-weight: 700; }
.empty-state__sub { font-size: 14px; color: var(--muted); max-width: 460px; }
.empty-state .btn { margin-top: 6px; }

.lib-list { background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.lib-item { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border-light); }
.lib-item:last-child { border-bottom: none; }
.lib-item .cover {
  position: relative; overflow: hidden; flex-shrink: 0;
  width: 48px; height: 64px; border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--surface-alt) 0%, var(--border) 100%);
}
.lib-item .cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.lib-item .cover__title { position: absolute; inset: 4px; font-size: 8px; line-height: 1.2; overflow: hidden; color: var(--muted); }
.lib-item__body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.lib-item__title { font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-item__title a:hover { color: var(--accent); }
.lib-item__meta { font-size: 12px; color: var(--caption); }
.lib-item__side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex-shrink: 0; }
.lib-item .tag { padding: 3px 8px; font-size: 11px; }
.update-item__read { font-size: 13px; font-weight: 500; color: var(--accent); }
.update-item__read:hover { text-decoration: underline; }

.container--reader { max-width: var(--reader-max-width); }
.prose { background: var(--surface); border-radius: var(--radius); padding: 24px; line-height: 1.75; }
@media (min-width: 768px) { .prose { padding: 32px; } }
.prose__title { font-size: 24px; font-weight: 700; margin-bottom: 16px; line-height: 1.3; }
.prose p, .prose ul, .prose ol { margin-bottom: 1em; }
.prose ul { list-style: disc; padding-left: 1.4em; }
.prose ol { list-style: decimal; padding-left: 1.4em; }
.prose a { color: var(--accent); }
.prose .btn { margin: 4px 8px 4px 0; }
.prose .btn--accent { color: #fff; }

.auth__tabs { display: flex; gap: 4px; background: var(--surface-alt); border-radius: var(--radius); padding: 4px; margin-bottom: 20px; }
.auth__tab { flex: 1; padding: 9px 12px; border-radius: 6px; font-size: 14px; font-weight: 500; color: var(--muted); }
.auth__tab.is-active { background: var(--surface); color: var(--fg); box-shadow: var(--shadow); }
.auth-form { display: grid; gap: 14px; }
.auth-form[hidden] { display: none; }
.auth-form__field { display: grid; gap: 6px; font-size: 13px; font-weight: 500; color: var(--muted); }
.auth-form__hint { font-weight: 400; color: var(--caption); }
.auth__note { font-size: 13px; color: var(--caption); margin-top: 16px; text-align: center; }

.error-page { text-align: center; padding: 48px 0; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.error-page__icon { font-size: 40px; }
.error-page__code { font-size: 64px; font-weight: 800; color: var(--accent); line-height: 1; }
.error-page__title { font-size: 17px; color: var(--muted); margin-bottom: 12px; }


/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 300;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: #201a17; color: #fff; font-size: 14px;
  padding: 10px 18px; border-radius: var(--radius); box-shadow: var(--shadow-md);
  transition: opacity 0.2s, transform 0.2s; max-width: calc(100% - 32px); text-align: center;
}
:root[data-theme="dark"] .toast { background: #f0ede8; color: #201a17; }
.toast.is-show { opacity: 1; transform: translate(-50%, 0); }
body[data-page="reader"] .toast { bottom: 84px; }
@media (min-width: 768px) { body[data-page="reader"] .toast { bottom: 24px; } }
