/* ============ PhimChill — phong cách điện ảnh ============ */
:root {
  --bg: #0b0b10;
  --bg-soft: #121218;
  --surface: #17171f;
  --surface-2: #1e1e28;
  --text: #f5f5f7;
  --muted: #a7a7b3;
  --accent: #e50914;
  --accent-2: #ff6a3d;
  --grad: linear-gradient(135deg, #e50914, #ff6a3d);
  --radius: 14px;
  --tabbar-h: 64px;
  --topbar-h: 60px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 15px; line-height: 1.55;
  overscroll-behavior-y: none;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
@media (min-width: 900px) {
  body { padding-bottom: 0; padding-top: var(--topbar-h); }
}
img { display: block; max-width: 100%; }
button { font-family: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* ---------- Splash ---------- */
#splash {
  position: fixed; inset: 0; z-index: 200; background: var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  transition: opacity .5s ease, visibility .5s;
}
#splash.gone { opacity: 0; visibility: hidden; }
.splash-logo {
  width: 84px; height: 84px; border-radius: 26px; background: var(--grad);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 12px 44px rgba(229, 9, 20, .45);
  animation: pop .7s cubic-bezier(.2, 1.4, .4, 1);
}
.splash-name { font-size: 30px; font-weight: 800; letter-spacing: .5px; animation: fadeUp .7s .1s both; }
@keyframes pop { from { transform: scale(.4); opacity: 0; } }
@keyframes fadeUp { from { transform: translateY(14px); opacity: 0; } }

/* ---------- Nút & chi tiết dùng chung ---------- */
.play-tri { width: 0; height: 0; border-style: solid; display: inline-block; }
.play-tri.sm { border-width: 7px 0 7px 12px; border-color: transparent transparent transparent #fff; }
.play-tri.md { border-width: 11px 0 11px 18px; border-color: transparent transparent transparent #fff; }
.play-tri.lg { border-width: 22px 0 22px 36px; border-color: transparent transparent transparent #fff; }

.btn-primary {
  border: 0; border-radius: 999px; padding: 13px 30px;
  background: var(--grad); color: #fff; font-weight: 700; font-size: 15px;
  display: inline-flex; align-items: center; gap: 10px;
  box-shadow: 0 8px 24px rgba(229, 9, 20, .35);
  transition: transform .18s ease, box-shadow .18s ease, filter .18s;
}
.btn-primary:hover { transform: translateY(-2px); filter: brightness(1.08); box-shadow: 0 12px 30px rgba(229, 9, 20, .5); }
.btn-primary:active { transform: scale(.96); }
.btn-ghost {
  border: 1px solid rgba(255, 255, 255, .28); border-radius: 999px; padding: 12px 26px;
  background: rgba(255, 255, 255, .08); color: #fff; font-weight: 600; font-size: 15px;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  transition: background .18s, transform .18s;
}
.btn-ghost:hover { background: rgba(255, 255, 255, .16); }
.btn-ghost:active { transform: scale(.96); }
.btn-ghost.on { background: var(--grad); border-color: transparent; }

.icon-btn {
  border: 0; background: transparent; color: #fff; padding: 10px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .18s, transform .18s;
}
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn:hover { background: rgba(255, 255, 255, .12); }
.icon-btn:active { transform: scale(.9); }
.icon-btn.glass { background: rgba(10, 10, 16, .5); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.icon-btn.big svg { width: 34px; height: 34px; }

/* ---------- Topbar (desktop) ---------- */
#topbar {
  display: none;
  position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-h); z-index: 60;
  align-items: center; gap: 34px; padding: 0 34px;
  background: rgba(11, 11, 16, .82); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(255, 255, 255, .07);
}
@media (min-width: 900px) { #topbar { display: flex; } }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 19px; cursor: pointer; }
.brand .play-tri.sm { border-width: 6px 0 6px 10px; }
.topnav { display: flex; gap: 6px; }
.topnav button {
  border: 0; background: transparent; color: var(--muted); font-size: 15px; font-weight: 600;
  padding: 9px 16px; border-radius: 999px; transition: color .18s, background .18s;
}
.topnav button:hover { color: #fff; }
.topnav button.active { color: #fff; background: rgba(255, 255, 255, .1); }
#topbar-search-btn { margin-left: auto; }

/* ---------- View ---------- */
.view { display: none; animation: viewIn .35s ease; }
.view.active { display: block; }
@keyframes viewIn { from { opacity: 0; transform: translateY(12px); } }

/* ---------- Hero ---------- */
.hero { position: relative; height: 62vh; min-height: 420px; max-height: 620px; overflow: hidden; }
.hero-bg {
  position: absolute; inset: -4%; background-size: cover; background-position: center 25%;
  filter: blur(2px) brightness(.9); transform: scale(1.04);
  transition: opacity .8s ease;
}
.hero-scrim {
  position: absolute; inset: 0;
  background: linear-gradient(to top, var(--bg) 4%, rgba(11, 11, 16, .55) 45%, rgba(11, 11, 16, .25) 100%);
}
.hero-content {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 26px 22px 30px;
  max-width: 760px;
}
.hero-kicker { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; font-weight: 600; letter-spacing: 1.5px; text-transform: uppercase; margin-bottom: 8px; }
.badge-cc { background: rgba(255, 255, 255, .14); border: 1px solid rgba(255, 255, 255, .25); border-radius: 6px; padding: 2px 8px; font-size: 11px; letter-spacing: 1px; }
.hero-content h1 { margin: 0 0 10px; font-size: clamp(30px, 6vw, 52px); font-weight: 800; line-height: 1.08; text-shadow: 0 4px 24px rgba(0, 0, 0, .6); }
.hero-content p {
  margin: 0 0 20px; color: #d7d7de; font-size: 14.5px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  max-width: 560px;
}
.hero-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.hero-dots { display: flex; gap: 8px; margin-top: 22px; }
.hero-dots span { width: 22px; height: 4px; border-radius: 4px; background: rgba(255, 255, 255, .28); transition: background .3s, width .3s; cursor: pointer; }
.hero-dots span.on { background: #fff; width: 34px; }

/* ---------- Hàng phim ---------- */
.row-title { font-size: 19px; font-weight: 750; margin: 30px 0 14px; padding: 0 18px; }
.rail {
  display: flex; gap: 14px; overflow-x: auto; padding: 4px 18px 14px;
  scroll-snap-type: x mandatory; scrollbar-width: none;
}
.rail::-webkit-scrollbar { display: none; }
.card {
  flex: 0 0 auto; width: 132px; scroll-snap-align: start; cursor: pointer;
  transition: transform .22s ease;
}
@media (min-width: 900px) { .card { width: 168px; } }
.card:hover { transform: translateY(-6px); }
.card .thumb {
  position: relative; aspect-ratio: 2/3; border-radius: var(--radius); overflow: hidden;
  background: var(--surface); box-shadow: 0 6px 20px rgba(0, 0, 0, .45);
  transition: box-shadow .22s ease;
}
.card:hover .thumb { box-shadow: 0 14px 34px rgba(229, 9, 20, .28); }
.card .thumb img { width: 100%; height: 100%; object-fit: cover; transition: transform .35s ease; }
.card:hover .thumb img { transform: scale(1.06); }
.card .thumb::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, .45), transparent 45%);
  opacity: 0; transition: opacity .22s;
}
.card:hover .thumb::after { opacity: 1; }
.card .progress { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgba(255, 255, 255, .25); }
.card .progress i { display: block; height: 100%; background: var(--accent); }
.card .name { margin: 9px 2px 0; font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .sub { margin: 2px 2px 0; font-size: 12px; color: var(--muted); }

/* Skeleton */
.skel .thumb { background: linear-gradient(100deg, var(--surface) 40%, var(--surface-2) 50%, var(--surface) 60%); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Lưới ---------- */
.grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; padding: 6px 18px 30px;
}
@media (min-width: 700px) { .grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 1100px) { .grid { grid-template-columns: repeat(6, 1fr); } }
.grid .card { width: auto; }
.page-title { font-size: 24px; font-weight: 800; margin: 26px 0 16px; padding: 0 18px; }

/* ---------- Tìm kiếm ---------- */
.search-head { padding: 22px 18px 6px; position: sticky; top: 0; z-index: 20; background: linear-gradient(var(--bg) 88%, transparent); }
@media (min-width: 900px) { .search-head { top: var(--topbar-h); } }
.search-box {
  display: flex; align-items: center; gap: 10px; background: var(--surface);
  border: 1px solid rgba(255, 255, 255, .09); border-radius: 14px; padding: 12px 16px;
  transition: border-color .2s, box-shadow .2s;
}
.search-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(229, 9, 20, .22); }
.search-box svg { width: 20px; height: 20px; color: var(--muted); flex: none; }
.search-box input { flex: 1; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 16px; font-family: inherit; }
.search-box input::placeholder { color: var(--muted); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 14px 2px 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid rgba(255, 255, 255, .16); background: transparent; color: var(--muted);
  border-radius: 999px; padding: 8px 18px; font-size: 13.5px; font-weight: 600;
  transition: all .2s;
}
.chip.on { background: var(--grad); border-color: transparent; color: #fff; }

.empty { text-align: center; color: var(--muted); padding: 70px 30px; font-size: 15px; }

/* ---------- Chi tiết ---------- */
.detail-hero { position: relative; height: 38vh; min-height: 260px; }
.detail-bg { position: absolute; inset: 0; background-size: cover; background-position: center 20%; filter: blur(14px) brightness(.7); transform: scale(1.12); }
.detail-scrim { position: absolute; inset: 0; background: linear-gradient(to top, var(--bg) 2%, transparent 60%); }
#detail-back { position: absolute; top: calc(14px + env(safe-area-inset-top)); left: 14px; z-index: 5; }
.detail-body { display: flex; gap: 20px; padding: 0 20px; margin-top: -90px; position: relative; z-index: 2; }
.detail-poster { width: 130px; flex: none; aspect-ratio: 2/3; object-fit: cover; border-radius: 12px; box-shadow: 0 14px 40px rgba(0, 0, 0, .6); }
@media (min-width: 900px) { .detail-poster { width: 210px; } }
.detail-info { min-width: 0; padding-top: 96px; }
@media (min-width: 900px) { .detail-info { padding-top: 100px; } }
.detail-info h1 { margin: 0 0 8px; font-size: clamp(22px, 4vw, 34px); font-weight: 800; }
.meta { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.meta span { font-size: 12.5px; color: #d7d7de; background: rgba(255, 255, 255, .1); border-radius: 8px; padding: 4px 11px; }
.detail-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.resume { color: #ffd9a8; font-size: 13.5px; font-weight: 600; margin: 0 0 10px; cursor: pointer; }
.resume:hover { text-decoration: underline; }
.detail-desc { color: #cfcfd8; font-size: 14.5px; margin: 0 0 14px; }
.license-note { font-size: 12px; color: var(--muted); border-left: 3px solid var(--accent); padding-left: 10px; }

/* ---------- Tabbar ---------- */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex; background: rgba(14, 14, 20, .9);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid rgba(255, 255, 255, .08);
}
@media (min-width: 900px) { #tabbar { display: none; } }
#tabbar button {
  flex: 1; border: 0; background: transparent; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 11px; font-weight: 600; transition: color .2s;
}
#tabbar button svg { width: 23px; height: 23px; }
#tabbar button.active { color: #fff; }
#tabbar button.active svg { filter: drop-shadow(0 0 8px rgba(229, 9, 20, .8)); }

/* ---------- Trình phát ---------- */
#player { position: fixed; inset: 0; z-index: 120; background: #000; }
#video { width: 100%; height: 100%; object-fit: contain; background: #000; }
#embed-frame { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #000; }

/* ---------- Danh sách tập ---------- */
.ep-grid { display: flex; flex-wrap: wrap; gap: 8px; padding: 2px 16px 6px; }
.ep-btn {
  border: 1px solid rgba(255, 255, 255, .16); background: rgba(255, 255, 255, .06);
  color: #fff; border-radius: 10px; padding: 9px 14px; font-size: 13.5px; font-weight: 600;
  transition: all .2s;
}
.ep-btn:active { background: var(--grad); border-color: transparent; transform: scale(.96); }
#player-ui { position: absolute; inset: 0; display: flex; flex-direction: column; transition: opacity .3s; }
#player.ui-hidden #player-ui { opacity: 0; pointer-events: none; }
#player-close { position: absolute; top: calc(14px + env(safe-area-inset-top)); left: 14px; z-index: 5; }
#player-title {
  position: absolute; top: calc(18px + env(safe-area-inset-top)); left: 64px; right: 18px;
  font-weight: 700; font-size: 16px; text-shadow: 0 2px 10px rgba(0, 0, 0, .8);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.big-play {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 92px; height: 92px; border-radius: 50%; border: 0; background: rgba(229, 9, 20, .92);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 10px 40px rgba(229, 9, 20, .55);
  transition: transform .2s;
}
.big-play:hover { transform: translate(-50%, -50%) scale(1.07); }
.controls {
  margin-top: auto; padding: 14px 18px calc(16px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0, 0, 0, .85));
}
.seek-row { display: flex; align-items: center; gap: 12px; font-size: 12.5px; color: #ddd; font-variant-numeric: tabular-nums; }
#seek { flex: 1; appearance: none; -webkit-appearance: none; height: 5px; border-radius: 5px; background: rgba(255, 255, 255, .28); outline: none; }
#seek::-webkit-slider-thumb { -webkit-appearance: none; width: 15px; height: 15px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px rgba(229, 9, 20, .8); cursor: pointer; }
#seek::-moz-range-thumb { width: 15px; height: 15px; border: 0; border-radius: 50%; background: var(--accent); cursor: pointer; }
.ctrl-row { display: flex; align-items: center; gap: 6px; margin-top: 8px; }
.ctrl-row .spacer { flex: 1; }
.player-error {
  position: absolute; inset: 0; z-index: 8; background: rgba(8, 8, 12, .96);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  text-align: center; padding: 30px;
}
.player-error p { color: var(--muted); margin: 4px 0; font-size: 14px; }
.player-error code { background: var(--surface-2); padding: 2px 8px; border-radius: 6px; color: #ffb3a8; }
.player-loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; }
.spinner { width: 52px; height: 52px; border-radius: 50%; border: 4px solid rgba(255, 255, 255, .18); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Khung xem trailer ---------- */
#trailer-modal {
  position: fixed; inset: 0; z-index: 120; background: rgba(0, 0, 0, .93);
  display: flex; align-items: center; justify-content: center; padding: 22px;
  animation: viewIn .3s ease;
}
#trailer-close { position: absolute; top: calc(14px + env(safe-area-inset-top)); right: 14px; z-index: 5; }
.trailer-box {
  position: relative; width: min(960px, 100%); aspect-ratio: 16/9;
  background: #000; border-radius: 14px; overflow: hidden;
  box-shadow: 0 20px 70px rgba(0, 0, 0, .7);
}
#trailer-frame { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 24px); transform: translateX(-50%) translateY(20px);
  background: var(--surface-2); border: 1px solid rgba(255, 255, 255, .12); color: var(--text);
  padding: 12px 22px; border-radius: 999px; font-size: 14px; font-weight: 600; z-index: 150;
  opacity: 0; transition: opacity .3s, transform .3s; pointer-events: none; white-space: nowrap;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
}
@media (min-width: 900px) { .toast { bottom: 30px; } }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
