/* ---------- Reset and base ---------- */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  background: #0e0e10;
  color: #fff;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
}

img {
  display: block;
}

button,
input,
select {
  font-family: inherit;
}

/* default focus ring is invisible on this dark bg */
:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- Header ---------- */

header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  padding: 16px 32px;
  border-bottom: 1px solid #1c1c20;
  position: sticky;
  top: 0;
  background: rgba(14, 14, 16, 0.92);
  backdrop-filter: blur(8px);
  z-index: 50;
}

.site-title {
  text-decoration: none;
}

.site-title h1 {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.nav-link {
  text-decoration: none;
  color: #aaa;
  font-size: 0.95rem;
  padding: 6px 0;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}

.nav-link:hover {
  color: #fff;
}

.nav-link.active {
  color: #fff;
  border-color: #fff;
}

.search-form {
  flex: 1;
  max-width: 420px;
}

.search-form input {
  width: 100%;
  background: #1a1a1d;
  border: 1px solid #2a2a30;
  border-radius: 6px;
  padding: 9px 12px;
  color: #fff;
  font-size: 0.95rem;
}

.search-form input::placeholder {
  color: #777;
}

.search-form input:focus {
  outline: none;
  border-color: #555;
  background: #1f1f22;
}

.type-toggle {
  display: flex;
  gap: 4px;
  flex-basis: 100%;
}

.type-toggle button {
  background: transparent;
  color: #aaa;
  border: 1px solid #2a2a30;
  padding: 6px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.type-toggle button:hover {
  color: #fff;
  border-color: #555;
}

.type-toggle button.active {
  background: #fff;
  color: #000;
  border-color: #fff;
}

/* ---------- Layout ---------- */

main {
  padding: 24px 32px 48px;
}

/* ---------- Generic grid (search, browse, similar) ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
}

/* ---------- Card ---------- */

.card {
  display: block;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  border-radius: 6px;
  overflow: hidden;
  background: #18181b;
  transition: transform 0.18s, box-shadow 0.18s;
}

.card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
}

.card-poster {
  position: relative;
}

.card img {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
}

/* poster corner tags: rating (right), cam flag (left) */
.card-rating,
.card-quality {
  position: absolute;
  top: 6px;
  font-size: 0.66rem;
  font-weight: 600;
  line-height: 1;
  padding: 2px 5px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.72);
}

.card-rating {
  right: 6px;
  color: #ffd54a;
}

/* only set on cam-quality movies (see resolveQualityBadge) */
.card-quality {
  left: 6px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #ff7a7a;
}

/* hidden until the lookup resolves */
.card-quality.pending {
  display: none;
}

.card-play {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  color: #fff;
  background: rgba(0, 0, 0, 0.35);
  opacity: 0;
  transition: opacity 0.18s;
  pointer-events: none;
}

.card:hover .card-play {
  opacity: 1;
}

.card .title {
  padding: 8px 10px 10px;
  font-size: 0.9rem;
  line-height: 1.3;
  color: #ddd;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta {
  padding: 0 8px 8px;
  font-size: 0.72rem;
  color: #8f8f96;
}

/* Skeleton placeholder while data loads. */
.card.skeleton {
  cursor: default;
  background: linear-gradient(90deg, #18181b 0%, #232326 50%, #18181b 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  height: 280px;
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ---------- Hero (home page) ---------- */

.hero {
  position: relative;
  height: 56vh;
  min-height: 320px;
  max-height: 520px;
  margin: -24px -32px 32px;
  overflow: hidden;
  background: #0a0a0c;
}

.hero.loading {
  background: #18181b;
}

.hero-bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center 25%;
}

.hero-fade {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(to right, rgba(14,14,16,0.92) 0%, rgba(14,14,16,0.4) 40%, rgba(14,14,16,0) 70%),
    linear-gradient(to top, rgba(14,14,16,1) 0%, rgba(14,14,16,0) 60%);
}

.hero-content {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 32px;
  max-width: 720px;
}

.hero-content h2 {
  font-size: 2.2rem;
  font-weight: 700;
  margin-bottom: 12px;
  line-height: 1.1;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.7);
}

