/**
 * 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: 5rem;
  right: 2rem;
  width: 3rem;
  height: 3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg,
      color-mix(in srgb, var(--color-primary) 95%, white),
      var(--color-primary));
  color: var(--color-icon-on-accent);
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  z-index: var(--z-fixed);
  transition: all var(--transition-base);
  opacity: 0;
  visibility: hidden;
  transform: translate3d(0, 20px, 0) scale(0.8);
  /* Neumorphic shadow - standardized */
  box-shadow: var(--neumorphic-base);
}

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

.back-to-top:hover {
  background: linear-gradient(180deg,
      color-mix(in srgb, var(--color-primary-hover) 95%, white),
      var(--color-primary-hover));
  /* Neumorphic hover - standardized */
  box-shadow: var(--neumorphic-hover);
  transform: translate3d(0, -4px, 0) scale(1.05);
}

.back-to-top:active {
  /* Neumorphic pressed - standardized */
  background: linear-gradient(180deg,
      color-mix(in srgb, var(--color-primary-active) 95%, black),
      var(--color-primary-active));
  box-shadow: var(--neumorphic-pressed);
  transform: translate3d(0, -1px, 0) scale(1.02);
}

/* Dark mode adjustments for back-to-top */
[data-theme="dark"] .back-to-top {
  background: linear-gradient(180deg,
      color-mix(in srgb, var(--color-primary) 90%, rgba(0, 0, 0, 0.3)),
      var(--color-primary));
  box-shadow: var(--neumorphic-base);
}

[data-theme="dark"] .back-to-top:hover {
  background: linear-gradient(180deg,
      color-mix(in srgb, var(--color-primary-hover) 90%, rgba(0, 0, 0, 0.2)),
      var(--color-primary-hover));
  box-shadow: var(--neumorphic-hover);
}

[data-theme="dark"] .back-to-top:active {
  background: linear-gradient(180deg,
      color-mix(in srgb, var(--color-primary-active) 90%, rgba(0, 0, 0, 0.4)),
      var(--color-primary-active));
  box-shadow: var(--neumorphic-pressed);
}

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

.back-to-top svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  stroke-width: 2.5;
  fill: none;
  display: block;
  pointer-events: none;
}

/* Ensure child elements inherit stroke */
.back-to-top svg line,
.back-to-top svg polyline {
  stroke: inherit;
}

/* Mobile adjustments */
@media (max-width: 768px) {
  .back-to-top {
    bottom: 4rem;
    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;
  /* Match header's frosty glass effect */
  background-color: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px) saturate(180%);
  -webkit-backdrop-filter: blur(12px) saturate(180%);
  z-index: var(--z-fixed);
  overflow: hidden;
}

/* Dark mode - match header's dark theme */
[data-theme="dark"] .reading-progress {
  background-color: rgba(26, 26, 26, 0.85);
}

/* Fallback for browsers without backdrop-filter */
@supports not (backdrop-filter: blur(12px)) {
  .reading-progress {
    background-color: var(--color-bg-primary);
  }
}

@supports not (backdrop-filter: blur(12px)) {
  [data-theme="dark"] .reading-progress {
    background-color: rgba(26, 26, 26, 0.95);
  }
}

.reading-progress__fill {
  height: 100%;
  background: linear-gradient(90deg,
      var(--color-primary) 0%,
      var(--color-accent) 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-inline-start: 0.5rem;
  padding: 0;
  /* Ghost/frosted glass effect with neumorphic shadow */
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(8px) saturate(180%);
  -webkit-backdrop-filter: blur(8px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-sm);
  color: var(--color-text-tertiary);
  opacity: 0;
  cursor: pointer;
  transition: all var(--transition-fast);
  vertical-align: middle;
  text-decoration: none;
  /* Neumorphic shadow - standardized */
  box-shadow: var(--neumorphic-subtle);
}

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

.copy-link:hover {
  color: var(--color-text-primary);
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.3);
  /* Neumorphic hover - standardized */
  box-shadow: var(--neumorphic-hover);
  transform: scale(1.08);
}

.copy-link:active {
  /* Neumorphic pressed state - standardized */
  box-shadow: var(--neumorphic-subtle-pressed);
  transform: scale(0.98);
  background: rgba(255, 255, 255, 0.15);
}

