/* BYoB Modern Minimalist Design System */

:root {
  /* Default: Modern Monochrome (Black, Grey, White) */
  --bg-primary: #141518;
  --bg-surface: #1c1e22;
  --bg-card: #24272e;
  --bg-hover: #2d3138;
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --border-color: #363a44;
  --border-active: #ffffff;
  --accent: #ffffff;
  --accent-secondary: #d1d1d6;
  --accent-text: #000000;
  --highlight-bg: rgba(255, 255, 255, 0.14);
  --highlight-border: #ffffff;
  --shadow-subtle: 0 2px 10px rgba(0, 0, 0, 0.4);
  --shadow-card: 0 4px 18px rgba(0, 0, 0, 0.45);
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 10px;
  --radius-pill: 9999px;
  
  --font-times: "Times New Roman", Times, serif;
  --font-merriweather: "Merriweather", Georgia, serif;
  --font-georgia: Georgia, "Times New Roman", serif;
  --font-palatino: "Palatino Linotype", Palatino, "Book Antiqua", serif;
  --font-lora: "Lora", Georgia, serif;
  --font-ptserif: "PT Serif", Georgia, serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Inter", sans-serif;
  --font-roboto: "Roboto", -apple-system, sans-serif;
  --font-opensans: "Open Sans", -apple-system, sans-serif;
  --font-lato: "Lato", -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", "Space Mono", "Courier New", monospace;
  --font-dyslexic: "Atkinson Hyperlegible", -apple-system, sans-serif;
  
  /* Times New Roman as primary default */
  --reader-font: var(--font-times);
  --reader-font-size: 19px;
  --reader-line-height: 1.85;
  --reader-letter-spacing: 0px;
  --reader-width: 760px;
  
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

/* 1. Monochrome Dark (Default) */
[data-theme="monochrome-dark"], [data-theme="brutalist-dark"], [data-theme="monochrome"] {
  --bg-primary: #141518;
  --bg-surface: #1c1e22;
  --bg-card: #24272e;
  --bg-hover: #2d3138;
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --border-color: #363a44;
  --border-active: #ffffff;
  --accent: #ffffff;
  --accent-secondary: #d0d7de;
  --accent-text: #000000;
  --highlight-bg: rgba(255, 255, 255, 0.14);
  --highlight-border: #ffffff;
  --shadow-subtle: 0 2px 10px rgba(0, 0, 0, 0.4);
  --shadow-card: 0 4px 18px rgba(0, 0, 0, 0.45);
}

/* 1b. Graphite: plain dark grey, no blue in it. The "less boring than slate black" one. */
[data-theme="graphite-dark"] {
  --bg-primary: #2a2a2a;
  --bg-surface: #333333;
  --bg-card: #3b3b3b;
  --bg-hover: #474747;
  --text-primary: #ececec;
  --text-secondary: #b0b0b0;
  --text-muted: #878787;
  --border-color: #4d4d4d;
  --border-active: #ffffff;
  --accent: #f2f2f2;
  --accent-secondary: #d4d4d4;
  --accent-text: #1c1c1c;
  --highlight-bg: rgba(255, 255, 255, 0.13);
  --highlight-border: #ffffff;
  --shadow-subtle: 0 2px 10px rgba(0, 0, 0, 0.35);
  --shadow-card: 0 4px 18px rgba(0, 0, 0, 0.4);
}

/* 1c. Warm Dark: dark brown-grey with cream text. Easiest on the eyes at night. */
[data-theme="warm-dark"] {
  --bg-primary: #221d19;
  --bg-surface: #2b2520;
  --bg-card: #342d27;
  --bg-hover: #403830;
  --text-primary: #f0e6d8;
  --text-secondary: #bdae9c;
  --text-muted: #8e8273;
  --border-color: #4a4138;
  --border-active: #e8b773;
  --accent: #e8b773;
  --accent-secondary: #d2a261;
  --accent-text: #221d19;
  --highlight-bg: rgba(232, 183, 115, 0.18);
  --highlight-border: #e8b773;
  --shadow-subtle: 0 2px 10px rgba(0, 0, 0, 0.4);
  --shadow-card: 0 4px 18px rgba(0, 0, 0, 0.45);
}

/* 1d. Dark Sepia: the warm-paper feel without the brightness. */
[data-theme="sepia-dark"] {
  --bg-primary: #2b2419;
  --bg-surface: #352d20;
  --bg-card: #3f3627;
  --bg-hover: #4b4130;
  --text-primary: #e9dcc3;
  --text-secondary: #bfae8e;
  --text-muted: #938468;
  --border-color: #544834;
  --border-active: #c99b55;
  --accent: #d9ab63;
  --accent-secondary: #c2954f;
  --accent-text: #2b2419;
  --highlight-bg: rgba(217, 171, 99, 0.2);
  --highlight-border: #d9ab63;
  --shadow-subtle: 0 2px 10px rgba(0, 0, 0, 0.4);
  --shadow-card: 0 4px 18px rgba(0, 0, 0, 0.45);
}

/* 1e. Forest: deep green-grey, calm without being cold. */
[data-theme="forest-dark"] {
  --bg-primary: #1b2420;
  --bg-surface: #222d28;
  --bg-card: #2a3630;
  --bg-hover: #35433b;
  --text-primary: #e4ece6;
  --text-secondary: #a8bbb0;
  --text-muted: #7b8c83;
  --border-color: #3c4b43;
  --border-active: #8fd3ad;
  --accent: #8fd3ad;
  --accent-secondary: #74bb94;
  --accent-text: #15201b;
  --highlight-bg: rgba(143, 211, 173, 0.16);
  --highlight-border: #8fd3ad;
  --shadow-subtle: 0 2px 10px rgba(0, 0, 0, 0.4);
  --shadow-card: 0 4px 18px rgba(0, 0, 0, 0.45);
}

/* 1f. Plum: dark violet-grey. Different enough to be a mood change. */
[data-theme="plum-dark"] {
  --bg-primary: #221c2a;
  --bg-surface: #2b2435;
  --bg-card: #332b3f;
  --bg-hover: #3f354d;
  --text-primary: #ece6f2;
  --text-secondary: #b6abc4;
  --text-muted: #8a8098;
  --border-color: #473c55;
  --border-active: #c4a2e8;
  --accent: #c4a2e8;
  --accent-secondary: #ab8ad0;
  --accent-text: #1d1724;
  --highlight-bg: rgba(196, 162, 232, 0.17);
  --highlight-border: #c4a2e8;
  --shadow-subtle: 0 2px 10px rgba(0, 0, 0, 0.4);
  --shadow-card: 0 4px 18px rgba(0, 0, 0, 0.45);
}

/* 1g. Nord: cool steel blue-grey, lower contrast than Slate Dark. */
[data-theme="nord-dark"] {
  --bg-primary: #2e3440;
  --bg-surface: #3b4252;
  --bg-card: #434c5e;
  --bg-hover: #4c566a;
  --text-primary: #eceff4;
  --text-secondary: #c2cbd8;
  --text-muted: #8b96a8;
  --border-color: #4c566a;
  --border-active: #88c0d0;
  --accent: #88c0d0;
  --accent-secondary: #81a1c1;
  --accent-text: #2e3440;
  --highlight-bg: rgba(136, 192, 208, 0.18);
  --highlight-border: #88c0d0;
  --shadow-subtle: 0 2px 10px rgba(0, 0, 0, 0.35);
  --shadow-card: 0 4px 18px rgba(0, 0, 0, 0.4);
}

/* 2. Monochrome Light */
[data-theme="monochrome-light"], [data-theme="brutalist-light"] {
  --bg-primary: #ffffff;
  --bg-surface: #f6f8fa;
  --bg-card: #ffffff;
  --bg-hover: #eaeef2;
  --text-primary: #1f2328;
  --text-secondary: #57606a;
  --text-muted: #8c959f;
  --border-color: #d0d7de;
  --border-active: #0969da;
  --accent: #000000;
  --accent-secondary: #24292f;
  --accent-text: #ffffff;
  --highlight-bg: rgba(0, 0, 0, 0.08);
  --highlight-border: #1f2328;
  --shadow-subtle: 0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-card: 0 4px 14px rgba(0, 0, 0, 0.08);
}

/* 3. Sepia Warm Paper */
[data-theme="sepia-parchment"] {
  --bg-primary: #f7f1e5;
  --bg-surface: #ede3d1;
  --bg-card: #fdf8ed;
  --bg-hover: #e5dac5;
  --text-primary: #2d261e;
  --text-secondary: #65584b;
  --text-muted: #8e8071;
  --border-color: #d6c8b4;
  --border-active: #8b5a2b;
  --accent: #8b5a2b;
  --accent-secondary: #a06834;
  --accent-text: #ffffff;
  --highlight-bg: rgba(139, 90, 43, 0.16);
  --highlight-border: #8b5a2b;
  --shadow-subtle: 0 2px 8px rgba(78, 52, 28, 0.08);
  --shadow-card: 0 4px 14px rgba(78, 52, 28, 0.1);
}

/* 4. OLED Blackout */
[data-theme="oled-blackout"] {
  --bg-primary: #000000;
  --bg-surface: #0a0a0a;
  --bg-card: #121212;
  --bg-hover: #1c1c1c;
  --text-primary: #c9d1d9;
  --text-secondary: #7d8590;
  --text-muted: #484f58;
  --border-color: #21262d;
  --border-active: #ffffff;
  --accent: #ffffff;
  --accent-secondary: #e6edf3;
  --accent-text: #000000;
  --highlight-bg: rgba(255, 255, 255, 0.1);
  --highlight-border: #ffffff;
  --shadow-subtle: 0 2px 8px rgba(0, 0, 0, 0.6);
  --shadow-card: 0 4px 16px rgba(0, 0, 0, 0.7);
}

/* 5. WebNovel Warm Paper */
[data-theme="webnovel-paper"] {
  --bg-primary: #f8f4e6;
  --bg-surface: #eee5d5;
  --bg-card: #f3ece0;
  --bg-hover: #e5dac7;
  --text-primary: #2c2c2c;
  --text-secondary: #666055;
  --text-muted: #8a8275;
  --border-color: #dcd4c4;
  --border-active: #3e3428;
  --accent: #3e3428;
  --accent-secondary: #574b3d;
  --accent-text: #ffffff;
  --highlight-bg: rgba(62, 52, 40, 0.12);
  --highlight-border: #3e3428;
  --shadow-subtle: 0 2px 8px rgba(50, 40, 30, 0.08);
  --shadow-card: 0 4px 14px rgba(50, 40, 30, 0.1);
}

/* 6. WebNovel Eye-Protection Mint */
[data-theme="webnovel-mint"] {
  --bg-primary: #e8f5e9;
  --bg-surface: #d8edd9;
  --bg-card: #def2e0;
  --bg-hover: #cbe6cd;
  --text-primary: #1b4332;
  --text-secondary: #2d6a4f;
  --text-muted: #52796f;
  --border-color: #b7dbba;
  --border-active: #1b4332;
  --accent: #1b4332;
  --accent-secondary: #2d6a4f;
  --accent-text: #ffffff;
  --highlight-bg: rgba(27, 67, 50, 0.15);
  --highlight-border: #1b4332;
  --shadow-subtle: 0 2px 8px rgba(20, 50, 35, 0.08);
  --shadow-card: 0 4px 14px rgba(20, 50, 35, 0.1);
}

/* 7. WebNovel Slate Dark */
[data-theme="webnovel-dark"] {
  --bg-primary: #23272e;
  --bg-surface: #1e2227;
  --bg-card: #282c34;
  --bg-hover: #323842;
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border-color: #3b4252;
  --border-active: #ffffff;
  --accent: #ffffff;
  --accent-secondary: #cbd5e1;
  --accent-text: #000000;
  --highlight-bg: rgba(255, 255, 255, 0.14);
  --highlight-border: #ffffff;
  --shadow-subtle: 0 2px 10px rgba(0, 0, 0, 0.4);
  --shadow-card: 0 4px 18px rgba(0, 0, 0, 0.45);
}

/* 8. WebNovel Midnight Ocean */
[data-theme="webnovel-ocean"] {
  --bg-primary: #0f172a;
  --bg-surface: #162038;
  --bg-card: #1e293b;
  --bg-hover: #26354d;
  --text-primary: #cbd5e1;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border-color: #334155;
  --border-active: #38bdf8;
  --accent: #38bdf8;
  --accent-secondary: #7dd3fc;
  --accent-text: #0f172a;
  --highlight-bg: rgba(56, 189, 248, 0.16);
  --highlight-border: #38bdf8;
  --shadow-subtle: 0 2px 10px rgba(0, 0, 0, 0.5);
  --shadow-card: 0 4px 18px rgba(0, 0, 0, 0.6);
}

/* Font Choices */
[data-font="times"], [data-font="serif"] { --reader-font: var(--font-times); }
[data-font="merriweather"] { --reader-font: var(--font-merriweather); }
[data-font="georgia"] { --reader-font: var(--font-georgia); }
[data-font="palatino"] { --reader-font: var(--font-palatino); }
[data-font="lora"] { --reader-font: var(--font-lora); }
[data-font="ptserif"] { --reader-font: var(--font-ptserif); }
[data-font="sans"] { --reader-font: var(--font-sans); }
[data-font="roboto"] { --reader-font: var(--font-roboto); }
[data-font="opensans"] { --reader-font: var(--font-opensans); }
[data-font="lato"] { --reader-font: var(--font-lato); }
[data-font="mono"] { --reader-font: var(--font-mono); }
[data-font="dyslexic"] { --reader-font: var(--font-dyslexic); }

/* Reading Width */
[data-width="narrow"] { --reader-width: 620px; }
[data-width="normal"] { --reader-width: 760px; }
[data-width="wide"] { --reader-width: 940px; }
[data-width="full"] { --reader-width: 100%; }

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-sans);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  transition: background-color 0.25s ease, color 0.25s ease;
  -webkit-font-smoothing: antialiased;
}

