/* General resets */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --primary-color: #ff5722;
  --progress-color: #ff5722;
  --buffered-color: rgba(255, 255, 255, 0.3);
  --overlay-bg: rgba(0, 0, 0, 0.5);
  --control-bg: rgba(15, 15, 15, 0.85);
  --highlight-color: #fff;
  --control-radius: 8px;
  --control-spacing: 12px;
  --slider-height: 5px;
  --slider-thumb-size: 14px;
  --transition-speed: 0.3s;
}

body {
  background-color: #000;
  color: #fff;
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, Oxygen, Ubuntu, sans-serif;
  overflow: hidden;
  touch-action: manipulation;
}

#playerContainer {
  position: relative;
  max-width: 100%;
  width: 100%;
  height: 100vh;
  background-color: #000;
  overflow: hidden;
}

/* Video element styles */
#videoPlayer {
  width: 100%;
  height: 100%;
  background-color: #000;
  object-fit: contain;
  touch-action: none;
}

/* Enhanced start overlay */
#startOverlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(5px);
  z-index: 10;
  cursor: pointer;
}

.start-button-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
  animation: pulse 2s infinite;
  padding: 30px;  
}

.start-button-container span {
  font-size: 18px;
  font-weight: 500;
  letter-spacing: 0.5px;
  color: #fff;
  text-shadow: 0 0 10px rgba(255, 87, 34, 0.5);
}

.play-icon-svg {
  width: 80px;
  height: 80px;
  fill: var(--primary-color);
  filter: drop-shadow(0 0 10px rgba(255, 87, 34, 0.5));
  transition: transform 0.3s ease;
}

.start-button-container:hover .play-icon-svg {
  transform: scale(1.1);
}

@keyframes pulse {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.05);
    opacity: 0.9;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* Overlay styles */
#overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 24px;
  z-index: 3;
  transition: opacity var(--transition-speed) ease;
}

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

/* Error message styles */
.error-message {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 15px 20px;
  border-radius: 8px;
  font-size: 16px;
  max-width: 80%;
  text-align: center;
  z-index: 100;
}

/* Improved controls styling */
#controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  background: linear-gradient(transparent, var(--control-bg));
  z-index: 4;
  transition: opacity var(--transition-speed) ease, transform var(--transition-speed) ease;
  touch-action: manipulation;
}

/* Top controls with title */
#topControls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  width: 100%;
}

.video-title {
  font-size: 16px;
  font-weight: 600;
  max-width: 70%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--primary-color);
  text-shadow: 0 0 5px rgba(255, 87, 34, 0.3);
}

.top-actions {
  display: flex;
  gap: 8px;
}

/* Progress bar enhancements */
#progressContainer {
  position: relative;
  width: 100%;
  height: 20px;
  display: flex;
  align-items: center;
  cursor: pointer;
}

#progressBar {
  position: absolute;
  top: 50%;
  left: 0;
  width: 100%;
  height: var(--slider-height);
  background-color: var(--buffered-color);
  border-radius: 10px;
  transform: translateY(-50%);
  overflow: hidden;
}

#progressIndicator {
  position: absolute;
  height: 100%;
  width: 0;
  background-color: var(--progress-color);
  border-radius: 10px;
  transition: width 0.1s linear;
}

#bufferedProgress {
  position: absolute;
  top: 50%;
  left: 0;
  height: var(--slider-height);
  width: 0;
  background-color: var(--buffered-color);
  border-radius: 10px;
  transform: translateY(-50%);
}

#progressHover {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

/* Hide default slider appearance but keep functionality */
#seekBar {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 20px;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  outline: none;
  z-index: 1;
  margin: 0;
  opacity: 0;
}

/* Main controls area */
#mainControls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 16px 16px;
}

#leftControls, #rightControls {
  display: flex;
  align-items: center;
  gap: var(--control-spacing);
}

/* Time display enhancement */
.time-display {
  display: flex;
  align-items: center;
  font-size: 14px;
  font-weight: 500;
  color: white;
  gap: 4px;
  margin-left: 6px;
}

.time-separator {
  opacity: 0.7;
}

/* Button styling */
#controls button {
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  transition: background-color 0.2s ease;
}

#controls button:hover {
  background-color: rgba(255,255,255,0.1);
}

#controls button:active {
  transform: scale(0.95);
}

/* Material icon button styles */
.material-icons-round {
  font-size: 24px;
  color: white;
}

/* Enhanced settings menu */
.settings-menu {
  position: absolute;
  bottom: 60px;
  right: 10px;
  background: rgba(28, 28, 28, 0.95);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--control-radius);
  padding: 12px;
  opacity: 0;
  transform: translateY(10px);
  transition: all var(--transition-speed) ease;
  z-index: 6;
  width: 220px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

.settings-menu.visible {
  opacity: 1;
  transform: translateY(0);
}

.settings-header {
  font-size: 16px;
  font-weight: 600;
  padding-bottom: 10px;
  margin-bottom: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  color: var(--highlight-color);
}

.settings-section {
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.setting-label {
  font-size: 14px;
  opacity: 0.9;
}

.select-wrapper {
  position: relative;
  width: 120px;
}

.settings-menu select {
  width: 100%;
  background: rgba(255,255,255,0.1);
  border: none;
  border-radius: 4px;
  padding: 8px 30px 8px 12px;
  color: white;
  font-size: 14px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  outline: none;
}

.settings-menu select:focus {
  background: rgba(255,255,255,0.2);
  box-shadow: 0 0 0 2px rgba(255, 87, 34, 0.3);
}

.select-arrow {
  position: absolute;
  right: 5px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  font-size: 18px !important;
  color: var(--primary-color);
}

/* Toggle switch for loop option */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 20px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(255,255,255,0.2);
  transition: .4s;
  border-radius: 34px;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  transition: .4s;
  border-radius: 50%;
}

