/* ==========================================================================
   Calibre Companion — Design System
   Dark theme · Glassmorphism · Premium aesthetic
   ========================================================================== */

/* ---------- Design Tokens ---------- */
:root {
  /* Surfaces */
  --bg-root: #0c0e14;
  --bg-sidebar: #10131a;
  --bg-card: rgba(22, 27, 38, 0.75);
  --bg-card-hover: rgba(30, 37, 52, 0.85);
  --bg-elevated: rgba(28, 34, 48, 0.9);
  --bg-input: rgba(18, 22, 32, 0.8);
  --bg-modal: rgba(16, 20, 30, 0.97);

  /* Borders */
  --border-subtle: rgba(var(--tint-rgb), 0.06);
  --border-medium: rgba(var(--tint-rgb), 0.1);
  --border-accent: rgba(232, 178, 80, 0.3);

  /* Text */
  --text-primary: #e8ecf4;
  --text-secondary: #8b95a8;
  --text-muted: #5a6478;
  --text-accent: #e8b250;

  /* Accent palette */
  --accent: #e8b250;
  --accent-hover: #f0c46a;
  --accent-muted: rgba(232, 178, 80, 0.15);
  --accent-glow: rgba(232, 178, 80, 0.08);

  /* Solid accent for filled buttons (dark text on gold) — stays vibrant in both themes */
  --accent-solid: #e8b250;
  --accent-solid-hover: #f0c46a;
  --accent-solid-ink: #1a1400;

  /* Semantic */
  --success: #4ade80;
  --success-bg: rgba(74, 222, 128, 0.1);
  --warning: #fbbf24;
  --warning-bg: rgba(251, 191, 36, 0.1);
  --danger: #f87171;
  --danger-bg: rgba(248, 113, 113, 0.1);
  --info: #60a5fa;
  --status-completed: #14532d;
  --status-in-progress: #7c5c00;
  --status-abandoned: #5c1626;
  --status-published: #163a63;
  --status-reading: #1d4ed8;

  /* Spacing */
  --sidebar-width: 260px;
  --topbar-height: 64px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 30px rgba(232, 178, 80, 0.06);

  /* White tint base for hover/surface washes (flips to ink in light theme) */
  --tint-rgb: 255, 255, 255;

  /* Transitions */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --duration: 0.2s;
  --duration-slow: 0.35s;
}


/* ---------- Light Theme ---------- */
[data-theme="light"] {
  /* Surfaces */
  --bg-root: #f4f3ef;
  --bg-sidebar: #faf9f6;
  --bg-card: rgba(255, 255, 255, 0.82);
  --bg-card-hover: rgba(255, 255, 255, 0.95);
  --bg-elevated: rgba(255, 255, 255, 0.97);
  --bg-input: rgba(255, 255, 255, 0.85);
  --bg-modal: rgba(252, 251, 248, 0.98);

  /* Borders */
  --border-subtle: rgba(15, 23, 42, 0.09);
  --border-medium: rgba(15, 23, 42, 0.16);
  --border-accent: rgba(154, 108, 26, 0.4);

  /* Text */
  --text-primary: #1c2331;
  --text-secondary: #4d5668;
  --text-muted: #707a8e;
  --text-accent: #92600d;

  /* Accent palette (darkened for contrast on light surfaces) */
  --accent: #b07c15;
  --accent-hover: #94670e;
  --accent-muted: rgba(176, 124, 21, 0.14);
  --accent-glow: rgba(176, 124, 21, 0.08);

  /* Semantic */
  --success: #15803d;
  --success-bg: rgba(21, 128, 61, 0.12);
  --warning: #a16207;
  --warning-bg: rgba(161, 98, 7, 0.12);
  --danger: #b91c1c;
  --danger-bg: rgba(185, 28, 28, 0.1);
  --info: #1d4ed8;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.1);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.12);
  --shadow-lg: 0 8px 32px rgba(15, 23, 42, 0.16);
  --shadow-glow: 0 0 30px rgba(176, 124, 21, 0.08);

  /* Ink tint replaces white tint for hover/surface washes */
  --tint-rgb: 15, 23, 42;
}

/* ---------- Reset & Base ---------- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-root);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  overflow-x: hidden;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--duration) var(--ease);
}

a:hover {
  color: var(--accent-hover);
}

img {
  max-width: 100%;
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(var(--tint-rgb), 0.1);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(var(--tint-rgb), 0.18);
}

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform var(--duration-slow) var(--ease);
}

.sidebar-header {
  padding: 24px 20px;
  border-bottom: 1px solid var(--border-subtle);
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  width: 28px;
  height: 28px;
  color: var(--accent);
  flex-shrink: 0;
}

.logo-text {
  font-size: 0.95rem;
  font-weight: 300;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
}

.logo-text strong {
  color: var(--text-primary);
  font-weight: 600;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 450;
  transition: all var(--duration) var(--ease);
  text-decoration: none;
}

.nav-link svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.65;
  transition: opacity var(--duration) var(--ease);
}

.nav-link:hover {
  background: rgba(var(--tint-rgb), 0.04);
  color: var(--text-primary);
}

.nav-link:hover svg {
  opacity: 0.9;
}

.nav-link.active {
  background: var(--accent-muted);
  color: var(--accent);
}

.nav-link.active svg {
  opacity: 1;
  color: var(--accent);
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border-subtle);
}

.nav-link-small {
  font-size: 0.8rem;
  padding: 8px 14px;
}

/* Sidebar collapse */
.sidebar-collapsed .sidebar {
  transform: translateX(-100%);
}

.sidebar-collapsed .main-content {
  margin-left: 0;
  width: 100%;
}

/* ---------- Main Content ---------- */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  width: calc(100% - var(--sidebar-width));
  min-width: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left var(--duration-slow) var(--ease);
}

/* ---------- Top Bar ---------- */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 16px;
  padding: 12px 32px;
  min-height: var(--topbar-height);
  height: auto;
  background: rgba(12, 14, 20, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: all var(--duration) var(--ease);
}

.sidebar-toggle:hover {
  background: rgba(var(--tint-rgb), 0.06);
  color: var(--text-primary);
}

.sidebar-toggle svg {
  width: 20px;
  height: 20px;
}

.page-title {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  /* Full title when space allows; the huge flex-shrink makes the title (not
     the top-bar actions) absorb the squeeze on narrow screens, ellipsizing
     via .page-title-text. */
  flex: 0 999 auto;
  min-width: 0;
}

.page-title-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.page-title-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.05em;
  height: 1.05em;
  flex-shrink: 0;
  background: transparent;
}

.page-title-icon svg {
  width: 100%;
  height: 100%;
}

.page-title-icon-book {
  color: #b45309;
}

.page-title-icon-tag {
  color: #991b1b;
}

.page-title-icon-bookshelf {
  color: #5b3715;
}

.page-title-icon-author-shelf {
  color: #5b2f88;
}

.page-title-icon-author {
  color: #a855f7;
}

.page-title-icon-author-avatar {
  width: 1.45em;
  height: 1.45em;
  border-radius: 50%;
  overflow: hidden;
  border: 1px solid rgba(250, 204, 21, 0.55);
  box-shadow: 0 0 0 2px rgba(250, 204, 21, 0.14);
  transition: transform var(--duration) var(--ease), box-shadow var(--duration) var(--ease);
}

.page-title-icon-author-avatar:hover,
.page-title-icon-author-avatar:focus-visible {
  transform: scale(1.06);
  box-shadow: 0 0 0 2px rgba(250, 204, 21, 0.26);
}

.page-title-icon-author-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.page-title-icon-quote {
  color: #1e3a8a;
}

.page-title-icon-reading {
  color: #166534;
}

.page-title-icon-fandom {
  color: #d97706;
}

.top-bar-actions {
  margin-left: auto;
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  flex-wrap: nowrap;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
}

.fandom-actions-pill {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px 4px 2px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-medium);
  background: rgba(var(--tint-rgb), 0.04);
  min-height: 34px;
}

.fandom-actions-label {
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
  padding-right: 4px;
}

.fandom-action-icon-btn {
  width: 34px;
  height: 34px;
  border: 1px solid var(--border-medium);
  border-radius: 10px;
  background: rgba(var(--tint-rgb), 0.08);
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(var(--tint-rgb), 0.08);
  transition: all var(--duration) var(--ease);
}

.fandom-action-icon-btn:hover {
  background: rgba(var(--tint-rgb), 0.16);
  border-color: var(--border-strong);
}

.fandom-action-icon-btn.active {
  background: var(--accent-muted);
  color: var(--accent);
}

.fandom-action-icon-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.fandom-action-icon-btn svg {
  width: 17px;
  height: 17px;
}

.search-form {
  flex: 1 1 360px;
  min-width: 220px;
  max-width: 760px;
}

.sort-form {
  flex: 0 0 auto;
}

.sort-form {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sort-form.sort-form-disabled {
  opacity: 0.5;
  pointer-events: none;
}

.sort-select {
  background: var(--bg-input);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font: inherit;
  font-size: 0.84rem;
  padding: 8px 12px;
  min-width: 150px;
  outline: none;
  transition: all var(--duration) var(--ease);
}

.sort-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

.sort-direction-btn {
  min-width: 34px;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: all var(--duration) var(--ease);
}

.sort-direction-btn:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

.sort-direction-btn svg {
  width: 16px;
  height: 16px;
}

.sort-direction-label {
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.sort-direction-btn.sort-direction-asc svg {
  transform: rotate(180deg);
}

.sort-direction-btn.sort-direction-desc svg {
  transform: rotate(0deg);
}

/* ---------- New Search/Sort UI Controls ---------- */

/* Clear Search Button */
.search-clear-btn {
  position: absolute;
  right: 10px;
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 1.2rem;
  font-weight: 300;
  cursor: pointer;
  transition: color var(--duration) var(--ease);
  padding: 0;
  flex-shrink: 0;
}

.search-clear-btn:hover {
  color: var(--text-primary);
}

/* Search Filter Container & Dropdown */
.search-filter-container {
  position: relative;
  flex: 0 0 auto;
}

.search-filter-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 34px;
  padding: 0 10px;
  background: rgba(var(--tint-rgb), 0.08);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: all var(--duration) var(--ease);
  gap: 6px;
}

.search-filter-btn:hover {
  background: rgba(var(--tint-rgb), 0.12);
  border-color: var(--border-medium);
  color: var(--text-primary);
}

.search-filter-btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.search-filter-label {
  white-space: nowrap;
}

/* EPUB open/download split button (book detail). */
.epub-menu-container {
  position: relative;
  display: inline-flex;
}

.epub-menu-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 90;
  background: var(--bg-elevated);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  min-width: 180px;
}

.epub-menu-option {
  width: 100%;
  display: block;
  background: transparent;
  border: none;
  color: var(--text-primary);
  text-align: left;
  padding: 10px 16px;
  font: inherit;
  font-size: 0.875rem;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--duration) var(--ease);
}

.epub-menu-option:hover {
  background: rgba(var(--tint-rgb), 0.08);
}

/* Count badge on the library "Advanced filters" button. */
.search-filter-count {
  margin-left: 6px;
  min-width: 16px;
  padding: 0 5px;
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1.5;
  color: var(--info);
  background: rgba(96, 165, 250, 0.14);
  border: 1px solid rgba(96, 165, 250, 0.35);
  border-radius: 9px;
  text-align: center;
}

/* Library-mode filter panel result rows are links, not checkbox labels. */
.ff-result-link {
  text-decoration: none;
  color: inherit;
}

.search-filter-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 90;
  background: var(--bg-elevated);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  min-width: 160px;
}

.search-filter-option {
  width: 100%;
  display: block;
  background: transparent;
  border: none;
  color: var(--text-primary);
  text-align: left;
  padding: 10px 16px;
  font: inherit;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background var(--duration) var(--ease);
}

.search-filter-option:hover {
  background: rgba(var(--tint-rgb), 0.08);
}

.search-filter-option--selected {
  background: rgba(59, 130, 246, 0.15);
  color: #93c5fd;
  font-weight: 500;
}

/* Sort Button Container & Dropdown */
.sort-button-container {
  position: relative;
  flex: 0 0 auto;
}

.sort-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 2.125rem;
  width: 2.125rem;
  padding: 0;
  background: rgba(var(--tint-rgb), 0.08);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--duration) var(--ease);
}

.sort-button:hover {
  background: rgba(var(--tint-rgb), 0.12);
  border-color: var(--accent);
  color: var(--text-primary);
}

.shelf-card-dragging {
  opacity: 0.45;
}

/* ---------- Book Detail Prev/Next Navigation ---------- */
.book-nav-strip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.book-nav-back {
  color: var(--text-secondary);
  font-size: 0.82rem;
  text-decoration: none;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-right: 4px;
}

.book-nav-back:hover {
  color: var(--accent);
}

/* Doubled class beats the later base .btn rule (same specificity would lose
   on source order), keeping these slimmer than standard buttons. */
.book-nav-btn.book-nav-btn {
  padding: 2px 10px;
  font-size: 0.82rem;
  line-height: 1.4;
}

.book-nav-btn svg {
  width: 14px;
  height: 14px;
}

.book-nav-btn-disabled {
  opacity: 0.35;
  pointer-events: none;
}

.book-nav-position {
  color: var(--text-secondary);
  font-size: 0.82rem;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.sort-button.sort-button-grid-accent {
  background: var(--accent-solid);
  border-color: var(--accent-solid);
  color: var(--accent-solid-ink);
}

.sort-button.sort-button-grid-accent:hover {
  background: var(--accent-solid-hover);
  border-color: var(--accent-solid-hover);
  color: var(--accent-solid-ink);
  box-shadow: 0 4px 12px rgba(232, 178, 80, 0.3);
}

.sort-button-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.sort-button-icon svg {
  width: 14px;
  height: 14px;
}

.sort-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 90;
  background: var(--bg-elevated);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  min-width: 200px;
  max-height: 400px;
  overflow-y: auto;
}

.sort-dropdown-section {
  border-bottom: 1px solid var(--border-subtle);
}

.sort-dropdown-section:last-child {
  border-bottom: none;
}

.sort-dropdown-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
}

.sort-dropdown-label {
  color: var(--text-primary);
  font-size: 0.84rem;
  line-height: 1.2;
  display: inline-flex;
  align-items: center;
}

.sort-dropdown-info {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 0.9375rem;
  height: 0.9375rem;
  margin-left: 6px;
  border: 1px solid var(--border-medium);
  border-radius: 50%;
  color: var(--text-secondary);
  font-size: 0.62rem;
  font-style: normal;
  cursor: help;
  flex: 0 0 auto;
}

