/* khongdich.com — Mobile First, reader-first styling */
:root {
  --bg: #fafaf8;
  --fg: #1a1a1a;
  --muted: #6b6b6b;
  --line: #e6e6e0;
  --accent: #E11D48;
  --accent-hover: #BE123C;
  --accent-light: rgba(225, 29, 72, 0.08);
  --card-bg: #fff;
  --radius: 8px;
  --radius-lg: 12px;
  --container: 1200px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-serif: 'Times New Roman', Cambria, serif;
  --font-mono: 'JetBrains Mono', Consolas, monospace;
  --header-h: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --destructive: #b91c1c;
  --danger: #dc2626;
  --border: var(--line);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.12);
  --transition: .2s ease;
}

/* ─── Reset & Base ─── */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--fg);
  background: var(--bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}
body.theme-dark {
  --bg: #121212;
  --fg: #e8e8e8;
  --muted: #999;
  --line: #2a2a2a;
  --card-bg: #1e1e1e;
  --destructive: #ef4444;
  --danger: #f87171;
  --accent-light: rgba(225, 29, 72, 0.15);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.2);
  --shadow-md: 0 4px 12px rgba(0,0,0,.25);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.35);
}
body.focus-mode .site-header,
body.focus-mode .site-footer,
body.focus-mode .reader-section,
body.focus-mode .author-note,
body.focus-mode .reader-settings { display: none; }

/* Focus mode: minimal floating toolbar */
body.focus-mode .reader-toolbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 90;
  background: transparent;
  padding: .5rem 1rem;
  max-width: 100%;
  opacity: 0;
  transition: opacity .3s ease;
}
body.focus-mode .reader-toolbar:hover { opacity: 1; background: color-mix(in srgb, var(--bg) 90%, transparent); }
body.focus-mode .reader-toolbar .back-link { display: none; }
body.focus-mode .reader-toolbar .toolbar-actions { margin-left: auto; }

a { color: var(--accent); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--accent-hover); }
img { max-width: 100%; height: auto; display: block; }
button { font-family: inherit; }
input, textarea, select { font-family: inherit; font-size: 1rem; }

/* ─── Container ─── */
.container {
  max-width: var(--container);
  margin: 0 auto;
  padding: 0 1rem;
}

/* ─── Header & Navigation ─── */
.site-header {
  background: var(--card-bg);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--header-h);
}
.nav {
  display: flex;
  align-items: center;
  height: var(--header-h);
  gap: 0;
  padding: 0 1rem;
}
.nav .brand { margin-right: 1.5rem; }
.brand {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-weight: 700;
  color: var(--fg);
  flex-shrink: 0;
}
.brand:hover { text-decoration: none; color: var(--fg); }
.brand-text {
  font-size: 1.1rem;
  letter-spacing: -.01em;
  white-space: nowrap;
}
.logo {
  display: inline-flex;
  width: 36px; height: 36px;
  align-items: center; justify-content: center;
  border-radius: 6px;
  object-fit: contain;
}
.logo.big { width: 64px; height: 64px; }

/* Mobile: hamburger button */
.hamburger {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px; height: 40px;
  background: none;
  border: 0;
  cursor: pointer;
  color: var(--fg);
  font-size: 1.5rem;
  margin-left: auto;
  padding: 0;
  border-radius: var(--radius);
  transition: background var(--transition);
}
.hamburger:hover { background: var(--accent-light); }

/* Mobile menu overlay */
.mobile-menu {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 60;
  opacity: 0;
  visibility: hidden;
  transition: opacity .3s, visibility .3s;
}
.mobile-menu.open { opacity: 1; visibility: visible; }
.mobile-menu-panel {
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: min(300px, 85vw);
  background: var(--card-bg);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: .25rem;
  transform: translateX(100%);
  transition: transform .3s ease;
  overflow-y: auto;
}
.mobile-menu.open .mobile-menu-panel { transform: translateX(0); }
.mobile-menu-close {
  align-self: flex-end;
  width: 36px; height: 36px;
  background: none;
  border: 0;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--fg);
  border-radius: var(--radius);
  margin-bottom: 1rem;
}
.mobile-menu-panel a,
.mobile-menu-panel button {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .85rem 1rem;
  color: var(--fg);
  border-radius: var(--radius);
  font-size: 1rem;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  cursor: pointer;
  transition: background var(--transition);
}
.mobile-menu-panel a:hover,
.mobile-menu-panel button:hover {
  background: var(--accent-light);
  text-decoration: none;
}
.mobile-menu-divider {
  height: 1px;
  background: var(--line);
  margin: .5rem 0;
}

/* Desktop: inline nav links */
.nav-links { display: none; gap: .15rem; flex: 1; align-items: center; }
.nav-links > a {
  color: var(--fg);
  padding: .5rem .65rem;
  border-radius: var(--radius);
  font-size: .9rem;
  transition: background var(--transition);
}
.nav-links > a:hover { background: var(--accent-light); text-decoration: none; }

/* ─── Nav Search (desktop only) ─── */
.nav-search {
  position: relative;
  display: none; /* shown on desktop via media query */
}
.nav-search-form {
  display: flex;
  align-items: center;
  position: relative;
}
.nav-search-icon {
  position: absolute;
  left: .6rem;
  color: var(--muted);
  pointer-events: none;
}
.nav-search-input {
  width: 180px;
  padding: .4rem .6rem .4rem 2rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  color: var(--fg);
  font-size: .85rem;
  transition: width var(--transition), border-color var(--transition), background var(--transition);
}
.nav-search-input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--card-bg);
  width: 240px;
}
.nav-search-input::placeholder { color: var(--muted); }
.nav-search-suggest {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 340px;
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 70;
  padding: .35rem;
  overflow: hidden;
}
.nav-search-item {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .5rem .6rem;
  color: var(--fg);
  border-radius: var(--radius);
  font-size: .85rem;
  text-decoration: none;
  transition: background var(--transition);
}
.nav-search-item:hover { background: var(--accent-light); text-decoration: none; }
.nav-search-cover {
  width: 32px; height: 42px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
  background: var(--line);
}
.nav-search-cover-placeholder {
  width: 32px; height: 42px;
  border-radius: 4px;
  flex-shrink: 0;
  background: var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .5rem;
  font-weight: 700;
  color: var(--muted);
  text-align: center;
  word-break: break-word;
  line-height: 1.1;
  overflow: hidden;
  padding: 2px;
}
.nav-search-info { min-width: 0; flex: 1; }
.nav-search-item-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.nav-search-item-meta { font-size: .78rem; color: var(--muted); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-search-empty { padding: .75rem; color: var(--muted); font-size: .85rem; text-align: center; }
.nav-search-all { border-bottom: 1px solid var(--line); }
.nav-search-all .nav-search-item-title { color: var(--accent); }

/* ─── Nav Dropdown (desktop) ─── */
.nav-dropdown { position: relative; }
.nav-dropdown-trigger {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  color: var(--fg);
  padding: .5rem .65rem;
  border-radius: var(--radius);
  font-size: .9rem;
  text-decoration: none;
  transition: background var(--transition);
}
.nav-dropdown-trigger:hover { background: var(--accent-light); }
.nav-chevron {
  transition: transform var(--transition);
  flex-shrink: 0;
}
.nav-dropdown:hover .nav-chevron { transform: rotate(180deg); }

.nav-dropdown-panel {
  position: absolute;
  top: 100%;
  left: 0;
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  min-width: 220px;
  padding: .4rem;
  box-shadow: var(--shadow-lg);
  z-index: 70;
  margin-top: -4px;
  padding-top: 8px;
}
.nav-dropdown-panel::before {
  content: '';
  position: absolute;
  top: -8px;
  left: 0;
  right: 0;
  height: 8px;
}
.nav-dropdown-panel.cat-dropdown {
  min-width: 240px;
  max-height: 480px;
  overflow-y: auto;
  scrollbar-width: thin;
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
}
/* "Tất cả thể loại" link spans full width */
.nav-dropdown-panel.cat-dropdown > a:first-child {
  grid-column: 1 / -1;
}
.nav-dropdown-panel a {
  display: block;
  padding: .55rem .75rem;
  color: var(--fg);
  border-radius: var(--radius);
  font-size: .85rem;
  text-decoration: none;
  transition: background var(--transition);
  white-space: nowrap;
}
.nav-dropdown-panel a:hover {
  background: var(--accent-light);
  text-decoration: none;
}

/* Dropdown animation */
.dd-enter { animation: ddIn .15s ease-out; }
.dd-leave { animation: ddOut .12s ease-in forwards; }
@keyframes ddIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes ddOut { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-6px); } }

/* ─── Mobile Accordion ─── */
.mobile-accordion { display: flex; flex-direction: column; }
.mobile-accordion-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .85rem 1rem;
  color: var(--fg);
  font-size: 1rem;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  cursor: pointer;
  border-radius: var(--radius);
  transition: background var(--transition);
}
.mobile-accordion-btn:hover { background: var(--accent-light); }
.mobile-chevron {
  transition: transform var(--transition);
  flex-shrink: 0;
}
.mobile-chevron.rotated { transform: rotate(180deg); }
.mobile-accordion-body {
  display: flex;
  flex-direction: column;
  padding-left: 1rem;
}
.mobile-accordion-body a {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .65rem 1rem;
  color: var(--fg);
  border-radius: var(--radius);
  font-size: .9rem;
  text-decoration: none;
  transition: background var(--transition);
}
.mobile-accordion-body a:hover {
  background: var(--accent-light);
  text-decoration: none;
}

.nav-user { display: none; gap: .25rem; align-items: center; }

/* ─── Buttons ─── */
.btn-text {
  color: var(--fg);
  padding: .5rem .75rem;
  background: none;
  border: 0;
  cursor: pointer;
  border-radius: var(--radius);
  transition: background var(--transition);
  font-size: .9rem;
}
.btn-text:hover { background: var(--accent-light); }
.follow-btn.following { color: var(--accent); font-weight: 600; }
.follow-btn.following:hover { color: var(--danger, #dc2626); }
.btn-primary {
  background: var(--accent);
  color: #fff;
  padding: .6rem 1.2rem;
  border-radius: var(--radius);
  border: 0;
  cursor: pointer;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  font-size: .9rem;
  transition: background var(--transition), transform var(--transition);
}
.btn-primary:hover { background: var(--accent-hover); color: #fff; text-decoration: none; }
.btn-primary:active { transform: scale(.97); }
.btn-secondary {
  background: var(--card-bg);
  color: var(--fg);
  padding: .6rem 1.2rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  cursor: pointer;
  font-size: .9rem;
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  transition: background var(--transition), border-color var(--transition);
}
.btn-secondary:hover { border-color: var(--muted); }
.btn-danger {
  background: var(--danger);
  color: #fff;
  padding: .6rem 1.2rem;
  border-radius: var(--radius);
  border: 0;
  cursor: pointer;
  font-weight: 600;
  font-size: .9rem;
  transition: background var(--transition), filter var(--transition);
}
.btn-danger:hover { filter: brightness(0.88); }
.btn-link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; }
.btn-sm { padding: .35rem .6rem; font-size: .8rem; }
.btn-icon {
  width: 40px; height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 0;
  cursor: pointer;
  border-radius: 50%;
  color: var(--fg);
  font-size: 1.2rem;
  transition: background var(--transition);
}
.btn-icon:hover { background: var(--accent-light); }
@media (max-width: 768px) {
  .btn-icon { min-width: 44px; min-height: 44px; }
}

/* ─── Notification Bell ─── */
.btn-icon.noti-btn { position: relative; }
.noti-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
}
.noti-btn:hover { background: var(--accent-light); }
.noti-badge {
  position: absolute;
  top: 2px; right: 2px;
  min-width: 18px; height: 18px;
  padding: 0 5px;
  border-radius: 99px;
  font-size: .65rem;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  background: var(--accent);
  color: #fff;
  pointer-events: none;
}

/* Mobile notification badge — inline next to bell icon */
.mobile-noti-link { position: relative; }
.noti-badge-mobile {
  display: inline-block;
  min-width: 18px; height: 18px;
  padding: 0 5px;
  border-radius: 99px;
  font-size: .65rem;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  background: var(--accent);
  color: #fff;
  vertical-align: middle;
  margin-left: .35rem;
}

/* ─── User Menu (desktop) ─── */
.user-menu { position: relative; }
.user-menu summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  padding: 2px;
  border-radius: 50%;
  transition: box-shadow var(--transition);
}
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu[open] summary { box-shadow: 0 0 0 2px var(--accent); }
.user-menu-panel {
  position: absolute;
  right: 0; top: calc(100% + 8px);
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  min-width: 200px;
  padding: .5rem;
  display: flex;
  flex-direction: column;
  gap: .15rem;
  box-shadow: var(--shadow-lg);
}
.user-menu-panel a, .user-menu-panel form {
  padding: .65rem .85rem;
  display: block;
  border-radius: var(--radius);
  transition: background var(--transition);
}
.user-menu-panel a:hover, .user-menu-panel form:hover {
  background: var(--accent-light);
  text-decoration: none;
}
.user-menu-panel button {
  background: none;
  border: 0;
  color: var(--fg);
  cursor: pointer;
  font-size: inherit;
  text-align: left;
  width: 100%;
  padding: 0;
}
.user-menu-panel button:hover {
  color: var(--fg);
}

