/**
 * responsive.css — Responsive Breakpoints
 * =========================================
 * Mobile-first responsive adjustments.
 * Breakpoints:
 *   xs: < 480px  (small phones)
 *   sm: 480-767px (large phones)
 *   md: 768-1023px (tablets)
 *   lg: 1024-1279px (laptops)
 *   xl: ≥ 1280px (desktops — base styles)
 */

/* ─── Tablet (md) — 768px and below ─────────────────────────────────────────── */
@media (max-width: 1023px) {
  :root {
    --card-width: 180px;
    --hero-height: 72vh;
    --nav-height: 60px;
  }

  .nav-links {
    display: none; /* Hidden on tablet — shown in mobile menu */
  }

  .hero-content {
    max-width: 100%;
    padding-bottom: var(--space-12);
  }

  .hero-description {
    -webkit-line-clamp: 2;
    font-size: 0.9rem;
  }

  .footer-top {
    flex-direction: column;
    gap: var(--space-6);
  }

  .footer-links {
    gap: var(--space-8);
  }

  .categories-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  }
}

/* ─── Large Phone (sm) — 767px and below ────────────────────────────────────── */
@media (max-width: 767px) {
  .player-page {
    padding-top: 0;
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    background: var(--color-bg-base, #141414);
  }

  .player-layout {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex: 1;
    min-height: 0;
  }

  .player-layout #player-wrapper {
    flex: 0 0 auto;
    width: 100%;
    aspect-ratio: 16 / 9;
    position: relative;
    z-index: 10;
  }

  #main-video {
    width: 100%;
    height: 100%;
    min-height: 0;
    max-height: none;
    object-fit: contain;
  }

  .player-controls {
    padding: 10px 14px calc(12px + env(safe-area-inset-bottom));
  }

  .controls-row {
    justify-content: space-between;
    gap: 4px;
  }

  .controls-left {
    flex: 0 1 auto;
    gap: 2px;
  }

  .controls-right { gap: 2px; }
  .ctrl-btn { width: 34px; height: 34px; padding: 5px; }
  .ctrl-btn svg { width: 20px; height: 20px; }
  .volume-wrapper input,
  .pip-btn,
  #theatre-btn { display: none; }
  .time-display { font-size: 0.72rem; margin-left: 3px; }

  .player-top-bar {
    justify-content: center;
    min-height: 56px;
    padding: 10px 58px;
  }

  .player-back-btn {
    position: absolute;
    left: 12px;
    width: 34px;
    height: 34px;
    justify-content: center;
    padding: 0;
    border-radius: 50%;
    font-size: 0;
  }

  .player-back-btn svg { width: 18px; height: 18px; }
  .player-top-title {
    width: 100%;
    text-align: center;
    font-size: 0.8rem;
    line-height: 1.25;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
  }

  #player-wrapper:not(.fullscreen):not(.theatre) .player-top-bar,
  #player-wrapper:not(.fullscreen):not(.theatre).controls-hidden .player-top-bar {
    opacity: 1;
    pointer-events: auto;
  }

  #player-wrapper:not(.fullscreen):not(.theatre) .player-top-bar {
    background: linear-gradient(to bottom, rgba(0,0,0,0.68), transparent);
  }

  #player-wrapper.fullscreen .player-top-bar,
  #player-wrapper.theatre .player-top-bar {
    top: env(safe-area-inset-top);
  }

  #player-wrapper.theatre {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100vw;
    height: 100dvh;
    aspect-ratio: auto;
  }

  #player-wrapper.theatre #main-video {
    width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    object-fit: contain;
  }

  #player-wrapper.theatre .player-controls {
    bottom: env(safe-area-inset-bottom);
  }

  :root {
    --card-width: 160px;
    --hero-height: 65vh;
    --content-pad: 16px;
  }

  /* Nav */
  .navbar {
    padding: 0 var(--space-4);
  }

  .logo {
    font-size: 1.3rem;
  }

  /* Hero */
  .hero-title {
    font-size: clamp(1.8rem, 8vw, 2.8rem);
  }

  .hero-badge {
    font-size: 0.65rem;
  }

  .hero-meta {
    font-size: 0.8rem;
    gap: var(--space-2);
  }

  .hero-actions {
    gap: var(--space-2);
  }

  .btn-lg {
    padding: var(--space-3) var(--space-5);
    font-size: 0.95rem;
  }

  /* Carousels */
  .row-title {
    font-size: 1.05rem;
  }

  .carousel-btn {
    display: none; /* Use swipe gestures on mobile */
  }

  /* Cards */
  .card-info {
    padding: var(--space-2);
  }

  .card-title {
    font-size: 0.78rem;
    line-height: 1.25;
  }

  .card-meta {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 6px !important;
    margin-top: 3px !important;
    width: 100% !important;
    min-width: 0 !important;
    overflow: hidden !important;
  }

  .card-category {
    display: inline-block !important;
    font-size: 0.62rem !important;
    white-space: nowrap !important;
    word-break: keep-all !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    flex: 1 1 auto !important;
    min-width: 0 !important;
    max-width: calc(100% - 65px) !important;
  }

  .card-size {
    display: inline-block !important;
    font-size: 0.62rem !important;
    white-space: nowrap !important;
    word-break: keep-all !important;
    flex: 0 0 auto !important;
    flex-shrink: 0 !important;
  }

  /* Search */
  .search-bar.open {
    width: 200px;
  }

  .search-results {
    width: 340px;
    right: -60px;
  }

  /* Footer */
  .footer-links {
    flex-direction: column;
    gap: var(--space-5);
  }

  .footer-bottom {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-2);
  }

  /* Categories grid */
  .categories-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  /* Toasts */
  .toast-container {
    bottom: var(--space-4);
    right: var(--space-4);
    left: var(--space-4);
  }

  .toast {
    min-width: unset;
    width: 100%;
  }
}

