/* ===== CSS Variables ===== */
:root {
  --bg-primary: #06060e;
  --bg-secondary: #0e0e1a;
  --bg-card: #12122280;
  --bg-card-hover: #1a1a3090;
  --bg-surface: #16162a;
  --bg-glass: rgba(18, 18, 34, 0.85);

  --accent: #e94560;
  --accent-glow: rgba(233, 69, 96, 0.4);
  --accent-gradient: linear-gradient(135deg, #e94560, #c23152);
  --accent-secondary: #7c3aed;
  --accent-secondary-glow: rgba(124, 58, 237, 0.3);

  --text-primary: #f0f0f8;
  --text-secondary: #8b8ba3;
  --text-muted: #555570;

  --border: rgba(255, 255, 255, 0.06);
  --border-hover: rgba(255, 255, 255, 0.12);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 30px var(--accent-glow);

  --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-smooth: 0.35s cubic-bezier(0.4, 0, 0.2, 1);

  --header-height: 72px;
  --content-padding: 48px;
}

/* ===== Reset & Base ===== */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(124, 58, 237, 0.08) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 100%, rgba(233, 69, 96, 0.06) 0%, transparent 60%);
  pointer-events: none;
  z-index: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
  border: none;
  background: none;
  color: inherit;
  cursor: pointer;
  outline: none;
}

img {
  display: block;
  max-width: 100%;
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ===== Header ===== */
#app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  z-index: 1000;
  background: linear-gradient(180deg, rgba(6, 6, 14, 0.95) 0%, rgba(6, 6, 14, 0.8) 100%);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  transition: background var(--transition-smooth);
}

#app-header.scrolled {
  background: rgba(6, 6, 14, 0.98);
}

.header-inner {
  max-width: 1800px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--content-padding);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 40px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.logo-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  background: var(--accent-gradient);
  border-radius: 10px;
  font-size: 1rem;
  box-shadow: var(--shadow-glow);
}

.logo-accent {
  color: var(--accent);
}

.nav-links {
  display: flex;
  gap: 4px;
}

.nav-link {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
  position: relative;
}

.nav-link:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

.nav-link.active {
  color: var(--text-primary);
  background: rgba(233, 69, 96, 0.12);
}

.nav-link.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 16px;
  right: 16px;
  height: 2px;
  background: var(--accent);
  border-radius: 2px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

#search-input {
  width: 240px;
  padding: 10px 44px 10px 16px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  transition: all var(--transition-fast);
}

#search-input::placeholder {
  color: var(--text-muted);
}

#search-input:focus {
  width: 320px;
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(233, 69, 96, 0.15);
}

#search-btn {
  position: absolute;
  right: 4px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  border-radius: 50%;
  transition: color var(--transition-fast);
}

#search-btn:hover {
  color: var(--accent);
}

/* ===== Main Content ===== */
#app-content {
  margin-top: var(--header-height);
  min-height: calc(100vh - var(--header-height));
  position: relative;
  z-index: 1;
}

/* ===== Hero Section ===== */
.hero {
  position: relative;
  height: 520px;
  margin-bottom: 20px;
  overflow: hidden;
}

.hero-bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center 20%;
  filter: brightness(0.4);
  transform: scale(1.05);
}

.hero-overlay {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(0deg, var(--bg-primary) 0%, transparent 40%),
    linear-gradient(90deg, rgba(6, 6, 14, 0.9) 0%, transparent 60%);
}

.hero-content {
  position: absolute;
  bottom: 60px;
  left: var(--content-padding);
  max-width: 600px;
  z-index: 2;
}

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  background: var(--accent);
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 16px;
}

.hero-title {
  font-size: 2.8rem;
  font-weight: 800;
  line-height: 1.1;
  margin-bottom: 8px;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

.hero-original-name {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: 16px;
  font-style: italic;
}

.hero-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.hero-meta-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.hero-meta-item.quality {
  padding: 2px 8px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.8rem;
}

.hero-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 28px;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 600;
  transition: all var(--transition-fast);
  cursor: pointer;
}