/* ─── Avatar ─── */
.avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; }
.avatar-lg { width: 80px; height: 80px; border-radius: 50%; object-fit: cover; }
.avatar-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--line);
  color: var(--fg);
  font-weight: 700;
  border-radius: 50%;
}

/* ─── Footer ─── */
.site-footer {
  margin-top: 2rem;
  padding: 1.5rem 0;
  padding-bottom: calc(1.5rem + var(--safe-bottom));
  border-top: 1px solid var(--line);
  color: var(--muted);
  text-align: center;
  font-size: .85rem;
}
.site-footer a { color: var(--muted); }
.site-footer a:hover { color: var(--accent); }
.tagline { font-style: italic; }

/* ─── Home ─── */
.home-section { margin: 0; }
.section-title {
  font-size: 1.1rem;
  margin-bottom: .65rem;
  display: flex;
  align-items: center;
  gap: .5rem;
  font-weight: 600;
}
/* ─── Scrollable Row with Arrows ─── */
.scroll-container {
  position: relative;
}
.scroll-arrow {
  position: absolute;
  top: 0;
  bottom: .75rem; /* match continue-row padding-bottom */
  width: 40px;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--card-bg);
  border: 1px solid var(--line);
  color: var(--fg);
  cursor: pointer;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transition: background var(--transition), opacity .25s ease;
}
.scroll-arrow-visible {
  opacity: 1;
  pointer-events: auto;
}
.scroll-arrow:hover { background: var(--accent-light); }
.scroll-left { left: 0; border-radius: 0 var(--radius) var(--radius) 0; }
.scroll-right { right: 0; border-radius: var(--radius) 0 0 var(--radius); }

