/* Custom styles for subtitle items - override to work with Tailwind classes */
.subtitle-item {
  /* Override specific styles while preserving Tailwind layout classes */
  transition: all 0.2s ease;
  border-radius: 0.5rem !important;
  border: 2px solid transparent;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  position: relative;
}

.subtitle-item:hover {
  border-color: #3b82f6;
  transform: translateY(-0.125rem);
  box-shadow: 0 2px 4px rgba(59, 130, 246, 0.1);
}

@media (prefers-color-scheme: dark) {
  .subtitle-item:hover {
    border-color: #3b82f6;
    background-color: #374151 !important;
    transform: translateY(-0.125rem);
    box-shadow: 0 2px 4px rgba(59, 130, 246, 0.3);
  }
}

.subtitle-item.active {
  background-color: #3b82f6 !important;
  color: #ffffff !important;
  border-color: #2563eb;
  transform: scale(1.02);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.subtitle-item.active:hover {
  box-shadow: 0 6px 12px rgba(59, 130, 246, 0.2);
}

/* Update text colors for active state */
.subtitle-item.active .text-xs.text-gray-500 {
  color: #fde047 !important;
}

.subtitle-item.active .text-sm.text-gray-800 {
  color: #ffffff !important;
}

/* Legacy support for old structure */
.subtitle-item.active .subtitle-time {
  color: #fde047;
}

.subtitle-time {
  font-weight: 600;
  color: #3b82f6;
  margin-right: 0.5rem;
  font-size: 0.75rem;
  font-family:
    ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
    "Courier New", monospace;
}

.subtitle-text {
  flex: 1;
  word-break: break-word;
}

/* Custom scrollbar styling (Tailwind doesn't have exact equivalents) */
.subtitle-list::-webkit-scrollbar {
  width: 8px;
}

.subtitle-list::-webkit-scrollbar-track {
  background: #e5e7eb;
  border-radius: 0.25rem;
}

.subtitle-list::-webkit-scrollbar-thumb {
  background: #9ca3af;
  border-radius: 0.25rem;
}

.subtitle-list::-webkit-scrollbar-thumb:hover {
  background: #6b7280;
}

/* Loading spinner (not easily achievable with Tailwind utilities) */
.loading {
  @apply flex items-center justify-center p-5 text-gray-600;
}

.loading::after {
  content: "";
  width: 20px;
  height: 20px;
  margin-left: 10px;
  border: 2px solid #f3f3f3;
  border-top: 2px solid #007acc;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* Error and success messages */
.error {
  background-color: #fef2f2;
  border: 1px solid #fca5a5;
  color: #b91c1c;
  padding: 0.75rem;
  border-radius: 0.375rem;
  margin: 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
}

.success {
  background-color: #f0fdf4;
  border: 1px solid #86efac;
  color: #166534;
  padding: 0.75rem;
  border-radius: 0.375rem;
  margin: 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
}

/* Responsive adjustments that need specific handling */
@media (max-width: 1024px) {
  .subtitle-item {
    padding: 0.625rem;
    font-size: 0.8125rem;
  }

  .subtitle-time {
    font-size: 0.75rem;
  }
}

@media (max-width: 768px) {
  .subtitle-item {
    padding: 0.75rem;
    font-size: 0.875rem;
    border-radius: 0.375rem;
    margin-bottom: 0.25rem;
  }

  .subtitle-time {
    font-size: 0.75rem;
    margin-right: 0.375rem;
  }

  .no-subtitles {
    padding: 1.875rem;
  }
}

@media (max-width: 480px) {
  .subtitle-item {
    padding: 0.5rem;
    font-size: 0.75rem;
    border-radius: 0.25rem;
  }

  .subtitle-time {
    font-size: 0.625rem;
    margin-right: 0.375rem;
    font-family:
      ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
      "Courier New", monospace;
  }

  .subtitle-item.active {
    transform: scale(1.01);
  }
}

/* Body background that was in original CSS */
body {
  @apply bg-gray-100;
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.6;
}

/* Full screen styles for video player page */
body.video-player-page {
  margin: 0;
  padding: 0;
  height: 100vh;
  overflow: hidden;
}

body.video-player-page > main {
  max-width: 100%;
  width: 100%;
  flex: 1;
  padding: 0;
  margin: 0;
}

/* 全屏模式下的样式调整 */
.video-subtitle-app-container:fullscreen {
  background-color: #000 !important;
}

.video-subtitle-app-container:fullscreen header {
  display: none !important;
}

.video-subtitle-app-container:fullscreen .bg-white {
  background-color: #000 !important;
  border: none !important;
}

.video-subtitle-app-container:fullscreen .grid {
  grid-template-columns: 1fr !important;
  height: 100vh !important;
}

.video-subtitle-app-container:fullscreen #video-player-container {
  max-height: 100vh !important;
  height: 100vh !important;
  width: 100vw !important;
}

.video-subtitle-app-container:fullscreen #videoPlayer {
  max-height: 100vh !important;
  height: 100vh !important;
  width: 100vw !important;
  object-fit: contain !important;
}

