/* ============================================================================
 * truyen.dev — design system
 * ============================================================================
 * Token layers (cascade order matters):
 *   1. :root            — base scale, spacing, shadow, type, radius, defaults
 *   2. .theme-*         — full color world (surface + brand co-designed)
 *   3. html.dark.theme-* — dark variant of that theme
 *
 * Each theme is one coherent palette so accent+surface never clash. Themes:
 *   indigo (default) · teal · amber · rose · sepia · mono.
 * The user picks a theme + toggles `html.dark` (dark mode) independently.
 * ========================================================================== */

/* ── Scale tokens (size-axis only — no colour here) ───────────────────────── */
:root {
  /* Typography — Vietnamese-first stack.
     Be Vietnam Pro is hand-designed for Vietnamese diacritics (stacked tone marks
     don't collide with caps); falls back to Inter then system-ui for the moment
     before web fonts load. The remaining fallbacks cover Windows/macOS/Linux. */
  --font:           'Be Vietnam Pro', 'Inter', system-ui, -apple-system,
                    BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue',
                    Arial, sans-serif;
  --font-size:      17px;
  --line-h:         1.75;

  /* Type scale (reading layout) */
  --text-xs:        0.72rem;
  --text-sm:        0.82rem;
  --text-base:      0.92rem;
  --text-md:        1rem;
  --text-lg:        1.15rem;
  --text-xl:        1.4rem;
  --text-2xl:       1.75rem;
  --text-3xl:       2.4rem;
  --text-hero:      clamp(2.2rem, 4.5vw, 3.4rem);

  /* Spacing (4px base) */
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-5:  1.25rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;

  /* Radius */
  --radius-xs:  3px;
  --radius-sm:  5px;
  --radius-md:  8px;
  --radius-lg:  12px;
  --radius-xl:  16px;
  --radius-pill: 999px;

  /* Layout */
  --wide:           1180px;
  --reading-width:  680px;
  --sidebar-w:      260px;
  --topbar-h:       56px;

  /* Motion */
  --transition:     180ms ease;
  --transition-fast: 100ms ease;

  /* Status palette (state colours — same across themes) */
  --green-fg:   #15803d;
  --green-bg:   #ecfdf5;
  --green-line: #86efac;
  --blue-fg:    #1d4ed8;
  --blue-bg:    #eff6ff;
  --blue-line:  #93c5fd;
  --amber-fg:   #92400e;
  --amber-bg:   #fffbeb;
  --amber-line: #fde68a;
  --red-fg:     #b91c1c;
  --red-bg:     #fef2f2;
  --red-line:   #fca5a5;
  --rating-color: #f59e0b;
}

/* ── Theme palette (single axis) ──────────────────────────────────────────────
 * Mỗi theme là một "color world" hoàn chỉnh — surface + brand co-designed cho
 * mood thống nhất (theo cách lazycoder làm). `html.dark` toggle dark variant của
 * theme đang dùng. Như vậy không bao giờ có chuyện accent ấm trên surface lạnh.
 *
 * Defaults: theme-indigo + light mode. UI list 6 theme, mỗi theme có dot màu để
 * preview; user pick theme + bật/tắt dark mode độc lập.
 * ──────────────────────────────────────────────────────────────────────────── */