.sort-dropdown-info:hover,
.sort-dropdown-info:focus {
  border-color: var(--accent);
  color: var(--text-primary);
  outline: none;
}

.sort-dropdown-info::after {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 95;
  width: 170px;
  padding: 7px 9px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  color: var(--text-secondary);
  font-size: 0.74rem;
  line-height: 1.35;
  white-space: normal;
  visibility: hidden;
  opacity: 0;
  transition: opacity var(--duration) var(--ease);
}

.sort-dropdown-info:hover::after,
.sort-dropdown-info:focus::after {
  visibility: visible;
  opacity: 1;
}

.sort-dropdown-arrow-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.sort-dropdown-option {
  background: transparent;
  border: none;
  color: var(--text-primary);
  font: inherit;
  cursor: pointer;
}

.sort-dropdown-arrow-btn {
  width: 1.75rem;
  height: 1.5rem;
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--duration) var(--ease);
}

.sort-dropdown-arrow-btn svg {
  width: 14px;
  height: 14px;
}

.sort-dropdown-arrow-btn:hover {
  background: rgba(var(--tint-rgb), 0.08);
  border-color: var(--border-medium);
  color: var(--text-primary);
}

.sort-dropdown-option--selected {
  background: rgba(59, 130, 246, 0.15);
  border-color: rgba(59, 130, 246, 0.45);
  color: #93c5fd;
}

/* ---------- Content Area ---------- */
.content-area {
  flex: 1;
  padding: 28px 32px 48px;
}

/* ---------- Search ---------- */
.search-form {
  display: flex;
  min-width: 0;
}

.search-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
  min-width: 0;
}

.search-input-shell {
  width: 100%;
  min-width: 0;
  min-height: 40px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  align-content: center;
  gap: 6px;
  padding: 4px 146px 4px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  transition: all var(--duration) var(--ease);
}

.search-form-library .search-input-shell {
  padding-right: 184px;
}

.search-input-shell-simple {
  padding-right: 46px;
}

.search-input-shell:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

.search-suggestions {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  width: 100%;
  min-width: 320px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  z-index: 80;
  max-height: 280px;
  overflow-y: auto;
}

.search-suggestion {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  border: none;
  color: var(--text-primary);
  text-align: left;
  padding: 9px 12px;
  cursor: pointer;
  font: inherit;
  transition: background var(--duration) var(--ease);
}

.search-suggestion:hover,
.search-suggestion.active {
  background: rgba(var(--tint-rgb), 0.07);
}

.search-suggestion-type {
  display: inline-flex;
  min-width: 52px;
  justify-content: center;
  padding: 2px 6px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.search-suggestion-type-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  padding: 0;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: rgba(var(--tint-rgb), 0.05);
  color: var(--text-secondary);
}

.search-suggestion-type-pill svg {
  width: 0.78rem;
  height: 0.78rem;
}

.search-suggestion-type-pill-tag {
  color: #991b1b;
}

.search-suggestion-type-pill-author {
  color: #a855f7;
}

.search-suggestion-type-pill-book {
  color: #b45309;
}

.search-suggestion-type-pill-series {
  color: #0d9488;
}

.search-suggestion-type-pill-my-tag {
  color: #db2777;
}

.search-suggestion-label {
  font-size: 0.85rem;
  line-height: 1.3;
}

.search-icon {
  position: absolute;
  left: 12px;
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-input {
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 4px 0;
  font-size: 0.875rem;
  font-family: inherit;
  color: var(--text-primary);
  flex: 1 1 180px;
  min-width: 120px;
  width: auto;
  transition: color var(--duration) var(--ease);
  outline: none;
}

.search-input::placeholder {
  color: var(--text-muted);
}

.search-input:focus {
  border: none;
  box-shadow: none;
}

.search-match-mode-btn {
  position: absolute;
  right: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 28px;
  padding: 0 10px;
  background: rgba(var(--tint-rgb), 0.08);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: all var(--duration) var(--ease);
}

.search-match-mode-btn:hover {
  background: rgba(var(--tint-rgb), 0.12);
  border-color: var(--border-medium);
  color: var(--text-primary);
}

.search-match-mode-btn.match-any {
  background: rgba(59, 130, 246, 0.15);
  border-color: rgba(59, 130, 246, 0.3);
  color: #93c5fd;
}

.search-match-mode-btn.match-any:hover {
  background: rgba(59, 130, 246, 0.25);
  border-color: rgba(59, 130, 246, 0.5);
}

.search-match-mode-label {
  text-transform: uppercase;
}

.search-submit-btn {
  position: absolute;
  right: 112px;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(var(--tint-rgb), 0.08);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--duration) var(--ease);
}

.search-input-shell-simple + .search-submit-btn {
  right: 10px;
}

.search-submit-btn:hover {
  background: rgba(var(--tint-rgb), 0.14);
  border-color: var(--border-medium);
  color: var(--text-primary);
}

.search-submit-btn svg {
  width: 14px;
  height: 14px;
}

.search-token-pills {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  flex: 0 1 auto;
  min-width: 0;
  max-width: 100%;
}

.search-form-library .search-token-pills {
  max-width: 100%;
}

.search-token-pills:empty {
  display: none;
}

.search-token-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 176px;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: rgba(var(--tint-rgb), 0.05);
  color: var(--text-secondary);
  font-size: 0.72rem;
  line-height: 1.25;
  white-space: nowrap;
}

.search-form-library .search-token-pill {
  max-width: 164px;
}

.search-token-pill-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-token-pill-symbol {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 0.86rem;
  height: 0.86rem;
  flex-shrink: 0;
  line-height: 1;
}

.search-token-pill-symbol svg {
  width: 100%;
  height: 100%;
}

.search-token-pill-symbol-tag {
  color: #991b1b;
}

.search-token-pill-symbol-author {
  color: #a855f7;
}

.search-token-pill-symbol-book {
  color: #b45309;
}

.search-token-pill-symbol-series {
  color: #0d9488;
}

.search-token-pill-symbol-my-tag {
  color: #db2777;
}

.search-token-pill-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: inherit;
  opacity: 0.78;
  font: inherit;
  font-weight: 700;
  line-height: 1.2;
  padding: 0;
  margin-left: 2px;
  flex-shrink: 0;
  cursor: pointer;
}

.search-token-pill-remove:hover {
  opacity: 1;
}

.search-token-pill-tag {
  color: var(--text-secondary);
  border-color: var(--border-subtle);
  background: rgba(var(--tint-rgb), 0.05);
}

.search-token-pill-exclude {
  color: #fecaca;
  border-color: rgba(248, 113, 113, 0.3);
  background: rgba(153, 27, 27, 0.25);
}

.search-token-pill-series {
  color: var(--text-secondary);
  border-color: rgba(13, 148, 136, 0.35);
  background: rgba(13, 148, 136, 0.12);
}

.search-token-pill-my-tag {
  color: var(--text-secondary);
  border-color: rgba(219, 39, 119, 0.35);
  background: rgba(219, 39, 119, 0.12);
}

.search-token-pill-text {
  color: var(--text-secondary);
}

/* ---------- Stats Bar ---------- */
.stats-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.reading-stats-disclosure {
  margin-bottom: 20px;
}

.reading-stats-disclosure .reading-stats-panel {
  margin-bottom: 0;
}

.reading-stats-summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 2px 10px;
  color: var(--text-secondary);
  font-size: 0.82rem;
  user-select: none;
}

.reading-stats-summary::-webkit-details-marker {
  display: none;
}

.reading-stats-summary-arrow {
  font-size: 0.7rem;
  color: var(--text-muted);
  transition: transform var(--duration) var(--ease);
}

.reading-stats-disclosure[open] .reading-stats-summary-arrow {
  transform: rotate(90deg);
}

.reading-stats-summary-title {
  font-weight: 600;
  color: var(--text-primary);
}

.reading-stats-summary-meta {
  color: var(--text-muted);
  font-size: 0.76rem;
}

.reading-stats-panel {
  margin-bottom: 20px;
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: rgba(12, 14, 20, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow-sm);
}

.reading-stats-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.reading-stats-header h2 {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.reading-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  grid-auto-rows: minmax(150px, auto);
}

.reading-stat-card {
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: rgba(var(--tint-rgb), 0.03);
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-height: 96px;
  height: 100%;
}

.reading-stat-card-monthly {
  min-height: 170px;
}

.reading-stat-card-list {
  min-height: 170px;
}

body[data-cover-aspect-ratio="1/1"] .reading-stat-card-covers {
  align-self: start;
  height: auto;
  min-height: 0;
}

.reading-stat-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  text-transform: uppercase;
}

.reading-stat-value {
  font-size: 1.28rem;
  line-height: 1.1;
  color: var(--text-primary);
}

.reading-stat-value-title {
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reading-stat-subtle {
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.reading-top-list {
  margin: 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.reading-top-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  min-height: 20px;
  padding: 1px 0;
  border-bottom: 1px dashed rgba(148, 163, 184, 0.15);
}

.reading-top-item:last-child {
  border-bottom: none;
}

.reading-top-item-empty {
  list-style: none;
  margin-left: -18px;
  color: var(--text-secondary);
}

.reading-top-text {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.reading-top-name {
  color: var(--text-primary);
  font-size: 0.83rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reading-top-name-link {
  color: var(--text-primary);
  text-decoration: none;
  font-size: 0.83rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reading-top-name-link:hover {
  color: var(--accent-hover);
}

.reading-top-meta {
  font-size: 0.68rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reading-top-meta-link {
  color: var(--text-muted);
  text-decoration: none;
}

.reading-top-meta-link:hover {
  color: #c7d2fe;
}

.reading-top-count {
  flex-shrink: 0;
  font-size: 0.74rem;
  color: #bfdbfe;
}

.reading-top-expand {
  margin-top: 6px;
}

.reading-top-expand summary {
  list-style: none;
  cursor: pointer;
  color: var(--accent-hover);
  font-size: 0.73rem;
  user-select: none;
}

.reading-top-expand summary::-webkit-details-marker {
  display: none;
}

.reading-top-expand summary::before {
  content: "▶";
  display: inline-block;
  margin-right: 6px;
  font-size: 0.56rem;
  transition: transform 0.15s ease;
}

.reading-top-expand[open] summary::before {
  transform: rotate(90deg);
}

.reading-top-list-expanded {
  margin-top: 6px;
  max-height: 220px;
  overflow-y: auto;
  padding-right: 2px;
}

.reading-top-book-covers {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin-top: 2px;
}

.reading-latest-covers {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px 8px;
  align-items: stretch;
  /* Fill the card and space the two cover rows evenly rather than piling the
     blank space under the second row. */
  flex: 1;
  align-content: center;
}

.reading-total-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 2px;
}

.reading-total-metric-block {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.reading-total-metric-title {
  margin-bottom: 2px;
}

.reading-total-metric-label {
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--text-secondary);
}

.reading-total-metric-value {
  font-size: 1rem;
  color: var(--text-primary);
  font-weight: 700;
}

.reading-top-book-cover {
  position: relative;
  display: block;
  width: 100%;
  max-width: 64px;
  margin: 0 auto;
  aspect-ratio: var(--book-cover-aspect-ratio, 2 / 3);
  overflow: hidden;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  text-decoration: none;
}

.reading-top-fanfics-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-top: 2px;
}

.reading-top-fanfic-card {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: inherit;
}

.reading-top-fanfic-cover {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: var(--book-cover-aspect-ratio, 2 / 3);
  overflow: hidden;
  border-radius: 8px 8px 0 0;
  border: 1px solid var(--border-subtle);
  border-bottom: none;
}

.reading-top-fanfic-cover .cover-placeholder {
  height: 100%;
  padding: 6px;
}

.reading-top-fanfic-cover .cover-title {
  font-size: 0.56rem;
  line-height: 1.2;
  -webkit-line-clamp: 4;
}

.reading-top-fanfic-meta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: 1px solid var(--border-subtle);
  border-top: none;
  border-radius: 0 0 8px 8px;
  background: rgba(232, 178, 80, 0.14);
  padding: 3px 4px;
  font-size: 0.68rem;
  color: var(--accent-hover);
}

.reading-top-fanfic-meta svg {
  width: 11px;
  height: 11px;
}

.reading-top-book-cover .cover-placeholder {
  padding: 6px;
}

.reading-top-book-cover .cover-title {
  font-size: 0.56rem;
  line-height: 1.2;
  -webkit-line-clamp: 4;
}

.reading-top-book-cover .read-badge {
  top: 4px;
  right: 4px;
  width: 18px;
  height: 18px;
  font-size: 0.62rem;
}

.reading-latest-cover {
  transition: transform var(--duration) var(--ease), border-color var(--duration) var(--ease), box-shadow var(--duration) var(--ease);
}

.reading-latest-cover:hover {
  transform: translateY(-2px);
  border-color: var(--border-accent);
  box-shadow: var(--shadow-md);
  z-index: 2;
}

.reading-top-book-caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 12px 5px 4px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.9), rgba(0, 0, 0, 0));
  color: #fff;
  font-size: 0.56rem;
  line-height: 1.15;
  text-align: center;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity var(--duration) var(--ease), transform var(--duration) var(--ease);
  pointer-events: none;
}

.reading-latest-cover:hover .reading-top-book-caption {
  opacity: 1;
  transform: translateY(0);
}

.reading-month-switcher {
  margin-top: 4px;
  margin-bottom: 8px;
  display: grid;
  grid-template-columns: 28px 1fr 28px;
  align-items: center;
  gap: 8px;
}

.reading-year-arrow {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  background: rgba(var(--tint-rgb), 0.06);
  color: #dbeafe;
  cursor: pointer;
  font-size: 0.8rem;
  line-height: 1;
  transition: all var(--duration) var(--ease);
}

.reading-year-arrow:hover {
  border-color: rgba(232, 178, 80, 0.55);
  background: rgba(232, 178, 80, 0.24);
  color: #f8dca0;
}

.reading-year-arrow:focus-visible {
  border-color: rgba(232, 178, 80, 0.55);
  box-shadow: 0 0 0 2px rgba(232, 178, 80, 0.2);
  outline: none;
}

.reading-year-arrow:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.reading-year-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.1;
}

.reading-year-current {
  text-align: center;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 0.02em;
}

