:root {
  --bg: #0b0d12;
  --bg2: #12151d;
  --card: #171b26;
  --text: #f2f4f8;
  --muted: #9aa3b5;
  --accent: #e50914;
  --accent2: #ffb020;
  --radius: 14px;
  --max: 1280px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
/* [hidden] must win over display:flex rules below (hero, modal/trailer
   backdrops) — otherwise a hidden backdrop/modal renders as a stuck
   empty black box on page load, with no working close button. */
[hidden] { display: none !important; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  min-height: 100vh;
}
a { color: var(--accent2); }
button { font-family: inherit; cursor: pointer; }
img { display: block; max-width: 100%; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(11,13,18,.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid #1e2430;
}
.topbar-inner {
  max-width: var(--max); margin: 0 auto;
  display: flex; align-items: center; gap: 16px;
  padding: 12px 20px;
}
.logo { font-size: 1.35rem; font-weight: 800; color: var(--text); text-decoration: none; white-space: nowrap; }
.logo:hover { color: var(--accent); }
.nav-links { display: flex; gap: 4px; }
.nav-links button {
  background: none; border: none; color: var(--muted);
  font-size: .95rem; font-weight: 600; padding: 8px 12px; border-radius: 8px;
}
.nav-links button.active, .nav-links button:hover { color: var(--text); background: #1b2130; }
.badge {
  display: inline-block; background: var(--accent); color: #fff;
  font-size: .7rem; border-radius: 999px; padding: 1px 7px; margin-left: 4px;
}
.search-wrap { position: relative; margin-left: auto; width: min(340px, 40vw); }
#search {
  width: 100%; background: var(--bg2); border: 1px solid #232a3a; color: var(--text);
  border-radius: 999px; padding: 10px 16px; font-size: .95rem; outline: none;
}
#search:focus { border-color: var(--accent); }
.search-dropdown {
  position: absolute; top: calc(100% + 8px); left: 0; right: 0;
  background: var(--card); border: 1px solid #232a3a; border-radius: var(--radius);
  max-height: 60vh; overflow-y: auto; box-shadow: 0 18px 50px rgba(0,0,0,.6);
}
.search-item {
  display: flex; gap: 12px; align-items: center; padding: 10px 12px; cursor: pointer;
}
.search-item:hover { background: #1e2434; }
.search-item img { width: 44px; height: 66px; object-fit: cover; border-radius: 6px; background: #232a3a; }
.search-item .t { font-weight: 600; font-size: .9rem; }
.search-item .s { color: var(--muted); font-size: .78rem; }

.genre-wrap {
  max-width: var(--max); margin: 0 auto; padding: 0 20px 12px;
  display: flex; align-items: center; gap: 8px;
}
.genre-bar {
  flex: 1; min-width: 0;
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: thin;
  scroll-behavior: smooth; cursor: grab; padding-bottom: 2px;
}
.genre-bar:active { cursor: grabbing; }
.genre-bar::-webkit-scrollbar { height: 6px; }
.genre-bar::-webkit-scrollbar-thumb { background: #232a3a; border-radius: 999px; }
.genre-scroll {
  flex: 0 0 auto; width: 32px; height: 32px; border-radius: 50%;
  border: 1px solid #232a3a; background: var(--bg2); color: var(--text);
  font-size: 1.2rem; line-height: 1;
}
.genre-scroll:hover { background: var(--accent); border-color: var(--accent); }
.genre-bar button {
  flex: 0 0 auto; background: var(--bg2); border: 1px solid #232a3a; color: var(--muted);
  border-radius: 999px; padding: 7px 14px; font-size: .82rem; font-weight: 600;
}
.genre-bar button.active, .genre-bar button:hover { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- filters ---------- */
.filter-bar {
  max-width: var(--max); margin: 0 auto; padding: 0 20px 14px;
  display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end;
}
.filter-bar label { color: var(--muted); font-size: .78rem; font-weight: 600; display: flex; flex-direction: column; gap: 4px; }
.filter-bar select {
  background: var(--bg2); border: 1px solid #232a3a; color: var(--text);
  border-radius: 10px; padding: 8px 10px; font-size: .88rem; font-weight: 600; outline: none;
}
.filter-bar select:focus { border-color: var(--accent); }
.filter-bar .btn { padding: 9px 16px; }

/* ---------- hero ---------- */
.hero {
  position: relative; height: min(62vh, 560px); min-height: 380px;
  display: flex; align-items: flex-end; overflow: hidden;
}
.hero-bg {
  position: absolute; inset: 0; background-size: cover; background-position: center 20%;
  transition: opacity .6s ease;
}
.hero::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(to top, var(--bg) 4%, rgba(11,13,18,.55) 45%, rgba(11,13,18,.15) 100%);
}
.hero-content { position: relative; z-index: 2; max-width: var(--max); margin: 0 auto; width: 100%; padding: 0 20px 48px; }
.hero-kicker { color: var(--accent2); font-weight: 700; letter-spacing: .12em; text-transform: uppercase; font-size: .78rem; margin-bottom: 8px; }
.hero h1 { font-size: clamp(1.8rem, 4.5vw, 3.4rem); line-height: 1.05; margin-bottom: 10px; max-width: 16ch; }
.hero-meta { color: var(--muted); font-size: .92rem; margin-bottom: 10px; display: flex; gap: 12px; flex-wrap: wrap; }
.hero-meta .star { color: var(--accent2); font-weight: 700; }
.hero p { color: #cdd4e1; max-width: 62ch; font-size: .98rem; line-height: 1.55;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; margin-bottom: 18px; }
.hero-actions { display: flex; gap: 10px; }
.btn { border: none; border-radius: 10px; padding: 12px 22px; font-size: .95rem; font-weight: 700; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #f6121d; }
.btn-ghost { background: rgba(255,255,255,.14); color: #fff; backdrop-filter: blur(6px); }
.btn-ghost:hover { background: rgba(255,255,255,.22); }
.hero-dots { position: absolute; z-index: 2; bottom: 16px; right: 24px; display: flex; gap: 6px; }
.hero-dots button { width: 8px; height: 8px; border-radius: 50%; border: none; background: rgba(255,255,255,.35); padding: 0; }
.hero-dots button.active { background: #fff; }

/* ---------- rows & cards ---------- */
#rows, .watchlist-view { max-width: var(--max); margin: 0 auto; padding: 8px 20px 40px; }
.row { margin-top: 30px; }
.row-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.row-head h2 { font-size: 1.25rem; }
.row-head button { background: none; border: none; color: var(--muted); font-size: .85rem; font-weight: 600; }
.row-head button:hover { color: var(--text); }
.rail { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 8px; scroll-snap-type: x mandatory; scrollbar-width: thin; }
.card {
  flex: 0 0 168px; scroll-snap-align: start; cursor: pointer;
  background: var(--card); border-radius: var(--radius); overflow: hidden;
  transition: transform .18s ease, box-shadow .18s ease; position: relative;
}
.card:hover { transform: translateY(-4px); box-shadow: 0 14px 34px rgba(0,0,0,.5); }
.card img { width: 100%; aspect-ratio: 2/3; object-fit: cover; background: #232a3a; }
.card .info { padding: 10px 12px 12px; }
.card .t { font-size: .88rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .s { color: var(--muted); font-size: .76rem; margin-top: 3px; display: flex; justify-content: space-between; }
.card .s .star { color: var(--accent2); }
.card .wl {
  position: absolute; top: 8px; right: 8px; width: 32px; height: 32px; border-radius: 50%;
  border: none; background: rgba(0,0,0,.55); color: #fff; font-size: 1rem; line-height: 1;
  opacity: 0; transition: opacity .15s;
}
.card:hover .wl, .card .wl.saved { opacity: 1; }
.card .wl.saved { background: var(--accent); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; }
.grid .card { flex: none; }
.watchlist-view h2 { margin: 26px 0 14px; font-size: 1.4rem; }
.empty-note { color: var(--muted); margin-top: 12px; }

/* ---------- modal ---------- */
.modal-backdrop, .trailer-backdrop {
  position: fixed; inset: 0; z-index: 100; background: rgba(4,6,10,.78);
  backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  background: var(--bg2); border-radius: 18px; max-width: 760px; width: 100%;
  max-height: 92vh; overflow-y: auto; position: relative;
}
.modal-close {
  position: absolute; top: 12px; right: 12px; z-index: 3;
  width: 36px; height: 36px; border-radius: 50%; border: none;
  background: rgba(0,0,0,.6); color: #fff; font-size: 1rem;
}
.modal-hero { height: 300px; background-size: cover; background-position: center 25%; position: relative; }
.modal-hero::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to top, var(--bg2), transparent 60%); }
.modal-body { padding: 4px 26px 30px; }
.modal-body h2 { font-size: 1.6rem; margin-bottom: 6px; }
.modal-meta { color: var(--muted); font-size: .9rem; margin-bottom: 14px; display: flex; gap: 10px; flex-wrap: wrap; }
.modal-meta .star { color: var(--accent2); font-weight: 700; }
.modal-actions { display: flex; gap: 10px; margin-bottom: 16px; }
.modal-body p { color: #cdd4e1; line-height: 1.65; font-size: .96rem; margin-bottom: 18px; }
.modal-body h3 { font-size: 1.05rem; margin: 18px 0 10px; }
.providers { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.providers img { width: 44px; height: 44px; border-radius: 10px; }
.provider-label { width: 100%; color: var(--muted); font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.cast-row { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 6px; }
.cast { flex: 0 0 84px; text-align: center; }
.cast img { width: 84px; height: 84px; border-radius: 50%; object-fit: cover; background: #232a3a; margin: 0 auto 6px; }
.cast .n { font-size: .74rem; font-weight: 600; }
.cast .c { font-size: .7rem; color: var(--muted); }

.trailer-box { position: relative; width: min(900px, 100%); }
.trailer-frame { position: relative; padding-top: 56.25%; background: #000; border-radius: 12px; overflow: hidden; }
.trailer-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: none; }

.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%); z-index: 200;
  background: #1d2331; border: 1px solid #2a3348; color: var(--text);
  padding: 12px 20px; border-radius: 999px; font-size: .9rem; box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
.footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 26px 20px 40px; }

/* ---------- loading animation ---------- */
.page-loader {
  position: fixed; inset: 0; z-index: 300; background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  transition: opacity .45s ease, visibility .45s ease;
}
.page-loader.hidden-loader { opacity: 0; visibility: hidden; }
.loader-inner { text-align: center; }
.loader-logo { font-size: 1.9rem; font-weight: 800; margin-bottom: 18px; }
.loader-spinner {
  width: 52px; height: 52px; margin: 0 auto 18px; border-radius: 50%;
  border: 4px solid #232a3a; border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader-bar {
  width: 200px; height: 6px; margin: 0 auto 12px; border-radius: 999px;
  background: #1b2130; overflow: hidden;
}
.loader-bar span {
  display: block; height: 100%; width: 40%; border-radius: 999px;
  background: var(--accent); animation: loadslide 1.1s ease-in-out infinite;
}
@keyframes loadslide {
  0% { transform: translateX(-110%); }
  100% { transform: translateX(520%); }
}
.loader-text { color: var(--muted); font-size: .9rem; }

/* Skeleton cards shown while a row / grid is loading */
.skeleton-rail { display: flex; gap: 12px; overflow: hidden; padding-bottom: 8px; }
.skeleton-card {
  flex: 0 0 168px; height: 252px; border-radius: var(--radius);
  background: linear-gradient(100deg, #171b26 40%, #232a3a 50%, #171b26 60%);
  background-size: 200% 100%; animation: shimmer 1.4s infinite;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .nav-links button { padding: 8px 8px; font-size: .88rem; }
  .card { flex-basis: 148px; }
  .hero { height: 52vh; min-height: 340px; }
}
@media (max-width: 640px) {
  .topbar-inner { flex-wrap: wrap; gap: 10px; padding: 10px 14px; }
  .search-wrap { width: 100%; margin-left: 0; order: 3; }
  .nav-links { order: 2; }
  .genre-bar { padding: 0 14px 10px; }
  #rows, .watchlist-view { padding: 8px 14px 32px; }
  .card { flex-basis: 132px; }
  .card .wl { opacity: 1; }
  .hero { height: 46vh; min-height: 300px; }
  .hero-content { padding: 0 14px 40px; }
  .hero p { -webkit-line-clamp: 2; font-size: .9rem; }
  .btn { padding: 10px 16px; font-size: .88rem; }
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal { border-radius: 18px 18px 0 0; max-height: 94vh; }
  .modal-hero { height: 200px; }
  .modal-body { padding: 4px 18px 26px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 10px; }
}
