/* ==========================================================================
   WatchFreeMovie v2 — design system
   เขียนเอง ไม่มี build step ไม่มี Tailwind
   เป้าหมาย: byte น้อยที่สุด, CLS = 0, ใช้ได้ทั้ง desktop/mobile
   ========================================================================== */

/* ---------- tokens ---------- */
:root {
  --bg:        #0b0b0f;
  --bg-2:      #131319;
  --bg-3:      #1c1c24;
  --bg-4:      #26262f;
  --fg:        #f4f4f5;
  --fg-2:      #a1a1aa;
  --fg-3:      #71717a;
  --accent:    #e50914;
  --accent-2:  #ff1f2d;
  --star:      #f5c518;
  --line:      rgba(255,255,255,.08);
  --line-2:    rgba(255,255,255,.16);

  --r:    10px;
  --r-sm: 6px;
  --r-lg: 16px;

  --gut: 16px;
  --max: 1440px;

  --ease: cubic-bezier(.4,0,.2,1);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
          "Noto Sans Thai", "Sarabun", sans-serif;
}

@media (min-width: 768px)  { :root { --gut: 24px; } }
@media (min-width: 1280px) { :root { --gut: 40px; } }

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeSpeed;
  overflow-x: hidden;
}

img, picture, svg, video { display: block; max-width: 100%; }
img { height: auto; background: var(--bg-3); }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
ul, ol { list-style: none; padding: 0; }
h1, h2, h3, h4 { line-height: 1.25; font-weight: 700; text-wrap: balance; }

:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; border-radius: 3px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0;
  margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: -9999px; top: 8px; z-index: 200;
  background: var(--accent); color: #fff; padding: 10px 16px; border-radius: var(--r-sm);
}
.skip-link:focus { left: 8px; }

/* ---------- layout ---------- */
.wrap { width: 100%; max-width: var(--max); margin-inline: auto; padding-inline: var(--gut); }
.stack > * + * { margin-top: var(--s, 16px); }
main { min-height: 60vh; padding-bottom: 56px; }

/* ---------- header ---------- */
.hdr {
  position: sticky; top: 0; z-index: 100;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
@supports not (backdrop-filter: blur(1px)) { .hdr { background: var(--bg); } }

.hdr-in { display: flex; align-items: center; gap: 12px; height: 58px; }
@media (min-width: 768px) { .hdr-in { height: 66px; gap: 20px; } }

.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 19px; letter-spacing: -.02em; flex-shrink: 0; }
.brand b { color: var(--accent); }

.nav { display: none; gap: 4px; margin-inline-start: 8px; }
@media (min-width: 900px) { .nav { display: flex; } }
.nav a { padding: 8px 12px; border-radius: var(--r-sm); color: var(--fg-2); font-size: 14px; font-weight: 500; transition: color .15s var(--ease), background .15s var(--ease); }
.nav a:hover { color: var(--fg); background: var(--bg-3); }
.nav a[aria-current="page"] { color: var(--fg); background: var(--bg-3); }

.hdr-end { margin-inline-start: auto; display: flex; align-items: center; gap: 8px; }

.srch { position: relative; display: flex; align-items: center; }
.srch input {
  width: 150px; background: var(--bg-3); border: 1px solid var(--line);
  border-radius: 999px; padding: 8px 14px 8px 36px; font-size: 14px;
  transition: width .2s var(--ease), border-color .15s var(--ease);
}
.srch input::placeholder { color: var(--fg-3); }
.srch input:focus { width: 210px; border-color: var(--line-2); outline: none; }
.srch svg { position: absolute; inset-inline-start: 12px; width: 16px; height: 16px; color: var(--fg-3); pointer-events: none; }
@media (max-width: 599px) { .srch input { width: 40px; padding-inline: 34px 0; } .srch input:focus { width: 160px; padding-inline-end: 12px; } }

.burger { display: grid; place-items: center; width: 40px; height: 40px; border-radius: var(--r-sm); }
@media (min-width: 900px) { .burger { display: none; } }

