:root {
  --bg: #0c0e13;
  --bg-2: #13161e;
  --bg-3: #1a1e28;
  --line: #262b38;
  --text: #e6e9f0;
  --muted: #8b93a7;
  --accent: #4a9eff;
  --radius: 10px;
}

* { box-sizing: border-box; }

/* คลาสที่ตั้ง display ทับ [hidden] ได้เพราะ specificity สูงกว่า
   (.player-overlay/.pager/.empty ใช้ flex กับ block) ต้องบังคับไว้ก่อน
   ไม่งั้นตัวเล่นจะเปิดค้างตั้งแต่โหลดหน้า */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Sans Thai', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 15px;
}

button { font-family: inherit; cursor: pointer; }

/* ---------------------------------------------------------- topbar */

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 18px;
  height: 58px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 9px; font-size: 16px; letter-spacing: .5px; }
.brand .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px var(--accent); }

.tabs { display: flex; gap: 4px; }

.tab {
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 14.5px;
  font-weight: 500;
  transition: background .15s, color .15s;
}
.tab:hover { color: var(--text); background: var(--bg-3); }
.tab.is-active { color: #fff; background: var(--accent); }

.search { flex: 1; max-width: 420px; }

.search input {
  width: 100%;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  padding: 9px 14px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
}
.search input:focus { border-color: var(--accent); }

.account { margin-left: auto; font-size: 13px; color: var(--muted); white-space: nowrap; }
.account.err { color: #ff6b6b; }

/* ---------------------------------------------------------- layout */

.layout { display: flex; height: calc(100vh - 58px); }

.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: var(--bg-2);
  border-right: 1px solid var(--line);
  overflow-y: auto;
}

.sidebar-head {
  padding: 16px 18px 10px;
  font-size: 12px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--muted);
}

.cats { list-style: none; margin: 0; padding: 0 8px 24px; }

.cats li {
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cats li:hover { background: var(--bg-3); color: var(--text); }
.cats li.is-active { background: var(--bg-3); color: var(--accent); font-weight: 600; }

.content { flex: 1; overflow-y: auto; padding: 22px 26px 60px; }

.content-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 18px; }
.content-head h1 { margin: 0; font-size: 21px; font-weight: 600; }
.count { color: var(--muted); font-size: 13.5px; }

/* ---------------------------------------------------------- grid */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 14px;
}

.card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform .13s, border-color .13s;
}
.card:hover { transform: translateY(-3px); border-color: var(--accent); }

.card .thumb {
  aspect-ratio: 16 / 10;
  background: var(--bg-3) center / contain no-repeat;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 12px;
}
.card.poster .thumb { aspect-ratio: 2 / 3; background-size: cover; }

.card .label {
  padding: 9px 11px;
  font-size: 13.5px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 48px;
}

.badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--bg-3);
  color: var(--accent);
  font-size: 10.5px;
  vertical-align: middle;
}

/* ---------------------------------------------------------- pager */

.pager { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: 28px; }

.pager button {
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 14px;
}
.pager button:hover:not(:disabled) { border-color: var(--accent); }
.pager button:disabled { opacity: .35; cursor: default; }
#pageinfo { color: var(--muted); font-size: 13.5px; }

.empty, .loading { text-align: center; color: var(--muted); padding: 60px 0; }

/* ---------------------------------------------------------- player */

.player-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 10, .9);
  backdrop-filter: blur(6px);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.player-box {
  position: relative;
  width: min(1060px, 100%);
  max-height: 100%;
  overflow-y: auto;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, .65);
  color: #fff;
  font-size: 15px;
}
.close:hover { background: var(--accent); }

.video-wrap { position: relative; background: #000; aspect-ratio: 16 / 9; }
.video-wrap video { width: 100%; height: 100%; display: block; background: #000; }

.video-msg {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  color: var(--muted);
  font-size: 14px;
  background: rgba(0, 0, 0, .55);
}

.player-meta { padding: 18px 22px 24px; }
.player-meta h2 { margin: 0 0 6px; font-size: 19px; font-weight: 600; }
.player-meta .sub { color: var(--muted); font-size: 13.5px; margin-bottom: 14px; }

.epg-item, .ep-item {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 7px;
  font-size: 13.5px;
  background: var(--bg-3);
}
.epg-item.now { border-color: var(--accent); }
.epg-item .time { color: var(--muted); font-size: 12px; margin-right: 8px; }

.ep-item { cursor: pointer; }
.ep-item:hover { border-color: var(--accent); }

.season-head { margin: 16px 0 8px; font-size: 14px; color: var(--muted); }

/* ---------------------------------------------------------- mobile */

@media (max-width: 860px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 16px; gap: 10px; }
  .search { order: 3; max-width: none; flex-basis: 100%; }
  .account { font-size: 12px; }
  .layout { flex-direction: column; height: auto; }
  .sidebar {
    width: 100%;
    max-height: 180px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .cats { display: flex; flex-wrap: wrap; gap: 6px; }
  .cats li { border: 1px solid var(--line); }
  .content { padding: 16px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(136px, 1fr)); gap: 10px; }
  .player-overlay { padding: 0; }
  .player-box { border-radius: 0; height: 100%; }
}
