/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-card: #1a1a2e;
  --bg-card-hover: #222240;
  --accent: #e63946;
  --accent-glow: rgba(230, 57, 70, 0.4);
  --accent-light: #ff6b6b;
  --blue: #1d3557;
  --blue-light: #457b9d;
  --gold: #f4a261;
  --text-primary: #f1faee;
  --text-secondary: #a8b2c1;
  --text-dim: #5a6577;
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --focus-ring: 0 0 0 3px var(--accent), 0 0 20px var(--accent-glow);
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Heebo', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  direction: rtl;
  overflow-x: hidden;
}

/* ── Loading Screen ─────────────────────────────────────────────────────── */
.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  transition: opacity 0.5s ease;
}

.loading-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}

.loading-logo {
  font-size: 5rem;
  animation: float 2s ease-in-out infinite;
}

@keyframes float {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-15px);
  }
}

.loading-text {
  font-size: 1.3rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(230, 57, 70, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── Header ──────────────────────────────────────────────────────────────── */
header {
  background: linear-gradient(180deg, rgba(10, 10, 15, 0.98) 0%, rgba(10, 10, 15, 0.8) 70%, transparent 100%);
  padding: 18px 40px;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
}

.header-content {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  font-size: 2rem;
  font-weight: 900;
  background: linear-gradient(135deg, var(--accent) 0%, var(--gold) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -1px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.search-container {
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-sm);
  overflow: hidden;
  transition: all var(--transition);
}

.search-container:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 15px var(--accent-glow);
}

.search-input {
  width: 100px;
  padding: 8px 12px;
  background: none;
  border: none;
  color: var(--text-primary);
  font-family: 'Heebo', sans-serif;
  font-size: 0.95rem;
  outline: none;
  direction: rtl;
  -moz-appearance: textfield;
}

.search-input::-webkit-inner-spin-button,
.search-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
}

.search-input::placeholder {
  color: var(--text-dim);
}

.search-btn {
  padding: 8px 12px;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1rem;
  transition: color var(--transition);
}

.search-btn:hover {
  color: var(--accent);
}

/* ── Continue Watching Section ───────────────────────────────────────────── */
.continue-section {
  margin-top: 70px;
  padding: 60px 40px 40px;
  background: linear-gradient(180deg, var(--blue) 0%, var(--bg-primary) 100%);
  position: relative;
  overflow: hidden;
}

.continue-section::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 70% 20%, rgba(230, 57, 70, 0.15) 0%, transparent 60%);
  pointer-events: none;
}

.continue-inner {
  max-width: 1400px;
  margin: 0 auto;
}

.continue-label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 2px;
}

.continue-title {
  font-size: 2.5rem;
  font-weight: 900;
  margin: 10px 0 16px;
  text-shadow: 0 2px 20px rgba(0, 0, 0, 0.5);
}

.continue-progress-bar {
  width: 300px;
  height: 4px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  margin-bottom: 24px;
  overflow: hidden;
}

.continue-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width var(--transition);
}

.btn-play {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 14px 36px;
  font-size: 1.15rem;
  font-weight: 700;
  font-family: 'Heebo', sans-serif;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: 0 4px 20px var(--accent-glow);
}

.btn-play:hover {
  background: var(--accent-light);
  transform: scale(1.05);
  box-shadow: 0 6px 30px var(--accent-glow);
}

.play-icon {
  font-size: 1.1em;
}

/* ── D-pad / TV Focus Styles ─────────────────────────────────────────────── */
.focusable:focus {
  outline: none;
  box-shadow: var(--focus-ring);
  transform: scale(1.05);
}

.episode-card:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
  transform: translateY(-6px) scale(1.02);
  background: var(--bg-card-hover);
}

.episode-card:focus .card-thumbnail::after {
  opacity: 1;
  transform: scale(1);
}

.episode-card:focus .card-ep-number {
  opacity: 0;
}

/* ── Episodes Section ────────────────────────────────────────────────────── */
.episodes-section {
  padding: 30px 40px 60px;
  max-width: 1400px;
  margin: 0 auto;
}

#home-view:not(:has(.continue-section[style*="block"])) .episodes-section {
  padding-top: 100px;
}

.section-title {
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: 24px;
  color: var(--text-primary);
}

.episodes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 20px;
}

/* ── Episode Card ────────────────────────────────────────────────────────── */
.episode-card {
  position: relative;
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: all var(--transition);
  border: 2px solid transparent;
}