.btn-primary {
  background: var(--accent-gradient);
  color: #fff;
  box-shadow: 0 4px 15px var(--accent-glow);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 25px var(--accent-glow);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
  border: 1px solid var(--border-hover);
  backdrop-filter: blur(10px);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.15);
  transform: translateY(-2px);
}

.btn-accent {
  background: var(--accent-gradient);
  color: #fff;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-weight: 600;
}

/* ===== Category Row ===== */
.category-section {
  padding: 0 var(--content-padding);
  margin-bottom: 40px;
}

.category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.category-title {
  font-size: 1.4rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
}

.category-title::before {
  content: '';
  width: 4px;
  height: 24px;
  background: var(--accent-gradient);
  border-radius: 2px;
}

.category-more {
  font-size: 0.85rem;
  color: var(--text-secondary);
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.category-more:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.movie-row {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  padding-bottom: 12px;
  scrollbar-width: none;
  -ms-overflow-style: none;
  cursor: grab;
}

.movie-row::-webkit-scrollbar {
  display: none;
}

/* ===== Movie Grid ===== */
.movie-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 20px;
  padding: 0 var(--content-padding);
  margin-bottom: 40px;
}

/* ===== Movie Card ===== */
.movie-card {
  flex: 0 0 200px;
  scroll-snap-align: start;
  cursor: pointer;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-card);
  border: 1px solid var(--border);
  transition: all var(--transition-smooth);
  position: relative;
}

.movie-grid .movie-card {
  flex: initial;
}

.movie-card:hover {
  transform: translateY(-8px) scale(1.02);
  border-color: var(--accent);
  box-shadow: var(--shadow-glow);
  z-index: 10;
}

.movie-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  transform: translateY(-8px) scale(1.02);
  box-shadow: var(--shadow-glow);
}

.card-poster {
  position: relative;
  aspect-ratio: 2/3;
  overflow: hidden;
  background: linear-gradient(110deg, var(--bg-secondary) 30%, rgba(255, 255, 255, 0.06) 50%, var(--bg-secondary) 70%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }

  100% {
    background-position: -200% 0;
  }
}

.card-poster img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform var(--transition-smooth), opacity 0.3s ease;
}

.card-poster img[src=""] {
  opacity: 0;
}

.movie-card:hover .card-poster img {
  transform: scale(1.08);
}

.card-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(0deg, rgba(0, 0, 0, 0.8) 0%, transparent 50%);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 12px;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.movie-card:hover .card-overlay {
  opacity: 1;
}

.card-play-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.8);
  width: 52px;
  height: 52px;
  background: var(--accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: all var(--transition-smooth);
  box-shadow: 0 0 20px var(--accent-glow);
}