.reading-year-total {
  font-size: 0.62rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.reading-year-compare {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 8px;
  margin: 0;
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.reading-year-compare-main {
  font-weight: 500;
}

.reading-year-delta {
  font-size: 0.68rem;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 999px;
}

.reading-year-delta.up {
  color: var(--accent-hover);
  background: rgba(232, 178, 80, 0.14);
}

.reading-year-delta.down {
  color: var(--text-muted);
  background: rgba(var(--tint-rgb), 0.08);
}

.reading-month-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  /* Grow the tiles to fill the card height instead of leaving blank below. */
  flex: 1;
  grid-auto-rows: minmax(56px, 1fr);
  gap: 7px;
}

.reading-month-tile {
  min-height: 56px;
  border-radius: 10px;
  border: 1px solid rgba(232, 178, 80, 0.22);
  background: linear-gradient(160deg, rgba(77, 58, 20, 0.24), rgba(35, 28, 12, 0.32));
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 3px;
}

.reading-month-tile-link {
  appearance: none;
  font: inherit;
  color: inherit;
  padding: 0;
  width: 100%;
  cursor: pointer;
}

.reading-month-tile-current {
  border-color: rgba(232, 178, 80, 0.7);
  background: linear-gradient(160deg, rgba(132, 94, 28, 0.44), rgba(77, 58, 20, 0.5));
  box-shadow: 0 0 0 1px rgba(232, 178, 80, 0.26) inset;
}

.reading-month-tile-future {
  border-color: rgba(100, 116, 139, 0.28);
  background: linear-gradient(160deg, rgba(51, 65, 85, 0.23), rgba(30, 41, 59, 0.26));
}

.reading-month-tile-future .reading-month-name {
  color: #94a3b8;
}

/* Heat map: background intensity by how busy the month was (1-3). Background
   only, so the current-month border + ring keep showing through. */
.reading-month-tile-heat-1 {
  background: rgba(232, 178, 80, 0.1);
}

.reading-month-tile-heat-2 {
  background: rgba(232, 178, 80, 0.2);
}

.reading-month-tile-heat-3 {
  background: rgba(232, 178, 80, 0.34);
}

.reading-month-name {
  font-size: 0.64rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #e5d9c1;
}

.reading-month-total {
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1;
  color: var(--accent-hover);
}

.library-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 18px;
  padding: 10px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: rgba(var(--tint-rgb), 0.03);
}

@media (max-width: 900px) {
  .reading-stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-rows: auto;
  }

  .reading-month-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .reading-top-fanfics-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .reading-latest-covers {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .reading-month-tile {
    min-height: 52px;
  }
}

@media (max-width: 640px) {
  .reading-stats-grid {
    /* minmax(0, …): plain 1fr floors at the content's min-width, which let
       the covers row push the panel wider than the phone screen. */
    grid-template-columns: minmax(0, 1fr);
  }

  .reading-stat-card {
    min-width: 0;
  }

  .reading-top-fanfics-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .reading-latest-covers {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

.library-pagination-info {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.library-pagination-controls {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.library-pagination.infinite-scroll-active {
  display: none;
}

.library-infinite-sentinel {
  width: 100%;
  height: 1px;
  margin-bottom: 4px;
}

.library-pagination .disabled {
  pointer-events: none;
  opacity: 0.45;
}

.stat {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.stat-with-icon {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.stat-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
}

.stat-icon svg {
  width: 100%;
  height: 100%;
}

.stat-icon-author {
  color: #a855f7;
}

.stat strong {
  color: var(--text-primary);
}

.search-filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.76rem;
  border: 1px solid var(--border-subtle);
  text-decoration: none;
}

.search-filter-chip-include {
  color: #c6f6d5;
  background: rgba(22, 101, 52, 0.35);
  border-color: rgba(34, 197, 94, 0.25);
}

.search-filter-chip-or {
  color: #bae6fd;
  background: rgba(7, 89, 133, 0.35);
  border-color: rgba(59, 130, 246, 0.25);
}

.search-filter-chip-exclude {
  color: #fecaca;
  background: rgba(153, 27, 27, 0.35);
  border-color: rgba(248, 113, 113, 0.25);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  /* Center content in stretched buttons (full-width mobile rows, flexed
     action bars); natural-width buttons are unaffected. */
  justify-content: center;
  text-align: center;
  gap: 8px;
  padding: 10px 20px;
  font-size: 0.875rem;
  font-family: inherit;
  font-weight: 500;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--duration) var(--ease);
  text-decoration: none;
  white-space: nowrap;
}

.btn svg {
  width: 16px;
  height: 16px;
}

.btn-primary {
  background: var(--accent-solid);
  color: var(--accent-solid-ink);
}

.btn-primary:hover {
  background: var(--accent-solid-hover);
  box-shadow: 0 4px 12px rgba(232, 178, 80, 0.3);
  transform: translateY(-1px);
}

.btn-secondary {
  background: rgba(var(--tint-rgb), 0.06);
  color: var(--text-primary);
  border: 1px solid var(--border-medium);
}

.btn-secondary:hover {
  background: rgba(var(--tint-rgb), 0.1);
  border-color: rgba(var(--tint-rgb), 0.2);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background: rgba(var(--tint-rgb), 0.06);
  color: var(--text-primary);
}

.btn-danger-ghost {
  background: transparent;
  color: var(--danger);
  opacity: 0.7;
}

.btn-danger-ghost:hover {
  background: var(--danger-bg);
  opacity: 1;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
}

.btn-icon {
  padding: 10px;
  width: 40px;
  height: 40px;
  justify-content: center;
}

.btn-full {
  width: 100%;
  justify-content: center;
}

/* ---------- Book Grid ---------- */
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 20px;
}

.view-toggle {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  background: rgba(var(--tint-rgb), 0.04);
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
}

.view-toggle-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  padding: 6px;
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  cursor: pointer;
  transition: all var(--duration) var(--ease);
}

.view-toggle-btn svg {
  width: 14px;
  height: 14px;
  display: block;
}

.view-toggle-btn:hover {
  color: var(--text-primary);
}

.view-toggle-btn.active {
  background: rgba(var(--tint-rgb), 0.12);
  color: var(--text-primary);
}

.book-view-root.book-view-grid .book-list {
  display: none;
}

.book-view-root.book-view-list .book-grid {
  display: none;
}

.book-view-root.book-view-list .author-grid {
  display: none;
}

.book-list {
  background: var(--bg-card);
  border: 1px solid rgba(var(--tint-rgb), 0.18);
  border-radius: var(--radius-md);
  overflow: auto;
  max-height: calc(100vh - 210px);
  position: relative;
}

/* DataTables list mode: enforce single-line, fixed-height rows */
#library-datatable.dataTable,
#bookshelf-datatable.dataTable,
#author-datatable.dataTable,
#tag-datatable.dataTable,
#fandom-datatable.dataTable,
#authors-datatable.dataTable,
#author-shelf-datatable.dataTable {
  table-layout: fixed;
  width: max-content !important;
  min-width: 100%;
}

#library-datatable.dataTable tbody tr,
#bookshelf-datatable.dataTable tbody tr,
#author-datatable.dataTable tbody tr,
#tag-datatable.dataTable tbody tr,
#fandom-datatable.dataTable tbody tr,
#authors-datatable.dataTable tbody tr,
#author-shelf-datatable.dataTable tbody tr {
  height: 2.375rem;
}

#library-datatable.dataTable tbody td,
#bookshelf-datatable.dataTable tbody td,
#author-datatable.dataTable tbody td,
#tag-datatable.dataTable tbody td,
#fandom-datatable.dataTable tbody td,
#authors-datatable.dataTable tbody td,
#author-shelf-datatable.dataTable tbody td {
  height: 2.375rem;
  max-height: 2.375rem;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  line-height: 2.375rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}

#library-datatable.dataTable thead th,
#library-datatable.dataTable tbody td,
#bookshelf-datatable.dataTable thead th,
#bookshelf-datatable.dataTable tbody td,
#author-datatable.dataTable thead th,
#author-datatable.dataTable tbody td,
#tag-datatable.dataTable thead th,
#tag-datatable.dataTable tbody td,
#fandom-datatable.dataTable thead th,
#fandom-datatable.dataTable tbody td,
#authors-datatable.dataTable thead th,
#authors-datatable.dataTable tbody td,
#author-shelf-datatable.dataTable thead th,
#author-shelf-datatable.dataTable tbody td {
  max-width: 340px;
}

#library-datatable.dataTable tbody td a,
#bookshelf-datatable.dataTable tbody td a,
#author-datatable.dataTable tbody td a,
#tag-datatable.dataTable tbody td a,
#fandom-datatable.dataTable tbody td a,
#authors-datatable.dataTable tbody td a,
#author-shelf-datatable.dataTable tbody td a {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#library-datatable.dataTable thead th,
#bookshelf-datatable.dataTable thead th,
#author-datatable.dataTable thead th,
#tag-datatable.dataTable thead th,
#fandom-datatable.dataTable thead th,
#authors-datatable.dataTable thead th,
#author-shelf-datatable.dataTable thead th {
  position: relative;
}

#library-datatable.dataTable .dt-col-resize-handle,
#bookshelf-datatable.dataTable .dt-col-resize-handle,
#author-datatable.dataTable .dt-col-resize-handle,
#tag-datatable.dataTable .dt-col-resize-handle,
#fandom-datatable.dataTable .dt-col-resize-handle,
#authors-datatable.dataTable .dt-col-resize-handle,
#author-shelf-datatable.dataTable .dt-col-resize-handle {
  position: absolute;
  top: 0;
  right: 0;
  width: 10px;
  height: 100%;
  cursor: col-resize;
  user-select: none;
  touch-action: none;
}

#library-datatable.dataTable .dt-col-resize-handle::after,
#bookshelf-datatable.dataTable .dt-col-resize-handle::after,
#author-datatable.dataTable .dt-col-resize-handle::after,
#tag-datatable.dataTable .dt-col-resize-handle::after,
#fandom-datatable.dataTable .dt-col-resize-handle::after,
#authors-datatable.dataTable .dt-col-resize-handle::after,
#author-shelf-datatable.dataTable .dt-col-resize-handle::after {
  content: '';
  position: absolute;
  top: 8px;
  bottom: 8px;
  left: 4px;
  width: 1px;
  background: rgba(var(--tint-rgb), 0.22);
}

#library-datatable.dataTable.dt-resizing,
#library-datatable.dataTable.dt-resizing *,
#bookshelf-datatable.dataTable.dt-resizing,
#bookshelf-datatable.dataTable.dt-resizing *,
#author-datatable.dataTable.dt-resizing,
#author-datatable.dataTable.dt-resizing *,
#tag-datatable.dataTable.dt-resizing,
#tag-datatable.dataTable.dt-resizing *,
#fandom-datatable.dataTable.dt-resizing,
#fandom-datatable.dataTable.dt-resizing *,
#authors-datatable.dataTable.dt-resizing,
#authors-datatable.dataTable.dt-resizing *,
#author-shelf-datatable.dataTable.dt-resizing,
#author-shelf-datatable.dataTable.dt-resizing * {
  cursor: col-resize !important;
}

.book-list-header,
.book-list-row {
  display: grid;
  grid-template-columns:
    300px
    220px
    repeat(var(--book-list-custom-cols, 0), 150px);
  width: max-content;
}

.book-list-header {
  position: sticky;
  top: 0;
  z-index: 3;
  background: rgba(22, 28, 40, 0.99);
  border-bottom: 1px solid rgba(var(--tint-rgb), 0.2);
  padding-right: 44px;
}

.book-list-reorder-overlay-btn {
  position: absolute;
  top: 6px;
  right: 8px;
  z-index: 5;
  width: 30px;
  height: 30px;
  border: 1px solid var(--border-medium);
  border-radius: 8px;
  background: rgba(var(--tint-rgb), 0.10);
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(var(--tint-rgb), 0.08);
  transition: all var(--duration) var(--ease);
}

.book-list-reorder-overlay-btn:hover {
  background: rgba(var(--tint-rgb), 0.16);
  border-color: var(--border-strong);
}

.book-list-reorder-overlay-btn svg {
  width: 16px;
  height: 16px;
}

.book-list-row {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid rgba(var(--tint-rgb), 0.12);
  transition: background var(--duration) var(--ease);
}

.book-list-row:nth-child(odd) {
  background: rgba(var(--tint-rgb), 0.02);
}

.book-list-row:hover {
  background: rgba(var(--tint-rgb), 0.08);
}

.book-list-row:last-child {
  border-bottom: none;
}

.book-list-cell {
  padding: 10px 12px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-right: 1px solid rgba(var(--tint-rgb), 0.14);
}