/* ── Indigo (default) — modern, fresh ────────────────────────────────────── */
:root, .theme-indigo {
  --surface:               #fcfcff;
  --surface-container:     #f5f5fb;
  --surface-container-low: #ededf6;
  --surface-overlay:       #ffffff;
  --on-surface:            #1a1a2e;
  --on-surface-variant:    #5b5b75;
  --on-surface-faint:      #9090aa;
  --outline:               #c4c4d6;
  --outline-variant:       #e4e4ee;
  --brand:                 #5b5bd6;
  --brand-hover:           #4f4ec0;
  --brand-soft:            rgba(91, 91, 214, 0.10);
  --brand-ring:            rgba(91, 91, 214, 0.35);
  --on-brand:              #ffffff;
  --hero-gradient:         linear-gradient(135deg, #ede9fe 0%, #ddd6fe 50%, #e0e7ff 100%);
  --shadow-rgb:            30, 27, 75;
}
html.dark.theme-indigo,
html.dark:not([class*="theme-"]) {
  --surface:               #0c0c14;
  --surface-container:     #14141f;
  --surface-container-low: #1c1c2c;
  --surface-overlay:       #20202f;
  --on-surface:            #e8e8f0;
  --on-surface-variant:    #9999b3;
  --on-surface-faint:      #6a6a85;
  --outline:               #3a3a52;
  --outline-variant:       #28283a;
  --brand:                 #a5b4fc;
  --brand-hover:           #c7d2fe;
  --brand-soft:            rgba(165, 180, 252, 0.16);
  --brand-ring:            rgba(165, 180, 252, 0.35);
  --on-brand:              #1e1b4b;
  --hero-gradient:         linear-gradient(135deg, #1e1b4b 0%, #312e81 50%, #1e1b4b 100%);
  --shadow-rgb:            0, 0, 0;
}

/* ── Teal — fresh, calm ─────────────────────────────────────────────────── */
.theme-teal {
  --surface:               #f7fdfb;
  --surface-container:     #effbf6;
  --surface-container-low: #e3f6ec;
  --surface-overlay:       #ffffff;
  --on-surface:            #0e2a25;
  --on-surface-variant:    #4d6e66;
  --on-surface-faint:      #8aa9a0;
  --outline:               #b8d4cb;
  --outline-variant:       #d6eae2;
  --brand:                 #0d9488;
  --brand-hover:           #0f766e;
  --brand-soft:            rgba(13, 148, 136, 0.10);
  --brand-ring:            rgba(13, 148, 136, 0.35);
  --on-brand:              #ffffff;
  --hero-gradient:         linear-gradient(135deg, #ccfbf1 0%, #99f6e4 50%, #d1fae5 100%);
  --shadow-rgb:            6, 78, 59;
}
html.dark.theme-teal {
  --surface:               #061614;
  --surface-container:     #0a1f1c;
  --surface-container-low: #112826;
  --surface-overlay:       #143230;
  --on-surface:            #d5ece5;
  --on-surface-variant:    #88b0a5;
  --on-surface-faint:      #5d8478;
  --outline:               #2d4d44;
  --outline-variant:       #1d3530;
  --brand:                 #5eead4;
  --brand-hover:           #99f6e4;
  --brand-soft:            rgba(94, 234, 212, 0.16);
  --brand-ring:            rgba(94, 234, 212, 0.35);
  --on-brand:              #042f2e;
  --hero-gradient:         linear-gradient(135deg, #042f2e 0%, #134e4a 50%, #042f2e 100%);
  --shadow-rgb:            0, 0, 0;
}

/* ── Amber — warm, cozy, paper-like ─────────────────────────────────────── */
.theme-amber {
  --surface:               #fdfaf2;
  --surface-container:     #faf3e3;
  --surface-container-low: #f4ead0;
  --surface-overlay:       #ffffff;
  --on-surface:            #2a200e;
  --on-surface-variant:    #6a5934;
  --on-surface-faint:      #a09064;
  --outline:               #d8c694;
  --outline-variant:       #ebdcad;
  --brand:                 #b45309;
  --brand-hover:           #92400e;
  --brand-soft:            rgba(180, 83, 9, 0.10);
  --brand-ring:            rgba(180, 83, 9, 0.32);
  --on-brand:              #ffffff;
  --hero-gradient:         linear-gradient(135deg, #fef3c7 0%, #fde68a 50%, #fed7aa 100%);
  --shadow-rgb:            120, 53, 15;
}
html.dark.theme-amber {
  --surface:               #1a1408;
  --surface-container:     #221a0d;
  --surface-container-low: #2b2114;
  --surface-overlay:       #312815;
  --on-surface:            #ece1c4;
  --on-surface-variant:    #b39a6b;
  --on-surface-faint:      #82704a;
  --outline:               #4a3a1f;
  --outline-variant:       #322716;
  --brand:                 #fbbf24;
  --brand-hover:           #fcd34d;
  --brand-soft:            rgba(251, 191, 36, 0.16);
  --brand-ring:            rgba(251, 191, 36, 0.38);
  --on-brand:              #422006;
  --hero-gradient:         linear-gradient(135deg, #422006 0%, #78350f 50%, #422006 100%);
  --shadow-rgb:            0, 0, 0;
}

/* ── Rose — soft warm pink, distinctive ─────────────────────────────────── */
.theme-rose {
  --surface:               #fffafc;
  --surface-container:     #fdf2f8;
  --surface-container-low: #fce8ef;
  --surface-overlay:       #ffffff;
  --on-surface:            #281118;
  --on-surface-variant:    #6e4a55;
  --on-surface-faint:      #a4818c;
  --outline:               #d8b8c4;
  --outline-variant:       #ecd0d9;
  --brand:                 #be185d;
  --brand-hover:           #9d174d;
  --brand-soft:            rgba(190, 24, 93, 0.09);
  --brand-ring:            rgba(190, 24, 93, 0.30);
  --on-brand:              #ffffff;
  --hero-gradient:         linear-gradient(135deg, #fce7f3 0%, #fbcfe8 50%, #f9a8d4 100%);
  --shadow-rgb:            136, 19, 55;
}
html.dark.theme-rose {
  --surface:               #160a0e;
  --surface-container:     #1e1014;
  --surface-container-low: #28161c;
  --surface-overlay:       #2c1a21;
  --on-surface:            #f5dce4;
  --on-surface-variant:    #c08899;
  --on-surface-faint:      #8a5d6b;
  --outline:               #4d2735;
  --outline-variant:       #321820;
  --brand:                 #f9a8d4;
  --brand-hover:           #fbcfe8;
  --brand-soft:            rgba(249, 168, 212, 0.14);
  --brand-ring:            rgba(249, 168, 212, 0.32);
  --on-brand:              #500724;
  --hero-gradient:         linear-gradient(135deg, #500724 0%, #831843 50%, #500724 100%);
  --shadow-rgb:            0, 0, 0;
}

/* ── Sepia — vintage book paper ─────────────────────────────────────────── */
.theme-sepia {
  --surface:               #f8f1e3;
  --surface-container:     #f1e9d6;
  --surface-container-low: #ebe1cc;
  --surface-overlay:       #fcf7eb;
  --on-surface:            #3a2a1a;
  --on-surface-variant:    #7a6044;
  --on-surface-faint:      #a99270;
  --outline:               #c8b896;
  --outline-variant:       #ddd0b0;
  --brand:                 #8b5a2b;
  --brand-hover:           #6d4520;
  --brand-soft:            rgba(139, 90, 43, 0.10);
  --brand-ring:            rgba(139, 90, 43, 0.30);
  --on-brand:              #ffffff;
  --hero-gradient:         linear-gradient(135deg, #f1e2c4 0%, #e8d4a8 50%, #f1e2c4 100%);
  --shadow-rgb:            74, 51, 27;
}
html.dark.theme-sepia {
  --surface:               #2a1f15;
  --surface-container:     #322619;
  --surface-container-low: #3b2d1f;
  --surface-overlay:       #3f3022;
  --on-surface:            #e4d4b2;
  --on-surface-variant:    #b39e7a;
  --on-surface-faint:      #8a7656;
  --outline:               #5c4831;
  --outline-variant:       #4a3a26;
  --brand:                 #d4a574;
  --brand-hover:           #e0b88c;
  --brand-soft:            rgba(212, 165, 116, 0.14);
  --brand-ring:            rgba(212, 165, 116, 0.32);
  --on-brand:              #2a1f15;
  --hero-gradient:         linear-gradient(135deg, #2a1f15 0%, #3b2d1f 50%, #2a1f15 100%);
  --shadow-rgb:            0, 0, 0;
}

/* ── Mono — minimalist neutral grayscale ─────────────────────────────────── */
.theme-mono {
  --surface:               #ffffff;
  --surface-container:     #f8f8f8;
  --surface-container-low: #f0f0f0;
  --surface-overlay:       #ffffff;
  --on-surface:            #18181b;
  --on-surface-variant:    #6b7280;
  --on-surface-faint:      #9ca3af;
  --outline:               #d1d5db;
  --outline-variant:       #e5e7eb;
  --brand:                 #18181b;
  --brand-hover:           #3f3f46;
  --brand-soft:            rgba(24, 24, 27, 0.06);
  --brand-ring:            rgba(24, 24, 27, 0.25);
  --on-brand:              #ffffff;
  --hero-gradient:         linear-gradient(135deg, #f4f4f5 0%, #e4e4e7 50%, #f4f4f5 100%);
  --shadow-rgb:            17, 24, 39;
}
html.dark.theme-mono {
  --surface:               #000000;
  --surface-container:     #0a0a0a;
  --surface-container-low: #141414;
  --surface-overlay:       #1a1a1a;
  --on-surface:            #f4f4f5;
  --on-surface-variant:    #a1a1aa;
  --on-surface-faint:      #71717a;
  --outline:               #3f3f46;
  --outline-variant:       #27272a;
  --brand:                 #f4f4f5;
  --brand-hover:           #d4d4d8;
  --brand-soft:            rgba(244, 244, 245, 0.08);
  --brand-ring:            rgba(244, 244, 245, 0.25);
  --on-brand:              #000000;
  --hero-gradient:         linear-gradient(135deg, #0a0a0a 0%, #1a1a1a 50%, #0a0a0a 100%);
  --shadow-rgb:            0, 0, 0;
}

/* Soft state tints work better than full saturation on dark mode */
html.dark {
  --green-bg:  rgba(134, 239, 172, 0.10);
  --blue-bg:   rgba(147, 197, 253, 0.10);
  --amber-bg:  rgba(253, 230, 138, 0.10);
  --red-bg:    rgba(252, 165, 165, 0.10);
}

/* ── Shadow scale (uses --shadow-rgb so dark themes get inkier shadows) ─── */
:root {
  --shadow-sm: 0 1px 2px rgba(var(--shadow-rgb), 0.06);
  --shadow-md: 0 2px 4px rgba(var(--shadow-rgb), 0.06), 0 4px 12px rgba(var(--shadow-rgb), 0.08);
  --shadow-lg: 0 4px 8px rgba(var(--shadow-rgb), 0.08), 0 12px 28px rgba(var(--shadow-rgb), 0.12);
  --shadow-xl: 0 8px 16px rgba(var(--shadow-rgb), 0.10), 0 24px 48px rgba(var(--shadow-rgb), 0.18);
  --shadow-glow: 0 0 0 3px var(--brand-ring);
}

/* ── Font axis (independent of theme) ─────────────────────────────────────── */
/* Mỗi font listed here đã được verify có Latin Extended Additional / Vietnamese
   subset trên Google Fonts. Người đọc chọn font hợp với gu của mình; default là
   Be Vietnam Pro (designed for VI). Các @font-face do Google Fonts cung cấp
   trong base.html. */

/* Sans-serif */
.font-be-vietnam-pro { --font: 'Be Vietnam Pro', 'Inter', system-ui, -apple-system,
                                BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; }
.font-inter          { --font: 'Inter', 'Be Vietnam Pro', system-ui, -apple-system,
                                BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; }
.font-nunito         { --font: 'Nunito', 'Be Vietnam Pro', system-ui, -apple-system,
                                BlinkMacSystemFont, 'Segoe UI', sans-serif; }

/* Serif — long-form reading */
.font-lora           { --font: 'Lora', 'Iowan Old Style', 'Charter', Georgia,
                                'Times New Roman', serif; }
.font-merriweather   { --font: 'Merriweather', 'Iowan Old Style', Georgia,
                                'Times New Roman', serif; }
.font-source-serif   { --font: 'Source Serif 4', 'Iowan Old Style', Georgia,
                                'Times New Roman', serif; }
.font-eb-garamond    { --font: 'EB Garamond', 'Iowan Old Style', Georgia,
                                'Times New Roman', serif; }

/* Mono */
.font-jetbrains-mono { --font: 'JetBrains Mono', 'Fira Code', 'Cascadia Code',
                                Consolas, 'Liberation Mono', Menlo, monospace; }

/* Legacy aliases (settings.js sẽ migrate prefs cũ, nhưng giữ tránh FOUC flash) */
.font-sans  { --font: 'Be Vietnam Pro', 'Inter', system-ui, sans-serif; }
.font-serif { --font: 'Lora', Georgia, serif; }
.font-mono  { --font: 'JetBrains Mono', Consolas, monospace; }

.size-sm { --font-size: 15px; }
.size-md { --font-size: 17px; }
.size-lg { --font-size: 19px; }
.size-xl { --font-size: 21px; }

.lh-tight  { --line-h: 1.5; }
.lh-normal { --line-h: 1.75; }
.lh-loose  { --line-h: 2.1; }

/* `--primary` is the legacy token; map it to the new brand for any styles that
   still reference it. New styles should reach for `--brand` directly. */
:root { --primary: var(--brand); }

/* ── Reset ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
  font-size: var(--font-size);
  font-family: var(--font);
  background: var(--surface);
  color: var(--on-surface);
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
}
body {
  line-height: var(--line-h);
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
}
a { color: var(--brand); text-decoration: none; transition: color var(--transition-fast); }
a:hover { color: var(--brand-hover); text-decoration: underline; text-underline-offset: 3px; }
img { max-width: 100%; display: block; }
button { font-family: inherit; }

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Accessible scrollbars (dark/light aware) */
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--outline-variant); border-radius: var(--radius-pill); border: 2px solid var(--surface); }
*::-webkit-scrollbar-thumb:hover { background: var(--outline); }

/* ── Topbar ───────────────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(140%) blur(12px);
  -webkit-backdrop-filter: saturate(140%) blur(12px);
  border-bottom: 1px solid var(--outline-variant);
  height: var(--topbar-h);
}
.topbar-inner {
  max-width: var(--wide);
  margin: 0 auto;
  padding: 0 var(--space-6);
  height: 100%;
  display: flex;
  align-items: center;
  gap: var(--space-4);
}
.logo {
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: -0.03em;
  color: var(--on-surface);
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}
.logo::before {
  content: '';
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--brand);
}
.topbar-title {
  flex: 1;
  font-size: var(--text-sm);
  color: var(--on-surface-variant);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-nav {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  margin-left: auto;
}
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border: none;
  background: none;
  color: var(--on-surface-variant);
  cursor: pointer;
  border-radius: var(--radius-md);
  font-size: 1.05rem;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.btn-icon:hover {
  background: var(--surface-container-low);
  color: var(--on-surface);
}
.btn-nav {
  font-size: var(--text-sm);
  color: var(--on-surface-variant);
  padding: 0.4rem 0.7rem;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-weight: 500;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.btn-nav:hover {
  background: var(--surface-container-low);
  color: var(--on-surface);
  text-decoration: none;
}
.btn-nav.active { color: var(--brand); }

/* ── Page wrappers ───────────────────────────────────────────────────────── */
.page        { max-width: var(--wide);           margin: 0 auto; padding: var(--space-8) var(--space-6); }
.page-narrow { max-width: var(--reading-width);  margin: 0 auto; padding: var(--space-8) var(--space-6); }
.page-wide   { max-width: var(--wide);           margin: 0 auto; padding: var(--space-8) var(--space-6); }
.page-heading {
  font-size: var(--text-2xl);
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: var(--space-6);
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0.65rem 1.4rem;
  background: var(--brand);
  color: var(--on-brand);
  border: 1px solid var(--brand);
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
  box-shadow: var(--shadow-sm);
  transition: background var(--transition-fast), transform var(--transition-fast), box-shadow var(--transition-fast);
}
.btn-primary:hover {
  background: var(--brand-hover);
  border-color: var(--brand-hover);
  color: var(--on-brand);
  text-decoration: none;
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}
.btn-primary:active { transform: translateY(0); box-shadow: var(--shadow-sm); }

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0.6rem 1.2rem;
  background: var(--surface);
  color: var(--on-surface);
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
  transition: border-color var(--transition-fast), background var(--transition-fast);
}
.btn-secondary:hover {
  background: var(--surface-container-low);
  border-color: var(--outline);
  color: var(--on-surface);
  text-decoration: none;
}

.btn-sm {
  display: inline-flex;
  align-items: center;
  padding: 0.28rem 0.7rem;
  font-size: var(--text-xs);
  font-weight: 500;
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--on-surface);
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
  white-space: nowrap;
  transition: border-color var(--transition-fast), background var(--transition-fast);
}
.btn-sm:hover {
  border-color: var(--brand);
  color: var(--brand);
  text-decoration: none;
}
.btn-danger { border-color: var(--red-line); color: var(--red-fg); }
.btn-danger:hover { background: var(--red-bg); border-color: var(--red-fg); color: var(--red-fg); }

/* ── Filter bar ──────────────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
  margin-bottom: var(--space-8);
  padding: var(--space-3);
  background: var(--surface-container);
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius-lg);
}
.filter-search {
  flex: 1;
  min-width: 200px;
  padding: 0.55rem 0.9rem;
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--on-surface);
  font-size: var(--text-base);
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.filter-search:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }
.filter-select {
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--on-surface);
  font-size: var(--text-base);
  font-family: inherit;
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition-fast);
}
.filter-select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }
.filter-btn {
  padding: 0.55rem 1.2rem;
  background: var(--brand);
  color: var(--on-brand);
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition-fast);
}
.filter-btn:hover { background: var(--brand-hover); }

/* ── Novel Grid + Cards ──────────────────────────────────────────────────── */
.novel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: var(--space-6) var(--space-5);
}
.novel-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  color: var(--on-surface);
  text-decoration: none;
  border-radius: var(--radius-md);
  transition: transform var(--transition-fast);
}
.novel-card a {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  color: var(--on-surface);
  text-decoration: none;
}
.novel-card:hover { transform: translateY(-3px); }
.novel-card:hover a { text-decoration: none; }
.novel-card:hover .novel-card-title,
.novel-card:hover .card-title {
  color: var(--brand);
}

.novel-cover {
  position: relative;
  aspect-ratio: 2/3;
  object-fit: cover;
  border-radius: var(--radius-md);
  background: var(--surface-container-low);
  width: 100%;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition-fast);
  overflow: hidden;
}
.novel-card:hover .novel-cover { box-shadow: var(--shadow-md); }
.novel-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: var(--radius-md);
}
.novel-cover-placeholder {
  aspect-ratio: 2/3;
  background: linear-gradient(135deg, var(--surface-container) 0%, var(--surface-container-low) 100%);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--on-surface-faint);
  font-size: 2.5rem;
  box-shadow: var(--shadow-sm);
}

.novel-card-body { display: flex; flex-direction: column; gap: 0.3rem; }
.card-title, .novel-card-title {
  font-weight: 600;
  font-size: var(--text-base);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  transition: color var(--transition-fast);
}
.card-author {
  font-size: var(--text-xs);
  color: var(--on-surface-variant);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-meta, .novel-card-meta {
  font-size: var(--text-xs);
  color: var(--on-surface-variant);
  display: flex;
  gap: var(--space-2);
  align-items: center;
  flex-wrap: wrap;
}
.card-tags { display: flex; gap: 0.3rem; flex-wrap: wrap; margin-top: 0.2rem; }

.tag {
  font-size: 0.68rem;
  padding: 0.14rem 0.5rem;
  background: var(--surface-container-low);
  border-radius: var(--radius-xs);
  color: var(--on-surface-variant);
  font-weight: 500;
}

/* ── Novel Detail ────────────────────────────────────────────────────────── */
.novel-header {
  display: flex;
  gap: var(--space-8);
  margin-bottom: var(--space-10);
  padding: var(--space-6);
  background: var(--surface-container);
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius-xl);
}
.novel-cover-lg { width: 170px; flex-shrink: 0; }
.novel-cover-lg img {
  border-radius: var(--radius-md);
  width: 100%;
  box-shadow: var(--shadow-lg);
}
.novel-info { flex: 1; min-width: 0; }
.novel-title {
  font-size: var(--text-3xl);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.035em;
  margin-bottom: var(--space-2);
}
.novel-author {
  color: var(--on-surface-variant);
  margin-bottom: var(--space-4);
  font-size: var(--text-md);
}
.novel-meta-row {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
}
.novel-tags {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-bottom: var(--space-5);
}
.tag-detail {
  font-size: var(--text-sm);
  padding: 0.28rem 0.7rem;
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius-pill);
  color: var(--on-surface-variant);
  transition: all var(--transition-fast);
  font-weight: 500;
}
.tag-detail:hover {
  border-color: var(--brand);
  color: var(--brand);
  background: var(--brand-soft);
  text-decoration: none;
}
.novel-description {
  color: var(--on-surface-variant);
  line-height: 1.7;
  margin-bottom: var(--space-6);
  font-size: var(--text-base);
}

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: var(--text-xs);
  padding: 0.25rem 0.7rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--outline-variant);
  background: var(--surface);
  color: var(--on-surface-variant);
  font-weight: 500;
  line-height: 1.4;
}
.badge-status-ongoing  { border-color: var(--green-line); color: var(--green-fg); background: var(--green-bg); }
.badge-status-complete { border-color: var(--blue-line);  color: var(--blue-fg);  background: var(--blue-bg); }
.badge-status-hiatus   { border-color: var(--amber-line); color: var(--amber-fg); background: var(--amber-bg); }
.badge-status-dropped  { border-color: var(--red-line);   color: var(--red-fg);   background: var(--red-bg); }
/* Dark-theme readable variants */
.theme-dark .badge-status-ongoing  { color: #4ade80; border-color: rgba(74, 222, 128, 0.35); }
.theme-dark .badge-status-complete { color: #60a5fa; border-color: rgba(96, 165, 250, 0.35); }
.theme-dark .badge-status-hiatus   { color: #fbbf24; border-color: rgba(251, 191, 36, 0.35); }
.theme-dark .badge-status-dropped  { color: #f87171; border-color: rgba(248, 113, 113, 0.35); }

/* ── Novel actions (bookmark, read, rating) ──────────────────────────────── */
.novel-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-5);
  flex-wrap: wrap;
}
.btn-bookmark {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0.6rem 1.1rem;
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--on-surface-variant);
  font-size: var(--text-base);
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: all var(--transition-fast);
}
.btn-bookmark:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }
.btn-bookmark.active {
  border-color: var(--brand);
  color: var(--brand);
  background: var(--brand-soft);
}
.btn-bookmark.active .bookmark-icon::before { content: '★'; }

