:root {
  --bg-color: #111;
  --bg-secondary: #222;
  --text-color: #eee;
  --accent-color: #3498db;
  --border-color: #333;
  --sidebar-width: 320px;
}

* {
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg-color);
  color: var(--text-color);
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation; /* Prevents double-tap zoom on mobile */
}

input {
  user-select: text;
  -webkit-user-select: text;
}

/* Mobile Header */
#mobile-header {
  display: none;
  padding: 10px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  align-items: center;
  justify-content: space-between;
  z-index: 60; /* Ensure above sidebar */
}

#menu-toggle {
  background: none;
  border: none;
  color: white;
  font-size: 24px;
  cursor: pointer;
}

/* Sidebar */
#sidebar {
  width: var(--sidebar-width);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  background: var(--bg-color);
  z-index: 50; /* Increased to be above player controls (20) */
  transition: transform 0.3s ease;
  position: relative;
}

.sidebar-header {
  padding: 10px;
  background: var(--bg-secondary);
  display: flex;
  gap: 5px;
  align-items: center;
}

#main-menu-btn {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#search {
  flex: 1;
  padding: 8px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: #1a1a1a;
  color: #fff;
  font-size: 16px; /* Prevents iOS zoom on focus */
}

#list {
  flex: 1;
  overflow-y: auto;
}

#now-playing {
  background: #000;
  border-top: 1px solid var(--border-color);
  display: none;
}

.list-nav-btns {
  position: absolute;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 30;
}

.list-nav-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent-color);
  color: white;
  border: none;
  box-shadow: 0 2px 5px rgba(0,0,0,0.5);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.8;
}

#list-top-btn {
  background: #e67e22; /* Orange */
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

#list-top-btn.visible {
  opacity: 0.8;
  pointer-events: auto;
}

#list-top-btn.visible:hover {
  opacity: 1;
}

.list-nav-btn:hover {
  opacity: 1;
}

#sidebar.has-player .list-nav-btns {
  bottom: 90px;
}

/* List Items */
.item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 15px;
  cursor: pointer;
  border-bottom: 1px solid var(--bg-secondary);
  transition: background 0.2s;
}

.item:hover {
  background: var(--bg-secondary);
}

.item img {
  width: 24px;
  height: auto;
  border-radius: 2px;
}

.item-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
}

.item-title {
  font-weight: bold;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-info {
  font-size: 12px;
  color: #888;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-info img {
  width: 16px;
  height: auto;
  border-radius: 2px;
}

.fav-btn {
  background: none;
  border: none;
  color: #555;
  cursor: pointer;
  font-size: 1.2em;
  padding: 5px;
}

.fav-btn.active {
  color: gold;
}

.back-btn {
  background: var(--bg-secondary);
  padding: 10px;
  text-align: center;
  cursor: pointer;
  font-weight: bold;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.back-btn:hover {
  background: #333;
}

.favorites-item {
  background: linear-gradient(90deg, rgba(255, 215, 0, 0.1), transparent);
  border-left: 3px solid gold;
}

.remove-btn {
  color: #e74c3c;
  background: none;
  border: none;
  cursor: pointer;
}

/* Main Content */
#content {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
}

.video-container {
  flex: 1;
  background: black;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  position: relative;
}

.live-badge {
  position: absolute;
  top: 20px;
  left: 20px;
  background: rgba(204, 0, 0, 0.9);
  color: white;
  padding: 5px 12px;
  border-radius: 4px;
  font-weight: bold;
  font-size: 14px;
  z-index: 5;
  pointer-events: none;
  box-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

/* Ensure subtitles are visible and above other elements */
video::-webkit-media-text-track-container {
  display: block !important;
  z-index: 100;
}

video {
  width: 100%;
  height: 100%;
  max-height: 100vh;
}

/* Aspect Ratio Modes */
video.fit { object-fit: contain; }
video.fill { object-fit: cover; }
video.stretch { object-fit: fill; }

/* Custom Controls */
.custom-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(transparent, rgba(0,0,0,0.9));
  padding: 40px 15px 15px 15px;
  display: flex;
  align-items: center;
  gap: 15px;
  opacity: 0;
  transition: opacity 0.3s;
  z-index: 20;
}

.video-container:hover .custom-controls,
.video-container.audio-mode .custom-controls {
  opacity: 1;
}

/* Idle State: Hide controls and cursor (Must be AFTER hover to override) */
.video-container.idle {
  cursor: none;
}
.video-container.idle .custom-controls {
  opacity: 0;
}

.control-btn {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  padding: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  width: 36px;
  height: 36px;
}

.control-btn:hover {
  background: rgba(255,255,255,0.2);
  color: var(--accent-color);
}

.volume-slider {
  width: 80px;
  cursor: pointer;
  accent-color: var(--accent-color);
}

/* Context Menu (Sleep Timer) */
.context-menu {
  position: absolute;
  bottom: 70px;
  right: 60px; /* Positioned near the sleep button */
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 5px 0;
  display: none;
  flex-direction: column;
  min-width: 140px;
  z-index: 30;
  box-shadow: 0 5px 15px rgba(0,0,0,0.5);
}
.context-menu.active { display: flex; }
.context-menu-item {
  padding: 10px 15px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
}
.context-menu-item:hover { background: #333; }
.context-menu-item.selected { color: var(--accent-color); font-weight: bold; }

/* Audio Only Mode */
.audio-placeholder {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #111;
  z-index: 10;
}

.video-container.audio-mode .audio-placeholder {
  display: flex;
}

/* Loader */
.loader-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 15;
}
.loader-overlay.active {
  display: flex;
}
.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(255,255,255,0.1);
  border-left-color: var(--accent-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin {
  100% { transform: rotate(360deg); }
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.8);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--bg-secondary);
  padding: 25px;
  border-radius: 8px;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 10px 25px rgba(0,0,0,0.5);
  transform: translateY(20px);
  transition: transform 0.3s;
  border: 1px solid var(--border-color);
}

.modal-overlay.active .modal {
  transform: translateY(0);
}

.modal-btns {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.modal-btn {
  padding: 8px 16px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: bold;
  background: var(--accent-color);
  color: white;
}

.modal-btn.secondary {
  background: #555;
}

/* Mobile Responsive */
@media (max-width: 960px) {
  body {
    flex-direction: column;
  }

  #mobile-header {
    display: flex;
  }

  #sidebar {
    position: fixed;
    top: 50px; /* Height of mobile header */
    bottom: 0;
    left: 0;
    transform: translateX(-100%);
    width: 100%;
  }

  #sidebar.open {
    transform: translateX(0);
  }

  #content {
    height: calc(100vh - 50px);
    height: calc(100dvh - 50px);
  }
  
  .custom-controls {
    opacity: 1; /* Always show controls on mobile when interacting */
  }
}

/* Inputs */
.input-area {
  width: 100%;
  height: 100px;
  background: #222;
  border: 1px solid #333;
  color: #eee;
  padding: 10px;
  box-sizing: border-box;
  resize: vertical;
  max-width: 100%;
  font-size: 16px; /* Prevents iOS zoom */
}

/* Settings Dropdown */
.settings-select {
  background: #111;
  color: white;
  border: 1px solid #333;
  padding: 8px;
  border-radius: 4px;
  font-size: 14px;
  outline: none;
  margin-left: auto;
}
