/* --- Variables & Themes --- */
:root {
  --primary: #f5831f;
  --primary-hover: #e0710d;
  --primary-light: #fff5eb;
  --primary-border: #fed7aa;
  
  --navy: #152238;
  --navy-light: #1f3150;
  --navy-dark: #0b1320;
  
  --bg-app: #f8fafc;
  --bg-card: #ffffff;
  --bg-input: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --card-shadow: 0 2px 10px rgba(0,0,0,0.05);
  
  --font-base: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mr: 'Noto Sans Devanagari', 'Inter', sans-serif;
  
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --reader-font-size: 16.5px;
}

/* Sepia Theme */
[data-theme="sepia"] {
  --bg-app: #fbf0d9;
  --bg-card: #f6e8cc;
  --bg-input: #fef7e9;
  --text-main: #433422;
  --text-muted: #7c6853;
  --border-color: #e8d5b5;
  --card-shadow: 0 2px 10px rgba(67, 52, 34, 0.08);
}

/* Dark Theme */
[data-theme="dark"] {
  --bg-app: #0b111e;
  --bg-card: #141e30;
  --bg-input: #1a273e;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --border-color: #23344e;
  --card-shadow: 0 4px 16px rgba(0,0,0,0.3);
}

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

body {
  font-family: var(--font-base);
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.2s ease, color 0.2s ease;
}

/* --- Header --- */
.app-header {
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-light) 100%);
  color: #ffffff;
  padding: 0.75rem 1.25rem;
  border-bottom: 3px solid var(--primary);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}

.header-container {
  max-width: 1300px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}

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

.brand-logo-icon {
  background-color: var(--primary);
  color: #ffffff;
  font-weight: 900;
  font-size: 1.1rem;
  padding: 0.4rem 0.7rem;
  border-radius: var(--radius-sm);
  letter-spacing: 0.5px;
}

.brand-text h1 {
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1.2;
}

.brand-text .tagline {
  font-size: 0.78rem;
  color: #cbd5e1;
  font-family: var(--font-mr);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Theme Mode Switch */
.theme-switch {
  display: flex;
  background-color: rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-md);
  padding: 2px;
}

.theme-btn {
  background: transparent;
  border: none;
  font-size: 0.85rem;
  padding: 0.35rem 0.55rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s ease;
  min-height: 34px;
}

.theme-btn.active {
  background-color: rgba(255, 255, 255, 0.25);
}

/* Language Switch */
.lang-switch {
  display: flex;
  background-color: rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-md);
  padding: 2px;
  gap: 2px;
}

.lang-btn {
  background: transparent;
  border: none;
  color: #e2e8f0;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: var(--font-mr);
  min-height: 34px;
}

.lang-btn.active {
  background-color: var(--primary);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(245, 131, 31, 0.4);
}

/* --- Main Layout --- */
.app-main {
  max-width: 1300px;
  margin: 0 auto;
  padding: 1.25rem 1rem;
  min-height: calc(100vh - 75px);
}

.view-section {
  display: none;
}

.view-section.active {
  display: block;
}

/* --- Filter & Search Bar --- */
.filter-bar {
  background: var(--bg-card);
  padding: 1rem;
  border-radius: var(--radius-md);
  box-shadow: var(--card-shadow);
  border: 1px solid var(--border-color);
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

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

.search-icon {
  position: absolute;
  left: 0.85rem;
  width: 18px;
  height: 18px;
  stroke: var(--text-muted);
}

.search-box input {
  width: 100%;
  padding: 0.75rem 2.5rem 0.75rem 2.5rem;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-sm);
  background-color: var(--bg-input);
  color: var(--text-main);
  font-size: 0.95rem;
  font-family: var(--font-base);
  outline: none;
  transition: border-color 0.15s ease;
  min-height: 44px;
}

.search-box input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(245, 131, 31, 0.15);
}

.clear-btn {
  position: absolute;
  right: 0.85rem;
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.2rem;
  min-height: 36px;
  min-width: 36px;
}

/* Month Filter Wrapper (Horizontal scrollable on touch) */
.month-filters-scroll-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
}

.month-filters-scroll-wrapper::-webkit-scrollbar {
  display: none;
}

.month-filters {
  display: flex;
  gap: 0.45rem;
  min-width: max-content;
}

.filter-pill {
  background: var(--bg-app);
  border: 1px solid var(--border-color);
  padding: 0.45rem 0.9rem;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  min-height: 36px;
}

.filter-pill.active {
  background: var(--navy);
  color: #ffffff;
  border-color: var(--navy);
}

[data-theme="dark"] .filter-pill.active {
  background: var(--primary);
  border-color: var(--primary);
}

/* Stats Banner */
.stats-banner {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  background: var(--primary-light);
  border: 1px solid var(--primary-border);
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1.25rem;
  font-size: 0.8rem;
  color: #9a3412;
  gap: 0.5rem;
  text-align: center;
}

[data-theme="dark"] .stats-banner {
  background: rgba(245, 131, 31, 0.12);
  border-color: rgba(245, 131, 31, 0.3);
  color: #fed7aa;
}

