/* LOKTV — UI mobile-first, tema gelap, aman untuk safe-area iOS/Android */
:root {
  --bg: #0b0d12;
  --bg-2: #11141b;
  --card: #161a23;
  --card-2: #1c2130;
  --fg: #e9ecf4;
  --mut: #8b93a7;
  --acc: #ff4d7e;
  --acc-2: #7c5cff;
  --line: #232838;
  --radius: 14px;
  --tab-h: 58px;
  --top-h: 56px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html {
  /* overflow di html/body ikut dipropagasikan ke viewport. Memakai `hidden`
     di sini membuat sebagian peramban memaksa sumbu Y jadi terkunci, sehingga
     SELURUH halaman tidak bisa digeser. `clip` hanya memotong, tanpa mengubah
     kemampuan scroll, jadi vertikal selalu bebas. */
  overflow-x: clip;
}
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  max-width: 100%;
}
body {
  overflow-x: clip;
  /* Jangan pernah mengunci tinggi; biarkan body tumbuh sesuai konten. */
  min-height: 100%;
}

img { display: block; max-width: 100%; }
button, input, select { font: inherit; color: inherit; max-width: 100%; }

.app { min-height: 100dvh; display: flex; flex-direction: column; min-width: 0; overflow-x: clip; }

/* Kunci scroll saat overlay pemutar terbuka. Dipakai lewat class (bukan inline
   style) supaya tidak tersangkut; lihat setPageScrollLock() di app.js. */
body.no-scroll { overflow-y: hidden; }

/* ------------------------------------------------------------- topbar --- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 8px;
  padding: calc(var(--safe-t) + 8px) 12px 8px;
  min-height: var(--top-h);
  background: rgba(11, 13, 18, .92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  min-width: 0;
  flex-wrap: wrap;           /* layar sangat sempit: pindah ke baris kedua */
  row-gap: 6px;
}
/* Brand = tombol muat ulang halaman (app.js: wireBrandLink). Sengaja <button>
   supaya klik tidak pernah membuka tab/jendela baru. */
.brand { display: inline-flex; align-items: center; margin: 0; white-space: nowrap;
         flex: 0 0 auto; color: inherit; text-decoration: none; border-radius: 8px;
         background: none; border: 0; padding: 0; font: inherit; cursor: pointer;
         -webkit-tap-highlight-color: transparent; }
.brand h1 { margin: 0; font-size: 18px; font-weight: 800; letter-spacing: .5px; }
.brand span { color: var(--acc); }
.brand:hover h1 { color: var(--acc); }
.brand:active { transform: scale(.97); }
.brand:focus-visible { outline: 2px solid var(--acc); outline-offset: 3px; }
.search { flex: 1 1 130px; min-width: 0; display: flex; align-items: center; gap: 6px;
          background: var(--bg-2); border: 1px solid var(--line); border-radius: 999px; padding: 2px 4px 2px 12px; }
.search input { flex: 1; min-width: 0; width: 100%; background: none; border: 0; outline: none; padding: 8px 0; }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; }

/* Grup tombol aksi supaya tidak ikut membelah baris pertama di layar sempit. */
.top-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; flex: 0 0 auto; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 40px; width: 40px; height: 40px; padding: 0;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px;
  font-size: 18px; cursor: pointer; transition: background .15s, transform .1s;
  flex: 0 0 auto;
}
.icon-btn:active { transform: scale(.94); }
.icon-btn:hover { background: var(--card-2); }

/* -------------------------------------------------------------- chips --- */
.chips {
  display: flex; gap: 8px; overflow-x: auto; padding: 10px 12px 2px;
  position: sticky; top: var(--top-h); z-index: 25;
  background: linear-gradient(var(--bg) 70%, transparent);
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; padding: 7px 14px; border-radius: 999px;
  background: var(--bg-2); border: 1px solid var(--line); color: var(--mut);
  font-size: 13px; cursor: pointer; white-space: nowrap;
}
.chip.active { background: var(--acc); border-color: var(--acc); color: #fff; font-weight: 600; }

/* --------------------------------------------------------------- view --- */
.view {
  flex: 1; padding: 12px 12px calc(var(--tab-h) + var(--safe-b) + 24px);
  animation: fade .25s ease;
}
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; } }

