:root {
  --bg: var(--tg-theme-bg-color, #0f1117);
  --bg-elev: var(--tg-theme-secondary-bg-color, #181c26);
  --text: var(--tg-theme-text-color, #f4f6fb);
  --muted: var(--tg-theme-hint-color, #9aa4b8);
  --accent: var(--tg-theme-button-color, #ff4d6d);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --border: rgba(255, 255, 255, 0.08);
  --radius: 14px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Kantumruy Pro", "Noto Sans Khmer", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  overscroll-behavior: none;
}

.app-shell {
  min-height: 100vh;
  padding-bottom: calc(74px + env(safe-area-inset-bottom, 0px));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: rgba(15, 17, 23, 0.88);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  font-size: 24px;
}

.brand-title {
  font-weight: 800;
  letter-spacing: 0.4px;
  font-size: 16px;
}

.brand-sub {
  font-size: 11px;
  color: var(--muted);
}

.vip-pill {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: var(--bg-elev);
  border: 1px solid var(--border);
}

.vip-pill.vip {
  background: linear-gradient(135deg, #ffb703, #fb8500);
  color: #16120b;
  border-color: transparent;
}

.main-content {
  padding: 12px;
  max-width: 720px;
  margin: 0 auto;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

input[type="search"],
input[type="url"],
input[type="number"],
.select-input,
select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 14px;
  outline: none;
}

input:focus, select:focus {
  border-color: var(--accent);
}

.btn-primary,
.btn-secondary,
.btn-ghost {
  border: none;
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
}

.btn-secondary {
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-ghost {
  background: transparent;
  color: var(--text);
  padding: 6px 10px;
}

.full-width {
  width: 100%;
}

.pill-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  scrollbar-width: none;
}

.pill-row::-webkit-scrollbar {
  display: none;
}

.pill {
  flex: 0 0 auto;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.pill.active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
}

.status-line {
  font-size: 12px;
  color: var(--muted);
  margin: 4px 0 10px;
  min-height: 18px;
}

.drama-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

@media (min-width: 560px) {
  .drama-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.drama-card {
  background: var(--bg-elev);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  flex-direction: column;
}

.drama-cover-wrap {
  position: relative;
  aspect-ratio: 3 / 4;
  background: #1d2230;
  overflow: hidden;
}

.drama-cover-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.ep-badge {
  position: absolute;
  bottom: 6px;
  right: 6px;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 6px;
}

.drama-card-title {
  padding: 7px 8px;
  font-size: 12px;
  font-weight: 600;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}

.section-title {
  margin: 0 0 8px;
  font-size: 15px;
}

.muted {
  color: var(--muted);
  margin: 0 0 10px;
}

.small {
  font-size: 12px;
}

.row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.between {
  justify-content: space-between;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(255, 77, 109, 0.16);
  color: #ff8fa3;
  font-weight: 700;
}

.mini-field {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: var(--muted);
}

/* Detail Sheet */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
}

.sheet-title {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 65%;
}

.sheet-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  padding-bottom: 32px;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

.player-wrap {
  margin-bottom: 12px;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  border: 1px solid var(--border);
}

.player-wrap video {
  width: 100%;
  max-height: 52vh;
  display: block;
  background: #000;
}

.player-meta {
  padding: 8px 12px;
  font-size: 12px;
  color: var(--muted);
  background: var(--bg-elev);
}

.drama-hero {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
}

.drama-hero img {
  width: 84px;
  height: 116px;
  object-fit: cover;
  border-radius: 10px;
  flex-shrink: 0;
  background: #1d2230;
}

.episode-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.ep-btn {
  padding: 10px 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
  position: relative;
}

.ep-btn.active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
}

.ep-btn.locked {
  opacity: 0.45;
}

.ep-btn .cached-dot {
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 9px;
}

.job-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}

.progress-track {
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  margin: 8px 0;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.3s ease;
}

.social-preview {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: rgba(15, 17, 23, 0.94);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
}

.nav-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px;
  cursor: pointer;
  font-size: 18px;
}

.nav-btn small {
  font-size: 11px;
  font-weight: 600;
}

.nav-btn.active {
  color: var(--accent);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 60;
  background: rgba(24, 28, 38, 0.96);
  color: #fff;
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}

.hidden {
  display: none !important;
}
