/* ── Reset & base ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: #0b0d12;
  color: #e2e8f0;
  min-height: 100dvh;
}
a { color: #60a5fa; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Topbar ────────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(13, 17, 25, 0.97);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid #1e2738;
  padding: 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.topbar-title {
  font-size: 17px;
  font-weight: 700;
  color: #f1f5f9;
  letter-spacing: -0.3px;
  flex-shrink: 0;
}
.filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.filters input,
.filters select,
.filters button {
  padding: 8px 10px;
  border-radius: 9px;
  border: 1px solid #253047;
  background: #111827;
  color: #e2e8f0;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
}
.filters input:focus, .filters select:focus { border-color: #3b82f6; }
.filters button {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.filters button:hover { background: #1d4ed8; }

/* ── Page layout (sidebar + main) ─────────────────────────────────── */
.page-layout {
  display: flex;
  align-items: flex-start;
}

/* ── Sidebar ───────────────────────────────────────────────────────── */
.sidebar {
  width: 52px;
  flex-shrink: 0;
  position: sticky;
  top: 86px; /* below topbar */
  height: calc(100dvh - 86px);
  overflow-y: auto;
  overflow-x: hidden;
  border-right: 1px solid #1a2235;
  background: #0d1119;
  padding: 12px 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: width 0.25s ease;
}
.sidebar:hover,
.sidebar:focus-within {
  width: 190px;
}
.sidebar-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #374869;
  padding: 4px 6px 8px;
  white-space: nowrap;
  overflow: hidden;
}