.movie-card:hover .card-play-icon {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.card-play-icon svg {
  margin-left: 3px;
}

.card-badges {
  position: absolute;
  top: 8px;
  left: 8px;
  display: flex;
  gap: 4px;
  z-index: 2;
}

.badge {
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-quality {
  background: var(--accent);
  color: white;
}

.badge-lang {
  background: rgba(124, 58, 237, 0.85);
  color: white;
}

.badge-episode {
  background: rgba(0, 0, 0, 0.7);
  color: #4ade80;
  border: 1px solid rgba(74, 222, 128, 0.3);
}

.card-info {
  padding: 12px;
}

.card-name {
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 4px;
}

.card-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.fav-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  z-index: 3;
  opacity: 0;
  transition: all var(--transition-fast);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.movie-card:hover .fav-btn {
  opacity: 1;
}

.fav-btn:hover {
  background: var(--accent);
  transform: scale(1.15);
}

.fav-btn.active {
  opacity: 1;
  color: var(--accent);
}

/* ===== Movie Detail Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.hidden {
  display: none;
}

.detail-backdrop,
.player-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
}

.detail-wrapper {
  position: relative;
  width: 90vw;
  max-width: 1000px;
  max-height: 90vh;
  background: var(--bg-secondary);
  border-radius: var(--radius-xl);
  border: 1px solid var(--border);
  overflow-y: auto;
  z-index: 1;
}

.close-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition: all var(--transition-fast);
}

.close-btn:hover {
  background: var(--accent);
  transform: scale(1.1);
}

.detail-hero {
  position: relative;
  height: 350px;
  overflow: hidden;
}

.detail-hero-bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  filter: brightness(0.4) blur(2px);
}

.detail-hero-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(0deg, var(--bg-secondary) 0%, transparent 70%);
}

.detail-hero-content {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 30px 40px;
  display: flex;
  gap: 24px;
  align-items: flex-end;
}

.detail-poster {
  width: 160px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  flex-shrink: 0;
}

.detail-title-area {
  flex: 1;
}

.detail-title {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.2;
  margin-bottom: 6px;
}

.detail-original {
  font-size: 1rem;
  color: var(--text-secondary);
  font-style: italic;
  margin-bottom: 12px;
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.detail-meta .badge {
  font-size: 0.8rem;
  padding: 4px 10px;
}

.detail-body {
  padding: 20px 40px 40px;
}

.detail-description {
  color: var(--text-secondary);
  line-height: 1.7;
  margin-bottom: 24px;
  font-size: 0.95rem;
}

.detail-info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.detail-info-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.detail-info-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
}

.detail-info-value {
  font-size: 0.95rem;
  color: var(--text-primary);
}

.detail-actions {
  display: flex;
  gap: 12px;
  margin-bottom: 28px;
}

.detail-episodes-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 16px;
}

/* ===== Video Player Modal ===== */
.player-wrapper {
  position: relative;
  width: 95vw;
  max-width: 1200px;
  z-index: 1;
}

.player-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
}

.player-header .close-btn {
  position: static;
}

.player-info h2 {
  font-size: 1.2rem;
  font-weight: 700;
}

.player-info span {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.player-header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-external {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
}

.btn-external:hover,
.btn-external:focus-visible {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.player-container {
  position: relative;
  aspect-ratio: 16/9;
  background: #000;
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.player-container video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.player-container iframe {
  width: 100%;
  height: 100%;
  border: none;
}

.player-error {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(0, 0, 0, 0.9);
}

.player-error p {
  font-size: 1.1rem;
  color: var(--text-secondary);
}

/* ===== Episode Selector ===== */
.episode-selector {
  margin-top: 20px;
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  padding: 20px;
  border: 1px solid var(--border);
}

.episode-selector h3 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 12px;
}

.server-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.server-tab {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  transition: all var(--transition-fast);
  cursor: pointer;
}

.server-tab:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.server-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.episode-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.episode-btn {
  min-width: 48px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  transition: all var(--transition-fast);
  text-align: center;
}

.episode-btn:hover {
  background: rgba(233, 69, 96, 0.15);
  border-color: var(--accent);
  color: var(--accent);
}

.episode-btn.active {
  background: var(--accent-gradient);
  border-color: var(--accent);
  color: #fff;
}

/* ===== Page Header ===== */
.page-header {
  padding: 40px var(--content-padding) 24px;
}

.page-title {
  font-size: 1.8rem;
  font-weight: 800;
}

.page-subtitle {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-top: 4px;
}

/* ===== Pagination ===== */
.pagination {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 20px var(--content-padding) 60px;
}

.page-btn {
  min-width: 40px;
  height: 40px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  background: var(--bg-card);
  border: 1px solid var(--border);
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
}

.page-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.page-btn.active {
  background: var(--accent-gradient);
  border-color: var(--accent);
  color: #fff;
}

.page-btn:disabled {
  opacity: 0.3;
  pointer-events: none;
}

/* ===== Loading / Toast ===== */
.loading {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 6, 14, 0.8);
  backdrop-filter: blur(4px);
}

.loading.hidden {
  display: none;
}

.loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.loader-ring {
  width: 44px;
  height: 44px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius-md);
  background: var(--bg-glass);
  border: 1px solid var(--border);
  backdrop-filter: blur(16px);
  font-size: 0.9rem;
  box-shadow: var(--shadow-card);
  animation: slideInRight 0.3s ease-out;
  max-width: 360px;
}

.toast.success {
  border-left: 3px solid #4ade80;
}

.toast.error {
  border-left: 3px solid var(--accent);
}

.toast.info {
  border-left: 3px solid var(--accent-secondary);
}

/* ===== History Remove Button ===== */
.history-remove-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
  opacity: 0;
  transition: all var(--transition-fast);
}

