/*
Theme Name: หนังสั้นฟรี
Description: ธีมสำหรับดูหนังสั้นแนวตั้ง สีขาวแดง เลื่อนดูต่อเนื่องแบบเต็มจอ
Version: 1.4.1
Requires PHP: 8.0
Text Domain: nungsunfree
*/

:root {
  --red: #d00f24;
  --red-deep: #9f0a1a;
  --red-tint: #fff0f1;
  --ink: #1d1416;
  --muted: #6d5f62;
  --line: #f1e2e4;
  --white: #fff;
  --head-h: 64px;
  --bar-h: 0px;
  --radius: 14px;
  --font: 'Anuphan', 'Noto Sans Thai', 'Leelawadee UI', system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--white); color: var(--ink); font: 400 16px/1.55 var(--font); }
body.admin-bar { --bar-h: 32px; }
img, video, iframe { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, p { margin: 0; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
:focus-visible { outline: 3px solid var(--red); outline-offset: 2px; }
.icon { width: 22px; height: 22px; flex: none; }
.screen-reader-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip-link { position: absolute; left: 12px; top: -60px; z-index: 50; padding: 10px 14px; background: var(--red); color: var(--white); border-radius: 8px; }
.skip-link:focus { top: 8px; }

/* Header */
.site-head { position: sticky; top: var(--bar-h); z-index: 20; display: flex; align-items: center; gap: 24px; height: var(--head-h); padding: 0 clamp(16px, 4vw, 40px); background: var(--white); border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; align-items: center; gap: 10px; flex: none; }
.brand__mark { display: block; width: 25px; height: 36px; flex: none; }
.brand__name { font-size: 22px; font-weight: 800; letter-spacing: -.01em; }
.brand__name b { color: var(--red); font-weight: 800; }
.site-nav { flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.site-nav::-webkit-scrollbar { display: none; }
.site-nav ul { display: flex; gap: 22px; margin: 0; padding: 0; list-style: none; font-weight: 600; white-space: nowrap; }
.site-nav a { display: block; padding: 10px 0; border-bottom: 3px solid transparent; }
.site-nav a:hover, .site-nav .current-menu-item a { color: var(--red); }
.site-nav .current-menu-item a { border-bottom-color: var(--red); }
.search { display: flex; align-items: center; gap: 8px; flex: 0 1 280px; min-width: 0; height: 42px; margin-left: auto; padding: 0 14px; color: var(--muted); background: var(--red-tint); border: 1px solid transparent; border-radius: 21px; }
.search:focus-within { background: var(--white); border-color: var(--red); }
.search input { flex: 1; min-width: 0; color: var(--ink); background: none; border: 0; outline: 0; -webkit-appearance: none; appearance: none; }
.search input::placeholder { color: var(--muted); }

/* Page shell */
.page { width: min(1320px, 100%); margin: 0 auto; padding: 20px clamp(16px, 4vw, 40px) 40px; }
.page-head { margin: 8px 0 16px; }
.page-head h1 { font-size: clamp(26px, 4vw, 38px); font-weight: 800; line-height: 1.2; }
.page > .search { margin: 0 0 20px; flex: none; max-width: 480px; }
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 0 26px; font-weight: 800; color: var(--red); background: var(--white); border-radius: 24px; }
.btn:hover { background: var(--red-tint); }
.btn--solid { color: var(--white); background: var(--red); }
.btn--solid:hover { background: var(--red-deep); }
.empty { padding: 56px 16px; color: var(--muted); text-align: center; }
.empty h1 { margin-bottom: 8px; color: var(--ink); font-size: 30px; font-weight: 800; }
.empty .btn { margin-top: 20px; }

/* Film cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 22px 14px; }
.poster { position: relative; aspect-ratio: 9 / 16; overflow: hidden; background: linear-gradient(160deg, #f6c7cc, var(--red)); border-radius: var(--radius); }
.poster img { width: 100%; height: 100%; object-fit: cover; }
.card a:hover .poster img { transform: scale(1.04); }
.card .poster img { transition: transform .3s ease; }
.poster__time { position: absolute; right: 8px; bottom: 8px; padding: 1px 7px; font-size: 13px; font-weight: 600; color: var(--white); background: rgba(20, 8, 10, .78); border-radius: 6px; }
.poster__rank { position: absolute; top: 0; left: 0; min-width: 44px; padding: 4px 12px 6px; font-size: 26px; font-weight: 800; line-height: 1.1; text-align: center; color: var(--white); background: var(--red); border-bottom-right-radius: var(--radius); }
.card__title { display: -webkit-box; margin-top: 9px; overflow: hidden; font-size: 16px; font-weight: 600; line-height: 1.4; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.card a:hover .card__title { color: var(--red); }
.card__meta { margin-top: 2px; font-size: 14px; color: var(--muted); }

/* Pagination */
.pagination { margin-top: 32px; }
.nav-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.page-numbers { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; height: 44px; padding: 0 12px; font-weight: 600; border: 1px solid var(--line); border-radius: 10px; }
a.page-numbers:hover { color: var(--red); border-color: var(--red); }
.page-numbers.current { color: var(--white); background: var(--red); border-color: var(--red); }
.page-numbers.dots { border-color: transparent; }

.prose { max-width: 760px; }
.prose h1 { margin-bottom: 16px; font-size: 34px; font-weight: 800; line-height: 1.25; }
.prose a { color: var(--red); text-decoration: underline; }
.prose p { margin-bottom: 1em; }

/* Footer and mobile tab bar */
.site-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 20px; padding: 22px clamp(16px, 4vw, 40px); font-size: 14px; color: var(--muted); border-top: 1px solid var(--line); }
.site-foot .brand__name { font-size: 18px; color: var(--ink); }
.tabbar { display: none; }

/* Vertical feed */
body.is-feed { height: 100dvh; overflow: hidden; }
.feed { height: calc(100vh - var(--head-h) - var(--bar-h)); height: calc(100dvh - var(--head-h) - var(--bar-h)); overflow-y: auto; overscroll-behavior: contain; scroll-snap-type: y mandatory; scrollbar-width: none; outline: 0; }
.feed::-webkit-scrollbar { display: none; }
.slide { display: grid; grid-template-columns: auto minmax(280px, 400px); justify-content: center; gap: 36px; height: 100%; padding: 20px; scroll-snap-align: start; scroll-snap-stop: always; }
.slide__stage { position: relative; height: 100%; aspect-ratio: 9 / 16; overflow: hidden; background: linear-gradient(160deg, #f6c7cc, var(--red)); border-radius: 18px; }
.slide__cover { width: 100%; height: 100%; object-fit: cover; }
.slide__media { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; border: 0; }
.slide__missing { position: absolute; inset: auto 16px 24px; padding: 10px 14px; font-weight: 600; text-align: center; color: var(--red); background: var(--white); border-radius: 10px; }
.slide__info { display: flex; flex-direction: column; justify-content: flex-end; gap: 20px; min-width: 0; padding-bottom: 8px; }
.slide__genre { display: inline-block; margin-bottom: 8px; padding: 3px 12px; font-size: 14px; font-weight: 600; color: var(--red); background: var(--red-tint); border-radius: 14px; }
.slide__title { font-size: clamp(24px, 2.4vw, 32px); font-weight: 800; line-height: 1.25; }
.slide__meta { margin-top: 6px; font-size: 15px; color: var(--muted); }
.slide__summary { margin-top: 12px; color: var(--ink); }
.slide__tags { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 10px; font-size: 14px; color: var(--muted); }
.slide__tags a:hover { color: var(--red); }
.slide__actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.act { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 44px; min-width: 44px; padding: 0 14px; font-size: 15px; font-weight: 600; background: var(--white); border: 1px solid var(--line); border-radius: 22px; }
.act:hover:not(:disabled) { color: var(--red); border-color: var(--red); }
.act:disabled { opacity: .35; cursor: default; }
.act--nav { padding: 0; }
.act--next { color: var(--white); background: var(--red); border-color: var(--red); }
.act--next:hover:not(:disabled) { color: var(--white); background: var(--red-deep); border-color: var(--red-deep); }
[data-like][aria-pressed='true'] { color: var(--red); background: var(--red-tint); border-color: var(--red); }
[data-like][aria-pressed='true'] .icon { fill: currentColor; }
.toast { position: fixed; left: 50%; bottom: 28px; z-index: 40; max-width: calc(100vw - 32px); padding: 10px 18px; font-weight: 600; color: var(--white); background: var(--ink); border-radius: 22px; transform: translateX(-50%); }
.toast[hidden] { display: none; }

@media (max-width: 860px) {
  .site-head { flex-wrap: wrap; gap: 4px 12px; height: auto; padding-top: 8px; }
  .site-head .search { flex: 1 1 120px; }
  .site-nav { order: 3; flex: 0 0 calc(100vw - 32px); }
  .brand__name { font-size: 20px; }
  .brand__mark { width: 21px; height: 30px; }
  .page { padding-top: 14px; padding-bottom: 24px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 18px 10px; }
  .site-foot { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
  .tabbar { position: fixed; inset: auto 0 0; z-index: 30; display: grid; grid-template-columns: repeat(3, 1fr); padding-bottom: env(safe-area-inset-bottom); background: var(--white); border-top: 1px solid var(--line); }
  .tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; min-height: 60px; font-size: 13px; font-weight: 600; color: var(--muted); }
  .tabbar a[aria-current='page'], .tabbar__main { color: var(--red) !important; }

  /* The feed takes the whole phone screen; navigation moves into each slide's white strip */
  body.is-feed .site-head { display: none; }
  .feed { height: calc(100vh - var(--bar-h)); height: calc(100dvh - var(--bar-h)); }
  .slide { display: flex; flex-direction: column; gap: 0; padding: 0; }
  .slide__stage { flex: 1; min-height: 0; width: 100%; height: auto; aspect-ratio: auto; background: #000; border-radius: 0; }
  .slide__cover { object-fit: contain; }
  .slide__info { flex: none; gap: 8px; padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); background: var(--white); border-top: 3px solid var(--red); }
  .slide__genre { display: none; }
  .slide__title { display: -webkit-box; overflow: hidden; font-size: 17px; line-height: 1.35; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
  .slide__meta { margin-top: 1px; font-size: 13px; }
  .slide__summary, .slide__tags { display: none; }
  .slide__actions { flex-wrap: nowrap; gap: 6px; }
  .act { padding: 0 11px; font-size: 14px; }
  .act--home span, .act[data-share] span { display: none; }
  .act--nav { display: none; }
  .act--next { margin-left: auto; padding: 0 16px; }
  .toast { bottom: 130px; }
}

@media (max-width: 782px) {
  body.admin-bar { --bar-h: 46px; }
}

@media (prefers-reduced-motion: reduce) {
  .card .poster img { transition: none; }
  .card a:hover .poster img { transform: none; }
}
