:root {
  --primary: #B99ADE;
  --primary-dark: #9B7BC2;
  --primary-light: #EDE7F6;
  --bg: #F7F3FB;
  --bg-card: #FFFFFF;
  --text: #3D2B5A;
  --text-muted: #7A6B8F;
  --border: #E4D4F4;
  --shadow: 0 4px 18px rgba(155, 123, 194, 0.10);
  --radius: 14px;
  --header-h: 60px;
}

[data-theme="dark"] {
  --bg: #120E1A;
  --bg-card: #1C1528;
  --text: #F0EAF8;
  --text-muted: #B99ADE;
  --border: #2A2038;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.45);
  --primary: #C4A8E8;
  --primary-dark: #B99ADE;
  --primary-light: #2A2038;
}

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

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--primary-dark); text-decoration: none; }
a:hover { color: var(--primary); }

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

.container { width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 16px; }

/* Header */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  height: var(--header-h);
  display: flex;
  align-items: center;
  box-shadow: var(--shadow);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 12px;
}

.logo,
.site-logo-link {
  display: flex;
  align-items: center;
  text-decoration: none;
  flex-shrink: 0;
}
.site-logo {
  height: 44px;
  width: auto;
  max-width: 180px;
  object-fit: contain;
  display: block;
}

@media (max-width: 768px) {
  .site-logo {
    height: 36px;
    max-width: 140px;
  }
  
}
@media (max-width: 400px) {
  .site-logo {
    height: 32px;
    max-width: 120px;
  }
}

.footer-logo {
  display: inline-block;
  text-decoration: none;
}
.footer-logo img,
.footer-logo .site-logo {
  width: 180px;
  max-width: 60vw;
  height: auto;
  display: block;
  object-fit: contain;
}
@media (max-width: 600px) {
  .footer-logo img,
  .footer-logo .site-logo {
    width: 150px;
    max-width: 55vw;
  }
}


.nav-links {
  display: flex;
  align-items: center;
  gap: 8px;
  list-style: none;
}

.nav-links a, .btn-link {
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--text);
  font-size: 0.95rem;
  background: none;
  border: none;
  cursor: pointer;
}
.nav-links a:hover, .btn-link:hover { background: var(--border); color: var(--primary-dark); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  transition: 0.2s;
}
.btn-primary { background: var(--primary-dark); color: #fff; }
.btn-primary:hover { background: var(--primary); }
.btn-sm { padding: 6px 12px; font-size: 0.85rem; }
.btn-outline {
  background: transparent;
  border: 1.5px solid var(--primary);
  color: var(--primary-dark);
}
.btn-outline:hover { background: var(--primary-light); }

.menu-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text);
}

/* Sections */
.section { padding: 28px 0; }
.section-title {
  font-size: 1.35rem;
  margin-bottom: 16px;
  color: var(--primary-dark);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Comments on homepage */
.comments-list { display: flex; flex-direction: column; gap: 12px; }
.comment-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  align-items: flex-start;
  display: flex;
  align-items: flex-start; /* prevent avatar stretch into ellipse */
  gap: 12px;
  transition: 0.2s;
}
.comment-card:hover { box-shadow: var(--shadow); border-color: var(--primary-light); }
.comment-avatar {
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  max-width: 40px;
  max-height: 40px;
  border-radius: 50%;
  background: var(--primary-light);
  object-fit: cover;
  object-position: center center;
  flex-shrink: 0;
  aspect-ratio: 1 / 1;
  display: block;
}
.comment-body { flex: 1; min-width: 0; }
.comment-meta { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 4px; }
.comment-meta strong { color: var(--text); }
.comment-content { font-size: 0.95rem; word-break: break-word; }
.comment-novel { font-size: 0.8rem; color: var(--primary-dark); margin-top: 4px; }
.empty-state {
  text-align: center;
  padding: 32px;
  color: var(--text-muted);
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px dashed var(--border);
}

