/* ==========================================================================
   Lumina Reader Engine - Main Stylesheet (With DOCX Table Styling Support)
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&family=Vazirmatn:wght@300;400;500;600;700;800;900&family=Fira+Code:wght@400;500&display=swap');

:root {
  /* Font Families */
  --font-persian: 'Vazirmatn', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-latin: 'Outfit', -apple-system, sans-serif;
  --font-code: 'Fira Code', monospace;

  /* Accent & Brand Colors */
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-glow: rgba(99, 102, 241, 0.25);
  --accent: #14b8a6;
  --accent-glow: rgba(20, 184, 166, 0.2);

  /* Transitions */
  --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);

  /* Elevation Shadows */
  --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.14);
  --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.3);

  /* Highlight Swatches */
  --hl-yellow: #fef08a;
  --hl-yellow-text: #713f12;
  --hl-green: #bbf7d0;
  --hl-green-text: #14532d;
  --hl-blue: #bfdbfe;
  --hl-blue-text: #1e3a8a;
  --hl-pink: #fbcfe8;
  --hl-pink-text: #831843;
}

/* --------------------------------------------------------------------------
   GLOBAL FONT RULE: Force Vazirmatn on ALL buttons, inputs, tables & marks
   -------------------------------------------------------------------------- */
*, button, input, select, textarea, mark, table, th, td, .theme-pill, .tool-btn, .btn-accent, 
.doc-link-item, .toc-nav-link, #hl-floating-popover, #hl-floating-popover *, 
.modal-card, .badge, .pill-tag {
  font-family: var(--font-persian) !important;
}

/* --------------------------------------------------------------------------
   THEMES (Dark, Light, Sepia)
   -------------------------------------------------------------------------- */
body.theme-light {
  --bg-app: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-glass: rgba(255, 255, 255, 0.85);
  --bg-sidebar: #f1f5f9;
  --bg-active: #e2e8f0;
  --bg-hover: #e2e8f0;
  --bg-code: #0f172a;
  --bg-code-inline: #f1f5f9;

  --border-color: #e2e8f0;
  --border-subtle: #f1f5f9;

  --text-main: #0f172a;
  --text-muted: #475569;
  --text-subtle: #94a3b8;
  --text-code: #f8fafc;

  --header-bg: rgba(255, 255, 255, 0.85);
}

body.theme-dark {
  --bg-app: #090d16;
  --bg-surface: #111726;
  --bg-surface-glass: rgba(17, 23, 38, 0.85);
  --bg-sidebar: #0c111d;
  --bg-active: #1e293b;
  --bg-hover: #192234;
  --bg-code: #030712;
  --bg-code-inline: #1e293b;

  --border-color: #1e293b;
  --border-subtle: #151d2a;

  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-subtle: #64748b;
  --text-code: #f1f5f9;

  --header-bg: rgba(17, 23, 38, 0.85);

  --hl-yellow: #854d0e;
  --hl-yellow-text: #fef08a;
  --hl-green: #14532d;
  --hl-green-text: #bbf7d0;
  --hl-blue: #1e3a8a;
  --hl-blue-text: #bfdbfe;
  --hl-pink: #831843;
  --hl-pink-text: #fbcfe8;
}

body.theme-sepia {
  --bg-app: #fbf0d9;
  --bg-surface: #f4e4bc;
  --bg-surface-glass: rgba(244, 228, 188, 0.85);
  --bg-sidebar: #ebd9b0;
  --bg-active: #dfcb9f;
  --bg-hover: #e6d3a7;
  --bg-code: #3a2d1d;
  --bg-code-inline: #e8d7b3;

  --border-color: #d6c193;
  --border-subtle: #e2ce9e;

  --text-main: #3a2d1d;
  --text-muted: #675237;
  --text-subtle: #897051;
  --text-code: #fbf0d9;

  --header-bg: rgba(244, 228, 188, 0.85);
}

/* --------------------------------------------------------------------------
   Resets & Basic Setup
   -------------------------------------------------------------------------- */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  width: 100%;
  direction: rtl;
  background-color: var(--bg-app);
  color: var(--text-main);
  transition: background-color var(--transition-normal), color var(--transition-normal);
  overflow-x: hidden;
  overflow-y: hidden;
  -webkit-font-smoothing: antialiased;
}