/* Rating widget */
.novel-rating {
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: 1px dashed var(--outline-variant);
}
.novel-rating-label {
  font-size: var(--text-sm);
  color: var(--on-surface-variant);
  margin-bottom: var(--space-2);
}
.novel-rating-label strong { color: var(--on-surface); }
.novel-rating-stars {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  background: var(--surface-container-low);
  padding: 0.3rem 0.5rem;
  border-radius: var(--radius-md);
}
.star-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.4rem;
  line-height: 1;
  padding: 0 0.15rem;
  color: var(--outline);
  transition: color var(--transition-fast), transform var(--transition-fast);
}
.star-btn:hover { color: var(--rating-color); transform: scale(1.1); }
.star-btn--filled { color: var(--rating-color); }
.star-btn-clear {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--on-surface-variant);
  font-size: 1rem;
  margin-left: 0.4rem;
  padding: 0 0.3rem;
}
.star-btn-clear:hover { color: var(--red-fg); }

/* ── Chapter list (on novel detail) ──────────────────────────────────────── */
.chapter-section { margin-top: var(--space-10); }
.section-title {
  font-size: var(--text-md);
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--on-surface);
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: 2px solid var(--outline-variant);
  position: relative;
}
.section-title::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 36px;
  height: 2px;
  background: var(--brand);
  border-radius: var(--radius-pill);
}
.chapter-list { list-style: none; display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 0 var(--space-4); }
.chapter-item {
  border-bottom: 1px solid var(--outline-variant);
  transition: background var(--transition-fast);
}
.chapter-item:hover { background: var(--surface-container-low); }
.chapter-item a {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  padding: 0.7rem 0.5rem;
  color: var(--on-surface);
  font-size: var(--text-base);
}
.chapter-item a:hover { color: var(--brand); text-decoration: none; }
.chapter-num {
  font-size: var(--text-xs);
  color: var(--on-surface-variant);
  min-width: 3rem;
  font-weight: 500;
}
.chapter-ttl { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chapter-date { font-size: var(--text-xs); color: var(--on-surface-faint); }

/* ── Reading layout (chapter page) ───────────────────────────────────────── */
.reading-layout {
  display: flex;
  min-height: calc(100vh - var(--topbar-h));
}
.reading-sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  border-right: 1px solid var(--outline-variant);
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: var(--space-5) var(--space-3);
  background: var(--surface-container);
}
.reading-content {
  flex: 1;
  min-width: 0;
  padding: var(--space-12) var(--space-8) var(--space-16);
}
.chapter-body {
  max-width: var(--reading-width);
  margin: 0 auto;
}
.chapter-heading {
  font-size: var(--text-xl);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: var(--space-8);
  line-height: 1.3;
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--outline-variant);
}
.chapter-text {
  font-size: var(--font-size);
  line-height: var(--line-h);
  color: var(--on-surface);
}
.chapter-text p { margin-bottom: 1.2em; }