.copy-link:focus-visible {
  outline: 2px solid var(--color-border-focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
  opacity: 1;
  /* Show on focus for accessibility */
}

/* Hide legacy pilcrow headerlinks if present (parser now outputs IDs only) */
.headerlink {
  display: none !important;
}

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

/* Success state */
.copy-link.copied {
  color: var(--color-success);
  background: rgba(34, 197, 94, 0.15);
  border-color: rgba(34, 197, 94, 0.3);
  /* Neumorphic shadow with success tint - using base pattern */
  box-shadow: var(--neumorphic-subtle);
}

/* Dark mode adjustments for ghost effect */
[data-theme="dark"] .copy-link {
  background: rgba(0, 0, 0, 0.2);
  border-color: rgba(255, 255, 255, 0.1);
  /* Neumorphic shadow for dark mode - standardized */
  box-shadow: var(--neumorphic-subtle);
}

[data-theme="dark"] .copy-link:hover {
  background: rgba(0, 0, 0, 0.3);
  border-color: rgba(255, 255, 255, 0.2);
  /* Neumorphic hover for dark mode - standardized */
  box-shadow: var(--neumorphic-hover);
}

[data-theme="dark"] .copy-link.copied {
  background: rgba(34, 197, 94, 0.2);
  border-color: rgba(34, 197, 94, 0.4);
}

/* Fallback for browsers without backdrop-filter */
@supports not (backdrop-filter: blur(8px)) {
  .copy-link {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid var(--color-border);
  }

  [data-theme="dark"] .copy-link {
    background: rgba(26, 26, 26, 0.9);
    border-color: var(--color-border);
  }
}

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

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

.lightbox {
  position: fixed;
  inset: 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;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

/* View Transitions API for smooth open/close */
@supports (view-transition-name: lightbox) {
  .lightbox {
    view-transition-name: lightbox;
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translate3d(0, 0, 0) scale(0.95);
  }

  to {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1);
  }
}

.lightbox.active {
  display: flex;
  animation: fadeIn 200ms ease-out;
  will-change: opacity, transform;
}

/* Remove will-change after animation completes */
.lightbox.active:not(:hover) {
  animation-fill-mode: forwards;
}

.lightbox.active {
  display: flex;
}

.lightbox__image {
  max-width: 90%;
  max-height: 90vh;
  object-fit: contain;
  border-radius: var(--radius-lg);
  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: linear-gradient(180deg,
      rgba(255, 255, 255, 0.15),
      rgba(255, 255, 255, 0.1));
  color: var(--color-icon-on-accent);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition-fast);
  backdrop-filter: blur(10px);
  /* Neumorphic shadow for dark overlay - standardized */
  box-shadow: var(--neumorphic-base);
}

.lightbox__close:hover {
  background: linear-gradient(180deg,
      rgba(255, 255, 255, 0.25),
      rgba(255, 255, 255, 0.2));
  border-color: rgba(255, 255, 255, 0.3);
  /* Neumorphic hover - standardized */
  box-shadow: var(--neumorphic-hover);
  transform: scale(1.1);
}

.lightbox__close:active {
  background: linear-gradient(180deg,
      rgba(255, 255, 255, 0.1),
      rgba(255, 255, 255, 0.05));
  /* Neumorphic pressed - standardized */
  box-shadow: var(--neumorphic-pressed);
  transform: scale(0.95);
}

/* Dark theme overrides keep icon visible on overlays */
:root[data-theme="dark"] .lightbox__close {
  background: linear-gradient(180deg,
      rgba(0, 0, 0, 0.45),
      rgba(0, 0, 0, 0.7));
  border-color: rgba(255, 255, 255, 0.25);
}

:root[data-theme="dark"] .lightbox__close:hover {
  background: linear-gradient(180deg,
      rgba(0, 0, 0, 0.35),
      rgba(0, 0, 0, 0.6));
}

:root[data-theme="dark"] .lightbox__close:active {
  background: linear-gradient(180deg,
      rgba(0, 0, 0, 0.6),
      rgba(0, 0, 0, 0.78));
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .lightbox__close {
    background: linear-gradient(180deg,
        rgba(0, 0, 0, 0.45),
        rgba(0, 0, 0, 0.7));
    border-color: rgba(255, 255, 255, 0.25);
  }

  :root:not([data-theme="light"]) .lightbox__close:hover {
    background: linear-gradient(180deg,
        rgba(0, 0, 0, 0.35),
        rgba(0, 0, 0, 0.6));
  }

  :root:not([data-theme="light"]) .lightbox__close:active {
    background: linear-gradient(180deg,
        rgba(0, 0, 0, 0.6),
        rgba(0, 0, 0, 0.78));
  }
}


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

.lightbox__close svg {
  width: 24px;
  height: 24px;
  stroke: currentColor;
  stroke-width: 2.5;
}

/* Ensure child elements inherit stroke */
.lightbox__close svg line {
  stroke: inherit;
}

/* Lightbox caption */
.lightbox__caption {
  position: absolute;
  bottom: 2rem;
  left: 50%;
  transform: translate3d(-50%, 0, 0);
  max-width: 80%;
  padding: 0.75rem 1.5rem;
  background-color: rgba(0, 0, 0, 0.7);
  color: white;
  border-radius: var(--radius-lg);
  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
   ============================================ */

/* fadeIn is defined above for lightbox - using GPU-accelerated version */

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: translate3d(-50%, -50%, 0) scale(0.95);
  }

  to {
    opacity: 1;
    transform: translate3d(-50%, -50%, 0) 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(--radius-lg);
  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-mono);
  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: translate3d(0, 0, 0) scale(1);
  }
}

/* Reduce motion class (JS-applied) */
/* Target specific interactive elements instead of universal selector to avoid dev tools conflicts */
.reduce-motion .back-to-top,
.reduce-motion .reading-progress__fill,
.reduce-motion .copy-link,
.reduce-motion .lightbox,
.reduce-motion .lightbox__image {
  animation-duration: 0ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0ms !important;
}

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

@media print {

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