[data-theme="sepia"] .stats-banner {
  background: #f1dfbc;
  border-color: #dfcaa2;
  color: #5c4426;
}

.stat-item {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
}

/* --- Cards Grid --- */
.editions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
}

.edition-card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  padding: 1.15rem;
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.edition-card:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
}

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.65rem;
}

.card-badge-lang {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 0.2rem 0.55rem;
  border-radius: 4px;
  letter-spacing: 0.3px;
}

.card-badge-lang.mr {
  background: #fef3c7;
  color: #92400e;
  font-family: var(--font-mr);
}

.card-badge-lang.en {
  background: #e0e7ff;
  color: #3730a3;
}

.card-meta-month {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
}

.card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 0.35rem;
  line-height: 1.35;
  font-family: var(--font-mr);
}

.card-date-range {
  font-size: 0.82rem;
  color: var(--primary);
  font-weight: 600;
  margin-bottom: 0.75rem;
}

.card-features {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-bottom: 1rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.card-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-top: auto;
}

.btn-read-online {
  background: var(--navy);
  color: #ffffff;
  border: none;
  padding: 0.65rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 44px;
  transition: opacity 0.15s ease;
}

.btn-read-online.has-text-badge {
  background: #0284c7;
}

.btn-download-card {
  background: var(--primary);
  color: #ffffff;
  text-decoration: none;
  padding: 0.65rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 44px;
  transition: background 0.15s ease;
}

.btn-download-card:hover {
  background: var(--primary-hover);
}

/* --- Reader View Layout --- */
.reader-header-bar {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  box-shadow: var(--card-shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  position: sticky;
  top: 70px;
  z-index: 90;
  margin-bottom: 1rem;
}

.reader-nav-left {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.btn-back {
  background: var(--bg-app);
  border: 1px solid var(--border-color);
  padding: 0.45rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  min-height: 38px;
}

.btn-back svg {
  width: 15px;
  height: 15px;
}

/* TOC Toggle Button (Shows on Tablet/Mobile) */
.btn-toc-toggle {
  display: none; /* hidden on wide desktop */
  background: var(--bg-app);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 0.45rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  align-items: center;
  gap: 0.35rem;
  min-height: 38px;
  font-family: var(--font-mr);
}

.btn-toc-toggle svg {
  width: 16px;
  height: 16px;
}

.reader-title-info h2 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
  font-family: var(--font-mr);
  line-height: 1.25;
}

.reader-meta-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.reader-nav-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.text-size-tools {
  display: flex;
  background: var(--bg-app);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  padding: 2px;
}

.size-btn {
  background: transparent;
  border: none;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.35rem 0.55rem;
  color: var(--text-main);
  cursor: pointer;
  border-radius: 4px;
  min-height: 32px;
  min-width: 32px;
}

.btn-download-primary {
  background: var(--primary);
  color: #ffffff;
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 700;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 38px;
}

.btn-download-primary svg {
  width: 15px;
  height: 15px;
}

.btn-share {
  background: #25d366;
  color: #ffffff;
  border: none;
  padding: 0.45rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 38px;
}

.btn-share svg {
  width: 15px;
  height: 15px;
}

/* Reader Layout Split */
.reader-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 1.25rem;
  align-items: start;
}

/* Sidebar Jump List */
.reader-sidebar {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  position: sticky;
  top: 145px;
  max-height: calc(100vh - 165px);
  overflow-y: auto;
  box-shadow: var(--card-shadow);
  transition: transform 0.25s ease-in-out;
}

.sidebar-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.sidebar-title-row h3 {
  font-size: 0.82rem;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

.btn-close-drawer {
  display: none;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.2rem;
  line-height: 1;
}

.in-edition-search input {
  width: 100%;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-main);
  font-size: 0.8rem;
  margin-bottom: 0.65rem;
  outline: none;
  min-height: 36px;
}

.page-jump-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.jump-item {
  display: block;
  padding: 0.45rem 0.65rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  color: var(--text-main);
  text-decoration: none;
  border: 1px solid transparent;
  transition: all 0.12s ease;
  cursor: pointer;
  font-family: var(--font-mr);
  line-height: 1.35;
}

.jump-item:hover, .jump-item.active {
  background: var(--primary-light);
  color: #9a3412;
  border-color: var(--primary-border);
}

[data-theme="dark"] .jump-item:hover, [data-theme="dark"] .jump-item.active {
  background: rgba(245, 131, 31, 0.15);
  color: #fed7aa;
}

/* Main Reader Article Area */
.reader-article {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.75rem 1.5rem;
  box-shadow: var(--card-shadow);
}

.reader-content-body {
  font-size: var(--reader-font-size);
  color: var(--text-main);
  line-height: 1.85;
  font-family: var(--font-mr);
}

.reader-page-block {
  margin-bottom: 2rem;
  padding-bottom: 1.75rem;
  border-bottom: 1px dashed var(--border-color);
  position: relative;
}

.page-badge-indicator {
  display: inline-block;
  background: var(--bg-app);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.15rem 0.55rem;
  border-radius: 4px;
  margin-bottom: 0.85rem;
}