.chapter-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: var(--space-12);
  padding-top: var(--space-8);
  border-top: 1px solid var(--outline-variant);
  gap: var(--space-3);
}
.chapter-nav a {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--on-surface);
  font-size: var(--text-base);
  font-weight: 500;
  padding: 0.6rem 1rem;
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius-md);
  background: var(--surface);
  max-width: 45%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: all var(--transition-fast);
}
.chapter-nav a:hover {
  color: var(--brand);
  border-color: var(--brand);
  background: var(--brand-soft);
  text-decoration: none;
}

/* Reading layout toggles */
.sidebar-right .reading-layout { flex-direction: row-reverse; }
.sidebar-right .reading-sidebar { border-right: none; border-left: 1px solid var(--outline-variant); }
.no-topbar .topbar { display: none; }
.no-topbar .reading-sidebar { top: 0; height: 100vh; }
.no-topbar .reading-layout { min-height: 100vh; }
.no-sidebar .reading-sidebar { display: none; }

/* Sidebar chapter list */
.sidebar-novel {
  font-size: var(--text-xs);
  color: var(--on-surface-variant);
  margin-bottom: var(--space-3);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.sidebar-novel a { color: var(--on-surface); }
.sidebar-novel a:hover { color: var(--brand); }
.sidebar-chapters { list-style: none; }
.sidebar-ch a {
  display: flex;
  gap: var(--space-2);
  padding: 0.4rem 0.6rem;
  font-size: var(--text-sm);
  color: var(--on-surface-variant);
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
}
.sidebar-ch a:hover {
  background: var(--surface-container-low);
  color: var(--on-surface);
  text-decoration: none;
}
.sidebar-ch.active a {
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 600;
}
.sidebar-ch-num {
  min-width: 2rem;
  font-size: var(--text-xs);
  color: var(--on-surface-faint);
}
.sidebar-ch.active .sidebar-ch-num { color: var(--brand); }

/* ── Comments (chapter page) ─────────────────────────────────────────────── */
.comments-section {
  margin-top: var(--space-12);
  padding-top: var(--space-8);
  border-top: 1px solid var(--outline-variant);
}
.comments-title {
  font-size: var(--text-lg);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: var(--space-5);
}
.comments-empty {
  color: var(--on-surface-variant);
  font-size: var(--text-base);
  text-align: center;
  padding: var(--space-8);
  background: var(--surface-container-low);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-5);
}
.comment {
  padding: var(--space-4);
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-3);
  background: var(--surface);
  transition: border-color var(--transition-fast);
}
.comment:hover { border-color: var(--outline); }
.comment-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}
.comment-author {
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--on-surface);
}
.comment-guest {
  font-size: var(--text-xs);
  color: var(--on-surface-faint);
  font-weight: 400;
}
.comment-time {
  font-size: var(--text-xs);
  color: var(--on-surface-faint);
}
.comment-body {
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--on-surface);
  white-space: pre-wrap;
  word-wrap: break-word;
}
.comment-form {
  margin-top: var(--space-6);
  padding: var(--space-5);
  background: var(--surface-container-low);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.comment-label {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: var(--text-sm);
  color: var(--on-surface-variant);
  font-weight: 500;
}
.comment-form input[type="text"],
.comment-form textarea {
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--on-surface);
  font-size: var(--text-base);
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.comment-form input[type="text"]:focus,
.comment-form textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-ring);
}
.comment-form textarea { resize: vertical; min-height: 90px; }
.comment-form .btn-primary { align-self: flex-start; }

