/* ============================================================
   AnimeFusion Stream Engine – Frontend Stylesheet
   Dark Theme + Glass Cards + Smooth Animations
   ============================================================ */

/* ── CSS Custom Properties ──────────────────────────────────── */
:root {
  --af-accent:          #6C63FF;
  --af-accent-hover:    #5a52e0;
  --af-accent-glow:     rgba(108, 99, 255, 0.35);

  --af-bg:              #0d0d12;
  --af-bg-card:         rgba(255, 255, 255, 0.05);
  --af-bg-card-hover:   rgba(255, 255, 255, 0.09);
  --af-bg-glass:        rgba(13, 13, 18, 0.75);
  --af-bg-overlay:      rgba(0, 0, 0, 0.65);

  --af-text-primary:    #f0f0f5;
  --af-text-secondary:  #9999aa;
  --af-text-muted:      #66667a;

  --af-border:          rgba(255, 255, 255, 0.08);
  --af-border-focus:    var(--af-accent);

  --af-radius-sm:       6px;
  --af-radius:          12px;
  --af-radius-lg:       18px;
  --af-radius-pill:     999px;

  --af-shadow-card:     0 4px 24px rgba(0,0,0,0.4);
  --af-shadow-glow:     0 0 24px var(--af-accent-glow);

  --af-transition:      0.22s cubic-bezier(0.4, 0, 0.2, 1);
  --af-font:            'Inter', 'Noto Sans', system-ui, sans-serif;
}

/* ── Light Theme Override ───────────────────────────────────── */
[data-af-theme="light"] {
  --af-bg:              #f4f4f9;
  --af-bg-card:         rgba(0, 0, 0, 0.04);
  --af-bg-card-hover:   rgba(0, 0, 0, 0.08);
  --af-bg-glass:        rgba(244, 244, 249, 0.85);
  --af-text-primary:    #111118;
  --af-text-secondary:  #44445a;
  --af-text-muted:      #888899;
  --af-border:          rgba(0, 0, 0, 0.08);
}

/* ── Reset & Base ───────────────────────────────────────────── */
.af-root, .af-root * { box-sizing: border-box; }

body { background-color: var(--af-bg); color: var(--af-text-primary); font-family: var(--af-font); }

