/* ===== CSS Variables ===== */
:root {
  --bg-primary: #0f0f0f;
  --bg-secondary: #1a1a1a;
  --bg-tertiary: #272727;
  --bg-hover: #3f3f3f;

  --text-primary: #f1f1f1;
  --text-secondary: #aaaaaa;
  --text-muted: #717171;

  --accent: #cc0000;
  --accent-hover: #ff0000;
  --accent-glow: rgba(204, 0, 0, 0.3);

  --border: #303030;
  --border-light: #3f3f3f;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  --shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  --transition: 0.2s ease;
}

/* ===== Reset ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  overflow-x: hidden;
  min-height: 100vh;
  -webkit-user-select: none;
  user-select: none;
}

input, textarea {
  -webkit-user-select: text;
  user-select: text;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
  border: none;
  background: none;
  cursor: pointer;
  color: inherit;
}

/* ===== Utility Classes ===== */
.hidden {
  display: none !important;
}

/* ===== Header ===== */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(15, 15, 15, 0.8);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}

.header-content {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 24px;
  max-width: 2000px;
  margin: 0 auto;
}

/* Logo */
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.logo-icon {
  width: 32px;
  height: 32px;
  background: var(--accent);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo-icon svg {
  width: 16px;
  height: 16px;
  color: white;
}

.logo-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.logo-name {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.logo-tld {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--accent);
}

/* Search */
.search-wrapper {
  flex: 1;
  max-width: 600px;
  display: flex;
  margin: 0 auto;
}

.search-box {
  flex: 1;
  display: flex;
  align-items: center;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-full) 0 0 var(--radius-full);
  padding: 0 16px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.search-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-glow);
}

.search-box input {
  flex: 1;
  height: 40px;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
}

.search-box input::placeholder {
  color: var(--text-muted);
}

.clear-btn {
  padding: 4px;
  color: var(--text-secondary);
  transition: color var(--transition);
}

.clear-btn:hover {
  color: var(--text-primary);
}

.clear-btn svg {
  width: 18px;
  height: 18px;
}

.search-btn {
  height: 40px;
  padding: 0 20px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 var(--radius-full) var(--radius-full) 0;
  color: var(--text-secondary);
  transition: background var(--transition), color var(--transition);
}

.search-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.search-btn svg {
  width: 20px;
  height: 20px;
}

/* Header Actions */
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: background var(--transition), color var(--transition);
}

.icon-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.icon-btn svg {
  width: 22px;
  height: 22px;
}

.icon-btn.small svg {
  width: 20px;
  height: 20px;
}

.icon-btn.large {
  width: 56px;
  height: 56px;
}

.icon-btn.large svg {
  width: 28px;
  height: 28px;
}

.icon-btn.xlarge {
  width: 72px;
  height: 72px;
  background: rgba(255, 255, 255, 0.1);
}

.icon-btn.xlarge:hover {
  background: rgba(255, 255, 255, 0.2);
}

.icon-btn.xlarge svg {
  width: 36px;
  height: 36px;
}

.user-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: border-color var(--transition), color var(--transition);
}

.user-btn:hover {
  border-color: var(--accent-glow);
  color: var(--text-primary);
}

.user-btn svg {
  width: 22px;
  height: 22px;
}

/* ===== Category Pills ===== */
.category-bar {
  border-bottom: 1px solid var(--border);
  background: var(--bg-primary);
}

.category-scroll {
  display: flex;
  gap: 8px;
  padding: 12px 24px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.category-scroll::-webkit-scrollbar {
  display: none;
}

.category-pill {
  flex-shrink: 0;
  padding: 8px 16px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  transition: background var(--transition);
  white-space: nowrap;
}

.category-pill:hover {
  background: var(--bg-hover);
}

.category-pill.active {
  background: var(--text-primary);
  color: var(--bg-primary);
}

/* ===== Main Content ===== */
.main-content {
  padding: 24px;
  max-width: 2000px;
  margin: 0 auto;
}

/* ===== Video Grid ===== */
.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 24px;
}