.continue-row {
  display: flex;
  gap: .85rem;
  overflow-x: auto;
  padding: 0 0 .75rem;
  scroll-snap-type: x mandatory;
  scroll-padding-left: 0;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  scroll-behavior: smooth;
}
.continue-row::-webkit-scrollbar { display: none; }
.continue-card {
  flex: 0 0 150px;
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  color: var(--fg);
  scroll-snap-align: start;
  transition: box-shadow var(--transition), transform var(--transition);
}
.continue-card:hover {
  text-decoration: none;
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.continue-card .cover {
  aspect-ratio: 3/4;
  background: var(--line);
  position: relative;
}
.continue-card .cover img { width: 100%; height: 100%; object-fit: cover; }
.continue-info { padding: .65rem; }
.continue-info h3 { margin: 0 0 .15rem; font-size: .85rem; line-height: 1.3; }
.continue-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .25rem;
  margin: 0;
  color: var(--muted);
  font-size: .75rem;
}
.continue-ch-label { white-space: nowrap; flex-shrink: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
/* On small screens, ensure chapter label drops to its own line below the content-type badge */
@media (max-width: 639px) {
  .continue-ch-label { flex-basis: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}

/* ─── Story Cards ─── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: .6rem;
  margin-bottom: .6rem;
}
.story-card {
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  color: var(--fg);
  display: block;
  transition: box-shadow var(--transition), transform var(--transition);
}
.story-card:hover {
  text-decoration: none;
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.story-card .cover {
  aspect-ratio: 3/4;
  background: var(--line);
  position: relative;
}
.story-card .cover img { width: 100%; height: 100%; object-fit: cover; }
.cover-fallback {
  width: 100%; height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 700;
  color: var(--muted);
  background: var(--line);
  padding: .3rem;
  text-align: center;
  word-break: break-word;
  overflow: hidden;
  line-height: 1.2;
}
.story-card-info { padding: .65rem; }
.story-title { margin: 0 0 .2rem; font-size: .9rem; line-height: 1.3; font-weight: 600; }
.story-author { margin: 0 0 .2rem; font-size: .8rem; color: var(--muted); }
.story-meta { margin: 0; font-size: .75rem; color: var(--muted); display: flex; gap: .35rem; flex-wrap: wrap; align-items: center; }
.story-rating { display: inline-flex; align-items: center; gap: .15rem; font-size: .72rem; color: var(--muted); }
.story-rating svg { vertical-align: middle; }

/* ─── Content Type Badge (on cover) ─── */
.ct-badge {
  position: absolute;
  top: .35rem; left: .35rem;
  padding: .15rem .45rem;
  border-radius: 4px;
  font-size: .65rem;
  font-weight: 700;
  line-height: 1.3;
  color: #fff;
  z-index: 2;
  pointer-events: none;
  text-shadow: 0 1px 2px rgba(0,0,0,.3);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  white-space: nowrap;
  letter-spacing: .01em;
}
.ct-badge-text   { background: rgba(37,99,235,.78); }
.ct-badge-manga  { background: rgba(147,51,234,.78); }
.ct-badge-video  { background: rgba(234,88,12,.78); }
.ct-badge-chat   { background: rgba(22,163,74,.78); }

/* Inline content type badge (for detail, ranking, etc.) */
.ct-badge-inline {
  display: inline-flex;
  align-items: center;
  gap: .2rem;
  padding: .2rem .55rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
  color: #fff;
}
.ct-badge-inline.ct-text   { background: #2563eb; }
.ct-badge-inline.ct-manga  { background: #9333ea; }
.ct-badge-inline.ct-video  { background: #ea580c; }
.ct-badge-inline.ct-chat   { background: #16a34a; }

/* ─── Two Column Layout (legacy, kept for other pages) ─── */
.two-col { display: grid; grid-template-columns: 1fr; gap: 1.5rem; }

/* ─── Hot Rank Badge (on card cover) ─── */
.hot-rank {
  position: absolute;
  top: .35rem; right: .35rem;
  min-width: 22px; height: 22px;
  padding: 0 5px;
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 800;
  line-height: 22px;
  text-align: center;
  color: #fff;
  z-index: 2;
  pointer-events: none;
  background: rgba(225, 29, 72, .85);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.hot-rank:first-child { background: linear-gradient(135deg, #f59e0b, #d97706); }
.hot-rank:nth-child(2) { background: linear-gradient(135deg, #9ca3af, #6b7280); }

/* ─── Hot/Fresh card overrides ─── */
.hot-card .cover .hot-rank { top: .35rem; right: .35rem; }

.link-more { display: inline-block; margin-top: .75rem; font-size: .9rem; }

/* ─── New chapters ─── */
.new-chapters-list { list-style: none; padding: 0; margin: 0; }
.new-chapters-list li { padding: .65rem 0; border-bottom: 1px solid var(--line); }
.new-chapters-list a { color: var(--fg); display: flex; flex-wrap: wrap; gap: .5rem; }
.ch-story { font-weight: 600; }
.ch-num { color: var(--accent); }

/* ─── Story Detail ─── */
.story-detail-head {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 1rem;
  margin: 1rem 0;
}
.cover-lg {
  aspect-ratio: 3/4;
  background: var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: relative;
}
.cover-lg img { width: 100%; height: 100%; object-fit: cover; }
.story-detail-info h1 { margin: 0 0 .4rem; font-size: 1.4rem; line-height: 1.3; }
.author { margin: 0 0 .75rem; font-size: .9rem; }
.badges { display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: .75rem; }
.badge {
  background: var(--line);
  color: var(--fg);
  padding: .2rem .55rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 500;
  text-decoration: none;
  transition: background var(--transition), color var(--transition);
}
.badge[href]:hover { background: var(--accent-light); color: var(--accent); }
.badge-ok { background: #dcfce7; color: #166534; }
.badge-tag { background: var(--accent-light); color: var(--accent); }
.badge-warn { background: #fef3c7; color: #92400e; }
.stats { display: flex; flex-wrap: wrap; gap: .75rem; color: var(--muted); margin-bottom: .75rem; font-size: .85rem; }
.synopsis { font-size: .9rem; line-height: 1.7; }
.synopsis p { margin: 0 0 .8em; }
.synopsis p:last-child { margin-bottom: 0; }
.story-actions { display: flex; gap: .5rem; margin-top: 1rem; flex-wrap: wrap; }
.story-section { margin: 1.5rem 0; }

/* Chapter list */
.chapter-list-wrap { display: flex; flex-direction: column; }
.chapter-item {
  display: flex;
  align-items: baseline;
  gap: .75rem;
  padding: .7rem .5rem;
  color: var(--fg);
  border-bottom: 1px solid var(--line);
  transition: background var(--transition);
  border-radius: var(--radius);
  font-size: .9rem;
}
.chapter-item:hover { background: var(--accent-light); text-decoration: none; }
.chapter-num { color: var(--muted); font-size: .8rem; flex-shrink: 0; min-width: 45px; }
.chapter-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chapter-views {
  color: var(--muted);
  font-size: .78rem;
  flex-shrink: 0;
  white-space: nowrap;
}

/* Volume header in chapter list — thin divider with inline label */
.volume-header {
  grid-column: 1 / -1;
  width: 100%;
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: 0;
  margin-top: .75rem;
  font-weight: 600;
  font-size: .78rem;
  color: var(--accent);
  white-space: nowrap;
  letter-spacing: .01em;
}
.volume-header::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--line);
  min-width: 1rem;
}
.volume-header:first-child { margin-top: 0; }

/* Chapter list toolbar */
.ch-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .5rem;
  gap: .5rem;
  flex-wrap: wrap;
}
.ch-toolbar-left { display: flex; align-items: center; gap: .5rem; }
.ch-toolbar-right { display: flex; align-items: center; gap: .5rem; }
.ch-sort-btn {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  padding: .3rem .65rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--card-bg);
  color: var(--fg);
  font-size: .8rem;
  cursor: pointer;
  transition: var(--transition);
}
.ch-sort-btn:hover { border-color: var(--accent); color: var(--accent); }
.ch-sort-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Chapter pagination */
.ch-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}
.ch-page-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px; height: 36px;
  padding: 0 .5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card-bg);
  color: var(--fg);
  font-size: .85rem;
  cursor: pointer;
  text-decoration: none;
  transition: var(--transition);
}
.ch-page-btn:hover { border-color: var(--accent); color: var(--accent); }
.ch-page-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.ch-page-btn.disabled { opacity: .4; pointer-events: none; }

.chapter-list-grid {
  display: flex;
  flex-direction: column;
}
.chapter-meta {
  font-size: .75rem;
  flex-shrink: 0;
  white-space: nowrap;
}
.chapter-meta.ch-meta-line {
  margin-left: 50px; /* align with title after Ch.N */
  order: 10;
}
.chapter-item-wrap { flex-wrap: wrap; }
.chapter-item-wrap .ch-meta-line { flex: 1 1 100%; margin-left: 50px; }
.chapter-item-actions {
  display: flex;
  gap: .35rem;
  flex-shrink: 0;
  margin-left: .5rem;
}
.chapter-item-actions button {
  font-size: .7rem;
  padding: .15rem .45rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--card-bg);
  color: var(--fg);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), border-color var(--transition);
}
.chapter-item-actions button:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.chapter-item-actions button.btn-publish-draft {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.chapter-item-actions button.btn-publish-draft:hover {
  background: var(--accent-hover);
}
.chapter-item-actions button.btn-delete-draft {
  border-color: var(--danger, #dc2626);
  color: var(--danger, #dc2626);
}
.chapter-item-actions button.btn-delete-draft:hover {
  background: var(--danger, #dc2626);
  color: #fff;
}
.ch-bulk-bar {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .5rem .75rem;
  background: var(--accent-light);
  border-radius: var(--radius);
  margin-bottom: .5rem;
  font-size: .85rem;
}
.ch-bulk-bar label {
  display: flex;
  align-items: center;
  gap: .35rem;
  cursor: pointer;
}
.ch-ellipsis {
  padding: 0 .35rem;
  color: var(--muted);
  font-size: .85rem;
}
.ch-jump {
  display: flex;
  align-items: center;
  gap: .35rem;
  margin-left: .5rem;
}
.ch-jump input[type="number"] {
  width: 60px;
  padding: .3rem .5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: .85rem;
  background: var(--card-bg);
  color: var(--fg);
  -moz-appearance: textfield;
}
.ch-jump input[type="number"]::-webkit-inner-spin-button,
.ch-jump input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Legacy chapter-list (used in partials) */
.chapter-list { list-style: none; padding: 0; margin: 0; }
.chapter-list li { padding: 0; border-bottom: 1px solid var(--line); }
.chapter-list a {
  display: flex;
  gap: .75rem;
  padding: .7rem .5rem;
  color: var(--fg);
  transition: background var(--transition);
  border-radius: var(--radius);
  font-size: .9rem;
}
.chapter-list a:hover { background: var(--accent-light); text-decoration: none; }
.chapter-list .num { color: var(--muted); min-width: 45px; font-size: .8rem; flex-shrink: 0; }
.chapter-list .title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ─── Reader ─── */
.reader { min-height: 100vh; }
.reader.theme-dark { background: #1a1a1a; color: #e8e8e8; }
.reader.theme-sepia { background: #f4ecd8; color: #5c4e3c; }
.reader.theme-night { background: #0d1117; color: #c9d1d9; }
.reader.font-serif .ch-body { font-family: var(--font-serif); }
.reader.font-sans .ch-body { font-family: var(--font-sans); }
.reader.font-mono .ch-body { font-family: var(--font-mono); }

.progress-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: transparent;
  z-index: 100;
}
.progress-fill { height: 100%; background: var(--accent); width: 0; transition: width .1s; }

.reader-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .75rem 1rem;
  max-width: var(--container);
  margin: 0 auto;
  gap: .5rem;
}
.back-link { color: inherit; font-size: .9rem; }
.toolbar-actions { display: flex; gap: .25rem; }
.toolbar-actions button {
  background: none;
  border: 0;
  font-size: 1.1rem;
  cursor: pointer;
  padding: .4rem;
  color: inherit;
  border-radius: var(--radius);
  transition: background var(--transition);
}
.toolbar-actions button:hover { background: var(--accent-light); }

.reader-content {
  max-width: var(--reader-width);
  margin: 0 auto;
  padding: .5rem 1rem 2rem;
}
.ch-head h1 { margin: 0 0 .4rem; font-size: 1.3rem; line-height: 1.35; }
.ch-volume-label { color: var(--accent); font-size: .85rem; font-weight: 600; margin: 0 0 .25rem; }
.ch-meta { color: var(--muted); font-size: .85rem; }
.ch-body {
  font-size: var(--reader-font-size);
  line-height: var(--reader-line);
  margin: 1.5rem 0;
}
.ch-body p { margin: 0 0 .8em; }
.ch-body hr { border: 0; text-align: center; margin: 2em 0; }
.ch-body hr::before { content: '\2726 \2726 \2726'; color: var(--muted); letter-spacing: .5em; }
.author-note {
  background: var(--card-bg);
  border-left: 3px solid var(--accent);
  padding: 1rem 1.25rem;
  margin: 2rem 0;
  border-radius: 0 var(--radius) var(--radius) 0;
}
.author-note h3 { margin: 0 0 .5rem; font-size: .95rem; }
.ch-nav {
  display: flex;
  justify-content: space-between;
  gap: .75rem;
  margin: 2rem 0;
}
.ch-nav a {
  background: var(--card-bg);
  padding: .65rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  color: var(--fg);
  font-size: .9rem;
  transition: border-color var(--transition), background var(--transition);
}
.ch-nav a:hover { border-color: var(--accent); background: var(--accent-light); text-decoration: none; }
.reader-section { margin: 1.75rem 0; }
/* Similar stories: horizontal scroll row instead of cramped grid columns */
.similar-scroll {
  display: flex;
  gap: .75rem;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  padding-bottom: .5rem;
  scrollbar-width: thin;
}
.similar-scroll::-webkit-scrollbar { height: 4px; }
.similar-scroll::-webkit-scrollbar-thumb {
  background: var(--line); border-radius: 2px;
}
.similar-scroll .story-card {
  flex: 0 0 130px;
  scroll-snap-align: start;
}
@media (min-width: 640px) {
  .similar-scroll .story-card { flex: 0 0 150px; }
}
@media (min-width: 768px) {
  .similar-scroll .story-card { flex: 0 0 170px; }
}

/* Reader Settings - mobile: bottom sheet, desktop: side panel */
.reader-settings {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--card-bg);
  padding: 1.25rem;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  border: 1px solid var(--line);
  border-bottom: none;
  z-index: 55;
  display: flex;
  flex-direction: column;
  gap: .85rem;
  box-shadow: 0 -4px 24px rgba(0,0,0,.12);
  color: var(--fg);
  max-height: 70vh;
  overflow-y: auto;
  padding-bottom: calc(1.25rem + var(--safe-bottom));
}
.reader-settings h3 { margin: 0; font-size: 1rem; }
.reader-settings label {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  font-size: .85rem;
}
.reader-settings select {
  padding: .5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card-bg);
  color: var(--fg);
}
.reader-settings input[type="range"] { width: 100%; }
.theme-row { display: flex; gap: .35rem; }
.theme-row button {
  flex: 1;
  padding: .5rem;
  border: 1px solid var(--line);
  background: transparent;
  border-radius: var(--radius);
  cursor: pointer;
  color: inherit;
  font-size: .85rem;
  transition: background var(--transition), border-color var(--transition);
}
.theme-row button:hover { border-color: var(--accent); }
.reader-settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 54;
}
[x-cloak] { display: none !important; }

/* ─── Đăng truyện Editor ─── */
.kd-editor { max-width: 900px; padding-bottom: 5rem; }
.editor-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: .75rem 0;
  gap: .75rem;
  flex-wrap: wrap;
}
.editor-status { display: flex; gap: .75rem; align-items: center; color: var(--muted); font-size: .85rem; flex-wrap: wrap; }
.ch-title-input {
  width: 100%;
  padding: .85rem;
  font-size: 1.2rem;
  font-family: var(--font-serif);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card-bg);
  color: var(--fg);
  margin-bottom: .75rem;
  transition: border-color var(--transition);
}
.ch-title-input:focus { border-color: var(--accent); outline: none; }

/* Chapter number badge & title warning */
.ch-title-group { margin-bottom: .75rem; }
.ch-number-label {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: .5rem;
  flex-wrap: wrap;
}
.ch-number-badge {
  display: inline-flex;
  align-items: center;
  background: var(--accent);
  color: #fff;
  padding: .2rem .65rem;
  border-radius: var(--radius);
  font-size: .85rem;
  font-weight: 600;
  letter-spacing: .02em;
}
.ch-number-hint {
  font-size: .8rem;
  color: var(--muted);
}
.ch-title-warning {
  display: flex;
  align-items: flex-start;
  gap: .5rem;
  background: #fef3c7;
  border: 1px solid #f59e0b;
  border-radius: var(--radius);
  padding: .55rem .75rem;
  margin-top: .5rem;
  font-size: .83rem;
  color: #92400e;
  line-height: 1.5;
}
.ch-title-warning strong { color: #78350f; }
.ch-title-warning em { font-style: normal; text-decoration: underline; text-decoration-style: dotted; }
.ch-warning-dismiss {
  background: none;
  border: none;
  color: #92400e;
  cursor: pointer;
  font-size: .9rem;
  padding: 0;
  flex-shrink: 0;
  line-height: 1;
}
.ch-warning-dismiss:hover { color: #78350f; }

.ch-content-input {
  width: 100%;
  min-height: 60vh;
  padding: 1.25rem;
  font-family: var(--font-serif);
  font-size: 16px;
  line-height: 1.8;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card-bg);
  color: var(--fg);
  resize: vertical;
  transition: border-color var(--transition);
}
.ch-content-input:focus { border-color: var(--accent); outline: none; }
.ch-note-input {
  width: 100%;
  padding: .75rem;
  font-family: var(--font-sans);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card-bg);
  color: var(--fg);
  transition: border-color var(--transition);
}
.ch-note-input:focus { border-color: var(--accent); outline: none; }
.editor-actions {
  display: flex;
  gap: .5rem;
  margin-top: .75rem;
  flex-wrap: wrap;
}
.word-count { font-weight: 600; }

/* Schedule panel */
.schedule-panel {
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  margin-top: 1rem;
}
.schedule-panel h3 { margin: 0 0 .75rem; }
.schedule-panel label { display: flex; flex-direction: column; gap: .25rem; margin-bottom: .75rem; }
.schedule-panel input[type="datetime-local"] {
  padding: .5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card-bg);
  color: var(--fg);
}

/* Chapter sidebar */
.chapter-sidebar {
  margin-top: 2rem;
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
}
.chapter-sidebar h3 { margin: 0 0 .75rem; font-size: 1rem; }
.ch-sidebar-list { list-style: none; padding: 0; margin: 0; }
.ch-sidebar-list li {
  border-bottom: 1px solid var(--line);
}
.ch-sidebar-list li:last-child { border-bottom: none; }
.ch-sidebar-list li a {
  display: block;
  padding: .65rem .5rem;
  color: var(--fg);
  font-size: .85rem;
  transition: background var(--transition);
  border-radius: var(--radius);
}
.ch-sidebar-list li a:hover { background: var(--accent-light); text-decoration: none; }
.ch-sidebar-list li.active a { color: var(--accent); font-weight: 600; }
.ch-sidebar-list li.draft a { color: var(--muted); }

/* ─── Login ─── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 200px);
  padding: 2rem 1rem;
}
.login-card {
  background: var(--card-bg);
  padding: 2rem;
  border-radius: var(--radius-lg);
  text-align: center;
  max-width: 380px;
  width: 100%;
  box-shadow: var(--shadow-md);
}
.login-card h1 { margin: 1rem 0 .25rem; font-size: 1.4rem; }
.btn-google {
  display: inline-flex;
  align-items: center;
  gap: .75rem;
  background: #fff;
  color: #333;
  padding: .7rem 1.25rem;
  border: 1px solid #ddd;
  border-radius: var(--radius);
  font-weight: 600;
  margin: 1.25rem 0;
  font-size: .95rem;
  transition: background var(--transition), box-shadow var(--transition);
}
.btn-google:hover { background: #f5f5f5; text-decoration: none; color: #333; box-shadow: var(--shadow-sm); }
.g-icon {
  display: inline-flex;
  width: 24px; height: 24px;
  align-items: center; justify-content: center;
  border-radius: 50%;
  background: linear-gradient(135deg,#4285f4,#34a853);
  color: #fff;
  font-weight: 700;
  font-size: .85rem;
}
.login-help { color: var(--muted); font-size: .85rem; }

/* ─── Comments ─── */
.comment-form { display: flex; flex-direction: column; gap: .5rem; margin: 1rem 0; }
.comment-form textarea {
  padding: .75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card-bg);
  color: var(--fg);
  font: inherit;
  font-size: .9rem;
  resize: vertical;
  min-height: 60px;
}
.comment-form textarea:focus { border-color: var(--accent); outline: none; }
.comment-form button {
  align-self: flex-end;
  padding: .5rem 1rem;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: .85rem;
}
.comment-list, .comment-replies { list-style: none; padding: 0; margin: 1rem 0 0; }
.comment { padding: .85rem 0; border-bottom: 1px solid var(--line); }
.comment-head { display: flex; align-items: center; gap: .5rem; margin-bottom: .4rem; flex-wrap: wrap; }
.comment-user { color: var(--fg); font-weight: 600; font-size: .9rem; }
.comment-body { white-space: pre-line; font-size: .9rem; }
.comment-actions { display: flex; gap: .75rem; margin-top: .35rem; }
.comment-actions button {
  background: none;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  padding: .2rem 0;
  font-size: .85rem;
  transition: color .15s;
}
.comment-actions button:hover { color: var(--accent); }
.comment-actions button.liked { color: #e11d48; }
.comment-replies { padding-left: 1.5rem; }

/* ─── Stats / Đăng truyện ─── */
.kd-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 1rem 0 .75rem;
  gap: .75rem;
}
.kd-head h1 { font-size: 1.2rem; margin: 0; }
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: .75rem;
  margin: 1rem 0;
}
.stat-card {
  background: var(--card-bg);
  padding: 1rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: .15rem;
}
.stat-label { font-size: .8rem; color: var(--muted); }
.stat-value { font-size: 1.3rem; font-weight: 700; }
.kd-section { margin: 1.5rem 0; }

/* Responsive table wrapper */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -1rem; padding: 0 1rem; }
.kd-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.kd-table th, .kd-table td { padding: .65rem .5rem; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.kd-table th { color: var(--muted); font-weight: 500; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
.recent-comments { list-style: none; padding: 0; margin: 0; }
.recent-comments li { padding: .75rem 0; border-bottom: 1px solid var(--line); }
.comment-preview { color: var(--muted); font-size: .85rem; }

/* ─── Forms ─── */
.story-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 720px;
  margin-bottom: 2rem;
}
.story-form label { display: flex; flex-direction: column; gap: .3rem; font-size: .9rem; font-weight: 500; }
.story-form input, .story-form textarea, .story-form select {
  padding: .6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card-bg);
  color: var(--fg);
  font: inherit;
  font-size: .9rem;
  transition: border-color var(--transition);
}
.story-form input:focus, .story-form textarea:focus, .story-form select:focus {
  border-color: var(--accent);
  outline: none;
}
.form-row { display: grid; grid-template-columns: 1fr; gap: .75rem; }
.cat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .5rem; }
.cat-chip {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .5rem;
  border-radius: var(--radius);
  background: var(--card-bg);
  border: 1px solid var(--line);
  cursor: pointer;
  font-size: .85rem;
  transition: border-color var(--transition);
}
.cat-chip:has(input:checked) { border-color: var(--accent); background: var(--accent-light); }
.cat-chip input { margin: 0; }
.form-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.danger-zone { margin-top: 3rem; padding-top: 1rem; border-top: 1px dashed var(--line); }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
legend { font-weight: 600; font-size: .9rem; padding: 0 .5rem; }
.collapsible-legend {
  display: flex;
  align-items: center;
  gap: .5rem;
  cursor: pointer;
  user-select: none;
}
.collapsible-legend:hover { color: var(--accent); }
.collapse-icon {
  font-size: .75rem;
  transition: transform .2s;
}
.collapse-icon.is-open { transform: rotate(90deg); }
.selected-count {
  font-size: .75rem;
  font-weight: 400;
  color: var(--accent);
  background: var(--accent-light);
  padding: .1rem .5rem;
  border-radius: 99px;
}
small { color: var(--muted); font-size: .8rem; }