/* ─── Small Phone (xs) — 480px and below ────────────────────────────────────── */
@media (max-width: 479px) {
  :root {
    --card-width: 145px;
    --hero-height: 60vh;
  }

  .hero-content {
    padding-bottom: var(--space-8);
  }

  .hero-title {
    font-size: clamp(1.5rem, 9vw, 2.2rem);
  }

  .hero-description {
    display: none; /* Hide on tiny screens */
  }

  .hero-actions .btn {
    flex: 1;
  }

  .search-bar.open {
    width: 180px;
  }

  .search-results {
    width: calc(100vw - 32px);
    right: -100px;
  }

  /* Categories */
  .categories-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Loading screen */
  .loading-logo {
    font-size: 2.2rem;
  }
}

/* ─── Large Desktop ────────────────────────────────────────────────────────── */
@media (min-width: 1440px) {
  :root {
    --card-width: 240px;
  }

  .hero-title {
    font-size: 5rem;
  }
}

/* ─── Player Page Responsive ───────────────────────────────────────────────── */
@media (max-width: 1023px) {
  .player-layout {
    flex-direction: column;
  }

  .player-sidebar {
    width: 100%;
    max-height: none;
    border-left: 0;
    border-top: 1px solid var(--color-border);
  }
}

@media (max-width: 767px) {
  .player-controls .controls-right {
    gap: var(--space-2);
  }

  /* Hide PiP button on mobile (not well supported) */
  .pip-btn {
    display: none;
  }

  .player-sidebar {
    background: var(--color-bg-base, #141414);
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  /* The player controls already show the current title. Avoid repeating it in
     a large block below the video on phones. */
  .player-sidebar:not(.has-related) {
    display: none;
  }

  .player-sidebar.has-related .sidebar-header {
    display: none;
  }

  .sidebar-header {
    padding: 16px;
    border-bottom: 0;
  }

  .sidebar-title {
    font-size: 0.95rem;
    line-height: 1.35;
  }

  .sidebar-meta {
    margin-top: 8px;
  }

  .player-sidebar.has-related .related-header {
    flex: 0 0 auto;
    padding: 12px 16px 8px;
    border-top: 1px solid var(--color-border);
    text-align: center;
    font-size: 0.82rem;
    letter-spacing: 0.08em;
  }

  .player-sidebar.has-related #related-list {
    width: 100%;
    max-width: 640px;
    margin: 0 auto;
    flex: 1;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 0 12px calc(20px + env(safe-area-inset-bottom));
  }

  /* Keyboard shortcuts are useful on desktop but waste valuable phone space. */
  .shortcuts-hint {
    display: none;
  }
}

/* ─── Print ────────────────────────────────────────────────────────────────── */
@media print {
  .navbar,
  .hero,
  .footer,
  .search-wrapper,
  .toast-container {
    display: none !important;
  }

  body {
    background: white;
    color: black;
  }
}

/* ─── Reduced Motion ───────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ─── High Contrast ────────────────────────────────────────────────────────── */
@media (prefers-contrast: high) {
  :root {
    --color-border: rgba(255,255,255,0.3);
    --color-text-secondary: #cccccc;
  }

  .movie-card {
    border: 1px solid var(--color-border);
  }

  .btn-ghost {
    border: 1px solid rgba(255,255,255,0.4);
  }
}

/* ─── Mobile Navigation Drawer ─────────────────────────────────────────────── */
.mobile-menu-btn {
  display: none;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.06);
  border-radius: var(--radius-md);
  color: var(--color-text-primary);
  font-size: 1.2rem;
  cursor: pointer;
  border: none;
  transition: background var(--transition-fast);
}

