/* ==========================================================================
   Luxury Academic Stylesheet - Master's Thesis & Modifications Showcase
   Theme: Royal Academic / Imperial Emerald / Diplomatic Sapphire / Warm Sepia
   Responsive: Mobile, iPad / Tablet, Desktop, Ultra-wide
   ========================================================================== */

/* Custom CSS Variables & Color Themes */
:root {
  /* Default Theme: Royal Pearl / Ivory & Gold */
  --bg-primary: #faf8f5;
  --bg-secondary: #f4efe6;
  --bg-surface: #ffffff;
  --bg-surface-glass: rgba(255, 255, 255, 0.88);
  --text-primary: #182230;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --border-color: rgba(197, 160, 89, 0.28);
  --border-hover: rgba(197, 160, 89, 0.65);
  --gold-primary: #b8860b;
  --gold-secondary: #c5a059;
  --gold-light: #fef9ed;
  --gold-glow: rgba(197, 160, 89, 0.22);
  --accent-emerald: #0d5c48;
  --accent-navy: #0f2744;
  --card-shadow: 0 10px 30px -10px rgba(184, 134, 11, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.03);
  --card-shadow-hover: 0 20px 40px -15px rgba(184, 134, 11, 0.16), 0 8px 12px -4px rgba(0, 0, 0, 0.05);
  --font-base-size: 16px;
  --line-height: 1.95;
}

/* Theme: Imperial Emerald (Soothing Academic Dark) */
[data-theme="emerald"] {
  --bg-primary: #071512;
  --bg-secondary: #0d221e;
  --bg-surface: #0f2b25;
  --bg-surface-glass: rgba(15, 43, 37, 0.92);
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --border-color: rgba(52, 211, 153, 0.25);
  --border-hover: rgba(245, 158, 11, 0.6);
  --gold-primary: #f59e0b;
  --gold-secondary: #fbbf24;
  --gold-light: rgba(245, 158, 11, 0.14);
  --gold-glow: rgba(245, 158, 11, 0.28);
  --accent-emerald: #10b981;
  --accent-navy: #1e3a5f;
  --card-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.65), 0 0 15px rgba(16, 185, 129, 0.08);
  --card-shadow-hover: 0 20px 40px -15px rgba(0, 0, 0, 0.85), 0 0 25px rgba(245, 158, 11, 0.2);
}

/* Theme: Midnight Sapphire (Diplomatic Royal Dark) */
[data-theme="sapphire"] {
  --bg-primary: #060d17;
  --bg-secondary: #0b1728;
  --bg-surface: #102038;
  --bg-surface-glass: rgba(16, 32, 56, 0.92);
  --text-primary: #ffffff;
  --text-secondary: #e2e8f0;
  --text-muted: #94a3b8;
  --border-color: rgba(56, 189, 248, 0.28);
  --border-hover: rgba(229, 192, 123, 0.65);
  --gold-primary: #e5c07b;
  --gold-secondary: #f39c12;
  --gold-light: rgba(229, 192, 123, 0.14);
  --gold-glow: rgba(56, 189, 248, 0.3);
  --accent-emerald: #0ea5e9;
  --accent-navy: #38bdf8;
  --card-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.75), 0 0 15px rgba(56, 189, 248, 0.1);
  --card-shadow-hover: 0 20px 40px -15px rgba(0, 0, 0, 0.95), 0 0 25px rgba(229, 192, 123, 0.22);
}

/* Theme: Warm Sepia / Classical Manuscript */
[data-theme="sepia"] {
  --bg-primary: #f5eedf;
  --bg-secondary: #ebe2cf;
  --bg-surface: #faf5ec;
  --bg-surface-glass: rgba(250, 245, 236, 0.92);
  --text-primary: #2d2218;
  --text-secondary: #574636;
  --text-muted: #786450;
  --border-color: rgba(153, 101, 21, 0.28);
  --border-hover: rgba(153, 101, 21, 0.6);
  --gold-primary: #996515;
  --gold-secondary: #a6701e;
  --gold-light: rgba(153, 101, 21, 0.12);
  --gold-glow: rgba(153, 101, 21, 0.2);
  --accent-emerald: #4d603a;
  --accent-navy: #3a4b60;
  --card-shadow: 0 10px 30px -10px rgba(80, 50, 20, 0.08);
  --card-shadow-hover: 0 20px 40px -15px rgba(80, 50, 20, 0.16);
}

/* Global Reset & Base Styles */
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Readex Pro', 'Cairo', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-size: var(--font-base-size);
  line-height: var(--line-height);
  transition: background-color 0.35s ease, color 0.35s ease;
  overflow-x: hidden;
  direction: rtl;
  text-align: right;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Background Canvas */
#bg-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
  pointer-events: none;
  opacity: 0.7;
  transition: opacity 0.5s ease;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}
::-webkit-scrollbar-thumb {
  background: var(--gold-secondary);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--gold-primary);
}

/* Typography Helpers */
.font-amiri {
  font-family: 'Amiri', serif;
}
.font-cairo {
  font-family: 'Cairo', sans-serif;
}
.font-readex {
  font-family: 'Readex Pro', sans-serif;
}
.font-english {
  font-family: 'Cormorant Garamond', 'Times New Roman', serif;
}
.font-heading {
  font-family: 'Cairo', 'Amiri', sans-serif;
}

