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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  overflow: hidden;
  background: #000;
  color: white;
  touch-action: pan-y;
  overscroll-behavior-y: none;
}

/* Video Container */
#video-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh; /* Dynamic viewport height for mobile browsers */
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: height 0.3s ease;
  overscroll-behavior: none;
}

body.controls-visible #video-container {
  height: calc(100vh - 80px);
  height: calc(100dvh - 80px); /* Dynamic viewport height for mobile browsers */
}

#player {
  width: 100%;
  height: 56.25vw; /* 16:9 aspect ratio */
  max-height: 100%;
  transition: opacity 0.3s ease;
}

/* Video transition animations */
#player.slide-out-up {
  animation: slideOutUp 0.4s ease-in-out forwards;
}

#player.slide-out-down {
  animation: slideOutDown 0.4s ease-in-out forwards;
}

#player.slide-in-up {
  animation: slideInUp 0.4s ease-in-out forwards;
}

#player.slide-in-down {
  animation: slideInDown 0.4s ease-in-out forwards;
}

@keyframes slideOutUp {
  from {
    transform: translateY(0);
    opacity: 1;
  }
  to {
    transform: translateY(-100vh);
    opacity: 0;
  }
}

@keyframes slideOutDown {
  from {
    transform: translateY(0);
    opacity: 1;
  }
  to {
    transform: translateY(100vh);
    opacity: 0;
  }
}

@keyframes slideInUp {
  from {
    transform: translateY(100vh);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes slideInDown {
  from {
    transform: translateY(-100vh);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* Loading State */
#loading {
  position: absolute;
  bottom: 33.33%;
  left: 50%;
  transform: translateX(-50%);
  font-size: 18px;
  color: rgba(255, 255, 255, 0.7);
  max-width: 90%;
  text-align: center;
}

#loading.hidden {
  display: none;
}

/* Controls (below video, single row layout) */
#controls {
  position: relative;
  width: 100vw;
  height: 80px;
  padding: 20px 30px;
  background: #000;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 20px;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

#controls.hidden {
  transform: translateY(100%);
  opacity: 0;
  pointer-events: none;
}

/* Video Info (left side) */
#video-info {
  flex: 1;
  min-width: 0;
  max-width: 35%;
  text-align: left;
}

#video-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 2px;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#video-stats {
  font-size: 12px;
  opacity: 0.7;
  color: #ddd;
  white-space: nowrap;
}

/* Action Buttons Container (right side) */
.action-buttons {
  display: flex;
  gap: 12px;
  flex-shrink: 0;
  justify-content: flex-end;
}

/* Heart Button */
#heart-btn {
  width: 50px;
  height: 50px;
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  font-size: 24px;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

#heart-btn:active {
  transform: scale(0.9);
}

#heart-btn.saved {
  background: rgba(255, 50, 80, 0.9);
  border-color: rgba(255, 50, 80, 1);
  color: white;
}

/* Library Button */
#library-btn {
  width: 50px;
  height: 50px;
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  padding: 12px;
}

#library-btn svg {
  width: 100%;
  height: 100%;
  color: white;
}

#library-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(1.05);
}

#library-btn:active {
  transform: scale(0.9);
}

/* Autoplay Button (in center with nav buttons) */
#autoplay-btn {
  width: 50px;
  height: 50px;
  padding: 0;
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

#autoplay-btn svg {
  width: 18px;
  height: 18px;
  color: white;
}

#autoplay-btn .play-icon {
  display: block;
  padding-left: 2px;
}

#autoplay-btn .pause-icon {
  display: none;
}

#autoplay-btn.active .play-icon {
  display: none;
}

#autoplay-btn.active .pause-icon {
  display: block;
}

#autoplay-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(1.05);
}

#autoplay-btn:active {
  transform: scale(0.9);
}

/* Fade Controls Button (fixed at bottom right) */
#fade-btn {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 50px;
  height: 50px;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(10px);
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  padding: 14px;
  z-index: 100;
}

body.controls-visible #fade-btn {
  bottom: 100px;
}

#fade-btn svg {
  width: 100%;
  height: 100%;
  color: white;
  transition: transform 0.3s ease;
}

#fade-btn.rotated svg {
  transform: rotate(180deg);
}

#fade-btn:hover {
  background: rgba(0, 0, 0, 0.8);
  transform: scale(1.05);
}

#fade-btn:active {
  transform: scale(0.9);
}

/* Modal Base */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.modal.show {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: #1a1a1a;
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
  padding: 20px;
  transform: translateY(100%);
  transition: transform 0.3s ease;
}