.episode-card:hover {
  background: var(--bg-card-hover);
  transform: translateY(-6px);
  border-color: rgba(230, 57, 70, 0.3);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4), 0 0 20px var(--accent-glow);
}

.episode-card:active {
  transform: translateY(-2px);
}

.card-thumbnail {
  width: 100%;
  aspect-ratio: 16/9;
  background: linear-gradient(135deg, var(--blue) 0%, var(--bg-card) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.card-thumbnail::after {
  content: '▶';
  font-size: 2rem;
  color: rgba(255, 255, 255, 0.7);
  opacity: 0;
  transform: scale(0.8);
  transition: all var(--transition);
}

.episode-card:hover .card-thumbnail::after {
  opacity: 1;
  transform: scale(1);
}

.card-ep-number {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 2.5rem;
  font-weight: 900;
  color: rgba(255, 255, 255, 0.12);
  transition: opacity var(--transition);
}

.episode-card:hover .card-ep-number {
  opacity: 0;
}

.card-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: rgba(255, 255, 255, 0.1);
}

.card-progress-fill {
  height: 100%;
  background: var(--accent);
  transition: width var(--transition);
}

.card-body {
  padding: 12px 14px;
}

.card-title {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.card-status {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.card-status.completed {
  color: var(--gold);
}

.card-badge-completed {
  position: absolute;
  top: 10px;
  left: 10px;
  background: rgba(244, 162, 97, 0.9);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
}

/* ── Player View ─────────────────────────────────────────────────────────── */
#player-view {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 200;
}

.player-container {
  width: 100%;
  height: 100%;
  position: relative;
}

#video-player {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

/* ── Buffering Indicator ─────────────────────────────────────────────────── */
.buffering-indicator {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 10;
}

.buffering-spinner {
  width: 60px;
  height: 60px;
  border: 4px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ── Controls Overlay ────────────────────────────────────────────────────── */
.controls-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  opacity: 1;
  transition: opacity 0.4s ease;
  cursor: default;
}

.controls-overlay.hidden {
  opacity: 0;
  cursor: none;
}

.controls-overlay.hidden * {
  pointer-events: none;
}

.controls-top {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 20px 30px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.8) 0%, transparent 100%);
}

.btn-back {
  padding: 8px 20px;
  font-size: 1rem;
  font-weight: 600;
  font-family: 'Heebo', sans-serif;
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  backdrop-filter: blur(10px);
}

.btn-back:hover {
  background: rgba(255, 255, 255, 0.2);
}

.player-title {
  font-size: 1.3rem;
  font-weight: 700;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

/* Center controls */
.controls-center {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 40px;
  flex: 1;
}

.btn-play-center {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: rgba(230, 57, 70, 0.85);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  box-shadow: 0 4px 30px rgba(230, 57, 70, 0.4);
  backdrop-filter: blur(10px);
}

.btn-play-center:hover {
  background: var(--accent);
  transform: scale(1.1);
}

.play-icon-big {
  font-size: 2rem;
  color: #fff;
  margin-right: -3px;
}

.btn-skip-back,
.btn-skip-forward {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: #fff;
  font-family: 'Heebo', sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 12px;
  border-radius: 50%;
  width: 56px;
  height: 56px;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition);
  backdrop-filter: blur(10px);
}

.btn-skip-back:hover,
.btn-skip-forward:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(1.1);
}

.btn-skip-back svg,
.btn-skip-forward svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.skip-label {
  font-size: 0.65rem;
  opacity: 0.8;
}

/* Bottom controls */
.controls-bottom {
  padding: 0 30px 20px;
  background: linear-gradient(0deg, rgba(0, 0, 0, 0.85) 0%, transparent 100%);
  padding-top: 60px;
}

.seek-bar-container {
  position: relative;
  height: 20px;
  display: flex;
  align-items: center;
  margin-bottom: 10px;
  direction: ltr;
}

.seek-bar {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  outline: none;
  cursor: pointer;
  position: relative;
  z-index: 2;
  transition: height 0.15s ease;
}

.seek-bar:hover {
  height: 8px;
}

.seek-bar::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 10px var(--accent-glow);
  transition: all 0.15s ease;
}

.seek-bar:hover::-webkit-slider-thumb {
  width: 20px;
  height: 20px;
}

.seek-progress {
  position: absolute;
  top: 50%;
  left: 0;
  height: 4px;
  background: var(--accent);
  border-radius: 4px;
  transform: translateY(-50%);
  pointer-events: none;
  z-index: 1;
  transition: height 0.15s ease;
}

.seek-bar:hover~.seek-progress {
  height: 8px;
}