/* ── Pagination ──────────────────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-12);
  justify-content: center;
}
.pagination a, .pagination span {
  display: inline-flex;
  align-items: center;
  font-size: var(--text-base);
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius-md);
  color: var(--on-surface);
  background: var(--surface);
  font-weight: 500;
  transition: all var(--transition-fast);
}
.pagination a:hover {
  background: var(--brand-soft);
  border-color: var(--brand);
  color: var(--brand);
  text-decoration: none;
}
.pagination .current {
  background: var(--brand);
  color: var(--on-brand);
  border-color: var(--brand);
}

/* ── Settings panel (dropdown anchored under topbar ⚙ button) ──────────────
 * The topbar is centered with `max-width: var(--wide)` so on viewports wider
 * than --wide the right-edge of the button sits *inside* the viewport, not at
 * the right margin. We align the panel to the same gutter using a max() —
 * when viewport ≤ --wide the topbar fills the width and the panel collapses
 * back to a plain `var(--space-6)` right offset. */
.settings-panel {
  position: fixed;
  top: calc(var(--topbar-h) + var(--space-2));
  right: max(var(--space-6), calc((100vw - var(--wide)) / 2 + var(--space-6)));
  z-index: 200;
  background: var(--surface-overlay);
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  width: 288px;
  max-height: calc(100vh - var(--topbar-h) - var(--space-6));
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
  display: none;
}
.settings-panel.open { display: block; }
.settings-section { margin-bottom: var(--space-4); }
.settings-section:last-child { margin-bottom: 0; }
.settings-lbl {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--on-surface-variant);
  margin-bottom: var(--space-2);
  display: block;
}
.settings-row { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.swatch {
  flex: 1;
  min-width: 0;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--on-surface-variant);
  cursor: pointer;
  font-size: var(--text-xs);
  text-align: center;
  font-family: inherit;
  font-weight: 500;
  transition: all var(--transition-fast);
}
.swatch:hover { border-color: var(--brand); color: var(--on-surface); }
.swatch.active {
  border-color: var(--brand);
  color: var(--on-brand);
  background: var(--brand);
  font-weight: 600;
}