.movie-card:hover .history-remove-btn,
.movie-card:focus .history-remove-btn,
.movie-card:focus-within .history-remove-btn {
  opacity: 1;
}

.history-remove-btn:hover {
  background: var(--accent);
  border-color: var(--accent);
  transform: scale(1.1);
}

/* ===== Drag-to-Scroll ===== */
.movie-row {
  cursor: grab;
  scroll-behavior: auto;
}

.movie-row:active {
  cursor: grabbing;
}

@keyframes slideInRight {
  from {
    transform: translateX(100%);
    opacity: 0;
  }

  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* ===== Empty / Error State ===== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  text-align: center;
}

.empty-state .emoji {
  font-size: 3rem;
  margin-bottom: 16px;
}

.empty-state h3 {
  font-size: 1.3rem;
  margin-bottom: 8px;
}

.empty-state p {
  color: var(--text-secondary);
  max-width: 400px;
}

/* ===== Genre Tags ===== */
.genre-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.genre-tag {
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 500;
  background: rgba(124, 58, 237, 0.12);
  color: #a78bfa;
  border: 1px solid rgba(124, 58, 237, 0.2);
  transition: all var(--transition-fast);
  cursor: pointer;
}

.genre-tag:hover {
  background: rgba(124, 58, 237, 0.25);
  border-color: #a78bfa;
}

/* ===== Filter Button & Badge ===== */
.icon-btn {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}

.icon-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(233, 69, 96, 0.1);
}

.filter-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.filter-badge.hidden {
  display: none;
}

/* ===== Filter Panel ===== */
.filter-panel {
  position: fixed;
  inset: 0;
  z-index: 3000;
}

.filter-panel.hidden {
  display: none;
}

.filter-panel-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}

.filter-panel-content {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 380px;
  max-width: 90vw;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  padding: 24px;
  overflow-y: auto;
  animation: slideInFromRight 0.3s ease-out;
}

@keyframes slideInFromRight {
  from {
    transform: translateX(100%);
  }

  to {
    transform: translateX(0);
  }
}

.filter-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.filter-panel-header h3 {
  font-size: 1.2rem;
  font-weight: 700;
}

.filter-panel-header .close-btn {
  position: static;
  width: 36px;
  height: 36px;
}

.filter-hint {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 16px;
}

.filter-actions-top {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.filter-section-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 20px 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.filter-year-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
}

.filter-year-row label {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.filter-year-row select {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 0.9rem;
  cursor: pointer;
  color-scheme: dark;
}

.filter-year-row select option {
  background: var(--bg-card);
  color: var(--text-primary);
}

.filter-action-btn {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 500;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  transition: all var(--transition-fast);
}

.filter-action-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.country-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 20px;
}

.country-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
  user-select: none;
}

.country-item:hover {
  background: rgba(255, 255, 255, 0.04);
}

.country-item input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border: 2px solid var(--text-muted);
  border-radius: 4px;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: all var(--transition-fast);
}

.country-item input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.country-item input[type="checkbox"]:checked::after {
  content: '✓';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 800;
}