/* Novel cards */
.novel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px;
}
.novel-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  transition: 0.2s;
}
.novel-card:hover { transform: translateY(-4px); box-shadow: var(--shadow); }
.novel-cover {
  aspect-ratio: 2/3;
  object-fit: cover;
  width: 100%;
  background: var(--border);
}
.novel-info { padding: 10px; }
.novel-title {
  font-size: 0.9rem;
  font-weight: 600;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  color: var(--text);
}
.novel-meta { font-size: 0.75rem; color: var(--text-muted); margin-top: 4px; }

.novel-card-large {
  display: flex;
  gap: 16px;
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 16px;
  margin-bottom: 12px;
}
.novel-card-large .novel-cover {
  width: 100px;
  height: 140px;
  border-radius: 8px;
  flex-shrink: 0;
}
.novel-card-large .novel-title { font-size: 1.1rem; -webkit-line-clamp: 2; }

/* Updated list */
.updated-list { display: flex; flex-direction: column; gap: 10px; }
.updated-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  transition: 0.2s;
}
.updated-item:hover { border-color: var(--primary); }
.updated-item img {
  width: 48px; height: 64px; object-fit: cover; border-radius: 6px;
}
.updated-info { flex: 1; min-width: 0; }
.updated-title { font-weight: 600; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.updated-chapter { font-size: 0.8rem; color: var(--primary-dark); }
.updated-time { font-size: 0.75rem; color: var(--text-muted); }

/* Forms */
.form-card {
  max-width: 420px;
  margin: 40px auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
}
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 500; font-size: 0.9rem; }
.form-group input, .form-group textarea, .form-group select {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}
.form-group input:focus, .form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
}
.form-error { color: #ef4444; font-size: 0.85rem; margin-top: 8px; }
.form-success { color: #22c55e; font-size: 0.85rem; margin-top: 8px; }

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 24px;
  flex-wrap: wrap;
}
.pagination button, .pagination a {
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
}
.pagination .active { background: var(--primary-dark); color: #fff; border-color: var(--primary-dark); }

/* Footer */
.footer {
  margin-top: auto;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding: 32px 0 20px;
}
.footer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 24px;
  margin-bottom: 20px;
}
.footer h4 { color: var(--primary-dark); margin-bottom: 10px; }
.footer a { display: block; color: var(--text-muted); margin-bottom: 6px; font-size: 0.9rem; }
.footer a:hover { color: var(--primary); }
.footer-bottom {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* Filters */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 20px;
}
.filters input, .filters select {
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
  color: var(--text);
}

/* Story page */
.story-header {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  margin-bottom: 28px;
}
.story-cover {
  width: 200px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.story-info { flex: 1; min-width: 260px; }
.story-info h1 { font-size: 1.6rem; margin-bottom: 8px; }
.story-meta { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 12px; }
.story-genres { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.tag {
  background: var(--primary-light);
  color: var(--primary-dark);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.8rem;
}
.chapter-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px;
  max-height: 400px;
  overflow-y: auto;
}
.chapter-item {
  padding: 10px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  transition: 0.15s;
}
.chapter-item:hover { border-color: var(--primary); background: var(--primary-light); }

/* Responsive — grid/story only (nav handled in unified header block) */
@media (max-width: 768px) {
  .novel-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
  .story-cover { width: 140px; margin: 0 auto; }
  .story-header { flex-direction: column; align-items: center; text-align: center; }
  .novel-card-large { flex-direction: column; align-items: center; text-align: center; }
  .novel-card-large .novel-cover { width: 120px; height: 160px; }
}

main { flex: 1; }

/* Pinned comments */
.comment-pinned {
  border-left: 3px solid #f59e0b;
  background: linear-gradient(90deg, rgba(245, 158, 11, 0.08), transparent);
}
.pin-label {
  display: inline-block;
  background: #fef3c7;
  color: #b45309;
  font-size: 0.72rem;
  padding: 1px 8px;
  border-radius: 999px;
  margin-left: 6px;
  font-weight: 600;
}

/* Account mobile tabs */
.account-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.account-tab {
  flex: 1;
  min-width: 100px;
  padding: 12px 16px;
  text-align: center;
  background: none;
  border: none;
  color: var(--text-muted);
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
}
.account-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.account-panel { display: none; }
.account-panel.active { display: block; }

/* Reader toolbar styles moved to reader.css (avoid conflict with mobile top bar) */

/* Games page */
.games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}
.game-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  cursor: pointer;
  transition: 0.15s;
}
.game-card:hover { border-color: var(--primary); box-shadow: var(--shadow); }
.quiz-option {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 16px;
  margin: 8px 0;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  font-size: 0.95rem;
}
.quiz-option:hover { border-color: var(--primary); }
.quiz-option.correct { border-color: #22c55e; background: rgba(34,197,94,0.1); }
.quiz-option.wrong { border-color: #ef4444; background: rgba(239,68,68,0.1); }

/* Icon navigation */
.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
  list-style: none;
  margin: 0;
  padding: 0;
}
.nav-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  min-height: 40px;
  padding: 6px 10px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 1.2rem;
  text-decoration: none;
  border-radius: 10px;
  cursor: pointer;
  line-height: 1;
}
.nav-icon-btn:hover,
.nav-icon-btn.active {
  background: var(--primary-light, #ede9fe);
  color: var(--primary, #7c3aed);
}
.nav-avatar-link {
  display: inline-flex;
  align-items: center;
  margin-left: 4px;
}
.nav-avatar {
  width: 32px;
  height: 32px;
  min-width: 32px;
  min-height: 32px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center center;
  border: 2px solid var(--primary, #7c3aed);
  background: var(--primary-light, #ede9fe);
  aspect-ratio: 1 / 1;
  display: block;
}

/* Search overlay */
.search-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 12px;
  padding-top: max(12px, env(safe-area-inset-top));
}
.search-overlay.open { display: flex; }
.search-overlay-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.45);
}
.search-overlay-panel {
  position: relative;
  width: 100%;
  max-width: 520px;
  max-height: min(80vh, 560px);
  background: var(--bg-card, #fff);
  border-radius: 14px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin-top: 48px;
}
.search-overlay-bar {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
}
.search-overlay-bar input {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}
.search-overlay-results {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.search-suggest-item {
  display: flex;
  gap: 12px;
  padding: 10px 14px;
  text-decoration: none;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  align-items: center;
}
.search-suggest-item:hover { background: var(--primary-light, #f5f3ff); }
.search-suggest-item img {
  width: 40px;
  height: 56px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
  background: #eee;
}
.ss-title { font-weight: 600; font-size: 0.95rem; }
.ss-meta { font-size: 0.8rem; color: var(--text-muted); }
.search-overlay-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  text-align: center;
}

/* Novel card — chapter at bottom-left, title multi-line */
.novel-card {
  position: relative;
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: inherit;
  background: var(--bg-card);
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.novel-card .novel-cover {
  width: 100%;
  aspect-ratio: 3/4;
  object-fit: cover;
  display: block;
  background: #e9d5ff;
}
.novel-card .novel-info {
  padding: 10px 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 72px;
}
.novel-card .novel-title {
  font-weight: 700;
  font-size: 0.9rem;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}
.novel-card .novel-meta { font-size: 0.78rem; color: var(--text-muted); }
.novel-card .chapter-link {
  display: inline-block;
  margin-top: 4px;
  font-size: 0.8rem;
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
  padding: 4px 0;
  min-height: 32px;
  line-height: 1.3;
}
.novel-card .chapter-link:hover { text-decoration: underline; }

/* Updated list chapter clickable */
.updated-item .chapter-link {
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
  display: inline-block;
  padding: 2px 0;
  min-height: 28px;
}
.updated-item .chapter-link:hover { text-decoration: underline; }

/* Genre chips in admin */
.genre-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.genre-chip {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
  user-select: none;
}
.genre-chip.selected {
  background: var(--primary, #7c3aed);
  border-color: var(--primary, #7c3aed);
  color: #fff;
}
.genre-chip:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

@media (max-width: 768px) {
  .nav-icon-btn { min-width: 44px; min-height: 44px; font-size: 1.25rem; }
  .novel-card .novel-title { -webkit-line-clamp: 3; font-size: 0.88rem; }
}

/* Novel cards — fixed chapter row alignment, no views beside chapter */
.novel-card {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}
.novel-card .novel-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 4.5rem;
  padding: 8px 10px 10px;
}
.novel-card .novel-title {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.3;
  min-height: 2.6em;
  margin-bottom: 6px;
  font-weight: 600;
  color: inherit;
  text-decoration: none;
}
.card-chapter-row {
  margin-top: auto;
  min-height: 1.4em;
  display: flex;
  align-items: center;
}
.card-chapter {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.8rem;
  color: var(--primary, #7c3aed);
  text-decoration: none;
}
.card-chapter.muted { color: var(--text-muted, #888); }
.updated-item .card-chapter-row { margin-top: 4px; }
.novel-card-cover { display: block; }

/* ===== Mobile-first homepage 2026 ===== */

/* (removed conflicting mobile header grid) */

/* Horizontal story rails (mobile) */
.h-rail-wrap {
  position: relative;
}
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.section-head .section-title {
  margin: 0;
}
.section-head .see-all {
  flex-shrink: 0;
  font-size: 0.85rem;
  color: var(--primary, #7c3aed);
  text-decoration: none;
  font-weight: 600;
  white-space: nowrap;
}

@media (max-width: 768px) {
  .h-rail,
  .novel-grid.h-rail,
  .updated-list.h-rail {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    gap: 12px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
    padding-bottom: 8px;
    margin: 0 -4px;
    padding-left: 4px;
    padding-right: 4px;
    grid-template-columns: none !important;
  }
  .h-rail > .novel-card,
  .h-rail > .updated-item,
  .h-rail > article {
    flex: 0 0 auto;
    width: 132px;
    scroll-snap-align: start;
  }
  .h-rail > .updated-item {
    width: 260px;
    display: flex;
    flex-direction: row;
    gap: 10px;
    align-items: stretch;
  }
  .h-rail > .updated-item img {
    width: 72px;
    height: 96px;
    object-fit: cover;
    border-radius: 8px;
    flex-shrink: 0;
  }
  .h-rail .novel-cover {
    width: 100%;
    height: 176px;
    object-fit: cover;
    border-radius: 10px;
  }
  .h-rail::-webkit-scrollbar { height: 4px; }
  .h-rail::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
  }
  /* prevent page horizontal scroll */
  body { overflow-x: hidden; }
}

@media (min-width: 769px) {
  .h-rail.novel-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 16px;
    overflow: visible;
  }
  .h-rail.updated-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow: visible;
  }
}

/* Comments scroll box */
.comments-scroll {
  max-height: 320px;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-right: 4px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-card, #fff);
}
.comments-scroll .comment-card,
.comments-scroll > a {
  border-left: none;
  border-radius: 0;
  border-bottom: 1px solid var(--border);
}
.comments-scroll .empty-state { padding: 24px 12px; }
@media (max-width: 768px) {
  .comments-scroll { max-height: 240px; }
}

/* ===== Unified header / navigation (single source of truth) ===== */
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-width: 0;
}
.header .logo,
.header .site-logo-link { flex-shrink: 0; }
.header nav {
  margin-left: auto;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex: 1 1 auto;
  min-width: 0;
}
.header .nav-links {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: flex-end;
  gap: 2px;
  list-style: none;
  margin: 0;
  padding: 0;
  position: static;
  width: auto;
  max-width: 100%;
  background: transparent;
  border: none;
  box-shadow: none;
}
.header .menu-toggle {
  display: none; /* icon nav always visible */
}
.header .nav-links > li {
  flex: 0 0 auto;
  width: auto;
  min-width: 0;
  max-width: none;
  text-align: center;
}
.header .nav-links #auth-area {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  width: auto;
}
.nav-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  min-height: 40px;
  padding: 6px 8px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 1.15rem;
  text-decoration: none;
  border-radius: 10px;
  cursor: pointer;
  line-height: 1;
  transition: background 0.15s, color 0.15s;
}
.nav-icon-btn:hover,
.nav-icon-btn:focus-visible,
.nav-icon-btn.active {
  background: var(--primary-light);
  color: var(--primary-dark);
  outline: none;
}
.nav-icon-btn:focus-visible {
  box-shadow: 0 0 0 2px var(--primary);
}
.nav-links .nav-icon-btn::after {
  display: none;
}
.nav-account-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  min-width: 36px;
  min-height: 36px;
  max-width: 36px;
  max-height: 36px;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  overflow: hidden;
  background: var(--primary-light);
  color: var(--primary-dark);
  text-decoration: none;
  border: 1.5px solid var(--border);
  flex-shrink: 0;
  font-size: 1.05rem;
  line-height: 1;
  padding: 0;
  box-sizing: border-box;
}
.nav-account-btn .nav-account-avatar,
.nav-account-avatar {
  width: 100% !important;
  height: 100% !important;
  max-width: 100%;
  max-height: 100%;
  object-fit: cover;
  object-position: center center;
  display: block;
  border-radius: 50%;
  /* prevent global img rules / flex stretch from deforming */
  flex-shrink: 0;
  aspect-ratio: 1 / 1;
}
.nav-account-guest:hover {
  background: var(--primary);
  color: #fff;
}

@media (max-width: 768px) {
  .header .nav-links {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: calc(100vw - 96px);
    scrollbar-width: none;
  }
  .header .nav-links::-webkit-scrollbar { display: none; }
  .header .nav-icon-btn {
    min-width: 44px;
    min-height: 44px;
    font-size: 1.2rem;
  }
  .nav-account-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
  }
  .novel-card .novel-title,
  .h-rail .novel-title,
  .updated-item .updated-title {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    text-overflow: ellipsis;
    word-break: break-word;
    overflow-wrap: anywhere;
    white-space: normal;
    max-width: 100%;
  }
  .novel-card .novel-info,
  .updated-item .updated-info {
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
  }
}

/* Filters — responsive */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 20px;
  align-items: stretch;
}
.filters input,
.filters select {
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
  color: var(--text);
  min-height: 44px;
  font-size: 0.95rem;
}
.filters .btn {
  min-height: 44px;
  align-self: stretch;
}
@media (max-width: 600px) {
  .filters {
    flex-direction: column;
  }
  .filters input,
  .filters select,
  .filters .btn {
    width: 100%;
    min-width: 0;
    flex: none;
  }
}

/* Empty / loading / error states — centered */
.empty-state,
.state-box,
.list-loading,
.list-error,
.list-empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-muted);
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px dashed var(--border);
  max-width: 480px;
  margin: 24px auto;
  width: 100%;
  box-sizing: border-box;
}
.list-error { border-color: #ef4444; color: #ef4444; }
.list-error .btn { margin-top: 12px; }

/* Footer mobile tighten */
@media (max-width: 600px) {
  .footer {
    padding: 20px 0 14px;
  }
  .footer-grid {
    grid-template-columns: 1fr;
    gap: 16px;
    text-align: center;
  }
  .footer-logo img,
  .footer-logo .site-logo {
    width: 120px;
    max-width: 45vw;
    margin: 0 auto;
  }
  .footer a { display: inline-block; margin: 0 8px 6px; }
  .footer h4 { margin-bottom: 6px; }
  .footer-bottom { padding-top: 12px; font-size: 0.75rem; }
}

body { overflow-x: hidden; }

/* ===== Uniform novel cards + h-rail on all screens ===== */
.h-rail-wrap {
  position: relative;
}
.h-rail,
.novel-grid.h-rail,
.updated-list.h-rail {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  gap: 12px;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x mandatory;
  padding-bottom: 10px;
  grid-template-columns: none !important;
  scrollbar-width: thin;
}
.h-rail > .novel-card,
.h-rail > article.novel-card {
  flex: 0 0 auto;
  width: 140px;
  scroll-snap-align: start;
  display: flex;
  flex-direction: column;
  height: auto;
  min-height: 260px;
}
.h-rail .novel-card-cover {
  display: block;
  width: 100%;
  height: 186px;
  overflow: hidden;
  border-radius: 10px;
  background: var(--border);
}
.h-rail .novel-cover {
  width: 100%;
  height: 186px;
  object-fit: cover;
  display: block;
}
.h-rail .novel-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 72px;
  padding: 8px 2px 0;
}
.h-rail .novel-title {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
  height: 2.6em;
  min-height: 2.6em;
  max-height: 2.6em;
  margin: 0 0 6px;
  font-size: 0.88rem;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.h-rail .card-chapter-row {
  margin-top: auto;
  min-height: 1.35em;
  max-height: 1.35em;
  overflow: hidden;
}
.h-rail .card-chapter {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.78rem;
}

/* Updated list cards in rail */
.h-rail > .updated-item {
  flex: 0 0 auto;
  width: 280px;
  scroll-snap-align: start;
  display: flex;
  flex-direction: row;
  gap: 10px;
  align-items: stretch;
  min-height: 100px;
  max-height: 110px;
  overflow: hidden;
  padding: 8px;
  box-sizing: border-box;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.h-rail > .updated-item > a {
  flex-shrink: 0;
}
.h-rail > .updated-item img {
  width: 72px;
  height: 96px;
  object-fit: cover;
  border-radius: 8px;
  display: block;
}
.h-rail > .updated-item .updated-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.h-rail > .updated-item .updated-title {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
  max-height: 2.6em;
  font-weight: 600;
  font-size: 0.9rem;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.h-rail > .updated-item .card-chapter-row {
  margin-top: auto;
}
.h-rail > .updated-item .updated-time {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Rail arrows (desktop) */
.rail-btn {
  display: none;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 5;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
  box-shadow: var(--shadow);
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}
.rail-btn.prev { left: 0; }
.rail-btn.next { right: 0; }
@media (min-width: 769px) {
  .h-rail-wrap .rail-btn { display: inline-flex; }
  .h-rail-wrap { padding: 0 40px; }
}

body { overflow-x: hidden; }



/* Site chat (homepage) */
.site-chat-box { max-width: 720px; }
.site-chat-list { max-height: 280px; margin-bottom: 10px; }
.site-chat-msg { display: flex; gap: 10px; padding: 10px 12px; }
.site-chat-msg .comment-avatar {
  width: 36px;
  height: 36px;
  min-width: 36px;
  min-height: 36px;
  max-width: 36px;
  max-height: 36px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center center;
  flex-shrink: 0;
  aspect-ratio: 1 / 1;
  display: block;
}
.site-chat-form {
  display: flex; gap: 8px; align-items: flex-end;
}
.site-chat-form textarea {
  flex: 1; min-height: 44px; max-height: 120px; resize: vertical;
  padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font: inherit;
}
.site-chat-form .btn { flex-shrink: 0; min-height: 44px; }
.site-chat-hint { font-size: 0.85rem; color: var(--text-muted); margin: 6px 0 0; }
.site-chat-hint a { color: var(--primary); }
@media (max-width: 768px) {
  .site-chat-list { max-height: 220px; }
  .site-chat-form { flex-direction: column; align-items: stretch; }
  .site-chat-form .btn { width: 100%; }
}


/* Mobile h-rail card sizing */
@media (max-width: 400px) {
  .h-rail > .novel-card,
  .h-rail > article.novel-card {
    width: 120px;
    min-height: 230px;
  }
  .h-rail .novel-card-cover,
  .h-rail .novel-cover { height: 156px; }
  .h-rail > .updated-item { width: 240px; }
}


/* ===== Perfect circular avatars (no ellipse stretch) ===== */
.comment-card,
.site-chat-msg {
  align-items: flex-start !important;
}
.avatar-circle {
  display: block !important;
  width: 36px !important;
  height: 36px !important;
  min-width: 36px !important;
  min-height: 36px !important;
  max-width: 36px !important;
  max-height: 36px !important;
  border-radius: 50% !important;
  overflow: hidden !important;
  flex: 0 0 36px !important;
  flex-shrink: 0 !important;
  flex-grow: 0 !important;
  align-self: flex-start !important;
  background: var(--primary-light);
  line-height: 0 !important;
  aspect-ratio: 1 / 1 !important;
  box-sizing: border-box !important;
  position: relative;
}
.avatar-circle img,
.avatar-circle > img {
  position: absolute !important;
  inset: 0 !important;
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  max-height: none !important;
  object-fit: cover !important;
  object-position: center center !important;
  border-radius: 50% !important;
  display: block !important;
}
.site-chat-msg .avatar-circle,
.comment-card .avatar-circle {
  width: 36px !important;
  height: 36px !important;
  min-width: 36px !important;
  min-height: 36px !important;
  max-width: 36px !important;
  max-height: 36px !important;
  flex: 0 0 36px !important;
}
.nav-account-btn.avatar-circle,
a.nav-account-btn {
  width: 36px !important;
  height: 36px !important;
  min-width: 36px !important;
  min-height: 36px !important;
  max-width: 36px !important;
  max-height: 36px !important;
  border-radius: 50% !important;
  overflow: hidden !important;
  padding: 0 !important;
  line-height: 0 !important;
}
.nav-account-btn img,
.nav-account-avatar {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
  object-position: center !important;
  border-radius: 50% !important;
  display: block !important;
}
/* chat action buttons */
.chat-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  flex-wrap: wrap;
}
.chat-actions button {
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  line-height: 1.2;
}
.chat-actions button:hover { border-color: var(--primary); color: var(--primary-dark); }
.chat-actions .btn-pin { color: #b45309; }
.chat-actions .btn-del { color: #ef4444; }
.site-chat-msg.is-pinned {
  border-left: 3px solid #f59e0b;
  background: linear-gradient(90deg, rgba(245, 158, 11, 0.08), transparent);
}
.site-chat-msg .pin-label {
  display: inline-block;
  background: #fef3c7;
  color: #b45309;
  font-size: 0.72rem;
  padding: 1px 8px;
  border-radius: 999px;
  margin-left: 6px;
  font-weight: 600;
}
[data-theme="dark"] .site-chat-msg .pin-label {
  background: #3b2f1a;
  color: #fbbf24;
}


/* Site ad slots */
.ad-banner,
.ad-site-top,
.ad-site-bottom {
  width: 100%;
  max-width: 1200px;
  margin: 12px auto;
  padding: 0 16px;
  text-align: center;
  box-sizing: border-box;
  min-height: 0;
  overflow: visible;
}
.ad-banner img,
.ad-site-top img,
.ad-site-bottom img {
  max-width: 100%;
  height: auto;
  margin: 0 auto;
  display: inline-block;
  border-radius: 8px;
}
.ad-banner:empty,
.ad-site-top:empty,
.ad-site-bottom:empty {
  display: none;
}





/* Ad slots (page banners only) */
.ad-banner,
.ad-slot {
  width: 100%;
  max-width: 1200px;
  margin: 12px auto;
  padding: 0 16px;
  text-align: center;
  box-sizing: border-box;
  overflow: hidden;
}
.ad-banner:not(.ad-banner-has-content),
.ad-slot:empty {
  display: none !important;
  margin: 0;
  padding: 0;
  min-height: 0;
}
.ad-banner img,
.ad-slot img {
  max-width: 100%;
  height: auto;
  display: inline-block;
  border-radius: 8px;
  vertical-align: middle;
}
.ad-slot-middle { margin: 20px auto; }
@media (max-width: 640px) {
  .ad-banner, .ad-slot { padding: 0 12px; margin: 10px auto; }
}