.controls-bottom-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.controls-left,
.controls-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.time-display {
  font-size: 0.9rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.85);
  font-variant-numeric: tabular-nums;
  direction: ltr;
}

.btn-nav {
  padding: 8px 18px;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: 'Heebo', sans-serif;
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  backdrop-filter: blur(10px);
}

.btn-nav:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(1.05);
}

.btn-next-highlight {
  background: var(--accent);
  border-color: var(--accent);
}

.btn-next-highlight:hover {
  background: var(--accent-light);
  border-color: var(--accent-light);
}

.btn-fullscreen {
  width: 42px;
  height: 42px;
  font-size: 1.3rem;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-sm);
  color: #fff;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(10px);
}

.btn-fullscreen:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ── Next Episode Overlay ────────────────────────────────────────────────── */
.next-episode-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.next-episode-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.next-episode-label {
  font-size: 1rem;
  color: var(--text-secondary);
}

.next-episode-countdown {
  font-size: 4rem;
  font-weight: 900;
  color: var(--accent);
  line-height: 1;
}

.next-episode-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.next-episode-actions {
  display: flex;
  gap: 16px;
}

/* ── Inactivity Modal ────────────────────────────────────────────────────── */
.inactivity-modal {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
}

.inactivity-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(10px);
}

.inactivity-dialog {
  position: relative;
  z-index: 1;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 48px;
  background: var(--bg-secondary);
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
  animation: scaleIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes scaleIn {
  from {
    transform: scale(0.9);
    opacity: 0;
  }

  to {
    transform: scale(1);
    opacity: 1;
  }
}

.inactivity-icon {
  font-size: 4rem;
}

.inactivity-dialog h2 {
  font-size: 2rem;
  font-weight: 900;
}

.inactivity-dialog p {
  color: var(--text-secondary);
  font-size: 1.1rem;
}

.btn-still-watching {
  margin-top: 8px;
  padding: 16px 48px;
  font-size: 1.3rem;
}

/* ── Install Banner ──────────────────────────────────────────────────────── */
.install-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 300;
  background: linear-gradient(135deg, var(--accent) 0%, #c62828 100%);
  padding: 14px 24px;
  animation: slideDown 0.5s ease;
}

@keyframes slideDown {
  from {
    transform: translateY(-100%);
  }

  to {
    transform: translateY(0);
  }
}

.install-banner-content {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  font-size: 1rem;
  font-weight: 500;
}

.btn-install {
  padding: 8px 24px;
  font-size: 0.95rem;
  font-weight: 700;
  font-family: 'Heebo', sans-serif;
  color: var(--accent);
  background: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
}

.btn-install:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.btn-install-dismiss {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.7);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 8px;
  transition: color var(--transition);
}

.btn-install-dismiss:hover {
  color: #fff;
}

/* ── Empty State ─────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-secondary);
}

.empty-state h3 {
  font-size: 1.5rem;
  margin-bottom: 12px;
  color: var(--text-primary);
}

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--bg-card);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--bg-card-hover);
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  header {
    padding: 14px 20px;
  }

  .logo {
    font-size: 1.5rem;
  }

  .continue-section {
    padding: 50px 20px 30px;
  }

  .continue-title {
    font-size: 1.8rem;
  }

  .continue-progress-bar {
    width: 200px;
  }

  .episodes-section {
    padding: 20px 20px 40px;
  }

  .episodes-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 14px;
  }

  .controls-top {
    padding: 14px 16px;
  }

  .controls-bottom {
    padding: 0 16px 14px;
  }

  .btn-nav {
    padding: 6px 12px;
    font-size: 0.85rem;
  }

  .player-title {
    font-size: 1rem;
  }

  .search-input {
    width: 70px;
  }
}

@media (min-width: 1600px) {
  .episodes-grid {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  }
}

/* ── TV Mode (large screens & lean-back) ─────────────────────────────────── */
@media (min-width: 1920px) {
  html {
    font-size: 20px;
  }

  .episodes-grid {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 28px;
  }

  .btn-play {
    padding: 18px 44px;
    font-size: 1.3rem;
  }

  .btn-nav {
    padding: 12px 24px;
    font-size: 1.1rem;
  }

  .btn-play-center {
    width: 100px;
    height: 100px;
  }

  .play-icon-big {
    font-size: 2.5rem;
  }

  .episode-card {
    border-width: 3px;
  }

  .episode-card:focus {
    box-shadow: 0 0 0 4px var(--accent), 0 0 30px var(--accent-glow);
  }
}