.country-item .country-name {
  font-size: 0.9rem;
  flex: 1;
}

.country-item.disabled .country-name {
  color: var(--text-muted);
  text-decoration: line-through;
}

.filter-actions {
  position: sticky;
  bottom: 0;
  padding-top: 12px;
  background: var(--bg-secondary);
}

.filter-actions .btn {
  width: 100%;
  justify-content: center;
}

/* ===== Responsive ===== */
@media (max-width: 1200px) {
  :root {
    --content-padding: 32px;
  }
}

@media (max-width: 768px) {
  :root {
    --content-padding: 16px;
    --header-height: 60px;
  }

  .nav-links {
    display: none;
  }

  .header-inner {
    padding: 0 16px;
  }

  #search-input {
    width: 160px;
  }

  #search-input:focus {
    width: 200px;
  }

  .hero {
    height: 360px;
  }

  .hero-title {
    font-size: 1.8rem;
  }

  .movie-card {
    flex: 0 0 140px;
  }

  .movie-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 12px;
  }

  .detail-wrapper {
    width: 95vw;
  }

  .detail-hero {
    height: 240px;
  }

  .detail-hero-content {
    padding: 16px 20px;
  }

  .detail-poster {
    width: 100px;
  }

  .detail-title {
    font-size: 1.4rem;
  }

  .detail-body {
    padding: 16px 20px 30px;
  }

  .player-wrapper {
    width: 100vw;
  }
}

/* ===== TV-specific (large screens, Android Box) ===== */
@media (min-width: 1400px) {

  /* Base sizing */
  :root {
    --content-padding: 60px;
  }

  body {
    font-size: 18px;
  }

  /* Header */
  .header-inner {
    padding: 0 48px;
  }

  .nav-link {
    font-size: 1.1rem;
    padding: 8px 16px;
  }

  #search-input {
    font-size: 1rem;
    width: 280px;
  }

  .icon-btn {
    width: 48px;
    height: 48px;
  }

  /* Hero */
  .hero {
    height: 600px;
  }

  .hero-title {
    font-size: 3.2rem;
  }

  .hero-meta {
    font-size: 1.1rem;
  }

  .hero-desc {
    font-size: 1.05rem;
    max-width: 650px;
  }

  .hero .btn {
    font-size: 1.05rem;
    padding: 14px 28px;
  }

  /* Category */
  .category-title {
    font-size: 1.6rem;
  }

  .category-more {
    font-size: 1rem;
    padding: 8px 18px;
  }

  /* Movie Cards — bigger for TV viewing distance */
  .movie-card {
    flex: 0 0 240px;
  }

  .movie-row {
    gap: 20px;
    padding-bottom: 16px;
  }

  .movie-grid {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 24px;
  }

  .card-name {
    font-size: 1rem;
  }

  .card-meta {
    font-size: 0.85rem;
  }

  /* Badges */
  .badge {
    font-size: 0.75rem;
    padding: 4px 10px;
  }

  /* Focus — bold outline for D-pad navigation */
  .movie-card:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 4px;
    transform: translateY(-6px) scale(1.05);
    box-shadow: 0 0 30px rgba(233, 69, 96, 0.4);
    z-index: 20;
  }

  .movie-card:focus-visible .card-overlay {
    opacity: 1;
  }

  .nav-link:focus-visible,
  .btn:focus-visible,
  .icon-btn:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 3px;
  }

  /* Page headers */
  .page-title {
    font-size: 2rem;
  }

  .page-subtitle {
    font-size: 1.1rem;
  }

  /* Detail modal */
  .detail-title {
    font-size: 2rem;
  }

  .detail-meta {
    font-size: 1rem;
  }

  .detail-desc {
    font-size: 1rem;
    line-height: 1.8;
  }

  /* Episode list */
  .ep-btn {
    font-size: 0.95rem;
    padding: 10px 18px;
  }

  /* Player */
  .player-wrapper {
    max-width: 1200px;
  }

  /* History remove button — always visible on focus for remote */
  .history-remove-btn {
    width: 34px;
    height: 34px;
    font-size: 1rem;
  }

  /* Filter panel */
  .filter-panel-content {
    width: 440px;
  }

  .country-item {
    padding: 14px 16px;
    font-size: 1rem;
  }

  .country-item input[type="checkbox"] {
    width: 24px;
    height: 24px;
  }

  /* Toast */
  .toast {
    font-size: 1rem;
    padding: 14px 24px;
  }

  /* Pagination */
  .page-btn {
    min-width: 44px;
    height: 44px;
    font-size: 1rem;
  }

  /* Empty state */
  .empty-state .emoji {
    font-size: 4rem;
  }

  .empty-state h3 {
    font-size: 1.5rem;
  }

  .empty-state p {
    font-size: 1.1rem;
  }
}

