/* ===== Reset & base ===== */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overscroll-behavior: none; }

:root {
  --bg: #0f0f10;
  --card-bg: #1a1a1c;
  --text: #f5f5f5;
  --text-dim: #a0a0a5;
  --accent: #ff4d6d;
  --accent-2: #7c5cff;
  --tag-bg: rgba(255,255,255,0.08);

  --banner-h: 50px; /* chuẩn banner ad mobile (320x50) */

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f2f2f5;
    --card-bg: #ffffff;
    --text: #1a1a1a;
    --text-dim: #666666;
    --tag-bg: rgba(0,0,0,0.05);
  }
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; }

/* ===================================================================
   BANNER ADS — thanh cố định trên/dưới, KHÔNG đè lên video (khác bản
   trước: quảng cáo nằm trong khu vực riêng, video hoàn toàn sạch).
   Nền đặc (không blur) — đây là vùng quảng cáo, không phải overlay.
   =================================================================== */
.banner-ad {
  position: fixed;
  left: 0; right: 0;
  z-index: 40;
  height: var(--banner-h);
  background: var(--card-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.banner-ad-top { top: 0; padding-top: var(--safe-t); height: calc(var(--banner-h) + var(--safe-t)); border-bottom: 1px solid rgba(255,255,255,0.08); }
.banner-ad-bottom { bottom: 0; padding-bottom: var(--safe-b); height: calc(var(--banner-h) + var(--safe-b)); border-top: 1px solid rgba(255,255,255,0.08); }
.banner-ad .ad-placeholder-inline {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
  border: 1px dashed rgba(255,255,255,0.18);
  border-radius: 8px;
  padding: 6px 14px;
}

/* ===================================================================
   FEED CHÍNH — vuốt DỌC (quen thuộc kiểu TikTok/Reels/Shorts), nằm giữa
   2 banner trên/dưới, video chiếm trọn phần còn lại, không bị che.
   =================================================================== */

.feed-container {
  position: fixed;
  top: calc(var(--banner-h) + var(--safe-t));
  bottom: calc(var(--banner-h) + var(--safe-b));
  left: 0; right: 0;
  display: flex;
  flex-direction: column;
  overflow-y: scroll;
  overflow-x: hidden;
  scroll-snap-type: y mandatory;
  scroll-behavior: smooth;
  background: #000;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  touch-action: pan-y;
}
.feed-container::-webkit-scrollbar { display: none; }

.video-slide, .ad-slide {
  position: relative;
  flex: 0 0 100%;
  width: 100%;
  height: 100%;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  background: #000;
  /* siêu tối ưu mobile: 419+ slide nhưng chỉ slide đang hiện mới được
     browser layout/paint đầy đủ — slide ngoài khung nhìn gần như miễn phí */
  content-visibility: auto;
  contain-intrinsic-size: 100% 640px;
}

.feed-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  cursor: pointer;
}

/* ----- Thanh mỏng phía trên video: logo/counter/stories, KHÔNG blur,
   KHÔNG nền — chỉ chữ có đổ bóng nhẹ, gần như không che gì cả.
   1 bản DUY NHẤT dùng chung toàn feed (fixed, không lặp lại trong từng
   slide) — đỡ DOM, đỡ lag. ----- */
.feed-topnav {
  position: fixed;
  top: calc(var(--banner-h) + var(--safe-t) + 10px);
  left: 14px;
  right: 14px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
}
.feed-topnav > * { pointer-events: auto; text-shadow: 0 1px 5px rgba(0,0,0,0.55); }
.feed-logo {
  font-weight: 800;
  font-size: 14px;
  color: #fff;
}
.feed-counter {
  font-size: 11px;
  color: rgba(255,255,255,0.85);
  font-variant-numeric: tabular-nums;
}
.feed-stories-link {
  font-size: 12px;
  font-weight: 600;
  color: #fff;
}

/* ----- Caption: gọn, tối đa 2 dòng, nền gradient nhẹ (rẻ hơn blur) ----- */
.feed-caption {
  position: absolute;
  left: 14px;
  right: 72px;
  bottom: 14px;
  padding: 0;
  pointer-events: none;
}
.feed-caption > * { pointer-events: auto; }
.feed-channel {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  background: rgba(255,255,255,0.18);
  padding: 3px 10px;
  border-radius: 20px;
  margin-bottom: 6px;
}
.feed-title {
  color: #fff;
  font-size: 14.5px;
  font-weight: 600;
  margin-bottom: 4px;
  text-shadow: 0 1px 6px rgba(0,0,0,0.6);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.feed-more {
  display: none; /* gọn theo yêu cầu bớt che video — vẫn bấm được caption để mở story qua feed-channel */
}

/* ----- Nút tròn: nền đặc mờ nhẹ, KHÔNG blur — rẻ, đủ rõ -----
   share-btn: mỗi slide 1 nút riêng (URL khác nhau theo từng video)
   mute-btn: 1 bản DUY NHẤT dùng chung toàn feed (trạng thái mute là global) */
.mute-btn, .share-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.16);
  color: #fff;
  font-size: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.mute-btn:active, .share-btn:active { transform: scale(0.85); background: rgba(255,255,255,0.28); }
.share-btn {
  position: absolute;
  right: 14px;
  bottom: 14px;
}
.mute-btn {
  position: fixed;
  right: 14px;
  bottom: calc(var(--banner-h) + var(--safe-b) + 66px);
  z-index: 10;
}

/* ===================================================================
   Ad slide (interstitial) — chen giữa feed mỗi AD_INTERVAL video
   =================================================================== */
.ad-slide {
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 30% 20%, rgba(124,92,255,0.25), transparent 55%),
    radial-gradient(circle at 75% 80%, rgba(255,77,109,0.22), transparent 55%),
    var(--bg);
}
.ad-slide .ad-placeholder {
  text-align: center;
  padding: 40px 32px;
  border-radius: 20px;
  max-width: 320px;
  background: var(--card-bg);
  border: 1px solid rgba(255,255,255,0.08);
}
.ad-label {
  display: block;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.6);
  margin-bottom: 14px;
}
.ad-box {
  color: rgba(255,255,255,0.75);
  font-size: 13px;
}

