/* CSS Variables for theming */
:root {
  --primary-color: #2196f3;
  --text-color: #ffffff;
  --bg-color: #1a1a1a;
  --card-bg: #2a2a2a;
  --card-text: #fff;
  --card-text-secondary: rgba(255, 255, 255, 0.7);
  --card-overlay: rgba(0, 0, 0, 0.7);
  --border-color: #404040;
  --shadow-color: rgba(0, 0, 0, 0.2);
  --header-bg: #121212;
  --footer-bg: #121212;
  --link-color: #64b5f6;

  /* Viewer-specific variables */
  --panel-bg: #fff;
  --panel-text-color: #000000;
  --control-bg: rgba(255, 255, 255, 0.8);
  --control-focus: #2196f3;
  --viewer-bg-color: #f5f5f5;

  /* Image loading variables */
  --image-loading-bg: #333;
  --image-loading-duration: 0.6s;
}

/* Reset any potential conflicting styles */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* Base styles */
body {
  background: var(--bg-color);
  color: var(--card-text);
  font-family: system-ui, -apple-system, sans-serif;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Accessibility enhancements */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* Focus styles for accessibility */
button:focus,
input:focus,
a:focus {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

button:focus:not(:focus-visible),
input:focus:not(:focus-visible),
a:focus:not(:focus-visible) {
  outline: none;
}

button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

/* ====================================================
   IMAGE VIEWER STYLES 
   ==================================================== */

/* Override some base styles for the viewer page */
.viewer-page {
  background: var(--viewer-bg-color);
  color: var(--text-color);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: row;
}

/* Layout structure */
.main-content {
  flex: 1;
  position: relative;
  overflow: hidden;
}

/* Viewer container */
.viewer-container {
  position: relative;
  width: 100%;
  height: 100%;
  background: #000;
  touch-action: none;
  overflow: auto;
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.viewer-container::-webkit-scrollbar {
  display: none;
}

/* Image loading styling */
@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.loading-indicator {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.85);
  padding: 20px;
  border-radius: 10px;
  z-index: 1000;
  min-width: 220px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  transition: opacity 0.3s ease;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top: 4px solid var(--primary-color);
  animation: spin 1s linear infinite;
  margin: 0 auto 15px;
}

.loading-text {
  font-size: 16px;
  font-weight: 500;
  letter-spacing: 0.5px;
  color: white;
}

/* LazyLoad specific styles */
.lazyload,
.lazyloading {
  opacity: 0;
}

.lazyloaded {
  opacity: 1;
  transition: opacity 0.5s ease;
}

/* High-resolution image styling */
#image {
  position: absolute;
  top: 0;
  left: 0;
  transform: scale(1);
  transition: transform 0.1s ease, opacity 0.3s ease-in-out;
  user-select: none;
  cursor: grab;
  max-width: 100%;
  max-height: 100%;
  /* Force high-resolution image rendering for accessibility and sharpness */
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  image-rendering: -webkit-optimize-contrast;
  /* Prevent browser downsampling */
  backface-visibility: hidden;
  transform-style: preserve-3d;
  will-change: transform;
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
  /* Ensure proper rendering */
  object-fit: contain;
  object-position: center;
  /* Improve sharpness */
  -webkit-font-smoothing: subpixel-antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Image container for proper aspect ratio */
.image-container {
  position: relative;
  overflow: hidden;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Override mobile-specific rendering */
.is-mobile-device #image {
  transform: translate3d(0, 0, 0);
  -webkit-transform: translate3d(0, 0, 0);
  image-rendering: high-quality !important;
  /* Remove any potential downsampling */
  max-width: none !important;
  width: auto !important;
  height: auto !important;
}

/* Force high quality on all devices */
@media screen and (max-width: 768px) {
  #image {
    image-rendering: high-quality !important;
    -webkit-font-smoothing: subpixel-antialiased !important;
  }
}

/* Controls styling - floating */
.floating-controls {
  padding: 4px !important;
  border-radius: 4px !important;
}

@media (max-width: 768px) {
  .floating-controls {
    position: fixed;
    top: auto;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: auto;
    max-width: none;
    flex-wrap: wrap;
    justify-content: center;
    padding: 10px;
    border-radius: 10px;
    z-index: 1050;
    display: flex !important;
    opacity: 1;
  }

  .compass-toggle,
  .compass-nav {
    display: none !important;
  }

  .nav-btn.nav-n,
  .nav-btn.nav-s {
    aspect-ratio: 1/1;
    width: 44px;
    height: 44px;
  }

  .floating-controls .controls,
  .other-controls {
    display: flex !important;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
  }

  .floating-controls button {
    background-color: rgba(60, 60, 60, 0.95) !important;
    border: 1px solid rgba(255, 255, 255, 0.3);
    min-width: 40px;
    min-height: 40px;
    font-size: 1em;
    font-weight: 500;
    border-radius: 8px;
  }
}

.floating-controls button {
  padding: 10px;
  font-size: 1em;
  border: none;
  background: var(--control-bg);
  color: var(--text-color);
  border-radius: 8px;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.floating-controls button:focus {
  outline: 2px solid var(--control-focus);
}

/* Floating controls layout */
.floating-controls .controls {
  display: flex;
  flex-direction: row;
  gap: 10px;
}

.other-controls {
  display: flex;
  gap: 10px;
  margin-top: 0;
}

/* Description panel styling */
.description-panel {
  position: absolute;
  top: 0;
  right: -450px;
  width: 450px;
  height: 100%;
  background: var(--panel-bg);
  color: var(--panel-text-color);
  box-shadow: -2px 0 4px var(--shadow-color);
  transition: right 0.3s ease;
  overflow-y: auto;
  padding: 15px;
  z-index: 15;
}

.description-panel.show {
  right: 0;
}

.description-panel h2 {
  margin-bottom: 10px;
  font-size: 1.2em;
  color: #000000;
}

.description-panel p {
  font-size: 0.95em;
  line-height: 1.5;
  color: #000000;
}

#desc-title,
#desc-text {
  color: #000000 !important;
}

#close-description {
  float: right;
  padding: 8px 12px;
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

/* Audio player styling */
.audio-player {
  margin-top: auto;
  padding: 15px 0;
}

.audio-player h2 {
  font-size: 1.2em;
  margin-bottom: 10px;
  color: #000000;
}

audio {
  width: 100%;
}

/* Utility class */
.hidden {
  display: none;
}

/* Responsive design for viewer */
@media (max-width: 768px) {
  .viewer-page {
    flex-direction: column;
  }

  .main-content {
    flex: 1;
    position: relative;
    overflow: hidden;
  }

  .floating-controls {
    bottom: 10px;
    width: 90%;
    max-width: 400px;
    flex-wrap: wrap;
    justify-content: center;
  }

  .description-panel {
    width: 100%;
    right: -100%;
  }

  .description-panel.show {
    right: 0;
  }
}

/* Compass toggle styles */
.compass-toggle {
    --toggle-size: 44px;
    --disc-size: 150px;
    --transition-duration: 0.3s;
    position: fixed;
    bottom: 20px;
    left: 50%;
    border: 1px solid var(--border-color);
    cursor: pointer;
    pointer-events: auto;
    opacity: 0;
}

.compass-toggle:hover {
    width: var(--disc-size);
    height: var(--disc-size);
    box-shadow: 0 4px 10px var(--shadow-color);
}

.compass-toggle:focus {
    outline: none;
    box-shadow: 0 0 0 3px var(--input-focus-shadow);
    border-color: var(--input-focus-border);
}

.compass-inner-circle {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    border: 1px solid rgba(255,255,255,0.5);
    display: flex;
    overflow: hidden;
    position: relative;
    transition: opacity var(--transition-duration) ease;
    visibility: hidden;
}

.compass-toggle:hover .compass-inner-circle {
    opacity: 0;
}

.compass-inner-circle {
    background: rgba(255,255,255,0.3);
    border-color: rgba(255,255,255,0.7);
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .compass-toggle {
        border-color: var(--border-color);
    }
    
    .compass-inner-circle {
        background: rgba(255,255,255,0.2);
        border-color: rgba(255,255,255,0.5);
    }
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .compass-toggle {
        --toggle-size: 40px;
        --disc-size: 120px;
        bottom: 15px;
    }
    
    .compass-inner-circle {
        width: 28px;
        height: 28px;
    }
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
    .compass-toggle {
        transition: none;
    }
    
    .compass-inner-circle {
        transition: none;
    }
}

/* Compass rose navigation */
.compass-nav {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    box-shadow: 0 2px 5px var(--shadow-color);
    color: var(--card-text);
    padding: 10px;
    border-radius: 8px;
}

.nav-btn {
    background-color: var(--button-bg);
    border: 1px solid var(--button-border);
    color: var(--button-text);
    padding: 8px;
    margin: 3px;
    border-radius: 4px;
    transition: background-color 0.2s ease;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-btn:hover {
    background-color: var(--button-hover-bg);
}

.nav-btn:focus {
    outline: none;
    box-shadow: 0 0 0 2px var(--input-focus-shadow);
    border-color: var(--input-focus-border);
}

/* Zoom cutout areas */
.zoom-cutout {
  position: absolute;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.zoom-cutout::before,
.zoom-cutout::after {
  content: '';
  position: absolute;
  width: 100%;
  height: 50%;
  background: rgba(0, 0, 0, 0.3);
  pointer-events: auto;
}

.zoom-cutout::before {
  top: 0;
  clip-path: polygon(0 0, 100% 0, 100% 100%, 0 0);
}

.zoom-cutout::after {
  bottom: 0;
  clip-path: polygon(0 100%, 100% 100%, 100% 0, 0 100%);
}

/* Center cell for zoom controls */
.compass-nav::after {
  content: "";
  grid-area: c;
  width: 60px;
  height: 60px;
  background: rgba(255, 255, 255, 0.8);
  border-radius: 12px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Media query for mobile */
@media (max-width: 768px) {
  .compass-toggle {
    bottom: 80px;
    width: 50px;
    height: 50px;
  }

  .compass-nav {
    bottom: 150px;
    width: 200px;
    height: 200px;
  }

  .nav-btn {
    width: 50px;
    height: 50px;
    font-size: 20px;
  }

  .compass-nav::after {
    width: 50px;
    height: 50px;
  }
}

/* Viewer controls color fix */
.floating-controls button {
  background-color: rgba(50, 50, 50, 0.75) !important;
  border: 1px solid rgba(255, 255, 255, 0.4) !important;
  min-width: 52px !important;
  min-height: 52px !important;
  padding: 12px !important;
  border-radius: 8px !important;
  backdrop-filter: blur(4px) !important;
  -webkit-backdrop-filter: blur(4px) !important;
  transition: all 0.2s ease !important;
}

.floating-controls button:hover {
  background-color: rgba(80, 80, 80, 0.85) !important;
  transform: scale(1.05) !important;
}

.floating-controls button:active {
  transform: scale(0.95) !important;
}

/* Adjust spacing between buttons */
.bottom-controls {
  gap: 16px !important;
  padding: 12px !important;
}

/* Mobile adjustments */
@media (max-width: 768px) {
  .floating-controls button {
    min-width: 48px !important;
    min-height: 48px !important;
    padding: 10px !important;
  }
  
  .bottom-controls {
    gap: 12px !important;
    padding: 10px !important;
  }
}

/* Increase font size for control icons */
.control-icon {
  font-size: 32px !important;
  font-weight: bold;
  line-height: 1;
}

.control-text {
  font-size: 20px !important;
  font-weight: bold;
}

/* Increase size of navigation arrows */
.nav-btn {
  font-size: 28px !important;
  background-color: rgba(80, 80, 80, 0.9) !important;
  border: 1px solid rgba(255, 255, 255, 0.3) !important;
}

.floating-controls button:hover {
  background-color: rgba(80, 80, 80, 0.9) !important;
}

.compass-nav {
  background-color: rgba(50, 50, 50, 0.9) !important;
}

.nav-btn:hover {
  background-color: rgba(100, 100, 100, 0.9) !important;
}

#close-description {
  background-color: var(--primary-color) !important;
  color: white !important;
  font-size: 18px !important;
}

/* Add rules to prevent flashing during interactions */
.is-scrolling .grid-item,
.is-touching .grid-item {
  transition: none !important;
  transform: translateZ(0);
  will-change: transform;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  contain: paint;
}

/* Direct override for description content styling in viewer */
.viewer-page .description-panel .description-content {
  overflow-y: auto !important;
  padding: 15px !important;
  margin-bottom: 20px !important;
  scrollbar-width: thin !important;
  scrollbar-color: rgba(0, 0, 0, 0.3) rgba(0, 0, 0, 0.05) !important;
  border: 1px solid rgba(0, 0, 0, 0.15) !important;
  border-radius: 8px !important;
  background-color: rgba(0, 0, 0, 0.03) !important;
  height: calc(100vh - 180px) !important;
  min-height: 200px !important;
  box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.05) !important;
  font-size: 14px !important;
}

/* Ensure scrollbar is always visible in Webkit browsers */
.viewer-page .description-panel .description-content::-webkit-scrollbar {
  width: 10px !important;
  height: 10px !important;
  display: block !important;
  background-color: rgba(0, 0, 0, 0.05) !important;
}

.viewer-page .description-panel .description-content::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.05) !important;
  border-radius: 4px !important;
  margin: 4px 0 !important;
}