/* drawer (mobile) */
.drawer {
  position: fixed; inset: 0 0 0 auto; width: min(82vw, 320px); z-index: 130;
  background: var(--bg-2); border-inline-start: 1px solid var(--line);
  padding: 20px var(--gut); transform: translateX(100%);
  transition: transform .25s var(--ease); overflow-y: auto;
}
.drawer[data-open="1"] { transform: translateX(0); }
.drawer a { display: block; padding: 12px 10px; border-radius: var(--r-sm); color: var(--fg-2); font-weight: 500; }
.drawer a:hover { background: var(--bg-3); color: var(--fg); }
.scrim { position: fixed; inset: 0; z-index: 120; background: rgba(0,0,0,.6); opacity: 0; pointer-events: none; transition: opacity .25s var(--ease); }
.scrim[data-open="1"] { opacity: 1; pointer-events: auto; }

/* ---------- section ---------- */
.sec { margin-top: 36px; }
.sec-hd { display: flex; align-items: baseline; gap: 12px; margin-bottom: 14px; }
.sec-hd h2 { font-size: 19px; letter-spacing: -.01em; }
@media (min-width: 768px) { .sec-hd h2 { font-size: 22px; } .sec { margin-top: 48px; } }
.sec-hd a { margin-inline-start: auto; font-size: 13px; color: var(--fg-2); font-weight: 500; flex-shrink: 0; }
.sec-hd a:hover { color: var(--accent-2); }

/* below-fold: อย่าเพิ่ง render จนกว่าจะเลื่อนถึง */
.sec.defer { content-visibility: auto; contain-intrinsic-size: auto 420px; }

/* ---------- poster grid ---------- */
.grid-p {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(136px, 1fr));
  gap: 14px 10px;
}
@media (min-width: 640px)  { .grid-p { grid-template-columns: repeat(auto-fill, minmax(155px, 1fr)); gap: 22px 14px; } }
@media (min-width: 1024px) { .grid-p { grid-template-columns: repeat(auto-fill, minmax(172px, 1fr)); gap: 26px 16px; } }

/* แถวเลื่อนแนวนอนบนมือถือ */
.rail {
  display: grid; grid-auto-flow: column; grid-auto-columns: 136px; gap: 10px;
  overflow-x: auto; scroll-snap-type: x mandatory;
  padding-bottom: 6px; margin-inline: calc(var(--gut) * -1); padding-inline: var(--gut);
  scrollbar-width: none;
}
.rail::-webkit-scrollbar { display: none; }
.rail > * { scroll-snap-align: start; }
@media (min-width: 640px)  { .rail { grid-auto-columns: 155px; gap: 14px; } }
@media (min-width: 1024px) { .rail { grid-auto-columns: 172px; gap: 16px; } }

/* ---------- card ---------- */
.card { position: relative; }
.card-link { display: block; }

.poster {
  position: relative;
  aspect-ratio: 2 / 3;          /* กัน CLS: จองที่ไว้ก่อนรูปมา */
  border-radius: var(--r);
  overflow: hidden;
  background: var(--bg-3);
  transform: translateZ(0);
}
.poster img {
  width: 100%; height: 100%; object-fit: cover;
  opacity: 0; transition: opacity .3s var(--ease), transform .35s var(--ease);
}
.poster img.on { opacity: 1; }
@media (hover: hover) {
  .card-link:hover .poster img { transform: scale(1.055); }
  .card-link:hover .poster::after { opacity: 1; }
}
.poster::after {
  content: ""; position: absolute; inset: 0; opacity: 0;
  background: linear-gradient(to top, rgba(0,0,0,.72) 0%, transparent 55%);
  transition: opacity .25s var(--ease);
}