#app-root {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  max-width: 100%;
  overflow-x: hidden;
}

/* Navbar */
.navbar {
  height: 64px;
  background: var(--header-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  z-index: 50;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
  transition: transform var(--transition-normal), opacity var(--transition-normal);
}

.navbar.hidden {
  display: none !important;
}

#app-root.navbar-is-hidden .app-viewport {
  height: 100vh;
  height: 100dvh;
}

#app-root.navbar-is-hidden .reading-bar {
  top: 0 !important;
}

#app-root.navbar-is-hidden .sidebar-nav, 
#app-root.navbar-is-hidden .toc-sidebar {
  top: 0 !important;
}

.floating-restore-nav-btn {
  position: fixed;
  top: 12px;
  left: 20px;
  z-index: 90;
  background: var(--bg-surface-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: var(--shadow-md);
  transition: var(--transition-fast);
  touch-action: manipulation;
}

.floating-restore-nav-btn:hover {
  background: var(--bg-hover);
  color: var(--primary);
  border-color: var(--primary);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  text-decoration: none;
}

.brand-badge {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-weight: 800;
  font-size: 1.15rem;
  box-shadow: var(--shadow-glow);
}

.brand-text-container {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--text-main);
  line-height: 1.2;
}

.brand-sub {
  font-size: 0.7rem;
  color: var(--text-subtle);
  font-weight: 500;
}

.nav-center {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--bg-sidebar);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 4px 8px;
}

.tool-btn {
  background: transparent;
  border: none;
  color: var(--text-main);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: var(--transition-fast);
}

.tool-btn:hover {
  background: var(--bg-hover);
  color: var(--primary);
}

.tool-icon-btn {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition-fast);
}

.tool-icon-btn:hover {
  background: var(--bg-hover);
  border-color: var(--primary);
  color: var(--primary);
}

.divider-vert {
  width: 1px;
  height: 20px;
  background: var(--border-color);
  margin: 0 4px;
}

/* Theme Switcher Pills */
.theme-switch-group {
  display: flex;
  align-items: center;
  background: var(--bg-app);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 3px;
  gap: 2px;
}

.theme-pill {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: 16px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: var(--transition-fast);
}

.theme-pill:hover {
  color: var(--text-main);
}

.theme-pill.active {
  background: var(--primary-glow);
  color: var(--primary);
  font-weight: 700;
  box-shadow: var(--shadow-sm);
}

.nav-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.btn-accent {
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  color: #ffffff;
  border: none;
  padding: 8px 16px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: var(--shadow-glow);
  transition: var(--transition-fast);
}

.btn-accent:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px var(--primary-glow);
}

/* Viewport Layout */
.app-viewport {
  display: flex;
  flex: 1;
  height: calc(100vh - 64px);
  height: calc(100dvh - 64px);
  position: relative;
  overflow: hidden;
}

.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 30;
  display: none;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.drawer-backdrop.active {
  display: block;
  opacity: 1;
}

/* Left Sidebar (Slide-Over Panel - Hardware-Accelerated, NO Article Reflow!) */
.sidebar-nav {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  width: 320px;
  background: var(--bg-sidebar);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  z-index: 40;
  box-shadow: var(--shadow-lg);
  transform: translate3d(100%, 0, 0);
  visibility: hidden;
  pointer-events: none;
  opacity: 0;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.25s ease, visibility 0.25s ease;
  will-change: transform;
}

.sidebar-nav.active {
  transform: translate3d(0, 0, 0);
  visibility: visible;
  pointer-events: auto;
  opacity: 1;
}

.sidebar-header-search {
  padding: 1rem;
  border-bottom: 1px solid var(--border-color);
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-box svg {
  position: absolute;
  right: 12px;
  color: var(--text-subtle);
  width: 18px;
  height: 18px;
}

.input-search {
  width: 100%;
  padding: 10px 38px 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-main);
  font-size: 0.88rem;
  outline: none;
  transition: var(--transition-fast);
}

.input-search:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.category-tree {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0.75rem;
}