/* Font picker — full-width select hiển thị tên font (option có preview live) */
.font-picker {
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: var(--surface);
  color: var(--on-surface);
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius-md);
  font-family: var(--font);
  font-size: var(--text-base);
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23999'><path d='M3 6l5 5 5-5H3z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
  background-size: 14px;
  padding-right: 1.75rem;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.font-picker:hover { border-color: var(--outline); }
.font-picker:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }

/* Theme picker — vertical list of theme options, each with a colored dot */
.theme-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
  margin-bottom: var(--space-3);
}
.theme-option {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.65rem;
  background: var(--surface);
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius-sm);
  color: var(--on-surface);
  font-size: var(--text-sm);
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: border-color var(--transition-fast), background var(--transition-fast);
}
.theme-option:hover {
  border-color: var(--outline);
  background: var(--surface-container-low);
}
.theme-option.active {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--on-surface);
}
.theme-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(var(--shadow-rgb), 0.15) inset;
  flex-shrink: 0;
}

.toggle-row { display: flex; align-items: center; justify-content: space-between; margin-top: var(--space-2); }
.toggle-lbl { font-size: var(--text-sm); color: var(--on-surface); }
.toggle { position: relative; width: 36px; height: 20px; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--outline-variant);
  border-radius: 10px;
  cursor: pointer;
  transition: background var(--transition-fast);
}
.toggle input:checked + .toggle-track { background: var(--brand); }
.toggle-track::before {
  content: '';
  position: absolute;
  width: 14px; height: 14px;
  background: white;
  border-radius: 50%;
  left: 3px; top: 3px;
  transition: transform var(--transition-fast);
  box-shadow: var(--shadow-sm);
}
.toggle input:checked + .toggle-track::before { transform: translateX(16px); }

/* ── Tags page ───────────────────────────────────────────────────────────── */
.tag-category { margin-bottom: var(--space-8); }
.tag-category-name {
  font-size: var(--text-sm);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--on-surface-variant);
  margin-bottom: var(--space-3);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--outline-variant);
}
.tag-grid { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.tag-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.85rem;
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius-pill);
  font-size: var(--text-sm);
  color: var(--on-surface);
  font-weight: 500;
  transition: all var(--transition-fast);
}
.tag-item:hover {
  background: var(--brand-soft);
  border-color: var(--brand);
  color: var(--brand);
  text-decoration: none;
}
.tag-count {
  font-size: var(--text-xs);
  color: var(--on-surface-faint);
  background: var(--surface-container-low);
  padding: 0.05rem 0.4rem;
  border-radius: var(--radius-pill);
}
.tag-item:hover .tag-count { background: var(--surface); color: var(--brand); }

/* ── Auth pages (login, register, forgot, reset) ─────────────────────────── */
.auth-page {
  max-width: 420px;
  margin: var(--space-12) auto;
  padding: var(--space-8) var(--space-6);
  background: var(--surface);
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
}
.auth-subtitle {
  color: var(--on-surface-variant);
  font-size: var(--text-base);
  margin-bottom: var(--space-5);
  line-height: 1.6;
}
.auth-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  margin-top: var(--space-4);
}
.auth-label {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--on-surface);
}
.auth-input {
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--on-surface);
  font-size: var(--text-md);
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.auth-input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-ring);
}
.auth-error {
  color: var(--red-fg);
  font-size: var(--text-base);
  padding: 0.6rem 0.85rem;
  background: var(--red-bg);
  border: 1px solid var(--red-line);
  border-radius: var(--radius-md);
}
.auth-divider {
  text-align: center;
  color: var(--on-surface-variant);
  font-size: var(--text-sm);
  margin: var(--space-4) 0;
  position: relative;
}
.auth-divider::before, .auth-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 42%;
  height: 1px;
  background: var(--outline-variant);
}
.auth-divider::before { left: 0; }
.auth-divider::after { right: 0; }
.auth-oauth { display: flex; flex-direction: column; gap: var(--space-2); }
.btn-oauth {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0.65rem 1rem;
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  font-weight: 500;
  text-decoration: none;
  color: var(--on-surface);
  background: var(--surface);
  transition: all var(--transition-fast);
}
.btn-oauth:hover {
  background: var(--surface-container-low);
  border-color: var(--outline);
  text-decoration: none;
}
.auth-footer {
  text-align: center;
  font-size: var(--text-base);
  color: var(--on-surface-variant);
  margin-top: var(--space-5);
}
.auth-footer a { color: var(--brand); font-weight: 500; }

/* ── Homepage ────────────────────────────────────────────────────────────── */
.home-hero {
  position: relative;
  margin: 0 auto var(--space-10);
  padding: var(--space-16) var(--space-8);
  background: var(--hero-gradient);
  border-radius: var(--radius-xl);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-5);
  overflow: hidden;
}
.home-hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 80% 20%, var(--brand-soft) 0%, transparent 55%);
  pointer-events: none;
}
.home-hero > * { position: relative; z-index: 1; }
.home-tagline {
  font-size: var(--text-hero);
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -0.04em;
  color: var(--on-surface);
  max-width: 720px;
}
.home-hero .btn-primary { font-size: var(--text-md); padding: 0.75rem 1.6rem; }
.home-section { margin-top: var(--space-10); }
.home-section-hd {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: var(--space-5);
}
.home-section-hd .section-title { border-bottom: none; padding-bottom: 0; margin-bottom: 0; }
.home-section-hd .section-title::after { display: none; }
.home-section-hd .section-title { font-size: var(--text-xl); }
.home-more {
  font-size: var(--text-base);
  color: var(--on-surface-variant);
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  transition: color var(--transition-fast), gap var(--transition-fast);
}
.home-more:hover { color: var(--brand); gap: 0.5rem; }