/* Source buttons */
.src-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 8px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: #64748b;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  transition: background 0.15s, color 0.15s;
}
.src-btn:hover { background: #151f30; color: #cbd5e1; }
.src-btn.active {
  background: #1a2e4a;
  color: #60a5fa;
}
.src-icon { font-size: 18px; flex-shrink: 0; line-height: 1; }
.src-name { overflow: hidden; text-overflow: ellipsis; opacity: 0; transition: opacity 0.2s; }
.sidebar:hover .src-name,
.sidebar:focus-within .src-name { opacity: 1; }
.src-count {
  margin-left: auto;
  font-size: 11px;
  background: #1e2d42;
  color: #475569;
  border-radius: 999px;
  padding: 1px 6px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.2s;
}
.sidebar:hover .src-count,
.sidebar:focus-within .src-count { opacity: 1; }

/* ── Main content ──────────────────────────────────────────────────── */
.main {
  flex: 1;
  min-width: 0;
  padding: 14px 12px 40px;
}
.stats {
  font-size: 12px;
  color: #64748b;
  margin-bottom: 12px;
}

/* ── Movie grid ────────────────────────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.card {
  background: #141a26;
  border: 1px solid #1e2d42;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  position: relative;
}
.card:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 28px rgba(0,0,0,0.5);
  border-color: #3b5278;
}
.card img {
  width: 100%;
  aspect-ratio: 2/3;
  object-fit: cover;
  background: #1a2030;
  display: block;
}
.card-body { padding: 8px; }
.card-title {
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  color: #f1f5f9;
}
.card-meta {
  font-size: 11px;
  color: #64748b;
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Source badge on card */
.card-src {
  position: absolute;
  top: 6px;
  left: 6px;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 5px;
  background: rgba(0,0,0,0.65);
  color: #94a3b8;
  letter-spacing: 0.3px;
}
.card-src[data-src="javhdz"] { background: rgba(37,99,235,0.75); color: #bfdbfe; }
.card-src[data-src="vlxx"]   { background: rgba(220,38,38,0.75); color: #fecaca; }
.card-src[data-src="qmh"]    { background: rgba(124,58,237,0.75); color: #ddd6fe; }

/* ── Overlay backdrop ──────────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(3px);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.overlay.open { opacity: 1; pointer-events: all; }

/* ── Drawer (detail panel) ─────────────────────────────────────────── */
.drawer {
  position: fixed;
  z-index: 110;
  background: #0f1520;
  overflow-y: auto;
  overscroll-behavior: contain;
  top: 0; right: 0;
  width: min(440px, 100vw);
  height: 100dvh;
  transform: translateX(100%);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  border-left: 1px solid #1e2d42;
}
.drawer.open { transform: translateX(0); }

.drawer-close {
  position: absolute; top: 12px; right: 12px; z-index: 10;
  width: 34px; height: 34px; border-radius: 50%; border: none;
  background: rgba(0,0,0,0.5); color: #e2e8f0; font-size: 16px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background 0.2s;
}
.drawer-close:hover { background: rgba(255,255,255,0.15); }

.drawer-poster-wrap {
  position: relative; width: 100%; aspect-ratio: 16/9;
  overflow: hidden; background: #0a0e16; flex-shrink: 0;
}
.drawer-poster { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }
.drawer-poster-fade {
  position: absolute; bottom: 0; left: 0; right: 0; height: 60%;
  background: linear-gradient(to bottom, transparent, #0f1520);
}

.drawer-body { padding: 14px 18px 32px; display: flex; flex-direction: column; gap: 12px; }
.drawer-title { font-size: 17px; font-weight: 700; line-height: 1.35; color: #f1f5f9; }
.drawer-meta { font-size: 13px; color: #64748b; line-height: 1.5; }
.drawer-desc {
  font-size: 13px; color: #94a3b8; line-height: 1.7;
  display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden;
}

/* ── Play button ───────────────────────────────────────────────────── */
.play-btn {
  width: 100%; padding: 13px; border-radius: 11px; border: none;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #fff; font-size: 15px; font-weight: 700; cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
  box-shadow: 0 4px 14px rgba(37,99,235,0.4);
}
.play-btn:hover { opacity: 0.9; transform: translateY(-1px); }
.play-btn:active { transform: translateY(0); }
.play-btn:disabled {
  background: #253047; color: #475569; cursor: not-allowed;
  box-shadow: none; transform: none;
}

/* ── Tags ──────────────────────────────────────────────────────────── */
.tag-wrap { display: flex; flex-wrap: wrap; gap: 5px; }
.tag {
  font-size: 11px; padding: 3px 9px; border-radius: 999px;
  background: #1a2540; border: 1px solid #2a3953; color: #94a3b8;
}
.tag-btn {
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.tag-btn:hover { background: #2a3f6a; border-color: #3b82f6; color: #93c5fd; }

/* ── Source link ───────────────────────────────────────────────────── */
.source-link { font-size: 12px; color: #475569; align-self: flex-start; }
.source-link:hover { color: #60a5fa; }

/* ── Mobile: bottom sheet + horizontal source tabs ─────────────────── */
@media (max-width: 640px) {
  .topbar { padding: 8px 12px; gap: 6px; }
  .topbar-title { font-size: 15px; }
  .filters { grid-template-columns: 1fr 1fr; gap: 5px; }

  /* Sidebar becomes horizontal scroll bar */
  .page-layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: sticky;
    top: 78px;
    flex-direction: row;
    border-right: none;
    border-bottom: 1px solid #1a2235;
    padding: 6px 10px;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    z-index: 40;
  }
  .sidebar:hover, .sidebar:focus-within { width: 100%; }
  .sidebar-label { display: none; }
  .src-btn {
    flex-direction: column;
    gap: 2px;
    padding: 6px 10px;
    font-size: 11px;
    border-radius: 8px;
    flex-shrink: 0;
  }
  .src-icon { font-size: 16px; }
  .src-name, .src-count { opacity: 1; }
  .src-count { margin-left: 0; }

  /* Bottom sheet */
  .drawer {
    top: auto; right: 0; bottom: 0; left: 0;
    width: 100%; height: 88dvh;
    border-left: none; border-top: 1px solid #1e2d42;
    border-radius: 18px 18px 0 0;
    transform: translateY(100%);
  }
  .drawer.open { transform: translateY(0); }
  .drawer::before {
    content: '';
    display: block; width: 36px; height: 3px;
    background: #2d3f5a; border-radius: 2px;
    margin: 10px auto 0;
  }
}

/* ── Desktop: wider grid ───────────────────────────────────────────── */
@media (min-width: 640px) {
  .topbar { flex-direction: row; align-items: center; gap: 14px; padding: 10px 20px; }
  .topbar-title { margin-bottom: 0; }
  .filters { grid-template-columns: 2fr 1fr 1fr 1fr auto; flex: 1; }
  .grid { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 900px) { .grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 1100px) { .grid { grid-template-columns: repeat(5, 1fr); } }