.modal.show .modal-content {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-header h2 {
  font-size: 22px;
  font-weight: 600;
}

.close-btn {
  background: none;
  border: none;
  font-size: 28px;
  color: white;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}


/* Saved Videos List */
.video-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.video-item {
  display: flex;
  gap: 12px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  padding: 10px;
  cursor: pointer;
  transition: background 0.2s ease;
}

.video-item:active {
  background: rgba(255, 255, 255, 0.1);
}

.video-item img {
  width: 120px;
  height: 68px;
  object-fit: cover;
  border-radius: 6px;
}

.video-item-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.video-item-title {
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.video-item-stats {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: rgba(255, 255, 255, 0.5);
}

.empty-state-icon {
  font-size: 48px;
  margin-bottom: 10px;
}

/* Welcome Modal Specific Styles */
.welcome-content {
  max-width: 500px;
}

.welcome-body {
  padding: 10px 0;
}

.welcome-stat {
  font-size: 18px;
  font-weight: 600;
  color: #FF0000;
  margin-bottom: 20px;
  line-height: 1.5;
}

.welcome-text {
  font-size: 15px;
  line-height: 1.7;
  color: rgba(255, 255, 255, 0.85);
  margin-bottom: 16px;
}

.welcome-btn {
  width: 100%;
  padding: 14px 24px;
  margin-top: 20px;
  background: #FF0000;
  border: none;
  border-radius: 8px;
  color: white;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.welcome-btn:hover {
  background: #CC0000;
  transform: translateY(-1px);
}

.welcome-btn:active {
  transform: translateY(0);
}

/* API Key Setup Notice */
#api-notice {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 20px;
}

#api-notice.hidden {
  display: none;
}

.notice-content {
  background: #1a1a1a;
  border-radius: 12px;
  padding: 30px;
  max-width: 500px;
  text-align: center;
}

.notice-content h2 {
  margin-bottom: 15px;
  color: #3b82f6;
}

.notice-content p {
  margin-bottom: 15px;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.8);
}

.notice-content input {
  width: 100%;
  padding: 12px;
  margin: 15px 0;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  color: white;
  font-size: 14px;
}

.notice-content a {
  color: #3b82f6;
  text-decoration: none;
}

.notice-content a:hover {
  text-decoration: underline;
}

/* Navigation Buttons Container (center) */
.nav-buttons {
  display: flex;
  gap: 12px;
  flex-shrink: 0;
  justify-content: center;
  align-items: center;
}

/* Navigation Buttons */
.nav-btn {
  min-width: 80px;
  height: 44px;
  padding: 0 24px;
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 22px;
  font-size: 16px;
  font-weight: 500;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s ease;
  user-select: none;
}

/* Play/Pause Button Special Styling */
#play-pause-btn {
  min-width: 60px;
  padding: 0 18px;
}

#play-pause-btn svg {
  width: 18px;
  height: 18px;
}

#play-pause-btn .play-icon {
  display: block;
}

#play-pause-btn .pause-icon {
  display: none;
}

#play-pause-btn.playing .play-icon {
  display: none;
}

#play-pause-btn.playing .pause-icon {
  display: block;
}

.nav-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.3);
  transform: scale(1.05);
}

.nav-btn:active {
  transform: scale(0.95);
}

.nav-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Mobile Responsive Styles */
@media (max-width: 768px) {
  /* Reduce control section height on mobile */
  #controls {
    height: auto;
    padding: 12px 16px;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    gap: 12px;
  }

  /* Adjust video container height for smaller controls */
  body.controls-visible #video-container {
    height: calc(100vh - 140px); /* Approximate height for mobile controls */
    height: calc(100dvh - 140px); /* Dynamic viewport height for mobile browsers */
  }

  /* Reorder grid: Nav buttons first, then video info, then action buttons */
  .nav-buttons {
    order: 1;
    justify-content: center;
    width: 100%;
  }

  #video-info {
    order: 2;
    max-width: 100%;
    text-align: center;
  }

  .action-buttons {
    order: 3;
    justify-content: center;
    width: 100%;
  }

  /* Hide fade/toggle button on mobile - controls always visible */
  #fade-btn {
    display: none;
  }

  /* Prevent controls from being hidden on mobile */
  #controls.hidden {
    transform: none;
    opacity: 1;
    pointer-events: auto;
  }

  /* Adjust button sizes for mobile */
  .nav-btn {
    min-width: 70px;
    height: 40px;
    font-size: 14px;
    padding: 0 20px;
  }

  #video-title {
    font-size: 14px;
  }

  #video-stats {
    font-size: 11px;
  }

  /* Full height welcome modal on mobile */
  #welcome-modal .modal-content {
    max-height: 100vh;
    max-height: 100dvh; /* Dynamic viewport height for mobile browsers */
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile browsers */
    border-radius: 0;
    display: flex;
    flex-direction: column;
  }

  #welcome-modal .welcome-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow-y: auto;
  }
}