.book-list-header .book-list-cell {
  font-size: 0.74rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.book-list-cell-draggable {
  cursor: grab;
  user-select: none;
}

.book-list-cell-draggable:active {
  cursor: grabbing;
}

.book-list-cell-drag-over {
  background: rgba(232, 178, 80, 0.16);
  color: var(--text-primary);
}

.book-list-cell:last-child {
  border-right: none;
}

.book-list-title {
  color: var(--text-primary);
  font-weight: 550;
}

.column-order-editor {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.column-order-help {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.column-order-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 360px;
  overflow-y: auto;
}

.column-order-item {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid rgba(var(--tint-rgb), 0.16);
  border-radius: var(--radius-sm);
  background: rgba(var(--tint-rgb), 0.03);
  cursor: grab;
}

.column-order-item:active {
  cursor: grabbing;
}

.column-order-item-dragging {
  opacity: 0.45;
}

.column-order-item-drag-over {
  border-color: rgba(232, 178, 80, 0.7);
  background: rgba(232, 178, 80, 0.12);
}

.column-order-index {
  color: var(--text-muted);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.column-order-label {
  font-size: 0.85rem;
  color: var(--text-primary);
}

.column-order-controls {
  display: inline-flex;
  gap: 6px;
}

.column-order-btn {
  border: 1px solid rgba(var(--tint-rgb), 0.2);
  border-radius: var(--radius-sm);
  background: rgba(var(--tint-rgb), 0.05);
  color: var(--text-primary);
  min-width: 28px;
  padding: 4px 8px;
  font-size: 0.92rem;
  line-height: 1;
  font-weight: 700;
  cursor: pointer;
}

.column-order-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.column-order-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

[data-sort-refresh-container].sort-refresh-loading {
  opacity: 0.58;
  transition: opacity var(--duration) var(--ease);
}

.fandom-pages-section {
  /* Symmetric padding so the carousel centres in the open panel. */
  padding: 14px;
  margin: 0;
}

.fandom-pages-empty-state {
  padding: 10px 14px 14px;
  margin-bottom: 0;
}

.fandom-pages-disclosure {
  margin-bottom: 18px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: rgba(10, 12, 18, 0.4);
  overflow: hidden;
  box-shadow:
    inset 0 1px 0 rgba(var(--tint-rgb), 0.03),
    inset 0 16px 28px rgba(0, 0, 0, 0.34),
    inset 0 -10px 20px rgba(0, 0, 0, 0.22);
}

.fandom-pages-disclosure summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  color: var(--text-secondary);
  font-size: 0.82rem;
  border-bottom: 1px solid transparent;
  transition: background var(--duration) var(--ease), border-color var(--duration) var(--ease);
}

.fandom-pages-disclosure summary:hover {
  background: rgba(var(--tint-rgb), 0.03);
}

.fandom-pages-disclosure summary::-webkit-details-marker {
  display: none;
}

.fandom-pages-disclosure[open] summary {
  border-bottom-color: var(--border-subtle);
}

.fandom-pages-disclosure-context {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.fandom-pages-disclosure-arrow {
  font-size: 0.72rem;
  color: var(--text-muted);
  transform: rotate(0deg);
  transition: transform var(--duration) var(--ease);
  flex: 0 0 auto;
}

.fandom-pages-disclosure[open] .fandom-pages-disclosure-arrow {
  transform: rotate(90deg);
}

.fandom-pages-disclosure-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.fandom-pages-disclosure-text {
  display: inline-flex;
  flex-direction: column;
  min-width: 0;
}

.fandom-pages-disclosure-title-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.fandom-pages-disclosure-thumb-wrap {
  width: 64px;
  height: 36px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid rgba(var(--tint-rgb), 0.14);
  flex: 0 0 auto;
  background: linear-gradient(135deg, rgba(79, 70, 229, 0.18), rgba(14, 116, 144, 0.2));
  transform-origin: left center;
  transition: width var(--duration) var(--ease), height var(--duration) var(--ease), transform var(--duration) var(--ease);
}

.fandom-pages-disclosure-thumb,
.fandom-pages-disclosure-thumb-placeholder {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

/* Fanned stack of up to three page previews in the collapsed summary. */
.fandom-pages-disclosure-thumb-wrap-stacked {
  position: relative;
  overflow: visible;
  border: none;
  background: none;
  margin-right: 8px;
}

.fandom-pages-disclosure-thumb-layer {
  position: absolute;
  inset: 0;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid rgba(var(--tint-rgb), 0.14);
  background: linear-gradient(135deg, rgba(79, 70, 229, 0.18), rgba(14, 116, 144, 0.2));
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  transition: transform var(--duration) var(--ease);
}

.fandom-pages-disclosure-thumb-layer-1 {
  z-index: 3;
}

.fandom-pages-disclosure-thumb-layer-2 {
  z-index: 2;
  transform: translate(5px, -2px) rotate(3deg);
  opacity: 0.75;
}

.fandom-pages-disclosure-thumb-layer-3 {
  z-index: 1;
  transform: translate(10px, -4px) rotate(6deg);
  opacity: 0.5;
}

.fandom-pages-disclosure-thumb-generated {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 6px;
  background:
    radial-gradient(circle at 18% 20%, rgba(var(--tint-rgb), 0.18), transparent 32%),
    linear-gradient(135deg,
      hsla(210, 64%, 48%, 0.92) 0%,
      hsla(234, 56%, 22%, 0.98) 100%);
}

.fandom-pages-disclosure-thumb-initial {
  font-size: 0.9rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.94);
  line-height: 1;
}

.fandom-pages-disclosure-thumb-label {
  margin-top: 2px;
  font-size: 0.46rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: rgba(255, 255, 255, 0.78);
}

.fandom-pages-disclosure-thumb-placeholder {
  display: grid;
  place-items: center;
  color: rgba(255, 255, 255, 0.86);
  font-weight: 700;
  font-size: 0.8rem;
}

.fandom-pages-disclosure-title {
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
}

.fandom-pages-disclosure-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fandom-pages-carousel {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
}

.fandom-pages-grid {
  display: flex;
  flex-wrap: nowrap;
  gap: 14px;
  overflow-x: auto;
  overflow-y: hidden;
  /* 6px vertical keeps the card hover lift + shadow inside the clip box. */
  padding: 6px 2px;
  width: auto;
  min-width: 0;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
  /* Scrollbar hidden: nav buttons + swipe scroll remain, and the reserved
     scrollbar space no longer skews the nav buttons off the card centreline. */
  scrollbar-width: none;
}

.fandom-pages-grid:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Desktop drag-to-scroll */
@media (hover: hover) {
  .fandom-pages-grid {
    cursor: grab;
  }
}

.fandom-pages-grid.drag-scrolling {
  cursor: grabbing;
  user-select: none;
  /* Snap fights the pointer mid-drag; it re-engages on release. */
  scroll-snap-type: none;
}

.fandom-pages-grid.drag-scrolling .fandom-page-card {
  pointer-events: none;
}

.fandom-pages-nav {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  background: rgba(10, 12, 18, 0.72);
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--duration) var(--ease);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.fandom-pages-nav:hover {
  background: rgba(26, 32, 45, 0.92);
  border-color: var(--border-medium);
}

/* [hidden] would lose to display:inline-flex above without this. */
.fandom-pages-nav[hidden] {
  display: none;
}

.fandom-pages-nav:disabled {
  opacity: 0.35;
  pointer-events: none;
}

.fandom-pages-nav svg {
  width: 16px;
  height: 16px;
}

.fandom-page-card {
  position: relative;
  flex: 0 0 320px;
  width: 320px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  aspect-ratio: 16 / 9;
  min-height: 130px;
  overflow: hidden;
  transition: all var(--duration) var(--ease);
  scroll-snap-align: start;
}

.fandom-pages-grid.reorder-mode .fandom-page-card {
  cursor: grab;
}

.fandom-pages-grid.reorder-mode .fandom-page-card:active {
  cursor: grabbing;
}

.fandom-page-card.dragging {
  opacity: 0.45;
  transform: scale(0.985);
}

.fandom-page-card.drag-over {
  outline: 2px solid rgba(232, 178, 80, 0.55);
  outline-offset: -2px;
}

.fandom-page-card:hover {
  border-color: var(--border-medium);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.fandom-page-card-link {
  display: block;
  text-decoration: none;
  color: inherit;
  width: 100%;
  height: 100%;
}

.fandom-page-card-image {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: linear-gradient(145deg, #1a2035 0%, #0f1420 50%, #1a1525 100%);
}

.fandom-page-card-image img,
.fandom-page-card-image-placeholder {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.fandom-page-card-image-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.92);
  font-size: 1.2rem;
  font-weight: 700;
  background:
    radial-gradient(circle at 30% 30%, rgba(var(--tint-rgb), 0.18), transparent 34%),
    linear-gradient(145deg, #2b2640 0%, #181426 100%);
}

.fandom-page-card-overlay {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  padding: 26px 40px 10px 10px;
  background: linear-gradient(to top, rgba(6, 8, 12, 0.82), rgba(6, 8, 12, 0.02));
}

.fandom-page-card-label-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.fandom-page-card-title {
  min-width: 0;
  font-size: 0.82rem;
  font-weight: 600;
  color: #ffffff;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

.fandom-page-card-meta {
  flex-shrink: 0;
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.86);
  letter-spacing: 0.02em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

.fandom-page-card-edit {
  position: absolute;
  bottom: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.92);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  z-index: 3;
  cursor: pointer;
  /* Hidden until the card is hovered/focused (same pattern as quote actions). */
  opacity: 0;
  transition: opacity var(--duration) var(--ease), color var(--duration) var(--ease);
}

.fandom-page-card:hover .fandom-page-card-edit,
.fandom-page-card:focus-within .fandom-page-card-edit {
  opacity: 1;
}

/* Touch devices have no hover: keep the pencil visible. */
@media (hover: none) {
  .fandom-page-card-edit {
    opacity: 0.9;
  }
}

.fandom-page-card-edit:hover {
  color: #ffffff;
}

.fandom-page-card-edit svg {
  width: 14px;
  height: 14px;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5));
}

.fandom-pages-grid::-webkit-scrollbar {
  display: none;
}

.book-card {
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  transition: all var(--duration-slow) var(--ease);
}

.book-card:hover {
  background: var(--bg-card);
  border-color: var(--border-subtle);
  transform: none;
  box-shadow: none;
}

.book-card-link {
  text-decoration: none;
  color: inherit;
}

.book-cover {
  position: relative;
  aspect-ratio: var(--book-cover-aspect-ratio, 2 / 3);
  overflow: hidden;
}

/* Cover status overlays (plans/cover-status-redesign.md): bottom-right holds
   at most ONE triangle; chips sit bottom-left; the reading bar spans the
   bottom edge. Rendered everywhere via the _cover_status.html macro. */
.book-corner-badges {
  position: absolute;
  right: 0;
  bottom: 0;
  z-index: 2;
  pointer-events: none;
}

.book-corner-badge {
  display: block;
  width: 18px;
  height: 18px;
  border-bottom-right-radius: 5px;
  clip-path: polygon(100% 0, 0 100%, 100% 100%);
  box-shadow: 0 0 0 1px rgba(var(--tint-rgb), 0.08) inset;
  opacity: 0.9;
}

.book-corner-badge-completed {
  background: var(--status-completed);
}

.book-corner-badge-in-progress {
  background: var(--status-in-progress);
}

.book-corner-badge-published {
  background: var(--status-published);
}

.book-cover-reading-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: var(--status-reading);
  z-index: 2;
  pointer-events: none;
}

.book-cover-state-chips {
  position: absolute;
  left: 6px;
  bottom: 6px;
  z-index: 2;
  display: flex;
  gap: 4px;
  pointer-events: none;
}

.book-cover-state-chip {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.4px;
  padding: 2px 7px;
  border-radius: 4px;
  background: rgba(12, 12, 14, 0.75);
}

.book-cover-state-chip-abandoned {
  color: #fac775;
}

.book-cover-state-chip-deleted {
  color: #f09595;
}

.cover-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.cover-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  text-align: center;
  background: linear-gradient(145deg, #1a2035 0%, #0f1420 50%, #1a1525 100%);
  position: relative;
}

.cover-placeholder::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg,
    rgba(232, 178, 80, 0.04) 0%,
    transparent 50%,
    rgba(100, 120, 200, 0.03) 100%);
}

.cover-placeholder.has-cover {
  background: linear-gradient(145deg, #1a2540 0%, #12182a 50%, #1a1830 100%);
}

.cover-placeholder.orphan {
  background: linear-gradient(145deg, #2a1a1a 0%, #1a0f0f 100%);
  border: 1px dashed rgba(248, 113, 113, 0.3);
}

.cover-title {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  line-height: 1.4;
  z-index: 1;
  max-height: 4.2em;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.cover-lg {
  width: 180px;
  aspect-ratio: var(--book-cover-aspect-ratio, 2 / 3);
  height: auto;
  border-radius: var(--radius-md);
  flex-shrink: 0;
}

.read-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--accent-solid);
  color: var(--accent-solid-ink);
  font-size: 0.7rem;
  font-weight: 700;
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  letter-spacing: 0.02em;
}

.book-info {
  padding: 12px;
}

.book-title {
  font-size: 0.82rem;
  font-weight: 550;
  color: var(--text-primary);
  line-height: 1.35;
  margin-bottom: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.book-author {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.book-notes {
  padding: 0 12px 8px;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-style: italic;
}

.remove-btn {
  margin: 0 12px 12px;
  align-self: flex-start;
}

/* read-action-icon in book cards and shelves */
.book-card .read-action-icon {
  margin: 0 12px 12px;
  align-self: flex-start;
}

.book-card .book-cover-remove-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 4;
  margin: 0;
  width: 24px;
  height: 24px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: rgba(248, 250, 252, 0.92);
}

.book-card .book-cover-remove-btn:hover,
.book-card .book-cover-remove-btn:focus-visible {
  color: #fecaca;
  border-color: rgba(248, 113, 113, 0.58);
  background: rgba(127, 29, 29, 0.36);
}

.author-card .read-action-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  padding: 0;
  flex-shrink: 0;
}
/* ---------- Shelf Grid ---------- */
.shelf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.shelf-card {
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 24px;
  text-decoration: none;
  color: inherit;
  transition: all var(--duration-slow) var(--ease);
  position: relative;
  overflow: hidden;
}

.shelf-banner-shell {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  margin: -24px -24px 16px;
  background: linear-gradient(145deg,
    hsla(var(--banner-hue, 210), 65%, 45%, 0.38),
    hsla(calc(var(--banner-hue, 210) + 28), 55%, 18%, 0.96));
  border-bottom: 1px solid var(--border-subtle);
}

.shelf-banner-shell-author {
  background: linear-gradient(145deg, rgba(74, 222, 128, 0.12), rgba(96, 165, 250, 0.08));
}

.shelf-banner-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.shelf-banner-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  color: var(--text-secondary);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.shelf-banner-placeholder-author {
  color: var(--text-secondary);
}

.shelf-banner-generated {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 14px;
  background:
    radial-gradient(circle at 18% 20%, rgba(var(--tint-rgb), 0.18), transparent 32%),
    linear-gradient(135deg,
      hsla(var(--banner-hue, 210), 64%, 48%, 0.92) 0%,
      hsla(calc(var(--banner-hue, 210) + 24), 56%, 22%, 0.98) 100%);
}

.shelf-banner-generated-author {
  background:
    radial-gradient(circle at 18% 20%, rgba(var(--tint-rgb), 0.18), transparent 32%),
    linear-gradient(135deg,
      hsla(var(--banner-hue, 210), 58%, 42%, 0.92) 0%,
      hsla(calc(var(--banner-hue, 210) + 34), 52%, 18%, 0.98) 100%);
}

.shelf-banner-generated-initial {
  font-size: 1.75rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.94);
  line-height: 1;
}

.shelf-banner-generated-label {
  margin-top: 4px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: rgba(255, 255, 255, 0.76);
}

.shelf-banner-detail-generated {
  aspect-ratio: 16 / 9;
  padding: 28px 32px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  background:
    radial-gradient(circle at 18% 20%, rgba(var(--tint-rgb), 0.18), transparent 30%),
    linear-gradient(135deg,
      hsla(var(--banner-hue, 210), 65%, 46%, 0.92) 0%,
      hsla(calc(var(--banner-hue, 210) + 24), 54%, 18%, 0.98) 100%);
}

.shelf-banner-detail-generated-author {
  background:
    radial-gradient(circle at 18% 20%, rgba(var(--tint-rgb), 0.18), transparent 30%),
    linear-gradient(135deg,
      hsla(var(--banner-hue, 210), 58%, 42%, 0.92) 0%,
      hsla(calc(var(--banner-hue, 210) + 34), 52%, 18%, 0.98) 100%);
}