.viewer-page .description-panel .description-content::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.3) !important;
  border-radius: 4px !important;
  border: 2px solid rgba(0, 0, 0, 0.05) !important;
  background-clip: padding-box !important;
}

.viewer-page .description-panel .description-content::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.5) !important;
}

/* Force scrollbar visibility */
.viewer-page .description-panel .description-content.scrollable {
  overflow-y: scroll !important;
}

/* Dark mode support for content area with higher specificity */
@media (prefers-color-scheme: dark) {
  .viewer-page .description-panel .description-content {
    border-color: rgba(255, 255, 255, 0.15) !important;
    background-color: rgba(255, 255, 255, 0.05) !important;
    color: rgba(255, 255, 255, 0.9) !important;
    box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.2) !important;
  }
  
  .viewer-page .description-panel .description-content::-webkit-scrollbar {
    background-color: rgba(255, 255, 255, 0.05) !important;
  }
  
  .viewer-page .description-panel .description-content::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05) !important;
  }
  
  .viewer-page .description-panel .description-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3) !important;
    border: 2px solid rgba(255, 255, 255, 0.05) !important;
  }
  
  .viewer-page .description-panel .description-content::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5) !important;
  }
}

/* Mobile flashing fix - GPU acceleration optimizations */
.viewer-container {
  overflow: hidden !important;
}

