/* ============================================================
   51xFree Media Engine V2 — Mobile Responsive Patch
   Drop this AFTER your existing desktop CSS on all pages.
   Breakpoints: 768px (tablet), 480px (phone)
   ============================================================ */

/* ─────────────────────────────────────────────
   CSS CUSTOM PROPERTIES (shared tokens)
───────────────────────────────────────────── */
:root {
  --bottom-bar-height: 64px;
  --sheet-radius: 20px;
  --purple: #a855f7;
  --purple-dark: #7c3aed;
  --bg-primary: #050505;
  --bg-nav: #0c0c0c;
  --bg-card: #1a1730;
  --border: #1e1e1e;
  --text-muted: #666;
  --transition-smooth: cubic-bezier(0.32, 0.72, 0, 1);
}

/* ─────────────────────────────────────────────
   GLOBAL MOBILE RESETS
───────────────────────────────────────────── */
@media (max-width: 768px) {
  html, body {
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
  }

  /* Add bottom padding so content isn't hidden behind Bottom App Bar */
  .page,
  .main,
  body > main,
  .feed,
  .video-grid-container {
    padding-bottom: calc(var(--bottom-bar-height) + env(safe-area-inset-bottom));
  }
}

/* ─────────────────────────────────────────────
   1. NAVIGATION — Hide desktop, show Bottom Bar
───────────────────────────────────────────── */
@media (max-width: 768px) {

  /* Hide left sidebar nav (Homepage, Player) */
  .left-nav {
    display: none !important;
  }

  /* Hide top bar nav (Category page) */
  .top-bar {
    display: none !important;
  }

  /* ── Bottom App Bar ── */
  .bottom-app-bar {
    display: flex !important;              /* hidden on desktop, shown here */
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-bar-height);
    padding-bottom: env(safe-area-inset-bottom);
    background: rgba(10, 10, 10, 0.96);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid #1e1e1e;
    z-index: 1000;
    align-items: center;
    justify-content: space-around;
  }

  .bottom-app-bar .bab-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    cursor: pointer;
    padding: 8px 16px;
    border-radius: 12px;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
  }

  .bottom-app-bar .bab-item:active {
    background: rgba(168, 85, 247, 0.12);
  }

  .bottom-app-bar .bab-icon {
    font-size: 20px;
    line-height: 1;
  }

  .bottom-app-bar .bab-label {
    font-size: 9px;
    color: var(--text-muted);
    font-family: 'DM Sans', sans-serif;
    letter-spacing: 0.3px;
  }

  .bottom-app-bar .bab-item.active .bab-label {
    color: var(--purple);
  }

  .bottom-app-bar .bab-item.active .bab-icon {
    filter: drop-shadow(0 0 6px rgba(168, 85, 247, 0.6));
  }

  /* Upload / Plus FAB in center of bottom bar */
  .bottom-app-bar .bab-fab {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--purple-dark), var(--purple));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    box-shadow: 0 4px 16px rgba(124, 58, 237, 0.4);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
}

/* Hide Bottom Bar on desktop */
.bottom-app-bar {
  display: none;
}

