:root {
  --bg:             #ffffff;
  --bg-elevated:    #ffffff;
  --bg-card:        #ffffff;
  --bg-card-hover:  #ffffff;
  --bg-toolbar:     rgba(255, 255, 255, 0.92);
  
  --border:         rgba(15, 23, 42, 0.08);
  --border-subtle:  rgba(15, 23, 42, 0.05);
  --border-card:    rgba(15, 23, 42, 0.08);
  --border-hover:   rgba(99, 102, 241, 0.45);
  --border-focus:   #6366f1;

  --accent:         #4f46e5;
  --accent-light:   #6366f1;
  --accent-glow:    rgba(99, 102, 241, 0.15);
  --purple:         #9333ea;
  --purple-glow:    rgba(147, 51, 234, 0.15);
  --cyan:           #0891b2;
  --emerald:        #059669;
  --red:            #dc2626;

  --text:           #0f172a;
  --text-dim:       #475569;
  --text-muted:     #64748b;

  --radius:         18px;
  --radius-sm:      10px;
  --radius-pill:    9999px;

  --fast:           0.2s cubic-bezier(0.16, 1, 0.3, 1);
  --smooth:         0.35s cubic-bezier(0.16, 1, 0.3, 1);

  --shadow-card:    0 4px 20px -2px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.04);
  --shadow-hover:   0 16px 36px -6px rgba(99, 102, 241, 0.2), 0 0 0 1px rgba(99, 102, 241, 0.35);

  --sat:            env(safe-area-inset-top, 0px);
  --sab:            env(safe-area-inset-bottom, 0px);
  --sal:            env(safe-area-inset-left, 0px);
  --sar:            env(safe-area-inset-right, 0px);
}

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

html {
  scroll-behavior: smooth;
  font-size: 16px;
  color-scheme: light;
}

body {
  font-family: 'Plus Jakarta Sans', 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  position: relative;
}

/* ── Ambient Background Glows ── */
.bg-glow-orb {
  position: fixed;
  border-radius: 50%;
  filter: blur(120px);
  pointer-events: none;
  z-index: 0;
  opacity: 0.35;
  animation: floatOrb 16s ease-in-out infinite alternate;
}

.bg-glow-1 {
  top: -120px;
  left: 15%;
  width: 550px;
  height: 550px;
  background: radial-gradient(circle, rgba(99, 102, 241, 0.08) 0%, rgba(168, 85, 247, 0.03) 60%, transparent 80%);
}

.bg-glow-2 {
  top: 250px;
  right: 10%;
  width: 480px;
  height: 480px;
  background: radial-gradient(circle, rgba(6, 182, 212, 0.06) 0%, rgba(99, 102, 241, 0.02) 60%, transparent 80%);
  animation-duration: 20s;
  animation-delay: -8s;
}

@keyframes floatOrb {
  0% { transform: translateY(0) scale(1); }
  50% { transform: translateY(35px) scale(1.08); }
  100% { transform: translateY(-25px) scale(0.95); }
}

.bg-noise {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 50% 0%, rgba(99, 102, 241, 0.02) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

/* ===================================================================
   1. Brand Navigation Bar
   =================================================================== */
.top-nav {
  position: sticky;
  top: 0;
  z-index: 50;
  width: 100%;
  height: 64px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
}

.nav-container {
  max-width: 1140px;
  width: 100%;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand-link {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--text);
  transition: opacity var(--fast);
}

.brand-link:hover {
  opacity: 0.9;
}

.brand-logo-wrap {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  padding: 2px;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.4), rgba(168, 85, 247, 0.2));
  border: 1px solid rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 16px rgba(99, 102, 241, 0.25);
  overflow: hidden;
}

.brand-logo-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.brand-text-wrap {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.brand-title {
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--text);
}

.brand-sub {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 2px 7px;
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid rgba(99, 102, 241, 0.25);
  border-radius: var(--radius-pill);
  color: var(--accent);
}

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

.club-badge-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 14px;
  background: rgba(15, 23, 42, 0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-dim);
  text-decoration: none;
  transition: all var(--fast);
}

.club-badge-btn:hover {
  background: rgba(99, 102, 241, 0.1);
  border-color: rgba(99, 102, 241, 0.35);
  color: var(--accent);
  transform: translateY(-1px);
}

.club-badge-btn i {
  color: var(--accent-light);
}