/* Glassmorphism Classes */
.glass-panel {
  background: var(--bg-surface-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  box-shadow: var(--card-shadow);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.glass-panel:hover {
  border-color: var(--border-hover);
  box-shadow: var(--card-shadow-hover);
}

/* Sticky Navigation Header */
.header-glass {
  background: var(--bg-surface-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-color);
}

/* Reading Progress Bar */
#reading-progress-bar {
  position: fixed;
  top: 0;
  right: 0;
  height: 3.5px;
  width: 0%;
  background: linear-gradient(90deg, var(--gold-primary), var(--gold-secondary), #34d399);
  z-index: 100;
  transition: width 0.1s ease-out;
}

/* Navigation Tabs */
.nav-tab-btn {
  position: relative;
  transition: all 0.25s ease;
  font-weight: 600;
  white-space: nowrap;
}

.nav-tab-btn::after {
  content: '';
  position: absolute;
  bottom: 0;
  right: 50%;
  transform: translateX(50%);
  width: 0;
  height: 3px;
  background: var(--gold-primary);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.nav-tab-btn.active {
  color: var(--gold-primary);
}

.nav-tab-btn.active::after {
  width: 80%;
}

/* Badges */
.badge-gold {
  background-color: var(--gold-light);
  color: var(--gold-primary);
  border: 1px solid var(--border-color);
}

.badge-green {
  background-color: rgba(16, 185, 129, 0.15);
  color: #10b981;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-amber {
  background-color: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.badge-blue {
  background-color: rgba(59, 130, 246, 0.15);
  color: #3b82f6;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.badge-purple {
  background-color: rgba(168, 85, 247, 0.15);
  color: #a855f7;
  border: 1px solid rgba(168, 85, 247, 0.3);
}

.badge-rose {
  background-color: rgba(244, 63, 94, 0.15);
  color: #f43f5e;
  border: 1px solid rgba(244, 63, 94, 0.3);
}

/* Thesis Reader Styling */
.thesis-reader-container {
  max-width: 900px;
  margin: 0 auto;
}

.thesis-reader-container.wide-mode {
  max-width: 1200px;
}

.thesis-paragraph {
  text-align: justify;
  text-justify: inter-word;
  color: var(--text-primary);
  margin-bottom: 1.4rem;
}

.thesis-paragraph p {
  margin-bottom: 1.25rem;
}

/* Footnotes Popover */
.footnote-ref {
  cursor: pointer;
  padding: 0.15rem 0.35rem;
  margin: 0 0.2rem;
  background: var(--gold-light);
  color: var(--gold-primary);
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  transition: all 0.2s ease;
  display: inline-block;
  vertical-align: super;
}

.footnote-ref:hover {
  background: var(--gold-primary);
  color: #ffffff;
  transform: translateY(-2px);
}

#footnote-popover {
  position: fixed;
  z-index: 1050;
  max-width: 360px;
  padding: 1rem 1.25rem;
  background: var(--bg-surface);
  border: 1px solid var(--gold-secondary);
  border-radius: 1rem;
  box-shadow: 0 15px 35px -5px rgba(0, 0, 0, 0.35);
  font-size: 0.85rem;
  line-height: 1.6;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

#footnote-popover.active {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

/* Lightbox Modal */
#lightbox-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(4, 10, 18, 0.94);
  backdrop-filter: blur(16px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  padding: 1rem;
}

#lightbox-modal.active {
  opacity: 1;
  pointer-events: auto;
}

/* Off-canvas TOC Drawer for Mobile & Tablet */
#mobile-toc-drawer {
  position: fixed;
  inset-y: 0;
  right: 0;
  width: 85%;
  max-width: 360px;
  z-index: 1040;
  background: var(--bg-surface);
  border-left: 1px solid var(--border-color);
  box-shadow: -10px 0 30px rgba(0, 0, 0, 0.3);
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
}

#mobile-toc-drawer.open {
  transform: translateX(0);
}

#mobile-toc-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1030;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

#mobile-toc-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

/* Floating TOC Pill on Mobile/Tablet */
#floating-toc-btn {
  position: fixed;
  bottom: 24px;
  right: 20px;
  z-index: 990;
  box-shadow: 0 8px 24px var(--gold-glow), 0 4px 12px rgba(0, 0, 0, 0.25);
  transition: all 0.25s ease;
}

#floating-toc-btn:hover {
  transform: scale(1.05);
}

/* Responsive Table Swipe Hint */
.table-swipe-hint {
  display: none;
}
@media (max-width: 768px) {
  .table-swipe-hint {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.725rem;
    color: var(--gold-primary);
    margin-bottom: 0.5rem;
  }
}

/* Print Styling */
@media print {
  #bg-canvas,
  header,
  #floating-toc-btn,
  #mobile-toc-drawer,
  #mobile-toc-backdrop,
  #reading-progress-bar,
  .no-print {
    display: none !important;
  }
  
  body {
    background: #ffffff !important;
    color: #000000 !important;
    font-size: 12pt !important;
    line-height: 1.6 !important;
  }
  
  .glass-panel {
    border: none !important;
    box-shadow: none !important;
    background: transparent !important;
  }
  
  .chapter-heading, .section-heading {
    page-break-before: always;
  }
  
  table {
    page-break-inside: avoid;
  }
}
