:root {
  --bg: #09090f;
  --bg2: #12121c;
  --card: #1a1a27;
  --line: #2a2a3c;
  --text: #f4f1ea;
  --muted: #a39e96;
  --accent: #ff4d6d;
  --accent2: #ffb703;
  --ok: #3ddc97;
  --warn: #ffb703;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font-family: "Segoe UI", "Noto Sans Thai", Tahoma, sans-serif; }
body { padding-top: calc(64px + var(--safe-t)); padding-bottom: calc(72px + var(--safe-b)); }
button, input, select { font: inherit; }
img { max-width: 100%; display: block; }
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 40;
  display: flex; gap: 10px; align-items: center;
  padding: calc(8px + var(--safe-t)) 12px 8px;
  background: linear-gradient(#0b0b12, #0b0b12ee);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex; align-items: center; gap: 8px; background: none; border: 0; color: var(--text);
  font-weight: 800; white-space: nowrap; cursor: pointer;
}
.brand-mark {
  width: 28px; height: 28px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #7c4dff); font-size: 12px;
}
.searchbox { flex: 1; display: flex; min-width: 0; background: var(--bg2); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.searchbox input { flex: 1; min-width: 0; border: 0; background: transparent; color: var(--text); padding: 10px 14px; outline: none; }
.searchbox button { border: 0; background: var(--accent); color: #fff; padding: 0 14px; font-weight: 700; cursor: pointer; }
.iconbtn { width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg2); color: var(--text); cursor: pointer; }
main { max-width: 1200px; margin: 0 auto; padding: 14px 14px 24px; }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: #101018f2; border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tabbar button {
  background: none; border: 0; color: var(--muted); padding: 10px 4px 8px; cursor: pointer; font-size: 12px; font-weight: 700;
}
.tabbar button.on { color: var(--accent2); }
h1, h2, h3 { margin: 0 0 10px; }
.muted { color: var(--muted); }
.hero {
  background: radial-gradient(circle at 20% 20%, #ff4d6d33, transparent 40%), var(--card);
  border: 1px solid var(--line); border-radius: 22px; padding: 18px;
  margin-bottom: 18px;
}
.hero h1 { font-size: 26px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.chip {
  border: 1px solid var(--line); background: var(--bg2); color: var(--text);
  border-radius: 999px; padding: 8px 12px; cursor: pointer; font-size: 13px;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.chip.ghost { opacity: .7; }
.appgrid, .postergrid { display: grid; gap: 12px; }
.appgrid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.postergrid { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); }
.appcard, .postcard {
  background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  overflow: hidden; cursor: pointer; text-align: left; color: inherit; padding: 0; width: 100%;
}
.appcard { padding: 8px 4px 10px; display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; }
.appcard img { width: 42px; height: 42px; }
.appcard b { font-size: 11px; text-align: center; line-height: 1.3; max-width: 100%; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); display: inline-block; }
.dot.off { background: #666; }
.postcard {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.postcard .coverwrap {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 3;
  background: #1a1a27;
  overflow: hidden;
  flex: 0 0 auto;
}
.postcard .coverwrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.postcard .info { padding: 8px 9px 10px; }
.postcard .info b { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: 13px; min-height: 34px; }
.tag { display: inline-block; font-size: 11px; color: var(--accent2); margin-top: 4px; }
.section { margin: 18px 0; }
.section-title { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.scrollrow { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 6px; scroll-snap-type: x mandatory; }
.scrollrow .postcard { min-width: 132px; max-width: 132px; scroll-snap-align: start; }
.banner {
  display: flex; gap: 12px; align-items: center; background: var(--card);
  border: 1px solid var(--line); border-radius: 16px; padding: 12px; margin: 10px 0;
}
.banner.warn { border-color: #ffb70366; }
.field { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; }
.field input {
  background: var(--bg); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 12px;
}
.btn {
  background: var(--accent); color: #fff; border: 0; border-radius: 12px;
  padding: 12px 16px; font-weight: 800; cursor: pointer;
}
.btn.sec { background: var(--bg2); border: 1px solid var(--line); color: var(--text); }
.btn.full { width: 100%; }
.help ol { padding-left: 20px; color: var(--muted); line-height: 1.7; }
.modal {
  position: fixed; inset: 0; background: #0008; z-index: 60;
  display: none; place-items: center; padding: 16px;
}
.modal.is-open {
  display: grid;
}
.modal[hidden] {
  display: none !important;
}
.modal-card {
  position: relative;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 20px;
  padding: 18px; width: min(520px, 100%); max-height: 86vh; overflow: auto;
}
.modal-x {
  position: absolute; top: 10px; right: 10px; width: 40px; height: 40px;
  border: 0; border-radius: 999px; background: #fff2; color: #fff;
  font-size: 22px; cursor: pointer; z-index: 2;
}
.qr { display: grid; place-items: center; gap: 8px; }
.qr img { width: 220px; height: 220px; background: #fff; border-radius: 12px; padding: 8px; }
.player {
  position: fixed; inset: 0; z-index: 70; background: #050508;
  overflow: auto; display: none;
}
.player.is-open { display: block; }
.player[hidden] { display: none !important; }
.player-stage { max-width: 980px; margin: 0 auto; padding: 10px 10px 40px; }
.player.is-vertical .player-stage { max-width: 430px; }
.player.is-vertical #video {
  width: 100%;
  height: min(86vh, 820px);
  min-height: 72vh;
  object-fit: contain;
  background: #000;
  border-radius: 16px;
}
.player-close {
  position: sticky; top: 8px; z-index: 2; float: right;
  background: #000a; color: #fff; border: 1px solid #fff3; border-radius: 999px; padding: 8px 14px; cursor: pointer;
}
#video { width: 100%; max-height: 78vh; min-height: 240px; background: #000; border-radius: 14px; margin-top: 8px; object-fit: contain; }
.player-meta { display: flex; justify-content: space-between; gap: 10px; align-items: start; margin: 12px 0; }
.player-meta h2 { font-size: 18px; }
.watch-link { color: #9ad; font-size: 12px; word-break: break-all; margin: 6px 0 0; cursor: pointer; }
.quality select { background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
.eps { display: flex; flex-wrap: wrap; gap: 8px; }
.ep {
  min-width: 48px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); padding: 8px 10px; cursor: pointer;
}
.ep.on { background: var(--accent); border-color: var(--accent); }
.ep-head { display: flex; justify-content: space-between; gap: 8px; align-items: center; margin: 8px 0; flex-wrap: wrap; }
.autonext { color: var(--muted); font-size: 13px; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.pager { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin: 16px 0 8px; }
.pager .btn[disabled] { opacity: .45; pointer-events: none; }
.pager-nav { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.page-chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.page-chip {
  min-width: 36px; height: 36px; padding: 0 8px;
  border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg2); color: var(--text); cursor: pointer; font-weight: 700;
}
.page-chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.page-jump { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.page-jump input {
  width: 72px; background: var(--bg); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 8px;
}
.spinner { width: 28px; height: 28px; border: 3px solid #fff2; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 20px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.langbar, .feedbar { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 10px; }
.app-switch {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  padding: 0 0 12px;
}
.app-mini {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; min-width: 0; width: 100%;
  border: 1px solid var(--line); background: var(--bg2); color: var(--text);
  border-radius: 14px; padding: 8px 4px 6px; cursor: pointer; text-align: center;
}
.app-mini img { width: 28px; height: 28px; }
.app-mini span {
  font-size: 11px; line-height: 1.2; max-width: 100%;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.app-mini.on { border-color: var(--accent); background: #2a1520; font-weight: 700; }
.app-mini em { font-style: normal; font-size: 10px; color: var(--warn); }
.appcard.is-maintenance, .app-mini.is-maintenance { opacity: .62; }
.appcard.is-maintenance img, .app-mini.is-maintenance img { filter: grayscale(1); }
.fav { position: absolute; right: 8px; top: 8px; background: #0008; border: 0; color: #fff; border-radius: 999px; width: 32px; height: 32px; cursor: pointer; display: grid; place-items: center; z-index: 2; }
.badge { position: absolute; left: 8px; top: 8px; background: #000a; color: #fff; font-size: 11px; padding: 3px 7px; border-radius: 999px; z-index: 2; }
@media (min-width: 860px) {
  .postergrid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .appgrid, .app-switch { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .appcard img { width: 56px; height: 56px; }
  .searchbox input { padding: 12px 16px; }
}
@media (max-width: 640px) {
  .brand span:last-child { display: none; }
  .player-meta { flex-direction: column; }
  #video { max-height: 62vh; }
}
.gate {
  position: fixed; inset: 0; z-index: 100;
  display: none; place-items: center; padding: 16px;
  background: radial-gradient(circle at 20% 10%, #ff4d6d22, transparent 42%), #09090f;
}
.gate:not([hidden]) { display: grid; }
body.is-gated .topbar,
body.is-gated .tabbar,
body.is-gated #app,
body.is-gated #player { visibility: hidden; }
.gate-card {
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 22px 18px 18px;
  display: grid;
  gap: 10px;
}
.gate-card h1 { font-size: 22px; margin: 0; text-align: center; }
.gate-card p { text-align: center; }
.gate-card input {
  background: var(--bg); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 14px; letter-spacing: .12em; text-align: center;
  font-size: 18px; font-weight: 700;
}
.gate-err { color: #ff8a9a; min-height: 1.2em; }
