:root {
  --panel-bg: rgba(18, 18, 18, 0.6);
  --panel-border: rgba(255, 255, 255, 0.12);
  --text: rgba(255, 255, 255, 0.92);
  --muted: rgba(255, 255, 255, 0.72);
  --label-bg: rgba(0, 0, 0, 0.36);
  --label-border: rgba(255, 255, 255, 0.14);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

body {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

img {
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

#app {
  width: 100%;
  height: 100%;
  position: relative;
  /* Creates a new stacking context so children don't fight */
  isolation: isolate;
}

#controls {
  position: absolute;
  left: 16px;
  bottom: 16px;
  z-index: 9999; /* Extremely high */
  width: 220px;
  padding: 12px 14px;
  background: rgba(18, 18, 18, 0.9); /* More opaque to prevent flicker */
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  backdrop-filter: blur(12px);
  /* Force this element onto its own GPU layer away from the world */
  transform: translateZ(0); 
  pointer-events: auto;
}

.control-section + .control-section {
  margin-top: 14px;
}

.control-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 8px;
}

#controls label {
  display: block;
  font-size: 14px;
  line-height: 1.45;
  margin: 5px 0;
  cursor: pointer;
}

#controls input[type="checkbox"],
#controls input[type="radio"] {
  margin-right: 8px;
  vertical-align: middle;
}

.range-input {
  width: 100%;
  margin: 0;
}

.control-button {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.96);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  cursor: pointer;
}

.control-button:hover {
  background: rgba(255, 255, 255, 0.12);
}

#stage-wrap {
  position: absolute;
  inset: 0;
  z-index: 10;
  overflow: hidden;
  cursor: grab;
}

#stage-wrap.dragging {
  cursor: grabbing;
}

#camera {
  position: absolute;
  inset: 0;
  overflow: hidden;
  transform-origin: center center;
}

#world {
  position: absolute;
  inset: 0;
  transform-origin: center center;
}

#stage,
#group-overlays {
  position: absolute;
  inset: 0;
}

#group-overlays {
  position: absolute;
  inset: 0;
  pointer-events: none !important;
  z-index: 20;
}

.group-label {
  pointer-events: none;
  position: absolute;
  transform: translate(-50%, -50%);
  padding: 4px 8px;
  font-size: 28px;
  line-height: 1.05;
  font-weight: 900;
  color: rgba(255, 255, 255, 1);
  text-align: center;
  white-space: nowrap;
  letter-spacing: 0.01em;
  text-shadow:
    0 0 2px rgba(0, 0, 0, 0.9),
    0 0 8px rgba(0, 0, 0, 0.9),
    0 2px 12px rgba(0, 0, 0, 0.8);
  background: rgba(0, 0, 0, 0.4); /* Added slight backing for legibility */
  padding: 4px 12px;
  border-radius: 4px;
  backdrop-filter: none;
}

.group-divider {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: rgba(255, 255, 255, 0.08);
}

.floating-image {
  position: absolute;
  transform-origin: center center;
  will-change: transform, left, top, width, height, opacity;
  /* Added 'transform' to the transition list for smooth scaling */
  transition:
    left 380ms cubic-bezier(0.2, 0.8, 0.2, 1),
    top 380ms cubic-bezier(0.2, 0.8, 0.2, 1),
    width 380ms cubic-bezier(0.2, 0.8, 0.2, 1),
    height 380ms cubic-bezier(0.2, 0.8, 0.2, 1),
    transform 450ms cubic-bezier(0.2, 0.8, 0.2, 1), /* Smooth scale up/down */
    opacity 220ms ease;
  pointer-events: auto !important;
  transform-origin: center center;
  z-index: 10;
  user-select: none;
}

.floating-image img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 10px 24px rgba(0, 0, 0, 0.42));
}

.floating-image.appear {
  animation: pop-in 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes pop-in {
  from {
    transform: scale(0.02);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.floating-image.hovered {
  z-index: 25;
}

#tooltip {
  position: absolute;
  z-index: 60;
  min-width: 260px;
  max-width: 360px;
  padding: 14px 16px;
  font-size: 20px;
  line-height: 1.35;
  color: rgba(255, 255, 255, 0.97);
  background: rgba(0, 0, 0, 0.84);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 12px;
  pointer-events: none;
  white-space: normal;
  backdrop-filter: blur(6px);
  pointer-events: none !important;
}

#tooltip strong {
  font-weight: 700;
}

#corner-status {
  position: absolute;
  right: 16px;
  bottom: 16px;
  z-index: 70;
  padding: 10px 14px;
  font-size: 16px;
  color: rgba(255, 255, 255, 0.96);
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  backdrop-filter: blur(5px);
}


#loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  
  /* Darkened background: 0.8 alpha makes the background images look dim 
     without hiding them or the loading text. */
  background-color: rgba(0, 0, 0, 0.8); 
  
  /* Removed backdrop-filter: blur to keep hallucinations sharp while loading */
  backdrop-filter: none; 
  
  display: none; /* Controlled by JS */
  place-items: center;
  z-index: 2000; 
  
  /* Ensures user can't click images while they are still initializing */
  pointer-events: auto; 
}