.section-title { font-size: 16px; font-weight: 700; margin: 18px 2px 10px; }
.section-title:first-child { margin-top: 4px; }

/* --------------------------------------------------------------- grid --- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); gap: 10px; }
.grid.wide { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }

.card {
  position: relative; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; cursor: pointer;
  transition: transform .15s, border-color .15s;
}
.card:active { transform: scale(.97); }
/* Kartu tanpa id (mis. dari /api/popular yang hanya kirim cover+name):
   tidak bisa diklik, jadi jangan beri affordance klik. */
.card.card-nolink { cursor: default; opacity: .82; }
.card.card-nolink:active { transform: none; }
.card.card-nolink::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(transparent 65%, rgba(0,0,0,.35));
}
.card img { width: 100%; aspect-ratio: 2/3; object-fit: cover; background: #1a1e28; }
/* Placeholder kartu tanpa cover/judul: kotak bernomor, bukan kartu kosong. */
.card .card-ph {
  width: 100%; aspect-ratio: 2/3; background: #1a1e28; color: #5a6377;
  display: flex; align-items: center; justify-content: center;
  font-size: 34px; font-weight: 700;
}
.pop-summary {
  margin: -4px 0 12px; font-size: 12.5px; line-height: 1.4;
}
.card .name {
  margin: 0; padding: 8px 8px 10px; font-size: 12.5px; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card .badge {
  position: absolute; top: 6px; left: 6px; font-size: 11px; font-weight: 700;
  background: rgba(0,0,0,.72); color: #fff; padding: 2px 7px; border-radius: 7px;
  backdrop-filter: blur(4px);
}
.card.wide img { aspect-ratio: 16/9; }

/* ------------------------------------------------------------ skeleton --- */
.skel {
  background: linear-gradient(100deg, var(--card) 30%, var(--card-2) 50%, var(--card) 70%);
  background-size: 220% 100%; animation: sh 1.2s infinite linear;
  border-radius: var(--radius);
}
@keyframes sh { from { background-position: 120% 0; } to { background-position: -120% 0; } }
.skel.card-s { aspect-ratio: 2/3; }
.skel.line { height: 12px; margin-top: 8px; border-radius: 6px; }
.skel.banner { aspect-ratio: 16/7; margin-bottom: 12px; }

/* -------------------------------------------------------------- detail --- */
.hero { position: relative; border-radius: var(--radius); overflow: hidden; margin-bottom: 14px; }
.hero img { width: 100%; max-width: 100%; aspect-ratio: 16/9; object-fit: cover; display: block; }
.hero .ov {
  position: absolute; inset: auto 0 0 0; padding: 26px 14px 12px;
  background: linear-gradient(transparent, rgba(0,0,0,.88));
}
.hero h2 { margin: 0 0 4px; font-size: 19px; line-height: 1.3; overflow-wrap: anywhere; }
.hero .sub { color: #cfd5e4; font-size: 12.5px; overflow-wrap: anywhere; }
.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  background: var(--acc); color: #fff; border: 0; border-radius: 12px;
  padding: 12px 18px; font-weight: 700; cursor: pointer;
  max-width: 100%; flex: 0 1 auto; min-width: 0;
}
.btn.ghost { background: var(--card-2); color: var(--fg); border: 1px solid var(--line); }
.actions { display: flex; gap: 10px; margin: 12px 0 4px; flex-wrap: wrap; }
.synopsis { color: var(--mut); font-size: 13.5px; line-height: 1.6; margin: 10px 0 4px; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.tag { font-size: 11.5px; color: var(--mut); border: 1px solid var(--line);
       background: var(--bg-2); border-radius: 999px; padding: 3px 10px; }

.eps { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; margin: 8px 0 20px; }
.ep {
  padding: 10px 4px; text-align: center; font-size: 12.5px; border-radius: 10px;
  background: var(--card-2); border: 1px solid var(--line); color: var(--fg); cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ep.on { background: var(--acc); border-color: var(--acc); color: #fff; font-weight: 700; }

/* -------------------------------------------------------------- tabbar --- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: grid; grid-template-columns: repeat(3, 1fr);
  height: calc(var(--tab-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: rgba(11, 13, 18, .96);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--mut); text-decoration: none; font-size: 11px; font-weight: 600;
}
.tab span { font-size: 19px; line-height: 1; }
.tab.active { color: var(--acc); }

/* -------------------------------------------------------------- player --- */
.player {
  position: fixed; inset: 0; z-index: 60; background: #000;
  display: flex; flex-direction: column;
  padding-top: var(--safe-t);
}
.player[hidden] { display: none; }
.player-head {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  background: rgba(8,10,14,.92); position: sticky; top: 0; z-index: 3;
  backdrop-filter: saturate(140%) blur(8px);
}
.player-titles { flex: 1; min-width: 0; }
.player-title { font-size: 14px; font-weight: 600; overflow: hidden;
                text-overflow: ellipsis; white-space: nowrap; }
.player-sub { font-size: 11.5px; color: var(--mut); margin-top: 1px; }
.player-head .icon-btn:disabled { opacity: .3; cursor: not-allowed; }
.video-wrap { position: relative; background: #000; }
video { width: 100%; max-height: 56vh; background: #000; display: block;
        object-fit: contain; }
.player-overlay {
  position: absolute; inset: auto 12px 12px 12px; z-index: 2;
  background: rgba(20,10,14,.88); border: 1px solid rgba(255,77,126,.5);
  color: #ffd7e3; font-size: 12.5px; line-height: 1.5;
  padding: 10px 12px; border-radius: 10px;
}
.player-overlay[hidden] { display: none; }
.tool-hint { color: var(--mut); font-size: 11px; flex-basis: 100%; line-height: 1.5; }
.spinner { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.spinner[hidden] { display: none; }
.spinner i { width: 34px; height: 34px; border-radius: 50%;
             border: 3px solid rgba(255,255,255,.25); border-top-color: var(--acc);
             animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.player-meta { padding: 10px 14px; color: var(--mut); font-size: 12.5px; }
.ep-strip { display: flex; gap: 8px; overflow-x: auto; padding: 4px 12px 16px; }
.ep-strip::-webkit-scrollbar { display: none; }
.ep-strip .ep { flex: 0 0 auto; }
.player.fullscreen .video-wrap { flex: 1; display: flex; align-items: center; }
.player.fullscreen video { max-height: none; height: 100%; }
/* Saat elemen .video-wrap sendiri yang masuk fullscreen (bukan .player). */
.video-wrap:fullscreen { display: flex; align-items: center; justify-content: center; background: #000; }
.video-wrap:fullscreen video { max-height: 100vh; height: 100%; width: auto; }

/* ------------------------------------------------------ bahasa & kualitas -- */
.lang-btn { display: inline-flex; align-items: center; gap: 3px; font-size: 13px; }
.lang-btn #langCode { font-size: 11px; color: var(--mut); letter-spacing: .5px; }

.lang-sheet {
  position: fixed; z-index: 90; left: 0; right: 0; bottom: 0;
  background: var(--bg-2); border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0; padding: 14px 14px calc(var(--safe-b) + 18px);
  box-shadow: 0 -12px 40px rgba(0,0,0,.55); max-height: 70vh; overflow-y: auto;
  animation: sheet-up .18s ease-out;
}
.lang-sheet[hidden] { display: none; }
@keyframes sheet-up { from { transform: translateY(12px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.sheet-head b { font-size: 15px; }
.lang-opts { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.lang-opt {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--card); border: 1px solid var(--line); color: var(--fg);
  padding: 11px 13px; border-radius: 12px; font-size: 14px; cursor: pointer;
  font-family: inherit; text-align: left;
}
.lang-opt.active { border-color: var(--acc); background: var(--card-2); }
.lang-opt .lang-abbr { font-size: 11px; color: var(--mut); text-transform: uppercase; letter-spacing: .5px; }
.lang-opt.active .lang-abbr { color: var(--acc); }
.sheet-note { margin: 12px 2px 0; color: var(--mut); font-size: 12px; line-height: 1.6; }

.player-tools { display: flex; flex-wrap: wrap; gap: 10px; padding: 0 14px 8px; }
.player-tools:empty { display: none; }
.player-tools .tool { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--mut); }
.player-tools .tool[hidden] { display: none; }
.player-tools select {
  background: var(--card); color: var(--fg); border: 1px solid var(--line);
  border-radius: 9px; padding: 6px 9px; font-size: 12px; font-family: inherit;
}

/* ------------------------------------------------------------ halaman detail -- */
.detail { display: flex; flex-direction: column; gap: 10px; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.detail-actions .btn { flex: 1 1 auto; }
.btn.small { padding: 7px 12px; font-size: 12px; }

.facts {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 8px; margin: 4px 0 2px; padding: 0; list-style: none;
}
.fact {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 12px; min-width: 0;
}
.fact dt { color: var(--mut); font-size: 11px; text-transform: uppercase; letter-spacing: .6px; margin: 0 0 3px; }
.fact dd { margin: 0; font-size: 14px; color: var(--fg); overflow-wrap: anywhere; }

.syn-block { margin-top: 2px; }
.synopsis.muted { color: var(--mut); font-style: italic; }

.ep-tools { margin: 0 0 8px; }
.ep-search {
  width: 100%; background: var(--card); color: var(--fg); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 12px; font-size: 13px; font-family: inherit;
}
.ep-search:focus { outline: 2px solid var(--acc); outline-offset: 1px; }
.eps .ep[hidden] { display: none; }
.muted { color: var(--mut); font-weight: 400; }

/* --------------------------------------------------------------- misc ---- */
.notice {
  background: var(--card); border: 1px solid var(--line); border-left: 3px solid var(--acc-2);
  border-radius: 12px; padding: 12px 14px; color: var(--mut); font-size: 13px; line-height: 1.6;
}
.notice b { color: var(--fg); }
.empty { text-align: center; color: var(--mut); padding: 48px 16px; font-size: 14px; }
.loading-more { text-align: center; color: var(--mut); padding: 16px; font-size: 13px; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tab-h) + var(--safe-b) + 16px); z-index: 80;
  background: var(--card-2); border: 1px solid var(--line); color: var(--fg);
  padding: 10px 16px; border-radius: 999px; font-size: 13px;
  box-shadow: 0 8px 30px rgba(0,0,0,.5); max-width: 88vw; text-align: center;
}
.toast[hidden] { display: none; }

@media (max-width: 420px) {
  .view { padding-left: 10px; padding-right: 10px; }
  .topbar { padding-left: 10px; padding-right: 10px; }
  .brand h1 { font-size: 15px; }
  .hero .ov { padding: 20px 10px 10px; }
  .hero h2 { font-size: 17px; }
  .facts { grid-template-columns: repeat(auto-fit, minmax(104px, 1fr)); }
  .fact { padding: 8px 10px; }
  .fact dd { font-size: 13px; }
  .player-tools { gap: 6px; }
  .tool { font-size: 11.5px; }
  .tool select { max-width: 92px; }
  .tool-hint { display: none; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
}
@media (min-width: 720px) {
  .view { padding: 16px 20px calc(var(--tab-h) + 32px); }
  .grid { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); }
  video { max-height: 68vh; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