/* ===== Ad slot trên trang Story (display ad thường) ===== */
.ad-slot { max-width: 700px; margin: 20px auto; padding: 0 20px; }
.ad-slot .ad-placeholder { padding: 40px; border-radius: 20px; background: var(--card-bg); border: 1px solid rgba(255,255,255,0.08); }
.ad-slot .ad-box { max-width: none; margin: 0 auto; }

/* ===================================================================
   Stories index (/stories) — nền gradient mềm + thẻ đơn giản (không blur)
   =================================================================== */
body:has(.site-header) {
  background:
    radial-gradient(circle at 15% 0%, rgba(124,92,255,0.16), transparent 45%),
    radial-gradient(circle at 85% 25%, rgba(255,77,109,0.14), transparent 45%),
    var(--bg);
  min-height: 100%;
}
.site-header { text-align: center; padding: calc(48px + var(--safe-t)) 20px 32px; }
.site-header .back-link { display: block; margin-bottom: 12px; color: var(--text-dim); font-size: 14px; }
.site-header h1 {
  font-size: 32px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.site-header p { color: var(--text-dim); margin-top: 8px; font-size: 15px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 20px 60px;
}
.card {
  border-radius: 16px;
  overflow: hidden;
  background: var(--card-bg);
  border: 1px solid rgba(255,255,255,0.06);
  transition: transform 0.2s ease;
  display: block;
}
.card:hover { transform: translateY(-4px); }
.card-thumb {
  aspect-ratio: 9/16;
  max-height: 320px;
  background-size: cover;
  background-position: center;
  background-color: #333;
  position: relative;
}
.card-count {
  position: absolute; bottom: 10px; right: 10px;
  background: rgba(0,0,0,0.6);
  color: #fff; font-size: 12px;
  padding: 4px 10px; border-radius: 20px;
}
.card-body { padding: 16px; }
.card-body h2 { font-size: 17px; margin-bottom: 6px; }
.card-body p {
  font-size: 13px; color: var(--text-dim);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-tags { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.card-tags span, .post-tags span {
  font-size: 11px; background: var(--tag-bg); padding: 3px 8px; border-radius: 12px; color: var(--text-dim);
}

/* ===================================================================
   Story page (/story/<slug>)
   =================================================================== */
.post-header { max-width: 700px; margin: 0 auto; padding: calc(32px + var(--safe-t)) 20px 0; }
.back-link { display: inline-block; margin-bottom: 16px; color: var(--text-dim); font-size: 14px; }
.post-header h1 { font-size: 26px; font-weight: 800; }
.post-meta { color: var(--text-dim); font-size: 13px; margin-top: 6px; }

.post-body { max-width: 700px; margin: 20px auto 0; padding: 0 20px 20px; }
.post-body p { font-size: 15px; color: var(--text-dim); }
.post-tags { margin-top: 14px; display: flex; gap: 6px; flex-wrap: wrap; }

.story-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
  max-width: 900px;
  margin: 28px auto 0;
  padding: 0 20px calc(40px + var(--safe-b));
}
.story-thumb {
  position: relative;
  aspect-ratio: 9/16;
  background-size: cover;
  background-position: center;
  background-color: #333;
  border-radius: 12px;
  overflow: hidden;
  display: block;
}
.story-thumb::after {
  content: "▶";
  position: absolute;
  top: 8px; left: 8px;
  color: #fff;
  font-size: 10px;
  background: rgba(0,0,0,0.55);
  width: 20px; height: 20px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.story-thumb-title {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 6px;
  font-size: 10.5px;
  color: #fff;
  background: linear-gradient(transparent, rgba(0,0,0,0.85));
  line-height: 1.3;
}

/* ===== Responsive / mobile ===== */
@media (max-width: 480px) {
  .grid { grid-template-columns: 1fr 1fr; gap: 12px; padding: 0 12px 40px; }
  .card-body h2 { font-size: 14px; }
  .card-body p { display: none; }
  .site-header h1 { font-size: 26px; }
}

/* Giảm hiệu ứng cho người dùng bật "reduce motion" */
@media (prefers-reduced-motion: reduce) {
  .feed-container { scroll-behavior: auto; }
  .mute-btn, .share-btn, .card { transition: none; }
}