/* ── Notifications page ──────────────────────────────────────────────────── */
.notifications-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-6);
  gap: var(--space-4);
  flex-wrap: wrap;
}
.notifications-header .page-heading { margin-bottom: 0; }
.notifications-list { list-style: none; display: flex; flex-direction: column; gap: var(--space-2); }
.notification {
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  transition: border-color var(--transition-fast);
}
.notification:hover { border-color: var(--outline); }
.notification--unread {
  background: var(--brand-soft);
  border-color: color-mix(in srgb, var(--brand) 30%, transparent);
}
.notification-link {
  flex: 1;
  color: var(--on-surface);
  font-size: var(--text-base);
}
.notification-link:hover { color: var(--brand); text-decoration: none; }
.notification-link strong { color: var(--brand); font-weight: 700; margin-right: 0.3rem; }
.notification-text { flex: 1; font-size: var(--text-base); color: var(--on-surface); }
.notification-time { font-size: var(--text-xs); color: var(--on-surface-faint); white-space: nowrap; }

.empty-state {
  text-align: center;
  padding: var(--space-16) var(--space-4);
  color: var(--on-surface-variant);
  font-size: var(--text-base);
}

/* ── History list ────────────────────────────────────────────────────────── */
.history-list { list-style: none; }
.history-item {
  border-bottom: 1px solid var(--outline-variant);
  transition: background var(--transition-fast);
}
.history-item:hover { background: var(--surface-container-low); }
.history-item a {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-2);
  color: var(--on-surface);
  text-decoration: none;
}
.history-item a:hover { color: var(--brand); }
.history-cover {
  width: 56px;
  height: 84px;
  flex-shrink: 0;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--surface-container-low);
  box-shadow: var(--shadow-sm);
}
.history-cover-ph {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  color: var(--on-surface-faint);
}
.history-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.2rem; }
.history-title { font-size: var(--text-base); font-weight: 600; line-height: 1.3; }
.history-ch { font-size: var(--text-sm); color: var(--brand); font-weight: 500; }
.history-date { font-size: var(--text-xs); color: var(--on-surface-faint); }
.history-arrow { color: var(--on-surface-variant); font-size: var(--text-md); }

/* ── Account settings page ──────────────────────────────────────────────── */
.settings-card {
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  margin-bottom: var(--space-5);
  background: var(--surface);
}
.settings-card-hd {
  font-size: var(--text-md);
  font-weight: 700;
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--outline-variant);
}
.alert-ok {
  color: var(--green-fg);
  background: var(--green-bg);
  border: 1px solid var(--green-line);
  border-radius: var(--radius-md);
  padding: 0.6rem 0.85rem;
  font-size: var(--text-base);
  margin-bottom: var(--space-5);
}
.alert-err {
  color: var(--red-fg);
  background: var(--red-bg);
  border: 1px solid var(--red-line);
  border-radius: var(--radius-md);
  padding: 0.6rem 0.85rem;
  font-size: var(--text-base);
  margin-bottom: var(--space-5);
}

/* ── Admin panel ─────────────────────────────────────────────────────────── */
.admin-wrap { display: flex; min-height: 100vh; }
.admin-sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface-container);
  border-right: 1px solid var(--outline-variant);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.admin-logo {
  font-weight: 800;
  font-size: var(--text-md);
  margin-bottom: var(--space-6);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  letter-spacing: -0.02em;
}
.admin-logo a { color: var(--on-surface); }
.admin-tag {
  font-size: 0.6rem;
  background: var(--brand);
  color: var(--on-brand);
  padding: 0.15rem 0.4rem;
  border-radius: var(--radius-xs);
  letter-spacing: 0.05em;
  font-weight: 700;
  text-transform: uppercase;
}
.admin-nav { display: flex; flex-direction: column; gap: 0.2rem; flex: 1; }
.admin-nav-link {
  font-size: var(--text-base);
  color: var(--on-surface-variant);
  padding: 0.5rem 0.7rem;
  border-radius: var(--radius-md);
  display: block;
  font-weight: 500;
  transition: all var(--transition-fast);
}
.admin-nav-link:hover {
  background: var(--surface-container-low);
  color: var(--on-surface);
  text-decoration: none;
}
.admin-nav-link.active {
  background: var(--brand-soft);
  color: var(--brand);
}
.admin-sidebar-footer { margin-top: var(--space-4); }
.admin-main {
  flex: 1;
  padding: var(--space-8) var(--space-10);
  min-width: 0;
}
.admin-page-hd {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--space-6);
  gap: var(--space-4);
}
.admin-page-title {
  font-size: var(--text-2xl);
  font-weight: 800;
  letter-spacing: -0.03em;
}
.admin-breadcrumb {
  font-size: var(--text-sm);
  color: var(--on-surface-variant);
  margin-bottom: 0.3rem;
}
.admin-breadcrumb a { color: var(--on-surface-variant); }
.admin-breadcrumb a:hover { color: var(--brand); }
.admin-stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-8);
}
.admin-stat {
  background: var(--surface);
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  transition: border-color var(--transition-fast);
}
.admin-stat:hover { border-color: var(--brand); }
.admin-stat-value {
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1.1;
}
.admin-stat-label {
  font-size: var(--text-sm);
  color: var(--on-surface-variant);
  margin-top: 0.3rem;
  font-weight: 500;
}
.admin-search-bar {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-5);
}
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-base);
}
.admin-table th {
  text-align: left;
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--on-surface-variant);
  padding: 0.6rem 0.75rem;
  border-bottom: 2px solid var(--outline-variant);
  white-space: nowrap;
}
.admin-table td {
  padding: 0.75rem;
  border-bottom: 1px solid var(--outline-variant);
  vertical-align: middle;
}
.admin-table tr:hover td { background: var(--surface-container-low); }
.admin-actions { display: flex; gap: 0.4rem; align-items: center; }
.admin-muted { color: var(--on-surface-variant); }
.admin-pagination { display: flex; align-items: center; gap: var(--space-3); margin-top: var(--space-6); }
.admin-form { max-width: 720px; display: flex; flex-direction: column; gap: var(--space-4); }
.admin-field { display: flex; flex-direction: column; gap: 0.4rem; }
.admin-field label { font-size: var(--text-base); font-weight: 600; }
.admin-row { display: flex; gap: var(--space-4); }
.admin-row .admin-field { flex: 1; }
.admin-input, .admin-select, .admin-textarea {
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--on-surface);
  font-size: var(--text-base);
  outline: none;
  font-family: inherit;
  width: 100%;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.admin-input:focus,
.admin-select:focus,
.admin-textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-ring);
}
.admin-textarea { resize: vertical; min-height: 100px; }
.admin-textarea-content { min-height: 420px; font-size: var(--text-base); line-height: 1.6; }

/* ── Small inline label (eg. "guest" on a comment row) ──────────────────── */
.admin-badge {
  display: inline-block;
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: var(--surface-container-low);
  color: var(--on-surface-variant);
  margin-left: 0.4rem;
  vertical-align: middle;
}
.admin-badge-read {
  background: color-mix(in srgb, var(--brand) 15%, transparent);
  color: var(--brand);
}