.shelf-banner-detail-generated-kicker {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: rgba(255, 255, 255, 0.76);
  margin-bottom: 10px;
}

.shelf-banner-detail-generated-title {
  font-size: 1.45rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.96);
  line-height: 1.15;
  margin-bottom: 10px;
}

.shelf-banner-detail-generated-desc {
  font-size: 0.9rem;
  max-width: 42rem;
  color: rgba(255, 255, 255, 0.78);
}

.modal-banner-preview {
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-bottom: 12px;
  border: 1px solid var(--border-subtle);
  position: relative;
}

.modal-banner-preview .shelf-banner-generated,
.modal-banner-preview .shelf-banner-generated-author {
  min-height: 160px;
}

.modal-banner-preview-compact .shelf-banner-image,
.modal-banner-preview-compact .shelf-banner-generated,
.modal-banner-preview-compact .shelf-banner-generated-author {
  width: 100%;
  height: 100%;
  min-height: 0;
  max-height: none;
}

.modal-banner-preview-compact.shelf-banner-shell,
.modal-banner-preview-compact.shelf-banner-shell-author {
  width: min(320px, calc(100% - 24px));
  aspect-ratio: 16 / 9;
  margin: 6px auto 10px;
  border-bottom: 0;
}

.modal-banner-preview .shelf-banner-generated-initial {
  font-size: 1.45rem;
}

.modal-banner-preview .shelf-banner-generated-label {
  font-size: 0.66rem;
}

.shelf-banner-detail {
  margin-bottom: 20px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  background: var(--bg-card);
  max-width: 640px;
}

.shelf-banner-detail-image {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  display: block;
}

.shelf-banner-detail-placeholder {
  aspect-ratio: 16 / 9;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  color: var(--text-muted);
  background: linear-gradient(145deg, rgba(96, 165, 250, 0.08), rgba(232, 178, 80, 0.06));
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.78rem;
}

.shelf-banner-detail-placeholder-author {
  background: linear-gradient(145deg, rgba(74, 222, 128, 0.08), rgba(96, 165, 250, 0.06));
}

.shelf-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), transparent);
  opacity: 0;
  transition: opacity var(--duration-slow) var(--ease);
}

.shelf-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-medium);
  transform: translateY(-3px);
  box-shadow: var(--shadow-md), var(--shadow-glow);
}

.shelf-card:hover::before {
  opacity: 1;
}

.shelf-card-author::before {
  background: linear-gradient(90deg, var(--info), transparent);
}

.shelf-card-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.shelf-name {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.shelf-count {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.shelf-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---------- Author Grid ---------- */
.author-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.author-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px;
  text-decoration: none;
  color: inherit;
  transition: all var(--duration-slow) var(--ease);
}

.author-card:hover {
  background: var(--bg-card);
  border-color: var(--border-subtle);
  transform: none;
  box-shadow: none;
}

.author-card-link {
  display: flex;
  align-items: center;
  gap: 14px;
  text-decoration: none;
  color: inherit;
  flex: 1;
}

.author-remove-btn {
  width: 22px;
  height: 22px;
  border: 1px solid rgba(239, 68, 68, 0.32);
  border-radius: 999px;
  background: rgba(127, 29, 29, 0.22);
  color: #fca5a5;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--duration) var(--ease);
}

.author-remove-btn:hover {
  background: rgba(153, 27, 27, 0.34);
  border-color: rgba(248, 113, 113, 0.45);
  color: #fecaca;
}

.author-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(96, 165, 250, 0.2), rgba(96, 165, 250, 0.05));
  border: 1px solid rgba(96, 165, 250, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 1rem;
  color: var(--info);
  flex-shrink: 0;
}

.author-avatar,
.author-detail-avatar,
.author-search-avatar {
  object-fit: cover;
  display: block;
}

.author-avatar.orphan {
  background: linear-gradient(135deg, rgba(248, 113, 113, 0.2), rgba(248, 113, 113, 0.05));
  border-color: rgba(248, 113, 113, 0.15);
  color: var(--danger);
}

.author-detail-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(96, 165, 250, 0.2), rgba(96, 165, 250, 0.05));
  border: 1px solid rgba(96, 165, 250, 0.15);
  flex-shrink: 0;
}

.author-info {
  min-width: 0;
}

.author-name {
  font-size: 0.9rem;
  font-weight: 550;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.author-books {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* ---------- Detail Layout ---------- */
.detail-layout {
  max-width: 900px;
}

.detail-header {
  display: flex;
  gap: 32px;
  margin-bottom: 32px;
}

.detail-cover {
  position: relative;
  flex-shrink: 0;
  align-self: flex-start;
  display: inline-flex;
  cursor: zoom-in;
  outline: none;
  transition: transform var(--duration) var(--ease);
}

/* Completion/status ribbons on the large detail cover — a touch bigger than the
   grid corner badges for legibility. The enlarged cover modal builds its own
   markup and intentionally omits these. */
.detail-cover .book-corner-badge {
  width: 26px;
  height: 26px;
  border-bottom-right-radius: 7px;
}

.detail-cover:hover,
.detail-cover:focus-visible {
  transform: translateY(-2px);
}

.detail-cover:hover .cover-lg,
.detail-cover:focus-visible .cover-lg {
  box-shadow: 0 0 0 3px var(--accent-muted);
}

.detail-meta {
  flex: 1;
  min-width: 0;
}

.metadata-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
}

.metadata-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px;
}

.metadata-card-wide {
  grid-column: 1 / -1;
}

.metadata-card h3 {
  font-size: 0.92rem;
  color: var(--text-primary);
  margin-bottom: 10px;
  margin-top: 4px;
}

.metadata-list {
  margin: 0;
}

.metadata-row {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px dashed var(--border-subtle);
}

.metadata-row:last-child {
  border-bottom: none;
}

.metadata-row dt {
  color: var(--text-secondary);
  font-size: 0.78rem;
}

.metadata-row dd {
  margin: 0;
  color: var(--text-primary);
  font-size: 0.82rem;
  word-break: break-word;
}

.metadata-pill-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
}

.metadata-pill-list li {
  font-size: 0.75rem;
  color: var(--text-primary);
  background: rgba(var(--tint-rgb), 0.06);
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  padding: 4px 10px;
}

.metadata-pill-list a {
  color: inherit;
  text-decoration: none;
  display: block;
}

.metadata-pill-list a:hover {
  color: var(--accent-hover);
}

.metadata-pill-list li:hover {
  border-color: var(--border-accent);
}

.metadata-comments {
  font-size: 0.82rem;
  color: var(--text-primary);
  background: rgba(var(--tint-rgb), 0.03);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 10px;
  margin-bottom: 12px;
}

.metadata-empty {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.metadata-hint {
  color: var(--text-muted);
  font-size: 0.72rem;
}

.detail-title {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
  margin-bottom: 8px;
}

.detail-authors {
  font-size: 0.95rem;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.author-link {
  color: var(--accent);
  transition: color var(--duration) var(--ease);
}

.author-link:hover {
  color: var(--accent-hover);
}

.detail-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.detail-actions .btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  /* One uniform slim height — icon size and per-button padding differences
     made the six header buttons render at mixed heights. */
  height: 40px;
  padding-top: 0;
  padding-bottom: 0;
}

.detail-actions .btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.detail-action-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  border: 1px solid rgba(var(--tint-rgb), 0.18);
  background: rgba(var(--tint-rgb), 0.09);
  font-size: 0.76rem;
  line-height: 1;
  color: inherit;
}

.author-detail-toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 22px;
}

.author-detail-toolbar-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}

.author-detail-toolbar-row-primary {
  align-items: center;
}

.detail-stats {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.detail-stats .stat-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: rgba(var(--tint-rgb), 0.04);
  font-size: 0.84rem;
  line-height: 1.2;
  color: var(--text-secondary);
}

.detail-stats .chip-icon {
  width: 16px;
  height: 16px;
  min-width: 16px;
  min-height: 16px;
  display: inline-block;
  flex-shrink: 0;
}

.author-detail-avatar-wrap {
  display: flex;
  align-items: center;
}

.author-detail-toolbar-row-primary .detail-actions {
  margin-left: 0;
}

.author-detail-toolbar-row-secondary .view-toggle {
  margin-left: 0;
}

.detail-description {
  margin-top: 14px;
}

.my-fields-compact {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.my-compact-row {
  display: grid;
  gap: 8px 12px;
}

.my-compact-row-3 {
  /* auto-fit lets rows with hidden empty cells fill the available width */
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}

.my-compact-row > div,
.my-compact-line {
  font-size: 0.82rem;
  color: var(--text-primary);
  background: rgba(var(--tint-rgb), 0.03);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  word-break: break-word;
}

.my-pill-field {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 8px;
}

.pill-link {
  /* Pills wrap as whole units via flex-wrap; never break their text mid-word. */
  word-break: normal;
}

.pill-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill-link {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: rgba(var(--tint-rgb), 0.06);
  color: var(--text-primary);
  font-size: 0.75rem;
  line-height: 1.3;
  text-decoration: none;
  transition: all var(--duration) var(--ease);
}

.pill-link:hover {
  color: var(--accent-hover);
  border-color: var(--border-accent);
  background: rgba(232, 178, 80, 0.12);
}

.pill-link-static {
  color: var(--text-primary);
}

.my-key {
  color: var(--text-secondary);
  font-size: 0.75rem;
  margin-right: 4px;
  /* Never break labels mid-word ("fando m:") or let them shrink in flex rows. */
  white-space: nowrap;
  flex-shrink: 0;
}

/* ---------- Book header: rating + stats pill (above the description) ---------- */
.my-stats-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 16px;
  margin-top: 14px;
  padding: 8px 12px;
  background: rgba(var(--tint-rgb), 0.03);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  color: var(--text-primary);
}

.my-stats-strip .star {
  font-size: 0.85rem;
}

.my-stat {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.my-stat svg {
  width: 14px;
  height: 14px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.my-stat + .my-stat::before {
  content: '·';
  color: var(--text-muted);
  margin-right: 10px;
}

.my-stat-value {
  font-weight: 600;
}

.my-stat-label {
  color: var(--text-secondary);
}

/* ---------- Book header: series line ---------- */
.detail-series {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin: -10px 0 14px;
}

.detail-series-name {
  color: var(--text-primary);
  font-weight: 600;
  text-decoration: none;
  transition: color var(--duration) var(--ease);
}

a.detail-series-name:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* ---------- Metadata tab: identifier links ---------- */
.metadata-identifier-link {
  color: var(--accent);
  word-break: break-all;
  transition: color var(--duration) var(--ease);
}

.metadata-identifier-link:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

/* ---------- Alert ---------- */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-bottom: 16px;
}

.alert-warning {
  background: var(--warning-bg);
  border: 1px solid rgba(251, 191, 36, 0.2);
  color: var(--warning);
}

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 24px;
}

.tab {
  padding: 10px 18px;
  font-size: 0.85rem;
  font-family: inherit;
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all var(--duration) var(--ease);
}

.tab:hover {
  color: var(--text-secondary);
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
  animation: fadeIn var(--duration) var(--ease);
}

/* ---------- Reads List ---------- */
.reading-log-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.reading-log-filter {
  flex: 1;
  min-width: 180px;
  background: var(--bg-input);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  font-size: 0.875rem;
  font-family: inherit;
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--duration) var(--ease), box-shadow var(--duration) var(--ease);
}

.reading-log-filter:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

.reading-log-no-results {
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 8px 2px 16px;
}

.read-sections {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.read-section {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: rgba(var(--tint-rgb), 0.02);
  scroll-margin-top: calc(var(--topbar-height) + 12px);
}

.read-section-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 10px 12px;
  list-style: none;
  user-select: none;
}

.read-section-summary::-webkit-details-marker {
  display: none;
}

.read-section-arrow {
  font-size: 0.72rem;
  color: var(--text-muted);
  transform: rotate(0deg);
  transition: transform var(--duration) var(--ease);
}

.read-section[open] .read-section-arrow {
  transform: rotate(90deg);
}

.read-section-title {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-primary);
}

.read-section-count {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* Spacing under a tab's "+ Add …" button so it doesn't touch the list below. */
.tab-add-btn {
  margin-bottom: 16px;
}

.reads-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0 10px 10px;
}

.read-card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  position: relative;
  transition: all var(--duration) var(--ease);
}

.read-card:hover {
  border-color: var(--border-medium);
}

.read-card-wide {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 12px;
}

.read-card-cover {
  flex: 0 0 auto;
  width: 40px;
  height: 60px;
  border-radius: 4px;
  overflow: hidden;
  display: block;
  background: rgba(var(--tint-rgb), 0.06);
  border: 1px solid var(--border-subtle);
}

.read-card-cover .cover-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.read-card-cover-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.read-card-cover-placeholder svg {
  width: 18px;
  height: 18px;
}

.read-card-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  /* Clear the absolute edit/delete cluster at the card's top-right. */
  padding-right: 62px;
}

.read-book-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.read-book-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.read-reread-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid rgba(232, 178, 80, 0.28);
  background: rgba(232, 178, 80, 0.14);
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--accent-hover);
  font-variant-numeric: tabular-nums;
}

.read-reread-badge svg {
  width: 12px;
  height: 12px;
}

.read-book-title {
  font-size: 0.95rem;
  font-weight: 550;
  color: var(--accent);
  text-decoration: none;
}

.read-book-title:hover {
  color: var(--accent-hover);
}