.mobile-menu-btn:hover {
  background: rgba(255,255,255,0.12);
}

@media (max-width: 1023px) {
  .mobile-menu-btn {
    display: flex;
  }

  /* The drawer provides logout on tablet and phone, keeping the top bar clear. */
  .navbar-right .logout-btn {
    display: none;
  }
}

.mobile-nav-drawer {
  position: fixed;
  top: 0;
  left: -280px;
  bottom: 0;
  width: 280px;
  background: var(--color-bg-elevated);
  z-index: 1500;
  display: flex;
  flex-direction: column;
  padding: var(--space-8) var(--space-5);
  border-right: 1px solid var(--color-border);
  transition: left var(--transition-normal);
  box-shadow: var(--shadow-xl);
}

.mobile-nav-drawer.open {
  left: 0;
}

.mobile-nav-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 1400;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal);
  backdrop-filter: blur(4px);
}

.mobile-nav-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.mobile-nav-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-8);
}

.mobile-nav-links {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.mobile-nav-links a {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-3);
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 500;
  color: var(--color-text-secondary);
  transition: color var(--transition-fast), background var(--transition-fast);
}

.mobile-nav-links a:hover,
.mobile-nav-links a.active {
  color: var(--color-text-primary);
  background: rgba(255,255,255,0.06);
}

.mobile-nav-links a span:first-child {
  font-size: 1.2rem;
  width: 24px;
  text-align: center;
}

.mobile-logout-link {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  margin-top: auto;
  padding: var(--space-3);
  border: 1px solid rgba(229, 9, 20, 0.45);
  border-radius: var(--radius-md);
  color: #ff6b70;
  font-size: 0.9rem;
  font-weight: 600;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

.mobile-logout-link:hover {
  background: rgba(229, 9, 20, 0.12);
  border-color: var(--color-accent);
  color: white;
}

/* Phone header: keep only the essential menu, brand and search controls.
   Refresh and logout are available from the navigation drawer. */
@media (max-width: 767px) {
  .navbar {
    gap: 8px;
    padding: 0 12px;
  }

  .navbar-left {
    gap: 10px;
    min-width: 0;
  }

  .navbar-right {
    margin-left: auto;
    gap: 0;
  }

  .navbar-right .refresh-btn,
  .navbar-right .logout-btn {
    display: none !important;
  }

  .navbar .logo {
    font-size: 1.05rem;
  }

  .navbar .logo-icon {
    width: 34px;
    height: 34px;
  }
}
