/* ── Short Drama UI v3 — unified theme ── */
:root {
  --bg: #06060a;
  --bg-elevated: #0c0c12;
  --surface: #13131c;
  --surface2: #1a1a26;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #f4f4f8;
  --muted: #8b90a5;
  --accent: #ff2d7a;
  --accent-dim: #e01862;
  --accent-soft: rgba(255, 45, 122, 0.12);
  --success: #2dd4a0;
  --warn: #f5b942;
  --bonus: #b8a9fc;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-pill: 999px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
  --quick-nav-h: 44px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --page-pad: clamp(12px, 3vw, 20px);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: "Noto Sans Thai", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 100% 80% at 50% -30%, rgba(255, 45, 122, 0.18), transparent 55%),
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(88, 120, 255, 0.06), transparent);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: calc(12px + var(--safe-bottom));
  line-height: 1.5;
  overscroll-behavior-y: none;
  overflow-x: clip;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

body.in-watch {
  padding-bottom: 0;
  background: #000;
}
body.in-watch .hero-compact,
body.in-watch .hero-full {
  display: none !important;
}
body.in-watch .player-wrap {
  scroll-margin-top: calc(var(--topbar-h) + 8px);
}

.app-shell { min-height: 100dvh; display: flex; flex-direction: column; }

/* ── Top bar shell (layout in platform-switcher.css) ── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(6, 6, 10, 0.88);
  backdrop-filter: blur(20px) saturate(1.3);
  -webkit-backdrop-filter: blur(20px) saturate(1.3);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(255, 45, 122, 0.25), 0 4px 20px rgba(0, 0, 0, 0.35);
}
.topbar::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent) 30%, #ff6b9d 70%, transparent);
  opacity: 0.85;
  pointer-events: none;
}

/* ── Wallet chip ── */
.wallet-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 6px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}
.wallet-chip.low { border-color: rgba(245, 185, 66, 0.35); background: rgba(245, 185, 66, 0.08); }
.wallet-chip.empty { border-color: rgba(248, 113, 113, 0.35); background: rgba(248, 113, 113, 0.08); }
.wallet-chip .coin-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--warn); flex-shrink: 0; }
.wallet-chip .bonus-text { color: var(--bonus); }
.wallet-chip .vip-badge {
  font-size: 0.6rem;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 4px;
  background: linear-gradient(135deg, #f5b942, #e59a1a);
  color: #1a1200;
}

/* ── Search ── */
.search-form {
  flex: 1;
  display: flex;
  gap: 6px;
  max-width: 400px;
  margin-left: auto;
}
.search-form input {
  flex: 1;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 9px 14px;
  color: var(--text);
  font-size: 0.88rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search-form input:focus {
  outline: none;
  border-color: rgba(255, 45, 122, 0.5);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.search-form input::placeholder { color: var(--muted); }

.search-panel {
  margin-bottom: 16px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.search-panel[hidden] { display: none !important; }
.search-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.search-panel-head h2 { font-size: 0.95rem; font-weight: 700; }
.search-panel-head .meta { color: var(--muted); font-size: 0.78rem; white-space: nowrap; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-pill);
  padding: 9px 16px;
  font-weight: 600;
  font-size: 0.84rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, transform 0.12s var(--ease);
  min-height: 36px;
}
.btn:hover { background: var(--accent-dim); }
.btn:active { transform: scale(0.97); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.ghost {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
}
.btn.ghost:hover { border-color: var(--border-strong); background: var(--surface); }
.btn.sm { padding: 6px 12px; font-size: 0.78rem; min-height: 32px; }
.api-btn { flex-shrink: 0; text-decoration: none; line-height: 1; }
.api-btn svg { width: 15px; height: 15px; flex-shrink: 0; }

/* ── Main layout ── */
.page {
  flex: 1;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: var(--page-pad);
}

.view { display: none; }
.view.active {
  display: block;
  animation: viewIn 0.22s var(--ease) forwards;
}
@keyframes viewIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

/* ── Home controls (static — ไม่ลอยตาม) ── */
.home-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}

/* ── Home stats ── */
.home-top { margin-bottom: 10px; }
.home-stats {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  margin-bottom: 0;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.home-stats-main {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  font-size: 0.82rem;
}
.home-stats-count {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
}
.home-stats-label { font-weight: 600; }
.home-stats-sub {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--muted);
}
.home-stats-dot { opacity: 0.45; }
.cache-hint {
  font-size: 0.72rem;
  color: var(--muted);
  margin: -8px 0 14px;
  padding: 8px 12px;
  background: var(--accent-soft);
  border: 1px solid rgba(255, 45, 122, 0.15);
  border-radius: var(--radius-sm);
}

/* ── Quick nav ── */
.quick-nav {
  position: static;
  z-index: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: none;
  overflow: hidden;
}
.quick-nav.show { display: block; }
body.in-watch .quick-nav { display: none !important; }

.quick-nav-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  padding: 8px 12px 0;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.quick-nav-total {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  font-size: 0.78rem;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text, #e8e8f0);
}
.quick-nav-total b {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--accent, #ff1a75);
}
.quick-nav-sep {
  color: var(--muted);
  opacity: 0.55;
  font-weight: 600;
}
.quick-nav-wasabi {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  font-size: 0.78rem;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text, #e8e8f0);
}
.quick-nav-wasabi b {
  font-size: 1.05rem;
  font-weight: 800;
  color: #2dd4a8;
}


.quick-nav-track {
  max-width: none;
  margin: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  touch-action: pan-x;
}
.quick-nav-track::-webkit-scrollbar { display: none; }
.quick-nav-inner {
  display: inline-flex;
  flex-wrap: nowrap;
  gap: 6px;
  padding: 6px 12px 10px;
  min-width: min(100%, max-content);
}
.quick-chip {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--muted);
  border-radius: var(--radius-pill);
  padding: 6px 12px;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.12s, color 0.12s, background 0.12s;
  font-family: inherit;
  min-height: 32px;
  flex-shrink: 0;
}
.quick-chip:hover { border-color: var(--border-strong); color: var(--text); }
.quick-chip.active {
  border-color: rgba(255, 45, 122, 0.45);
  color: #fff;
  background: var(--accent-soft);
}

/* ── Sections ── */
.section-block {
  margin-bottom: 28px;
  scroll-margin-top: calc(var(--topbar-h) + 12px);
}
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  padding: 0 2px;
}
.section-title {
  font-size: 0.95rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-title::before {
  content: "";
  width: 3px;
  height: 16px;
  background: var(--accent);
  border-radius: 2px;
  flex-shrink: 0;
}
.section-count { font-size: 0.75rem; color: var(--muted); }

/* ── Cards ── */
.row-scroll {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 2px 2px 10px;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.row-scroll::-webkit-scrollbar { display: none; }

.card {
  flex: 0 0 132px;
  scroll-snap-align: start;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  border: 1px solid rgba(255, 45, 122, 0.12);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.12s;
}
@media (min-width: 768px) { .card { flex: 0 0 152px; } }

@media (hover: hover) {
  .card:hover {
    border-color: rgba(255, 45, 122, 0.35);
    box-shadow: var(--shadow-sm);
  }
  .card:hover .card-cover img { transform: scale(1.03); }
  .card:hover .card-play { opacity: 1; transform: scale(1); }
}

.card:active { transform: scale(0.98); transition: transform 0.1s; }

.card-cover {
  aspect-ratio: 3/4;
  background: var(--surface2);
  position: relative;
  overflow: hidden;
}
.card-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  image-rendering: auto;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  transition: transform 0.25s var(--ease);
}
.card-cover::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.65) 0%, transparent 45%);
  pointer-events: none;
}