.cat-block {
  margin-bottom: 1.5rem;
}

.cat-header {
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--text-subtle);
  padding: 0 0.75rem 0.5rem 0.75rem;
  display: flex;
  align-items: center;
  gap: 6px;
}

.cat-icon {
  color: var(--primary);
}

.doc-list {
  list-style: none;
}

.doc-link-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition-fast);
  margin-bottom: 3px;
}

.doc-link-item:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

.doc-link-item.active {
  background: var(--primary-glow);
  color: var(--primary);
  font-weight: 700;
  border-right: 3px solid var(--primary);
}

/* Reader Canvas */
.reader-canvas {
  flex: 1;
  overflow-y: auto;
  padding: 2.5rem 3rem;
  position: relative;
  scroll-behavior: smooth;
  display: flex;
  justify-content: center;
}

.article-container {
  width: 100%;
  max-width: 840px;
  transition: max-width var(--transition-normal);
  padding-bottom: 8rem;
}

.reader-canvas.mode-full .article-container {
  max-width: 100%;
}

.reader-canvas.mode-compact .article-container {
  max-width: 680px;
}

.article-hero {
  margin-bottom: 2.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-color);
}

.article-meta-tags {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.85rem;
  flex-wrap: wrap;
}

.pill-tag {
  background: var(--primary-glow);
  color: var(--primary);
  padding: 3px 10px;
  border-radius: 16px;
  font-weight: 700;
  font-size: 0.78rem;
}

.article-title-main {
  font-size: 2.2rem;
  font-weight: 900;
  line-height: 1.35;
  color: var(--text-main);
  margin-bottom: 0.85rem;
}

.article-lead-sub {
  font-size: 1.15rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.article-content {
  font-size: 1.05rem;
  line-height: 1.85;
  color: var(--text-main);
  transition: font-size var(--transition-fast), line-height var(--transition-fast);
}

.article-content h2 {
  font-size: 1.6rem;
  font-weight: 800;
  margin: 2.5rem 0 1.25rem 0;
  color: var(--text-main);
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-subtle);
  scroll-margin-top: 80px;
}

.article-content h3 {
  font-size: 1.3rem;
  font-weight: 700;
  margin: 2rem 0 1rem 0;
  color: var(--text-main);
  scroll-margin-top: 80px;
}

.article-content p {
  margin-bottom: 1.35rem;
  text-align: justify;
}

.article-content ul, .article-content ol {
  margin: 1rem 0 1.5rem 1.75rem;
  padding-right: 1rem;
}

.article-content li {
  margin-bottom: 0.5rem;
}

.article-content blockquote {
  border-right: 4px solid var(--primary);
  background: var(--bg-sidebar);
  padding: 1rem 1.25rem;
  border-radius: 0 10px 10px 0;
  margin: 1.5rem 0;
  font-style: italic;
  color: var(--text-muted);
}

/* Enhanced Code Block Container */
.code-block-wrapper {
  margin: 1.75rem 0;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border-color);
  background: #0d1117;
  box-shadow: var(--shadow-md);
  direction: ltr;
}

.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #161b22;
  padding: 8px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-family: var(--font-code);
  font-size: 0.78rem;
}

.code-lang-tag {
  color: var(--primary);
  font-weight: 700;
  letter-spacing: 0.5px;
}

.code-copy-btn {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #c9d1d9;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 0.75rem;
  font-family: var(--font-main);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: var(--transition-fast);
}

.code-copy-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.3);
}

.code-block-wrapper pre {
  margin: 0 !important;
  background: #0d1117 !important;
  border-radius: 0 !important;
  padding: 1.25rem !important;
  direction: ltr !important;
  text-align: left !important;
}

.article-content pre {
  background: #0d1117;
  color: #e6edf3;
  padding: 1.25rem;
  border-radius: 12px;
  overflow-x: auto;
  font-family: var(--font-code) !important;
  font-size: 0.9rem;
  direction: ltr;
  text-align: left;
  margin: 1.5rem 0;
}

.article-content code {
  font-family: var(--font-code) !important;
  background: var(--bg-code-inline);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 0.88rem;
  direction: ltr;
  display: inline-block;
}

