:root {
  --bg: #0b0d12;
  --surface: #151821;
  --surface-2: #1d212c;
  --line: rgba(255, 255, 255, 0.08);
  --text: #f2f4f8;
  --mid: #a4acba;
  --dim: #6c7484;
  --accent: #f589b6;
  --top: env(safe-area-inset-top, 0px);
  --bottom: env(safe-area-inset-bottom, 0px);
  --left: env(safe-area-inset-left, 0px);
  --right: env(safe-area-inset-right, 0px);
  --tabs: calc(58px + var(--bottom));
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.36 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; }
input { font: inherit; color: inherit; }
img { display: block; }

#view { min-height: 100vh; padding: 0 var(--right) var(--tabs) var(--left); }
body.player #view { padding-bottom: var(--bottom); }

/* bottom tabs */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  height: var(--tabs); padding: 6px max(12px, var(--right)) var(--bottom) max(12px, var(--left));
  display: flex; justify-content: space-around;
  background: rgba(11, 13, 18, 0.86);
  -webkit-backdrop-filter: blur(20px) saturate(1.4); backdrop-filter: blur(20px) saturate(1.4);
  border-top: 1px solid var(--line);
}
#tabs[hidden] { display: none; }
#tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; color: var(--dim); font-size: 10.5px; font-weight: 600; }
#tabs svg { width: 24px; height: 24px; fill: currentColor; }
#tabs a.on { color: var(--accent); }

/* page header */
.head { padding: calc(var(--top) + 18px) 18px 8px; }
.head h1 { margin: 0; font-size: 30px; font-weight: 800; letter-spacing: -0.02em; }
.head p { margin: 4px 0 0; color: var(--mid); font-size: 14px; }

/* rows of posters */
.row { margin: 22px 0 0; }
.row h2 { margin: 0 18px 10px; font-size: 19px; font-weight: 750; letter-spacing: -0.01em; }
.shelf {
  display: flex; gap: 12px; overflow-x: auto; padding: 0 18px 4px;
  scroll-snap-type: x mandatory; scroll-padding: 0 18px; scrollbar-width: none;
}
.shelf::-webkit-scrollbar { display: none; }
.card { flex: 0 0 auto; width: 124px; scroll-snap-align: start; }
.card .poster { position: relative; aspect-ratio: 2 / 3; border-radius: 12px; overflow: hidden; background: var(--surface-2); }
.card .poster img { width: 100%; height: 100%; object-fit: cover; }
.card .name { margin-top: 7px; font-size: 13px; font-weight: 650; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .meta { margin-top: 2px; color: var(--mid); font-size: 12px; }
.bar { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgba(255, 255, 255, 0.25); }
.bar i { display: block; height: 100%; background: var(--accent); }
.card:active .poster, .ep:active, .btn:active { transform: scale(0.97); }
.card .poster, .ep, .btn { transition: transform 0.15s ease; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); gap: 16px 12px; padding: 12px 18px 24px; }
.grid .card { width: auto; }

/* home hero */
.hero { position: relative; height: calc(min(62vh, 560px) + var(--top)); overflow: hidden; }
.hero .slides { display: flex; height: 100%; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; }
.hero .slides::-webkit-scrollbar { display: none; }
.slide { position: relative; flex: 0 0 100%; scroll-snap-align: start; }
.slide img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.slide::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(11,13,18,0.35) 0%, rgba(11,13,18,0) 30%, rgba(11,13,18,0.55) 65%, var(--bg) 100%); }
.slide .words { position: absolute; z-index: 1; left: 18px; right: 18px; bottom: 22px; }
.slide .words h2 { margin: 0; font-size: 28px; font-weight: 850; line-height: 1.1; letter-spacing: -0.02em; text-shadow: 0 2px 16px rgba(0,0,0,0.5); }
.slide .words p { margin: 8px 0 0; color: #d6dae2; font-size: 13.5px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tag { padding: 3px 9px; border-radius: 99px; background: rgba(255,255,255,0.12); color: #e6e9ef; font-size: 11.5px; font-weight: 650; }
.tag.accent { background: var(--accent); color: var(--bg); }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 44px; padding: 0 18px; border-radius: 12px; background: var(--surface-2); font-weight: 700; font-size: 15px; }
.btn.primary { background: var(--accent); color: var(--bg); }
.btn svg { width: 18px; height: 18px; fill: currentColor; }
.btn[disabled] { opacity: 0.45; }

/* search */
.searchbox { position: sticky; top: 0; z-index: 5; padding: calc(var(--top) + 12px) 18px 10px; background: rgba(11,13,18,0.9); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px); }
.searchbox input { width: 100%; height: 44px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-size: 16px; outline: none; }
.searchbox input:focus { border-color: var(--accent); }