/* Sleek Harmonized Button System */
.btn-brutal {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}

.btn-brutal:hover {
  background: var(--bg-hover);
  border-color: var(--text-secondary);
}

.btn-brutal:active {
  transform: translateY(1px);
  box-shadow: none;
}

/* Button Sizing */
.btn-sm,
.btn-brutal.btn-sm {
  height: 28px;
  padding: 0 9px;
  font-size: 11.5px;
  border-radius: var(--radius-sm);
}

.btn-lg,
.btn-brutal.btn-lg {
  height: 42px;
  padding: 0 20px;
  font-size: 14px;
  border-radius: var(--radius-md);
}

/* Button Color Variants */
.btn-brutal-accent {
  background: var(--accent) !important;
  color: var(--accent-text) !important;
  border-color: var(--accent) !important;
  font-weight: 700;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

.btn-brutal-accent svg {
  fill: currentColor;
}

.btn-brutal-accent:hover {
  filter: brightness(0.95);
  background: var(--accent-secondary) !important;
  color: var(--accent-text) !important;
  border-color: var(--accent-secondary) !important;
}

.btn-brutal-accent:active {
  background: var(--accent-secondary) !important;
  color: var(--accent-text) !important;
}

.btn-brutal-danger {
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.35);
  background: rgba(239, 68, 68, 0.06);
}

.btn-brutal-danger:hover {
  color: #f87171;
  border-color: #ef4444;
  background: rgba(239, 68, 68, 0.16);
}

.btn-brutal-ghost {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}

.btn-brutal-ghost:hover {
  background: var(--bg-hover);
  border-color: var(--border-color);
}

/* Segmented Control Switcher */
.segmented-control {
  display: inline-flex;
  align-items: center;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 7px;
  padding: 2px;
  gap: 2px;
}

.segmented-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 28px;
  padding: 0 10px;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  white-space: nowrap;
}

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