.read-book-author {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.read-date {
  font-size: 0.82rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.read-rating {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-wrap: wrap;
}

.star {
  font-size: 1rem;
  color: var(--text-muted);
  opacity: 0.3;
}

.star.filled {
  color: var(--accent);
  opacity: 1;
}

.star.half {
  color: var(--accent);
  opacity: 0.5;
}

.rating-value {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-left: 4px;
}

.read-notes {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 0;
  line-height: 1.5;
  /* Keep the note's own formatting (line breaks) visible; no italics. */
  white-space: pre-line;
}

.read-meta-row {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

/* Book-detail read cards: keep the row clear of the absolute top-right actions.
   (The reading-log page's wide cards already reserve space via .read-book-info.) */
.read-card:not(.read-card-wide) .read-meta-row {
  padding-right: 66px;
}

.read-number {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(var(--tint-rgb), 0.18);
  background: rgba(var(--tint-rgb), 0.09);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.read-relative {
  color: var(--text-muted);
  font-weight: 400;
}

.read-no-rating {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-style: italic;
}

/* ---------- Metadata tab: raw fields disclosure ---------- */
.metadata-raw {
  margin-top: 12px;
  border-top: 1px solid var(--border-subtle);
}

.metadata-raw summary {
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--text-secondary);
  padding: 8px 0 6px;
  user-select: none;
  transition: color var(--duration) var(--ease);
}

.metadata-raw summary:hover {
  color: var(--accent);
}

.metadata-raw[open] summary {
  margin-bottom: 4px;
}

.stat-icon-book {
  color: #b45309;
}

.stat-icon-reading {
  color: #166534;
}

.stat-icon-quote {
  color: #1e3a8a;
}

.read-actions {
  display: flex;
  gap: 6px;
  position: absolute;
  top: 10px;
  right: 10px;
}

.read-action-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  background: rgba(var(--tint-rgb), 0.06);
  color: #dbeafe;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: color var(--duration) var(--ease);
}

.read-action-icon svg {
  width: 15px;
  height: 15px;
}

.read-action-edit:hover {
  color: #e0f2fe;
  border-color: rgba(125, 211, 252, 0.55);
  background: rgba(14, 116, 144, 0.35);
}

.read-action-delete:hover {
  color: #fecaca;
  border-color: rgba(248, 113, 113, 0.5);
  background: rgba(127, 29, 29, 0.32);
}

/* ---------- Shelf Chips ---------- */
.shelf-chips {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.shelf-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--accent-muted);
  border: 1px solid var(--border-accent);
  border-radius: 20px;
  padding: 6px 16px;
  font-size: 0.85rem;
}

.shelf-chip a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

.shelf-chip a:hover {
  color: var(--accent-hover);
}

.chip-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0 2px;
  transition: color var(--duration) var(--ease);
}

.chip-remove:hover {
  color: var(--danger);
}

/* ---------- Quotes ---------- */
.quotes-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 16px;
}

.quotes-masonry {
  columns: 2 320px;
  column-gap: 20px;
}

.quote-card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  /* --qc-color is the quote's first collection colour (quotes.html). */
  border-left: 3px solid var(--qc-color, var(--accent));
  border-radius: 2px var(--radius-md) var(--radius-md) 2px;
  padding: 14px 18px;
  margin: 0;
  break-inside: avoid;
  margin-bottom: 14px;
  transition: all var(--duration) var(--ease);
}

.quote-card:hover {
  border-left-color: var(--accent-hover);
  box-shadow: var(--shadow-sm);
}

/* Shuffle target: a brief glow, transition-based so reduce-motion stays calm. */
/* Shuffle target: an unmistakable pulse so it reads even without scrolling. */
.quote-card-flash {
  border-left-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent), 0 6px 20px var(--accent-glow);
  background: color-mix(in srgb, var(--accent) 12%, var(--bg-card));
}

@media (prefers-reduced-motion: no-preference) {
  .quote-card-flash {
    animation: quote-card-flash-pulse 1.4s ease-out;
  }
}

@keyframes quote-card-flash-pulse {
  0% {
    box-shadow: 0 0 0 6px var(--accent), 0 8px 26px var(--accent-glow);
  }
  55% {
    box-shadow: 0 0 0 3px var(--accent), 0 6px 20px var(--accent-glow);
  }
  100% {
    box-shadow: 0 0 0 0 transparent;
    background: var(--bg-card);
  }
}

.quotes-filter-count {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.quote-text {
  font-size: 0.95rem;
  color: var(--text-primary);
  line-height: 1.6;
  /* Preserve the quote's own line breaks. */
  white-space: pre-line;
  margin-bottom: 10px;
}

/* Decorative opening quote mark — replaces literal quotes around the text. */
.quote-text::before {
  content: '\201C';
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 1.9rem;
  line-height: 0;
  vertical-align: -0.35em;
  margin-right: 5px;
  color: var(--accent);
  opacity: 0.5;
}

.quote-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--text-muted);
  flex-wrap: wrap;
}

/* Dot separators between footer parts (source · ch. · p.). */
.quote-footer > * + *::before {
  content: '·';
  margin-right: 8px;
  color: var(--text-muted);
}

.quote-source-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 500;
  color: var(--accent);
}

.quote-source-link:hover {
  color: var(--accent-hover);
}

.quote-source-icon {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
}

/* ---------- Settings: section nav + sticky save bar ---------- */
.settings-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
}

.settings-nav-chip {
  display: inline-flex;
  align-items: center;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: rgba(var(--tint-rgb), 0.05);
  color: var(--text-secondary);
  font-size: 0.8rem;
  text-decoration: none;
  transition: all var(--duration) var(--ease);
}

.settings-nav-chip:hover {
  color: var(--accent);
  border-color: var(--border-accent);
}

/* Anchored sections stop clear of the sticky save bar / viewport edge. */
.settings-section {
  scroll-margin-top: 16px;
}

.settings-section-title svg {
  width: 16px;
  height: 16px;
  color: var(--accent);
  flex-shrink: 0;
}

.settings-save-bar {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 14px;
  padding: 12px 0;
  margin-top: 8px;
  border-top: 1px solid var(--border-subtle);
  background: rgba(12, 14, 20, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

[data-theme="light"] .settings-save-bar {
  background: rgba(250, 250, 248, 0.92);
}

.settings-unsaved-note {
  font-size: 0.78rem;
  color: var(--warning, #fbbf24);
}

/* ---------- Settings: backup export / import ---------- */
.settings-backup-section {
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid var(--border-subtle);
}

.settings-backup-import-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.settings-backup-import-row input[type="file"] {
  flex: 1;
  min-width: 200px;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

/* ---------- Settings: ribbon colour pickers ---------- */
.ribbon-color-row {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  margin-top: 12px;
}

/* display:flex above would defeat the [hidden] attribute without this. */
.ribbon-color-row[hidden] {
  display: none;
}

.ribbon-color-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.ribbon-color-field label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  cursor: pointer;
}

.ribbon-color-field input[type="color"] {
  width: 44px;
  height: 28px;
  padding: 2px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
}

/* ---------- Quote collections ---------- */
.collection-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
}

.collection-chip-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--qc-color, var(--accent));
  flex-shrink: 0;
}

.collection-description {
  margin: 0 0 14px;
  padding: 10px 14px;
  background: rgba(var(--tint-rgb), 0.04);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.88rem;
  font-style: italic;
}

/* Long-quote collapse (quotes.html adds the class when text overflows). */
.quote-text-clamped {
  max-height: 320px;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(to bottom, #000 75%, transparent);
  mask-image: linear-gradient(to bottom, #000 75%, transparent);
}

.quote-expand-btn {
  background: none;
  border: none;
  color: var(--accent);
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  padding: 2px 0;
}

/* Fanfic picker in the quotes-page Add Quote modal. */
.quote-source-results {
  margin-top: 8px;
  max-height: 210px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.quote-source-heading {
  margin: 0 0 2px;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.quote-source-option {
  display: flex;
  align-items: center;
  min-height: 34px;
  text-align: left;
  background: rgba(var(--tint-rgb), 0.04);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font: inherit;
  font-size: 0.85rem;
  line-height: 1.3;
  padding: 0 10px;
  cursor: pointer;
}

.quote-source-option-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.quote-source-option:hover {
  border-color: var(--border-medium);
}

.quote-source-option.is-active {
  border-color: var(--accent);
  background: rgba(232, 178, 80, 0.12);
}

/* Collection picker inside the add-quote modal. */
.quote-add-collections {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.quote-add-collections .quote-add-collection-chip {
  /* Doubled-up selector: .form-group label's display:block outranks a
     single class and stacked the checkbox above the name. */
  display: flex;
  align-items: center;
  margin: 0;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: rgba(var(--tint-rgb), 0.05);
  font-size: 0.8rem;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

.quote-add-collections .quote-add-collection-chip input {
  /* Beat .form-group input's width:100%, which swallowed the chip. */
  width: auto;
  accent-color: var(--accent);
  margin: 0;
  flex-shrink: 0;
}

.quote-add-collection-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.quote-add-collection-chip.is-checked {
  border-color: color-mix(in srgb, var(--qc-color, var(--accent)) 55%, transparent);
  background: color-mix(in srgb, var(--qc-color, var(--accent)) 14%, transparent);
  color: var(--text-primary);
}

.quote-add-collection-new {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.quote-add-collection-new input {
  flex: 1;
  min-width: 0;
}

/* Collection colour swatches in the create/edit modal. */
.qc-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.qc-swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}

.qc-swatch.is-active {
  border-color: var(--text-primary);
}

.qc-swatch-auto {
  background: rgba(var(--tint-rgb), 0.1);
  color: var(--text-secondary);
  font-size: 0.72rem;
  font-weight: 600;
}

.collection-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: rgba(var(--tint-rgb), 0.05);
  color: var(--text-secondary);
  font-size: 0.8rem;
  text-decoration: none;
  cursor: pointer;
  transition: all var(--duration) var(--ease);
}

a.collection-chip:hover {
  color: var(--accent);
  border-color: var(--border-accent);
}

.collection-chip.active {
  color: var(--accent);
  border-color: var(--border-accent);
  background: rgba(232, 178, 80, 0.1);
  font-weight: 600;
}

.collection-chip-icon {
  display: inline-flex;
  align-items: center;
}

.collection-chip-icon svg {
  width: 13px;
  height: 13px;
}

.collection-chip-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  font: inherit;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity var(--duration) var(--ease);
}

.collection-chip-action:hover {
  opacity: 1;
}

.collection-chip-action svg {
  width: 12px;
  height: 12px;
}

.collection-chip-new {
  border-style: dashed;
  background: transparent;
  font-family: inherit;
}

.collection-chip-new:hover {
  color: var(--accent);
  border-color: var(--border-accent);
}

/* Tiny collection chips at the end of a quote card's footer. */
.quote-collection-chip {
  display: inline-flex;
  align-items: center;
  padding: 1px 8px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--qc-color, var(--accent)) 45%, transparent);
  background: color-mix(in srgb, var(--qc-color, var(--accent)) 14%, transparent);
  color: var(--text-muted);
  font-size: 0.7rem;
  text-decoration: none;
  transition: all var(--duration) var(--ease);
}

.quote-collection-chip:hover {
  color: var(--accent);
  border-color: var(--border-accent);
}

/* Chips read as badges — no dot separator before them. */
.quote-footer > .quote-collection-chip::before {
  content: none;
}

/* Manage-collections modal checklist */
.quote-collection-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 260px;
  overflow-y: auto;
  margin-bottom: 12px;
}

.quote-collection-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--duration) var(--ease);
}

.quote-collection-option:hover {
  background: rgba(var(--tint-rgb), 0.06);
}

.quote-collection-option-name {
  flex: 1;
  font-size: 0.88rem;
  color: var(--text-primary);
}

.quote-collection-option-count {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.quote-collection-inline-create {
  display: flex;
  gap: 8px;
  align-items: center;
}

.quote-collection-inline-create input {
  flex: 1;
}

.quote-shelf {
  color: var(--text-muted);
}

.quote-page {
  color: var(--text-muted);
}

.quote-source {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.quote-notes {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border-subtle);
}

.quote-notes-label {
  font-style: normal;
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-right: 2px;
}

/* Floated top-right so quote text wraps around it — no dead bottom row, and
   long first lines can never run underneath the buttons. */
.quote-actions {
  float: right;
  display: flex;
  gap: 6px;
  margin: 0 0 6px 12px;
  opacity: 0;
  transition: opacity var(--duration) var(--ease);
}

.quote-card:hover .quote-actions,
.quote-card:focus-within .quote-actions {
  opacity: 1;
}

/* Touch devices have no hover: keep the actions visible. */
@media (hover: none) {
  .quote-actions {
    opacity: 0.85;
  }
}

/* ---------- Orphan ---------- */
.orphan-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
}

.orphan-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--warning-bg);
  border: 1px solid rgba(251, 191, 36, 0.15);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
}

.orphan-id {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.orphan-label {
  font-size: 0.78rem;
  color: var(--warning);
}

/* ---------- Section ---------- */
.section-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
}

.section-desc {
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.6;
  margin-bottom: 20px;
  max-width: 700px;
}

/* ---------- Empty State ---------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 80px 24px;
  color: var(--text-muted);
}

.empty-icon {
  width: 56px;
  height: 56px;
  margin-bottom: 20px;
  opacity: 0.4;
}

.empty-state h3 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 0.9rem;
  max-width: 360px;
  line-height: 1.5;
}

.empty-state .btn {
  margin-top: 20px;
}

.empty-state-sm {
  text-align: center;
  padding: 32px 24px;
  color: var(--text-muted);
  font-size: 0.88rem;
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 24px;
}

.modal-overlay.open {
  display: flex;
  animation: fadeIn 0.15s var(--ease);
}

.modal {
  background: var(--bg-modal);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.2s var(--ease);
}

.modal-shelf-editor {
  max-width: 460px;
}

.modal-cover-viewer {
  max-width: 96vw;
  width: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-subtle);
}

#modal-title {
  font-size: 1.05rem;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: all var(--duration) var(--ease);
}

.modal-close:hover {
  background: rgba(var(--tint-rgb), 0.06);
  color: var(--text-primary);
}

.modal-body {
  padding: 24px;
}

.modal-shelf-editor .modal-header {
  padding: 14px 18px;
}

.modal-shelf-editor .modal-body {
  padding: 14px 18px 16px;
}

.modal-cover-viewer .modal-body {
  padding: 16px 20px 20px;
}

.modal-form-compact .form-group {
  margin-bottom: 12px;
}

.modal-form-compact .form-group label {
  margin-bottom: 4px;
}

.modal-form-compact .form-group textarea {
  min-height: 52px;
}

.modal-form-compact .btn.btn-full {
  margin-top: 2px;
}

.modal-banner-remove-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border: 1px solid rgba(var(--tint-rgb), 0.32);
  border-radius: 999px;
  background: rgba(9, 13, 23, 0.72);
  color: rgba(255, 255, 255, 0.92);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
  transition: background var(--duration) var(--ease), border-color var(--duration) var(--ease), transform var(--duration) var(--ease);
}

.modal-banner-remove-btn:hover {
  background: rgba(190, 24, 93, 0.85);
  border-color: rgba(251, 113, 133, 0.9);
  transform: scale(1.04);
}

.cover-viewer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.cover-viewer-link {
  display: inline-flex;
  max-width: 88vw;
  max-height: 82vh;
}

.cover-viewer-image {
  display: block;
  max-width: 88vw;
  max-height: 82vh;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
}

.cover-viewer-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
}

/* ---------- Forms ---------- */
.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-group input,
.form-group textarea,
.form-group select,
.quote-collection-inline-create input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.875rem;
  font-family: inherit;
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--duration) var(--ease), box-shadow var(--duration) var(--ease);
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus,
.quote-collection-inline-create input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