/* ─── Profile ─── */
.profile-head { display: flex; gap: 1rem; margin: 1rem 0; align-items: center; }
.profile-head h1 { margin: 0; font-size: 1.2rem; }
.profile-stats { display: flex; gap: .75rem; margin-top: .35rem; flex-wrap: wrap; color: var(--muted); font-size: .85rem; }
.streak-badge { background: #fef3c7; color: #92400e; padding: .2rem .55rem; border-radius: 999px; font-weight: 600; font-size: .8rem; }

/* Avatar edit overlay */
.profile-avatar-wrap { position: relative; flex-shrink: 0; }
.profile-avatar-wrap.editable { cursor: pointer; }
.avatar-edit-btn {
  position: absolute; bottom: 2px; right: 2px;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: 2px solid var(--card-bg);
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem;
  cursor: pointer;
  transition: transform var(--transition);
}
.avatar-edit-btn:hover { transform: scale(1.1); }

/* Profile edit panel */
.profile-edit-panel {
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin: 1rem 0;
  box-shadow: var(--shadow-sm);
}
.profile-edit-form {
  display: flex;
  flex-direction: column;
  gap: .85rem;
}
.profile-edit-form label {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  font-size: .9rem;
  font-weight: 500;
}
.profile-edit-form input,
.profile-edit-form textarea {
  padding: .6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card-bg);
  color: var(--fg);
  font: inherit;
  font-size: .9rem;
  transition: border-color var(--transition);
}
.profile-edit-form input:focus,
.profile-edit-form textarea:focus {
  border-color: var(--accent);
  outline: none;
}

/* ─── Cover Image Upload ─── */
.cover-upload-section { margin-bottom: .25rem; }