/* ── Soft-deleted comment row ───────────────────────────────────────────── */
.admin-row-muted td {
  opacity: 0.55;
  background: var(--surface-container-low);
}

/* ── Inline form error (between header + form) ─────────────────────────── */
.admin-error {
  background: color-mix(in srgb, #b00020 10%, transparent);
  color: #b00020;
  border-left: 3px solid #b00020;
  padding: 0.7rem 1rem;
  border-radius: var(--radius-md);
  margin-bottom: var(--space-4);
  max-width: 720px;
}

/* ── JSON payload preview in notifications table ───────────────────────── */
.admin-payload {
  font-family: var(--font-mono, ui-monospace, Consolas, monospace);
  font-size: var(--text-xs);
  background: var(--surface-container-low);
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius-sm);
  white-space: pre-wrap;
  word-break: break-all;
  margin: 0;
  max-width: 480px;
  max-height: 6rem;
  overflow: auto;
  color: var(--on-surface);
}

/* ── Star rating cell ──────────────────────────────────────────────────── */
.admin-rating {
  display: inline-block;
  font-weight: 600;
  color: #d97706;       /* amber-600 — readable on light + dark surface */
  white-space: nowrap;
}

/* ── Comment body cell: wrap long text, cap width ──────────────────────── */
.admin-comment-body {
  max-width: 38rem;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* ── Card grid on detail pages ─────────────────────────────────────────── */
.admin-detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: var(--space-5);
}
.admin-card {
  background: var(--surface);
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}
.admin-card-title {
  font-size: var(--text-lg);
  font-weight: 700;
  margin: 0 0 var(--space-4);
  color: var(--on-surface);
}

/* Description list (Profile box) */
.admin-dl {
  display: grid;
  grid-template-columns: 7rem 1fr;
  gap: 0.4rem 1rem;
  font-size: var(--text-base);
  margin: 0;
}
.admin-dl dt {
  color: var(--on-surface-variant);
  font-weight: 600;
}
.admin-dl dd {
  margin: 0;
  word-break: break-word;
}

/* Compact table for the identities list */
.admin-table-compact th,
.admin-table-compact td {
  padding: 0.4rem 0.5rem;
  font-size: var(--text-sm);
}

/* Stat grid sized down for the activity card */
.admin-stat-grid-sm {
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: var(--space-3);
  margin-bottom: 0;
}
.admin-stat-grid-sm .admin-stat {
  padding: var(--space-3);
}
.admin-stat-grid-sm .admin-stat-value {
  font-size: 1.6rem;
}

/* Action list inside the Actions card */
.admin-action-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.admin-action-list form {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

/* Reset password banner — prominently shows the one-shot URL */
.admin-reset-banner {
  background: color-mix(in srgb, var(--brand) 8%, transparent);
  border: 1px solid var(--brand);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  margin-bottom: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.admin-reset-link {
  font-family: var(--font-mono, ui-monospace, Consolas, monospace);
  font-size: var(--text-sm);
  background: var(--surface);
}

/* ── 404 page ────────────────────────────────────────────────────────────── */
.not-found { text-align: center; padding: var(--space-16) var(--space-4); }
.not-found-code {
  font-size: 6rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1;
  margin-bottom: var(--space-3);
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-hover) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.not-found-msg {
  color: var(--on-surface-variant);
  margin-bottom: var(--space-8);
  font-size: var(--text-md);
}

/* ── Misc ────────────────────────────────────────────────────────────────── */
.empty { text-align: center; padding: var(--space-16) var(--space-4); color: var(--on-surface-variant); }
.muted { color: var(--on-surface-variant); }
.rating { color: var(--rating-color); }

/* ── Reading progress bar (top of viewport) ──────────────────────────────── */
#reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--brand) 0%, var(--brand-hover) 100%);
  z-index: 300;
  transition: width 100ms linear;
}

/* ── Code blocks ─────────────────────────────────────────────────────────── */
.prose pre {
  background: var(--surface-container-low);
  padding: var(--space-5);
  margin: var(--space-5) 0;
  overflow-x: auto;
  border-radius: var(--radius-md);
  position: relative;
  border: 1px solid var(--outline-variant);
}
.prose pre code {
  font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', Consolas, 'Liberation Mono', Menlo, 'Courier New', monospace;
  font-size: 0.875rem;
  line-height: 1.7;
  color: var(--on-surface);
}
.prose code {
  font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', Consolas, 'Liberation Mono', Menlo, 'Courier New', monospace;
  font-size: 0.875em;
  background: var(--surface-container-low);
  padding: 0.12em 0.4em;
  border-radius: var(--radius-xs);
}
.copy-btn {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--on-surface-variant);
  background: var(--surface);
  border: 1px solid var(--outline-variant);
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}
.copy-btn:hover { color: var(--brand); border-color: var(--brand); }

/* ── Search overlay ──────────────────────────────────────────────────────── */
.search-overlay {
  display: flex;
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  align-items: flex-start;
  justify-content: center;
  padding-top: 7rem;
  animation: fadeIn 150ms ease;
}
.search-overlay[hidden] { display: none; }
.search-overlay-inner {
  width: 100%;
  max-width: 38rem;
  padding: 0 var(--space-4);
}
.search-overlay-form {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  background: var(--surface-overlay);
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius-lg);
  padding: 0.85rem 1.1rem;
  box-shadow: var(--shadow-xl);
}
.search-overlay-form input[type="search"] {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-size: var(--text-md);
  font-family: inherit;
  color: var(--on-surface);
  min-width: 0;
}
.search-overlay-form input[type="search"]::placeholder {
  color: var(--on-surface-faint);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  :root {
    --topbar-h: 52px;
  }
  .topbar-inner { padding: 0 var(--space-4); }
  .page, .page-narrow, .page-wide { padding: var(--space-5) var(--space-4); }
  .novel-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: var(--space-4) var(--space-3); }
  .novel-header { flex-direction: column; padding: var(--space-4); gap: var(--space-4); }
  .novel-cover-lg { width: 130px; align-self: center; }
  .novel-title { font-size: var(--text-2xl); }
  .reading-sidebar { display: none; }
  .reading-content { padding: var(--space-6) var(--space-4) var(--space-12); }
  .home-hero { padding: var(--space-10) var(--space-5); margin-bottom: var(--space-6); }
  .chapter-list { grid-template-columns: 1fr; }
  .chapter-nav { flex-direction: column; gap: var(--space-2); }
  .chapter-nav a { max-width: 100%; width: 100%; justify-content: center; }
  .settings-panel { right: 0.75rem; left: 0.75rem; width: auto; top: calc(var(--topbar-h) + 0.5rem); }
  .admin-sidebar { display: none; }
  .admin-main { padding: var(--space-5) var(--space-4); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