/* ── Typography ─────────────────────────────────────────────── */
.af-section-title {
  font-size: clamp(1.25rem, 2.5vw, 1.75rem);
  font-weight: 700;
  color: var(--af-text-primary);
  margin: 0 0 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.af-section-title::before {
  content: '';
  display: inline-block;
  width: 4px; height: 1.2em;
  background: var(--af-accent);
  border-radius: var(--af-radius-pill);
}

/* ── Anime Grid ─────────────────────────────────────────────── */
.af-grid {
  display: grid;
  gap: 16px;
}
.af-grid--cols-2 { grid-template-columns: repeat(2, 1fr); }
.af-grid--cols-3 { grid-template-columns: repeat(3, 1fr); }
.af-grid--cols-4 { grid-template-columns: repeat(4, 1fr); }
.af-grid--cols-5 { grid-template-columns: repeat(5, 1fr); }
.af-grid--cols-6 { grid-template-columns: repeat(6, 1fr); }

@media (max-width: 1024px) { .af-grid--cols-6 { grid-template-columns: repeat(4, 1fr); } }
@media (max-width: 768px)  { .af-grid--cols-6, .af-grid--cols-5, .af-grid--cols-4 { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 480px)  { .af-grid { grid-template-columns: repeat(2, 1fr) !important; } }

/* ── Anime Card ─────────────────────────────────────────────── */
.af-card {
  position: relative;
  border-radius: var(--af-radius);
  overflow: hidden;
  background: var(--af-bg-card);
  border: 1px solid var(--af-border);
  transition: transform var(--af-transition), box-shadow var(--af-transition), border-color var(--af-transition);
  cursor: pointer;
}
.af-card:hover {
  transform: translateY(-4px) scale(1.02);
  box-shadow: var(--af-shadow-card), var(--af-shadow-glow);
  border-color: var(--af-accent);
}
.af-card__link { display: block; text-decoration: none; color: inherit; }
.af-card__poster {
  position: relative;
  aspect-ratio: 2/3;
  overflow: hidden;
}
.af-card__poster img {
  width: 100%; height: 100%;
  object-fit: cover;
  transition: transform 0.4s ease;
}
.af-card:hover .af-card__poster img { transform: scale(1.06); }
.af-card__hover {
  position: absolute; inset: 0;
  background: var(--af-bg-overlay);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 0.5rem;
  opacity: 0;
  transition: opacity var(--af-transition);
}
.af-card:hover .af-card__hover { opacity: 1; }
.af-card__body {
  padding: 0.6rem 0.75rem 0.75rem;
}
.af-card__title {
  font-size: 0.82rem; font-weight: 600;
  color: var(--af-text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin: 0 0 0.2rem;
}
.af-card__type {
  font-size: 0.7rem; color: var(--af-text-muted);
}
.af-card__score {
  font-size: 0.78rem; color: #ffd700; font-weight: 600;
}
.af-card__rank {
  position: absolute; top: 8px; left: 8px;
  background: var(--af-accent);
  color: #fff; font-size: 0.7rem; font-weight: 700;
  padding: 2px 7px; border-radius: var(--af-radius-pill);
  z-index: 2;
}

/* ── Badges ─────────────────────────────────────────────────── */
.af-badge {
  display: inline-block; padding: 2px 8px;
  border-radius: var(--af-radius-pill);
  font-size: 0.68rem; font-weight: 600; letter-spacing: 0.02em;
  line-height: 1.6;
}
.af-badge--type    { background: var(--af-accent); color: #fff; }
.af-badge--filler  { background: rgba(255,165,0,0.2); color: #ffa500; border: 1px solid #ffa500; }
.af-badge--quality { background: rgba(0,200,100,0.15); color: #00c864; border: 1px solid #00c864; }
.af-badge--lang    { background: rgba(108,99,255,0.15); color: var(--af-accent); border: 1px solid var(--af-accent); }

/* ── Buttons ────────────────────────────────────────────────── */
.af-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 0.55rem 1.25rem;
  border-radius: var(--af-radius-pill);
  font-size: 0.85rem; font-weight: 600;
  cursor: pointer; border: none; text-decoration: none;
  transition: all var(--af-transition);
  white-space: nowrap;
}
.af-btn--primary { background: var(--af-accent); color: #fff; }
.af-btn--primary:hover { background: var(--af-accent-hover); box-shadow: var(--af-shadow-glow); }
.af-btn--ghost { background: transparent; color: var(--af-text-primary); border: 1.5px solid var(--af-border); }
.af-btn--ghost:hover { border-color: var(--af-accent); color: var(--af-accent); }
.af-btn--outline { background: transparent; border: 1.5px solid var(--af-accent); color: var(--af-accent); }
.af-btn--outline:hover { background: var(--af-accent); color: #fff; }
.af-btn--sm { padding: 0.3rem 0.8rem; font-size: 0.75rem; }

/* ── Hero Slider ────────────────────────────────────────────── */
.af-hero { position: relative; overflow: hidden; }
.af-hero__slide {
  background-size: cover; background-position: center;
  display: flex; align-items: flex-end;
  min-height: 70vh;
}
.af-hero__overlay {
  position: absolute; inset: 0;
  background: linear-gradient(to right, rgba(0,0,0,0.85) 0%, rgba(0,0,0,0.3) 60%, transparent 100%),
              linear-gradient(to top, rgba(0,0,0,0.6) 0%, transparent 50%);
}
.af-hero__content {
  position: relative; z-index: 2;
  padding: clamp(1.5rem, 5vw, 4rem);
  max-width: 560px;
}
.af-hero__title {
  font-size: clamp(1.5rem, 4vw, 2.8rem);
  font-weight: 800; line-height: 1.2;
  color: #fff; margin: 0.5rem 0;
}
.af-hero__meta { display: flex; gap: 1rem; margin: 0.5rem 0; }
.af-hero__score { color: #ffd700; font-weight: 600; }
.af-hero__status { color: #00c864; font-size: 0.85rem; }
.af-hero__synopsis {
  color: rgba(255,255,255,0.8); font-size: 0.9rem; line-height: 1.6;
  margin: 0.75rem 0 1.25rem;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.af-hero__actions { display: flex; gap: 0.75rem; flex-wrap: wrap; }

/* ── Player ─────────────────────────────────────────────────── */
.af-player-wrap { background: #000; border-radius: var(--af-radius); overflow: hidden; }
.af-player__frame-wrap {
  position: relative; padding-top: 56.25%; /* 16:9 */
  background: #000;
}
.af-player__iframe {
  position: absolute; inset: 0; width: 100%; height: 100%;
  border: 0;
}
.af-player__sources {
  display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 16px;
  background: rgba(255,255,255,0.04);
  border-top: 1px solid var(--af-border);
}
.af-player__src {
  padding: 6px 14px; border-radius: var(--af-radius-pill);
  background: var(--af-bg-card); border: 1px solid var(--af-border);
  color: var(--af-text-secondary); font-size: 0.8rem; cursor: pointer;
  transition: all var(--af-transition);
  display: flex; align-items: center; gap: 5px;
}
.af-player__src:hover, .af-player__src--active {
  background: var(--af-accent); color: #fff; border-color: var(--af-accent);
}
.af-player__placeholder {
  aspect-ratio: 16/9; display: flex; align-items: center; justify-content: center;
  background: var(--af-bg-card); color: var(--af-text-muted); border-radius: var(--af-radius);
}

/* ── Episode List ───────────────────────────────────────────── */
.af-episode-list { }
.af-episode-list__header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1rem;
}
.af-episode-list__count { color: var(--af-text-secondary); font-size: 0.88rem; }
.af-episode-list__sort { display: flex; gap: 6px; }
.af-episode-list__sort-btn {
  padding: 4px 12px; border-radius: var(--af-radius-pill); border: 1px solid var(--af-border);
  background: transparent; color: var(--af-text-muted); cursor: pointer; font-size: 0.75rem;
  transition: all var(--af-transition);
}
.af-episode-list__sort-btn.active { background: var(--af-accent); border-color: var(--af-accent); color: #fff; }
.af-episode-list__grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 8px;
}
.af-episode-card {
  display: flex; flex-direction: column; align-items: center;
  padding: 8px; border-radius: var(--af-radius-sm);
  background: var(--af-bg-card); border: 1px solid var(--af-border);
  text-decoration: none; color: var(--af-text-secondary); font-size: 0.78rem;
  transition: all var(--af-transition);
}
.af-episode-card:hover, .af-episode-card--active {
  background: var(--af-accent); border-color: var(--af-accent); color: #fff;
}
.af-episode-card__num { font-weight: 700; font-size: 0.85rem; }
.af-episode-card__title { font-size: 0.68rem; text-align: center; margin-top: 2px; opacity: 0.75; }

/* ── Schedule ───────────────────────────────────────────────── */
.af-schedule__tabs {
  display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px;
  margin-bottom: 1rem; scrollbar-width: none;
}
.af-schedule__tab {
  padding: 6px 18px; border-radius: var(--af-radius-pill); border: 1px solid var(--af-border);
  background: transparent; color: var(--af-text-muted); cursor: pointer; white-space: nowrap;
  transition: all var(--af-transition);
}
.af-schedule__tab--active { background: var(--af-accent); border-color: var(--af-accent); color: #fff; }
.af-schedule__panel { display: none; }
.af-schedule__panel--active { display: block; }
.af-schedule__item {
  display: flex; align-items: center; gap: 12px; padding: 10px;
  border-radius: var(--af-radius-sm); border: 1px solid var(--af-border);
  margin-bottom: 8px; background: var(--af-bg-card); transition: all var(--af-transition);
}
.af-schedule__item:hover { border-color: var(--af-accent); }
.af-schedule__thumb { width: 48px; height: 64px; object-fit: cover; border-radius: 6px; }
.af-schedule__info { display: flex; flex-direction: column; gap: 4px; }
.af-schedule__title { color: var(--af-text-primary); font-size: 0.85rem; font-weight: 600; text-decoration: none; }
.af-schedule__title:hover { color: var(--af-accent); }
.af-schedule__time { font-size: 0.75rem; color: var(--af-text-muted); }
.af-schedule__empty { color: var(--af-text-muted); font-size: 0.88rem; padding: 1rem 0; }

/* ── Genre Chips ────────────────────────────────────────────── */
.af-genre-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.af-genre-chip {
  padding: 7px 16px; border-radius: var(--af-radius-pill);
  background: var(--af-bg-card); border: 1px solid var(--af-border);
  color: var(--af-text-secondary); font-size: 0.82rem;
  text-decoration: none; transition: all var(--af-transition);
  display: flex; align-items: center; gap: 6px;
}
.af-genre-chip:hover { background: var(--af-accent); border-color: var(--af-accent); color: #fff; }
.af-genre-chip__count {
  background: rgba(255,255,255,0.12); border-radius: 999px;
  padding: 1px 7px; font-size: 0.7rem;
}

/* ── Search Box ─────────────────────────────────────────────── */
.af-search-wrap { position: relative; max-width: 500px; }
.af-search-input {
  width: 100%; padding: 12px 48px 12px 20px;
  border-radius: var(--af-radius-pill); border: 1.5px solid var(--af-border);
  background: var(--af-bg-card); color: var(--af-text-primary);
  font-size: 0.9rem; outline: none;
  transition: border-color var(--af-transition);
}
.af-search-input:focus { border-color: var(--af-accent); }
.af-search-input::placeholder { color: var(--af-text-muted); }
.af-search-btn {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  background: var(--af-accent); border: none; color: #fff;
  padding: 6px 10px; border-radius: var(--af-radius-pill); cursor: pointer;
}
.af-search-results {
  position: absolute; top: calc(100% + 8px); left: 0; right: 0;
  background: #1a1a24; border: 1px solid var(--af-border); border-radius: var(--af-radius);
  box-shadow: var(--af-shadow-card); z-index: 9999; overflow: hidden;
}
.af-search-results__item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; text-decoration: none; color: var(--af-text-primary);
  border-bottom: 1px solid var(--af-border); transition: background var(--af-transition);
}
.af-search-results__item:last-child { border-bottom: none; }
.af-search-results__item:hover { background: var(--af-bg-card-hover); }
.af-search-results__thumb { width: 36px; height: 48px; object-fit: cover; border-radius: 4px; }
.af-search-results__info { flex: 1; }
.af-search-results__title { font-size: 0.85rem; font-weight: 600; }
.af-search-results__meta { font-size: 0.72rem; color: var(--af-text-muted); }

/* ── Ad Slots (layout-safe) ─────────────────────────────────── */
.af-ad-slot {
  min-height: 0; /* collapses cleanly if empty */
  transition: min-height 0.2s;
}
.af-ad-slot:has(.af-ad) { min-height: 90px; }
.af-ad { display: flex; justify-content: center; align-items: center; width: 100%; overflow: hidden; }
.af-ad-floating {
  position: fixed; bottom: 24px; right: 24px; z-index: 9990;
  background: var(--af-bg-glass); backdrop-filter: blur(12px);
  border: 1px solid var(--af-border); border-radius: var(--af-radius);
  box-shadow: var(--af-shadow-card); padding: 12px;
  animation: af-slide-up 0.4s ease;
}
.af-ad-floating__close {
  position: absolute; top: 6px; right: 8px;
  background: none; border: none; color: var(--af-text-muted);
  font-size: 1.1rem; cursor: pointer; line-height: 1;
}
.af-ad-sticky-mobile {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 9989;
  background: var(--af-bg-glass); backdrop-filter: blur(8px);
  border-top: 1px solid var(--af-border); padding: 8px;
  display: flex; justify-content: center;
}

/* ── Sidebar Suggestions ────────────────────────────────────── */
.af-sidebar-suggestions { }
.af-sidebar-suggestions__title { font-size: 1rem; font-weight: 700; margin: 0 0 1rem; color: var(--af-text-primary); }
.af-sidebar-suggestions__item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0; border-bottom: 1px solid var(--af-border);
  text-decoration: none; transition: all var(--af-transition);
}
.af-sidebar-suggestions__item:last-child { border-bottom: none; }
.af-sidebar-suggestions__item:hover .af-sidebar-suggestions__name { color: var(--af-accent); }
.af-sidebar-suggestions__thumb { width: 44px; height: 60px; object-fit: cover; border-radius: 6px; flex-shrink: 0; }
.af-sidebar-suggestions__info { flex: 1; }
.af-sidebar-suggestions__name { font-size: 0.82rem; font-weight: 600; color: var(--af-text-primary); display: block; transition: color var(--af-transition); }
.af-sidebar-suggestions__score { font-size: 0.72rem; color: #ffd700; }

/* ── Load More ───────────────────────────────────────────────── */
.af-load-more-wrap { display: flex; justify-content: center; margin-top: 2rem; }
.af-load-more { min-width: 160px; }
.af-load-more.is-loading { opacity: 0.6; pointer-events: none; }

/* ── Infinite Scroll Sentinel ────────────────────────────────── */
.af-scroll-sentinel { height: 1px; }

/* ── Watchlist Button ────────────────────────────────────────── */
.af-watchlist-toggle.is-added { background: #00c864; border-color: #00c864; color: #fff; }

/* ── Animations ─────────────────────────────────────────────── */
@keyframes af-slide-up {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes af-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.af-fade-in { animation: af-fade-in 0.3s ease; }

/* ── Swiper Overrides ────────────────────────────────────────── */
.af-trending-row__slider { overflow: hidden; position: relative; }
.swiper-button-next, .swiper-button-prev {
  color: var(--af-accent) !important;
  --swiper-navigation-size: 22px;
}
.swiper-pagination-bullet { background: var(--af-text-muted) !important; }
.swiper-pagination-bullet-active { background: var(--af-accent) !important; }

/* ── Utility Classes ─────────────────────────────────────────── */
.af-sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }
.af-text-accent { color: var(--af-accent); }
.af-text-muted { color: var(--af-text-muted); }
.af-mt-0 { margin-top: 0; }
.af-mb-0 { margin-bottom: 0; }
