/* KidsTube - Modern CSS with tokens, utilities & components */

/* ============================================
   CSS CUSTOM PROPERTIES (Design Tokens)
   ============================================ */
:root {
  /* Colors - Dark theme default */
  --bg: #0f1115;
  --bg-elev: #151924;
  --bg-card: #171b26;
  --border: #232838;
  --text: #e7eaf0;
  --text-muted: #aab2c0;
  
  /* Accent colors */
  --accent-red: #ff4b4b;
  --accent-blue: #4bb6ff;
  --accent-green: #4bff9a;
  --accent-yellow: #ffca3a;
  --accent-purple: #9b59b6;
  
  /* Spacing scale (4px base) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;
  
  /* Border radius */
  --radius-s: 8px;
  --radius-m: 12px;
  --radius-l: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;
  
  /* Shadows */
  --shadow-1: 0 2px 6px rgba(0, 0, 0, 0.25);
  --shadow-2: 0 4px 12px rgba(0, 0, 0, 0.3);
  --shadow-3: 0 10px 30px rgba(0, 0, 0, 0.35);
  
  /* Transitions */
  --transition-fast: 150ms;
  --transition: 200ms;
  
  /* Z-index layers */
  --z-base: 1;
  --z-header: 100;
  --z-sidebar: 200;
  --z-player: 300;
  --z-overlay: 400;
  --z-modal: 500;
}

/* Light theme (optional) */
@media (prefers-color-scheme: light) {
  :root[data-theme="auto"] {
    --bg: #f5f7fa;
    --bg-elev: #ffffff;
    --bg-card: #ffffff;
    --border: #e2e8f0;
    --text: #1a202c;
    --text-muted: #64748b;
  }
}

:root[data-theme="light"] {
  --bg: #f5f7fa;
  --bg-elev: #ffffff;
  --bg-card: #ffffff;
  --border: #e2e8f0;
  --text: #1a202c;
  --text-muted: #64748b;
}

/* ============================================
   BASE RESET & TYPOGRAPHY
   ============================================ */
*, *::before, *::after {
  box-sizing: border-box;
}

* {
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

img, picture, video, canvas, svg {
  display: block;
  max-width: 100%;
}

img, video {
  height: auto;
}

button, input, textarea, select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

a {
  color: inherit;
  text-decoration: none;
}

/* Focus styles */
:focus-visible {
  outline: 3px solid var(--accent-blue);
  outline-offset: 2px;
}

button:focus-visible,
a:focus-visible {
  outline: 3px solid var(--accent-blue);
  outline-offset: 2px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

/* Display */
.flex { display: flex; }
.inline-flex { display: inline-flex; }
.grid { display: grid; }
.hidden { display: none; }
.block { display: block; }

/* Flex utilities */
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.items-end { align-items: flex-end; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-5 { gap: var(--space-5); }
.gap-6 { gap: var(--space-6); }

/* Spacing */
.p-1 { padding: var(--space-1); }
.p-2 { padding: var(--space-2); }
.p-3 { padding: var(--space-3); }
.p-4 { padding: var(--space-4); }
.p-5 { padding: var(--space-5); }
.p-6 { padding: var(--space-6); }
.px-2 { padding-left: var(--space-2); padding-right: var(--space-2); }
.px-3 { padding-left: var(--space-3); padding-right: var(--space-3); }
.px-4 { padding-left: var(--space-4); padding-right: var(--space-4); }
.py-2 { padding-top: var(--space-2); padding-bottom: var(--space-2); }
.py-3 { padding-top: var(--space-3); padding-bottom: var(--space-3); }
.py-4 { padding-top: var(--space-4); padding-bottom: var(--space-4); }
.m-auto { margin: auto; }
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }

/* Width & Height */
.w-full { width: 100%; }
.h-full { height: 100%; }
.min-h-screen { min-height: 100vh; }

/* Border radius */
.rounded-s { border-radius: var(--radius-s); }
.rounded-m { border-radius: var(--radius-m); }
.rounded-l { border-radius: var(--radius-l); }
.rounded-xl { border-radius: var(--radius-xl); }
.rounded-full { border-radius: var(--radius-full); }

/* Text */
.text-sm { font-size: 0.875rem; }
.text-base { font-size: 1rem; }
.text-lg { font-size: 1.125rem; }
.text-xl { font-size: 1.25rem; }
.text-2xl { font-size: 1.5rem; }
.text-3xl { font-size: 1.875rem; }
.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Position */
.relative { position: relative; }
.absolute { position: absolute; }
.fixed { position: fixed; }
.sticky { position: sticky; }
.inset-0 { top: 0; right: 0; bottom: 0; left: 0; }

/* Overflow */
.overflow-hidden { overflow: hidden; }
.overflow-auto { overflow: auto; }
.overflow-x-auto { overflow-x: auto; }
.overflow-y-auto { overflow-y: auto; }

/* Scroll snap */
.scroll-snap-x {
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}
.scroll-snap-start { scroll-snap-align: start; }
.scroll-snap-center { scroll-snap-align: center; }

/* Aspect ratio */
.aspect-video {
  aspect-ratio: 16 / 9;
}
/* Fallback for older browsers */
@supports not (aspect-ratio: 16 / 9) {
  .aspect-video {
    position: relative;
    padding-bottom: 56.25%;
  }
  .aspect-video > * {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
  }
}

/* Shadow */
.shadow-1 { box-shadow: var(--shadow-1); }
.shadow-2 { box-shadow: var(--shadow-2); }
.shadow-3 { box-shadow: var(--shadow-3); }

/* Transition */
.transition { transition: all var(--transition) ease; }
.transition-fast { transition: all var(--transition-fast) ease; }

/* Skeleton loader */
.skeleton {
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-elev) 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s ease-in-out infinite;
}
@keyframes skeleton-loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ============================================
   COMPONENT CLASSES
   ============================================ */

/* Skip link (accessibility) */
.skip-link {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  background: var(--accent-blue);
  color: white;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-s);
  font-weight: 600;
  z-index: var(--z-modal);
  transform: translateY(-200%);
  transition: transform var(--transition);
}
.skip-link:focus {
  transform: translateY(0);
}