/* ===== Extra Large TV (4K / 55"+) ===== */
@media (min-width: 1920px) {
  body {
    font-size: 20px;
  }

  .movie-card {
    flex: 0 0 280px;
  }

  .movie-grid {
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  }

  .hero {
    height: 700px;
  }

  .hero-title {
    font-size: 3.8rem;
  }

  .category-title {
    font-size: 1.8rem;
  }

  .card-name {
    font-size: 1.1rem;
  }

  .movie-card:focus-visible {
    outline-width: 4px;
    outline-offset: 6px;
    box-shadow: 0 0 40px rgba(233, 69, 96, 0.5);
  }
}

/* ===== TV D-pad Navigation System ===== */
/* Universal focus ring for ALL interactive elements */
*:focus-visible {
  outline: 3px solid var(--accent) !important;
  outline-offset: 2px !important;
}

/* Also support :focus for older WebViews that don't have focus-visible */
.country-item:focus,
.filter-action-btn:focus,
.filter-year-row select:focus,
.server-tab:focus,
.episode-btn:focus,
.page-btn:focus,
.close-btn:focus,
.nav-link:focus,
.btn:focus,
.icon-btn:focus,
.badge:focus,
#search-input:focus {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* Country/genre items in filter — make focusable with D-pad */
.country-item:focus,
.country-item:focus-within {
  background: rgba(233, 69, 96, 0.15) !important;
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  border-radius: var(--radius-sm);
}

/* Movie card focus state for D-pad (no :focus-visible needed, just :focus) */
.movie-card:focus {
  transform: translateY(-8px) scale(1.04);
  border-color: var(--accent);
  box-shadow: 0 0 30px rgba(233, 69, 96, 0.4);
  z-index: 20;
}

.movie-card:focus .card-overlay {
  opacity: 1;
}

.movie-card:focus .card-play-icon {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* ===== TV Mode (.tv class added by JS on Android TV / WebView) ===== */
/* This ONLY applies when body has class "tv" — phone UI stays untouched */

/* Hide cursor & ALL scrollbars on TV */
body.tv,
body.tv * {
  cursor: none !important;
  scrollbar-width: none !important;
  -ms-overflow-style: none !important;
}

body.tv::-webkit-scrollbar,
body.tv *::-webkit-scrollbar {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
}

body.tv .movie-row {
  overflow-x: hidden;
}

/* Disable hover effects (no mouse on TV) */
body.tv .movie-card:hover {
  transform: none;
  box-shadow: none;
  border-color: var(--border);
}

body.tv .movie-card:hover .card-overlay,
body.tv .movie-card:hover .card-play-icon,
body.tv .movie-card:hover .fav-btn {
  opacity: 0;
}

body.tv .movie-card:hover .card-poster img {
  transform: none;
}

/* ===== TV Sidebar ===== */
/* Hidden on non-TV */
.tv-sidebar {
  display: none;
}

body.tv {
  font-size: 11px;
}

/* Show sidebar on TV: thin icon strip, expand on demand */
body.tv .tv-sidebar {
  display: flex;
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: 48px;
  background: #0a0f19;
  z-index: 1000;
  flex-direction: column;
  justify-content: center;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  overflow: hidden;
}

body.tv .tv-sidebar.expanded {
  width: 200px;
}

body.tv .tv-sidebar-label {
  display: none;
}

body.tv .tv-sidebar.expanded .tv-sidebar-label {
  display: inline;
}

/* Sidebar items must be clickable/focusable */
body.tv .tv-sidebar-item {
  pointer-events: auto;
}

body.tv #app-header {
  display: none;
}