.nav-ext-icon {
  font-size: 0.7rem;
  opacity: 0.7;
}

/* ===================================================================
   2. Library Hero Section
   =================================================================== */
.lib-hero {
  text-align: center;
  padding: clamp(52px, 8vw, 84px) 24px clamp(36px, 5vw, 54px);
  max-width: 820px;
  margin: 0 auto;
}

.hero-title {
  font-size: clamp(2.3rem, 5.5vw, 3.8rem);
  font-weight: 800;
  letter-spacing: -0.035em;
  line-height: 1.15;
  background: linear-gradient(135deg, #0f172a 30%, #312e81 75%, #4f46e5 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 16px;
}

.hero-subtitle {
  font-size: clamp(1rem, 2vw, 1.15rem);
  color: var(--text-dim);
  line-height: 1.65;
  max-width: 660px;
  margin: 0 auto;
  font-weight: 400;
}

/* ===================================================================
   3. Archive Section & Magazine Cards
   =================================================================== */
.archive-section {
  max-width: 1040px;
  margin: 0 auto;
  padding: 0 24px clamp(48px, 8vw, 84px);
}

.section-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border-subtle);
}

.section-title-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

.section-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-title i {
  color: var(--accent);
  font-size: 1.1rem;
}

.section-badge {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--accent);
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid rgba(99, 102, 241, 0.22);
  padding: 3px 10px;
  border-radius: var(--radius-pill);
}

.section-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.sort-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 12px;
  color: var(--text-dim);
  transition: border-color var(--fast);
}

.sort-wrap:hover {
  border-color: var(--border-hover);
}

.sort-wrap .sort-icon {
  font-size: 0.76rem;
  color: var(--accent);
}

.sort-select {
  background: transparent;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  outline: none;
  cursor: pointer;
}

.sort-select option {
  background: #ffffff;
  color: #0f172a;
}

.btn-sync-drive {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 14px;
  background: rgba(99, 102, 241, 0.09);
  border: 1px solid rgba(99, 102, 241, 0.28);
  border-radius: var(--radius-sm);
  color: var(--accent-light);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--fast);
}

.btn-sync-drive:hover {
  background: rgba(99, 102, 241, 0.2);
  border-color: rgba(99, 102, 241, 0.5);
  transform: translateY(-1px);
}

.btn-sync-drive.spinning i {
  animation: syncSpin 0.8s linear infinite;
}

@keyframes syncSpin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* ── File Grid ── */
.file-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 28px;
}

/* ── Magazine Edition Card ── */
.edition-card {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  cursor: pointer;
  transition: transform var(--smooth), box-shadow var(--smooth), border-color var(--smooth);
  position: relative;
  user-select: none;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.edition-card:hover {
  transform: translateY(-6px);
  box-shadow: var(--shadow-hover);
  border-color: var(--border-hover);
}

.edition-card:active {
  transform: translateY(-2px) scale(0.995);
}

/* ── Real PDF First Page Cover ── */
.card-cover-page {
  position: relative;
  width: 100%;
  height: 250px;
  background: linear-gradient(180deg, #f8fafc 0%, #edf2f7 100%);
  border-top-left-radius: var(--radius);
  border-top-right-radius: var(--radius);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid var(--border-subtle);
}

.cover-canvas {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  display: block;
  transition: transform var(--smooth);
  background: #f8fafc;
}

.edition-card:hover .cover-canvas {
  transform: scale(1.025);
}

.cover-page-sheen {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.01) 0%, transparent 40%, rgba(0, 0, 0, 0.08) 100%);
  pointer-events: none;
  z-index: 1;
}

/* ── Card Details & Body ── */
.card-details {
  padding: 20px 22px 22px;
  display: flex;
  flex-direction: column;
  flex: 1;
  background: var(--bg-card);
}

.card-heading-box {
  margin-bottom: 18px;
}

.card-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--text);
  line-height: 1.35;
  word-break: break-word;
  margin: 0;
}

/* ── Card Action Footer ── */
.card-action-footer {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: auto;
}

.btn-read-online {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 18px;
  background: #4f46e5;
  border: none;
  border-radius: var(--radius-sm);
  color: #ffffff !important;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(79, 70, 229, 0.32);
  transition: all var(--fast);
  text-decoration: none;
}