.badge {
  position: absolute; z-index: 2; font-size: 11px; font-weight: 700;
  padding: 3px 7px; border-radius: var(--r-sm); line-height: 1.3;
  backdrop-filter: blur(6px);
}
.badge-rate { inset-block-start: 7px; inset-inline-start: 7px; background: rgba(0,0,0,.66); color: var(--star); }
.badge-q    { inset-block-start: 7px; inset-inline-end: 7px;  background: rgba(229,9,20,.9); color: #fff; }
.badge-ep   { inset-block-end: 7px;  inset-inline-start: 7px; background: rgba(0,0,0,.72); color: var(--fg); }

.card-body { padding-top: 8px; }
.card-title {
  font-size: 13.5px; font-weight: 600; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
@media (min-width: 1024px) { .card-title { font-size: 14px; } }
.card-meta { margin-top: 3px; font-size: 12px; color: var(--fg-3); display: flex; gap: 7px; }

.fav {
  position: absolute; z-index: 3; inset-block-start: 6px; inset-inline-end: 6px;
  width: 30px; height: 30px; display: grid; place-items: center;
  border-radius: 50%; background: rgba(0,0,0,.5); color: #fff;
  opacity: 0; transition: opacity .2s var(--ease), background .15s var(--ease);
}
.card:hover .fav, .fav:focus-visible, .fav[aria-pressed="true"] { opacity: 1; }
.fav[aria-pressed="true"] { color: var(--accent-2); }
.fav:hover { background: rgba(0,0,0,.75); }
@media (hover: none) { .fav { opacity: 1; } }

/* ---------- skeleton ---------- */
.skel { position: relative; overflow: hidden; background: var(--bg-3); border-radius: var(--r-sm); }
.skel::after {
  content: ""; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.06), transparent);
  animation: sweep 1.25s infinite;
}
@keyframes sweep { to { transform: translateX(100%); } }
.skel-poster { aspect-ratio: 2/3; border-radius: var(--r); }
.skel-line { height: 11px; margin-top: 8px; }
.skel-line.s { width: 55%; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 20px; border-radius: var(--r-sm); font-size: 14px; font-weight: 600;
  background: var(--bg-4); color: var(--fg); transition: background .15s var(--ease), transform .1s var(--ease);
  white-space: nowrap;
}
.btn:hover { background: #32323d; }
.btn:active { transform: scale(.975); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-2); }
.btn-ghost { background: transparent; border: 1px solid var(--line-2); }
.btn-ghost:hover { background: var(--bg-3); }

/* ---------- chips ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; padding: 7px 14px; border-radius: 999px; font-size: 13px; font-weight: 500;
  background: var(--bg-3); color: var(--fg-2); border: 1px solid transparent;
}
.chip:hover { color: var(--fg); border-color: var(--line-2); }
.chip[aria-current="page"] { background: var(--accent); color: #fff; }

/* ---------- breadcrumbs ---------- */
.crumbs { display: flex; flex-wrap: wrap; gap: 6px; font-size: 12.5px; color: var(--fg-3); padding-top: 16px; }
.crumbs a:hover { color: var(--fg); }
.crumbs li + li::before { content: "/"; margin-inline-end: 6px; color: var(--fg-3); }
.crumbs ol, .crumbs li { display: flex; gap: 6px; }

/* ---------- pagination ---------- */
.pager { display: flex; justify-content: center; gap: 6px; flex-wrap: wrap; margin-top: 40px; }
.pager a, .pager span {
  min-width: 38px; height: 38px; display: grid; place-items: center; padding-inline: 10px;
  border-radius: var(--r-sm); background: var(--bg-3); font-size: 14px; font-weight: 500; color: var(--fg-2);
}
.pager a:hover { background: var(--bg-4); color: var(--fg); }
.pager .cur { background: var(--accent); color: #fff; }
.pager .off { opacity: .35; }

/* ---------- empty ---------- */
.empty { text-align: center; padding: 64px 20px; color: var(--fg-2); }
.empty h2 { font-size: 18px; margin-bottom: 8px; color: var(--fg); }

/* ---------- footer ---------- */
.ftr { border-top: 1px solid var(--line); background: var(--bg-2); padding: 36px 0 28px; margin-top: 56px; }
.ftr-grid { display: grid; gap: 28px; grid-template-columns: 1fr; }
@media (min-width: 720px) { .ftr-grid { grid-template-columns: 1.6fr 1fr 1fr; gap: 40px; } }
.ftr h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--fg-3); margin-bottom: 12px; }
.ftr li + li { margin-top: 8px; }
.ftr a { font-size: 14px; color: var(--fg-2); }
.ftr a:hover { color: var(--fg); }
.ftr-btm { margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--fg-3); }