/* Workspace: upload area + live preview side-by-side on desktop */
.cover-workspace {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
@media (min-width: 768px) {
  .cover-workspace {
    flex-direction: row;
    align-items: flex-start;
  }
}

.cover-upload-area {
  border: 2px dashed var(--line);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  position: relative;
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
}
.cover-upload-area:hover,
.cover-upload-area.drag-over {
  border-color: var(--accent);
  background: var(--accent-light);
}
.cover-upload-area.has-preview {
  border-style: solid;
  border-color: var(--line);
  padding: 1rem;
}

.cover-upload-placeholder {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  align-items: center;
  color: var(--muted);
}
.cover-upload-placeholder p { margin: 0; font-size: .9rem; }
.upload-icon { font-size: 2rem; }
.cover-ratio-hint {
  color: var(--accent);
  font-weight: 600;
  background: var(--accent-light);
  padding: .2rem .6rem;
  border-radius: var(--radius);
  font-size: .78rem !important;
}

.cover-preview-wrap {
  position: relative;
  width: 100%;
  max-width: 200px;
  margin: 0 auto;
}
.cover-preview-img {
  width: 100%;
  aspect-ratio: 3/4;
  object-fit: cover;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.cover-remove-btn {
  position: absolute; top: -8px; right: -8px;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: 0;
  font-size: .75rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-sm);
}
.cover-remove-btn:hover { background: var(--accent-hover); }

/* Live preview: realistic story card mockup */
.cover-live-preview {
  flex-shrink: 0;
  width: 100%;
  max-width: 180px;
}
@media (min-width: 768px) {
  .cover-live-preview {
    max-width: 200px;
  }
}
.cover-preview-label {
  margin: 0 0 .4rem;
  font-size: .78rem;
  color: var(--muted);
  text-align: center;
}
.cover-mock-card {
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.cover-mock-img {
  aspect-ratio: 3/4;
  position: relative;
  background: var(--line);
  overflow: hidden;
}
.cover-mock-img img {
  width: 100%; height: 100%; object-fit: cover;
  display: block;
}
.cover-mock-img .cover-fallback {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  font-size: .85rem; font-weight: 700; color: var(--muted);
  padding: .3rem; text-align: center;
  word-break: break-word; overflow: hidden; line-height: 1.2;
}
/* Title gradient overlay at bottom of cover image */
.cover-mock-title {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: linear-gradient(transparent, rgba(0,0,0,.72));
  color: #fff;
  padding: 2rem .5rem .5rem;
  font-size: .8rem;
  font-weight: 700;
  line-height: 1.25;
  word-break: break-word;
  text-shadow: 0 1px 3px rgba(0,0,0,.4);
}
.cover-mock-info { padding: .5rem; }
.cover-mock-story-title {
  font-size: .78rem; font-weight: 600; line-height: 1.3;
  margin-bottom: .15rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cover-mock-author {
  font-size: .7rem; color: var(--muted); margin-bottom: .1rem;
}
.cover-mock-meta {
  font-size: .65rem; color: var(--muted);
}

/* Upload progress */
.upload-progress {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--card-bg) 85%, transparent);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  font-size: .85rem;
  color: var(--muted);
}
.upload-spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  display: inline-block;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Tabs ─── */
.tabs {
  display: flex;
  gap: 0;
  margin: 1rem 0;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  padding: .6rem .85rem;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  font-size: .9rem;
  transition: color var(--transition), border-color var(--transition);
}
.tabs a:hover { color: var(--fg); text-decoration: none; }
.tabs a.active { border-bottom-color: var(--accent); color: var(--accent); font-weight: 500; }

/* ─── Search ─── */
.search-form { display: flex; gap: .5rem; margin: 1rem 0; }
.search-form input {
  flex: 1;
  padding: .7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 1rem;
  background: var(--card-bg);
  color: var(--fg);
  min-width: 0;
  transition: border-color var(--transition);
}
.search-form input:focus { border-color: var(--accent); outline: none; }
.search-form button {
  padding: .7rem 1.25rem;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 600;
  font-size: .9rem;
  white-space: nowrap;
}

/* ─── Notifications ─── */
.noti-panel { background: var(--card-bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.noti-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .5rem; }
.noti-head-actions { display: flex; gap: .5rem; align-items: center; }
.noti-list { list-style: none; padding: 0; margin: 0; }
.noti-list li { padding: .75rem 0; border-bottom: 1px solid var(--line); }
.noti-list li.unread { font-weight: 600; background: var(--accent-light); border-radius: var(--radius); padding: .75rem .5rem; margin: 0 -.25rem; }
.noti-list li.unread .noti-dot { display: inline-block; }
.noti-dot { display: none; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-right: .4rem; vertical-align: middle; flex-shrink: 0; }
.noti-page-list { list-style: none; padding: 0; margin: 0; }
.noti-item { padding: .85rem .75rem; border-bottom: 1px solid var(--line); border-radius: var(--radius); transition: background var(--transition); }
.noti-item:last-child { border-bottom: none; }
.noti-item.unread { background: var(--accent-light); }
.noti-item.unread .noti-dot { display: inline-block; }
.noti-link { display: flex; align-items: flex-start; color: var(--fg); padding: .25rem 0; gap: .4rem; flex: 1; min-width: 0; }
.noti-link:hover { text-decoration: none; background: var(--accent-light); border-radius: var(--radius); padding: .25rem .5rem; margin: 0 -.5rem; }
.noti-content strong { display: block; margin-bottom: .2rem; }
.noti-content p { margin: .2rem 0; color: var(--muted); font-size: .9rem; }

/* Notification icon */
.noti-icon { font-size: 1.3rem; flex-shrink: 0; margin-right: .1rem; line-height: 1.4; }
.noti-icon-sm { font-size: 1.1rem; flex-shrink: 0; line-height: 1.4; }

/* Notification row layout */
.noti-row { display: flex; align-items: flex-start; gap: .5rem; position: relative; }
.noti-row .noti-link { flex: 1; min-width: 0; }

/* Delete button */
.noti-delete {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 1.1rem; padding: .2rem .4rem; border-radius: var(--radius);
  opacity: 0; transition: all var(--transition); flex-shrink: 0; line-height: 1;
}
.noti-item:hover .noti-delete { opacity: 1; }
.noti-delete:hover { color: var(--accent); background: var(--accent-light); }

/* Notification dropdown */
.noti-dropdown-wrap { position: relative; }
.noti-dropdown {
  display: none; position: absolute; top: calc(100% + .5rem); right: 0;
  width: 380px; max-height: 480px; overflow-y: auto;
  background: var(--card-bg); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.15);
  z-index: 100;
}
.noti-dropdown.open { display: block; }
@media (max-width: 600px) {
  .noti-dropdown { position: fixed; top: auto; bottom: 0; left: 0; right: 0; width: 100%; max-height: 70vh; border-radius: var(--radius) var(--radius) 0 0; }
}

/* ─── Filter Row ─── */
.page-head { margin: 1rem 0 .75rem; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; }
.page-head h1 { margin: 0; font-size: 1.2rem; }
.filter-row { display: flex; gap: .35rem; flex-wrap: wrap; }
.filter-row a {
  padding: .35rem .85rem;
  border-radius: 999px;
  background: var(--card-bg);
  color: var(--fg);
  border: 1px solid var(--line);
  font-size: .85rem;
  transition: all var(--transition);
}
.filter-row a:hover { border-color: var(--accent); text-decoration: none; }
.filter-row a.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ─── Utilities ─── */
.muted { color: var(--muted); }
.error { color: #b91c1c; padding: .6rem .85rem; background: #fef2f2; border-radius: var(--radius); font-size: .9rem; }
.success { color: #166534; padding: .6rem .85rem; background: #f0fdf4; border-radius: var(--radius); font-size: .9rem; }
.icon-link { font-size: 1.2rem; cursor: pointer; }

/* HTMX Indicator */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-block; }
.htmx-request.htmx-indicator { display: inline-block; }

/* ─── Toast ─── */
.toast-container {
  position: fixed;
  bottom: 1rem;
  left: 1rem;
  right: 1rem;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  align-items: center;
  pointer-events: none;
}
.toast {
  background: var(--card-bg);
  color: var(--fg);
  border: 1px solid var(--line);
  padding: .85rem 1.25rem;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  border-left: 4px solid var(--accent);
  max-width: 400px;
  width: 100%;
  font-size: .9rem;
  pointer-events: auto;
}
.toast.success { border-left-color: #22c55e; }
.toast.error { border-left-color: #ef4444; }

/* ─── Global Components ─── */
.nav-item { position: relative; display: flex; align-items: center; }

/* Report modal */
dialog {
  border: 0;
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  max-width: 450px;
  width: calc(100% - 2rem);
  background: var(--card-bg);
  color: var(--fg);
  box-shadow: var(--shadow-lg);
}
dialog::backdrop { background: rgba(0,0,0,.5); }
.close-btn {
  float: right;
  background: none;
  border: 0;
  font-size: 1.3rem;
  cursor: pointer;
  color: var(--muted);
  padding: .25rem;
}
dialog form { display: flex; flex-direction: column; gap: .75rem; }
dialog label { display: flex; flex-direction: column; gap: .25rem; font-size: .9rem; }
dialog input, dialog select, dialog textarea {
  padding: .5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card-bg);
  color: var(--fg);
  font: inherit;
}

/* Review form */
.review-form {
  margin-top: 1rem;
  padding: 1rem;
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.review-form h3 { margin: 0 0 .75rem; }
.star-input { display: flex; gap: .25rem; align-items: center; margin-bottom: .75rem; }
.star-input button {
  background: none;
  border: 0;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}
.star-active { color: #f59e0b; }
.star-inactive { color: var(--line); }
.review-form textarea {
  width: 100%;
  padding: .6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card-bg);
  color: var(--fg);
  font: inherit;
  font-size: .9rem;
  resize: vertical;
}

/* ─── Skeleton / Loading ─── */
@keyframes shimmer { 0% { opacity: 0.5; } 50% { opacity: 0.8; } 100% { opacity: 0.5; } }
.skeleton { background: var(--line); animation: shimmer 1.5s infinite; border-radius: var(--radius); }

/* ─── My Works Cards (Dashboard) ─── */
.my-works-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: .85rem;
}
.my-work-card {
  display: grid;
  grid-template-columns: 80px 1fr;
  gap: 1rem;
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 1rem;
  transition: box-shadow var(--transition);
}
.my-work-card:hover { box-shadow: var(--shadow-md); }
.my-work-cover {
  aspect-ratio: 3/4;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--line);
  display: block;
}
.my-work-cover img { width: 100%; height: 100%; object-fit: cover; }
.my-work-cover .cover-fallback { font-size: .75rem; aspect-ratio: 3/4; }
.my-work-body { display: flex; flex-direction: column; gap: .35rem; min-width: 0; }
.my-work-top { display: flex; flex-direction: column; gap: .25rem; }
.my-work-title {
  font-size: .95rem;
  font-weight: 600;
  color: var(--fg);
  line-height: 1.3;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.my-work-title:hover { color: var(--accent); }
.my-work-badges { display: flex; flex-wrap: wrap; gap: .25rem; }
.my-work-stats {
  display: flex;
  gap: .65rem;
  color: var(--muted);
  font-size: .8rem;
}
.my-work-actions { display: flex; gap: .25rem; flex-wrap: wrap; margin-top: .15rem; }
.kd-empty-state {
  text-align: center;
  padding: 2rem;
  background: var(--card-bg);
  border: 1px dashed var(--line);
  border-radius: var(--radius-lg);
}

/* ─── Inline Tag Creation ─── */
.tag-create-row {
  display: flex;
  gap: .35rem;
  margin-top: .5rem;
}
.tag-create-row input {
  flex: 1;
  padding: .4rem .6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: .85rem;
  background: var(--card-bg);
  color: var(--fg);
  min-width: 0;
  transition: border-color var(--transition);
}
.tag-create-row input:focus { border-color: var(--accent); outline: none; }
.tag-create-row button {
  padding: .4rem .75rem;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: var(--radius);
  font-size: .8rem;
  cursor: pointer;
  font-weight: 600;
  white-space: nowrap;
}
.tag-create-row button:hover { background: var(--accent-hover); }

/* ═══════════════════════════════════════════════════
   TABLET BREAKPOINT (>= 640px)
   ═══════════════════════════════════════════════════ */
@media (min-width: 640px) {
  .container { padding: 0 1.5rem; }

  .continue-card { flex: 0 0 170px; }
  .card-grid { grid-template-columns: repeat(3, 1fr); gap: .7rem; margin-bottom: .7rem; }
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
  .form-row { grid-template-columns: repeat(2, 1fr); }
  .cat-grid { grid-template-columns: repeat(3, 1fr); }
  .story-detail-head { grid-template-columns: 160px 1fr; gap: 1.25rem; }
  .story-detail-info h1 { font-size: 1.5rem; }
  .section-title { font-size: 1.3rem; }
  .ch-head h1 { font-size: 1.5rem; }
  .my-works-grid { grid-template-columns: repeat(2, 1fr); }
  .story-form { max-width: 860px; }

  /* Toast centered on larger screens */
  .toast-container { left: auto; right: 1.5rem; align-items: flex-end; }
}

/* ═══════════════════════════════════════════════════
   DESKTOP BREAKPOINT (>= 900px)
   ═══════════════════════════════════════════════════ */
@media (min-width: 900px) {
  .container { padding: 0 2rem; }

  /* Show desktop nav, hide hamburger */
  .hamburger { display: none; }
  .nav-links { display: flex; }
  .nav-user { display: flex; }
  .nav-search { display: block; margin-left: auto; }

  /* Desktop: hide mobile accordion */
  .mobile-accordion { display: none; }

  .card-grid { grid-template-columns: repeat(4, 1fr); gap: .85rem; margin-bottom: .85rem; }
  .two-col { grid-template-columns: 1fr 1fr; gap: 2rem; }
  .story-detail-head { grid-template-columns: 200px 1fr; gap: 1.5rem; }
  .story-detail-info h1 { font-size: 1.7rem; }
  .cover-lg .cover-fallback { font-size: 1.4rem; }
  .home-section { margin: 0; }
  .section-title { font-size: 1.25rem; }

  /* Reader settings: side panel on desktop */
  .reader-settings {
    position: fixed;
    left: auto; right: 1rem; bottom: auto;
    top: 80px;
    width: 280px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--line);
    box-shadow: var(--shadow-lg);
    max-height: none;
    padding-bottom: 1rem;
  }
  .reader-settings-overlay { display: none; }

  .avatar-lg { width: 96px; height: 96px; }
  .cat-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
  .form-row { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
  .chapter-list-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0 1.5rem;
  }
  .chapter-list-grid .chapter-item { min-width: 0; }
  .chapter-list-grid .chapter-item-wrap { flex-wrap: wrap; }
  .chapter-list-grid .ch-meta-line { flex: 1 1 100%; margin-left: 50px; }

  /* Category dropdown: 5 columns on desktop */
  .nav-dropdown-panel.cat-dropdown {
    grid-template-columns: repeat(5, 1fr);
    min-width: 720px;
    max-height: 480px;
  }

  /* Story form wider on desktop */
  .story-form { max-width: 960px; }

  /* Chapter editor: side-by-side editor + sidebar */
  .kd-editor { max-width: 100%; }
  .kd-editor-layout {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 1.5rem;
    align-items: start;
  }
  .kd-editor-main { min-width: 0; }
  .chapter-sidebar {
    position: sticky;
    top: calc(var(--header-h) + 1rem);
    max-height: calc(100vh - var(--header-h) - 2rem);
    overflow-y: auto;
    margin-top: 0;
  }

  /* My works: 2-col with larger cover */
  .my-works-grid { grid-template-columns: repeat(2, 1fr); }
  .my-work-card { grid-template-columns: 100px 1fr; }
}

/* ═══════════════════════════════════════════════════
   LARGE DESKTOP (>= 1200px)
   ═══════════════════════════════════════════════════ */
@media (min-width: 1200px) {
  .continue-card { flex: 0 0 200px; }
  .card-grid { grid-template-columns: repeat(6, 1fr); gap: .85rem; margin-bottom: .85rem; }
  .story-card-info { padding: .85rem; }
  .story-title { font-size: 1rem; }
  .chapter-list-grid { grid-template-columns: repeat(2, 1fr); gap: 0 2rem; }
  .nav-search-input { width: 220px; }
  .nav-search-input:focus { width: 300px; }


  /* Category dropdown: 6 columns on large desktop */
  .nav-dropdown-panel.cat-dropdown {
    grid-template-columns: repeat(6, 1fr);
    min-width: 840px;
    max-height: 520px;
  }
}

/* ─── Content Type Badge ─── */
.content-type-badge {
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  padding: .15rem .5rem;
  border-radius: 999px;
  background: var(--accent-light);
  color: var(--accent);
}

/* ─── Markdown Toolbar ─── */
.md-toolbar {
  display: flex;
  gap: .15rem;
  padding: .5rem;
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  flex-wrap: wrap;
}
.md-toolbar button {
  width: 34px; height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  color: var(--fg);
  font-size: .9rem;
  transition: background var(--transition), border-color var(--transition);
}
.md-toolbar button:hover {
  background: var(--accent-light);
  border-color: var(--line);
}
.md-toolbar-sep {
  width: 1px;
  height: 20px;
  background: var(--line);
  margin: 7px .25rem;
  flex-shrink: 0;
}

/* ─── Manga Editor ─── */
.manga-editor { display: flex; flex-direction: column; gap: 1.5rem; }
.manga-text-section {
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0;
}
.manga-text-section summary {
  padding: .75rem 1rem;
  cursor: pointer;
  font-weight: 600;
  font-size: .9rem;
  color: var(--fg);
  transition: background var(--transition);
  border-radius: var(--radius);
}
.manga-text-section summary:hover { background: var(--accent-light); }
.manga-text-section[open] summary { border-bottom: 1px solid var(--line); border-radius: var(--radius) var(--radius) 0 0; }
.manga-text-area { padding: .75rem 1rem; }
.manga-text-area .ch-content-input {
  min-height: 15vh;
  border-radius: 0 0 var(--radius) var(--radius);
  border-top: none;
}

.manga-image-section { display: flex; flex-direction: column; gap: .75rem; }
.manga-image-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.manga-image-header h3 { margin: 0; font-size: 1rem; }

.manga-image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: .75rem;
  min-height: 100px;
  padding: .75rem;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  transition: border-color var(--transition), background var(--transition);
}
.manga-image-grid.drag-over {
  border-color: var(--accent);
  background: var(--accent-light);
}

.manga-page-card {
  position: relative;
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: grab;
  transition: box-shadow var(--transition), transform var(--transition);
}
.manga-page-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.manga-page-card.drag-target { border: 2px solid var(--accent); opacity: .7; }
.manga-page-card:active { cursor: grabbing; }

.manga-page-number {
  position: absolute;
  top: 4px; left: 4px;
  background: rgba(0,0,0,.65);
  color: #fff;
  font-size: .7rem;
  font-weight: 700;
  width: 22px; height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  z-index: 2;
}
.manga-page-thumb {
  width: 100%;
  aspect-ratio: 3/4;
  object-fit: cover;
  background: var(--line);
}
.manga-page-actions {
  position: absolute;
  top: 4px; right: 4px;
  display: flex;
  gap: 2px;
  z-index: 2;
  opacity: 0;
  transition: opacity var(--transition);
}
.manga-page-card:hover .manga-page-actions { opacity: 1; }
.manga-page-caption {
  padding: .35rem .5rem;
  font-size: .75rem;
  color: var(--muted);
  border-top: 1px solid var(--line);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-danger-icon {
  background: var(--danger) !important;
  color: #fff !important;
  border-radius: 50% !important;
  width: 24px !important;
  height: 24px !important;
  font-size: .7rem !important;
}
.btn-danger-icon:hover { filter: brightness(0.88); }

/* Manga page upload states */
.manga-page-card.uploading {
  opacity: .85;
  cursor: default;
}
.manga-page-card.uploading .manga-page-thumb {
  filter: brightness(.7);
}
.manga-page-card.upload-error {
  border-color: var(--danger);
}

.manga-page-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  z-index: 3;
  border-radius: var(--radius);
  font-size: .75rem;
  font-weight: 600;
}
.uploading-overlay {
  background: rgba(0,0,0,.45);
  color: #fff;
}
.error-overlay {
  background: rgba(0,0,0,.65);
  color: #fca5a5;
  padding: .5rem;
  text-align: center;
}
.error-overlay .error-text {
  font-size: .7rem;
  line-height: 1.3;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.btn-retry {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: .2rem .6rem;
  font-size: .7rem;
  font-weight: 600;
  cursor: pointer;
  transition: filter var(--transition);
}
.btn-retry:hover { filter: brightness(1.15); }

.upload-spinner {
  width: 24px;
  height: 24px;
  border: 3px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: kd-spin .8s linear infinite;
}
@keyframes kd-spin {
  to { transform: rotate(360deg); }
}

.manga-add-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  cursor: pointer;
  gap: .25rem;
  transition: border-color var(--transition), color var(--transition), background var(--transition);
}
.manga-add-page:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }
.manga-add-page span { font-weight: 600; font-size: .9rem; }
.manga-add-page small { font-size: .75rem; }