.btn-read-online:hover {
  background: #4338ca;
  box-shadow: 0 6px 20px rgba(79, 70, 229, 0.45);
  transform: translateY(-1px);
}

.action-arrow {
  font-size: 0.8rem;
  transition: transform var(--fast);
}

.edition-card:hover .action-arrow {
  transform: translateX(3px);
}

.btn-quick-download {
  width: 46px;
  height: 46px;
  border-radius: var(--radius-sm);
  background: #ffffff;
  border: 1px solid #e2e8f0;
  color: #334155 !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  cursor: pointer;
  transition: all var(--fast);
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.btn-quick-download:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
  color: #0f172a !important;
  transform: translateY(-1px);
}

.btn-quick-download i {
  color: #334155 !important;
  font-size: 0.95rem;
}
  font-size: 1.15rem !important;
  display: inline-block;
  line-height: 1;
  pointer-events: none;
}

.btn-quick-download:hover {
  background: rgba(99, 102, 241, 0.12);
  border-color: rgba(99, 102, 241, 0.4);
  color: var(--accent) !important;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.18);
}

.btn-quick-download:hover i {
  color: var(--accent) !important;
}

/* ── Loader & Error ── */
.loader,
.error-msg {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 64px 20px;
  color: var(--text-dim);
  font-size: 0.95rem;
  text-align: center;
}

.error-msg i {
  font-size: 2rem;
  color: var(--red);
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(99, 102, 241, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ===================================================================
   5. Reader View & Top Toolbar
   =================================================================== */
#readerView {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: #ffffff;
  overflow: hidden;
  z-index: 100;
}

/* ── Reading Progress Track & Bar ── */
.reading-progress-track {
  position: sticky;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background: rgba(15, 23, 42, 0.06);
  z-index: 105;
}

.reading-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent) 0%, var(--purple) 50%, var(--cyan) 100%);
  transition: width 0.18s ease-out;
  box-shadow: 0 0 10px var(--accent-light);
}

/* ── Primary Toolbar ── */
.reader-toolbar {
  position: sticky;
  top: 3px;
  z-index: 100;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 max(18px, var(--sar)) 0 max(18px, var(--sal));
  background: var(--bg-toolbar);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 4px 20px -4px rgba(0, 0, 0, 0.06);
}

.tb-title-container {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px;
}

.tb-title {
  font-size: 0.95rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}

.tb-pill {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 7px;
  border-radius: 4px;
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid rgba(99, 102, 241, 0.25);
  color: var(--accent);
  flex-shrink: 0;
}

.tb-controls {
  display: flex;
  align-items: center;
  gap: 5px;
}

.mobile-actions {
  display: none;
  align-items: center;
  gap: 6px;
}

/* ── Toolbar Buttons ── */
.tb-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  min-width: 34px;
  height: 34px;
  padding: 0 8px;
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--fast);
  text-decoration: none;
  font-size: 0.85rem;
}

.tb-btn:hover {
  background: rgba(15, 23, 42, 0.05);
  color: var(--text);
  border-color: var(--border);
}

.tb-btn:active {
  transform: scale(0.95);
}

.tb-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  pointer-events: none;
}

.tb-btn.active {
  background: rgba(99, 102, 241, 0.15);
  color: var(--accent);
  border-color: rgba(99, 102, 241, 0.35);
}

.tb-btn.highlight-btn {
  background: rgba(99, 102, 241, 0.12);
  color: var(--accent);
  border-color: rgba(99, 102, 241, 0.25);
}

.tb-btn.highlight-btn:hover {
  background: var(--accent);
  color: #fff;
}

.back-btn {
  gap: 6px;
  padding: 0 12px 0 8px;
  font-weight: 500;
  font-size: 0.86rem;
}

.tb-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
}

.page-info {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.82rem;
  color: var(--text-dim);
  padding: 0 2px;
}

.page-info input {
  width: 44px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  text-align: center;
  font-size: 0.82rem;
  padding: 4px 0;
  font-family: inherit;
  transition: border-color var(--fast);
}

.page-info input:focus {
  outline: none;
  border-color: var(--accent);
  background: #ffffff;
}

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

#zoomSelect {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.8rem;
  padding: 5px 8px;
  font-family: inherit;
  cursor: pointer;
  outline: none;
}

#zoomSelect:focus {
  border-color: var(--accent);
}