/* ---------- player ---------- */
.plyr {
  position: relative; width: 100%; aspect-ratio: 16 / 9;
  background: #000; border-radius: var(--r); overflow: hidden;
  contain: layout paint;
}
.plyr > iframe, .plyr .tserver-player, .plyr .tserver-player iframe {
  position: absolute; inset: 0; width: 100% !important; height: 100% !important; border: 0;
}
.plyr-cover { position: absolute; inset: 0; }
.plyr-cover img { width: 100%; height: 100%; object-fit: cover; opacity: .82; }
.plyr-play {
  position: absolute; inset-block-start: 50%; inset-inline-start: 50%;
  transform: translate(-50%, -50%);
  width: 68px; height: 68px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent); color: #fff;
  box-shadow: 0 8px 28px rgba(0,0,0,.5);
  transition: transform .15s var(--ease), background .15s var(--ease);
}
.plyr-play:hover  { background: var(--accent-2); transform: translate(-50%,-50%) scale(1.07); }
.plyr-play:active { transform: translate(-50%,-50%) scale(.96); }
.plyr-play svg { margin-inline-start: 3px; }

.plyr-spin { position: absolute; inset: 0; display: none; place-items: center; }
.plyr-spin span {
  width: 38px; height: 38px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.2); border-top-color: #fff;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.plyr-err {
  position: absolute; inset: 0; display: none; place-items: center; text-align: center;
  padding: 24px; color: var(--fg-2); font-size: 14px;
}

.plyr[data-state="loading"] .plyr-cover { opacity: .3; }
.plyr[data-state="loading"] .plyr-spin  { display: grid; }
.plyr[data-state="playing"] .plyr-cover,
.plyr[data-state="playing"] .plyr-spin  { display: none; }
.plyr[data-state="error"]   .plyr-cover,
.plyr[data-state="error"]   .plyr-spin  { display: none; }
.plyr[data-state="error"]   .plyr-err   { display: grid; }

/* ---------- watch ---------- */
.watch { padding-top: 16px; }
.watch-main { max-width: 1100px; margin-inline: auto; }
.watch-title { font-size: 21px; margin-top: 18px; }
@media (min-width: 768px) { .watch-title { font-size: 27px; } }
.watch-meta { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; font-size: 13.5px; color: var(--fg-2); align-items: center; }
.watch-meta .tag { background: var(--bg-3); border: 1px solid var(--line); padding: 2px 8px; border-radius: var(--r-sm); font-size: 12px; font-weight: 600; }
.watch-desc { margin-top: 18px; color: var(--fg-2); font-size: 14.5px; line-height: 1.7; max-width: 76ch; }

