/* ==================== FEATURES CSS ====================
   Reading Progress, Stats, Focus Mode, Tags, Settings, 
   Micro-interactions, PWA
   ================================================== */

/* ==================== READING PROGRESS TRACKER ==================== */

.progress-tracker {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  margin: 1rem 0;
}

.progress-tracker__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.progress-tracker__label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.progress-tracker__status {
  font-size: 0.8rem;
  color: var(--accent-primary);
  font-weight: 500;
}

.progress-tracker__bar {
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 0.75rem;
}

.progress-tracker__fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary, var(--accent-primary)));
  border-radius: 99px;
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

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

.progress-tracker__slider {
  flex: 1;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--bg-tertiary);
  border-radius: 99px;
  outline: none;
  cursor: pointer;
}

.progress-tracker__slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent-primary);
  cursor: pointer;
  border: 2px solid var(--bg-primary);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s ease;
}

.progress-tracker__slider::-webkit-slider-thumb:hover {
  transform: scale(1.3);
}

.progress-tracker__btn {
  padding: 0.4rem 0.75rem;
  font-size: 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.progress-tracker__btn:hover {
  background: var(--accent-primary);
  color: var(--bg-primary);
  border-color: var(--accent-primary);
}

.progress-tracker__btn.completed {
  background: rgba(74, 222, 128, 0.15);
  color: #4ade80;
  border-color: rgba(74, 222, 128, 0.3);
}

/* ==================== STATS DASHBOARD ==================== */

.stats-dashboard {
  max-width: 900px;
  margin: 0 auto;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.stats-card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 1.5rem;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.stats-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  border-radius: 16px 16px 0 0;
}

.stats-card--gold::before { background: linear-gradient(90deg, #f0b429, #f59e0b); }
.stats-card--blue::before { background: linear-gradient(90deg, #3b82f6, #60a5fa); }
.stats-card--purple::before { background: linear-gradient(90deg, #a855f7, #c084fc); }
.stats-card--green::before { background: linear-gradient(90deg, #22c55e, #4ade80); }

.stats-card__icon {
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

.stats-card__value {
  font-size: 2rem;
  font-weight: 800;
  color: var(--text-primary);
  font-family: var(--font-heading);
  line-height: 1.2;
}

.stats-card__label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stats-progress-ring {
  text-align: center;
  margin: 2rem 0;
}

.stats-ring {
  display: inline-block;
  position: relative;
  width: 120px;
  height: 120px;
}

.stats-ring svg {
  width: 100%;
  height: 100%;
}

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

.stats-ring__pct {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--accent-primary);
}

.stats-ring__sub {
  font-size: 0.65rem;
  color: var(--text-secondary);
  text-transform: uppercase;
}

.stats-ring__caption {
  margin-top: 0.75rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.stats-section {
  margin-top: 2rem;
}

.stats-section__title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text-primary);
}

.stats-bars {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

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

.stats-bar__label {
  width: 120px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-align: right;
  flex-shrink: 0;
}

.stats-bar__track {
  flex: 1;
  height: 8px;
  background: var(--bg-tertiary);
  border-radius: 99px;
  overflow: hidden;
}

.stats-bar__fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary, var(--accent-primary)));
  border-radius: 99px;
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.stats-bar__count {
  width: 30px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* ==================== FOCUS MODE ==================== */

body.focus-mode .header,
body.focus-mode .footer,
body.focus-mode .sidebar,
body.focus-mode .back-to-top,
body.focus-mode .breadcrumb {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

body.focus-mode {
  background: var(--bg-primary);
}

body.focus-mode .book-detail__content,
body.focus-mode .main-content {
  max-width: 720px;
  margin: 0 auto;
  padding-top: 1rem;
}

.focus-btn {
  font-size: 0.8rem;
  padding: 0.4rem 0.8rem;
}

/* ==================== TAG CLOUD & BOOK TAGS ==================== */

.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.tag-chip {
  padding: 0.35rem 0.85rem;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 500;
  border: 1px solid var(--border-color);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
}

.tag-chip:hover {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.tag-chip.active {
  background: var(--accent-primary);
  color: var(--bg-primary);
  border-color: var(--accent-primary);
  font-weight: 600;
}

.book-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.5rem;
}

.book-tag {
  padding: 0.15rem 0.5rem;
  border-radius: 99px;
  font-size: 0.6rem;
  font-weight: 500;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-tertiary);
  border: 1px solid rgba(255, 255, 255, 0.08);
  text-decoration: none;
  transition: all 0.15s ease;
}

.book-tag:hover {
  background: var(--accent-primary);
  color: var(--bg-primary);
  border-color: var(--accent-primary);
}

/* ==================== NOTIFICATION BADGE ==================== */

.notif-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 99px;
  background: #ef4444;
  color: white;
  font-size: 0.65rem;
  font-weight: 700;
  position: absolute;
  top: -4px;
  right: -4px;
}

.pulse-glow {
  animation: pulseGlow 2s ease-in-out infinite;
}

@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
  50% { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
}

/* ==================== SETTINGS PANEL ==================== */

.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.settings-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.settings-panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  width: min(460px, 90vw);
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

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

.settings-panel__header h2 {
  font-size: 1.1rem;
  font-weight: 700;
}

.settings-panel__close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border-color);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.settings-panel__close:hover {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.3);
}

.settings-panel__body {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.settings-group {
  /* Structural container for settings options */
}

.settings-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.settings-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.settings-opt {
  padding: 0.5rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 500;
  transition: all 0.2s ease;
}

.settings-opt:hover {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.settings-opt.active {
  background: var(--accent-primary);
  color: var(--bg-primary);
  border-color: var(--accent-primary);
  font-weight: 600;
}

/* Accent color swatches */
.accent-swatch {
  width: 32px;
  height: 32px;
  border-radius: 50% !important;
  padding: 0 !important;
  position: relative;
}

.accent-swatch.active::after {
  content: '✓';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 0.75rem;
  font-weight: 700;
}

.accent-swatch--gold { background: #f0b429 !important; border-color: #f0b429 !important; }
.accent-swatch--blue { background: #3b82f6 !important; border-color: #3b82f6 !important; }
.accent-swatch--purple { background: #a855f7 !important; border-color: #a855f7 !important; }
.accent-swatch--rose { background: #f43f5e !important; border-color: #f43f5e !important; }
.accent-swatch--cyan { background: #06b6d4 !important; border-color: #06b6d4 !important; }

/* Toggle switch */
.settings-toggle {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
}

.settings-toggle input {
  display: none;
}

.settings-toggle__slider {
  width: 44px;
  height: 24px;
  border-radius: 99px;
  background: var(--bg-tertiary);
  position: relative;
  transition: background 0.2s ease;
}

.settings-toggle__slider::after {
  content: '';
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: white;
  position: absolute;
  top: 3px;
  left: 3px;
  transition: transform 0.2s ease;
}

.settings-toggle input:checked + .settings-toggle__slider {
  background: var(--accent-primary);
}

.settings-toggle input:checked + .settings-toggle__slider::after {
  transform: translateX(20px);
}

.settings-toggle__label {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* ==================== ACCENT COLOR THEMES ==================== */

[data-accent="blue"] {
  --accent-primary: #3b82f6;
  --accent-gold: #3b82f6;
}

[data-accent="purple"] {
  --accent-primary: #a855f7;
  --accent-gold: #a855f7;
}

[data-accent="rose"] {
  --accent-primary: #f43f5e;
  --accent-gold: #f43f5e;
}

[data-accent="cyan"] {
  --accent-primary: #06b6d4;
  --accent-gold: #06b6d4;
}

/* ==================== FONT SIZE VARIANTS ==================== */

[data-font-size="small"] {
  --text-base: 0.85rem;
}

[data-font-size="large"] {
  --text-base: 1.1rem;
}

/* ==================== CARD STYLE VARIANTS ==================== */

[data-card-style="compact"] .book-card {
  padding: 0.75rem;
}

[data-card-style="compact"] .book-card__title {
  font-size: 0.85rem;
}

[data-card-style="compact"] .book-card__cover {
  height: 180px;
}

[data-card-style="list"] .books-grid {
  grid-template-columns: 1fr !important;
}

[data-card-style="list"] .book-card {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 1rem;
  padding: 0.75rem;
}

[data-card-style="list"] .book-card__cover {
  height: 140px;
}

/* ==================== REDUCE MOTION ==================== */

.reduce-motion *,
.reduce-motion *::before,
.reduce-motion *::after {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
}

/* ==================== MICRO-INTERACTIONS ==================== */

.ripple-effect {
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  transform: translate(-50%, -50%) scale(0);
  animation: ripple 0.5s ease-out forwards;
  pointer-events: none;
}

@keyframes ripple {
  to {
    transform: translate(-50%, -50%) scale(10);
    opacity: 0;
  }
}

/* ==================== ANIMATIONS ==================== */

.animate-fade-in {
  animation: fadeIn 0.5s ease forwards;
  opacity: 0;
}

.animate-scale-in {
  animation: scaleIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  opacity: 0;
}

.animate-slide-up {
  animation: slideUp 0.35s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes fadeIn {
  to { opacity: 1; }
}

@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.85); }
  to { opacity: 1; transform: scale(1); }
}

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

/* ==================== PWA INSTALL BUTTON ==================== */

#pwaInstallBtn {
  display: none;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--accent-primary);
  background: rgba(240, 180, 41, 0.1);
  color: var(--accent-primary);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  transition: all 0.2s ease;
}

#pwaInstallBtn:hover {
  background: var(--accent-primary);
  color: var(--bg-primary);
}

/* ==================== SETTINGS GEAR BUTTON ==================== */

.settings-gear {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border-color);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  position: relative;
}

.settings-gear:hover {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  transform: rotate(90deg);
}

/* ==================== RESPONSIVE ==================== */

@media (max-width: 640px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .settings-panel {
    border-radius: 16px 16px 0 0;
    width: 100vw;
    max-height: 85vh;
  }
  
  .settings-overlay {
    align-items: flex-end;
  }
  
  .progress-tracker__controls {
    flex-direction: column;
    align-items: stretch;
  }
  
  .tag-cloud {
    gap: 0.35rem;
  }
  
  .tag-chip {
    font-size: 0.7rem;
    padding: 0.25rem 0.6rem;
  }
}