#zoomSelect option {
  background: #ffffff;
  color: #0f172a;
}

/* ===================================================================
   3. PDF Stage & Scrollable Canvas Container
   =================================================================== */
.pdf-stage {
  flex: 1 1 0%;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #ffffff;
  padding: clamp(10px, 2.5vw, 28px) clamp(8px, 2vw, 24px) clamp(64px, 8vw, 88px);
  overflow-y: auto;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y pinch-zoom;
}

.pdf-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 80px 20px;
  color: var(--text-dim);
  font-size: 0.95rem;
  user-select: none;
}

/* ── Progress Wheel Component ── */
.progress-wheel-wrap {
  position: relative;
  width: 104px;
  height: 104px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.progress-wheel-svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.progress-wheel-track {
  fill: none;
  stroke: rgba(15, 23, 42, 0.08);
  stroke-width: 7;
}

.progress-wheel-bar {
  fill: none;
  stroke: var(--accent);
  stroke-width: 7;
  stroke-linecap: round;
  stroke-dasharray: 264;
  stroke-dashoffset: 264;
  transition: stroke-dashoffset 0.15s ease-out, stroke 0.3s ease;
}

.progress-wheel-bar.complete {
  stroke: var(--emerald);
}

.progress-wheel-content {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.progress-wheel-percent {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  font-family: 'Plus Jakarta Sans', sans-serif;
}

.progress-wheel-title {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-dim);
  text-align: center;
}

/* ── Dual Stream Status Badges ── */
.progress-dual-badges {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.stream-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: var(--radius-pill);
  font-size: 0.76rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  background: rgba(15, 23, 42, 0.04);
  border: 1px solid var(--border);
  color: var(--text-muted);
  transition: all var(--fast);
}

.stream-badge.part1 {
  background: rgba(99, 102, 241, 0.08);
  border-color: rgba(99, 102, 241, 0.2);
  color: var(--accent);
}

.stream-badge.part2 {
  background: rgba(147, 51, 234, 0.08);
  border-color: rgba(147, 51, 234, 0.2);
  color: var(--purple);
}

.stream-badge i {
  font-size: 0.7rem;
}

/* ── Friendly Loading Reminder ── */
.loading-friendly-tip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  max-width: 440px;
  padding: 10px 18px;
  margin-top: 8px;
  background: rgba(99, 102, 241, 0.05);
  border: 1px solid rgba(99, 102, 241, 0.15);
  border-radius: var(--radius-pill);
  font-size: 0.84rem;
  line-height: 1.45;
  color: var(--text-dim);
  text-align: center;
  box-shadow: 0 2px 10px rgba(99, 102, 241, 0.04);
  animation: pulseGently 3s ease-in-out infinite alternate;
}

.loading-friendly-tip i {
  color: var(--accent);
  font-size: 0.95rem;
  flex-shrink: 0;
}

@keyframes pulseGently {
  0% { transform: translateY(0); opacity: 0.88; }
  100% { transform: translateY(-2px); opacity: 1; }
}

/* ── Container for All PDF Pages (Continuous Scroll or Single Page) ── */
.pdf-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  width: 100%;
  max-width: 100%;
  transition: gap var(--fast);
}

.pdf-container.single-mode {
  gap: 0;
}

/* ── Individual Page Wrapper ── */
.pdf-page-wrapper {
  position: relative;
  background: #ffffff;
  border-radius: 4px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08), 0 1px 4px rgba(0, 0, 0, 0.06), 0 0 0 1px rgba(0, 0, 0, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
  overflow: hidden;
  user-select: none;
}

.pdf-page-wrapper canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 4px;
}

/* Page number label badge floating on each page */
.page-badge {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(15, 23, 42, 0.75);
  color: rgba(255, 255, 255, 0.9);
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 500;
  pointer-events: none;
  opacity: 0.8;
  backdrop-filter: blur(4px);
}

/* Placeholder skeleton when page hasn't rendered yet */
.pdf-page-skeleton {
  position: absolute;
  inset: 0;
  background: #f1f5f9;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  gap: 8px;
}

.pdf-page-skeleton .mini-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(15, 23, 42, 0.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* Floating Scroll to Top button */
.scroll-top-btn {
  position: fixed;
  bottom: calc(20px + var(--sab));
  right: calc(20px + var(--sar));
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: all var(--fast);
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  z-index: 90;
}

.scroll-top-btn.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.scroll-top-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  transform: translateY(-2px);
}