/* ─── Video Editor ─── */
.video-editor { display: flex; flex-direction: column; gap: 1.5rem; }
.video-embed-section { display: flex; flex-direction: column; gap: .75rem; }
.video-embed-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.video-embed-header h3 { margin: 0; font-size: 1rem; }

.video-embed-list { display: flex; flex-direction: column; gap: .75rem; }
.video-embed-card {
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.video-embed-preview { background: #000; }
.video-embed-info {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .5rem .75rem;
  flex-wrap: wrap;
}
.video-embed-type {
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  background: var(--accent-light);
  color: var(--accent);
  padding: .1rem .4rem;
  border-radius: 999px;
}
.video-embed-caption-input {
  flex: 1;
  min-width: 120px;
  padding: .35rem .5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--fg);
  font-size: .85rem;
}
.video-embed-caption-input:focus { border-color: var(--accent); outline: none; }

.video-add-embed {
  display: flex;
  gap: .5rem;
}
.video-add-embed input[type="url"] {
  flex: 1;
  padding: .5rem .75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card-bg);
  color: var(--fg);
  font-size: .9rem;
}
.video-add-embed input[type="url"]:focus { border-color: var(--accent); outline: none; }

/* ─── Chat Editor ─── */
.chat-editor { display: flex; flex-direction: column; gap: 1.5rem; }

.chat-characters-section {
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
}
.chat-characters-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .75rem;
}
.chat-characters-header h3 { margin: 0; font-size: 1rem; }

.chat-char-form {
  display: flex;
  gap: .5rem;
  align-items: center;
  margin-bottom: .75rem;
  flex-wrap: wrap;
}
.chat-char-form input[type="text"] {
  flex: 2;
  padding: .4rem .6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--fg);
  font-size: .85rem;
}
.chat-char-form input[type="text"]:focus { border-color: var(--accent); outline: none; }

.chat-char-list {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  align-items: flex-start;
}
.chat-char-tip {
  font-size: .8rem;
  color: var(--muted);
  background: rgba(59,130,246,.08);
  border: 1px dashed rgba(59,130,246,.3);
  border-radius: var(--radius);
  padding: .4rem .7rem;
  line-height: 1.5;
  width: 100%;
}
.chat-char-tip strong { color: var(--accent); }
.chat-char-item {
  display: flex;
  align-items: center;
  gap: .35rem;
  padding: .3rem .6rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: .85rem;
}
.chat-char-avatar {
  width: 24px; height: 24px;
  border-radius: 50%;
  object-fit: cover;
}
.chat-char-avatar-fallback {
  width: 24px; height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: .65rem;
  font-weight: 700;
}
.chat-char-name { font-weight: 600; }

.chat-messages-section {
  display: flex;
  flex-direction: column;
  gap: .75rem;
}
.chat-messages-section h3 { margin: 0; font-size: 1rem; }

.chat-messages-list {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  max-height: 60vh;
  overflow-y: auto;
  padding-right: .25rem;
}

.chat-msg-item {
  display: flex;
  gap: .5rem;
  align-items: flex-start;
  padding: .5rem;
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: background var(--transition);
}
.chat-msg-item:hover { background: var(--accent-light); }
.chat-msg-item.msg-type-action { border-left: 3px solid #f59e0b; }
.chat-msg-item.msg-type-narration { border-left: 3px solid #3b82f6; }
.chat-msg-item.msg-type-system { border-left: 3px solid #8b5cf6; }

.chat-msg-drag {
  cursor: grab;
  color: var(--muted);
  font-size: 1.1rem;
  padding: .2rem;
  flex-shrink: 0;
  user-select: none;
}
.chat-msg-drag:active { cursor: grabbing; }

.chat-msg-content-area { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .35rem; }
.chat-msg-dialogue { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.chat-msg-char-select {
  padding: .3rem .4rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--fg);
  font-size: .8rem;
  max-width: 140px;
}
.chat-msg-input {
  flex: 1;
  min-width: 0;
  padding: .35rem .5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--fg);
  font-size: .85rem;
}
.chat-msg-input:focus { border-color: var(--accent); outline: none; }
.chat-msg-action { font-style: italic; }
.chat-msg-narration { resize: vertical; min-height: 40px; font-family: var(--font-serif); }
.chat-msg-system { background: color-mix(in srgb, #8b5cf6 8%, var(--bg)); }

.chat-msg-actions {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  flex-shrink: 0;
}
.chat-msg-type-select {
  padding: .2rem .3rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--fg);
  font-size: .7rem;
}

.chat-add-msg {
  display: flex;
  gap: .35rem;
  flex-wrap: wrap;
}

/* Chat quick input mode */
.chat-quick-mode {
  margin-top: .75rem;
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 1rem;
}
.chat-quick-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .5rem;
}
.chat-quick-header h4 { margin: 0; font-size: .95rem; }
.chat-quick-hint {
  font-size: .8rem;
  color: var(--muted);
  margin: 0 0 .75rem;
  line-height: 1.6;
}
.chat-quick-hint code {
  background: var(--bg);
  padding: .1rem .35rem;
  border-radius: 4px;
  font-size: .78rem;
  color: var(--fg);
}
.chat-quick-input {
  width: 100%;
  min-height: 140px;
  padding: .75rem;
  font-family: var(--font-mono);
  font-size: .85rem;
  line-height: 1.6;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--fg);
  resize: vertical;
  transition: border-color var(--transition);
}
.chat-quick-input:focus { border-color: var(--accent); outline: none; }


/* ─── Post Cards (Công nghệ viết) ─── */
.post-list { display: flex; flex-direction: column; gap: .75rem; }
.post-card {
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  transition: box-shadow var(--transition), transform var(--transition);
  overflow: hidden;
}
.post-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.post-cover {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  flex-shrink: 0;
}
@media (min-width: 640px) {
  .post-cover { width: 200px; aspect-ratio: 16 / 10; border-radius: var(--radius-lg) 0 0 var(--radius-lg); }
}
.post-info { flex: 1; min-width: 0; padding: .85rem 1rem; }
.post-info h2 { margin: 0 0 .3rem; font-size: 1rem; line-height: 1.4; }
.post-info h2 a { color: var(--fg); }
.post-info h2 a:hover { color: var(--accent); text-decoration: none; }
.post-meta {
  display: flex;
  gap: .4rem;
  color: var(--muted);
  font-size: .75rem;
  flex-wrap: wrap;
  margin-top: .35rem;
}

/* ─── Post Detail ─── */
.post-detail { max-width: 800px; margin: 1.5rem auto; }
.post-detail-cover {
  width: 100%;
  max-height: 360px;
  object-fit: cover;
  border-radius: var(--radius-lg);
  margin-bottom: 1.5rem;
}
.post-detail h1 { font-size: 1.6rem; margin: 0 0 .75rem; line-height: 1.35; }
.post-detail-author {
  display: flex;
  align-items: center;
  gap: .65rem;
  margin-bottom: 1rem;
}
.post-detail-body { line-height: 1.8; font-size: 1.05rem; }
.post-detail-body h1, .post-detail-body h2, .post-detail-body h3 { margin: 1.5em 0 .5em; }
.post-detail-body p { margin: 0 0 1em; }
.post-detail-body img { border-radius: var(--radius); margin: 1em 0; }
.post-detail-body blockquote {
  border-left: 3px solid var(--accent);
  padding: .5rem 1rem;
  margin: 1em 0;
  color: var(--muted);
  background: var(--accent-light);
  border-radius: 0 var(--radius) var(--radius) 0;
}
.post-detail-body pre {
  background: var(--bg);
  padding: 1rem;
  border-radius: var(--radius);
  overflow-x: auto;
  font-size: .9rem;
}
.post-detail-body code { font-family: var(--font-mono); font-size: .9em; }
.post-detail-body table { width: 100%; border-collapse: collapse; margin: 1em 0; }
.post-detail-body th, .post-detail-body td {
  padding: .5rem .75rem;
  border: 1px solid var(--line);
  text-align: left;
  font-size: .9rem;
}
.post-detail-body th { background: var(--bg); font-weight: 600; }

/* Review-specific styles */
.review-rating {
  display: flex;
  gap: .15rem;
  font-size: 1.3rem;
  margin: .5rem 0;
}
.review-rating .star-filled { color: #f59e0b; }
.review-rating .star-empty { color: var(--line); }
.review-subject {
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .75rem 1rem;
  margin-bottom: 1rem;
}
.review-story-link {
  display: flex;
  align-items: center;
  gap: .75rem;
}
.review-story-cover {
  width: 48px; height: 64px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
}

/* ─── Post Form ─── */
.post-type-selector {
  display: flex;
  gap: .75rem;
  margin-bottom: .5rem;
}
.post-type-option {
  flex: 1;
  padding: .75rem;
  border: 2px solid var(--line);
  border-radius: var(--radius-lg);
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}
.post-type-option:hover { border-color: var(--accent); }
.post-type-option.active { border-color: var(--accent); background: var(--accent-light); }
.post-type-option span { display: block; font-size: 1.5rem; }
.post-type-option small { display: block; color: var(--muted); font-size: .8rem; margin-top: .25rem; }

.star-selector {
  display: flex;
  gap: .15rem;
  font-size: 1.5rem;
}
.star-selector span {
  cursor: pointer;
  transition: color .15s;
}
.star-selector span:hover { color: #f59e0b; }

.external-subject-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .5rem;
}
.external-subject-fields input {
  padding: .4rem .6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--fg);
  font-size: .85rem;
}

/* ─── Empty State ─── */
.empty-state, .kd-empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
}
.empty-state p, .kd-empty-state p { margin-bottom: 1rem; }

/* ─── Manga/Chat/Video Reader Styles ─── */
.manga-gallery { display: flex; flex-direction: column; gap: 0; margin: 1.5rem 0; }
.manga-page { margin: 0; }
.manga-page img { width: 100%; display: block; }
.manga-page figcaption { text-align: center; font-size: .85rem; color: var(--muted); padding: .5rem 0; border-bottom: 1px solid var(--line); }
.manga-empty { text-align: center; padding: 3rem 1.5rem; color: var(--muted); background: var(--card-bg); border: 2px dashed var(--line); border-radius: var(--radius-lg); margin: 2rem 0; }
.manga-empty p { margin: .35rem 0; }

.video-embed { margin: 1.5rem 0; }
.embed-caption { text-align: center; font-size: .85rem; color: var(--muted); margin-top: .5rem; }

/* ─── Chat Full-Screen Immersive Reader ─── */
.chat-hidden { display: none !important; }

.chat-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  background: #FFFFFF;
  color: #1a1a1a;
  font-family: var(--font-sans);
}
.chat-fullscreen.chat-night-mode {
  background: #0D0D0D;
  color: #E8E8E8;
}