/* ─────────────────────────────────────────────
   2. HOMEPAGE & CATEGORY — 2-col grid, hide sidebar
───────────────────────────────────────────── */
@media (max-width: 768px) {

  /* ── Layout: make page a single column ── */
  .page {
    flex-direction: column;
  }

  /* ── Hide Right Panel ── */
  .right-panel,
  .right-side {
    display: none !important;
  }

  /* ── Center / Main takes full width ── */
  .center,
  .main,
  .center-feed {
    width: 100% !important;
    max-width: 100vw;
  }

  /* ── Category top header compact ── */
  .cat-header {
    padding: 12px 14px 0;
  }

  .cat-title {
    font-size: 16px !important;
  }

  .filter-bar {
    padding-bottom: 0;
    gap: 0;
  }

  .ftab, .tab {
    padding: 8px 12px;
    font-size: 11px;
  }

  /* ── 2-column card grid (Homepage) ── */
  .card-grid,
  .video-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 8px !important;
    padding: 10px !important;
  }

  /* Slightly more rounded on mobile */
  .v-card {
    border-radius: 12px;
  }

  /* ── Feed header compact ── */
  .center-header,
  .feed-header {
    padding: 12px 14px 0;
  }

  .center-title,
  .feed-title {
    font-size: 17px !important;
  }

  /* ── Controls bar compact ── */
  .controls {
    padding: 8px 14px;
    flex-wrap: wrap;
    gap: 6px;
  }

  .result-info {
    display: none;
  }

  /* ── Scrollable feed ── */
  .feed,
  .video-grid-container {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* ─────────────────────────────────────────────
   3. PLAYER PAGE — Full-screen immersive mobile
───────────────────────────────────────────── */
@media (max-width: 768px) {

  /* ── Player page layout: full viewport ── */
  .page:has(.center-player) {
    flex-direction: column;
  }

  /* ── Hide right panel (creator info goes into bottom sheet) ── */
  .page:has(.center-player) .right-panel {
    display: none !important;
  }

  /* ── Center player: 100vw × 100vh ── */
  .center-player {
    width: 100vw !important;
    height: 100vh !important;
    position: fixed !important;
    top: 0;
    left: 0;
    z-index: 10;
    background: #000;
  }

  /* ── Player wrap fills screen ── */
  .player-wrap {
    width: 100% !important;
    height: 100% !important;
    aspect-ratio: unset !important;
  }

  /* ── Floating actions: bottom-right corner ── */
  .float-actions {
    position: fixed !important;
    right: 12px !important;
    bottom: calc(80px + env(safe-area-inset-bottom)) !important;
    top: auto !important;
    transform: none !important;
    z-index: 100;
    gap: 14px;
  }

  .f-icon {
    width: 46px !important;
    height: 46px !important;
    background: rgba(15, 15, 15, 0.75) !important;
    border: 1px solid rgba(255,255,255,0.08) !important;
  }

  /* ── Player bottom info: avoid bottom bar ── */
  .player-bottom {
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }

  /* ── More button opens bottom sheet ── */
  .mobile-more-btn {
    display: flex !important;
    position: fixed;
    bottom: calc(var(--bottom-bar-height) + 12px + env(safe-area-inset-bottom));
    left: 14px;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: rgba(255,255,255,0.7);
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(8px);
    padding: 6px 12px;
    border-radius: 20px;
    cursor: pointer;
    z-index: 100;
    border: 1px solid rgba(255,255,255,0.1);
    -webkit-tap-highlight-color: transparent;
  }
}

/* Hide mobile-only elements on desktop */
.mobile-more-btn {
  display: none;
}

/* ─────────────────────────────────────────────
   BOTTOM SHEET (Drawer) — Creator Info + Related
   Used on Player Page mobile
───────────────────────────────────────────── */

/* Overlay */
.sheet-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 200;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.sheet-overlay.open {
  opacity: 1;
}

/* Sheet container */
.bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #111;
  border-radius: var(--sheet-radius) var(--sheet-radius) 0 0;
  border-top: 1px solid #1e1e1e;
  z-index: 201;
  max-height: 85vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  transform: translateY(100%);
  transition: transform 0.38s var(--transition-smooth);
  padding-bottom: env(safe-area-inset-bottom);
}

.bottom-sheet.open {
  transform: translateY(0);
}

/* Drag handle */
.sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: #333;
  margin: 12px auto 16px;
  cursor: grab;
  flex-shrink: 0;
}

/* Sheet content areas */
.sheet-creator-card {
  padding: 0 16px 16px;
  border-bottom: 1px solid #1a1a1a;
  margin-bottom: 14px;
}

.sheet-creator-top {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.sheet-av {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--purple-dark), var(--purple));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 600;
  border: 2px solid var(--purple);
  flex-shrink: 0;
  font-family: 'DM Sans', sans-serif;
  color: #fff;
}

.sheet-creator-name {
  font-size: 15px;
  font-weight: 500;
  color: #eee;
  font-family: 'DM Sans', sans-serif;
}

.sheet-creator-handle {
  font-size: 11px;
  color: #555;
  font-family: 'DM Sans', sans-serif;
  margin-top: 2px;
}