/* show page */
.banner { position: relative; height: calc(240px + var(--top)); overflow: hidden; background: var(--surface); }
.banner img { width: 100%; height: 100%; object-fit: cover; }
.banner::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(11,13,18,0.2), var(--bg)); }
.back { position: fixed; z-index: 15; top: calc(var(--top) + 10px); left: calc(var(--left) + 12px); width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: rgba(0,0,0,0.5); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); }
.back svg { width: 20px; height: 20px; fill: #fff; }
.show-top { display: flex; gap: 16px; padding: 0 18px; margin-top: -96px; position: relative; z-index: 1; align-items: flex-end; }
.show-top .cover { flex: 0 0 112px; aspect-ratio: 2/3; border-radius: 12px; overflow: hidden; box-shadow: 0 10px 30px rgba(0,0,0,0.5); background: var(--surface-2); }
.show-top .cover img { width: 100%; height: 100%; object-fit: cover; }
.show-top h1 { margin: 0; font-size: 22px; font-weight: 850; line-height: 1.15; letter-spacing: -0.01em; }
.show-top .meta { margin-top: 6px; color: var(--mid); font-size: 13px; }
.actions { display: flex; gap: 10px; padding: 16px 18px 0; }
.actions .btn.primary { flex: 1; }
.desc { margin: 14px 18px 0; color: #c9ced8; font-size: 14px; line-height: 1.5; }
.desc.clamp { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.seasons { display: flex; gap: 8px; overflow-x: auto; padding: 16px 18px 2px; scrollbar-width: none; }
.seasons::-webkit-scrollbar { display: none; }
.seasons a { flex: 0 0 auto; padding: 8px 14px; border-radius: 99px; background: var(--surface-2); font-size: 13px; font-weight: 650; color: var(--mid); }
.seasons a.on { background: var(--accent); color: var(--bg); }
.eps { padding: 6px 18px 24px; }
.eps h2 { font-size: 18px; margin: 18px 0 8px; }
.ep { position: relative; display: flex; align-items: center; gap: 14px; padding: 12px 14px; margin-bottom: 8px; border-radius: 12px; background: var(--surface); overflow: hidden; }
.ep .n { flex: 0 0 34px; font-size: 18px; font-weight: 800; color: var(--accent); text-align: center; }
.ep .t { flex: 1; min-width: 0; }
.ep .t b { display: block; font-size: 14.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ep .t span { color: var(--dim); font-size: 12px; }
.ep.off { opacity: 0.45; }
.ep .check { width: 20px; height: 20px; fill: var(--accent); }
.note { margin: 10px 18px; padding: 12px 14px; border-radius: 12px; background: var(--surface); color: var(--mid); font-size: 13.5px; }

/* player */
.player { padding-top: var(--top); }
.stage { position: relative; background: #000; }
.stage video { display: block; width: 100%; aspect-ratio: 16 / 9; max-height: calc(100vh - var(--top)); background: #000; }
.skip { position: absolute; right: 14px; bottom: 58px; padding: 10px 16px; border-radius: 10px; background: rgba(255,255,255,0.92); color: #000; font-weight: 800; font-size: 14px; }
.skip[hidden] { display: none; }
.player .info { padding: 14px 18px; }
.player .info .series { color: var(--accent); font-weight: 750; font-size: 14px; }
.player .info h1 { margin: 4px 0 0; font-size: 21px; font-weight: 800; line-height: 1.2; }
.player .info .actions { padding: 14px 0 0; }
.player .back { position: static; background: var(--surface-2); }
.player .topbar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; }

/* login */
.login { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 14px; padding: 24px; text-align: center; }
.login img { width: 84px; height: 84px; border-radius: 20px; }
.login h1 { margin: 6px 0 0; font-size: 26px; }
.login p { margin: 0; color: var(--mid); }
.login input { width: min(340px, 100%); height: 48px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-size: 16px; outline: none; }
.login .btn { width: min(340px, 100%); }
.err { color: #ff8a8a; font-size: 13.5px; min-height: 1.2em; }

.empty { padding: 40px 24px; text-align: center; color: var(--mid); }
.spinner { width: 28px; height: 28px; margin: 60px auto; border: 3px solid rgba(255,255,255,0.15); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.fade { animation: fade 0.25s ease both; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } }
@media (prefers-reduced-motion: reduce) { .fade { animation: none; } }

@media (min-width: 700px) {
  .card { width: 150px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 20px 16px; padding: 16px 24px 32px; }
  .head { padding-left: 24px; padding-right: 24px; }
  .row h2 { margin-left: 24px; }
  .shelf { padding: 0 24px 4px; scroll-padding: 0 24px; gap: 14px; }

  /* Home: the wide banner, not quite so tall */
  .hero { height: calc(min(52vh, 520px) + var(--top)); }
  .slide img { object-position: center 25%; }
  .slide .words { left: 32px; right: 32px; bottom: 30px; max-width: 640px; }
  .slide .words h2 { font-size: 38px; }

  /* show page: one centred column, wider poster, episodes in two columns */
  .banner { height: calc(340px + var(--top)); }
  .page { max-width: 1040px; margin: 0 auto; }
  .show-top { margin-top: -130px; gap: 24px; padding: 0 24px; }
  .show-top .cover { flex-basis: 170px; }
  .show-top h1 { font-size: 30px; }
  .actions { padding: 18px 24px 0; }
  .actions .btn.primary { flex: 0 0 auto; min-width: 260px; }
  .desc { margin: 16px 24px 0; font-size: 15px; max-width: 760px; }
  .page > .tags { padding: 0 24px !important; }
  .seasons { padding: 18px 24px 2px; }
  .note { margin: 12px 24px; }
  .eps { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 8px 24px 32px; }
  .eps h2 { grid-column: 1 / -1; margin-bottom: 0; }
  .eps .ep { margin: 0; }

  /* player: the video as big as fits, the details under it in a column */
  .player .stage video { max-height: calc(100vh - var(--top) - 150px); }
  .player .info { max-width: 1040px; margin: 0 auto; padding: 18px 24px; }

  #tabs { justify-content: center; gap: 24px; }
  #tabs a { flex: 0 0 96px; }
}

/* landscape tablets: the poster beside the details */
@media (min-width: 1000px) and (orientation: landscape) {
  .banner { height: calc(300px + var(--top)); }
  .show-top { margin-top: -110px; }
  .eps { grid-template-columns: 1fr 1fr 1fr; }
}