.form-group textarea {
  resize: vertical;
  min-height: 60px;
}

.form-group select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%235a6478' viewBox='0 0 24 24'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.settings-section {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: rgba(var(--tint-rgb), 0.02);
  padding: 14px 16px;
  margin-bottom: 14px;
}

.settings-section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 10px;
}

.settings-static-value {
  margin-top: 6px;
  padding: 12px 14px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.35);
}

.settings-help-text {
  margin-top: 6px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.settings-inline-label {
  display: block;
  margin-bottom: 10px;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text-primary);
}

.settings-subsection {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid rgba(148, 163, 184, 0.2);
}

.cover-ratio-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.cover-ratio-option {
  position: relative;
  display: block;
  cursor: pointer;
}

.cover-ratio-option-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  background: rgba(var(--tint-rgb), 0.03);
  transition: all var(--duration) var(--ease);
}

.cover-ratio-option:hover .cover-ratio-option-body {
  border-color: var(--border-medium);
  background: rgba(var(--tint-rgb), 0.05);
}

.cover-ratio-input:checked + .cover-ratio-option-body {
  border-color: rgba(232, 178, 80, 0.55);
  background: rgba(232, 178, 80, 0.08);
  box-shadow: 0 0 0 1px rgba(232, 178, 80, 0.18) inset;
}

.cover-ratio-input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.cover-ratio-preview {
  min-height: 112px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, rgba(15, 23, 42, 0.55), rgba(22, 28, 40, 0.95));
  border: 1px solid rgba(var(--tint-rgb), 0.08);
}

.cover-ratio-preview-frame {
  display: block;
  width: 56px;
  aspect-ratio: var(--cover-preview-ratio, 2 / 3);
  border-radius: 8px;
  border: 1px solid rgba(232, 178, 80, 0.35);
  background: linear-gradient(145deg, #1a2540 0%, #12182a 50%, #1a1830 100%);
  box-shadow: 0 12px 22px rgba(0, 0, 0, 0.26);
}

.cover-ratio-preview-ratio-23 {
  --cover-preview-ratio: 2 / 3;
}

.cover-ratio-preview-ratio-34 {
  --cover-preview-ratio: 3 / 4;
}

.cover-ratio-preview-ratio-11 {
  --cover-preview-ratio: 1 / 1;
}

.cover-ratio-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cover-ratio-title {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-primary);
}

.cover-ratio-description {
  font-size: 0.76rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.cover-ratio-option:focus-within {
  border-radius: 14px;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

.form-group .toggle-control {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  margin-bottom: 0;
}

.settings-toggle-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 10px;
}

.form-group .toggle-control input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
  padding: 0;
  border: 0;
  background: transparent;
}

.toggle-slider {
  position: relative;
  width: 44px;
  height: 24px;
  min-width: 44px;
  border-radius: 999px;
  background: rgba(var(--tint-rgb), 0.16);
  border: 1px solid var(--border-medium);
  transition: all var(--duration) var(--ease);
  flex-shrink: 0;
}

.toggle-slider::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ffffff;
  transition: transform var(--duration) var(--ease);
}

.form-group .toggle-control input:checked + .toggle-slider {
  background: var(--accent-muted);
  border-color: var(--accent);
}

.form-group .toggle-control input:checked + .toggle-slider::after {
  transform: translateX(20px);
}

.toggle-text {
  display: inline-block;
  font-size: 0.86rem;
  color: var(--text-secondary);
  line-height: 1.35;
}

.global-read-book-results {
  margin-top: 8px;
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: rgba(var(--tint-rgb), 0.02);
}

.global-read-book-option {
  display: block;
  width: 100%;
  border: 0;
  border-bottom: 1px solid rgba(var(--tint-rgb), 0.06);
  background: transparent;
  color: var(--text-secondary);
  text-align: left;
  padding: 10px 12px;
  cursor: pointer;
}

.global-read-book-option-title {
  display: block;
  color: var(--text-primary);
  font-size: 0.85rem;
  line-height: 1.3;
}

.global-read-book-option-meta {
  display: block;
  margin-top: 3px;
  color: var(--text-muted);
  font-size: 0.76rem;
  line-height: 1.25;
}

.global-read-book-option:last-child {
  border-bottom: 0;
}

.global-read-book-option:hover,
.global-read-book-option:focus-visible {
  background: rgba(96, 165, 250, 0.12);
  color: var(--text-primary);
}

.global-read-book-empty {
  padding: 10px 12px;
  color: var(--text-muted);
  font-size: 0.84rem;
}

.ao3-icon-btn svg {
  width: 18px;
  height: 18px;
}

.ao3-icon-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid rgba(var(--tint-rgb), 0.18);
  background: rgba(var(--tint-rgb), 0.08);
  color: var(--text-primary);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 0.5rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.date-input-shell {
  position: relative;
}

.date-input-shell input[type="text"] {
  padding-right: 42px;
}

.date-picker-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  background: rgba(var(--tint-rgb), 0.05);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.date-picker-btn:hover,
.date-picker-btn:focus-visible {
  color: var(--text-primary);
  border-color: var(--border-medium);
  background: rgba(var(--tint-rgb), 0.12);
}

.date-picker-btn svg {
  width: 14px;
  height: 14px;
}

.date-picker-native {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.fandom-options-list {
  max-height: 280px;
  overflow: auto;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 6px;
  background: rgba(var(--tint-rgb), 0.02);
}

.fandom-option-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-secondary);
}

.fandom-option-item:hover {
  background: rgba(var(--tint-rgb), 0.06);
  color: var(--text-primary);
}

.fandom-option-item input {
  width: auto;
  accent-color: var(--accent);
}

.fandom-image-hint {
  margin-top: 4px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.fandom-image-preview {
  width: 192px;
  max-width: 100%;
  aspect-ratio: 16 / 9;
  height: auto;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  background: linear-gradient(145deg, #1a2035 0%, #0f1420 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.fandom-image-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.modal-actions-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

/* ---------- Toast ---------- */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 2000;
}

.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  font-size: 0.85rem;
  color: var(--text-primary);
  box-shadow: var(--shadow-md);
  animation: slideInRight 0.3s var(--ease), fadeOut 0.3s var(--ease) 2.7s forwards;
  max-width: 360px;
}

.toast-success {
  border-left: 3px solid var(--success);
}

.toast-error {
  border-left: 3px solid var(--danger);
}

/* ---------- Animations ---------- */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(40px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Page load animation */
.content-area {
  animation: fadeIn 0.3s var(--ease);
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-toggle {
    display: flex;
  }

  .main-content {
    margin-left: 0;
    width: 100%;
  }

  .top-bar {
    padding: 10px 16px;
    flex-wrap: wrap;
    align-items: flex-start;
  }

  .top-bar-actions {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .search-form {
    flex: 1 1 100%;
    max-width: none;
    min-width: 0;
  }

  /* The filter/sort buttons wrap to the LEFT edge on mobile, so their
     right-anchored dropdowns would open off-screen left — anchor left
     instead and cap the width to the viewport. */
  .search-filter-dropdown,
  .sort-dropdown {
    right: auto;
    left: 0;
    max-width: calc(100vw - 32px);
  }

  .content-area {
    padding: 20px 16px 40px;
  }

  .page-title {
    max-width: 200px;
    font-size: 1.1rem;
  }

  .search-input-shell {
    padding-right: 136px;
  }

  .search-form-library .search-input-shell {
    padding-right: 164px;
  }

  .search-form-library .search-submit-btn {
    right: 96px;
  }

  .search-input {
    width: auto;
    min-width: 90px;
  }

  .search-token-pills {
    max-width: 100%;
  }

  .search-form-library .search-token-pills {
    max-width: 100%;
  }

  .author-detail-toolbar-row {
    align-items: flex-start;
  }

  .author-detail-toolbar-row-primary .detail-actions,
  .author-detail-toolbar-row-secondary .view-toggle {
    margin-left: 0;
  }

  .fandom-pages-disclosure summary {
    padding: 9px 10px;
  }

  .fandom-pages-disclosure-thumb-wrap {
    width: 56px;
    height: 32px;
  }

  .fandom-pages-disclosure[open] .fandom-pages-disclosure-thumb-wrap {
    width: 56px;
    height: 32px;
  }

  /* One full-width fandom card per swipe on phones — the fixed 320px width
     left the card's right edge cut off next to the nav arrows. */
  .fandom-page-card {
    flex: 0 0 100%;
    width: 100%;
  }

  /* Auto-hiding top bar: app.js adds .top-bar-hidden while scrolling down
     (mobile only) so the tall wrapped bar stops eating screen height. */
  .top-bar {
    transition: transform 0.25s var(--ease);
  }

  .top-bar.top-bar-hidden {
    transform: translateY(-100%);
  }

  /* List view: pin the first (Title) column while the other columns scroll
     under it (the table is ~2000px wide; titles were the first thing lost).
     ID selectors + !important to outrank the desktop ID rules
     (position: relative on th, max-width: 340px on cells). */
  #library-datatable.dataTable thead th:first-child,
  #library-datatable.dataTable tbody td:first-child,
  #bookshelf-datatable.dataTable thead th:first-child,
  #bookshelf-datatable.dataTable tbody td:first-child,
  #author-datatable.dataTable thead th:first-child,
  #author-datatable.dataTable tbody td:first-child,
  #tag-datatable.dataTable thead th:first-child,
  #tag-datatable.dataTable tbody td:first-child,
  #fandom-datatable.dataTable thead th:first-child,
  #fandom-datatable.dataTable tbody td:first-child,
  #authors-datatable.dataTable thead th:first-child,
  #authors-datatable.dataTable tbody td:first-child,
  #author-shelf-datatable.dataTable thead th:first-child,
  #author-shelf-datatable.dataTable tbody td:first-child {
    position: sticky !important;
    left: 0;
    z-index: 2;
    /* Opaque stack: --bg-card alone is 75% alpha and would let scrolled
       columns ghost through the pinned one. */
    background-color: var(--bg-root);
    background-image: linear-gradient(var(--bg-card), var(--bg-card));
    width: 170px !important;
    min-width: 170px;
    max-width: 170px !important;
    border-right: 1px solid rgba(var(--tint-rgb), 0.18);
  }

  /* Header fields: flow all six cells (fandom/ship/rating/status/
     published/updated) through ONE two-column grid — the old per-row
     wrapping left blank cells to the right of Rating and Updated. */
  .my-fields-compact {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .my-fields-compact .my-compact-row-3 {
    display: contents;
  }

  .my-fields-compact .my-compact-line {
    grid-column: 1 / -1;
  }

  /* Thumb-sized hit areas for small controls (visual size unchanged where
     possible; 44px is the usual touch guideline, these were 24px). */
  .search-clear-btn {
    width: 36px;
    height: 36px;
    right: 4px;
  }

  .fandom-page-card-edit {
    width: 40px;
    height: 40px;
    bottom: 2px;
    right: 2px;
  }

  .ff-chip-x {
    padding: 8px 8px;
    margin: -8px -4px;
  }

  .search-token-pill-remove {
    padding: 8px 6px;
    margin: -8px -4px -8px -2px;
  }

  /* Filter-panel range/date inputs: shrink to fit — the natural width of
     two date pickers + separator overflowed the modal's right edge. */
  .ff-range .ff-num,
  .ff-range .ff-date {
    flex: 1 1 0;
    min-width: 0;
  }

  /* Filter-panel action bar: count + select-all on row 1, the action
     buttons side by side and equal-width on row 2 (they used to wrap
     unevenly across rows). */
  .ff-actionbar .ff-actionbar-spacer {
    flex: 0 0 100%;
    height: 0;
  }

  .ff-actionbar .btn {
    flex: 1 1 0;
    min-width: 0;
  }

  /* Modal action rows (e.g. fandom edit: Delete Page / Save Changes) —
     buttons could overflow past the modal's right edge on phones. */
  .modal-actions-row {
    flex-wrap: wrap;
  }

  .modal-actions-row .btn {
    flex: 1 1 auto;
    min-width: 0;
  }

  .book-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
  }

  .book-list {
    max-height: calc(100vh - 190px);
  }

  .book-list-header,
  .book-list-row {
    grid-template-columns:
      230px
      190px
      repeat(var(--book-list-custom-cols, 0), 130px);
  }

  .detail-header {
    flex-direction: column;
    gap: 20px;
  }

  /* Header is a column here: centre the cover instead of leaving dead space right. */
  .detail-cover {
    align-self: center;
  }

  .cover-lg {
    width: 140px;
    height: auto;
  }

  .quotes-masonry {
    columns: 1;
  }

  .form-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .book-grid {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 10px;
  }

  .shelf-grid {
    grid-template-columns: 1fr;
  }

  .author-grid {
    /* minmax(0, …), not plain 1fr: long unbroken author names otherwise
       floor the track at their min-content and push cards off-screen. */
    grid-template-columns: minmax(0, 1fr);
  }

  .author-card {
    min-width: 0;
  }

  .author-card .author-info,
  .author-card .author-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Book detail header: compact actions so two buttons fit per row. */
  .detail-title {
    font-size: 1.4rem;
  }

  .detail-actions {
    gap: 8px;
  }

  .detail-actions .btn {
    padding: 0 12px;
    height: 36px;
    font-size: 0.8rem;
    gap: 6px;
  }

  .detail-action-count {
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    font-size: 0.7rem;
  }

  /* Tab strip: two-column grid, left-aligned — the old horizontal scroll
     hid the "Metadata" tab entirely with no affordance it existed. */
  .tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tab {
    white-space: nowrap;
    padding: 8px 10px;
    font-size: 0.8rem;
    text-align: left;
  }

  /* Book-detail action buttons: two equal columns, full-width buttons
     (content centering comes from the base .btn rule). Scoped to the book
     header — author pages reuse .detail-actions in their toolbar. */
  .detail-meta .detail-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .detail-meta .detail-actions .btn,
  .detail-meta .detail-actions .epub-menu-container,
  .detail-meta .detail-actions .epub-menu-container .btn,
  .detail-meta .detail-actions .reading-now-group {
    width: 100%;
  }

  /* Stats strip: 2x2 grid with the dot separators dropped, so the kudos
     heart sits directly under the chapters icon when the strip wraps. */
  .my-stats-strip {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 12px;
  }

  .my-stat + .my-stat::before {
    content: none;
    margin-right: 0;
  }

  /* Prev/next strip: drop the position counter, keep the buttons. */
  .book-nav-position {
    display: none;
  }
}

/* ---------- Star Rating Input ---------- */
.star-rating-input {
  display: flex;
  align-items: center;
  gap: 4px;
}

.star-input {
  font-size: 1.5rem;
  color: var(--text-muted);
  opacity: 0.3;
  cursor: pointer;
  transition: all var(--duration) var(--ease);
  user-select: none;
}

.star-input:hover {
  opacity: 0.6;
  transform: scale(1.15);
}

.star-input.filled {
  color: var(--accent);
  opacity: 1;
}

.star-input.half {
  color: var(--accent);
  opacity: 0.55;
}

.rating-step-btn {
  border: 1px solid var(--border-subtle);
  background: rgba(var(--tint-rgb), 0.04);
  color: var(--text-secondary);
  border-radius: 6px;
  width: 24px;
  height: 24px;
  line-height: 1;
  font-weight: 700;
  cursor: pointer;
}

.rating-step-btn:hover {
  color: var(--text-primary);
  border-color: var(--border-medium);
}

.rating-display {
  margin-left: 10px;
  font-size: 0.82rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ---------- Select Options ---------- */
.form-group select option {
  background: #1a1f2e;
  color: var(--text-primary);
}

/* ---------- Utility ---------- */
code {
  background: rgba(var(--tint-rgb), 0.06);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85em;
  font-family: 'SF Mono', 'Fira Code', monospace;
}

/* ---------- Author Search Results (Modal) ---------- */
.author-search-results {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 380px;
  overflow-y: auto;
}

.author-search-result {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: rgba(var(--tint-rgb), 0.03);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  transition: all var(--duration) var(--ease);
}

.author-search-result:hover {
  background: rgba(var(--tint-rgb), 0.06);
  border-color: var(--border-medium);
}

.author-search-result.already-added {
  opacity: 0.5;
}

.author-search-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(96, 165, 250, 0.2), rgba(96, 165, 250, 0.05));
  border: 1px solid rgba(96, 165, 250, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--info);
  flex-shrink: 0;
}

.author-search-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.author-search-name {
  font-size: 0.88rem;
  font-weight: 550;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.author-search-books {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.author-search-badge {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  padding: 4px 10px;
  background: rgba(var(--tint-rgb), 0.04);
  border-radius: 12px;
}

.search-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ---------- Add-fanfic advanced filter panel ---------- */
.modal-filter-panel {
  max-width: 720px;
}

.filter-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.ff-textsearch .search-input {
  width: 100%;
}

.ff-groups {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: rgba(var(--tint-rgb), 0.02);
}

.ff-groups-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  list-style: none;
  user-select: none;
}

.ff-groups-summary::-webkit-details-marker {
  display: none;
}

.ff-groups-summary:hover {
  background: rgba(var(--tint-rgb), 0.03);
}

.ff-groups-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.ff-groups-chevron {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  color: var(--text-muted);
  transition: transform var(--duration) var(--ease);
}

.ff-groups[open] .ff-groups-chevron {
  transform: rotate(90deg);
}

.ff-clear {
  background: none;
  border: none;
  color: var(--info);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}

.ff-clear:hover {
  background: rgba(var(--tint-rgb), 0.06);
}

.ff-groups-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 18px;
  padding: 4px 14px 14px;
}

/* Author `display: grid` above overrides the UA rule that hides a closed
   <details>'s content, so re-hide it explicitly when collapsed. */
.ff-groups:not([open]) .ff-groups-body {
  display: none;
}

.ff-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.ff-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  font-weight: 600;
}