.segmented-btn.active {
  background: var(--bg-card);
  color: var(--text-primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  border-color: var(--border-color);
}

.badge-brutal {
  display: inline-block;
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-secondary);
}

.badge-brutal.accent {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

/* App Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  backdrop-filter: blur(8px);
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.logo-icon {
  width: 28px;
  height: 28px;
  background: var(--accent);
  color: var(--accent-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  border-radius: var(--radius-sm);
}

.logo-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.logo-sub {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Main Container */
.main-content {
  flex: 1;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 18px;
}

/* Reading: the fixed top bar sets the spacing at the top, so the page's own vertical padding
   would only be dead space under it. Side padding stays, it is the reading margin. */
body.reading-mode .main-content {
  padding-top: 0;
  padding-bottom: 0;
}

/* Resume Hero Banner */
.resume-hero {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  box-shadow: var(--shadow-card);
  padding: 22px;
  margin-bottom: 32px;
  display: grid;
  grid-template-columns: 85px 1fr auto;
  gap: 20px;
  align-items: center;
}

.resume-cover {
  width: 85px;
  height: 120px;
  object-fit: cover;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
}

.resume-info h3 {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.resume-info h2, #resumeNovelTitle {
  font-family: var(--font-times);
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 6px;
  line-height: 1.25;
  cursor: pointer;
  transition: color 0.15s ease;
}

.resume-info h2:hover, #resumeNovelTitle:hover {
  color: var(--accent-secondary);
}

.resume-chapter-tag {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.progress-bar-container {
  height: 5px;
  background: var(--bg-primary);
  border-radius: var(--radius-pill);
  width: 100%;
  max-width: 280px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: var(--radius-pill);
  width: 0%;
  transition: width 0.3s ease;
}

/* ==========================================================================
   Library Section & Toolbar
   ========================================================================== */
.library-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
}

.library-toolbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.library-toolbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.section-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.2px;
  margin: 0;
}

/* Compact Search Bar */
.library-search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.library-search-icon {
  position: absolute;
  left: 10px;
  color: var(--text-muted);
  pointer-events: none;
}

.library-search-input {
  height: 34px;
  padding: 0 28px 0 30px;
  font-family: var(--font-sans);
  font-size: 12.5px;
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  width: 180px;
  transition: all 0.15s ease;
}

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

.library-search-input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg-card);
  box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.15);
  width: 210px;
}

.library-search-clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

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

/* Sort Selector */
.library-sort-control {
  display: flex;
  align-items: center;
  gap: 6px;
}

.library-sort-label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.library-sort-select {
  height: 34px;
  padding: 0 26px 0 10px;
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 500;
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='none' stroke='%23888888' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round' d='M1 1l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.library-sort-select:hover {
  border-color: var(--text-secondary);
}

.library-sort-select:focus {
  outline: none;
  border-color: var(--accent);
}

/* ==========================================================================
   Tile View (Grid)
   ========================================================================== */
.novel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.novel-card {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  box-shadow: var(--shadow-subtle);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.novel-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-card);
  border-color: var(--text-secondary);
}

.novel-card-cover-wrap {
  position: relative;
  cursor: pointer;
  overflow: hidden;
  background: var(--bg-card);
  width: 100%;
  aspect-ratio: 16 / 10;
}

.novel-card-cover-wrap::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.4) 0%, transparent 45%);
  pointer-events: none;
}

.novel-card-cover {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.2s ease;
}

.novel-card:hover .novel-card-cover {
  transform: scale(1.02);
}

.cover-overlay-badge {
  position: absolute;
  bottom: 6px;
  right: 6px;
  background: rgba(10, 10, 12, 0.92) !important;
  border: 1px solid rgba(255, 255, 255, 0.35) !important;
  border-radius: 4px;
  padding: 2px 7px;
  font-size: 10px;
  font-weight: 600;
  color: #ffffff !important;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  opacity: 0.95;
  transition: opacity 0.15s ease, background 0.15s ease;
  z-index: 2;
}

.cover-overlay-badge:hover {
  opacity: 1;
  background: #000000 !important;
  border-color: #ffffff !important;
  color: #ffffff !important;
}

.novel-card-body {
  padding: 14px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.novel-card-title {
  font-family: var(--font-times);
  font-size: 16px;
  font-weight: 700;
  line-height: 1.25;
  margin-bottom: 3px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  cursor: pointer;
  transition: color 0.15s ease;
}

.novel-card-title:hover {
  color: var(--accent-secondary);
}

.novel-card-author {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.novel-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 10px;
}

.novel-card-progress {
  margin-bottom: 12px;
}

.novel-card-progress-info {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.novel-card-progress-info span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 150px;
}

.novel-card-actions {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.novel-card-actions .novel-card-primary-action {
  width: 100%;
}

.novel-card-actions .novel-card-secondary-actions {
  display: flex;
  gap: 5px;
  width: 100%;
}

.novel-card-actions .novel-card-secondary-actions .btn-brutal {
  flex: 1;
}

/* ==========================================================================
   List View
   ========================================================================== */
.novel-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.novel-card-list {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  box-shadow: var(--shadow-subtle);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.novel-card-list:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-card);
  border-color: var(--text-secondary);
}

.novel-list-cover-wrap {
  width: 60px;
  height: 84px;
  flex-shrink: 0;
  border-radius: 5px;
  overflow: hidden;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  position: relative;
  cursor: pointer;
}

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

.novel-list-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.novel-list-title {
  font-family: var(--font-times);
  font-size: 16px;
  font-weight: 700;
  line-height: 1.3;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  transition: color 0.15s ease;
}

.novel-list-title:hover {
  color: var(--accent-secondary);
}

.novel-list-author {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.novel-list-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin: 2px 0;
}

.novel-list-progress-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 320px;
}

.novel-list-progress-info {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

.novel-list-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* ==========================================================================
   Reader View (WebNovel Style with Auto-Hiding Menus)
   ========================================================================== */
.reader-container {
  display: none;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  width: 100%;
}

/* Solid strip under the status bar / Dynamic Island.
   Sits below every header (so a visible header still paints it) but above the page text, so when a
   header hides, or the page is scrolled, the inset stays a flat theme colour instead of blurred text. */
.safe-area-scrim {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--safe-top);
  background: var(--bg-primary);
  z-index: 140;
  pointer-events: none;
}

/* Auto-Hiding Top Bar (Lowered on Mobile to avoid iPhone status bar/notch overlap) */
.reader-top-bar {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 150;
  width: 100%;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  padding: calc(14px + var(--safe-top)) 18px 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  backdrop-filter: blur(14px);
  box-sizing: border-box;
  transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.25s ease;
}

.reader-top-bar.minimized {
  transform: translateY(-100%);
  opacity: 0;
  pointer-events: none;
}

#backToLibraryBtn,
#readerMenuBtn,
#drawerBackToLibraryBtn,
#footerLibraryBtn,
#footerMenuBtn,
#floatingQuickMenuBtn {
  cursor: pointer;
  position: relative;
  z-index: 160;
  pointer-events: auto !important;
}

.reader-ch-info {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  min-width: 0;
  flex: 1 1 auto;
}

.reader-ch-info strong {
  font-family: var(--font-times);
  color: var(--text-primary);
  font-size: 14px;
}

.reader-progress-pill {
  font-size: 11px;
  font-weight: 600;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-color);
  padding: 3px 8px;
  background: var(--bg-surface);
}

/* Reading Body (Times New Roman Main Font & Configurable Edge-to-Edge Margins)
   `body` already pads the top and bottom insets, so the wrapper must not count them again:
   it only clears the fixed top bar (--reader-bar-h, measured in reader.js) and the floating bar. */