.video-subtitle-app-container:fullscreen #subtitle-container {
  display: none !important;
}

/* 移动端全屏支持 */
@supports (-webkit-touch-callout: none) {
  /* iOS Safari */
  .video-subtitle-app-container:fullscreen {
    padding: 0 !important;
    margin: 0 !important;
  }

  .video-subtitle-app-container:fullscreen #video-player-container {
    padding-top: env(safe-area-inset-top) !important;
    padding-bottom: env(safe-area-inset-bottom) !important;
  }
}

/* Webkit全屏API支持 */
.video-subtitle-app-container:-webkit-full-screen {
  background-color: #000 !important;
}

.video-subtitle-app-container:-webkit-full-screen header {
  display: none !important;
}

.video-subtitle-app-container:-webkit-full-screen .bg-white {
  background-color: #000 !important;
  border: none !important;
}

.video-subtitle-app-container:-webkit-full-screen .grid {
  grid-template-columns: 1fr !important;
  height: 100vh !important;
}

.video-subtitle-app-container:-webkit-full-screen #video-player-container {
  max-height: 100vh !important;
  height: 100vh !important;
  width: 100vw !important;
}

.video-subtitle-app-container:-webkit-full-screen #videoPlayer {
  max-height: 100vh !important;
  height: 100vh !important;
  width: 100vw !important;
  object-fit: contain !important;
}

.video-subtitle-app-container:-webkit-full-screen #subtitle-container {
  display: none !important;
}

/* Plyr video player container styles */
#video-player-container {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #000;
  min-height: 300px;
  max-height: 70vh; /* 限制最大高度，防止竖屏视频过度拉伸 */
  flex: 1;
  min-width: 0; /* 允许容器收缩 */
  aspect-ratio: auto; /* 允许自然宽高比 */
}

/* 移动端竖屏视频优化 */
@media (max-width: 768px) and (orientation: portrait) {
  #video-player-container {
    min-height: 500px;
  }

  #videoPlayer {
    max-height: 60vh;
  }

  .plyr__video-wrapper {
    max-height: 60vh;
  }
}

/* md 断点优化 (768px 及以上，包含 iPad mini 竖屏) */
@media (min-width: 768px) and (orientation: portrait) {
  #video-player-container {
    max-height: none; /* md 断点竖屏调整高度，移除固定高度让 flex 布局控制 */
    min-height: 250px;
  }

  #videoPlayer {
    max-height: none; /* 移除固定高度 */
  }

  .plyr__video-wrapper {
    max-height: none; /* 移除固定高度 */
  }
}

/* 超小屏幕优化 */
@media (max-width: 480px) {
  #video-player-container {
    min-height: 50vh;
    /*min-height: 150px;*/
  }

  #videoPlayer {
    max-height: 50vh;
  }
}

/* 为视频控件区域预留空间 */
.plyr--video .plyr__controls {
  padding-bottom: 20px; /* 确保控件不会遮挡视频内容 */
}

#videoPlayer {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  max-height: 70vh; /* 限制最大高度，防止竖屏视频过度拉伸 */
  background-color: #000; /* 确保没有视频时显示黑色背景 */
  object-fit: contain; /* 保持视频比例并适应容器 */
}

/* 确保Plyr播放器在没有视频源时也保持正确尺寸 */
.plyr {
  width: 100%;
  height: 100%;
  min-height: 300px;
}

.plyr__video-wrapper {
  min-height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  flex: 1;
  height: auto !important; /* 覆盖plyr的固定高度 */
}