.hero-content p {
  font-size: 1rem;
  line-height: 1.5;
  color: #ddd;
  margin-bottom: 18px;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.7);
}

.hero-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-block;
  background: rgba(60, 60, 65, 0.85);
  color: #fff;
  text-decoration: none;
  padding: 9px 18px;
  border-radius: 4px;
  font-size: 0.95rem;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s;
}

.btn:hover {
  background: rgba(80, 80, 85, 0.9);
}

.btn-primary {
  background: #fff;
  color: #000;
}

.btn-primary:hover {
  background: #ddd;
}

/* ---------- Rows (home page) ---------- */

.row {
  margin-bottom: 32px;
}

.row h2 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 12px;
  color: #ddd;
}

.row-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.row-head h2 {
  margin-bottom: 0;
}

.btn-text {
  background: none;
  border: 0;
  color: #9a9a9a;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 2px 4px;
}

.btn-text:hover {
  color: #fff;
}

.row-scroller {
  position: relative;
}

.row-arrow {
  position: absolute;
  top: 0;
  bottom: 8px;
  width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  cursor: pointer;
  font-size: 1.8rem;
  color: #fff;
  background: rgba(14, 14, 16, 0.7);
  opacity: 0;
  pointer-events: none; /* don't let the hidden arrow cover card controls */
  transition: opacity 0.15s;
  z-index: 2;
}

.row-arrow.left {
  left: 0;
  border-radius: 6px 0 0 6px;
}

.row-arrow.right {
  right: 0;
  border-radius: 0 6px 6px 0;
}

/* show on hover, but only the directions we can actually scroll (JS sets disabled) */
.row-scroller:hover .row-arrow:not([disabled]) {
  opacity: 1;
  pointer-events: auto;
}

.row-arrow:hover {
  background: rgba(14, 14, 16, 0.92);
}

.row-cards {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 8px;
  scroll-behavior: smooth;
}

.row-cards::-webkit-scrollbar {
  height: 6px;
}

.row-cards::-webkit-scrollbar-track {
  background: transparent;
}

.row-cards::-webkit-scrollbar-thumb {
  background: #2a2a30;
  border-radius: 3px;
}

.row-cards .card {
  flex: 0 0 170px;
}

.row-status {
  color: #9a9a9a;
  padding: 8px 0;
  font-size: 0.9rem;
}

/* Continue Watching cards wrap a link plus a remove button. */
.continue-card {
  position: relative;
}

.continue-link {
  display: block;
  text-decoration: none;
  color: inherit;
}

.continue-remove {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
  z-index: 2;
}

.continue-card:hover .continue-remove,
.continue-remove:focus-visible {
  opacity: 1;
}

.continue-remove:hover {
  background: rgba(220, 60, 60, 0.9);
}

/* ---------- Detail page ---------- */

.detail {
  max-width: 1100px;
  margin: 0 auto;
}

.detail .backdrop {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 20px;
  aspect-ratio: 16 / 9;
  background: #111;
}

.detail .backdrop img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.55;
}

.detail .backdrop-empty {
  background: linear-gradient(135deg, #1a1a1f, #101013);
}

.detail .backdrop-text {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 24px 28px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.85));
}

.detail h2 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.detail .meta {
  color: #ccc;
  font-size: 0.9rem;
}

.detail-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 18px;
}

.tag {
  display: inline-block;
  background: #1d1d21;
  color: #ccc;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 0.82rem;
  text-decoration: none;
  border: 1px solid #2a2a30;
  transition: background 0.15s, color 0.15s;
}

.tag:hover {
  background: #2a2a30;
  color: #fff;
}