.reader-body-wrapper {
  width: 100%;
  max-width: var(--reader-width);
  padding: calc(var(--reader-bar-h, 122px) - var(--safe-top) + 10px) var(--reader-padding-x, 6px) 100px var(--reader-padding-x, 6px);
  font-family: var(--reader-font);
  font-size: var(--reader-font-size);
  line-height: var(--reader-line-height);
  letter-spacing: var(--reader-letter-spacing, 0px);
  transition: max-width 0.2s ease, font-size 0.15s ease;
  box-sizing: border-box;
  cursor: pointer; /* Centerscreen tap indicator */
}

.chapter-separator-banner {
  border-top: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  padding: 12px;
  text-align: center;
  /* Always the first block of a chapter, so no top margin: the wrapper already spaces it off the bar. */
  margin: 0 0 24px 0;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
}

.reader-heading {
  font-family: var(--font-times);
  font-size: 1.5em;
  font-weight: 700;
  margin: 32px 0 20px 0;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
  line-height: 1.25;
}

.reader-paragraph {
  margin-bottom: 1.35em;
  text-align: left;
  text-rendering: optimizeLegibility;
  word-break: break-word;
  letter-spacing: var(--reader-letter-spacing, 0px);
  line-height: var(--reader-line-height, 1.85);
  position: relative;
  padding: 2px 2px;
  border-radius: var(--radius-sm);
  transition: background 0.12s ease;
}

/* TTS Speaking Focus & Highlight */
.reader-paragraph.speaking-active,
.reader-heading.speaking-active {
  background: rgba(255, 255, 255, 0.12) !important;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
}

[data-theme="monochrome-light"] .reader-paragraph.speaking-active,
[data-theme="monochrome-light"] .reader-heading.speaking-active {
  background: rgba(0, 0, 0, 0.08) !important;
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.08);
}

.reader-image, .reader-content img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 28px auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: #1a1c20;
}

/* Chapter Bottom Navigation */
.reader-footer-nav {
  margin-top: 45px;
  padding-top: 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  gap: 8px;
  width: 100%;
  justify-content: center;
  align-items: center;
}

.reader-footer-nav .btn-brutal,
.btn-footer-nav {
  flex: 1;
  font-size: 12px;
  padding: 6px 10px;
  min-height: 32px;
  max-height: 36px;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Floating Action Bar (Hides on scroll down) */
.reader-floating-bar {
  position: fixed;
  bottom: calc(20px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 95;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-card);
  display: flex;
  align-items: center;
  padding: 4px 6px;
  gap: 4px;
  transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.25s ease;
  backdrop-filter: blur(12px);
}

.reader-floating-bar.minimized {
  transform: translate(-50%, 140%);
  opacity: 0;
  pointer-events: none;
}

.reader-floating-bar .btn-brutal {
  min-height: 36px;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  border: none;
  box-shadow: none;
  font-size: 12px;
}

/* Floating Discreet Menu Toggle Button (Always accessible) */
.floating-quick-menu-btn {
  position: fixed;
  bottom: calc(20px + var(--safe-bottom));
  right: 20px;
  z-index: 155;
  height: 40px;
  padding: 0 14px;
  border-radius: var(--radius-pill);
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-card);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: transform 0.2s ease, background 0.15s ease;
}

.floating-quick-menu-btn:hover {
  background: var(--bg-hover);
  transform: scale(1.04);
}

.floating-quick-menu-btn:active {
  transform: scale(0.95);
}

/* Active Floating Pill for Auto-Scroll */
.autoscroll-pill {
  position: fixed;
  bottom: calc(75px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 96;
  background: var(--bg-surface);
  border: 1px solid var(--border-active);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-card);
  padding: 6px 14px;
  display: none;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  font-weight: 600;
  backdrop-filter: blur(10px);
}

/* ==========================================================================
   Active Floating Mini Badge (Desktop PC + Draggable Mobile)
   ========================================================================== */
.tts-mini-badge {
  position: fixed;
  bottom: 74px;
  right: 20px;
  z-index: 160;
  background: var(--bg-surface);
  border: 1px solid var(--border-active);
  border-radius: 30px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  padding: 6px 12px;
  display: none;
  align-items: center;
  backdrop-filter: blur(12px);
  user-select: none;
  transition: box-shadow 0.2s ease, transform 0.15s ease;
}

.tts-pc-only {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.tts-mobile-only {
  display: none;
}

.tts-skip-btn {
  min-height: 28px;
  padding: 3px 8px;
  font-size: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.tts-play-btn {
  min-height: 28px;
  padding: 3px 12px;
  font-size: 12px;
  font-weight: 700;
}

.tts-rate-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  padding: 0 4px;
}

.tts-mini-cover-wrap {
  position: relative;
  width: 32px;
  height: 44px;
  border-radius: 4px;
  border: 1px solid var(--border-color);
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  margin-right: 4px;
  transition: transform 0.15s ease;
}

.tts-mini-cover-wrap:hover {
  transform: scale(1.05);
}

.tts-mini-cover-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 3px;
}

.tts-mini-cover-placeholder {
  font-size: 14px;
}

.tts-mini-cog {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}

.sleep-timer-badge {
  background: var(--accent);
  color: var(--accent-text);
  border-radius: var(--radius-pill);
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 700;
}

/* Mobile Draggable Floating Badge */
@media (max-width: 768px) {
  .tts-pc-only {
    display: none !important;
  }
  .tts-mobile-only {
    display: inline-flex !important;
    align-items: center;
    gap: 8px;
  }

  .tts-mini-badge {
    position: fixed;
    bottom: calc(75px + var(--safe-bottom));
    right: 14px;
    padding: 6px 8px;
    border-radius: 26px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.55);
    touch-action: none;
    cursor: grab;
  }

  .tts-mini-badge:active {
    cursor: grabbing;
  }

  .tts-mobile-btn {
    min-height: 32px;
    padding: 4px 10px;
    font-size: 13px;
  }
}

/* ==========================================================================
   Full-Screen Mobile Audiobook Mode
   ========================================================================== */
.audiobook-full-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 250;
  background: var(--bg-primary);
  display: none;
  flex-direction: column;
  justify-content: space-between;
  padding: calc(14px + var(--safe-top)) 18px calc(24px + var(--safe-bottom)) 18px;
  box-sizing: border-box;
  animation: audiobookSlideUp 0.26s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
}

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

.audiobook-full-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.audiobook-minimize-btn {
  font-size: 12px;
  padding: 5px 12px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.audiobook-cog-btn {
  width: 32px;
  height: 32px;
  min-height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  transition: transform 0.12s ease, background 0.15s ease, color 0.15s ease;
}

.audiobook-cog-btn:hover {
  color: var(--accent);
  background: var(--bg-card);
}

.audiobook-cog-btn:active {
  transform: scale(0.94);
}

.audiobook-header-info {
  flex: 1;
  text-align: center;
  overflow: hidden;
}

.audiobook-header-title {
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
}

.audiobook-header-chapter {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.audiobook-full-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px 0;
  overflow: hidden;
}

.audiobook-book-icon-wrap {
  width: 76px;
  height: 106px;
  border-radius: 6px;
  border: 1px solid var(--border-active);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  background: var(--bg-surface);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  flex-shrink: 0;
  overflow: hidden;
}

.audiobook-modal-cover {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.audiobook-modal-cover-placeholder {
  font-size: 32px;
}

.audiobook-spoken-card {
  width: 100%;
  max-width: 580px;
  flex: 1;
  max-height: 46vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 18px 16px;
  border-radius: 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-card);
  overflow-y: auto;
  box-sizing: border-box;
}

.audiobook-para-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}

.audiobook-spoken-text {
  font-size: 18px;
  line-height: 1.7;
  font-family: var(--font-active, serif);
  color: var(--text-primary);
  letter-spacing: 0.2px;
  user-select: text;
}

.tts-word {
  display: inline;
  padding: 1px 3px;
  border-radius: 3px;
  transition: background 0.12s ease, color 0.12s ease;
}

.tts-word-active {
  background: var(--accent) !important;
  color: var(--accent-text) !important;
  font-weight: 700;
  border-radius: 4px;
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.45);
}