/* ===================================================================
   4. Mobile Bottom Floating Bar (Thumb Navigation)
   =================================================================== */
.mobile-bottom-bar {
  display: none;
  position: fixed;
  bottom: calc(14px + var(--sab));
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
  align-items: center;
  gap: 6px;
  transition: transform 0.25s ease, opacity 0.25s ease;
}

.mobile-bottom-bar.hidden {
  transform: translate(-50%, 80px);
  opacity: 0;
  pointer-events: none;
}

.m-btn {
  background: transparent;
  border: none;
  color: var(--text);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background var(--fast);
}

.m-btn:active {
  background: rgba(15, 23, 42, 0.08);
}

.m-btn:disabled {
  opacity: 0.3;
  pointer-events: none;
}

.m-page-info {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text);
  padding: 0 8px;
  white-space: nowrap;
}

.m-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 2px;
}

/* ===================================================================
   5. Custom Scrollbars
   =================================================================== */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

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

::-webkit-scrollbar-thumb {
  background: rgba(15, 23, 42, 0.15);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(15, 23, 42, 0.28);
}

/* ===================================================================
   6. Responsive Breakpoints
   =================================================================== */

/* ── Tablet & Small Laptops (max-width: 860px) ── */
@media (max-width: 860px) {

  .tb-btn.extra-control,
  #fullscreenBtn,
  #rotateBtn {
    display: none;
  }
}

/* ── Mobile Devices (max-width: 680px) ── */
@media (max-width: 680px) {
  .lib-header {
    padding: 36px 16px 20px;
  }

  .archive-section {
    padding: 0 16px clamp(36px, 6vw, 64px);
  }

  .section-top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 20px;
    padding-bottom: 12px;
  }

  .section-title {
    font-size: 1.1rem;
    gap: 8px;
  }

  .section-badge {
    font-size: 0.72rem;
    padding: 2px 8px;
  }

  .sort-wrap {
    padding: 5px 10px;
  }

  .sort-select {
    font-size: 0.78rem;
  }

  .file-grid {
    grid-template-columns: 1fr;
    padding: 0 0 calc(48px + var(--sab));
    gap: 20px;
  }

  /* Toolbar: hide crowded controls on top, show mobile actions */
  #desktopControls {
    display: none;
  }

  .mobile-actions {
    display: flex;
  }

  .back-label {
    display: none;
  }

  .reader-toolbar {
    height: 50px;
    padding: 0 12px;
  }

  .tb-title {
    font-size: 0.85rem;
  }

  /* Show floating mobile bottom bar */
  .mobile-bottom-bar {
    display: flex;
  }

  /* Stage margins minimized for maximum reading width on small screens */
  .pdf-stage {
    padding: 8px 4px calc(72px + var(--sab));
  }

  .pdf-container {
    gap: 12px;
  }

  .scroll-top-btn {
    bottom: calc(72px + var(--sab));
    right: 14px;
    width: 38px;
    height: 38px;
    font-size: 0.88rem;
  }
}

/* ── Very Small Screens (max-width: 380px) ── */
@media (max-width: 380px) {
  .section-top-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .section-controls {
    width: 100%;
  }

  .sort-wrap {
    width: 100%;
    justify-content: space-between;
  }

  .m-page-info {
    font-size: 0.76rem;
    padding: 0 4px;
  }

  .m-btn {
    width: 34px;
    height: 34px;
    font-size: 0.82rem;
  }
}

/* ===================================================================
   9. Interactive Quick Preview Modal Dialog
   =================================================================== */
dialog.preview-dialog {
  border: none;
  background: transparent;
  padding: 0;
  max-width: min(94vw, 920px);
  width: 100%;
  max-height: 92vh;
  margin: auto;
  border-radius: var(--radius);
  box-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.25), 0 0 0 1px rgba(0, 0, 0, 0.08);
  color: var(--text);
  overflow: hidden;
}

dialog.preview-dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