.card-badge {
  position: absolute;
  z-index: 4;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 5px;
  pointer-events: none;
  color: #fff;
}
.card-badge-ep { left: 6px; bottom: 6px; background: rgba(0, 0, 0, 0.7); }
.card-badge-views {
  right: 6px;
  bottom: 6px;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: rgba(0, 0, 0, 0.72);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}
.card-badge-views::before {
  content: "";
  width: 10px;
  height: 10px;
  flex-shrink: 0;
  background: currentColor;
  opacity: 0.9;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1 12s4-7 11-7 11 7 11 7-4 7-11 7S1 12 1 12z'/%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1 12s4-7 11-7 11 7 11 7-4 7-11 7S1 12 1 12z'/%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3C/svg%3E") center / contain no-repeat;
}
.card-badge-hot { top: 6px; right: 6px; background: var(--accent); font-size: 0.58rem; }
.card-badge-wasabi {
  top: 6px;
  right: 6px;
  background: linear-gradient(135deg, #0d9f6e, #067a54);
  color: #e8fff6;
  font-size: 0.58rem;
  letter-spacing: 0.02em;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}
.card-badge-hot.with-wasabi { top: 28px; }
.card-badge-dub {
  top: 6px; left: 6px;
  background: rgba(45, 212, 160, 0.92);
  color: #042a1c;
  font-size: 0.58rem;
}
.card-badge-sub {
  top: 6px; left: 6px;
  background: rgba(88, 180, 255, 0.92);
  color: #031a2e;
  font-size: 0.58rem;
}
.card-play {
  position: absolute;
  bottom: 8px;
  right: 8px;
  z-index: 2;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  opacity: 0;
  transform: scale(0.85);
  transition: opacity 0.15s, transform 0.15s;
}
.card-body { padding: 8px 8px 10px; }
.card-title {
  font-size: 0.76rem;
  font-weight: 600;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-tags-row { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 4px; }
.card-tag {
  font-size: 0.62rem;
  padding: 2px 5px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: #ffb8d0;
  border: 1px solid rgba(255, 45, 122, 0.15);
}

/* ── Catalog grid (DreameBox) ── */
.catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
  gap: 10px;
  padding: 2px 2px 10px;
}
@media (min-width: 768px) {
  .catalog-grid { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 12px; }
}
.catalog-grid .card { flex: none; width: auto; }
.catalog-section .section-head {
  padding: 6px 0;
  margin-bottom: 8px;
}

/* ── Native classify panel (หมวดหมู่) ── */
.classify-panel {
  margin: 0 0 12px;
  padding: 12px;
  border: 1px solid var(--border, #2a2a3d);
  border-radius: 12px;
  background: rgba(255,255,255,.03);
}
.classify-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.classify-group { margin-bottom: 10px; }
.classify-group:last-child { margin-bottom: 0; }
.classify-group-title {
  font-size: .78rem;
  color: var(--muted, #9498ab);
  font-weight: 700;
  margin-bottom: 6px;
}
.classify-group-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.theater-feed-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

/* ── Filter chips ── */
.chip-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0 0 14px;
  padding: 10px 12px;
  position: static;
  z-index: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: none;
  overflow: visible;
}
.chip-stack::before {
  content: "กรองหมวด";
  display: block;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 2px;
}
.chip-row {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  align-items: center;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  touch-action: pan-x;
  padding-bottom: 2px;
}
.chip-row::-webkit-scrollbar { display: none; }
.filter-chip {
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  padding: 6px 11px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  white-space: nowrap;
  font-size: 0.74rem;
  line-height: 1.2;
  min-height: 32px;
  flex-shrink: 0;
  transition: border-color 0.12s, background 0.12s;
  font-family: inherit;
}
.filter-chip-more { border-style: dashed; color: var(--muted); background: transparent; }
.filter-chip:hover { border-color: var(--border-strong); }
.filter-chip.active {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}

/* ── Banner cards ── */
.banner-section .section-title::before { background: linear-gradient(180deg, #ff6b35, var(--accent)); }
.row-scroll.banner-scroll { gap: 10px; }
.card.banner-card { flex: 0 0 min(82vw, 280px); }
.card.banner-card .card-cover { aspect-ratio: 16/10; }
.card.banner-card .card-play {
  opacity: 1;
  transform: scale(1);
  width: auto;
  padding: 0 10px;
  border-radius: var(--radius-pill);
  font-size: 0.68rem;
  font-weight: 700;
  height: 26px;
}

/* ── Detail ── */
.back-row { margin-bottom: 12px; }
.detail-layout { display: grid; gap: 20px; }
@media (min-width: 1024px) {
  .detail-layout { grid-template-columns: 1fr 380px; align-items: start; }
  .player-col { position: sticky; top: calc(var(--topbar-h) + 8px); }
}

.hero-compact {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.hero-thumb {
  width: 64px;
  height: 86px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  flex-shrink: 0;
  background: var(--surface2);
}
.hero-thumb img { width: 100%; height: 100%; object-fit: cover; }
.hero-meta { min-width: 0; }
.hero-meta h1 {
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.35;
  margin-bottom: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.meta { display: flex; flex-wrap: wrap; gap: 5px; }
.tag {
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: 0.68rem;
  color: var(--muted);
}
.desc { display: none; }
.hero-full { display: none; }

@media (min-width: 768px) {
  .hero-compact { display: none; }
  .hero-full {
    display: grid;
    grid-template-columns: 160px 1fr;
    gap: 18px;
    margin-bottom: 14px;
  }
  .hero-cover {
    border-radius: var(--radius);
    overflow: hidden;
    aspect-ratio: 3/4;
    background: var(--surface2);
    box-shadow: var(--shadow-sm);
  }
  .hero-cover img { width: 100%; height: 100%; object-fit: cover; }
  .hero-info h1 { font-size: 1.2rem; margin-bottom: 8px; line-height: 1.3; }
  .desc {
    display: block;
    color: var(--muted);
    font-size: 0.84rem;
    line-height: 1.6;
    margin-top: 10px;
    max-height: 110px;
    overflow-y: auto;
  }
}

/* ── Player ── */
.player-wrap {
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}
.now-playing { display: flex; align-items: center; gap: 6px; min-width: 0; }
.now-playing-meta {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  flex: 1;
}
.now-playing-title {
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.now-playing-label {
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 7px;
  border-radius: 5px;
  flex-shrink: 0;
}
.now-playing-text {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}
body.in-watch .now-playing-title { color: #fff; }
body.in-watch .now-playing-text { color: rgba(255, 255, 255, 0.68); }
.now-playing.loading .now-playing-text { color: var(--muted); }

.player-top {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
}
body.in-watch .player-top {
  background: rgba(0, 0, 0, 0.55);
  border-bottom-color: rgba(255, 255, 255, 0.06);
  padding-top: 8px;
}
@media (max-width: 640px) {
  body.in-watch .player-top {
    padding-top: 6px;
    padding-bottom: 6px;
  }
}
.player-back {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.player-top .now-playing { flex: 1; min-width: 0; padding: 0; background: none; border: none; }

video {
  width: 100%;
  max-height: 52vh;
  display: block;
  background: #000;
  object-fit: contain;
}
@media (min-width: 1024px) { video { max-height: 46vh; } }
body.in-watch video { max-height: min(70vh, 70dvh); }

@media (min-width: 768px) {
  body.in-watch video { max-height: min(76vh, 76dvh); }
}
@media (min-width: 1024px) {
  body.in-watch video { max-height: min(82vh, 82dvh); }
  body.in-watch .player-col { position: sticky; top: calc(var(--topbar-h) + 8px); }
}

@media (max-width: 640px) {
  body.in-watch video {
    max-height: min(56vh, 56dvh);
    width: 100%;
  }
  body.in-watch .player-wrap {
    margin-top: 0;
  }
  body.in-watch .detail-layout {
    gap: 0;
  }
  body.in-watch .player-col {
    position: static;
  }
}

.video-shell { position: relative; background: #000; container-type: inline-size; }
.player-loading {
  position: absolute;
  inset: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}
.player-loading.show { opacity: 1; pointer-events: auto; }

.player-nav {
  position: absolute;
  inset: 0;
  z-index: 12;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2px;
  pointer-events: none;
}
.player-nav button {
  pointer-events: auto;
  width: 36px;
  height: 48px;
  border: none;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  font-size: 1.4rem;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
@media (hover: hover) {
  .video-shell:hover .player-nav button,
  .video-shell:focus-within .player-nav button { opacity: 0.8; }
}
@media (pointer: coarse) {
  .player-nav button { opacity: 0.65; }
}
.player-nav button:disabled { opacity: 0 !important; cursor: default; }

.subtitle-overlay {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 10;
  bottom: clamp(44px, 9%, 64px);
  padding: 0 clamp(8px, 4%, 24px);
  padding-bottom: var(--safe-bottom);
  text-align: center;
  pointer-events: none;
}
.subtitle-overlay span {
  display: inline-block;
  max-width: min(92%, 30em);
  color: #fff;
  font-size: clamp(12px, 3.2cqi, 17px);
  font-weight: 600;
  line-height: 1.3;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.95), 0 0 6px rgba(0, 0, 0, 0.8);
}
.subtitle-off .subtitle-overlay { display: none; }

.player-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
body.in-watch .player-bar { background: #0e0e14; }
.player-bar .icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.player-bar .spacer { flex: 1; }
.player-bar .ctrl-group {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px 8px;
}
.player-bar label { font-size: 0.7rem; color: var(--muted); }
.player-bar select {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 0.78rem;
  cursor: pointer;
  padding: 3px 0;
}
.auto-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: var(--radius-pill);
  padding: 4px 9px;
  font-size: 0.68rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.auto-btn.active { color: var(--accent); border-color: rgba(255, 45, 122, 0.35); }

/* ── Episodes ── */
.episodes-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.ep-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 10px 12px 8px;
  border-bottom: 1px solid var(--border);
}
.ep-toolbar h2 { font-size: 0.88rem; font-weight: 700; margin-right: auto; }
.ep-filters { display: flex; flex-wrap: wrap; gap: 5px; }
.ep-filter {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: var(--radius-pill);
  padding: 4px 10px;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 30px;
}
.ep-filter.active {
  background: var(--accent-soft);
  border-color: rgba(255, 45, 122, 0.4);
  color: var(--accent);
}
.ep-list { padding: 8px 10px 12px; }
.ep-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 6px;
}
@media (min-width: 480px) {
  .ep-grid { grid-template-columns: repeat(auto-fill, minmax(50px, 1fr)); gap: 7px; }
}
.ep-chip {
  aspect-ratio: 1;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface2);
  color: var(--text);
  font-weight: 700;
  font-size: 0.78rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 44px;
  transition: border-color 0.12s, background 0.12s;
}
.ep-chip.playing {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.ep-chip.unlocked-pay { border-color: rgba(45, 212, 160, 0.4); color: var(--success); }
.ep-chip.locked-pay { opacity: 0.45; }
.ep-chip.cached { border-color: rgba(96, 165, 250, 0.45); }
.ep-chip .lock-dot {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--warn);
}
.ep-chip .unlock-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  font-size: 0.5rem;
  font-weight: 800;
  color: var(--success);
}
.ep-chip .cache-badge {
  position: absolute;
  bottom: 2px;
  left: 2px;
  font-size: 0.4rem;
  font-weight: 800;
  padding: 1px 3px;
  border-radius: 3px;
  background: rgba(96, 165, 250, 0.25);
  color: #bfdbfe;
}
.ep-chip .cache-badge.is-wasabi,
.ep-chip .cache-badge-wasabi {
  background: rgba(96, 165, 250, 0.22);
  color: #93c5fd;
}
.ep-chip.playing .cache-badge.is-wasabi,
.ep-chip.playing .cache-badge-wasabi {
  color: #dbeafe;
  background: rgba(96, 165, 250, 0.32);
}

.ep-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 0 10px 8px;
  font-size: 0.66rem;
  color: var(--muted);
}
.ep-legend i { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }

.next-hint {
  position: absolute;
  bottom: 16%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 14;
  background: rgba(0, 0, 0, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 7px 14px;
  border-radius: var(--radius-pill);
  font-size: 0.74rem;
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  white-space: nowrap;
}
.next-hint.show { opacity: 1; }

.prefetch-hint {
  display: none;
  align-items: center;
  gap: 8px;
  margin: 0 10px 8px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  background: rgba(96, 165, 250, 0.08);
  border: 1px solid rgba(96, 165, 250, 0.2);
  font-size: 0.68rem;
  color: #93c5fd;
}
.prefetch-hint.show { display: flex; }
.prefetch-hint .prefetch-bar {
  flex: 1;
  height: 3px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
}
.prefetch-hint .prefetch-bar i {
  display: block;
  height: 100%;
  width: 0%;
  background: #60a5fa;
  transition: width 0.3s ease;
}

/* ── Prefetch panel (compact) ── */
.prefetch-all-panel {
  margin-bottom: 0;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.prefetch-all-panel.running {
  border-color: rgba(96, 165, 250, 0.35);
  background: rgba(96, 165, 250, 0.05);
}
.prefetch-all-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
}
.prefetch-all-status {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 0.72rem;
  line-height: 1.3;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.prefetch-all-panel.running .prefetch-all-status { color: #93c5fd; }
.prefetch-all-panel .prefetch-all-bar {
  margin-top: 6px;
  width: 100%;
  height: 2px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 2px;
  overflow: hidden;
}
.prefetch-all-panel .prefetch-all-bar i {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #60a5fa, #3b82f6);
  transition: width 0.3s ease;
}
.btn-cache-all {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  font-size: 0.74rem;
  font-weight: 600;
  color: #fff;
  background: #3b82f6;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  font-family: inherit;
  transition: opacity 0.12s, transform 0.12s var(--ease);
}
  min-height: 34px;
}
.btn-cache-all:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-cache-all.stop {
  background: rgba(239, 68, 68, 0.12);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.3);
}
.repair-cache-btn {
  flex-shrink: 0;
  margin-left: auto;
  padding: 4px 9px;
  border-radius: var(--radius-pill);
  border: 1px solid rgba(96, 165, 250, 0.35);
  background: rgba(96, 165, 250, 0.1);
  color: #93c5fd;
  font-size: 0.64rem;
  cursor: pointer;
  min-height: 28px;
}

/* ── States ── */
.loading, .error-box, .empty {
  text-align: center;
  padding: 48px 16px;
  color: var(--muted);
  font-size: 0.88rem;
}
.error-box { color: #f87171; }
.spinner {
  width: 32px;
  height: 32px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: calc(12px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(6px);
  background: var(--surface2);
  border: 1px solid var(--border-strong);
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  font-size: 0.82rem;
  z-index: 200;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s var(--ease);
  pointer-events: none;
  box-shadow: var(--shadow);
  max-width: min(90vw, 360px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Watch mode (page/player) ── */
@media (max-width: 640px) {
  .search-form input { font-size: 16px; }
  .home-controls { gap: 8px; margin-bottom: 12px; }
  .home-stats { padding: 10px 12px; gap: 6px 10px; }
  .home-stats-count { font-size: 1.2rem; }
  .prefetch-all-row { gap: 6px; }
  .prefetch-all-status { font-size: 0.68rem; }
  .btn-cache-all { padding: 6px 9px; font-size: 0.7rem; }
  body.in-watch .page { padding: 0; }
  body.in-watch .back-row { display: none; }
  body.in-watch .hero-compact { display: none; }
  body.in-watch .player-wrap { border-radius: 0; border: none; }
  body.in-watch .episodes-panel { border: none; border-radius: 0; background: #0a0a0f; }
}

@media (min-width: 1024px) {
  .ep-list {
    max-height: calc(100dvh - var(--topbar-h) - 40px);
    overflow-y: auto;
    scrollbar-width: thin;
  }
  .ep-list::-webkit-scrollbar { width: 5px; }
  .ep-list::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
}

/* ── Performance & a11y ── */
img { max-width: 100%; height: auto; }
button, input, select, textarea { font: inherit; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Catalog browse — ported from DramaWave / FlickReels */
.catalog-browse {
  margin: 0 0 24px;
}
.catalog-browse-head {
  margin: 0 0 14px;
  padding: 14px 16px;
  border-radius: 16px;
  background:
    radial-gradient(120% 140% at 0% 0%, rgba(255, 45, 122, 0.16), transparent 55%),
    linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.01));
  border: 1px solid var(--border);
}
.catalog-browse-title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}
.catalog-browse-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
}
.catalog-browse-sort {
  font-size: 0.72rem;
  font-weight: 700;
  color: #ffb8d0;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 45, 122, 0.12);
  border: 1px solid rgba(255, 45, 122, 0.22);
  white-space: nowrap;
}
.catalog-browse-meta {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.45;
}
.catalog-browse-meta b {
  color: var(--text);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.catalog-browse-dot { margin: 0 0.35em; opacity: 0.55; }
.catalog-scroll-sentinel {
  height: 1px;
  margin: 8px 0 40px;
}
.catalog-scroll-status {
  text-align: center;
  padding: 12px 8px 28px;
  color: var(--muted);
  font-size: 0.78rem;
}
.catalog-scroll-hint.error { color: #ff8fa8; }
.loading.compact {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--muted);
}
.loading.compact .spinner {
  width: 16px;
  height: 16px;
  border-width: 2px;
}

.card-coming-soon { opacity: 0.92; }
.card-badge-soon {
  position: absolute; top: 8px; left: 8px; z-index: 3;
  background: rgba(20, 20, 28, 0.82); color: #ffd9a8;
  font-size: 0.66rem; font-weight: 800; letter-spacing: 0.02em;
  padding: 3px 7px; border-radius: 999px; border: 1px solid rgba(255,200,120,0.35);
}