[data-theme="monochrome-light"] .tts-word-active {
  background: #000000 !important;
  color: #ffffff !important;
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.35);
}

[data-theme="sepia-parchment"] .tts-word-active {
  background: #8b5a2b !important;
  color: #ffffff !important;
  box-shadow: 0 0 8px rgba(139, 90, 43, 0.35);
}

.tts-word-spoken {
  opacity: 0.65;
}

.audiobook-full-footer {
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex-shrink: 0;
  padding-top: 10px;
  border-top: 1px solid var(--border-color);
}

/* Audiobook Transport Bar */
.audiobook-transport-bar,
.audiobook-transport-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  box-sizing: border-box;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-pill);
  padding: 4px 6px;
  gap: 4px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.audiobook-bar-btn {
  flex: 1;
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: var(--radius-pill);
  color: var(--text-primary);
  cursor: pointer;
  padding: 6px 8px;
  transition: background 0.15s ease, transform 0.1s ease, color 0.15s ease;
}

.audiobook-bar-btn:hover {
  background: var(--bg-hover);
}

.audiobook-bar-btn:active {
  transform: scale(0.93);
  background: var(--highlight-bg);
}

.audiobook-bar-btn.audiobook-bar-play {
  flex: 1.4;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.audiobook-bar-btn.audiobook-bar-play:hover {
  filter: brightness(1.08);
}

.audiobook-bar-btn.audiobook-bar-play:active {
  transform: scale(0.95);
}

.audiobook-skip-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.audiobook-skip-btn:active {
  transform: scale(0.92);
  background: var(--highlight-bg);
}

.audiobook-main-play-btn {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: var(--accent);
  border: 1px solid var(--accent);
  color: var(--accent-text);
  font-size: 22px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  transition: transform 0.12s ease;
}

.audiobook-main-play-btn:active {
  transform: scale(0.94);
}

.audiobook-settings-compact {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg-surface);
  border-radius: 8px;
  padding: 8px 12px;
  border: 1px solid var(--border-color);
}

.audiobook-compact-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.audiobook-compact-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  width: 45px;
  text-transform: uppercase;
}

.audiobook-speed-chips {
  display: flex;
  gap: 6px;
  flex: 1;
  overflow-x: auto;
}

.speed-chip {
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid var(--border-color);
  background: var(--bg-primary);
  color: var(--text-secondary);
  cursor: pointer;
}

.speed-chip.selected {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

.audiobook-compact-select {
  flex: 1;
  font-size: 12px;
  padding: 4px 8px;
  min-height: 30px;
}

/* ==========================================================================
   Master Side Panel (Streamlined Single Hub)
   ========================================================================== */
.drawer.master-panel {
  position: fixed;
  top: 0;
  right: -100%;
  width: 100%;
  max-width: 440px;
  height: 100vh;
  background: var(--bg-primary);
  border-left: 1px solid var(--border-color);
  z-index: 210;
  display: flex;
  flex-direction: column;
  transition: right 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.4);
}

.drawer.master-panel.open {
  right: 0;
}

.master-panel-title {
  font-size: 15px;
  font-weight: 700;
}

.master-nav-tabs {
  display: flex;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  padding: 4px;
  gap: 4px;
}

.master-tab-btn {
  flex: 1;
  padding: 8px 4px;
  background: transparent;
  color: var(--text-secondary);
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: center;
}

.master-tab-btn:hover {
  color: var(--text-primary);
  background: var(--bg-card);
}

.master-tab-btn.active {
  color: var(--accent-text);
  background: var(--accent);
  font-weight: 600;
}

.master-panel-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.master-tab-content {
  display: none;
}

.master-tab-content.active {
  display: block;
}

.drawer-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
  z-index: 205;
  display: none;
}

.drawer-backdrop.open {
  display: block;
}

.drawer-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-surface);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.drawer-search-input {
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  padding: 10px 14px;
  outline: none;
  margin-bottom: 12px;
  transition: border-color 0.15s ease;
}

.drawer-search-input:focus {
  border-color: var(--border-active);
}

.toc-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
}

.toc-volume-header {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 12px 6px 6px 6px;
  border-bottom: 1px solid var(--border-color);
  margin-top: 14px;
  margin-bottom: 6px;
}

.toc-item {
  padding: 10px 10px;
  border-radius: var(--radius-sm);
  border-bottom: 1px solid transparent;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background 0.12s ease;
}

.toc-item:hover {
  background: var(--bg-surface);
}

.toc-item.active {
  background: var(--highlight-bg);
  border-left: 2px solid var(--accent);
  font-weight: 600;
}

.toc-item-words {
  font-size: 11px;
  color: var(--text-muted);
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-content {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-surface);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-surface);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Multi-File Upload Queue and Reordering */
.upload-file-item {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  margin-bottom: 8px;
  background: var(--bg-surface);
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.upload-file-item:hover {
  border-color: var(--border-active);
}

.upload-file-item-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1 1 auto;
}

.upload-order-badge {
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--accent-text);
  flex-shrink: 0;
}

.upload-file-details {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.upload-file-name {
  font-weight: 600;
  color: var(--text-primary);
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-file-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.upload-item-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.upload-reorder-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  min-height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.upload-reorder-btn:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--border-active);
}

.upload-reorder-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.upload-remove-btn {
  background: transparent;
  border: 1px solid transparent;
  color: #ef4444;
  border-radius: var(--radius-sm);
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  min-height: 26px;
  transition: all 0.15s ease;
}

.upload-remove-btn:hover {
  background: rgba(239, 68, 68, 0.1);
  border-color: #ef4444;
}

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

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 7px;
  letter-spacing: 0.2px;
}

.form-select, .form-input {
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  padding: 10px 14px;
  outline: none;
  min-height: 42px;
  transition: border-color 0.15s ease;
}

.form-select:focus, .form-input:focus {
  border-color: var(--border-active);
}

.grid-choices {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
  gap: 8px;
}

.choice-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  padding: 8px 10px;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.choice-btn.selected {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
  font-weight: 600;
}

.range-slider {
  width: 100%;
  height: 5px;
  accent-color: var(--accent);
  margin: 10px 0;
}

/* Toast */
.toast-container {
  position: fixed;
  top: calc(70px + var(--safe-top));
  right: 18px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  padding: 10px 18px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  pointer-events: auto;
  animation: slideIn 0.2s ease;
}

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Subtle Audiobook Percentage Badge */
.audiobook-para-pct {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
}

/* Mobile Offline Badges & Alerts (Amber Luminous Aesthetic) */
.mobile-offline-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 700;
  color: #f59e0b;
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.4);
  padding: 2px 7px;
  border-radius: var(--radius-pill);
  letter-spacing: 0.3px;
  text-transform: uppercase;
  animation: offlinePulse 3s infinite ease-in-out;
}

@keyframes offlinePulse {
  0%, 100% { opacity: 0.85; border-color: rgba(245, 158, 11, 0.35); }
  50% { opacity: 1; border-color: rgba(245, 158, 11, 0.75); }
}

.audiobook-offline-status {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 700;
  color: #f59e0b;
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.4);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  letter-spacing: 0.2px;
}

/* Margin Presets */
[data-margin="edge"] {
  --reader-padding-x: 2px;
}
[data-margin="edge"] .reader-paragraph {
  padding-left: 0px;
  padding-right: 0px;
}
[data-margin="compact"] {
  --reader-padding-x: 12px;
}
[data-margin="comfortable"] {
  --reader-padding-x: 22px;
}

/* Menu Active Word Light Highlight */
.toc-item.active {
  background: var(--bg-surface);
  border-left: 3px solid var(--accent);
  font-weight: 600;
}

.toc-item.active .toc-chapter-title {
  background: rgba(255, 255, 255, 0.16);
  color: var(--text-primary);
  padding: 2px 7px;
  border-radius: 4px;
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.12);
  display: inline-block;
}

[data-theme="monochrome-light"] .toc-item.active .toc-chapter-title {
  background: rgba(0, 0, 0, 0.09);
  color: #000000;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.06);
}