.is-scrolling #image,
.is-touching #image,
body:not(.is-zooming) #image {
  transition: none !important;
}

.is-zooming #image {
  transition: transform 0.2s ease-out !important;
}

/* Additional mobile-specific optimizations */
.is-mobile-device #image {
  transform: translate3d(0, 0, 0);
  -webkit-transform: translate3d(0, 0, 0);
  image-rendering: auto;
}

/* Prevent browser-level touch actions that can cause flashing */
.is-mobile-device .viewer-container {
  touch-action: none !important;
}

/* Floating Disc Styles */
.floating-disc {
  position: fixed;
  left: 50%;
  bottom: 40px;             
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background-color: #808080; 
  z-index: 1000;
  transform: translateX(-50%);
  opacity: .8;
  display: block !important;
  pointer-events: auto;    
  border: 3px solid #ffffff;
  transition: opacity 0.3s ease-out;
}

/* When joystick is visible, hide the floating disc */
.joystick-control.visible ~ .floating-disc,
.joystick-control[style*="display: block"] ~ .floating-disc {
  display: none;
  opacity: 0;
  pointer-events: none !important;
}

/* Hide floating disc on mobile devices */
@media (max-width: 768px) {
  .floating-disc {
    display: none !important;
  }
}

/* Add or update joystick control z-index */
.joystick-control {
  z-index: 1001 !important;
  pointer-events: none;
}