.detail .overview {
  line-height: 1.65;
  max-width: 760px;
  font-size: 1rem;
  color: #ddd;
  margin-bottom: 36px;
}

.similar-section h3 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 14px;
  color: #ddd;
}

/* ---------- Search ---------- */

.search-heading {
  font-size: 1.05rem;
  font-weight: 600;
  color: #ddd;
  margin-bottom: 16px;
}

/* ---------- Browse / filters ---------- */

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-end;
  padding: 14px 16px;
  background: #16161a;
  border: 1px solid #1f1f24;
  border-radius: 8px;
  margin-bottom: 18px;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.filter-group label {
  font-size: 0.78rem;
  color: #9a9a9a;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.filter-group select,
.filter-group input {
  background: #1d1d21;
  color: #fff;
  border: 1px solid #2a2a30;
  border-radius: 5px;
  padding: 7px 10px;
  font-size: 0.92rem;
  min-width: 130px;
}

.filter-group select:focus,
.filter-group input:focus {
  outline: none;
  border-color: #555;
}

.seg {
  display: inline-flex;
  border: 1px solid #2a2a30;
  border-radius: 5px;
  overflow: hidden;
}

.seg button {
  background: #1d1d21;
  color: #ccc;
  border: 0;
  padding: 7px 14px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.seg button + button {
  border-left: 1px solid #2a2a30;
}

.seg button:hover {
  background: #25252a;
  color: #fff;
}

.seg button.active {
  background: #fff;
  color: #000;
}

.btn-clear {
  background: transparent;
  color: #aaa;
  border: 1px solid #2a2a30;
  border-radius: 5px;
  padding: 7px 14px;
  cursor: pointer;
  font-size: 0.9rem;
  margin-left: auto;
}

.btn-clear:hover {
  color: #fff;
  border-color: #555;
}

.genre-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 18px;
}

.genre-chip {
  background: #1a1a1d;
  color: #bbb;
  border: 1px solid #2a2a30;
  border-radius: 999px;
  padding: 5px 13px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.genre-chip:hover {
  color: #fff;
  border-color: #555;
}

.genre-chip.active {
  background: #fff;
  color: #000;
  border-color: #fff;
}

.load-more-wrap {
  display: flex;
  justify-content: center;
  margin: 28px 0 0;
}

#load-more {
  min-width: 160px;
}

#load-more[disabled] {
  opacity: 0.6;
  cursor: default;
}

/* ---------- Watch page (player) ---------- */

.player {
  max-width: 1400px;
  margin: 0 auto;
}

.player-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
}

.player-frame iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.player-info {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 12px;
  margin: 18px 4px 14px;
}

.player-info h2 {
  font-size: 1.4rem;
  font-weight: 700;
}

.player-subtitle {
  color: #aaa;
  font-size: 0.92rem;
  margin-top: 2px;
}

.back-link {
  color: #aaa;
  text-decoration: none;
  font-size: 0.9rem;
}

.back-link:hover {
  color: #fff;
}

.player-controls {
  background: #16161a;
  border: 1px solid #1f1f24;
  border-radius: 8px;
  padding: 14px 16px;
}

.control-group {
  margin-bottom: 14px;
}

.control-group:last-child {
  margin-bottom: 0;
}

.control-label {
  display: block;
  font-size: 0.78rem;
  color: #9a9a9a;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}

.control-hint {
  display: inline-block;
  color: #9a9a9a;
  font-size: 0.82rem;
  margin-left: 6px;
}

.server-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-bottom: 8px;
}

.control-count {
  display: inline-block;
  background: #2a2a30;
  color: #aaa;
  font-size: 0.7rem;
  padding: 1px 7px;
  border-radius: 999px;
  margin-left: 4px;
  vertical-align: middle;
  text-transform: none;
  letter-spacing: 0;
}

.player-info-actions {
  display: flex;
  gap: 16px;
  align-items: center;
}

