/* 
 * Story Player - Main Stylesheet
 * 
 * This file contains all styling for the Reveal.js-based story player
 * with custom media controls and UI elements.
 */

/* ===== Core Dependencies ===== */
@import 'https://cdn.jsdelivr.net/npm/reveal.js/dist/reveal.css';
@import 'https://cdn.jsdelivr.net/npm/reveal.js/dist/theme/white.css';

/* ===== Variables ===== */
:root {
  --tribute-white: #fff;
  --tribute-black: #141414;
  --r-link-color: var(--tribute-white);
  --r-link-color-dark: var(--tribute-white);
  --r-link-color-hover: var(--tribute-white);
  --r-selection-background-color: var(--tribute-white);
}

/* ===== Base Layout ===== */
* {
  user-select: none;
}

*::selection {
  background: transparent;
  color: inherit;
}

html {
  font-family: 'Figree', Helvetica, sans-serif;
}

.reveal-viewport {
  background-color: var(--tribute-black);
}

.player-wrapper,
.story-player-container {
  width: 100%;
  aspect-ratio: 16 / 9;
}

.reveal {
  height: 100%;
  width: 100%;
  position: relative;
  background-color: var(--tribute-black);
}

.reveal .slides {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===== Slide Styling ===== */
.reveal .slides section {
  width: 100% !important;
  height: auto !important;
  display: flex !important;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.reveal .slides section#intro media-poster-image::part(poster img) {
  object-fit: cover !important;
}

/* ===== Media Elements ===== */
.img-container,
.title-container,
.reveal .img-container,
.reveal .title-container, /* images and titled slides */
.reveal video /* regular videos */ {
  width: 100% !important;
  max-width: none;
  height: 100% !important;
  max-height: none;
  margin: 0 auto;
  object-fit: contain;
  aspect-ratio: 16 / 9;
}

.reveal img {
  width: auto;
  max-width: 100% !important;
  height: 100%;
  max-height: 100% !important;
  margin: auto !important;
}

/* ===== Text Overlays ===== */
.text-overlay {
  position: absolute;
  display: flex;
  width: auto !important;
  height: auto !important;
  overflow-wrap: break-word;
  word-wrap: break-word;
  line-height: 1.2;
  z-index: 100;
  pointer-events: none;
}

/* ===== Progress Indicator ===== */
.slide-progress-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 5px;
  background-color: #2c2c2c;
  z-index: 900;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.slide-progress-bar {
  height: 100%;
  width: 0;
  background-color: var(--tribute-white);
  transition: width 0.1s linear;
}

.reveal .progress {
  height: 5px;
  border-radius: 0;
}

/* Show progress bar on images, hide on videos */
.image-slide .slide-progress-container {
  opacity: 1;
}

.video-slide .slide-progress-container {
  opacity: 0;
}

/* ===== Play/Pause Controls ===== */
.play-pause-container {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 9999;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.play-pause-container.active {
  opacity: 1;
}

.play-pause-container.hidden {
  opacity: 0 !important;
  pointer-events: none;
}

.play-button, .pause-button {
  background-color: rgba(0, 0, 0, 0.6);
  border: none;
  border-radius: 50%;
  color: white;
  width: 80px;
  height: 80px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: all 0.3s ease;
  pointer-events: auto;
}

.play-button:hover, .pause-button:hover {
  background-color: rgba(0, 0, 0, 0.8);
}

.play-button:focus-visible, .pause-button:focus-visible {
  outline: none;
}

.play-button svg, .pause-button svg {
  width: 40px;
  height: 40px;
}

.play-pause-container button.navigation-active {
  opacity: 0.3;
}

/* ===== Reveal.js Navigation Controls ===== */
.reveal .controls {
  position: absolute;
  top: 20px;
  left: 20px;
  width: 56px;
  height: 34px;
  display: flex !important;
  justify-content: space-between;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.reveal .controls.active {
  opacity: 1;
  pointer-events: auto;
}

.reveal .controls .navigate-left,
.reveal .controls .navigate-right {
  position: relative;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 28px;
  height: 34px;
}

.reveal .controls .controls-arrow {
  width: 28px;
  height: 34px;
}

.reveal .controls .navigate-left[disabled="disabled"],
.reveal .controls .navigate-right[disabled="disabled"] {
  opacity: 0.25;
  visibility: visible;
  pointer-events: none;
}

.reveal .controls .controls-arrow::after, .reveal .controls .controls-arrow::before {
  width: 2em;
  height: 0.4em;
}

.reveal .controls .navigate-right.highlight {
  animation: none !important;
}

.reveal .controls[data-controls-back-arrows="faded"] .navigate-left.enabled {
  opacity: 1 !important;
}

.navigate-right {
  animation: none;
}

/* ===== Top Right Controls ===== */
.top-right-controls {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 9999;
  display: flex;
  gap: 10px;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.top-right-controls.active {
  opacity: 1;
  pointer-events: auto;
}

/* Overview, mute, and fullscreen button styling */
.overview-button-container,
.mute-button-container,
.fullscreen-button-container {
  pointer-events: auto;
}

.overview-button,
.mute-button,
.fullscreen-button {
  background-color: rgba(0, 0, 0, 0.6);
  border: none;
  border-radius: 50%;
  border: 2px solid transparent;
  color: white;
  width: 40px;
  max-width: 40px;
  height: 40px;
  max-height: 40px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: all 0.3s ease;
  pointer-events: auto;
}

.overview-button:hover,
.mute-button:hover,
.fullscreen-button:hover {
  background-color: rgba(0, 0, 0, 0.8);
}

.overview-button:focus-visible,
.mute-button:focus-visible,
.fullscreen-button:focus-visible {
  border: none;
  outline: none;
  box-shadow: none;
}

.overview-button.active,
.mute-button.active,
.fullscreen-button.active {
  border: 2px solid var(--tribute-white);
}

.overview-button svg,
.mute-button svg,
.fullscreen-button svg {
  width: 20px;
  height: 20px;
}

/* ===== Overview Mode ===== */
.overview .slides section {
  width: 100% !important;
  height: 100% !important;
}

.overview .slides section.present,
.overview .slides section:hover {
  outline: 10px solid rgba(255,255,255,.75) !important;
}

.overview  .img-container,
.overview  .title-container,
.reveal.overview .img-container,
.reveal.overview .title-container,
.reveal.overview  video {
  height: 100% !important;
}

/* ===== Fullscreen Support ===== */
.reveal:-webkit-full-screen {
  width: 100%;
  height: 100%;
}

.reveal:-moz-full-screen {
  width: 100%;
  height: 100%;
}

.reveal:-ms-fullscreen {
  width: 100%;
  height: 100%;
}

.reveal:fullscreen {
  width: 100%;
  height: 100%;
}

/* ===== iOS Fullscreen Support ===== */
/* Custom fullscreen implementation for iOS Safari */
.reveal.ios-fullscreen {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  max-width: 100vw !important;
  max-height: 100vh !important;
  margin: 0 !important;
  padding: 0 !important;
  z-index: 9999 !important;
  background: #000 !important;
  border-radius: 0 !important;
  
  /* ✅ ENHANCED: Better iOS handling */
  /* Use safe area insets for notched devices */
  padding-top: env(safe-area-inset-top) !important;
  padding-bottom: env(safe-area-inset-bottom) !important;
  padding-left: env(safe-area-inset-left) !important;
  padding-right: env(safe-area-inset-right) !important;
  
  /* Force full height including status bar area */
  height: 100vh !important;
  height: calc(100vh + env(keyboard-inset-height, 0px)) !important;
}

/* Body styles when in iOS fullscreen */
body.ios-fullscreen-body {
  position: fixed !important;
  width: 100% !important;
  height: 100% !important;
  overflow: hidden !important;
  margin: 0 !important;
  padding: 0 !important;
  /* Prevent iOS Safari bounce/rubber-band effect */
  -webkit-overflow-scrolling: touch;
  /* Hide iOS Safari UI */
  -webkit-appearance: none;
  
  /* ✅ ENHANCED: Additional iOS optimizations */
  /* Prevent address bar from showing */
  overflow-x: hidden !important;
  overflow-y: hidden !important;
  /* Disable user interaction that might trigger Safari UI */
  -webkit-touch-callout: none !important;
  -webkit-user-select: none !important;
  /* Force hardware acceleration */
  -webkit-transform: translate3d(0, 0, 0) !important;
  transform: translate3d(0, 0, 0) !important;
}

/* Ensure slides fill the entire iOS fullscreen container */
.reveal.ios-fullscreen .slides {
  width: 100% !important;
  height: 100% !important;
  margin: 0 !important;
  padding: 0 !important;
}

.reveal.ios-fullscreen .slides section {
  width: 100% !important;
  margin: 0 !important;
  padding: 0 !important;
  border-radius: 0 !important;
}

/* Media containers in iOS fullscreen */
.reveal.ios-fullscreen .img-container,
.reveal.ios-fullscreen .title-container,
.reveal.ios-fullscreen video {
  width: 100% !important;
  object-fit: contain !important;
}

/* Control positioning in iOS fullscreen */
.reveal.ios-fullscreen .top-right-controls {
  position: fixed !important;
  bottom: 20px !important;
  left: 20px !important;
  z-index: 9999 !important;
}

/* Media chrome adjustments for iOS fullscreen */
.reveal.ios-fullscreen media-controller {
  width: 100% !important;
  height: 100% !important;
}

.reveal.ios-fullscreen media-control-bar {
  bottom: 0 !important;
  left: 0 !important;
  width: 100% !important;
}

/* Text overlays in iOS fullscreen */
.reveal.ios-fullscreen .text-overlay {
  /* Maintain text overlay positioning */
  position: absolute;
  z-index: 100;
}

/* Prevent iOS Safari zoom/scroll issues in fullscreen */
.ios-fullscreen-body * {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* ===== Preloader ===== */
.preloader {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.9);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  transition: opacity 0.5s ease;
}

.preloader.loaded {
  opacity: 0;
  pointer-events: none;
}

.loader-spinner {
  width: 50px;
  height: 50px;
  border: 5px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: var(--tribute-white);
  animation: spin 1s ease-in-out infinite;
  margin-bottom: 20px;
}

.loader-text {
  color: var(--tribute-white);
  font-size: 18px;
}

/* ===== Media Chrome Integration ===== */
media-controller {
  width: 100%;
  height: 100%;
  position: relative;
  --media-primary-color: var(--tribute-white);
  --media-secondary-color: var(--tribute-white);
  --media-text-color: var(--tribute-white);
  --media-control-background: transparent;
  --media-control-hover-background: rgba(20, 20, 20, 0.4);
}

media-time-display {
  --media-text-color: var(--tribute-white);
}

media-controller video[slot="media"] {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* Control bar styling with visibility control */
media-control-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 48px;
  background: rgba(20, 20, 20, 0.25);
  margin-bottom: 5px;
  padding: 0 15px;
  display: flex;
  align-items: center;
  z-index: 50;
  opacity: 0;
  pointer-events: auto;
  transition: opacity 0.3s ease;
}

/* Show controls when active class is added */
media-control-bar.active {
  opacity: 1;
  visibility: visible;
}

/* Control element spacing */
media-mute-button,
media-time-display {
  margin-right: 10px;
}

/* Time range (scrubber) styling */
media-time-range {
  flex-grow: 1;
  margin: 0 10px;
  --media-range-track-height: 5px;
  --media-range-thumb-height: 14px;
  --media-range-thumb-width: 14px;
  --media-range-track-background: rgba(255, 255, 255, 0.3);
  --media-range-track-progress-background: var(--tribute-white);
  --media-control-hover-background: transparent;
}

/* Hide media controls in overview mode */
.overview media-control-bar {
  display: none !important;
}

/* Make sure bottom-left controls remain visible in overview */
.overview .top-right-controls {
  opacity: 1 !important;
  visibility: visible !important;
}

/* ===== Content Rotation Support ===== */
.rotated-media {
  transform-origin: center center;
}

/* Specific rotation angles */
.rotated-media[data-rotation-index="1"] {
  /* 90deg clockwise rotation */
  transform: rotate(90deg);
}

.rotated-media[data-rotation-index="2"] {
  /* 180deg rotation */
  transform: rotate(180deg);
}

.rotated-media[data-rotation-index="3"] {
  /* 270deg clockwise rotation (90deg counterclockwise) */
  transform: rotate(-90deg);
}

/* Ensure videos and poster images remain visible when rotated */
video.rotated-media,
media-poster-image.rotated-media {
  min-width: 1px;
  min-height: 1px;
}

/* Keep controls unrotated when video elements inside are rotated */
media-controller .rotated-media ~ media-control-bar,
media-controller .rotated-media + media-control-bar {
  transform: none !important;
}

/* ===== Unmute Tooltip ===== */
.unmute-tooltip {
  position: absolute;
  top: 64px;
  left: 10px;
  background-color: white;
  color: #333;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 14px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  z-index: 2000;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
  font-family: 'Figree', Helvetica, sans-serif;
  max-width: 150px;
  text-align: center;
  white-space: normal;
}

.unmute-tooltip.visible {
  opacity: 1;
}

.unmute-tooltip:after {
  content: "";
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-bottom: 8px solid white;
}

/* ===== Video Background Enhancement ===== */
/* Container for enhanced video slides */
.enhanced-video-container {
  position: relative;
  z-index: 1;
  background-color: transparent !important;
}

/* Ensure video and poster are properly sized and positioned */
.enhanced-video-container video[slot="media"],
.enhanced-video-container media-poster-image {
  position: relative;
  z-index: 2;
  background-color: transparent;
}

/* Background blur container */
.video-background-blur {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  overflow: hidden;
  background-color: #000;
}

/* Background blur image */
.video-background-blur > div {
  position: absolute;
  top: 0%;
  left: 0%;
  width: 100%;
  height: 100%;
  background-size: cover;
  background-position: center;
  filter: blur(20px) brightness(0.75);
  transform: scale(1.1);
  opacity: 0.75;
}

/* Adjust video container to maintain aspect ratio but allow letterboxing to be filled */
.reveal .slides section.video-slide {
  background-color: transparent !important;
}

/* ===== Mobile Optimizations ===== */
@media (max-width: 767px) {
  .reveal .slides section {
    width: 100% !important;
    border-radius: 0;
  }

  .img-container,
  .title-container,
  .reveal .img-container,
  .reveal .title-container,
  .reveal video {
    max-width: 100%;
    height: auto !important;
  }

  media-control-bar {
    height: 36px;
    margin-bottom: 0;
  }
  
  media-mute-button {
    min-width: 40px;
    min-height: 40px;
  }
  
  .top-right-controls {
    right: auto;
    left: 15px;
  }
  
  .overview-button,
  .mute-button,
  .fullscreen-button {
    width: 30px;
    height: 30px;
    padding: 5px;
  }

  .overview .slides {
    aspect-ratio: 16 / 9;
    height: auto !important;
  }

  .overview .slides section {
    width: auto !important;
    height: auto !important;
  }

  .play-button, .pause-button {
    width: 60px;
    height: 60px;
  }
  
  .play-button svg, .pause-button svg {
    width: 30px;
    height: 30px;
  }

  .reveal:not(.has-vertical-slides) .controls .navigate-left,
  .reveal[data-navigation-mode=linear].has-horizontal-slides .navigate-left {
    bottom: 1.2em;
    right: 3.5em;
  }

  .reveal:not(.has-vertical-slides) .controls .navigate-right,
  .reveal[data-navigation-mode=linear].has-horizontal-slides .navigate-right {
    bottom: .5em;
  }

  .reveal .controls {
    top: 15px;
    right: 15px;
    left: auto;
    bottom: auto;
    width: 44px;
    height: 34px;
  }

  .reveal .controls .navigate-left,
  .reveal .controls .navigate-right,
  .controls-arrow {
    width: 22px;
    height: 34px;
  }

  .reveal .controls .navigate-right {
    right: 0;
  }

  .reveal .controls .controls-arrow::after, .reveal .controls .controls-arrow::before {
    width: 1.3em;
    height: 0.3em;
  }

  .video-background-blur > div {
    filter: blur(15px) brightness(0.5);
  }
}

/* ===== Animations ===== */
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== Custom Reveal.js Transitions ===== */