/* Header */
.header {
  position: sticky;
  top: 0;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-1);
  z-index: var(--z-header);
  padding: var(--space-3) var(--space-4);
}

/* Sidebar */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 240px;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  z-index: var(--z-sidebar);
  transform: translateX(0);
  transition: transform var(--transition);
  overflow-y: auto;
  padding-top: 64px; /* header height */
}

.sidebar.collapsed {
  transform: translateX(-100%);
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  color: var(--text-muted);
  transition: all var(--transition-fast);
  border-left: 3px solid transparent;
}

.sidebar-item:hover {
  background: var(--bg-card);
  color: var(--text);
}

.sidebar-item.active {
  background: var(--bg-card);
  color: var(--text);
  border-left-color: var(--accent-blue);
}

/* Bottom navigation (mobile) */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: var(--space-2);
  padding-bottom: calc(var(--space-2) + env(safe-area-inset-bottom));
  z-index: var(--z-header);
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.2);
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-2);
  min-width: 44px;
  min-height: 44px;
  color: var(--text-muted);
  transition: color var(--transition-fast);
}

.bottom-nav-item.active {
  color: var(--accent-blue);
}

.bottom-nav-item:hover {
  color: var(--text);
}

/* Video card */
.video-card {
  background: var(--bg-card);
  border-radius: var(--radius-m);
  overflow: hidden;
  transition: all var(--transition);
  cursor: pointer;
}

.video-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-2);
}

.video-card-thumbnail {
  position: relative;
  width: 100%;
  background: var(--bg);
  overflow: hidden;
}

.video-card-thumbnail img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.video-card-duration {
  position: absolute;
  bottom: var(--space-2);
  right: var(--space-2);
  background: rgba(0, 0, 0, 0.85);
  color: white;
  padding: 2px var(--space-2);
  border-radius: var(--radius-s);
  font-size: 0.75rem;
  font-weight: 600;
}

.video-card-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: rgba(255, 255, 255, 0.3);
}

.video-card-progress-bar {
  height: 100%;
  background: var(--accent-red);
  transition: width var(--transition);
}

.video-card-body {
  padding: var(--space-3);
}

.video-card-meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.channel-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: var(--accent-blue);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 600;
  font-size: 0.875rem;
  flex-shrink: 0;
}

.channel-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: var(--radius-full);
}

.video-card-title {
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: var(--space-1);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.video-card-info {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Carousel */
.carousel {
  position: relative;
  margin-bottom: var(--space-6);
}

.carousel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
  padding: 0 var(--space-4);
}

.carousel-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 1.25rem;
  font-weight: 700;
}

.carousel-container {
  position: relative;
  overflow: hidden;
}

.carousel-track {
  display: flex;
  gap: var(--space-4);
  overflow-x: auto;
  scroll-behavior: smooth;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 0 var(--space-4) var(--space-2);
}

.carousel-track::-webkit-scrollbar {
  display: none;
}

.carousel-item {
  flex: 0 0 280px;
  scroll-snap-align: start;
}

@media (max-width: 768px) {
  .carousel-item {
    flex: 0 0 220px;
  }
}

.carousel-nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-base);
  opacity: 0;
  transition: opacity var(--transition);
  backdrop-filter: blur(8px);
}

.carousel:hover .carousel-nav-btn {
  opacity: 1;
}

.carousel-nav-btn.prev {
  left: var(--space-2);
}

.carousel-nav-btn.next {
  right: var(--space-2);
}

.carousel-nav-btn:hover {
  background: rgba(0, 0, 0, 0.85);
}

.carousel-nav-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* Profile avatar (large) */
.profile-avatar {
  width: 120px;
  height: 120px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 3rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: var(--shadow-2);
  border: 4px solid transparent;
}

.profile-avatar:hover {
  transform: scale(1.05);
  box-shadow: var(--shadow-3);
  border-color: var(--accent-blue);
}

.profile-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: var(--radius-full);
}

/* Player sheet (video page swipe-down) */
.player-sheet {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: var(--z-player);
  overscroll-behavior: contain;
  touch-action: pan-y;
  will-change: transform;
  transition: transform var(--transition);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-height: 100dvh;
}