input:checked + .toggle-slider {
  background-color: var(--primary-color);
}

input:checked + .toggle-slider:before {
  transform: translateX(20px);
}

/* Ensure controls stay visible when locked */
#controls.locked {
  pointer-events: none;
}

#controls.locked button:not(#lockBtn) {
  opacity: 0.5;
  pointer-events: none;
}

#lockBtn {
  pointer-events: auto !important;
  opacity: 1 !important;
}

/* Gesture indicator styles */
#gestureIndicator {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--overlay-bg);
  border-radius: 50%;
  width: 80px;
  height: 80px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 5;
  animation: fadeInOut 0.5s ease-in-out;
}

#gestureIcon {
  width: 40px;
  height: 40px;
  fill: white;
}

#gestureText {
  font-size: 14px;
  margin-top: 5px;
  font-weight: bold;
}

/* Seek indicators with improved styling */
.seek-indicator {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: var(--overlay-bg);
  border-radius: 50%;
  width: 80px;
  height: 80px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  animation: fadeInOut 0.5s ease-in-out;
  z-index: 5;
}

.seek-indicator.forward {
  right: 20%;
}

.seek-indicator.backward {
  left: 20%;
}

.seek-indicator .material-icons-round {
  font-size: 36px;
}

.seek-indicator .seek-time {
  font-size: 14px;
  margin-top: 4px;
  font-weight: bold;
}

@keyframes fadeInOut {
  0% {
    opacity: 0;
    transform: translateY(-50%) scale(0.8);
  }
  50% {
    opacity: 1;
    transform: translateY(-50%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateY(-50%) scale(0.8);
  }
}

/* Thumbnail preview on hover */
#seekPreview {
  position: absolute;
  bottom: 60px;
  transform: translateX(-50%);
  background: var(--overlay-bg);
  border-radius: var(--control-radius);
  padding: 4px;
  z-index: 7;
}

.preview-time {
  text-align: center;
  font-size: 14px;
  padding: 2px 8px;
}

/* Chapter markers */
#chapterMarkers {
  position: absolute;
  bottom: 40px;
  left: 16px;
  background: var(--overlay-bg);
  border-radius: var(--control-radius);
  padding: 6px 12px;
  z-index: 7;
  transition: opacity 0.3s ease;
}

.chapter-title {
  font-size: 14px;
  font-weight: 500;
}

/* On-screen control buttons for forward/backward */
.on-screen-controls {
  position: absolute;
  top: 50%;
  width: 100%;
  display: flex;
  justify-content: space-between;
  padding: 0 15%;
  z-index: 3;
  pointer-events: none;
  transform: translateY(-50%);
  opacity: 1;
  transition: opacity var(--transition-speed) ease;
}

.on-screen-button {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  cursor: pointer;
  border: none;
  opacity: 0.7;
  transition: opacity 0.3s ease, transform 0.2s ease;
}

.on-screen-button:hover, .on-screen-button:focus {
  opacity: 1;
  transform: scale(1.1);
}

.on-screen-button .material-icons-round {
  font-size: 30px;
}

/* Improve fullscreen behavior */
:fullscreen #playerContainer,
:-webkit-full-screen #playerContainer {
  width: 100vw;
  height: 100vh;
  background: #000;
}

:fullscreen #videoPlayer,
:-webkit-full-screen #videoPlayer {
  width: 100%;
  height: 100%;
}

/* Mobile optimizations */
@media (max-width: 768px) {
  :root {
    --control-spacing: 8px;
    --slider-height: 4px;
    --slider-thumb-size: 12px;
  }
  
  #controls button {
    width: 34px;
    height: 34px;
  }
  
  .material-icons-round {
    font-size: 20px;
  }
  
  .video-title {
    font-size: 14px;
    max-width: 60%;
  }
  
  .time-display {
    font-size: 12px;
  }
  
  #mainControls {
    padding: 3px 12px 12px;
  }
  
  #topControls {
    padding: 8px 12px;
  }
  
  .on-screen-controls {
    padding: 0 5%;
  }
  
  .on-screen-button {
    width: 45px;
    height: 45px;
    opacity: 0.8;
  }
  
  .on-screen-button .material-icons-round {
    font-size: 22px;
  }
  
  .start-button-container .play-icon-svg {
    width: 50px;
    height: 50px;
  }
  
  .start-button-container span {
    font-size: 14px;
  }
}

@media (max-width: 480px) {
  #controls button {
    width: 32px;
    height: 32px;
  }
  
  .material-icons-round {
    font-size: 18px;
  }
  
  #leftControls, #rightControls {
    gap: 4px;
  }
  
  .video-title {
    max-width: 50%;
    font-size: 13px;
  }
  
  .time-display {
    font-size: 11px;
  }
  
  .on-screen-button {
    width: 40px;
    height: 40px;
  }
  
  .on-screen-button .material-icons-round {
    font-size: 20px;
  }
}

/* Fullscreen specific styles */
:fullscreen #controls {
  padding-bottom: env(safe-area-inset-bottom);
}

:fullscreen .settings-menu {
  bottom: calc(70px + env(safe-area-inset-bottom));
}