body.tv #app-content {
  padding-top: 8px;
  padding-left: 56px;
}

.tv-sidebar-items {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 0;
}

.tv-sidebar-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  color: rgba(255, 255, 255, 0.6);
  text-decoration: none;
  border: none;
  background: none;
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  /* no transition for perf */
  border-left: 3px solid transparent;
  font-family: inherit;
}

.tv-sidebar-item:focus {
  color: white;
  background: rgba(255, 255, 255, 0.08);
  border-left-color: var(--accent);
  outline: none;
}

.tv-sidebar-item.active {
  color: var(--accent);
  border-left-color: var(--accent);
}

.tv-sidebar-icon {
  font-size: 1.2rem;
  flex-shrink: 0;
  width: 24px;
  text-align: center;
}

.tv-sidebar-label {
  opacity: 1;
}

/* Header: compact, search visible */
.tv .header-inner {
  padding: 0 24px;
  gap: 12px;
}

.tv .logo {
  font-size: 1.2rem;
  gap: 6px;
}

.tv .logo-icon {
  width: 30px;
  height: 30px;
  font-size: 0.8rem;
}

.tv .nav-links {
  gap: 2px;
}

.tv .nav-link {
  font-size: 0.8rem;
  padding: 6px 10px;
}

/* Search: smaller, always fully visible */
.tv #search-input {
  width: 180px;
  padding: 8px 36px 8px 12px;
  font-size: 0.8rem;
}

.tv #search-input:focus {
  width: 220px;
}

.tv #search-btn {
  width: 30px;
  height: 30px;
}

.tv .icon-btn {
  width: 36px;
  height: 36px;
}

/* Hero: much smaller for TV */
.tv .hero {
  height: 160px;
  margin-bottom: 6px;
}

.tv .hero-title {
  font-size: 1.8rem;
}

.tv .hero-original-name {
  font-size: 0.85rem;
}

.tv .hero-meta-item {
  font-size: 0.8rem;
}

.tv .hero-actions .btn {
  padding: 8px 18px;
  font-size: 0.85rem;
}

/* Movie cards: Netflix landscape style */
.tv .movie-card {
  flex: 0 0 180px;
}

.tv .card-poster {
  aspect-ratio: 16/9;
}

.tv .movie-grid {
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px;
}

.tv .movie-row {
  gap: 8px;
}

.tv .card-info {
  padding: 4px 6px;
}

.tv .card-name {
  font-size: 0.7rem;
}

.tv .card-meta {
  font-size: 0.6rem;
}