/* Mobile Overscroll Infinite Scroll Indicators */
.overscroll-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  border: 1px dashed var(--border-color);
  border-radius: 8px;
  background: var(--bg-surface);
  margin: 10px 0;
  opacity: 0;
  transform: scale(0.98);
  transition: opacity 0.2s ease, transform 0.2s ease, color 0.15s ease, border-color 0.15s ease, max-height 0.2s ease;
  user-select: none;
  pointer-events: none;
}

/* Collapse top indicator to 0 height when idle so it leaves zero blank space above chapter title */
.overscroll-indicator.top-indicator {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  margin-top: 0;
  margin-bottom: 0;
  border-color: transparent;
  overflow: hidden;
  opacity: 0;
}

.overscroll-indicator.top-indicator.pulling,
.overscroll-indicator.top-indicator.armed {
  max-height: 60px;
  padding: 10px 14px;
  margin: 8px 0;
  border-color: var(--border-color);
  opacity: 1;
}

.overscroll-indicator.armed {
  opacity: 1;
  color: var(--accent);
  border-color: var(--accent);
  border-style: solid;
  transform: scale(1.02);
}

/* Chapter End Scroll Tip (Small, subtle, non-intrusive) */
.reader-chapter-end-tip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 24px auto 10px;
  padding: 5px 14px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--text-muted);
  opacity: 0.65;
  border-radius: var(--radius-pill);
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  width: fit-content;
  max-width: 90%;
  pointer-events: none;
  user-select: none;
}

.reader-chapter-end-tip .tip-icon-down {
  display: inline-flex;
  align-items: center;
  color: var(--text-muted);
  animation: subtleTipBounce 2.4s infinite ease-in-out;
}

@keyframes subtleTipBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(2.5px); }
}

/* Mobile Slide-Up Quick Reader Sheet (High z-index to never be overlapped) */
.quick-sheet-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  z-index: 245;
  display: none;
  opacity: 0;
  transition: opacity 0.22s ease;
}

.quick-sheet-backdrop.open {
  display: block;
  opacity: 1;
}

.mobile-quick-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
  z-index: 250;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-bottom: none;
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  box-shadow: 0 -10px 36px rgba(0, 0, 0, 0.6);
  box-sizing: border-box;
  padding: 10px 16px calc(22px + var(--safe-bottom)) 16px;
  transform: translateY(105%);
  transition: transform 0.26s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 88vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.mobile-quick-sheet button {
  appearance: none;
  -webkit-appearance: none;
  outline: none;
  font-family: inherit;
  user-select: none;
  -webkit-user-select: none;
}

.mobile-quick-sheet.open {
  transform: translateY(0);
}

.quick-sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--border-active);
  margin: 0 auto 4px auto;
  opacity: 0.35;
}

.quick-sheet-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  box-sizing: border-box;
}

/* 1. Chapter Navigation Bar */
.quick-sheet-nav-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  box-sizing: border-box;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 4px 8px;
  min-height: 40px;
  gap: 6px;
}

.quick-sheet-nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-primary);
  background: transparent;
  border: none;
  cursor: pointer;
  border-radius: 8px;
  white-space: nowrap;
  transition: background 0.12s ease;
}

.quick-sheet-nav-btn:hover:not(:disabled) {
  background: var(--bg-hover);
}

.quick-sheet-nav-btn:active:not(:disabled) {
  transform: scale(0.96);
}

.quick-sheet-chapter-info {
  flex: 1;
  text-align: center;
  overflow: hidden;
  padding: 0 4px;
}

.quick-sheet-chapter-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.2px;
}

/* 2. 4-Item Quick Action Clipart Grid */
.quick-sheet-action-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  width: 100%;
  box-sizing: border-box;
}

.quick-action-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 8px 4px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  cursor: pointer;
  min-height: 60px;
  color: var(--text-primary);
  width: 100%;
  box-sizing: border-box;
  transition: transform 0.1s ease, border-color 0.15s ease, background 0.15s ease;
}

.quick-action-tile:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
}

.quick-action-tile:active {
  transform: scale(0.96);
}

.quick-action-tile.active {
  border-color: var(--accent);
  background: var(--bg-hover);
  box-shadow: 0 0 0 1px var(--accent);
}

.quick-tile-icon-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  color: var(--text-primary);
  flex-shrink: 0;
}

.quick-tile-label {
  font-size: 10.5px;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  color: var(--text-secondary);
}

.quick-action-tile:hover .quick-tile-label,
.quick-action-tile.active .quick-tile-label {
  color: var(--text-primary);
}

/* 3. Narration Speed Chips Row */
.quick-sheet-speed-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 8px 10px;
  width: 100%;
  box-sizing: border-box;
}

.quick-sheet-speed-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.quick-sheet-speed-title {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.quick-sheet-speed-val {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-primary);
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  padding: 1px 7px;
  border-radius: var(--radius-pill);
}

.quick-sheet-speed-chips {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  width: 100%;
  box-sizing: border-box;
}

.quick-sheet-speed-chip {
  padding: 6px 2px;
  font-size: 11px;
  font-weight: 600;
  text-align: center;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-surface);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.12s ease;
}

.quick-sheet-speed-chip:hover {
  border-color: var(--text-secondary);
  color: var(--text-primary);
}

.quick-sheet-speed-chip.selected {
  border-color: var(--border-active);
  background: var(--bg-hover);
  color: var(--text-primary);
  font-weight: 800;
  box-shadow: 0 0 0 1px var(--border-active);
}

/* 3.5 Auto-Scroll Active Control Bar (Visible when active) */
.quick-sheet-autoscroll-bar {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 8px 10px;
  width: 100%;
  box-sizing: border-box;
}

.quick-autoscroll-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.quick-autoscroll-title {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.quick-autoscroll-speed-val {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-primary);
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  padding: 1px 7px;
  border-radius: var(--radius-pill);
}

.quick-autoscroll-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
}

.quick-autoscroll-stepper {
  display: flex;
  align-items: center;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow: hidden;
}

.quick-autoscroll-btn {
  min-width: 32px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  font-weight: 700;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.quick-autoscroll-btn:hover {
  background: var(--bg-hover);
}

.quick-autoscroll-stop-btn {
  height: 28px;
  padding: 0 12px;
  font-size: 11px;
  font-weight: 700;
  color: #ef4444 !important;
  background: var(--bg-surface);
  border: 1px solid rgba(239, 68, 68, 0.4);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.12s ease;
}

.quick-autoscroll-stop-btn:hover {
  background: rgba(239, 68, 68, 0.12);
  border-color: #ef4444;
}

/* 4. Typography & Spacing Steppers */
.quick-sheet-steppers {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 8px 10px;
  width: 100%;
  box-sizing: border-box;
}

.quick-stepper-row-font {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.quick-stepper-grid-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
  box-sizing: border-box;
}

.quick-stepper-col {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 3px 6px;
  width: 100%;
  box-sizing: border-box;
}

.quick-stepper-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
}

.quick-stepper-pill {
  display: flex;
  align-items: center;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow: hidden;
}

.quick-stepper-btn {
  min-width: 32px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  font-weight: 700;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s ease;
}

.quick-stepper-btn:hover {
  background: var(--bg-hover);
}

.quick-stepper-btn:active {
  transform: scale(0.94);
}

.quick-stepper-val {
  font-size: 11.5px;
  font-weight: 700;
  min-width: 38px;
  text-align: center;
  color: var(--text-primary);
  border-left: 1px solid var(--border-color);
  border-right: 1px solid var(--border-color);
  padding: 0 4px;
}

/* Bionic Reading Fixation (Font-Agnostic & Italics-Compatible) */
.bionic-fixation {
  font-weight: var(--bionic-fixation-weight, 850) !important;
  font-size: var(--bionic-fixation-scale, 1.2em);
  font-family: inherit !important;
  display: inline;
  color: var(--text-primary);
  line-height: 1;
  vertical-align: baseline;
}