/* ---------- hero ---------- */
.hero { margin-top: 18px; }
.hero-link { display: block; position: relative; border-radius: var(--r-lg); overflow: hidden; background: var(--bg-2); }
.hero-art { position: relative; aspect-ratio: 16/9; }
@media (min-width: 900px) { .hero-art { aspect-ratio: 21/8; } }
.hero-art img { width: 100%; height: 100%; object-fit: cover; }
.hero-art::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to top, rgba(11,11,15,.96) 6%, rgba(11,11,15,.55) 45%, transparent 78%); }
.hero-body { position: absolute; inset-block-end: 0; inset-inline: 0; padding: 20px var(--gut); z-index: 2; }
@media (min-width: 900px) { .hero-body { padding: 34px 40px; } }
.hero-kicker { display: inline-block; font-size: 11px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--accent-2); margin-bottom: 8px; }
.hero-title { font-size: 24px; letter-spacing: -.02em; max-width: 20ch; }
@media (min-width: 900px) { .hero-title { font-size: 40px; } }
.hero-meta { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 10px; font-size: 13.5px; color: var(--fg-2); }
.hero-meta .tag { background: rgba(255,255,255,.1); padding: 2px 8px; border-radius: var(--r-sm); font-size: 12px; font-weight: 600; }
.hero-cta { margin-top: 16px; }

/* ---------- category tiles ---------- */
.cat-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
@media (min-width: 768px) { .cat-grid { gap: 14px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); } }
.cat-tile { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 18px; border-radius: var(--r); background: var(--bg-3); border: 1px solid var(--line); transition: background .15s var(--ease), border-color .15s var(--ease); }
.cat-tile:hover { background: var(--bg-4); border-color: var(--line-2); }
.cat-name { font-weight: 600; font-size: 14.5px; }
.cat-count { font-size: 12px; color: var(--fg-3); }

/* ---------- prose ---------- */
.prose { color: var(--fg-2); font-size: 15px; line-height: 1.75; }
.prose > * + * { margin-top: 14px; }
.prose a:not(.btn) { color: var(--accent-2); text-decoration: underline; }


/* ---------- parts this site adds to the v2 set: the series sheet, the episode
   list, the previous/next episode buttons and the wide search field. Same
   tokens as everything above. ---------- */
.shw { display: grid; grid-template-columns: 210px minmax(0, 1fr); gap: 24px; }
.shw-art { border-radius: var(--r); overflow: hidden; background: var(--bg-2); aspect-ratio: 2/3; }
.shw-art img { width: 100%; height: 100%; object-fit: cover; }
@media (max-width: 640px) {
  .shw { grid-template-columns: 130px minmax(0, 1fr); gap: 16px; }
}

.epl { list-style: none; padding: 0; display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; }
.epl a { display: flex; align-items: center; gap: 12px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 12px 14px; min-height: 48px; font-size: 14px; color: var(--fg);
  text-decoration: none; transition: background .15s var(--ease); }
.epl a:hover { background: var(--bg-3); }
.epl a.cur { background: var(--accent); border-color: var(--accent); }
.epl b { color: var(--accent-2); font-weight: 700; min-width: 22px; font-size: 13px; }
.epl a.cur b { color: #fff; }
.epl span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 640px) { .epl { grid-template-columns: 1fr; } }

.epnav { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.epnav a, .epnav .off { border: 1px solid var(--line-2); border-radius: 999px;
  padding: 10px 18px; font-size: 13.5px; font-weight: 600; color: var(--fg);
  text-decoration: none; }
.epnav a:hover { background: var(--bg-3); }
.epnav .off { color: var(--fg-3); border-color: var(--line); }

.srch-big { width: 100%; max-width: 560px; }
.srch-big input { font-size: 16px; padding-block: 12px; }


/* ---------- the visit counter is kept but takes no space and shows nothing:
   the element it draws into and the image its no-script fallback loads are both
   out of the layout, with display rather than a size of zero, so it never
   reserves a line or shifts what is around it. ---------- */
#histats_counter,
#histats_counter *,
img[src*="histats"],
a[href*="histats"] { display: none !important; }


/* ---------- the line that says what this page is, above the first row ---------- */
.lede { padding: 22px 0 4px; }
.lede h1 { font-size: clamp(21px, 2.6vw, 30px); line-height: 1.2; letter-spacing: -.02em; }
.lede p { margin-top: 8px; color: var(--fg-2); font-size: 14.5px; max-width: 74ch; }
@media (max-width: 640px) { .lede { padding: 16px 0 2px; } .lede p { font-size: 13.5px; } }
