/* === AVMovieX UX v13 — สัดส่วน / ความคมชัด / มือถือ+เดสก์ท็อป === */

:root {
  --avx-bg: #0a0a0e;
  --avx-surface: #121018;
  --avx-surface-2: #18141f;
  --avx-line: rgba(168, 85, 247, 0.22);
  --avx-accent: #8b5cf6;
  --avx-accent-soft: rgba(139, 92, 246, 0.16);
  --avx-text: #f5f3ff;
  --avx-muted: rgba(237, 233, 254, 0.62);
  --avx-radius: 0.85rem;
  --avx-header-h: 3.5rem;
}

html {
  scroll-behavior: smooth;
}

body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background: var(--avx-bg);
  color: var(--avx-text);
  text-rendering: optimizeLegibility;
}

/* --- Header / Nav --- */
header {
  min-height: var(--avx-header-h);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(10, 10, 14, 0.82) !important;
}

header a[href="/"][class*="items-center"] {
  gap: 0.65rem !important;
}

header nav,
header [class*="gap-"] {
  scrollbar-width: none;
}

@media (max-width: 767px) {
  header {
    --avx-header-h: 3.25rem;
  }
  /* เมนูแนวนอนเลื่อนได้บนมือถือ ไม่เบียด */
  header nav {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
    padding-bottom: 2px;
  }
  header a {
    flex: 0 0 auto;
    white-space: nowrap;
    min-height: 36px;
    padding-left: 0.7rem !important;
    padding-right: 0.7rem !important;
    font-size: 0.8125rem !important;
  }
}

/* --- Hero / Search --- */
main h1,
h1 {
  letter-spacing: -0.02em;
  line-height: 1.25;
}

@media (max-width: 640px) {
  main h1,
  h1 {
    font-size: 1.35rem !important;
    padding-inline: 0.25rem;
  }
}

form:has(input[type="text"]),
form:has(input[placeholder*="รหัส"]) {
  gap: 0.65rem;
}

input[type="text"],
input[placeholder] {
  background: var(--avx-surface) !important;
  border-color: var(--avx-line) !important;
  color: var(--avx-text) !important;
  min-height: 44px;
}

input::placeholder {
  color: rgba(196, 181, 253, 0.45) !important;
}

input[type="text"]:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.35), 0 0 24px rgba(139, 92, 246, 0.12);
}

button[type="submit"],
form button {
  min-height: 44px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

/* --- Category pills --- */
a[href^="/genre/"],
a[href="/genres"] {
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.15s ease;
}

a[href^="/genre/"]:hover,
a[href="/genres"]:hover {
  border-color: rgba(168, 85, 247, 0.45) !important;
  background: rgba(139, 92, 246, 0.2) !important;
}

@media (max-width: 640px) {
  /* แท็กหมวดบนหน้าแรก: แถวเดียวเลื่อนแทนม้วนหลายบรรทัด */
  section:has(a[href^="/genre/"]) ul,
  .tag-cloud ul,
  div:has(> a[href^="/genre/"]) {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 0.5rem !important;
    justify-content: flex-start !important;
    padding: 0.15rem 0.25rem 0.5rem;
    scrollbar-width: thin;
  }
  a[href^="/genre/"],
  a[href="/genres"] {
    flex: 0 0 auto;
    min-height: 36px;
    display: inline-flex !important;
    align-items: center;
  }
}

/* --- Movie cards --- */
a[href^="/watch/"] {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  border-radius: var(--avx-radius) !important;
  overflow: hidden;
  background: var(--avx-surface) !important;
  border: 1px solid rgba(168, 85, 247, 0.14) !important;
  transition: transform 0.22s cubic-bezier(0.25, 0.46, 0.45, 0.94),
    box-shadow 0.22s ease, border-color 0.22s ease;
  will-change: transform;
}

a[href^="/watch/"]:hover {
  transform: translateY(-3px);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(139, 92, 246, 0.28);
  border-color: rgba(139, 92, 246, 0.4) !important;
}

a[href^="/watch/"] img,
a[href^="/watch/"] picture,
a[href^="/watch/"] video {
  border-radius: 0;
}

/* ชื่อเรื่องสูงคงที่ ให้วันที่เรียงเส้นเดียวกัน */
a[href^="/watch/"] .line-clamp-2,
a[href^="/watch/"] [class*="line-clamp"] {
  min-height: 2.6em;
  line-height: 1.35 !important;
  font-size: 0.8125rem !important;
  color: rgba(255, 255, 255, 0.92) !important;
}

a[href^="/watch/"] time,
a[href^="/watch/"] .text-xs,
a[href^="/watch/"] [class*="text-white/40"],
a[href^="/watch/"] [class*="text-white\/40"] {
  color: rgba(196, 181, 253, 0.55) !important;
  font-variant-numeric: tabular-nums;
}

/* ป้ายรหัส */
a[href^="/watch/"] span:first-of-type {
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #f3e8ff !important;
  -webkit-text-fill-color: #f3e8ff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.65);
}

/* ไอคอนเล่นเบาๆ — ไม่บังพรีวิว */
a[href^="/watch/"]::before {
  content: "";
  position: absolute;
  top: 42%;
  left: 50%;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 11px 0 11px 18px;
  border-color: transparent transparent transparent rgba(255, 255, 255, 0.88);
  transform: translate(-40%, -50%) scale(0.85);
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.55));
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
  z-index: 4;
}

