/**
 * Bengal SSG Default Theme
 * Interactive Components
 *
 * Styles for interactive UI elements:
 * - Back to top button
 * - Reading progress bar
 * - Copy link buttons
 * - Image lightbox
 */

/* ============================================
   BACK TO TOP BUTTON
   ============================================ */

.back-to-top {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 3rem;
  height: 3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--color-primary);
  color: var(--color-text-inverse);
  border: none;
  border-radius: var(--border-radius-full);
  box-shadow: var(--elevation-card);
  cursor: pointer;
  z-index: var(--z-fixed);
  transition: all var(--transition-base);
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.8);
}

.back-to-top.visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.back-to-top:hover {
  background-color: var(--color-primary-hover);
  box-shadow: var(--elevation-card-hover);
  transform: translateY(-4px) scale(1.05);
}

.back-to-top:active {
  transform: translateY(-2px) scale(1);
}

.back-to-top:focus-visible {
  outline: 2px solid var(--color-border-focus);
  outline-offset: 3px;
}

.back-to-top svg {
  width: 20px;
  height: 20px;
}

/* Mobile adjustments */
@media (max-width: 768px) {
  .back-to-top {
    bottom: 1rem;
    right: 1rem;
    width: 2.5rem;
    height: 2.5rem;
  }

  .back-to-top svg {
    width: 18px;
    height: 18px;
  }
}

/* ============================================
   READING PROGRESS BAR
   ============================================ */

.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background-color: var(--color-bg-secondary);
  z-index: var(--z-fixed);
  overflow: hidden;
}

.reading-progress__fill {
  height: 100%;
  background: linear-gradient(
    90deg,
    var(--color-primary) 0%,
    var(--color-secondary) 100%
  );
  transition: width 150ms ease-out;
  transform-origin: left;
}

/* Hide on very small screens */
@media (max-width: 640px) {
  .reading-progress {
    height: 2px;
  }
}

/* ============================================
   COPY LINK BUTTONS (for headings)
   ============================================ */

.heading-anchor {
  position: relative;
  scroll-margin-top: 5rem; /* Account for fixed header */
}

.copy-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  margin-left: 0.5rem;
  padding: 0;
  background: transparent;
  border: none;
  color: var(--color-text-tertiary);
  opacity: 0;
  cursor: pointer;
  transition: all var(--transition-fast);
  vertical-align: middle;
  text-decoration: none; /* Remove underline for anchor tags */
}

.heading-anchor:hover .copy-link,
.copy-link:focus {
  opacity: 1;
}

.copy-link:hover {
  color: var(--color-primary);
  transform: scale(1.1);
}

.copy-link:active {
  transform: scale(0.95);
}

.copy-link:focus-visible {
  outline: 2px solid var(--color-border-focus);
  outline-offset: 2px;
  border-radius: 2px;
}

.copy-link svg {
  width: 16px;
  height: 16px;
}

/* Success state */
.copy-link.copied {
  color: var(--color-success);
}

/* Always show on mobile (can't hover) */
@media (max-width: 768px) {
  .copy-link {
    opacity: 0.5;
  }
}

/* ============================================
   IMAGE LIGHTBOX
   ============================================ */

.lightbox {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.9);
  z-index: var(--z-modal);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  cursor: zoom-out;
  animation: fadeIn 200ms ease-out;
}

.lightbox.active {
  display: flex;
}

.lightbox__image {
  max-width: 90%;
  max-height: 90vh;
  object-fit: contain;
  border-radius: var(--border-radius-medium);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  cursor: default;
  animation: scaleIn 200ms ease-out;
}

.lightbox__close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 3rem;
  height: 3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(255, 255, 255, 0.1);
  color: white;
  border: none;
  border-radius: var(--border-radius-full);
  cursor: pointer;
  transition: all var(--transition-fast);
  backdrop-filter: blur(10px);
}

.lightbox__close:hover {
  background-color: rgba(255, 255, 255, 0.2);
  transform: scale(1.1);
}

.lightbox__close:active {
  transform: scale(0.95);
}

.lightbox__close:focus-visible {
  outline: 2px solid white;
  outline-offset: 2px;
}

.lightbox__close svg {
  width: 24px;
  height: 24px;
}

/* Lightbox caption */
.lightbox__caption {
  position: absolute;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  max-width: 80%;
  padding: 0.75rem 1.5rem;
  background-color: rgba(0, 0, 0, 0.7);
  color: white;
  border-radius: var(--border-radius-medium);
  text-align: center;
  backdrop-filter: blur(10px);
}

/* Clickable images indicator */
img[data-lightbox] {
  cursor: zoom-in;
  transition: all var(--transition-base);
}

img[data-lightbox]:hover {
  opacity: 0.9;
  box-shadow: var(--elevation-card);
}

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

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

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

/* ============================================
   KEYBOARD SHORTCUTS HINT
   ============================================ */

.keyboard-shortcuts {
  position: fixed;
  bottom: 1rem;
  left: 1rem;
  padding: 0.75rem 1rem;
  background-color: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-medium);
  box-shadow: var(--elevation-card);
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  z-index: var(--z-popover);
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-base);
}

.keyboard-shortcuts.visible {
  opacity: 1;
  visibility: visible;
}

.keyboard-shortcuts kbd {
  display: inline-block;
  padding: 0.125rem 0.375rem;
  font-size: var(--text-xxs);
  font-family: var(--font-family-code);
  background-color: var(--color-bg-tertiary);
  border: 1px solid var(--color-border);
  border-radius: 3px;
  box-shadow: 0 1px 0 var(--color-border-dark);
  margin: 0 0.25rem;
}

/* ============================================
   REDUCED MOTION
   ============================================ */

@media (prefers-reduced-motion: reduce) {
  .back-to-top,
  .reading-progress__fill,
  .copy-link,
  .lightbox,
  .lightbox__image {
    animation: none !important;
    transition: none !important;
  }

  .back-to-top.visible {
    transform: translateY(0) scale(1);
  }
}

/* Reduce motion class (JS-applied) */
.reduce-motion * {
  animation-duration: 0.001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.001ms !important;
}

/* ============================================
   PRINT
   ============================================ */

@media print {
  .back-to-top,
  .reading-progress,
  .copy-link,
  .lightbox,
  .keyboard-shortcuts {
    display: none !important;
  }
}