.joystick-control.visible {
  pointer-events: auto !important;
}

/* Make sure the joystick disc gets pointer events when visible */
.joystick-control.visible .joystick-disc {
  pointer-events: auto !important;
}

/* Image container with intrinsic ratio technique */
.ratio-container {
  position: relative;
  height: 0;
  display: block;
  width: 100%;
  /* padding-bottom will be calculated dynamically in JS */
}

.ratio-container img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* For unknown aspect ratios */
.unknown-ratio-container {
  position: relative;
}

.unknown-ratio-container img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

/* Prevent layout shift during loading */
.image-container {
  min-height: 200px;
}

/* Improve loading aesthetics */
.lazyload,
.lazyloading {
  opacity: 0;
  min-height: 200px;
}

.lazyloaded {
  opacity: 1;
  transition: opacity 0.5s ease-in-out;
}

/* Blur-up effect for images */
.blur-up {
  -webkit-filter: blur(5px);
  filter: blur(5px);
  transition: filter 400ms, -webkit-filter 400ms;
}

.blur-up.lazyloaded {
  -webkit-filter: blur(0);
  filter: blur(0);
}

/* Additional mobile-specific image quality enhancements */
@media (max-width: 768px) {
  #image.lazyloaded {
    image-rendering: -webkit-optimize-contrast !important;
    image-rendering: crisp-edges !important;
    image-rendering: high-quality !important;
  }
  
  /* Prevent mobile browser image optimizations */
  .image-container {
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    will-change: transform;
  }
}