/* 当没有视频源时，保持容器的样式 */
video#videoPlayer:not([src]):not([srcset]) {
  background-color: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 300px;
}

/* 优化视频在容器中的显示效果 */
.plyr--video .plyr__video-wrapper video {
  object-fit: contain !important; /* 强制视频适应容器同时保持宽高比 */
  width: 100% !important;
  height: 100% !important;
}

/* 主播放器布局的容器统一高度 */
.video-subtitle-app-container .grid {
  /* 确保视频播放器和字幕列表高度一致 */
  align-items: stretch;
}

/* md 断点竖屏模式下的容器高度控制 */
@media (min-width: 768px) and (orientation: portrait) {
  .video-subtitle-app-container .grid {
    /* 限制网格容器高度，确保视频、字幕和状态栏都能完整展示 */
    max-height: calc(100vh - 180px); /* 减去头部、状态栏和间距 */
    min-height: 0;
  }

  /* 视频播放器容器 - 分配更多空间 */
  .video-subtitle-app-container .lg\\:col-span-8 {
    flex: 3; /* 视频占 60% 空间 */
    min-height: 0;
    max-height: none;
  }

  /* 字幕容器 - 分配较少空间 */
  .video-subtitle-app-container .lg\\:col-span-4 {
    flex: 2; /* 字幕占 40% 空间 */
    min-height: 0;
    max-height: none;
  }

  /* 视频播放器容器 */
  #video-player-container {
    max-height: none;
    flex: 1;
  }

  /* 字幕容器 */
  #subtitle-container {
    max-height: none;
    flex: 1;
  }

  /* 字幕列表内容区域 */
  #subtitleList {
    max-height: none;
    flex: 1;
    min-height: 0;
  }
}

/* 视频播放器和字幕列表容器高度同步 */
.video-subtitle-app-container .lg\\:col-span-8,
.video-subtitle-app-container .lg\\:col-span-4 {
  /* 两个容器都使用相同的高度约束 */
  min-height: 300px;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
}

@media (max-width: 768px) and (orientation: portrait) {
  .video-subtitle-app-container .lg\\:col-span-8,
  .video-subtitle-app-container .lg\\:col-span-4 {
    min-height: 200px;
    max-height: 60vh;
  }
}

/* md 断点优化 (768px 及以上，包含 iPad mini 竖屏) */
@media (min-width: 768px) and (orientation: portrait) {
  .video-subtitle-app-container .lg\\:col-span-8,
  .video-subtitle-app-container .lg\\:col-span-4 {
    min-height: 250px;
    max-height: none; /* 移除 max-height，让 flex 布局控制 */
  }
}

@media (max-width: 480px) {
  .video-subtitle-app-container .lg\\:col-span-8,
  .video-subtitle-app-container .lg\\:col-span-4 {
    min-height: 150px;
    max-height: 50vh;
  }
}

/* 字幕列表容器内部高度控制 */
#subtitle-container {
  /* 确保与视频播放器相同的高度约束 */
  min-height: 300px;
  max-height: 70vh;
}

/* 字幕列表内容区域高度控制 */
#subtitleList {
  /* 计算高度：总高度减去头部高度 */
  height: calc(100% - 60px); /* 减去头部区域高度 */
  min-height: 240px; /* 300px - 60px */
  max-height: calc(70vh - 60px);
}

@media (max-width: 768px) and (orientation: portrait) {
  #subtitle-container {
    min-height: 200px;
    max-height: 40vh;
  }

  #subtitleList {
    min-height: 140px; /* 200px - 60px */
    max-height: calc(60vh - 60px);
  }
}

/* md 断点优化 (768px 及以上，包含 iPad mini 竖屏) */
@media (min-width: 768px) and (orientation: portrait) {
  #subtitle-container {
    min-height: 250px;
    max-height: none; /* 移除 max-height，让 flex 布局控制 */
  }

  #subtitleList {
    min-height: 190px; /* 250px - 60px */
    max-height: none; /* 移除 max-height，让 flex 布局控制 */
  }
}

@media (max-width: 480px) {
  #subtitle-container {
    min-height: 150px;
    max-height: 50vh;
  }

  #subtitleList {
    min-height: 90px; /* 150px - 60px */
    max-height: calc(50vh - 60px);
  }
}