a[href^="/watch/"]:hover::before {
  opacity: 0.9;
  transform: translate(-40%, -50%) scale(1);
}

/* เมื่อมีวิดีโอพรีวิว ให้ซ่อนไอคอนเล่น */
a[href^="/watch/"]:has(video[src])::before,
a[href^="/watch/"]:has(video:not([src=""]))::before {
  opacity: 0 !important;
}

a[href^="/watch/"] video {
  /* วิดีโอว่างต้องไม่บังปก */
  display: none !important;
}
a[href^="/watch/"] video[src],
a[href^="/watch/"] video:not([src=""]) {
  display: block !important;
  position: absolute !important;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  object-fit: cover;
  z-index: 6 !important;
  opacity: 1 !important;
  visibility: visible !important;
  background: #000;
  pointer-events: none;
}

/* กริดให้การ์ดสูงเท่ากัน */
.grid {
  align-items: stretch;
}

@media (max-width: 640px) {
  .grid.grid-cols-2,
  .grid-cols-2 {
    gap: 0.55rem !important;
  }
  a[href^="/watch/"] .line-clamp-2,
  a[href^="/watch/"] [class*="line-clamp"] {
    font-size: 0.75rem !important;
    min-height: 2.45em;
  }
}

@media (min-width: 768px) {
  .md\:grid-cols-4,
  .grid {
    gap: 1rem !important;
  }
}

/* --- Watch page --- */
video:not([src*="preview"]) {
  border-radius: 0.75rem;
  background: #000;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
}

@media (min-width: 1024px) {
  main .max-w-5xl,
  main .max-w-4xl,
  main .max-w-6xl {
    max-width: 72rem;
  }
}

/* แท็กบนหน้าดูหนัง */
a[href^="/genre/"][class*="rounded-full"] {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
}

/* --- Footer contrast --- */
footer {
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
  margin-top: 3.5rem !important;
  padding: 2.25rem 1rem 2.75rem !important;
  border-top: 1px solid rgba(139, 92, 246, 0.2) !important;
  background: linear-gradient(180deg, rgba(18, 16, 24, 0.4), rgba(18, 16, 24, 0.95)) !important;
  color: rgba(237, 233, 254, 0.78) !important;
}

footer nav[aria-label="legal"],
footer nav {
  display: flex !important;
  flex-wrap: wrap !important;
  justify-content: center !important;
  gap: 0.55rem 1.1rem !important;
  margin-bottom: 0.9rem !important;
}

footer a {
  color: rgba(196, 181, 253, 0.92) !important;
  text-decoration: none !important;
  font-size: 0.875rem;
}

footer a:hover {
  color: #fff !important;
  text-decoration: underline !important;
}

footer p {
  color: rgba(237, 233, 254, 0.55) !important;
  text-align: center;
  font-size: 0.8125rem;
  line-height: 1.55;
}

/* --- Genres page --- */
@media (min-width: 768px) {
  ul:has(> li > a[href^="/genre/"]) {
    max-width: 72rem;
    margin-inline: auto;
    justify-content: flex-start !important;
  }
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}
::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.04);
}
::-webkit-scrollbar-thumb {
  background: rgba(139, 92, 246, 0.35);
  border-radius: 999px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(139, 92, 246, 0.55);
}

/* --- Touch --- */
@media (hover: none) and (pointer: coarse) {
  a[href^="/watch/"] {
    -webkit-tap-highlight-color: rgba(139, 92, 246, 0.18);
  }
  a[href^="/watch/"]:active {
    transform: scale(0.985);
  }
  a[href^="/watch/"]::before {
    display: none;
  }
}

/* --- Reduce motion --- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}


/* --- v13.1 refinements --- */
a[href^="/watch/"]:has(video[src])::before {
  opacity: 0 !important;
}
a[href^="/watch/"] video[src] {
  z-index: 6 !important;
}
@media (max-width: 767px) {
  header {
    padding-inline: 0.75rem !important;
  }
}