.reader-page-text {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
}

.reader-page-text strong {
  display: inline-block;
  margin-top: 0.5rem;
  color: var(--text-main);
}

/* Pending text box */
.pending-text-box {
  background: var(--bg-app);
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 2rem 1.25rem;
  text-align: center;
  margin: 1.5rem 0;
}

.pending-text-box h3 {
  font-size: 1.2rem;
  color: var(--primary);
  margin-bottom: 0.5rem;
  font-family: var(--font-mr);
}

.pending-text-box p {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 1.25rem;
  max-width: 550px;
  margin-left: auto;
  margin-right: auto;
  font-family: var(--font-mr);
}

.pending-text-box .btn-download-pending {
  background: var(--primary);
  color: #ffffff;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 0.92rem;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 44px;
}

/* Bottom Banner */
.bottom-cmp-banner {
  margin-top: 2.5rem;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-light) 100%);
  color: #ffffff;
  padding: 1.5rem;
  border-radius: var(--radius-md);
  border-left: 5px solid var(--primary);
}

.banner-content h3 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 0.4rem;
  font-family: var(--font-mr);
}

.banner-content p {
  font-size: 0.85rem;
  color: #cbd5e1;
  margin-bottom: 1rem;
  font-family: var(--font-mr);
}

.banner-cta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.btn-banner-contact, .btn-banner-link {
  padding: 0.6rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 700;
  text-decoration: none;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
}

.btn-banner-contact {
  background: var(--primary);
  color: #ffffff;
}

.btn-banner-link {
  background: rgba(255, 255, 255, 0.15);
  color: #ffffff;
}

/* --- Mobile Floating Bottom Action Bar --- */
.mobile-sticky-bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border-top: 1px solid var(--border-color);
  padding: 0.5rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  z-index: 95;
  box-shadow: 0 -4px 16px rgba(0,0,0,0.1);
}

.mobile-bar-btn {
  background: var(--bg-app);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 42px;
  text-decoration: none;
}

.mobile-bar-btn svg {
  width: 16px;
  height: 16px;
}

.mobile-bar-btn.download {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
  flex: 1;
  justify-content: center;
}

.mobile-font-pills {
  display: flex;
  background: var(--bg-app);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
}

.mobile-font-pills button {
  background: none;
  border: none;
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--text-main);
  padding: 0.4rem 0.6rem;
  min-height: 40px;
  cursor: pointer;
}

/* Drawer Backdrop Overlay */
.drawer-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
  z-index: 105;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.drawer-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

/* ===================================================
   TABLET & MOBILE RESPONSIVE ADAPTATIONS
   =================================================== */

/* Tablet & Smaller Screens (< 1024px) */
@media (max-width: 1024px) {
  .btn-toc-toggle {
    display: inline-flex; /* Show TOC trigger button */
  }

  .reader-layout {
    grid-template-columns: 1fr; /* Single column */
  }

  /* Transform Sidebar into Off-Canvas Slide Drawer */
  .reader-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 320px;
    max-width: 85vw;
    height: 100vh;
    max-height: 100vh;
    z-index: 110;
    border-radius: 0;
    transform: translateX(-105%);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.2);
  }

  .reader-sidebar.drawer-open {
    transform: translateX(0);
  }

  .btn-close-drawer {
    display: block; /* Show close button in drawer */
  }
}

/* Small Tablets & Mobile Phones (< 768px) */
@media (max-width: 768px) {
  .app-header {
    padding: 0.6rem 0.85rem;
  }

  .header-container {
    gap: 0.5rem;
  }

  .brand-text h1 {
    font-size: 0.95rem;
  }

  .brand-text .tagline {
    font-size: 0.7rem;
  }

  .app-main {
    padding: 0.75rem 0.5rem 4.5rem 0.5rem; /* bottom padding for mobile sticky bar */
  }

  .reader-header-bar {
    top: 55px;
    padding: 0.6rem 0.75rem;
  }

  .reader-article {
    padding: 1.25rem 0.85rem;
  }

  /* Compact header buttons in reader */
  .btn-dl-text, .btn-share-text {
    display: none; /* Icon only on mobile header */
  }

  .btn-download-primary, .btn-share {
    padding: 0.45rem 0.55rem;
  }

  .reader-title-info h2 {
    font-size: 0.95rem;
  }

  /* Show floating mobile bottom action bar when reader is active */
  #reader-view.active ~ .mobile-sticky-bottom-bar,
  .mobile-sticky-bottom-bar.show {
    display: flex !important;
  }
}

/* Very Small Mobile (< 480px) */
@media (max-width: 480px) {
  .editions-grid {
    grid-template-columns: 1fr; /* Full single column */
  }

  .card-actions {
    grid-template-columns: 1fr; /* Stack buttons vertically on small phones */
    gap: 0.4rem;
  }

  .theme-btn {
    padding: 0.25rem 0.4rem;
    font-size: 0.75rem;
  }

  .lang-btn {
    padding: 0.35rem 0.55rem;
    font-size: 0.75rem;
  }
}