/* Empty State */
.empty-state {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 24px;
  color: var(--text-muted);
}

.empty-state svg {
  width: 64px;
  height: 64px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state p {
  font-size: 16px;
}

/* ===== Video Card ===== */
.video-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  cursor: pointer;
  transition: opacity var(--transition);
}

.video-card:hover {
  opacity: 0.85;
}

.video-thumbnail {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-secondary);
}

.video-thumbnail img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.video-card:hover .video-thumbnail img {
  transform: scale(1.05);
}

.video-duration {
  position: absolute;
  bottom: 8px;
  right: 8px;
  padding: 3px 6px;
  background: rgba(0, 0, 0, 0.85);
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
}

.video-info {
  display: flex;
  gap: 12px;
}

.channel-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--bg-secondary);
  flex-shrink: 0;
  overflow: hidden;
}

.channel-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.video-details {
  flex: 1;
  min-width: 0;
}

.video-title {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
  color: var(--text-primary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 4px;
}

.video-channel {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

.video-meta {
  font-size: 12px;
  color: var(--text-secondary);
}

/* ===== Loading ===== */
#searchLoading {
  display: flex;
  justify-content: center;
  padding: 40px;
}

.spinner-small {
  width: 32px;
  height: 32px;
  border: 3px solid var(--bg-tertiary);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ===== Player Container ===== */
#playerContainer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: #000;
  z-index: 1000;
}

#videoCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* ===== Player Controls ===== */
#playerControls {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.7) 0%,
    transparent 20%,
    transparent 80%,
    rgba(0, 0, 0, 0.9) 100%
  );
  opacity: 1;
  transition: opacity 0.3s ease;
  padding: 16px;
}

#playerControls.hidden {
  opacity: 0;
  pointer-events: none;
}

/* Player Top */
.player-top {
  display: flex;
  align-items: center;
  gap: 12px;
}

.player-title {
  font-size: 16px;
  font-weight: 500;
  color: white;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Player Center */
.player-center {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 32px;
  flex: 1;
}

/* Player Bottom */
.player-bottom {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Progress Bar */
.progress-container {
  display: flex;
  align-items: center;
  gap: 12px;
}

.time {
  font-size: 13px;
  font-weight: 500;
  color: white;
  min-width: 45px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.progress-bar {
  flex: 1;
  height: 5px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
  position: relative;
  cursor: pointer;
  transition: height 0.1s ease;
}

.progress-bar:hover {
  height: 7px;
}

.progress-buffered {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 3px;
  width: 0%;
}

.progress-played {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  width: 0%;
}

.progress-handle {
  position: absolute;
  top: 50%;
  left: 0%;
  width: 14px;
  height: 14px;
  background: var(--accent);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  opacity: 0;
  transition: opacity 0.1s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.progress-bar:hover .progress-handle {
  opacity: 1;
}

/* Controls Row */
.controls-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.controls-left,
.controls-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Volume Slider */
.volume-slider {
  width: 80px;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  background: white;
  border-radius: 50%;
  cursor: pointer;
}

.volume-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: white;
  border-radius: 50%;
  border: none;
  cursor: pointer;
}

/* Loading Overlay */
#loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  z-index: 10;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

#loading p {
  color: white;
  font-size: 14px;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .header-content {
    padding: 8px 16px;
  }

  .logo-text {
    display: none;
  }

  .search-wrapper {
    margin: 0 8px;
  }

  .category-scroll {
    padding: 8px 16px;
  }

  .main-content {
    padding: 16px;
  }

  .video-grid {
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 16px;
  }

  .player-center {
    gap: 24px;
  }

  .icon-btn.large {
    width: 48px;
    height: 48px;
  }

  .icon-btn.xlarge {
    width: 64px;
    height: 64px;
  }
}

@media (max-width: 480px) {
  .video-grid {
    grid-template-columns: 1fr;
  }

  .search-box input {
    font-size: 16px; /* Prevents zoom on iOS */
  }

  .player-title {
    font-size: 14px;
  }

  .volume-slider {
    display: none;
  }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--bg-hover);
}