/* ===== NUCLEAR TV PERF: Kill ALL expensive effects ===== */
body.tv *,
body.tv *::before,
body.tv *::after {
  animation: none !important;
  transition: none !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

/* Kill box-shadow everywhere on TV */
body.tv .movie-card,
body.tv .btn,
body.tv .badge,
body.tv .modal,
body.tv .filter-panel-content,
body.tv .detail-modal-content,
body.tv .toast {
  box-shadow: none !important;
}

/* Kill blur on overlays */
body.tv .card-overlay,
body.tv .hero-overlay,
body.tv .hero-bg,
body.tv .detail-hero-bg,
body.tv .player-backdrop,
body.tv .filter-panel-backdrop {
  filter: none !important;
  backdrop-filter: none !important;
}

/* Simpler backgrounds on TV — solid colors instead of gradients */
body.tv .header-inner {
  background: #06060e !important;
}

body.tv .card-overlay {
  background: rgba(0, 0, 0, 0.6) !important;
}

/* GPU compositing for card focus — separate layer */
body.tv .movie-card {
  will-change: auto;
  contain: layout style paint;
  transform: translateZ(0);
}

/* Simpler poster — no shimmer gradient */
body.tv .card-poster {
  background: #1a1a2e !important;
}

/* Reduce image quality for faster decode */
body.tv img {
  image-rendering: optimizeSpeed;
}

/* ===== VIRTUAL FOCUS: JS-managed, bypass WebView focus engine ===== */
/* Remove all native focus styles on TV */
body.tv .movie-card:focus,
body.tv .movie-card:focus-visible {
  outline: none !important;
  z-index: auto;
}

/* Cards: no pointer events = WebView skips hit-testing */
body.tv .movie-card {
  pointer-events: none;
}

/* Focus Ring: single element that moves to highlight */
#tv-focus-ring {
  display: none;
}

body.tv #tv-focus-ring {
  display: block;
  position: fixed;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  border: 3px solid var(--accent);
  border-radius: var(--radius-lg);
  z-index: 9999;
  pointer-events: none;
  transform: translateZ(0);
}

/* TV sizing */
.tv .category-section {
  margin-bottom: 20px;
}

.tv .category-title {
  font-size: 1.1rem;
  margin-bottom: 12px;
}

.tv .card-name {
  font-size: 0.8rem;
}

.tv .card-meta {
  font-size: 0.7rem;
}

.tv .card-info {
  padding: 8px;
}

.tv .badge {
  font-size: 0.6rem;
  padding: 2px 6px;
}

/* Show name highlight on focused card (via .tv-focused class for text only) */
.tv .movie-card.tv-focused .card-name {
  color: var(--accent);
  font-weight: 600;
}

/* Page header */
.tv .page-header {
  padding: 24px 32px 16px;
}

.tv .page-title {
  font-size: 1.4rem;
}

/* Detail modal — compact for TV */
.tv .detail-title {
  font-size: 1.5rem;
}

.tv .detail-hero {
  height: 180px;
}

.tv .detail-poster {
  width: 100px;
}

/* Hide description on TV — show episodes directly */
.tv .detail-description {
  display: none;
}

.tv .detail-info-grid {
  display: none;
}

.tv .genre-tags {
  display: none;
}

/* Player: TRUE fullscreen on TV */
.tv #player-modal {
  align-items: stretch;
  justify-content: stretch;
}

.tv .player-wrapper {
  width: 100vw;
  max-width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.tv .player-header {
  display: none;
}

.tv .player-container {
  flex: 1;
  border-radius: 0;
  aspect-ratio: auto;
}

/* Filter panel */
.tv .filter-panel-content {
  width: 360px;
  padding: 16px;
}

.tv .country-item {
  padding: 10px 12px;
  font-size: 0.85rem;
}

/* Pagination */
.tv .page-btn {
  min-width: 36px;
  height: 36px;
  font-size: 0.85rem;
}

/* Smooth focus transition for movie cards */
.tv .movie-card {
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease, outline-color 0.2s ease;
}

/* Episode buttons: focusable with D-pad */
.tv .episode-btn {
  transition: all 0.15s ease;
}

.tv .episode-btn:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  background: var(--accent);
  color: white;
  transform: scale(1.05);
}

/* Server tabs: focusable */
.tv .server-tab:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Detail modal buttons */
.tv .btn:focus {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
  transform: scale(1.03);
}

/* Focused card: show name more prominently */
.tv .movie-card:focus .card-name {
  color: var(--accent);
  font-weight: 600;
}

/* Scroll hint arrows (visual only) on category rows */
.tv .category-section {
  position: relative;
}

/* Grab cursor for PC drag-to-scroll */
.movie-row:active {
  cursor: grabbing;
}