/* Top bar */
.chat-fs-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .5rem .75rem;
  background: inherit;
  border-bottom: 1px solid #e6e6e0;
  flex-shrink: 0;
  z-index: 10;
}
.chat-night-mode .chat-fs-topbar { border-bottom-color: #2a2a2a; }
.chat-fs-btn {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  background: none; border: 0; cursor: pointer;
  border-radius: 50%; font-size: 1.1rem; color: inherit;
  transition: background .15s;
}
.chat-fs-btn:hover { background: rgba(0,0,0,.06); }
.chat-night-mode .chat-fs-btn:hover { background: rgba(255,255,255,.08); }
.chat-fs-title {
  font-size: .85rem; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 60%; text-align: center;
}

/* Settings panel */
.chat-fs-settings {
  position: absolute;
  top: 48px; right: .5rem;
  background: #fff;
  border: 1px solid #e6e6e0;
  border-radius: 12px;
  padding: .75rem;
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
  z-index: 20;
  min-width: 240px;
}
.chat-night-mode .chat-fs-settings {
  background: #1e1e1e;
  border-color: #333;
  color: #E0E0E0;
}
.chat-fs-settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .4rem 0;
  font-size: .85rem;
  gap: .5rem;
}
.chat-fs-settings-btns {
  display: flex; align-items: center; gap: .35rem;
}
.chat-fs-settings-btns button {
  padding: .25rem .5rem;
  border: 1px solid #ddd;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  font-size: .8rem;
  color: inherit;
  transition: background .15s, border-color .15s;
}
.chat-fs-settings-btns button:hover { border-color: var(--accent); color: var(--accent); }
.chat-night-mode .chat-fs-settings-btns button { border-color: #444; }
.chat-fs-settings-btns span { min-width: 40px; text-align: center; font-size: .8rem; }

/* Messages area */
.chat-fs-messages {
  flex: 1;
  overflow-y: auto;
  padding: .75rem;
  display: flex;
  flex-direction: column;
  gap: .35rem;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

/* Message wrapper */
.chat-fs-msg {
  will-change: transform, opacity;
  transition: opacity .3s ease, transform .3s ease;
  animation: chatMsgIn .3s ease-out;
}
@keyframes chatMsgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Left-side bubble (other character) — Messenger style */
.chat-fs-bubble-left {
  display: flex;
  gap: .4rem;
  align-items: flex-end;
  max-width: 80%;
}
.chat-fs-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.chat-fs-avatar-fallback {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  color: #fff;
  font-weight: 700;
  font-size: .75rem;
}
.chat-fs-bubble-body {
  min-width: 0;
}
.chat-fs-name {
  font-weight: 600;
  font-size: calc(var(--chat-fs, 16px) * 0.68);
  display: block;
  margin-bottom: .1rem;
  line-height: 1.3;
}
.chat-fs-name-right { text-align: right; }
.chat-fs-text {
  padding: .5rem .8rem;
  border-radius: 18px 18px 18px 4px;
  background: #E8E8E8;
  font-size: var(--chat-fs, 16px);
  line-height: var(--chat-lh, 1.4);
  display: inline-block;
  word-break: break-word;
}
.chat-night-mode .chat-fs-text { background: #2C2C2E; color: #E8E8E8; }

/* Right-side bubble ("me") — Messenger blue */
.chat-fs-bubble-right {
  display: flex;
  justify-content: flex-end;
  gap: .4rem;
  align-items: flex-end;
  max-width: 80%;
  margin-left: auto;
}
.chat-fs-text-me {
  padding: .5rem .8rem;
  border-radius: 18px 18px 4px 18px;
  background: #0084FF;
  color: #FFFFFF;
  font-size: var(--chat-fs, 16px);
  line-height: var(--chat-lh, 1.4);
  display: inline-block;
  word-break: break-word;
}
.chat-night-mode .chat-fs-text-me { background: #0A7AFF; color: #FFFFFF; }

/* Fake input bar at bottom of chat */
.chat-fs-input-bar {
  flex-shrink: 0;
  padding: .5rem .75rem;
  border-top: 1px solid #e6e6e0;
  background: inherit;
  z-index: 10;
}
.chat-night-mode .chat-fs-input-bar { border-top-color: #2a2a2a; }
.chat-fs-input-wrap {
  display: flex;
  align-items: center;
  gap: .4rem;
  background: #f0f0f0;
  border-radius: 22px;
  padding: .35rem .5rem .35rem .85rem;
  transition: background .15s;
  min-height: 40px;
}
.chat-fs-input-editing { background: #e8e8e8; }
.chat-night-mode .chat-fs-input-wrap { background: #2a2a2a; }
.chat-night-mode .chat-fs-input-editing { background: #333; }
.chat-fs-input-field {
  flex: 1;
  min-height: 22px;
  max-height: 100px;
  overflow-y: auto;
  font-size: var(--chat-fs, 16px);
  line-height: var(--chat-lh, 1.4);
  outline: none;
  word-break: break-word;
  -webkit-user-select: text;
  user-select: text;
  /* NOTE: Do NOT use display:flex or align-items:center on contenteditable —
     it breaks text input for shifted keys like ), !, @, # and IME composition.
     See: https://github.com/nicolo-ribaudo/contenteditable-flex-bug
     Vertical centering is achieved via padding on the parent .chat-fs-input-wrap instead. */
}
.chat-fs-input-field:empty::before {
  content: attr(data-placeholder);
  color: #999;
  pointer-events: none;
}
.chat-night-mode .chat-fs-input-field:empty::before { color: #666; }
.chat-fs-send-btn {
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  background: none; border: 0; cursor: pointer;
  border-radius: 50%;
  color: #999;
  transition: color .15s, background .15s;
  flex-shrink: 0;
}
.chat-fs-send-active { color: #0084FF; }
.chat-fs-send-btn:hover { background: rgba(0,0,0,.06); }
.chat-night-mode .chat-fs-send-active { color: #0A7AFF; }
.chat-night-mode .chat-fs-send-btn:hover { background: rgba(255,255,255,.08); }

/* Action message */
.chat-fs-action {
  text-align: center;
  font-style: italic;
  color: #999;
  font-size: calc(var(--chat-fs, 16px) * 0.85);
  padding: .25rem .5rem;
}
.chat-night-mode .chat-fs-action { color: #777; }

/* Narration message */
.chat-fs-narration {
  text-align: center;
  font-style: italic;
  font-size: var(--chat-fs, 16px);
  line-height: var(--chat-lh, 1.4);
  padding: .3rem 1rem;
  color: inherit;
  opacity: .75;
  border-left: 3px solid var(--accent);
  text-align: left;
  margin: .1rem 2rem;
}

/* System message */
.chat-fs-system {
  text-align: center;
  font-size: calc(var(--chat-fs, 16px) * 0.72);
  color: #999;
  background: rgba(0,0,0,.04);
  padding: .2rem .75rem;
  border-radius: 999px;
  margin: .15rem auto;
  display: inline-block;
}
.chat-bubble.narrator .chat-text { border-radius: 12px; text-align: center; background: var(--accent-light); }
.chat-action { font-style: italic; color: var(--muted); text-align: center; font-size: .9rem; padding: .25rem 0; }
.chat-narration { font-family: var(--font-serif); line-height: 1.7; margin: .5rem 0; }
.chat-system { text-align: center; color: var(--muted); font-size: .8rem; padding: .25rem .75rem; background: var(--bg); border-radius: 999px; margin: .25rem auto; display: inline-block; }
.chat-night-mode .chat-fs-system { background: rgba(255,255,255,.06); color: #777; }

/* End of chapter */
.chat-fs-end {
  text-align: center;
  padding: 1.5rem .5rem .75rem;
}
.chat-fs-end-text {
  color: #999;
  font-style: italic;
  font-size: .9rem;
  margin-bottom: 1rem;
}
.chat-fs-end-nav {
  display: flex;
  gap: .5rem;
  justify-content: center;
  flex-wrap: wrap;
}
.chat-fs-nav-btn {
  display: inline-flex;
  align-items: center;
  padding: .5rem 1rem;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font-size: .85rem;
  cursor: pointer;
  text-decoration: none;
  transition: border-color .15s, background .15s;
}
.chat-fs-nav-btn:hover { border-color: var(--accent); color: var(--accent); }
.chat-night-mode .chat-fs-nav-btn { border-color: #333; }
.chat-fs-exit-btn { font-family: inherit; }

/* Tap hint */
.chat-fs-tap-hint {
  text-align: center;
  padding: .5rem;
  color: #bbb;
  font-size: .8rem;
  animation: chatPulse 2s ease-in-out infinite;
}

/* Typing indicator (dots + text) */
.chat-fs-typing-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  padding: .5rem;
  color: #bbb;
  font-size: .8rem;
}
.chat-fs-typing-dots {
  display: inline-flex;
  gap: .2rem;
}
.chat-fs-typing-dots span {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: #bbb;
  animation: chatTypingDot 1.4s ease-in-out infinite;
}
.chat-fs-typing-dots span:nth-child(2) { animation-delay: .2s; }
.chat-fs-typing-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes chatTypingDot {
  0%, 60%, 100% { opacity: .3; transform: scale(.8); }
  30% { opacity: 1; transform: scale(1.1); }
}
.chat-night-mode .chat-fs-typing-dots span { background: #777; }
.chat-night-mode .chat-fs-typing-hint { color: #777; }
@keyframes chatPulse {
  0%, 100% { opacity: .5; }
  50% { opacity: 1; }
}

/* Chat msg image in full-screen mode */
.chat-fullscreen .chat-msg-image {
  max-width: 100%;
  border-radius: 12px;
  margin: .2rem 0;
  cursor: zoom-in;
}

/* ─── Chat editor: Image upload loading overlay ─── */
.chat-msg-image-preview {
  position: relative;
  display: inline-block;
}
.chat-img-uploading img { opacity: .5; }
.chat-img-loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.15);
  border-radius: 6px;
}
.chat-img-spinner {
  width: 24px; height: 24px;
  border: 3px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: chatImgSpin .6s linear infinite;
}
@keyframes chatImgSpin { to { transform: rotate(360deg); } }
.chat-img-error-overlay {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: rgba(185,28,28,.85);
  color: #fff;
  font-size: .65rem;
  padding: .2rem .4rem;
  border-radius: 0 0 6px 6px;
  text-align: center;
}
.chat-img-error img { opacity: .5; border: 1px solid #dc2626; border-radius: 6px; }

/* ─── Chat reader: Image size limit + right-align for "me" ─── */
.chat-fullscreen .chat-msg-image {
  max-width: min(280px, 70vw);
  max-height: 280px;
  object-fit: contain;
  border-radius: 12px;
  margin: .2rem 0;
  cursor: zoom-in;
}
.chat-fs-bubble-right .chat-msg-image {
  margin-left: auto;
}
.chat-fs-bubble-right .chat-fs-bubble-body {
  align-items: flex-end;
}

/* ─── Admin Panel ─── */
.admin-nav {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
}
.admin-nav .btn-secondary {
  font-size: .85rem;
  padding: .4rem .75rem;
  display: inline-flex;
  align-items: center;
  gap: .3rem;
}

/* Admin guide */
.guide-toc {
  background: var(--bg-alt);
  border-radius: var(--radius);
  padding: 1rem 1.5rem;
  margin-bottom: 2rem;
}
.guide-toc h3 { margin: 0 0 .5rem; }
.guide-toc ol { margin: 0; padding-left: 1.5rem; line-height: 2; }
.guide-toc a { color: var(--accent); text-decoration: none; }
.guide-toc a:hover { text-decoration: underline; }

/* Admin section headings */
.guide-toc + section h2 { scroll-margin-top: 4rem; }

/* Admin review detail: approval status badges */
.review-status {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  font-size: .8rem;
  font-weight: 600;
  padding: .2rem .6rem;
  border-radius: 99px;
}
.review-status-pending { background: #fef3c7; color: #92400e; }
.review-status-approved { background: #dcfce7; color: #166534; }
.review-status-rejected { background: #fee2e2; color: #991b1b; }
.review-status-draft { background: #f3f4f6; color: #6b7280; }
.review-status-public { background: #dbeafe; color: #1e40af; }
.review-status-private { background: #fce7f3; color: #9d174d; }
.review-status-deleted { background: #f3f4f6; color: #6b7280; text-decoration: line-through; }

/* Admin review notice banner */
.review-notice {
  padding: .75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: .9rem;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.review-notice-info { background: #dbeafe; color: #1e40af; border-left: 3px solid #3b82f6; }
.review-notice-warning { background: #fef3c7; color: #92400e; border-left: 3px solid #f59e0b; }
.review-notice-success { background: #dcfce7; color: #166534; border-left: 3px solid #22c55e; }
.review-notice-error { background: #fee2e2; color: #991b1b; border-left: 3px solid #ef4444; }

/* Admin details/summary rejection form */
.ch-reject-details,
details.inline-reject {
  display: inline;
  position: relative;
}
details.inline-reject > summary,
.ch-reject-details > summary {
  cursor: pointer;
  list-style: none;
}
details.inline-reject > summary::-webkit-details-marker,
.ch-reject-details > summary::-webkit-details-marker {
  display: none;
}
details.inline-reject[open],
.ch-reject-details[open] {
  display: block;
}
details.inline-reject[open] > summary,
.ch-reject-details[open] > summary {
  margin-bottom: .5rem;
}
details.inline-reject form,
.ch-reject-details form {
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .75rem;
  min-width: 280px;
}
details.inline-reject textarea,
.ch-reject-details textarea {
  width: 100%;
  font-size: .85rem;
  padding: .35rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--fg);
  resize: vertical;
}
details.inline-reject textarea:focus,
.ch-reject-details textarea:focus {
  border-color: var(--accent);
  outline: none;
}

/* Admin card block */
.admin-card {
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}
.admin-card h2 {
  margin: 0 0 .75rem;
  font-size: 1.1rem;
}
.admin-card h3 {
  margin: 1rem 0 .5rem;
  font-size: 1rem;
}

/* ── Admin Review Detail (Mobile-First) ─── */

/* Content type badges */
.content-type-badge {
  display: inline-block;
  padding: .2rem .6rem;
  border-radius: 99px;
  font-size: .8rem;
  font-weight: 600;
  color: #fff;
}
.content-type-manga { background: #E11D48; }
.content-type-chat  { background: #7C3AED; }
.content-type-video { background: #2563EB; }
.content-type-text  { background: #6b7280; }

/* Trust score colors */
.trust-high { color: #22c55e; font-weight: 600; }
.trust-mid  { color: #eab308; font-weight: 600; }
.trust-low  { color: #ef4444; font-weight: 600; }

/* Page header actions */
.page-head-actions {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
}

/* Story header: cover + info — stacks on mobile */
.review-story-header {
  display: flex;
  gap: 1.25rem;
  align-items: flex-start;
}
.review-cover {
  width: 100px;
  height: auto;
  border-radius: var(--radius);
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid var(--line);
}
.review-cover-fallback {
  width: 100px;
  height: 140px;
  border-radius: var(--radius);
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 1px dashed var(--line);
  font-size: .75rem;
  color: var(--muted);
  text-align: center;
  padding: .5rem;
}
.review-story-info {
  flex: 1;
  min-width: 0;
}

/* Meta grid: 2 cols on desktop, 1 col on mobile */
.review-meta-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: .4rem .75rem;
  font-size: .88rem;
}

/* Pending reason banner */
.review-pending-reason {
  margin-top: .75rem;
  padding: .5rem .75rem;
  background: #fef3c7;
  border-left: 4px solid #eab308;
  border-radius: 4px;
  font-size: .88rem;
}

/* Chapter table responsive */
.review-chapter-table .cell-title {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.review-chapter-table .th-actions,
.review-chapter-table .cell-actions {
  /* Allow wrapping in action cells */
  white-space: normal;
}
.ch-action-group {
  display: flex;
  align-items: center;
  gap: .3rem;
  flex-wrap: wrap;
}
.ch-btn-approve {
  background: #22c55e;
  color: #fff;
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: .75rem;
  padding: .15rem .4rem;
}
.ch-btn-reject {
  background: #ef4444;
  color: #fff;
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: .75rem;
  padding: .15rem .4rem;
}

/* Preview header */
.preview-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .75rem;
}

/* Pending edit notice */
.review-pending-edit-notice {
  margin-bottom: .75rem;
  padding: .5rem .75rem;
  background: #fef3c7;
  border-left: 4px solid #eab308;
  border-radius: 4px;
  font-size: .85rem;
}
.btn-toggle-old {
  margin: .4rem 0 0;
  padding: .15rem .5rem;
  font-size: .75rem;
  border: 1px solid #d97706;
  border-radius: 4px;
  background: #fffbeb;
  cursor: pointer;
  color: #92400e;
  display: block;
}

/* Approval actions — stacks on mobile */
.review-approval-actions {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  align-items: flex-start;
}
.reject-form {
  display: flex;
  gap: .5rem;
  align-items: flex-start;
  flex-wrap: wrap;
}

/* ── Desktop breakpoint ─── */
@media (min-width: 640px) {
  .review-meta-grid {
    grid-template-columns: 1fr 1fr;
  }
  .review-cover {
    width: 120px;
  }
  .review-cover-fallback {
    width: 120px;
    height: 160px;
  }
  .btn-toggle-old {
    display: inline-block;
    margin: 0 0 0 .5rem;
  }
}

/* ── Small mobile: compress admin cards ─── */
@media (max-width: 480px) {
  .admin-card {
    padding: 1rem;
    margin-bottom: 1rem;
  }
  .admin-card h2 {
    font-size: 1rem;
  }
  .review-story-header {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }
  .review-story-info {
    width: 100%;
  }
  .review-story-info h2 {
    font-size: 1.05rem;
  }
  .review-meta-grid {
    font-size: .82rem;
    text-align: left;
  }
  .review-cover,
  .review-cover-fallback {
    width: 80px;
    height: auto;
  }
  .review-cover-fallback {
    height: 110px;
  }
  .review-pending-reason {
    font-size: .82rem;
  }
  /* Table: smaller font */
  .review-chapter-table {
    font-size: .8rem;
  }
  .review-chapter-table th {
    font-size: .7rem;
  }
  /* Force chapter actions to stack vertically on very small screens */
  .ch-action-group {
    flex-direction: column;
    align-items: flex-start;
    gap: .2rem;
  }
  /* Approval: full width */
  .review-approval-actions {
    flex-direction: column;
  }
  .review-approval-actions .btn-primary {
    width: 100%;
    text-align: center;
  }
  details.inline-reject {
    width: 100%;
  }
  details.inline-reject > summary {
    width: 100%;
    text-align: center;
  }
  .reject-form {
    flex-direction: column;
  }
  .reject-form textarea {
    width: 100%;
  }
}

/* Author facing: approval status notice */
.approval-notice {
  padding: .75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: .9rem;
  line-height: 1.5;
  display: flex;
  align-items: flex-start;
  gap: .5rem;
}
.approval-notice-pending {
  background: #fef3c7;
  color: #92400e;
  border-left: 3px solid #f59e0b;
}
.approval-notice-rejected {
  background: #fee2e2;
  color: #991b1b;
  border-left: 3px solid #ef4444;
}
.approval-notice-approved {
  background: #dcfce7;
  color: #166534;
  border-left: 3px solid #22c55e;
}
.approval-notice p { margin: 0; }
.approval-notice strong { display: block; margin-bottom: .25rem; }

/* Dark theme overrides for admin elements */
body.theme-dark .review-status-pending { background: #78350f; color: #fde68a; }
body.theme-dark .review-status-approved { background: #14532d; color: #bbf7d0; }
body.theme-dark .review-status-rejected { background: #7f1d1d; color: #fecaca; }
body.theme-dark .review-status-draft { background: #374151; color: #d1d5db; }
body.theme-dark .review-status-public { background: #1e3a5f; color: #93c5fd; }
body.theme-dark .review-status-private { background: #4a1942; color: #f9a8d4; }
body.theme-dark .review-status-deleted { background: #374151; color: #9ca3af; }
body.theme-dark .review-notice-info { background: #1e3a5f; color: #93c5fd; }
body.theme-dark .review-notice-warning { background: #78350f; color: #fde68a; }
body.theme-dark .review-notice-success { background: #14532d; color: #bbf7d0; }
body.theme-dark .review-notice-error { background: #7f1d1d; color: #fecaca; }
body.theme-dark .approval-notice-pending { background: #78350f; color: #fde68a; }
body.theme-dark .approval-notice-rejected { background: #7f1d1d; color: #fecaca; }
body.theme-dark .approval-notice-approved { background: #14532d; color: #bbf7d0; }

/* ── Accessibility ─────────────────────────────────── */
.skip-link {
  position: absolute;
  top: -100%;
  left: 0;
  z-index: 9999;
  background: var(--accent);
  color: #fff;
  padding: .5rem 1rem;
  font-weight: 600;
  text-decoration: none;
  border-radius: 0 0 var(--radius) 0;
}
.skip-link:focus {
  top: 0;
}
.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;
}

/* ── HTMX Loading Indicator ────────────────────────── */
.htmx-indicator {
  display: none;
}
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  display: inline-block;
}
.htmx-indicator.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: kd-spin .6s linear infinite;
  vertical-align: middle;
}
@keyframes kd-spin {
  to { transform: rotate(360deg); }
}

/* ── Studio Detail Panels (Followers / Bookmarks) ─── */
.stat-card-clickable {
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.stat-card-clickable:hover,
.stat-card-clickable:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-light);
  outline: none;
}
.stat-hint {
  font-size: .72rem;
  color: var(--accent);
  font-weight: 500;
  margin-top: .15rem;
}

.studio-panel {
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  margin: 1rem 0;
  overflow: hidden;
}
.studio-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.studio-panel-head h3 {
  margin: 0;
  font-size: 1rem;
}

/* Follower list */
.studio-follower-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 420px;
  overflow-y: auto;
}
.studio-follower-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .6rem 1rem;
  border-bottom: 1px solid var(--line);
  gap: .5rem;
}
.studio-follower-item:last-child { border-bottom: none; }
.studio-follower-link {
  display: flex;
  align-items: center;
  gap: .6rem;
  text-decoration: none;
  color: var(--fg);
  flex: 1;
  min-width: 0;
}
.studio-follower-link:hover { color: var(--accent); }
.studio-follower-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.studio-follower-info strong {
  font-size: .88rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.studio-follower-info span {
  font-size: .75rem;
}

.avatar-sm { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; }
.avatar-fallback-sm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--line);
  color: var(--fg);
  font-weight: 700;
  font-size: .8rem;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Bookmark breakdown */
.studio-bookmark-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 420px;
  overflow-y: auto;
}
.studio-bookmark-item {
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--line);
}
.studio-bookmark-item:last-child { border-bottom: none; }
.studio-bookmark-title {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: .35rem;
}
.studio-bookmark-title a {
  font-weight: 600;
  font-size: .9rem;
  text-decoration: none;
  color: var(--fg);
}
.studio-bookmark-title a:hover { color: var(--accent); }
.studio-bookmark-title .badge {
  font-size: .7rem;
  padding: .1rem .4rem;
}
.studio-bookmark-breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  margin-bottom: .4rem;
}
.bm-tag {
  font-size: .72rem;
  padding: .15rem .45rem;
  border-radius: 999px;
  white-space: nowrap;
}
.bm-reading  { background: #dbeafe; color: #1e40af; }
.bm-favorite { background: #fce7f3; color: #9d174d; }
.bm-completed { background: #dcfce7; color: #166534; }
.bm-plan     { background: #fef9c3; color: #854d0e; }

.studio-bookmark-bar {
  display: flex;
  height: 6px;
  border-radius: 3px;
  overflow: hidden;
  background: var(--line);
}
.bm-bar-segment { height: 100%; transition: width .3s; }
.bm-bar-reading  { background: #3b82f6; }
.bm-bar-favorite { background: #ec4899; }
.bm-bar-completed { background: #22c55e; }
.bm-bar-plan     { background: #eab308; }

/* Pagination in studio panels */
.studio-panel .pagination {
  display: flex;
  align-items: center;
  gap: .3rem;
  flex-wrap: wrap;
  padding: .5rem 1rem;
  border-top: 1px solid var(--line);
  justify-content: center;
}
.page-active {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-size: .8rem;
  font-weight: 600;
}
.page-ellipsis {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  font-size: .8rem;
  color: var(--muted);
}