.sheet-stats {
  display: flex;
  gap: 20px;
  margin-bottom: 12px;
}

.sheet-stat-num {
  font-size: 16px;
  font-weight: 600;
  color: #ddd;
  font-family: 'DM Sans', sans-serif;
}

.sheet-stat-lbl {
  font-size: 9px;
  color: #555;
  font-family: 'DM Sans', sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.sheet-follow-btn {
  width: 100%;
  padding: 11px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--purple-dark), var(--purple));
  border: none;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: 'DM Sans', sans-serif;
  margin-bottom: 10px;
  -webkit-tap-highlight-color: transparent;
}

.sheet-share-btn {
  width: 100%;
  padding: 10px;
  border-radius: 10px;
  background: transparent;
  border: 1px solid var(--purple);
  color: var(--purple);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  font-family: 'DM Sans', sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  -webkit-tap-highlight-color: transparent;
}

/* Related videos section inside sheet */
.sheet-related-label {
  font-size: 10px;
  color: #444;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  padding: 0 16px;
  margin-bottom: 10px;
  font-family: 'DM Sans', sans-serif;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sheet-related-more {
  font-size: 10px;
  color: var(--purple);
  cursor: pointer;
}

.sheet-related-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 10px;
}

.sheet-rel-card {
  display: flex;
  gap: 10px;
  padding: 8px 6px;
  border-radius: 10px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s;
}

.sheet-rel-card:active {
  background: rgba(255,255,255,0.04);
}

.sheet-rel-thumb {
  width: 54px;
  height: 96px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}

.sheet-rel-play {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sheet-rel-tri {
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 9px solid #fff;
  margin-left: 2px;
}

.sheet-rel-views {
  position: absolute;
  bottom: 3px;
  left: 3px;
  font-size: 8px;
  background: rgba(0,0,0,0.7);
  padding: 1px 4px;
  border-radius: 3px;
  color: #bbb;
  font-family: 'DM Sans', sans-serif;
}

.sheet-rel-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.sheet-rel-title {
  font-size: 12px;
  color: #ccc;
  line-height: 1.4;
  font-family: 'DM Sans', sans-serif;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.sheet-rel-meta {
  font-size: 10px;
  color: #555;
  font-family: 'DM Sans', sans-serif;
  margin-top: 4px;
}

/* ─────────────────────────────────────────────
   BOTTOM SHEET — JavaScript activation
   Add this snippet to your page's <script>:
   initBottomSheet()
───────────────────────────────────────────── */

/* Show overlay + sheet when .open class added via JS */
.sheet-overlay {
  display: block;
  pointer-events: none;
}

.sheet-overlay.open {
  pointer-events: all;
}

/* ─────────────────────────────────────────────
   TABLET (768px–1024px) — Minor adjustments
───────────────────────────────────────────── */
@media (min-width: 769px) and (max-width: 1024px) {
  .left-nav {
    width: 64px !important;
    min-width: 64px !important;
  }

  /* Hide text labels in nav, keep icons only */
  .left-nav .nav-item span:last-child,
  .left-nav .logo-sub,
  .left-nav .login-btn {
    display: none;
  }

  .right-panel,
  .right-side {
    width: 200px !important;
    min-width: 200px !important;
  }

  .card-grid,
  .video-grid {
    grid-template-columns: repeat(3, 1fr) !important;
  }

  .top-bar .top-nav .tn-item {
    padding: 6px 8px;
    font-size: 11px;
  }
}

/* ─────────────────────────────────────────────
   SAFE AREA support (iPhone notch / home bar)
───────────────────────────────────────────── */
@supports (padding: env(safe-area-inset-bottom)) {
  .bottom-app-bar {
    padding-bottom: env(safe-area-inset-bottom);
    height: calc(var(--bottom-bar-height) + env(safe-area-inset-bottom));
  }

  .bottom-sheet {
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
}

/* ─────────────────────────────────────────────
   TOUCH FEEDBACK — remove blue tap highlight
───────────────────────────────────────────── */
@media (max-width: 768px) {
  * {
    -webkit-tap-highlight-color: transparent;
  }

  button, .v-card, .nav-item, .bab-item {
    touch-action: manipulation;
  }
}