#loading-card {
  text-align: center;
}

#loading-text {
  font-size: 34px;
  color: rgba(255, 255, 255, 0.95);
  letter-spacing: 0.03em;
}

#loading-progress {
  margin-top: 10px;
  font-size: 22px;
  color: rgba(255, 255, 255, 0.78);
}

/* --- LIGHTBOX & INDIVIDUAL HIGHLIGHTING --- */
#lightbox {
  position: absolute;
  inset: 0;
  z-index: 20000; /* Ensure it is above the controls if needed */
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.4s ease, visibility 0.4s ease;
  pointer-events: none;
}

#lightbox.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

#lightbox-backdrop {
  position: absolute;
  inset: 0;
  /* Lowered from 0.82 to 0.2 to let the background through */
  background: rgba(0, 0, 0, 0.2); 
  /* We use the camera's filter for blur instead of this to keep things sharp */
  backdrop-filter: none; 
}

#lightbox-content {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
}

#lightbox-image {
  /* Increased from 78% to 92% for better visibility */
  max-width: 92vw;
  max-height: 92vh;
  object-fit: contain;
  filter: drop-shadow(0 18px 40px rgba(0, 0, 0, 0.45));
}

#lightbox-info {
  position: absolute;
  right: 28px;
  bottom: 28px;
  z-index: 2;
  max-width: min(560px, 60vw);
  padding: 16px 20px;
  font-size: 28px;
  line-height: 1.3;
  color: rgba(255, 255, 255, 0.98);
  background: rgba(0, 0, 0, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 14px;
  backdrop-filter: blur(6px);
}

/* --- SLIDE SYSTEM --- */
.slide-container {
  position: absolute;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  
  /* CRITICAL: This makes the entire layer 'invisible' to clicks/drags */
  pointer-events: none; 
  
  transition: backdrop-filter 0.5s ease, background 0.5s ease;
}

#active-slide-img {
  width: 95vw;
  height: 95vh;
  max-width: 95%;
  max-height: 95%;
  object-fit: contain;
  transition: opacity 0.4s ease;
  filter: drop-shadow(0 0 30px rgba(0,0,0,0.5));
  
  /* Ensure the image itself doesn't block clicks either */
  pointer-events: none;
  background-color: transparent;
  
  /* This transition helps the opacity change we use in the updateImg function */
  transition: opacity 0.3s ease-in-out;
}

/* We only want slides to block the mouse if we are in Fullscreen mode 
   and actually want to interact with a slide (rare) */
#stage-wrap.fullscreen-slides .slide-container {
  background: #000;
  z-index: 9998;
  /* Uncomment the line below only if you need to click on things ON the slide */
  /* pointer-events: auto; */
}

/* Fullscreen Mode */
#stage-wrap.fullscreen-slides .slide-container {
  background: #000;
  z-index: 9998;
}

#stage-wrap.fullscreen-slides #active-slide-img {
  width: 100vw;
  height: 100vh;
  max-width: 100%;
  max-height: 100%;
}

#stage-wrap.fullscreen-slides #camera {
  visibility: hidden;
}

/* --- CAMERA BLUR --- */
#camera {
  position: absolute;
  inset: 0;
  transition: filter 0.5s ease;
}

body.lightbox-open #camera {
  filter: blur(4px) brightness(0.6);
}

/* Fix for the hidden controls state */
#controls.minimized {
  width: auto;
  padding: 8px;
}
#controls.minimized #controlsContent {
  display: none;
}

#stage-wrap.blur-active .slide-container {
  backdrop-filter: blur(10px) brightness(0.3);
  background: rgba(0, 0, 0, 0.3);
}

.group-label {
  line-height: 1.4;
  white-space: nowrap; /* Or remove this if you want the text to wrap naturally */
  /* your other styles like font-size, color, etc. */
}

#attribution-box {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background-color: rgba(0, 0, 0, 0.7);
  color: #ffffff;
  padding: 10px 25px; /* Increased side padding slightly for better balance */
  border-radius: 8px;
  font-family: sans-serif;
  font-size: 13px;
  z-index: 1000;
  text-align: center;
  pointer-events: auto;
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 255, 255, 0.1);

  /* --- ADD THESE TWO LINES --- */
  width: max-content; 
  max-width: 90vw;     /* Ensures it doesn't break on small screens */
}

#attribution-box a {
  color: #ffffff;
  text-decoration: underline;
  margin-left: 4px;
  transition: opacity 0.2s;
}

#attribution-box a:hover {
  opacity: 0.8;
}

/* Ensure it doesn't overlap with your controls on very small screens */
@media (max-width: 1200px) {
  #attribution-box {
    width: 100%;
    font-size: 11px;
  }
}