.ff-chip-input {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.ff-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.ff-chips:empty {
  display: none;
}

.ff-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.78rem;
  padding: 3px 6px 3px 9px;
  background: rgba(var(--tint-rgb), 0.06);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  color: var(--text-primary);
}

.ff-chip-x {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}

.ff-chip-x:hover {
  color: var(--danger);
}

.ff-typeahead {
  position: relative;
  display: flex;
  gap: 6px;
  align-items: stretch;
}

.ff-input {
  flex: 1;
  min-width: 0;
}

.ff-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.ff-mode,
.ff-segmented {
  display: inline-flex;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  overflow: hidden;
  width: max-content;
  flex-shrink: 0;
}

.ff-mode-btn {
  font-size: 0.68rem;
  padding: 2px 8px;
  background: none;
  border: none;
  border-right: 1px solid var(--border-subtle);
  color: var(--text-muted);
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.ff-mode-btn:last-child {
  border-right: none;
}

.ff-mode-btn.is-active {
  background: rgba(96, 165, 250, 0.18);
  color: var(--info);
}

.ff-incexc {
  flex-shrink: 0;
  width: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  line-height: 1;
  background: rgba(var(--tint-rgb), 0.04);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--info);
  cursor: pointer;
}

.ff-incexc:hover {
  border-color: var(--border-medium);
}

.ff-incexc.is-exclude {
  color: var(--danger);
  background: rgba(220, 80, 80, 0.1);
  border-color: rgba(220, 80, 80, 0.35);
}

.ff-chip-exclude {
  background: rgba(220, 80, 80, 0.12);
  border-color: rgba(220, 80, 80, 0.32);
  color: var(--danger);
}

.ff-topbar {
  display: flex;
  gap: 8px;
  align-items: center;
}

.ff-search-shell {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-sm);
  transition: all var(--duration) var(--ease);
}

.ff-search-shell:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

.ff-search-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--text-muted);
}

.ff-search-input {
  flex: 1;
  min-width: 0;
  padding: 0;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 0.875rem;
  font-family: inherit;
}

.ff-search-input::placeholder {
  color: var(--text-muted);
}

.ff-expand {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  background: rgba(var(--tint-rgb), 0.04);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--duration) var(--ease);
}

.ff-expand svg {
  width: 17px;
  height: 17px;
}

.ff-expand:hover {
  color: var(--text-primary);
  border-color: var(--border-medium);
}

.ff-expand.is-active {
  color: var(--info);
  border-color: rgba(96, 165, 250, 0.4);
  background: rgba(96, 165, 250, 0.14);
}

/* Full-screen expanded modal */
.modal.modal-fullpage {
  max-width: 96vw;
  width: 96vw;
  max-height: 94vh;
  height: 94vh;
  display: flex;
  flex-direction: column;
}

.modal.modal-fullpage .modal-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.modal-fullpage .ff-groups-body {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.modal-fullpage .author-search-results {
  max-height: none;
}

.ff-input,
.ff-num,
.ff-date {
  width: 100%;
  padding: 6px 10px;
  font-size: 0.82rem;
  background: var(--bg-modal);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
}

.ff-input:focus,
.ff-num:focus,
.ff-date:focus {
  outline: none;
  border-color: var(--border-medium);
}

.ff-suggest {
  position: absolute;
  z-index: 30;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  max-height: 220px;
  overflow-y: auto;
  background: var(--bg-modal);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
}

.ff-suggest-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 7px 10px;
  font-size: 0.82rem;
  color: var(--text-primary);
  cursor: pointer;
}

.ff-suggest-item:hover {
  background: rgba(var(--tint-rgb), 0.08);
}

.ff-suggest-count {
  font-size: 0.72rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.ff-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.ff-toggle {
  font-size: 0.78rem;
  padding: 4px 10px;
  background: rgba(var(--tint-rgb), 0.04);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--duration) var(--ease);
}

.ff-toggle:hover {
  border-color: var(--border-medium);
  color: var(--text-primary);
}

.ff-toggle.is-active {
  background: rgba(96, 165, 250, 0.18);
  border-color: rgba(96, 165, 250, 0.4);
  color: var(--info);
}

.ff-segmented {
  display: inline-flex;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  overflow: hidden;
  width: max-content;
}

.ff-seg {
  font-size: 0.78rem;
  padding: 5px 12px;
  background: none;
  border: none;
  border-right: 1px solid var(--border-subtle);
  color: var(--text-muted);
  cursor: pointer;
}

.ff-seg:last-child {
  border-right: none;
}

.ff-seg.is-active {
  background: rgba(96, 165, 250, 0.18);
  color: var(--info);
}

.ff-range {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ff-range-sep {
  color: var(--text-muted);
}

.ff-actionbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
  flex-wrap: wrap;
}

.ff-count {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 550;
}

.ff-selectall {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.8rem;
  color: var(--text-muted);
  cursor: pointer;
}

.ff-actionbar-spacer {
  flex: 1;
}

.ff-result {
  cursor: pointer;
}

.ff-result.already-added {
  cursor: default;
}

.ff-check {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.ff-more {
  display: flex;
  justify-content: center;
}

.ff-more:empty {
  display: none;
}

.ff-loadmore-btn {
  width: 100%;
}

/* ---------- Currently reading indicator ---------- */

/* Book detail: "Reading" pill + finish/stop actions */
.reading-now-group {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.reading-now-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--info);
  background: rgba(96, 165, 250, 0.14);
  border: 1px solid rgba(96, 165, 250, 0.4);
  border-radius: var(--radius-md);
  white-space: nowrap;
}

.reading-now-pill svg {
  width: 14px;
  height: 14px;
}

.reading-now-stop {
  flex-shrink: 0;
}

/* Sidebar nav: currently-reading count pill */
.nav-reading-count {
  margin-left: auto;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--info);
  background: rgba(96, 165, 250, 0.14);
  border: 1px solid rgba(96, 165, 250, 0.35);
  border-radius: 9px;
  padding: 0 7px;
  line-height: 1.5;
}

/* Reading log: currently-reading strip */
.currently-reading-section {
  margin-bottom: 20px;
}

.currently-reading-heading {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 10px;
}

.currently-reading-heading svg {
  width: 18px;
  height: 18px;
  color: var(--info);
}

.currently-reading-count {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  background: rgba(var(--tint-rgb), 0.06);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 1px 8px;
}

.currently-reading-strip {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 6px;
}

.currently-reading-card {
  display: flex;
  gap: 10px;
  align-items: stretch;
  min-width: 260px;
  max-width: 320px;
  flex-shrink: 0;
  padding: 10px;
  background: rgba(var(--tint-rgb), 0.03);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.currently-reading-cover {
  flex-shrink: 0;
  width: 48px;
  height: 68px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: rgba(var(--tint-rgb), 0.06);
}

.currently-reading-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.currently-reading-cover-placeholder {
  display: block;
  padding: 4px;
  font-size: 0.6rem;
  color: var(--text-muted);
  overflow: hidden;
}

.currently-reading-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.currently-reading-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.currently-reading-title:hover {
  color: var(--accent);
}

.currently-reading-author {
  font-size: 0.76rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.currently-reading-since {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.currently-reading-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: auto;
  padding-top: 4px;
}

@media (max-width: 640px) {
  .ff-groups-body,
  .modal-fullpage .ff-groups-body {
    grid-template-columns: 1fr;
  }
}

/* ---------- Light theme fixes for hardcoded dark surfaces ---------- */
[data-theme="light"] .top-bar {
  background: rgba(250, 249, 246, 0.85);
}

[data-theme="light"] .reading-stats-panel {
  background: rgba(255, 255, 255, 0.9);
}

[data-theme="light"] .book-list-header {
  background: rgba(248, 247, 243, 0.99);
}

[data-theme="light"] .fandom-pages-disclosure {
  background: rgba(255, 255, 255, 0.55);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.6),
    inset 0 10px 20px rgba(15, 23, 42, 0.05);
}

[data-theme="light"] .fandom-pages-nav {
  background: rgba(255, 255, 255, 0.8);
}

[data-theme="light"] .fandom-pages-nav:hover {
  background: rgba(255, 255, 255, 0.95);
}

/* ---------- Light theme: edit/delete icon buttons (contrast fix) ---------- */
[data-theme="light"] .read-action-icon {
  color: var(--text-secondary);
  border-color: var(--border-medium);
  background: rgba(var(--tint-rgb), 0.04);
}

[data-theme="light"] .read-action-edit:hover {
  color: #1d4ed8;
  border-color: rgba(29, 78, 216, 0.4);
  background: rgba(29, 78, 216, 0.1);
}

[data-theme="light"] .read-action-delete:hover {
  color: var(--danger);
  border-color: rgba(185, 28, 28, 0.45);
  background: var(--danger-bg);
}

/* ---------- Light theme: reading-log month tiles ---------- */
[data-theme="light"] .reading-month-tile {
  background: var(--accent-muted);
  border-color: var(--border-accent);
}

[data-theme="light"] .reading-month-tile-current {
  background: rgba(232, 178, 80, 0.3);
  border-color: rgba(176, 124, 21, 0.65);
  box-shadow: 0 0 0 1px rgba(176, 124, 21, 0.3) inset;
}

[data-theme="light"] .reading-month-tile-future {
  background: rgba(15, 23, 42, 0.04);
  border-color: var(--border-medium);
}

[data-theme="light"] .reading-month-name {
  color: var(--text-secondary);
}

[data-theme="light"] .reading-month-tile-future .reading-month-name {
  color: var(--text-muted);
}

[data-theme="light"] .reading-month-tile-heat-1 {
  background: rgba(176, 124, 21, 0.12);
}

[data-theme="light"] .reading-month-tile-heat-2 {
  background: rgba(176, 124, 21, 0.24);
}

[data-theme="light"] .reading-month-tile-heat-3 {
  background: rgba(176, 124, 21, 0.4);
}

/* Light theme: the top-5 counts and year arrows were too pale (light blue) —
   use the same dark gold as the top-10 read-count badges. */
[data-theme="light"] .reading-top-count {
  color: var(--accent-hover);
}

[data-theme="light"] .reading-year-arrow,
[data-theme="light"] .reading-year-arrow:hover {
  color: var(--accent-hover);
}

/* ---------- Light theme: settings page contrast fixes ---------- */
[data-theme="light"] .settings-static-value {
  background: rgba(15, 23, 42, 0.04);
  border-color: var(--border-medium);
}

[data-theme="light"] .form-group .toggle-control input:checked + .toggle-slider {
  background: var(--accent-solid);
  border-color: var(--accent-solid-hover);
}

[data-theme="light"] .toggle-slider::after {
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.28);
}

[data-theme="light"] .cover-ratio-preview {
  background: linear-gradient(145deg, rgba(15, 23, 42, 0.05), rgba(15, 23, 42, 0.1));
  border-color: var(--border-medium);
}

[data-theme="light"] .cover-ratio-preview-frame {
  background: linear-gradient(145deg, #ffffff 0%, #f3ead6 100%);
  border-color: rgba(176, 124, 21, 0.5);
  box-shadow: 0 8px 16px rgba(15, 23, 42, 0.14);
}