/* --------------------------------------------------------------------------
   STUNNING MODERN DOCX TABLES STYLING
   -------------------------------------------------------------------------- */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  margin: 2rem 0;
  border-radius: 14px;
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  box-shadow: var(--shadow-sm);
}

.doc-table {
  width: 100%;
  border-collapse: collapse;
  text-align: right;
  font-size: 0.95rem;
  line-height: 1.6;
}

.doc-table th {
  background: var(--bg-sidebar);
  color: var(--text-main);
  font-weight: 800;
  padding: 14px 18px;
  border-bottom: 2px solid var(--border-color);
  border-left: 1px solid var(--border-subtle);
  white-space: nowrap;
}

.doc-table th:last-child {
  border-left: none;
}

.doc-table td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-subtle);
  border-left: 1px solid var(--border-subtle);
  color: var(--text-main);
  vertical-align: middle;
}

.doc-table td:last-child {
  border-left: none;
}

.doc-table tbody tr {
  transition: background-color var(--transition-fast);
}

.doc-table tbody tr:hover {
  background: var(--bg-hover);
}

.doc-table tbody tr:last-child td {
  border-bottom: none;
}

/* Highlight Styling */
mark.hl {
  border-radius: 4px;
  padding: 2px 5px;
  cursor: pointer;
  position: relative;
  transition: filter var(--transition-fast);
}

mark.hl:hover {
  filter: brightness(0.92);
}

mark.hl-yellow { background-color: var(--hl-yellow); color: var(--hl-yellow-text); }
mark.hl-green  { background-color: var(--hl-green);  color: var(--hl-green-text);  }
mark.hl-blue   { background-color: var(--hl-blue);   color: var(--hl-blue-text);   }
mark.hl-pink   { background-color: var(--hl-pink);   color: var(--hl-pink-text);   }

/* Right TOC Sidebar (Slide-Over Panel - Hardware-Accelerated, NO Article Reflow!) */
.toc-sidebar {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 300px;
  background: var(--bg-surface-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-right: 1px solid var(--border-color);
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  z-index: 40;
  box-shadow: var(--shadow-lg);
  transform: translate3d(-100%, 0, 0);
  visibility: hidden;
  pointer-events: none;
  opacity: 0;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.25s ease, visibility 0.25s ease;
  will-change: transform;
}

.toc-sidebar.active {
  transform: translate3d(0, 0, 0);
  visibility: visible;
  pointer-events: auto;
  opacity: 1;
}

.toc-header-title {
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--text-subtle);
  text-transform: uppercase;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 6px;
}

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

.toc-nav-item {
  margin-bottom: 4px;
}

.toc-nav-link {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 6px;
  line-height: 1.4;
  transition: var(--transition-fast);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toc-nav-link:hover {
  color: var(--text-main);
  background: var(--bg-hover);
}

.toc-nav-link.active {
  color: var(--primary);
  background: var(--primary-glow);
  font-weight: 700;
}

/* Reading Progress Bar */
.reading-bar {
  position: fixed;
  top: 64px;
  right: 0;
  left: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  width: 0%;
  z-index: 60;
  transition: width 0.1s linear;
}

/* Floating Selection Popover (Fixed positioning for precise collision avoidance) */
#hl-floating-popover {
  position: fixed;
  display: none;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 30px;
  padding: 6px 14px;
  box-shadow: var(--shadow-lg);
  z-index: 150;
  align-items: center;
  gap: 8px;
  animation: fadeIn 0.15s ease-out;
  touch-action: manipulation;
}

.swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  cursor: pointer;
  transition: transform var(--transition-fast);
  touch-action: manipulation;
}

.swatch:active {
  transform: scale(1.25);
}

