:root {
  --bg: #0d0f14;
  --bg-soft: #161a23;
  --bg-card: #1b202b;
  --line: #262d3a;
  --text: #e8ebf2;
  --muted: #8b93a7;
  --accent: #6c8cff;
  --gold: #ffc83d;
  --radius: 14px;
}

* { box-sizing: border-box; }

/* Ensure [hidden] always wins over component display rules. */
[hidden] { display: none !important; }

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

a { color: inherit; text-decoration: none; }

.wrap { max-width: 1280px; margin: 0 auto; padding: 0 24px 64px; }

/* ---- Search ---- */
.search-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: 28px 0 18px;
  background: linear-gradient(var(--bg) 70%, transparent);
}
.search-box {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 22px;
  height: 58px;
  transition: border-color .2s, box-shadow .2s;
}
.search-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(108, 140, 255, .15);
}
.search-box i { color: var(--muted); font-size: 18px; width: 20px; text-align: center; }
.search-box input {
  flex: 1;
  background: none;
  border: 0;
  outline: 0;
  color: var(--text);
  font-size: 18px;
}
.search-box input::placeholder { color: var(--muted); }

/* ---- Sections ---- */
.section-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 26px 4px 14px;
}

/* ---- Grid ---- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 22px;
}
/* Continue watching scrolls horizontally instead of wrapping. */
.continue .grid {
  display: flex;
  grid-template-columns: none;
  overflow-x: auto;
  padding-bottom: 10px;
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
}
.continue .card {
  flex: 0 0 200px;
  scroll-snap-align: start;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform .18s, border-color .18s;
  display: flex;
  flex-direction: column;
}
.card:hover { transform: translateY(-4px); border-color: var(--accent); }

.poster {
  position: relative;
  aspect-ratio: 2 / 3;
  background: #0a0c11;
}
.poster img { width: 100%; height: 100%; object-fit: cover; display: block; }
.poster .ph { width: 100%; height: 100%; display: grid; place-items: center; color: var(--line); font-size: 32px; }

.badge {
  position: absolute;
  top: 10px;
  left: 10px;
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(13, 15, 20, .82);
  backdrop-filter: blur(4px);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 600;
}
.badge.rating i { color: var(--gold); }
.badge.type { left: auto; right: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }

.remove-btn {
  position: absolute;
  top: 8px; right: 8px;
  width: 28px; height: 28px;
  border: 0;
  border-radius: 8px;
  background: rgba(13, 15, 20, .82);
  backdrop-filter: blur(4px);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  opacity: 0;
  transition: opacity .15s, background .15s;
}
.card:hover .remove-btn { opacity: 1; }
.remove-btn:hover { background: #b23b46; }

.progress {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 4px;
  background: rgba(255, 255, 255, .12);
}
.progress > span { display: block; height: 100%; background: var(--accent); }
.watched-flag {
  position: absolute;
  bottom: 8px; right: 8px;
  color: #5ee08a;
  background: rgba(13, 15, 20, .82);
  border-radius: 50%;
  width: 24px; height: 24px;
  display: grid; place-items: center;
  font-size: 12px;
}

.card-body { padding: 12px 13px 14px; }
.card-title { font-size: 14.5px; font-weight: 600; line-height: 1.3; }
.card-meta { margin-top: 6px; font-size: 12px; color: var(--muted); line-height: 1.5; min-height: 34px; }
.card-meta .skeleton { display: inline-block; width: 70%; height: 11px; border-radius: 4px; background: var(--line); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .45; } }

.empty { color: var(--muted); padding: 40px 4px; }

/* spinner */
.spin { animation: rot .8s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }

/* ---- Watch page ---- */
.player-stage {
  position: relative;
  background: #000;
  aspect-ratio: 16 / 9;
  width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
}
.player-stage iframe { width: 100%; height: 100%; border: 0; }
.player-loading {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  color: var(--muted); font-size: 40px;
  background: #000;
}

.overlay-controls {
  position: absolute;
  top: 14px; left: 14px;
  display: flex;
  gap: 8px;
  z-index: 5;
}
.overlay-controls button {
  width: 40px; height: 40px;
  border: 0;
  border-radius: 10px;
  background: rgba(13, 15, 20, .7);
  backdrop-filter: blur(6px);
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
  transition: background .15s;
}
.overlay-controls button:hover { background: var(--accent); }
.overlay-controls button:disabled { opacity: .35; cursor: default; }

.watch-head { display: flex; align-items: baseline; gap: 14px; margin: 22px 4px 4px; }
.watch-head h1 { font-size: 24px; margin: 0; }
.watch-head .now { color: var(--muted); font-size: 15px; }
.back { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); margin: 24px 4px 0; font-size: 14px; }
.back:hover { color: var(--text); }

.controls-row { display: flex; align-items: center; gap: 14px; margin: 22px 4px 10px; flex-wrap: wrap; }
select {
  background: var(--bg-soft);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 15px;
  outline: none;
}

/* episode list (under player) */
.ep-list { display: flex; flex-direction: column; gap: 10px; }
.ep-row {
  display: flex;
  gap: 14px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.ep-row:hover { border-color: var(--accent); }
.ep-row.active { border-color: var(--accent); background: #1f2535; }
.ep-row img { width: 150px; aspect-ratio: 16/9; object-fit: cover; border-radius: 8px; background: #0a0c11; flex: none; }
.ep-info { flex: 1; min-width: 0; }
.ep-info .t { font-weight: 600; font-size: 15px; }
.ep-info .t .num { color: var(--muted); margin-right: 8px; }
.ep-info .p { color: var(--muted); font-size: 13px; margin-top: 6px; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ep-watch { color: var(--muted); align-self: flex-start; font-size: 16px; padding: 4px; }
.ep-watch.on { color: #5ee08a; }

/* modal episode list */
.modal {
  position: fixed; inset: 0;
  background: rgba(5, 6, 10, .72);
  backdrop-filter: blur(4px);
  z-index: 50;
  display: none;
  padding: 6vh 20px;
  overflow: auto;
}
.modal.open { display: block; }
.modal-inner {
  max-width: 560px;
  margin: 0 auto;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}
.modal-inner h3 { margin: 4px 4px 14px; font-size: 17px; }
.modal-list { display: flex; flex-direction: column; }
.modal-list .row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 12px;
  border-radius: 9px;
  cursor: pointer;
}
.modal-list .row:hover { background: var(--bg-card); }
.modal-list .row.active { color: var(--accent); }
.modal-list .row .mark { font-size: 14px; color: var(--muted); }
.modal-list .row .mark.on { color: #5ee08a; }

.btn {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  cursor: pointer;
}
.btn.on { background: #1f3326; border-color: #2f6b45; color: #88e6a8; }