.watch-masthead {
  flex-shrink: 0;
  position: relative;
  z-index: 40;
}

.watch-masthead .search-bar {
  min-width: 0;
}

.player-sheet-handle {
  flex-shrink: 0;
  height: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
}

.player-sheet-handle::after {
  content: '';
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: var(--text-muted);
  opacity: 0.35;
}

.watch-page-body {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
}

.watch-primary-col {
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

@media (min-width: 1024px) {
  .watch-page-body {
    flex-direction: row;
    gap: var(--space-5);
    padding-left: var(--space-4);
    padding-right: var(--space-4);
  }

  .watch-sidebar-col {
    width: 402px;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    align-self: flex-start;
    max-height: calc(100dvh - 88px);
    overflow-y: auto;
    padding: var(--space-4) 0;
    background: var(--bg);
    border-left: 1px solid var(--border);
  }
}

@media (max-width: 1023px) {
  .watch-sidebar-col {
    display: none !important;
  }
}

.player-sheet-scroll {
  min-height: 0;
}

.player-video-stack {
  position: relative;
  width: 100%;
  max-width: 100vw;
  margin: 0 auto;
  background: #000;
}

.player-video-el {
  display: block;
  max-height: 60vh;
  object-fit: contain;
}

.player-bottom-chrome {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 25;
  display: flex;
  flex-direction: column;
  pointer-events: none;
}

.player-bottom-chrome > * {
  pointer-events: auto;
}

.player-controls-expanded {
  width: 100%;
}

.player-progress-rail {
  padding: var(--space-2) var(--space-3) var(--space-3);
  cursor: pointer;
  min-height: 28px;
  display: flex;
  align-items: center;
  touch-action: none;
}

.player-progress-rail-inner {
  width: 100%;
  height: 3px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.25);
  overflow: hidden;
}

.player-progress-rail-fill {
  height: 100%;
  background: var(--accent-red);
  border-radius: 2px;
  pointer-events: none;
}

.player-seek-track {
  cursor: pointer;
  touch-action: none;
  height: 6px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.25);
  overflow: hidden;
  transition: height var(--transition-fast);
}

.player-seek-track:hover {
  height: 8px;
}

.player-seek-track-fill {
  height: 100%;
  background: var(--accent-red);
  border-radius: var(--radius-full);
  pointer-events: none;
}

.player-sheet.dismissing {
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.player-container {
  position: relative;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  flex-shrink: 0;
}

.player-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  z-index: 10;
  cursor: pointer;
  transition: opacity var(--transition);
}

.player-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.play-button {
  width: 80px;
  height: 80px;
  background: var(--accent-red);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: var(--shadow-3);
  transition: all var(--transition);
}

.play-button:hover {
  transform: scale(1.1);
  background: #ff3333;
}

/* Button component */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-m);
  font-weight: 600;
  transition: all var(--transition-fast);
  min-height: 44px;
  justify-content: center;
}

.btn-primary {
  background: var(--accent-blue);
  color: white;
}

.btn-primary:hover {
  background: #3aa0e6;
  transform: translateY(-2px);
  box-shadow: var(--shadow-2);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg-elev);
  border-color: var(--text-muted);
}

/* Icon button */
.icon-btn {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-m);
  transition: all var(--transition-fast);
}

.icon-btn:hover {
  background: var(--bg-card);
}

/* Search bar */
.search-bar {
  position: relative;
  width: 100%;
  max-width: 600px;
}

.search-input {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  padding-left: var(--space-7);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  color: var(--text);
  transition: all var(--transition-fast);
}

.search-input:focus {
  outline: none;
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(75, 182, 255, 0.2);
}

.search-icon {
  position: absolute;
  left: var(--space-4);
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

/* Grid layouts */
.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-5);
  padding: var(--space-4);
}

@media (max-width: 768px) {
  .video-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: var(--space-3);
  }
}

/* Main content area */
.main-content {
  margin-left: 240px;
  padding-bottom: var(--space-8);
  min-height: 100vh;
  transition: margin-left var(--transition);
}

.main-content.sidebar-collapsed {
  margin-left: 0;
}

@media (max-width: 1024px) {
  .main-content {
    margin-left: 0;
    padding-bottom: calc(var(--space-8) + 60px); /* account for bottom nav */
  }
}

/* Responsive utilities */
@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
  }
  
  .sidebar.open {
    transform: translateX(0);
  }
  
  .bottom-nav {
    display: flex;
  }
}

@media (min-width: 1025px) {
  .bottom-nav {
    display: none;
  }
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: var(--space-8) var(--space-4);
}

.empty-state-icon {
  font-size: 4rem;
  margin-bottom: var(--space-4);
  opacity: 0.5;
}

.empty-state-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: var(--space-2);
}

.empty-state-text {
  color: var(--text-muted);
  max-width: 400px;
  margin: 0 auto;
}

/* Missing utility classes used in templates */
.bg-card {
  background: var(--bg-card);
}

.bg-gray-600 {
  background-color: #4b5563;
}

.bg-red-600 {
  background-color: #dc2626;
}