.server-btn {
  background: #1d1d21;
  color: #ddd;
  border: 1px solid #2a2a30;
  border-radius: 4px;
  padding: 5px 11px;
  cursor: pointer;
  font-size: 0.82rem;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.ep-btn {
  background: #1d1d21;
  color: #ddd;
  border: 1px solid #2a2a30;
  border-radius: 4px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 0.86rem;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.server-btn:hover,
.ep-btn:hover {
  background: #25252a;
  color: #fff;
}

.server-btn.active,
.ep-btn.active {
  background: #fff;
  color: #000;
  border-color: #fff;
}

.season-select {
  background: #1d1d21;
  color: #fff;
  border: 1px solid #2a2a30;
  border-radius: 4px;
  padding: 7px 10px;
  font-size: 0.9rem;
  margin-bottom: 12px;
  margin-right: 12px;
}

.ep-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ep-list--compact .ep-btn {
  min-width: 40px;
  text-align: center;
}

/* When episode names are available, lay them out as a scrollable list. */
.ep-list--named {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 6px;
  max-height: 320px;
  overflow-y: auto;
  padding-right: 4px;
}

.ep-list--named .ep-btn {
  display: flex;
  align-items: baseline;
  gap: 8px;
  text-align: left;
}

.ep-num {
  color: #9a9a9a;
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto;
}

.ep-btn.active .ep-num {
  color: #000;
}

.ep-name {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* episodes that haven't aired yet: visible but not selectable */
.ep-btn.upcoming {
  opacity: 0.45;
  cursor: not-allowed;
}

.ep-btn.upcoming:hover {
  background: #1d1d21;
  color: #ddd;
  border-color: #2a2a30;
}

/* tag on the newest available episode */
.ep-new {
  flex: 0 0 auto;
  align-self: center;
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #6fd08c;
  border: 1px solid currentColor;
  border-radius: 3px;
  padding: 0 4px;
}

.ep-btn.active .ep-new {
  color: #000;
}

/* ---------- Episode prev/next nav ---------- */

.episode-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 14px 4px 0;
}

.episode-nav-label {
  flex: 1;
  text-align: center;
  color: #ddd;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn:disabled {
  opacity: 0.4;
  cursor: default;
  pointer-events: none;
}

/* ---------- Footer ---------- */

.site-footer {
  border-top: 1px solid #1c1c20;
  padding: 24px 32px 40px;
  color: #7d7d85;
  font-size: 0.8rem;
  line-height: 1.5;
  max-width: 900px;
}

.site-footer p + p {
  margin-top: 6px;
}

/* ---------- Mobile ---------- */

@media (max-width: 720px) {
  /* swipe to scroll on touch; arrows aren't reachable anyway */
  .row-arrow {
    display: none;
  }

  .site-footer {
    padding: 20px 16px 32px;
  }

  .ep-list--named {
    grid-template-columns: 1fr;
  }

  header {
    padding: 12px 16px;
    gap: 10px;
  }

  .site-title h1 {
    font-size: 1.2rem;
  }

  .search-form {
    flex-basis: 100%;
    max-width: 100%;
    order: 10;
  }

  main {
    padding: 16px 16px 40px;
  }

  .hero {
    margin: -16px -16px 24px;
    height: 50vh;
    min-height: 280px;
  }

  .hero-content {
    padding: 20px;
  }

  .hero-content h2 {
    font-size: 1.6rem;
  }

  .hero-content p {
    font-size: 0.92rem;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 10px;
  }

  .row-cards .card {
    flex: 0 0 130px;
  }

  .card.skeleton {
    height: 200px;
  }

  .detail h2 {
    font-size: 1.4rem;
  }

  .detail .backdrop-text {
    padding: 16px;
  }

  .filter-bar {
    gap: 10px;
    padding: 12px;
  }

  .btn-clear {
    margin-left: 0;
  }

  .player-info h2 {
    font-size: 1.1rem;
  }
}