em .bionic-fixation,
i .bionic-fixation,
cite .bionic-fixation,
dfn .bionic-fixation,
.italic .bionic-fixation,
[style*="italic"] .bionic-fixation,
[style*="oblique"] .bionic-fixation {
  font-style: italic !important;
  font-weight: var(--bionic-fixation-weight, 850) !important;
  font-size: var(--bionic-fixation-scale, 1.2em);
  font-family: inherit !important;
  line-height: 1;
  vertical-align: baseline;
}

.bionic-fragment {
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  color: inherit;
}

/* Quick Sheet Bionic Reading Bar */
.quick-sheet-bionic-bar {
  display: flex;
  flex-direction: column;
  gap: 7px;
  width: 100%;
  box-sizing: border-box;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 8px 12px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.quick-sheet-bionic-bar:hover {
  border-color: var(--accent);
}

.quick-bionic-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  box-sizing: border-box;
}

.quick-bionic-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.quick-bionic-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
}

.quick-bionic-title {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.2px;
}

.quick-bionic-slider-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  box-sizing: border-box;
  transition: opacity 0.15s ease;
}

.quick-bionic-slider-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  min-width: 24px;
}

.quick-bionic-slider-row input[type="range"],
.quick-sheet-speed-row input[type="range"] {
  flex: 1;
  min-width: 0;
  height: 6px;
  accent-color: var(--accent);
  cursor: pointer;
  margin: 0;
  padding: 0;
}

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

.quick-bionic-stepper {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 2px 4px;
}

.quick-bionic-step-btn {
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  padding: 1px 6px;
  line-height: 1;
  border-radius: 4px;
  transition: all 0.15s ease;
}

.quick-bionic-step-btn:hover {
  background: var(--bg-hover);
  color: var(--accent);
}

.quick-bionic-step-val {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-primary);
  min-width: 34px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.quick-bionic-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
  appearance: none;
  -webkit-appearance: none;
}

.quick-bionic-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border-color);
  transition: background 0.15s ease;
}

.quick-bionic-btn.active {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
}

.quick-bionic-btn.active .quick-bionic-indicator {
  background: #000;
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.4);
}

/* Reading Mode Choice Buttons (Master Panel) */
.reading-mode-btn {
  font-weight: 600;
}

/* Quick Sheet Bionic Row (Legacy Fallback) */
.quick-sheet-bionic-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  box-sizing: border-box;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 8px 12px;
  min-height: 42px;
}

.quick-sheet-bionic-label {
  display: flex;
  flex-direction: column;
  cursor: pointer;
  user-select: none;
}

.quick-bionic-sub {
  font-size: 10px;
  color: var(--text-muted);
}

.quick-sheet-checkbox,
.settings-checkbox {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
  cursor: pointer;
  margin: 0;
}

/* Master Panel Settings Toggle Row */
.toggle-control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 8px;
}

.toggle-label {
  display: flex;
  flex-direction: column;
  cursor: pointer;
}

.toggle-label-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.toggle-subtext {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* 5. Quick Footer Toggles (Margin & Theme Switch) */
.quick-sheet-footer-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
  box-sizing: border-box;
}

.quick-sheet-footer-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  height: 36px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.12s ease;
  width: 100%;
  box-sizing: border-box;
}

.quick-sheet-footer-btn:hover {
  border-color: var(--accent);
  color: var(--text-primary);
  background: var(--bg-hover);
}

.quick-sheet-footer-btn:active {
  transform: scale(0.97);
}

.quick-sheet-clipart {
  stroke: currentColor;
  vertical-align: middle;
  flex-shrink: 0;
}

/* 6. Audiobook Sound Bars Loading Animation */
.audiobook-loading-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 140px;
  width: 100%;
  margin: auto 0;
}

.audiobook-sound-bars {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
}

.audiobook-sound-bars span,
.audiobook-sound-bar {
  display: inline-block;
  width: 5px;
  height: 100%;
  background: var(--accent, #ffffff);
  border-radius: 3px;
  animation: soundBarBounce 1.2s ease-in-out infinite alternate;
  -webkit-animation: soundBarBounce 1.2s ease-in-out infinite alternate;
}

.audiobook-sound-bars span:nth-child(1),
.audiobook-sound-bar:nth-child(1) { animation-delay: 0.1s; -webkit-animation-delay: 0.1s; }
.audiobook-sound-bars span:nth-child(2),
.audiobook-sound-bar:nth-child(2) { animation-delay: 0.3s; -webkit-animation-delay: 0.3s; }
.audiobook-sound-bars span:nth-child(3),
.audiobook-sound-bar:nth-child(3) { animation-delay: 0.0s; -webkit-animation-delay: 0.0s; }
.audiobook-sound-bars span:nth-child(4),
.audiobook-sound-bar:nth-child(4) { animation-delay: 0.4s; -webkit-animation-delay: 0.4s; }
.audiobook-sound-bars span:nth-child(5),
.audiobook-sound-bar:nth-child(5) { animation-delay: 0.2s; -webkit-animation-delay: 0.2s; }

@keyframes soundBarBounce {
  0% { height: 8px; opacity: 0.35; transform: scaleY(0.25); }
  100% { height: 36px; opacity: 1; transform: scaleY(1); }
}

@-webkit-keyframes soundBarBounce {
  0% { -webkit-transform: scaleY(0.25); height: 8px; opacity: 0.35; }
  100% { -webkit-transform: scaleY(1); height: 36px; opacity: 1; }
}

.audiobook-loading-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted, var(--text-secondary));
  letter-spacing: 0.8px;
  text-transform: uppercase;
  text-align: center;
}

/* Brutalist Spinner Animation */
@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@-webkit-keyframes spin {
  0% { -webkit-transform: rotate(0deg); }
  100% { -webkit-transform: rotate(360deg); }
}

.spinner-brutal {
  display: inline-block;
  width: 28px;
  height: 28px;
  border: 3px solid var(--border-color);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  -webkit-animation: spin 0.8s linear infinite;
  box-sizing: border-box;
  flex-shrink: 0;
}

