:root {
  --bg: #141414; --surface: #1f1f23; --surface2: #2a2a30; --line: #333; --text: #f2f2f2; --muted: #a3a3ab;
  --red: #e50914; --red-press: #b20710; --radius: 10px;
  --gutter: max(16px, env(safe-area-inset-left));
  --gutter-r: max(16px, env(safe-area-inset-right));
  --top: env(safe-area-inset-top);
  --card-w: 112px;
}
@media (min-width: 700px) { :root { --card-w: 150px; } }
@media (min-width: 1100px) { :root { --card-w: 180px; } }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--bg); color-scheme: dark; }
body {
  margin: 0; min-height: 100vh; min-height: 100dvh; background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%; overflow-x: hidden;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; touch-action: manipulation; cursor: pointer; }
img { display: block; }
.hidden { display: none !important; }
:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* Top bar */
#topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 6px;
  padding: calc(var(--top) + 8px) var(--gutter-r) 8px var(--gutter);
  background: linear-gradient(rgba(20,20,20,.97), rgba(20,20,20,.9));
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
.logo { color: var(--red); font-weight: 900; letter-spacing: 1.5px; font-size: 22px; margin-right: auto; padding: 4px 0; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px;
  border: 0; border-radius: 50%; background: none; color: var(--text); margin-left: -8px;
}
#searchLink { margin: 0 -8px 0 0; }
.icon-btn:active { background: var(--surface2); }
body.player #topbar { display: none; }

main { padding-bottom: calc(env(safe-area-inset-bottom) + 24px); outline: none; }

/* Messages, spinner */
.msg { color: var(--muted); text-align: center; padding: 48px var(--gutter); }
.msg button { margin-top: 14px; }
.spinner {
  width: 32px; height: 32px; margin: 64px auto; border-radius: 50%;
  border: 3px solid var(--surface2); border-top-color: var(--red); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 8px;
  padding: 12px 22px; font-weight: 700; background: var(--surface2); color: var(--text);
}
.btn:active { filter: brightness(.85); }
.btn.primary { background: var(--red); color: #fff; }
.btn.primary:active { background: var(--red-press); }
.btn svg { width: 18px; height: 18px; }

/* Rows */
.row { margin-top: 18px; }
.row h2 { font-size: 18px; margin: 0 var(--gutter-r) 8px var(--gutter); }
.scroller {
  display: flex; gap: 10px; overflow-x: auto; overscroll-behavior-x: contain;
  scroll-snap-type: x proximity; scroll-padding-left: var(--gutter);
  padding: 0 var(--gutter-r) 4px var(--gutter); scrollbar-width: none;
}
.scroller::-webkit-scrollbar { display: none; }
.scroller .card { flex: 0 0 var(--card-w); scroll-snap-align: start; }

/* Cards */
.card { min-width: 0; display: block; }
.poster {
  position: relative; width: 100%; aspect-ratio: 2/3; border-radius: var(--radius); overflow: hidden;
  background: var(--surface2); display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 12px; text-align: center; padding: 6px;
}
.poster img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.card:active .poster { filter: brightness(.8); }
.card .t { font-size: 13px; margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .y { font-size: 12px; color: var(--muted); }
.badge {
  position: absolute; left: 6px; bottom: 6px; background: rgba(0,0,0,.75); color: #fff;
  font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 5px;
}
.grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--card-w), 1fr)); gap: 14px 10px;
  padding: 14px var(--gutter-r) 0 var(--gutter);
}
@media (max-width: 420px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

/* Search */
.search-box { padding: 4px var(--gutter-r) 0 var(--gutter); }
#q {
  width: 100%; font: inherit; font-size: 17px; padding: 12px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); outline: none;
  -webkit-appearance: none; appearance: none;
}
#q:focus { border-color: #666; }

/* Details */
.hero { position: relative; }
.backdrop {
  width: 100%; aspect-ratio: 16/9; max-height: 56vh; object-fit: cover; background: var(--surface);
  -webkit-mask-image: linear-gradient(#000 60%, transparent); mask-image: linear-gradient(#000 60%, transparent);
}
.backdrop.empty { aspect-ratio: auto; height: 24px; }
.info { padding: 0 var(--gutter-r) 0 var(--gutter); margin-top: -40px; position: relative; max-width: 900px; }
.info h1 { font-size: 26px; line-height: 1.15; margin: 0 0 6px; }
.meta { color: var(--muted); font-size: 14px; display: flex; flex-wrap: wrap; gap: 4px 12px; }
.tagline { color: var(--muted); font-style: italic; margin: 10px 0 0; }
.overview { margin: 12px 0 0; color: #d6d6dc; font-size: 15px; }
.actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.actions .btn.primary { flex: 1 1 200px; max-width: 360px; }
.notice { color: var(--muted); font-size: 13px; margin-top: 8px; }

/* Seasons and episodes */
.seasons { display: flex; gap: 8px; overflow-x: auto; padding: 18px var(--gutter-r) 4px var(--gutter); scrollbar-width: none; }
.seasons::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 7px 14px; font-size: 14px; font-weight: 600; color: var(--muted);
}
.chip.active { background: var(--text); color: #111; border-color: var(--text); }
.episodes { list-style: none; margin: 8px 0 0; padding: 0 var(--gutter-r) 0 var(--gutter); max-width: 900px; }
.episode {
  display: grid; grid-template-columns: 136px minmax(0, 1fr); gap: 12px; width: 100%; text-align: left;
  border: 0; background: none; padding: 10px 0; border-bottom: 1px solid #222; align-items: start;
}
.episode:active { background: var(--surface); }
.still { position: relative; width: 136px; aspect-ratio: 16/9; border-radius: 8px; overflow: hidden; background: var(--surface2); }
.still img { width: 100%; height: 100%; object-fit: cover; }
.still .play {
  position: absolute; inset: 0; margin: auto; width: 34px; height: 34px; border-radius: 50%;
  background: rgba(0,0,0,.6); border: 1.5px solid #fff; display: flex; align-items: center; justify-content: center;
}
.still .play svg { width: 14px; height: 14px; margin-left: 2px; }
.ep-title { font-weight: 600; font-size: 15px; }
.ep-meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.ep-overview {
  color: #c4c4cc; font-size: 13px; margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 3;
  -webkit-box-orient: vertical; overflow: hidden;
}
.last-watched { color: var(--red); font-weight: 700; }

/* Player */
#playerWrap { position: fixed; inset: 0; background: #000; z-index: 20; display: flex; flex-direction: column; }
.player-bar {
  display: flex; align-items: center; gap: 8px; flex: none;
  padding: calc(var(--top) + 4px) var(--gutter-r) 6px var(--gutter); background: #000;
}
.player-bar .title { flex: 1; min-width: 0; font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-bar .ext { font-size: 13px; padding: 7px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); }
#playerFrame { flex: 1; width: 100%; border: 0; background: #000; padding-bottom: env(safe-area-inset-bottom); }
/* Phone held sideways: drop the bar and float a small back button so the video gets the whole screen. */
@media (orientation: landscape) and (max-height: 500px) {
  .player-bar { position: absolute; top: 0; left: 0; z-index: 2; background: none; padding: 8px var(--gutter); pointer-events: none; }
  .player-bar > * { pointer-events: auto; }
  .player-bar .title, .player-bar .ext { display: none; }
  .player-bar .icon-btn { background: rgba(0,0,0,.55); }
  #playerFrame { padding-bottom: 0; }
}
