/* Reset and base styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  background: #000;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}

/* Tile View - Video Selection Screen */
#tile-view {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  display: flex;
  flex-direction: column;
  z-index: 1000;
}

#tile-view.hidden {
  display: none;
}

.tile-header {
  padding: 1rem;
  text-align: center;
  color: white;
  flex-shrink: 0;
}

.tile-header h1 {
  font-size: 1.8rem;
}

/* Tile Grid */
#tile-grid {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.5rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  align-content: start;
  -webkit-overflow-scrolling: touch;
}

/* Individual Tile */
.video-tile {
  position: relative;
  background: #2a2a4a;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  aspect-ratio: 16/9;
}

.video-tile:active {
  transform: scale(0.98);
}

.video-tile.selected {
  box-shadow: 0 0 0 4px #4ecdc4, 0 4px 20px rgba(78, 205, 196, 0.4);
}

.tile-thumbnail {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.tile-title {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0.5rem;
  background: linear-gradient(transparent, rgba(0,0,0,0.8));
  color: white;
  font-size: 0.85rem;
  font-weight: 500;
}

/* Selection Badge */
.selection-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  background: #4ecdc4;
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  color: #1a1a2e;
  font-weight: bold;
  font-size: 1rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.video-tile.selected .selection-badge {
  display: flex;
}

/* Footer with Action Buttons */
.tile-footer {
  padding: 1rem;
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-shrink: 0;
  background: rgba(0,0,0,0.3);
}

.tile-footer button {
  padding: 0.8rem 1.5rem;
  font-size: 1rem;
  border: none;
  border-radius: 25px;
  cursor: pointer;
  font-weight: bold;
  transition: transform 0.2s, opacity 0.2s;
}

.tile-footer button:active {
  transform: scale(0.95);
}

#play-selected-btn {
  background: #4ecdc4;
  color: #1a1a2e;
}

#play-selected-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#play-all-btn {
  background: #ff6b6b;
  color: white;
}

/* Player Container */
#player-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #000;
}

#player-container.hidden {
  display: none;
}

/* Video Element */
#video-player {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

/* Touch Blocking Overlay */
#touch-blocker {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 100;
  background: transparent;
  touch-action: none;
  pointer-events: auto;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* Loading Indicator */
#loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 150;
}

#loading.hidden {
  display: none;
}

.spinner {
  width: 50px;
  height: 50px;
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Safe area insets for notched devices */
@supports (padding: max(0px)) {
  #tile-view {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
  #player-container {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
}

/* Fullscreen styles */
:fullscreen #video-player,
:-webkit-full-screen #video-player {
  width: 100vw;
  height: 100vh;
  object-fit: contain;
}

:fullscreen #touch-blocker,
:-webkit-full-screen #touch-blocker {
  width: 100vw;
  height: 100vh;
}