/* Responsive adjustments & Overlap Prevention */
@media (max-width: 768px) {
  /* Mobile Toolbar Layout */
  .library-toolbar {
    gap: 10px;
    margin-bottom: 14px;
    padding-bottom: 10px;
  }
  .library-toolbar-left {
    flex: 1 1 auto;
  }
  .library-toolbar-right {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .library-search-box {
    flex: 1 1 120px;
    min-width: 110px;
  }
  .library-search-input {
    width: 100%;
    font-size: 12px;
    height: 32px;
  }
  .library-search-input:focus {
    width: 100%;
  }
  .library-sort-control {
    flex: 0 0 auto;
  }
  .library-sort-label {
    display: none;
  }
  .library-sort-select {
    height: 32px;
    font-size: 11.5px;
    padding: 0 20px 0 8px;
    max-width: 105px;
  }
  .segmented-control {
    flex: 0 0 auto;
  }
  .segmented-btn {
    height: 26px;
    padding: 0 7px;
    font-size: 11px;
    gap: 4px;
  }

  /* Strictly 2-across Tile Layout on Mobile */
  .novel-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px !important;
  }

  .novel-card-cover-wrap {
    aspect-ratio: 16 / 11;
  }

  .novel-card-body {
    padding: 8px;
  }

  .novel-card-title {
    font-size: 13px;
    line-height: 1.2;
    margin-bottom: 2px;
  }

  .novel-card-author {
    font-size: 11px;
    margin-bottom: 6px;
  }

  .novel-card-meta {
    gap: 4px;
    margin-bottom: 6px;
  }

  .novel-card-meta .badge-brutal {
    font-size: 9px;
    padding: 1px 5px;
  }

  .novel-card-progress {
    margin-bottom: 8px;
  }

  .novel-card-progress-info {
    font-size: 10px;
  }

  .novel-card-progress-info span:first-child {
    max-width: 90px;
  }

  .novel-card-actions {
    gap: 5px;
  }

  .novel-card-actions .novel-card-primary-action .btn-brutal {
    height: 30px;
    font-size: 12px;
  }

  .novel-card-actions .novel-card-secondary-actions {
    gap: 4px;
  }

  .novel-card-actions .novel-card-secondary-actions .btn-brutal {
    height: 26px;
    padding: 0 4px;
    font-size: 10.5px;
  }

  .cover-overlay-badge {
    font-size: 8.5px;
    padding: 1px 4px;
    bottom: 4px;
    right: 4px;
  }

  /* List View Mobile Layout */
  .novel-card-list {
    padding: 10px;
    gap: 10px;
    flex-wrap: wrap;
  }

  .novel-list-cover-wrap {
    width: 48px;
    height: 68px;
  }

  .novel-list-title {
    font-size: 14px;
  }

  .novel-list-author {
    font-size: 11px;
  }

  .novel-list-meta .badge-brutal {
    font-size: 9px;
    padding: 1px 5px;
  }

  .novel-list-progress-info {
    font-size: 10px;
    max-width: 120px;
  }

  .novel-list-actions {
    width: 100%;
    margin-top: 4px;
    padding-top: 6px;
    border-top: 1px dashed var(--border-color);
    justify-content: flex-end;
  }

  .novel-list-actions .btn-brutal {
    flex: 1;
    height: 28px;
    font-size: 11.5px;
  }

  /* Resume Hero Mobile Fit (Balanced cover and text height) */
  .resume-hero {
    grid-template-columns: 82px 1fr !important;
    grid-template-rows: auto auto !important;
    gap: 10px 14px !important;
    padding: 14px 16px !important;
    margin-bottom: 20px !important;
    align-items: center !important;
  }

  .resume-cover {
    width: 82px !important;
    height: 118px !important;
    grid-row: 1 !important;
    grid-column: 1 !important;
  }

  .resume-info {
    grid-row: 1 !important;
    grid-column: 2 !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: center !important;
    min-width: 0 !important;
    gap: 2px !important;
  }

  .resume-info h3 {
    font-size: 10px !important;
    margin-bottom: 2px !important;
    letter-spacing: 0.5px !important;
  }

  .resume-info h2, #resumeNovelTitle {
    font-size: 16px !important;
    line-height: 1.22 !important;
    margin-bottom: 4px !important;
    display: -webkit-box !important;
    -webkit-line-clamp: 2 !important;
    -webkit-box-orient: vertical !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  .resume-chapter-tag {
    font-size: 12px !important;
    font-weight: 600 !important;
    color: var(--text-secondary) !important;
    margin-bottom: 6px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  .progress-bar-container {
    max-width: 100% !important;
  }

  .resume-hero > div:last-child {
    grid-row: 2 !important;
    grid-column: 1 / -1 !important;
    width: 100% !important;
    margin-top: 2px !important;
  }

  #resumeReadBtn {
    width: 100% !important;
    padding: 9px 12px !important;
    font-size: 13px !important;
    justify-content: center !important;
  }

  /* Footer Previous/Next buttons are visible and compact on mobile */
  #footerPrevBtn,
  #footerNextBtn {
    display: inline-flex !important;
    flex: 1;
    font-size: 11.5px !important;
    padding: 6px 8px !important;
    min-height: 32px !important;
  }

  #footerMenuBtn,
  #footerLibraryBtn {
    flex: 1;
    font-size: 11.5px !important;
    padding: 6px 8px !important;
    min-height: 32px !important;
  }

  .reader-footer-nav {
    display: flex !important;
    justify-content: center;
    gap: 6px;
    width: 100%;
    margin-top: 36px;
    padding-top: 16px;
  }

  /* Floating Bar button cleanup on mobile */
  #prevChapterBtn,
  #nextChapterBtn {
    display: none !important;
  }

  /* Mobile Chapter Top: Eliminate blank gaps above text & volume banner */
  .reader-body-wrapper {
    padding: calc(var(--reader-bar-h, 122px) - var(--safe-top) + 10px) var(--reader-padding-x, 6px) 90px var(--reader-padding-x, 6px) !important;
  }

  .chapter-separator-banner {
    margin: 0 0 12px 0 !important;
    padding: 8px 10px !important;
    font-size: 11.5px !important;
  }

  .reader-heading {
    margin: 10px 0 14px 0 !important;
    font-size: 1.35em !important;
    padding-bottom: 8px !important;
  }

  .reader-floating-bar {
    width: auto;
    max-width: calc(100% - 32px);
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(18px + var(--safe-bottom));
  }

  /* Hide floating menu badge on mobile (access via center-tap quick sheet or auto-revealing top bar) */
  .floating-quick-menu-btn {
    display: none !important;
  }

  .overscroll-indicator {
    display: flex;
  }
}

@media (min-width: 769px) {
  .mobile-quick-sheet,
  .quick-sheet-backdrop,
  .overscroll-indicator,
  .mobile-offline-badge,
  .audiobook-offline-status {
    display: none !important;
  }
}

/* Audiobook Sleep Timer Modal */
.audiobook-sleep-modal {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 440px;
  background: var(--bg-surface);
  border: 2px solid var(--border-color);
  border-bottom: none;
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  padding: 18px 20px calc(22px + var(--safe-bottom));
  box-shadow: 0 -10px 36px rgba(0, 0, 0, 0.5);
  z-index: 1060;
  box-sizing: border-box;
  animation: slideUpSleepModal 0.24s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUpSleepModal {
  from {
    transform: translate(-50%, 100%);
    opacity: 0.5;
  }
  to {
    transform: translate(-50%, 0);
    opacity: 1;
  }
}

.audiobook-sleep-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-color);
}

.audiobook-sleep-active-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 14px;
}

.audiobook-sleep-time-remaining {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sleep-time-label {
  font-size: 12px;
  color: var(--text-secondary);
}

.sleep-time-digits {
  font-family: var(--font-mono, monospace);
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
}

.audiobook-sleep-extend-btns {
  display: flex;
  gap: 6px;
}

.sleep-extend-btn {
  font-size: 11px;
  padding: 4px 10px;
  min-height: 28px;
  font-weight: 600;
  border-radius: 6px;
}

.audiobook-sleep-presets-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.sleep-preset-btn {
  padding: 11px 12px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  justify-content: center;
  border-radius: 8px;
}

.sleep-turn-off-btn {
  width: 100%;
  padding: 9px;
  font-size: 12px;
  color: var(--text-muted);
  border: 1px dashed var(--border-color);
  background: transparent;
  justify-content: center;
  border-radius: 8px;
}
.sleep-turn-off-btn:hover {
  color: #ef4444;
  border-color: #ef4444;
}

/* Sleep Timer Resumption Modal */
.sleep-resume-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 90%;
  max-width: 440px;
  background: var(--bg-surface);
  border: 2px solid var(--border-color);
  border-radius: 14px;
  padding: 20px 22px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.55);
  z-index: 1110;
  box-sizing: border-box;
  animation: fadeInModal 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

.sleep-resume-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
}

.sleep-resume-desc {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.sleep-resume-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sleep-resume-choice-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 12px 14px;
  text-align: left;
  width: 100%;
  border-radius: 8px;
  transition: transform 0.12s ease, border-color 0.15s ease;
}

.sleep-resume-choice-btn:active {
  transform: scale(0.98);
}

.sleep-choice-title {
  font-size: 13.5px;
  font-weight: 700;
  margin-bottom: 3px;
}

.sleep-choice-sub {
  font-size: 11px;
  opacity: 0.85;
}

/* Tactile button active feedback */
.btn-brutal:active:not(:disabled) {
  transform: scale(0.975);
}




/* Small version tag, bottom-left of the library screen */
.app-version-tag {
  position: fixed;
  left: 12px;
  bottom: calc(8px + var(--safe-bottom));
  font-family: var(--font-sans, sans-serif);
  font-size: 10px;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  opacity: 0.7;
  pointer-events: auto;
  padding: 6px 8px 6px 0;
  z-index: 5;
}