.swatch-yellow { background-color: #fef08a; }
.swatch-green  { background-color: #bbf7d0; }
.swatch-blue   { background-color: #bfdbfe; }
.swatch-pink   { background-color: #fbcfe8; }

/* Modals */
.modal-overlay-bg {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
}

.modal-overlay-bg.active {
  display: flex;
}

.modal-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  width: 100%;
  max-width: 540px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-card-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-card-body {
  padding: 1.5rem;
  max-height: 70vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.modal-card-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  background: var(--bg-sidebar);
}

/* Bottom Sheet Modal Mode for Mobile */
.bottom-sheet-card {
  position: relative;
}

.bottom-sheet-handle {
  display: none;
  width: 38px;
  height: 4px;
  background: var(--border-color);
  border-radius: 2px;
  margin: 8px auto 0 auto;
}

.mobile-theme-selector {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.mobile-control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.mobile-action-btn {
  background: var(--bg-sidebar);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: var(--transition-fast);
  touch-action: manipulation;
}

.mobile-action-btn:active {
  background: var(--bg-hover);
  transform: scale(0.97);
}

/* Mobile Bottom Dock */
.mobile-bottom-dock {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: var(--header-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-color);
  z-index: 45;
  padding: 0 0.5rem;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.mobile-dock-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-fast);
  position: relative;
  touch-action: manipulation;
}

.mobile-dock-btn:active, .mobile-dock-btn.active {
  color: var(--primary);
}

.mobile-dock-btn svg {
  transition: transform var(--transition-fast);
}

.mobile-dock-btn:active svg {
  transform: scale(1.15);
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.97); }
  to   { opacity: 1; transform: scale(1); }
}

@media (min-width: 1025px) {
  .drawer-backdrop {
    display: none !important;
    opacity: 0 !important;
    pointer-events: none !important;
  }

  .sidebar-nav {
    position: relative;
    top: auto;
    bottom: auto;
    right: auto;
    width: 280px;
    height: 100%;
    transform: none !important;
    visibility: visible !important;
    pointer-events: auto !important;
    opacity: 1 !important;
    box-shadow: none;
    border-left: 1px solid var(--border-color);
    transition: margin-right 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
  }

  .sidebar-nav.hidden-desktop {
    margin-right: -280px;
    opacity: 0;
    pointer-events: none;
  }

  .toc-sidebar {
    position: relative;
    top: auto;
    bottom: auto;
    left: auto;
    width: 260px;
    height: 100%;
    transform: none !important;
    visibility: visible !important;
    pointer-events: auto !important;
    opacity: 1 !important;
    box-shadow: none;
    border-right: 1px solid var(--border-color);
    transition: margin-left 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
  }

  .toc-sidebar.hidden-desktop {
    margin-left: -260px;
    opacity: 0;
    pointer-events: none;
  }
}

/* Responsive Breakpoints & Mobile Optimization */
@media (max-width: 1024px) {
  .toc-sidebar {
    position: fixed;
    top: 64px;
    bottom: 0;
    width: 290px;
    z-index: 55;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
  }
  .sidebar-nav {
    position: fixed;
    top: 64px;
    bottom: 0;
    width: 290px;
    z-index: 55;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
  }
  .reader-canvas {
    padding: 1.5rem 1.25rem;
    -webkit-overflow-scrolling: touch;
    overflow-x: hidden;
  }
}

@media (max-width: 768px) {
  #app-root {
    height: 100vh;
    height: 100dvh;
  }

  .navbar {
    height: 56px;
    padding: 0 0.85rem;
  }

  .brand-title {
    font-size: 0.98rem;
  }

  .brand-sub {
    display: none;
  }

  .nav-center {
    display: none;
  }

  .desktop-only-text, .desktop-only-flex {
    display: none !important;
  }

  .reading-bar {
    top: 56px;
  }

  .app-viewport {
    height: calc(100vh - 56px - 60px);
    height: calc(100dvh - 56px - 60px);
  }

  .sidebar-nav, .toc-sidebar {
    top: 56px;
    bottom: 60px;
  }

  .mobile-bottom-dock {
    display: flex;
  }

  .reader-canvas {
    padding: 1.25rem 0.85rem 4rem 0.85rem;
  }

  .article-title-main {
    font-size: 1.45rem;
    line-height: 1.45;
  }

  .article-hero {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
  }

  /* Bottom sheet modal styling on mobile */
  .modal-overlay-bg {
    align-items: flex-end;
    padding: 0;
  }

  .modal-card {
    border-radius: 20px 20px 0 0;
    max-height: 85vh;
    animation: slideUp 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .bottom-sheet-handle {
    display: block;
  }
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}