dialog.preview-dialog[open] {
  animation: modalFadeIn 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalFadeIn {
  from { opacity: 0; transform: scale(0.96) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.preview-dialog-inner {
  background: #ffffff;
  display: flex;
  flex-direction: column;
  height: 86vh;
  max-height: 820px;
  overflow: hidden;
  border-radius: var(--radius);
}

/* ── Modal Header ── */
.preview-header {
  height: 60px;
  padding: 0 20px;
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.preview-title-box {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.preview-pill {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid rgba(99, 102, 241, 0.25);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.preview-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.preview-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.preview-page-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 2px 6px;
}

.prev-ctrl-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  transition: all var(--fast);
}

.prev-ctrl-btn:hover {
  background: rgba(15, 23, 42, 0.06);
  color: var(--text);
}

.prev-ctrl-btn:disabled {
  opacity: 0.25;
  pointer-events: none;
}

.preview-page-text {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text);
  padding: 0 4px;
  min-width: 44px;
  text-align: center;
}

.btn-launch-reader {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid rgba(99, 102, 241, 0.25);
  border-radius: var(--radius-sm);
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--fast);
}

.btn-launch-reader:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.preview-close-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  background: rgba(15, 23, 42, 0.04);
  border: 1px solid var(--border);
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.95rem;
  transition: all var(--fast);
}

.preview-close-btn:hover {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.3);
  color: var(--red);
}

/* ── Preview Stage ── */
.preview-stage {
  flex: 1;
  position: relative;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 24px 20px;
}

.preview-loading {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.88);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-dim);
  font-size: 0.9rem;
  z-index: 10;
}

.preview-canvas-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  max-height: 100%;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

#previewCanvas {
  max-width: 100%;
  max-height: calc(86vh - 170px);
  width: auto;
  height: auto;
  border-radius: 4px;
  box-shadow: 0 8px 30px -4px rgba(0, 0, 0, 0.12), 0 0 0 1px rgba(0, 0, 0, 0.08);
  background: #fff;
}

/* ── Floating Chevrons in Preview ── */
.preview-nav-chevron {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
  transition: all var(--fast);
  z-index: 5;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

.preview-nav-chevron.left { left: 16px; }
.preview-nav-chevron.right { right: 16px; }

.preview-nav-chevron:hover {
  background: var(--accent);
  border-color: var(--accent-light);
  color: #fff;
  transform: translateY(-50%) scale(1.08);
}

.preview-nav-chevron:disabled {
  opacity: 0.2;
  pointer-events: none;
}

/* ── Preview Footer ── */
.preview-footer {
  height: 64px;
  padding: 0 20px;
  background: #ffffff;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.preview-footer-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.preview-meta-badge {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--red);
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.2);
  padding: 3px 8px;
  border-radius: 4px;
}

.preview-meta-size {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.preview-page-thumbnails {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  padding: 4px 0;
  max-width: 320px;
}

.preview-thumb-btn {
  padding: 4px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: 6px;
  background: rgba(15, 23, 42, 0.04);
  border: 1px solid var(--border);
  color: var(--text-dim);
  cursor: pointer;
  transition: all var(--fast);
  white-space: nowrap;
}

.preview-thumb-btn:hover {
  background: rgba(15, 23, 42, 0.08);
  color: var(--text);
}

.preview-thumb-btn.active {
  background: rgba(99, 102, 241, 0.12);
  border-color: var(--accent);
  color: var(--accent);
}

.preview-footer-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.preview-download-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: rgba(15, 23, 42, 0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.84rem;
  font-weight: 600;
  transition: all var(--fast);
}

.preview-download-btn:hover {
  background: rgba(15, 23, 42, 0.08);
  color: var(--text);
}

.preview-open-reader-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  background: linear-gradient(135deg, var(--accent) 0%, #4f46e5 100%);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.28);
  transition: all var(--fast);
}

.preview-open-reader-btn:hover {
  background: linear-gradient(135deg, var(--accent-light) 0%, var(--accent) 100%);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.45);
  transform: translateY(-1px);
}

@media (max-width: 640px) {
  .preview-dialog-inner {
    height: 94vh;
    max-height: none;
  }

  .preview-header {
    height: 54px;
    padding: 0 14px;
  }

  .preview-pill {
    display: none;
  }

  .launch-label {
    display: none;
  }

  .preview-page-thumbnails {
    display: none;
  }

  .preview-nav-chevron {
    width: 38px;
    height: 38px;
    font-size: 0.95rem;
  }

  .preview-nav-chevron.left { left: 8px; }
  .preview-nav-chevron.right { right: 8px; }

  .preview-footer {
    height: 56px;
    padding: 0 14px;
  }
}