/* --- General Setup & Layout --- */
html {
  height: 100%;
  box-sizing: border-box;
}
*,
*:before,
*:after {
  box-sizing: inherit;
}

body {
  height: 100%;
  margin: 0;
  background-color: #e0e0e0; /* Fallback/outer background */
  font-family: Calibri, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden; /* Prevent scrollbars caused by fixed elements */
}

.main-content {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

/* --- Viewer Area (Black Background) --- */
#viewer-area {
  flex: 1 1 auto;
  background-color: black;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 10px;
  overflow: hidden;
  position: relative; /* Needed for hint positioning */
}

#image-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

#movie-frame {
  display: block;
  max-width: 100%;
  max-height: 100%;
  height: auto;
  width: auto;
  object-fit: contain;
  cursor: pointer;
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.4);
  background-color: #111;
  min-height: 100px;
}

#loading-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 10;
  width: 60px;
  height: 60px;
  pointer-events: none; /* Prevent interaction */
}
#loading-spinner img {
  width: 100%;
  height: 100%;
}

.grid-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  pointer-events: none;
  z-index: 5;
}
.grid-overlay img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* --- Initial Click Hint --- */
#click-hint {
  position: absolute;
  top: 40%; /* Position slightly above center */
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 8px 15px;
  border-radius: 5px;
  font-size: 14px;
  z-index: 50; /* Above image, below controls */
  pointer-events: none; /* Don't block clicks on image */
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.4s ease, visibility 0.4s ease;
}

#click-hint.visible {
  opacity: 1;
  visibility: visible;
}

/* --- Controls (Floating, Hover-Reveal, No Background Gradient) --- */
#controls-container {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  /* REMOVED background gradient */
  /* background: linear-gradient(to top, rgba(0,0,0,0.8), rgba(0,0,0,0.6) 50%, transparent); */
  padding: 15px; /* Adjusted padding */
  display: flex;
  flex-direction: column; /* Stack button row and footer row */
  align-items: center; /* Center rows horizontally */
  gap: 10px; /* Space between button row and footer row */
  z-index: 100;

  /* Hide/Show Logic */
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px);
  transition: opacity 0.4s ease, visibility 0.4s ease, transform 0.4s ease;
  pointer-events: none;
}

/* Show controls when hovering near bottom OR when initially visible */
/* IMPORTANT: Added :not(.explicitly-hidden) */
.main-content:hover #controls-container:not(.explicitly-hidden),
#controls-container.visible-initially:not(.explicitly-hidden) {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  pointer-events: auto;
}

/* Style for when explicitly hidden by the user */
#controls-container.explicitly-hidden {
  opacity: 0 !important;
  visibility: hidden !important;
  transform: translateY(20px) !important;
  pointer-events: none !important;
}

/* --- Control Rows --- */
.controls-button-row {
  display: flex;
  flex-wrap: wrap; /* Allow buttons to wrap on small screens */
  justify-content: center;
  align-items: center;
  gap: 10px; /* Space between buttons */
}

.controls-footer-row {
  font-size: 12px;
  color: #ccc; /* Lighter color for footer text */
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7); /* Shadow for readability */
  text-align: center;
  width: 100%;
}
.controls-footer-row a {
  color: #eee; /* Lighter link color */
  text-decoration: none;
}
.controls-footer-row a:hover {
  text-decoration: underline;
}

/* --- Control Buttons --- */
.control-button,
a.control-button {
  background-color: rgba(40, 40, 40, 0.85); /* Darker semi-transparent */
  color: #eee; /* Light text */
  border: 1px solid rgba(255, 255, 255, 0.2); /* Subtle light border */
  border-radius: 8px;
  padding: 8px 15px;
  font-size: 15px;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease, transform 0.1s ease,
    box-shadow 0.2s ease;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.5); /* Subtle text shadow */
}
.control-button:hover,
a.control-button:hover {
  background-color: rgba(60, 60, 60, 0.9);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
}
.control-button:active,
a.control-button:active {
  transform: translateY(0px);
  background-color: rgba(30, 30, 30, 0.9);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}
.control-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

/* Active state for main grid button */
.control-button.active-grid {
  background-color: rgba(90, 90, 90, 0.9); /* Indicate active grid */
  color: white;
}

.download-button img {
  width: 16px;
  height: 16px;
  vertical-align: middle;
  filter: invert(90%); /* Make SVG icon lighter */
}

/* Hide Controls Button ('X') */
.hide-button {
  padding: 6px 10px; /* Make slightly smaller */
  font-size: 18px;
  line-height: 1; /* Ensure 'X' is centered vertically */
  min-width: 30px;
}

/* --- Grid Button Menu --- */
.control-button-wrapper {
  position: relative; /* Needed for absolute positioning of menu */
  display: inline-flex; /* Align with other buttons */
}

.grid-menu {
  position: absolute;
  bottom: calc(100% + 8px); /* Position above the main button with gap */
  left: 50%;
  transform: translateX(-50%);
  background-color: rgba(50, 50, 50, 0.95); /* Slightly darker menu */
  border-radius: 6px;
  padding: 8px;
  display: flex;
  flex-direction: column; /* Stack menu items vertically */
  gap: 5px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
  z-index: 110; /* Above controls container */

  /* Hide/Show via hover on wrapper */
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateX(-50%) translateY(10px); /* Start slightly lower */
  transition: opacity 0.25s ease, visibility 0.25s ease, transform 0.25s ease;
}

.grid-control-wrapper:hover .grid-menu {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

.grid-menu-button {
  background-color: transparent;
  color: #ddd;
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  text-align: left;
  width: 100%;
  transition: background-color 0.2s ease;
}
.grid-menu-button:hover {
  background-color: rgba(255, 255, 255, 0.15);
  color: white;
}
.grid-menu-button.active {
  background-color: rgba(255, 255, 255, 0.25); /* Highlight active choice */
  font-weight: bold;
  color: white;
}

/* --- Footer (REMOVED - now part of controls) --- */
/* .footer { display: none; } */

/* --- Fullscreen View --- */
#fullscreen-container {
  /* ... (no changes needed) ... */
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: black;
  z-index: 9999;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
}
#fullscreen-image {
  /* ... (no changes needed) ... */
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
#fullscreen-loader {
  /* ... (no changes needed) ... */
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 60px;
  height: 60px;
  z-index: 10000;
  pointer-events: none;
}
#fullscreen-loader img {
  width: 100%;
  height: 100%;
}

/* Hide fullscreen button on desktop */
@media (min-width: 769px) {
  #fullscreen-button {
    display: none !important;
  }
}

/* --- Responsiveness --- */
@media (max-width: 650px) {
  /* Adjust breakpoint as needed */
  .control-button,
  a.control-button {
    font-size: 13px;
    padding: 6px 10px;
  }
  #controls-container {
    padding: 10px;
    gap: 8px;
  }
  .controls-button-row {
    gap: 8px; /* Smaller gap between wrapped buttons */
  }
  .controls-footer-row {
    font-size: 11px;
  }
  .hide-button {
    padding: 5px 8px;
    font-size: 16px;
  }
  .grid-menu {
    /* Optional: Adjust menu position/size on small screens if needed */
  }
  #click-hint {
    font-size: 12px;
    padding: 6px 10px;
    top: 35%; /* Maybe move higher */
  }
}
