:root {
  --bg: #0b0c10;
  --bg-elev: #16181d;
  --bg-elev-2: #1f2229;
  --text: #eef0f3;
  --text-dim: #9aa1ac;
  --accent: #f2c94c;
  --accent-2: #5b8def;
  --danger: #e0575b;
  --radius: 10px;
  --shadow: 0 4px 20px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 24px;
  background: rgba(11,12,16,0.9);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid #23262d;
  flex-wrap: wrap;
}

.brand {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}

.searchbox { flex: 1; min-width: 200px; }

.searchbox input {
  width: 100%;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid #2a2d35;
  background: var(--bg-elev);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
}
.searchbox input:focus { border-color: var(--accent-2); }

.genreSelect select {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #2a2d35;
  background: var(--bg-elev);
  color: var(--text);
  font-size: 0.9rem;
}

main { max-width: 1200px; margin: 0 auto; padding: 24px; }

h1#sectionTitle {
  font-size: 1.4rem;
  margin: 8px 0 20px;
  font-weight: 600;
}

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

.card {
  background: var(--bg-elev);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: var(--shadow);
}
.card:hover { transform: translateY(-4px); box-shadow: 0 8px 28px rgba(0,0,0,0.55); }

.card .poster {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  background: var(--bg-elev-2);
  display: block;
}

.card .info { padding: 10px 12px 12px; }
.card .title {
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.25;
  margin-bottom: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card .meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-dim);
}
.card .rating {
  color: var(--accent);
  font-weight: 600;
}

#loadMoreWrap { display: flex; justify-content: center; margin: 28px 0; }
#loadMoreBtn {
  padding: 10px 26px;
  border-radius: 999px;
  border: 1px solid #2a2d35;
  background: var(--bg-elev);
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
}
#loadMoreBtn:hover { border-color: var(--accent-2); }
#loadMoreBtn:disabled { opacity: 0.5; cursor: default; }

.empty, .error {
  text-align: center;
  color: var(--text-dim);
  padding: 60px 20px;
  grid-column: 1 / -1;
}
.error { color: var(--danger); }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.72);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  z-index: 100;
}
.modal-overlay.hidden { display: none; }

.modal {
  position: relative;
  background: var(--bg-elev);
  border-radius: var(--radius);
  max-width: 900px;
  width: 100%;
  box-shadow: var(--shadow);
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 14px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.8rem;
  cursor: pointer;
  z-index: 5;
  line-height: 1;
}

.detail-hero {
  display: flex;
  gap: 24px;
  padding: 28px;
  flex-wrap: wrap;
}
.detail-hero img.poster-lg {
  width: 220px;
  border-radius: var(--radius);
  flex-shrink: 0;
  background: var(--bg-elev-2);
}
.detail-main { flex: 1; min-width: 240px; }
.detail-main h2 { margin: 0 0 6px; font-size: 1.6rem; }
.detail-tagline { color: var(--text-dim); font-style: italic; margin-bottom: 12px; }
.detail-genres { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.chip {
  background: var(--bg-elev-2);
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.78rem;
  color: var(--text-dim);
}
.detail-stats { display: flex; gap: 20px; margin-bottom: 16px; flex-wrap: wrap; }
.stat { font-size: 0.85rem; color: var(--text-dim); }
.stat b { color: var(--accent); display: block; font-size: 1.1rem; }
.detail-overview { line-height: 1.5; color: var(--text); margin-bottom: 16px; }
.detail-cast { padding: 0 28px 28px; }
.detail-cast h3, .detail-similar h3 { font-size: 1.1rem; margin-bottom: 12px; }
.cast-row { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 8px; }
.cast-item { flex-shrink: 0; width: 100px; text-align: center; font-size: 0.78rem; }
.cast-item img {
  width: 100px; height: 100px; object-fit: cover; border-radius: 50%;
  background: var(--bg-elev-2); margin-bottom: 6px;
}
.cast-item .cname { font-weight: 600; }
.cast-item .crole { color: var(--text-dim); }

.detail-similar { padding: 0 28px 28px; }
.similar-row { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 8px; }
.similar-item { flex-shrink: 0; width: 120px; cursor: pointer; }
.similar-item img {
  width: 120px; height: 180px; object-fit: cover; border-radius: 8px;
  background: var(--bg-elev-2);
}
.similar-item .stitle { font-size: 0.78rem; margin-top: 6px; }

.action-row {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.watch-btn {
  display: inline-block;
  padding: 8px 18px;
  background: var(--accent);
  color: #1a1a1a;
  border: none;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.85rem;
  text-decoration: none;
  cursor: pointer;
}
.watch-btn:hover { filter: brightness(1.08); }

.trailer-link {
  display: inline-block;
  padding: 8px 18px;
  background: var(--bg-elev-2);
  color: var(--text);
  border-radius: 999px;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.85rem;
}

.player-wrap { padding: 0 28px 20px; }
.player-wrap.hidden { display: none; }
.player-16x9 {
  position: relative;
  width: 100%;
  padding-top: 56.25%;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
}
.player-16x9 iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}
.player-16x9 .empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }

/* Watch page */
.back-link {
  color: var(--text);
  text-decoration: none;
  font-size: 1.3rem;
  padding: 4px 10px;
  border-radius: 8px;
}
.back-link:hover { background: var(--bg-elev-2); }

.watch-title {
  color: var(--text-dim);
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.watch-main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
}

.watch-main .player-16x9 { border-radius: var(--radius); box-shadow: var(--shadow); }

.watch-info {
  display: flex;
  gap: 24px;
  margin-top: 24px;
  flex-wrap: wrap;
}
.watch-poster {
  width: 160px;
  border-radius: var(--radius);
  flex-shrink: 0;
  background: var(--bg-elev-2);
}
.watch-meta { flex: 1; min-width: 240px; }
.watch-meta h1 { font-size: 1.5rem; margin: 0 0 10px; }
.watch-year { color: var(--text-dim); font-weight: 400; }
.watch-meta .detail-genres { margin: 10px 0; }
.watch-meta .detail-stats { margin-bottom: 14px; }
.watch-meta .detail-overview { max-width: 640px; }
