:root {
  --bg: #141414;
  --surface: #1f1f1f;
  --surface-2: #2a2a2a;
  --hover: #333333;
  --accent: #e50914;
  --accent-hover: #f6121d;
  --text: #ffffff;
  --muted: #b3b3b3;
  --border: rgba(255,255,255,0.12);
  --thai: #2ecc71;
  --sub: #4fc3f7;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
  font-family: 'Kanit', 'Prompt', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

.auth-loader {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
.auth-loader.hide { display: none; }
.auth-loader-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255,255,255,0.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.auth-loader-text { font-size: 13px; color: var(--muted); }

.toast-banner {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(28, 28, 28, 0.96);
  color: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 12px;
  z-index: 950;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  max-width: 92vw;
  text-align: center;
}
.toast-banner.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast-banner.error { border-color: rgba(229, 9, 20, 0.65); color: #ff8a8a; }
.toast-banner.success { border-color: rgba(46, 204, 113, 0.6); color: #7ef2ad; }

header {
  position: sticky;
  top: 0;
  z-index: 60;
  background: linear-gradient(180deg, rgba(10,10,10,0.97) 0%, rgba(20,20,20,0.94) 100%);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 10px 12px 8px;
}

.brand-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.user-pill {
  font-size: 11px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 4px 8px;
  border-radius: 999px;
}

.count-tag {
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  padding: 1px 6px;
  font-size: 10px;
  margin-left: 2px;
}
.count-tag.hide { display: none; }

.logo {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 1px;
  color: var(--accent);
  text-transform: uppercase;
  white-space: nowrap;
  cursor: pointer;
}

.icon-btn {
  background: var(--surface-2);
  color: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: 0.15s;
}
.icon-btn:hover { background: var(--hover); }
.icon-btn.active-fav { border-color: #ff4757; color: #ff6b81; background: rgba(255,71,87,0.14); }

.site-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 8px;
}

.site-btn {
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: 0.15s;
}
.site-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.search-row {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
  width: 100%;
}
.search-row input {
  flex: 1;
  min-width: 0;
  background: var(--surface);
  color: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 11px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
}
.search-row input:focus { border-color: #fff; }

.btn-red {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0 13px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.btn-red:hover { background: var(--accent-hover); }

.btn-ghost {
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  flex: 0 0 auto;
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: 0.15s;
}
.tab.active {
  background: #fff;
  color: #141414;
  border-color: #fff;
  font-weight: 700;
}

main { max-width: 1280px; margin: 0 auto; padding: 12px; }
.page { display: none; }
.page.active { display: block; }

.status-bar {
  font-size: 12px;
  color: var(--muted);
  padding: 6px 2px 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
@media (min-width: 540px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; } }
@media (min-width: 820px) { .grid { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; } }

.card {
  background: var(--surface);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  border: 1px solid rgba(255,255,255,0.06);
  transition: transform 0.2s ease, border-color 0.2s ease;
  display: flex;
  flex-direction: column;
  position: relative;
}
.card:hover { transform: translateY(-3px); border-color: rgba(255,255,255,0.35); }

.poster-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 3;
  background: #101010;
  overflow: hidden;
}
.poster-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; }

.badge {
  position: absolute;
  bottom: 6px;
  right: 6px;
  background: rgba(20,20,20,0.88);
  border: 1px solid rgba(255,255,255,0.2);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  max-width: 80%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fav-mini-btn {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.22);
  background: rgba(15,15,15,0.78);
  color: #fff;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 3;
}
.fav-mini-btn.active {
  color: #ff4757;
  border-color: rgba(255,71,87,0.7);
}

.card-del-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1.5px solid #ffffff;
  background: var(--accent);
  color: #ffffff;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 20;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.65);
  transition: transform 0.15s ease, background 0.15s ease;
}
.card-del-btn:hover {
  transform: scale(1.06);
  background: var(--accent-hover);
}


.card-title {
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
  padding: 8px;
  color: #f3f3f3;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.card-meta {
  font-size: 11px;
  color: var(--muted);
  padding: 0 8px 8px;
}

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin: 22px 0 12px;
}
.page-btn {
  background: var(--surface);
  color: #fff;
  border: 1px solid var(--border);
  padding: 7px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.page-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.detail-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.back-btn {
  background: var(--surface-2);
  color: #fff;
  border: 1px solid var(--border);
  padding: 7px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.mode-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.detail-title { font-size: 17px; font-weight: 700; line-height: 1.35; margin-bottom: 6px; }
.play-mode-info { font-size: 12px; color: var(--thai); min-height: 18px; margin-bottom: 6px; }

.resume-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: rgba(79, 195, 247, 0.12);
  border: 1px solid rgba(79, 195, 247, 0.35);
  color: #d8f2ff;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.player-box {
  background: #000;
  border-radius: 10px;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 14px;
  border: 1px solid var(--border);
}
.player-box video, .player-box iframe { width: 100%; height: 100%; border: 0; }

.ep-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 14px;
}
.ep-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  padding-bottom: 10px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.ep-header h3 { font-size: 14px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.track-filter { display: flex; gap: 6px; flex-wrap: wrap; }

.track-pill {
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
.track-pill.active { background: #fff; color: #141414; border-color: #fff; }

.track-group {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255,255,255,0.02);
  margin-bottom: 8px;
  overflow: hidden;
}
.track-group:last-child { margin-bottom: 0; }

.track-toggle {
  width: 100%;
  background: rgba(255,255,255,0.04);
  border: none;
  color: #fff;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  text-align: left;
}
.track-toggle:hover { background: rgba(255,255,255,0.08); }
.track-toggle.tag-thai { color: var(--thai); }
.track-toggle.tag-sub  { color: var(--sub); }
.track-arrow { font-size: 11px; color: var(--muted); font-weight: 500; }

.track-body {
  display: none;
  padding: 10px;
  border-top: 1px solid var(--border);
}
.track-group.open .track-body { display: block; }

.eps-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
  max-height: 240px;
  overflow-y: auto;
  padding-right: 2px;
}
@media (min-width: 600px) { .eps-grid { grid-template-columns: repeat(8, minmax(0, 1fr)); } }

.ep-btn {
  background: var(--surface-2);
  color: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  text-align: center;
  transition: 0.15s;
}
.ep-btn:hover { background: var(--hover); border-color: rgba(255,255,255,0.3); }
.ep-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.ep-subtag {
  font-size: 9px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 4px;
  line-height: 1.2;
}
.ep-subtag.thai { background: rgba(46, 204, 113, 0.2); color: var(--thai); }
.ep-subtag.sub  { background: rgba(79, 195, 247, 0.2); color: var(--sub); }
.ep-btn.active .ep-subtag { background: rgba(255,255,255,0.22); color: #fff; }

.log-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--muted);
}
.copy-btn {
  background: #fff;
  color: #141414;
  border: none;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}
.log {
  display: none;
  background: #0b0b0b;
  border: 1px solid var(--border);
  padding: 10px;
  border-radius: 8px;
  font-family: monospace;
  font-size: 11px;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 160px;
  overflow: auto;
  color: #a6e3a1;
}
.log.open { display: block; }

.limit-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
}
.limit-overlay.show { display: flex; }
.limit-card {
  background: var(--surface);
  border: 1px solid rgba(229, 9, 20, 0.5);
  border-radius: 12px;
  padding: 22px 18px;
  max-width: 360px;
  width: 100%;
  text-align: center;
}
.limit-icon { font-size: 32px; margin-bottom: 8px; }
.limit-title { font-size: 16px; font-weight: 700; margin-bottom: 8px; color: #ff6b6b; }
.limit-desc { font-size: 13px; color: var(--muted); line-height: 1.5; margin-bottom: 16px; }
