/* ── CJK typography ── */
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* System CJK font stack — optimised for Simplified Chinese / Hui audience */
body,
button,
input,
.clarity-card__title,
.clarity-card__intro,
.clarity-section__heading,
.clarity-section__body,
.clarity-hook__text,
.clarity-vid-thumb__label,
.clarity-readmore-btn,
.kp-nav-label,
.kp-sound-hint,
.reel-empty {
  font-family:
    "PingFang SC",          /* macOS / iOS */
    "Hiragino Sans GB",     /* older macOS */
    "Microsoft YaHei UI",   /* Windows 8+ */
    "Microsoft YaHei",      /* Windows */
    "Noto Sans SC",         /* Android / Linux */
    "WenQuanYi Micro Hei",  /* Linux */
    sans-serif;
}

/* Chinese body copy needs taller line-height and slight tracking */
.clarity-section__body,
.clarity-card__intro {
  line-height: 1.75;
  letter-spacing: 0.02em;
  word-break: break-all;          /* no word boundaries in CJK */
}

.clarity-hook__text {
  line-height: 1.6;
  word-break: break-all;
}

.clarity-card__title,
.clarity-section__heading {
  word-break: break-all;
}

/* ── navigation ── */
.kp-bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: 58px;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  /* Solid fallback for WeChat X5 which doesn't support backdrop-filter */
  background: rgba(0,0,0,0.88);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 12;
  border-top: 1px solid rgba(255,255,255,0.12);
}
.kp-nav-item { color: #fff; text-decoration: none; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; opacity: 0.9; }
.kp-nav-item.is-active { opacity: 1; }
.kp-nav-icon { font-size: 20px; line-height: 1; display: inline-flex; align-items: center; justify-content: center; }
.kp-nav-icon svg { width: 22px; height: 22px; fill: #fff; }
.kp-nav-label { font-size: 11px; }

/* Vertical kuaipai layout */
/* --kp-vh is set to window.innerHeight * 0.01 by JS, fixing WeChat X5's broken 100vh */
.kuaipai-body { background: #111; color: #fff; --kp-nav-h: 0px; }
.kuaipai-container {
  height: calc(var(--kp-vh, 1vh) * 100);
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
  overflow-y: auto;
  -webkit-scroll-snap-type: y mandatory;
  scroll-snap-type: y mandatory;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y; /* eliminates 300ms tap delay without blocking vertical scroll */
}
/* Desktop: keep nav full-width, space items across the same 480px column as the feed */
.kp-nav-item { width: 240px; justify-content: center; }
.kuaipai-reel {
  position: relative;
  height: calc(var(--kp-vh, 1vh) * 100 - var(--kp-nav-h));
  -webkit-scroll-snap-align: start;
  scroll-snap-align: start;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

/* Non-video clarity section — defined in full at bottom of file */
.kuaipai-video {
  width: 99%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

/* Cloudflare Stream iframe wrapper ensures full-size fit */
.kp-player-frame {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}
.kp-player-frame iframe.kuaipai-video {
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
}
.kuaipai-overlay {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 35%;
  pointer-events: none; /* don’t block video taps */
  background: linear-gradient(to top, rgba(0,0,0,0.6), rgba(0,0,0,0));
  z-index: 2;
}
.kuaipai-controls {
  position: absolute;
  right: 16px;
  bottom: 140px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: rgba(80,80,80,0.7);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  padding: 8px 10px;
  border-radius: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  z-index: 3;
}
.kuaipai-btn { background: rgba(255,255,255,0.15); color: #fff; border: none; border-radius: 20px; padding: 8px 12px; cursor: pointer; }
.kuaipai-btn:active { transform: scale(0.98); }
.like-toggle.liked { background: rgba(255,0,80,0.5); }
.mute-toggle { transition: background 0.2s, opacity 0.2s; }
.mute-toggle.is-muted { opacity: 0.6; background: rgba(255,255,255,0.08); }

.reel-empty { opacity: 0.8; font-size: 18px; }

/* Hide native controls to enforce kuaipai-style */
.kuaipai-video::-webkit-media-controls { display: none !important; }

.kp-indicator {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 64px;
  line-height: 1;
  color: rgba(255,255,255,0.96);
  text-shadow: 0 4px 20px rgba(0,0,0,0.55);
  opacity: 0;
  transform: scale(0.9);
  pointer-events: none;
  z-index: 4;
  transition: opacity 120ms ease, transform 120ms ease;
}
.kp-indicator.show { opacity: 1; transform: scale(1); }
.kp-indicator.is-paused-icon { opacity: 0.75; transform: scale(1); }

.kp-progress {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 68px;
  z-index: 5;
  padding: 6px 0; /* thumb overflow space */
}
.kp-progress__track {
  position: relative;
  height: 6px;
  background: rgba(255,255,255,0.25);
  border-radius: 999px;
  overflow: hidden;
}
.kp-progress__fill {
  position: absolute;
  top: 0; left: 0; bottom: 0;
  width: 0%;
  background: linear-gradient(90deg, rgba(255,255,255,0.9), rgba(255,255,255,0.7));
}
.kp-progress__thumb {
  position: absolute;
  top: 50%;
  left: 0%;
  transform: translate(-50%, -50%);
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
}
.kp-progress, .kp-progress * { cursor: pointer; }

.kp-sound-hint {
  position: absolute;
  left: 50%;
  /* bottom: 122px; sit above progress bar + hint */
  transform: translateX(-50%);
  background: rgba(0,0,0,0.65);
  color: #fff;
  padding: 12px 22px;
  border-radius: 24px;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  z-index: 6;
  cursor: pointer;
  pointer-events: auto;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.45);
  animation: kp-pulse 1.8s ease-in-out infinite;
  user-select: none;
  -webkit-user-select: none;
}
@keyframes kp-pulse {
  0%, 100% { opacity: 0.8; }
  50% { opacity: 1; }
}

.kp-next-arrow {
  position: absolute;
  bottom: 110px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 36px;
  line-height: 1;
  color: rgba(255,255,255,0.85);
  text-shadow: 0 2px 8px rgba(0,0,0,0.6);
  pointer-events: auto;
  cursor: pointer;
  touch-action: manipulation; /* removes 300ms tap delay in WeChat/mobile */
  z-index: 6;
  animation: kp-bounce 1.4s ease-in-out infinite;
}
/* When the clarity body panel is open, anchor arrow to the very bottom */
.clarity-card.is-expanded ~ .kp-next-arrow {
  bottom: 12px;
  color: rgba(255,255,255,0.6);
}
@keyframes kp-bounce {
  0%, 100% { transform: translateX(-50%) translateY(0);    opacity: 0.7; }
  50%       { transform: translateX(-50%) translateY(8px); opacity: 1;   }
}
.hint-hidden .kp-next-arrow { display: none; }

.kuaipai-hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  transform: translateY(12px);
  z-index: 3;
  width: 100%;
  height: 58px;
  pointer-events: none;
  border-radius: 12px 12px 0 0;
  overflow: hidden;
  box-shadow: 0 -4px 18px rgba(0,0,0,0.55);
  animation: kp-peek 2s ease-in-out infinite;
}
.kuaipai-hint::before { content: none; }
.kuaipai-hint img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  display: block;
}
@keyframes kp-peek {
  0%, 100% { transform: translateY(12px); opacity: 0.7; }
  50%       { transform: translateY(0);   opacity: 1;   }
}

/* Hide hint after first interaction */
.hint-hidden .kuaipai-hint { display: none; }
.hint-hidden .kp-sound-hint { display: none; }

/* Responsive improvements for tablets/desktops */
@media (min-width: 768px) {
  .kuaipai-reel { padding-left: 0; padding-right: 0; }
  .kuaipai-hint {
    left: 50%;
    right: auto;
    width: calc((100vh - var(--kp-nav-h)) * 9 / 16);
    animation: kp-peek-desktop 2s ease-in-out infinite;
  }
  @keyframes kp-peek-desktop {
    0%, 100% { transform: translateX(-50%) translateY(12px); opacity: 0.7; }
    50%       { transform: translateX(-50%) translateY(0);   opacity: 1;   }
  }
  /* For native video tag */
  .kuaipai-video {
    width: auto;              /* prevent stretching full width */
    height: 100%;             /* fill vertical space */
    max-height: 100%;
    aspect-ratio: 9 / 16;     /* keep vertical video shape */
    object-fit: cover;
    border-radius: 12px;
    box-shadow: 0 12px 36px rgba(0,0,0,0.5);
  }
  /* For Cloudflare iframe, constrain using wrapper while filling height */
  .kp-player-frame {
    height: 100%;
  }
  .kp-player-frame iframe.kuaipai-video {
    width: auto;
    height: 100%;
    aspect-ratio: 9 / 16;
    border-radius: 12px;
    box-shadow: 0 12px 36px rgba(0,0,0,0.5);
  }
  /* Center the progress bar under the video on larger screens */
  .kp-progress {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: min(56vh, 560px);
  }
}

@media (min-width: 1200px) {
  .kuaipai-video {
    width: auto;
    height: 92%;               /* add a little breathing room */
    border-radius: 14px;
  }
  .kp-player-frame iframe.kuaipai-video {
    height: 92%;
    border-radius: 14px;
  }
  .kp-progress { width: min(52vh, 600px); }
  .kuaipai-hint { width: calc((100vh - var(--kp-nav-h)) * 0.92 * 9 / 16); }
}

/* Non-video clarity section — full snap viewport, inner content scrolls */
.clarity-section-wrap {
  position: relative;
  height: calc(var(--kp-vh, 1vh) * 100 - var(--kp-nav-h));
  -webkit-scroll-snap-align: start;
  scroll-snap-align: start;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  background: #000;
  overflow: hidden;
}

/* Clarity card: relative container for absolutely-positioned children */
.clarity-card {
  position: relative;
  height: 100%;
  overflow: hidden;
}

/* Top: video / poster fills full height by default; shrinks when body is open */
.clarity-card__video-wrap {
  position: absolute;
  inset: 0;
  background: #000;
  overflow: hidden;
  transition: height 0.38s cubic-bezier(0.4, 0, 0.2, 1);
  height: 100%;
}
.clarity-hv {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #000;
}
.clarity-hv--placeholder {
  background: linear-gradient(180deg, #333, #111);
}

/* Hook — entire box is the tap target */
.clarity-hook {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 75%;
  text-align: center;
  background: rgba(0, 0, 0, 0.62);
  border: 2px solid rgba(255, 255, 255, 0.82);
  border-radius: 10px;
  padding: 20px 20px;
  color: #fff;
  pointer-events: auto;
  cursor: pointer;
  user-select: none;
}
.clarity-hook::after {
  content: '点击展开';
  display: block;
  margin-top: 10px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: rgba(255,255,255,0.75);
  animation: kp-hook-hint 1.6s ease-in-out infinite;
}
@keyframes kp-hook-hint {
  0%, 100% { opacity: 0.45; transform: translateY(0); }
  50%       { opacity: 1;    transform: translateY(4px); }
}
.clarity-hook a,
.clarity-hook__cta { pointer-events: auto; }
.clarity-hook__text {
  margin: 0 0 8px;
  font-size: 28px;
  line-height: 1.45;
}
.clarity-hook__cta {
  display: inline-block;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* Scrollable body — hidden below the fold until is-expanded */
.clarity-card__body {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 62%;
  transform: translateY(100%);
  transition: transform 0.38s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 14px calc(10px + env(safe-area-inset-bottom));
  background: #111;
  color: #fff;
  z-index: 5;
}

/* Expanded state: shrink video to top 38%, slide body up */
.clarity-card.is-expanded .clarity-card__video-wrap { height: 38%; }
.clarity-card.is-expanded .clarity-card__body { transform: translateY(0); }
.clarity-card.is-expanded .clarity-hv { object-fit: contain; }

/* Progress bar sits just below the video area, outside the video-wrap */
.clarity-progress {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: calc(64% + 10px);
  top: auto;
  display: none;
  z-index: 6;
}
.clarity-card.is-expanded .clarity-progress { display: block; }
.clarity-card__title { margin: 0 0 6px; font-size: 18px; line-height: 1.3; }
.clarity-card__intro { margin: 0 0 10px; font-size: 14px; opacity: 0.85; }
.clarity-section__heading { margin: 12px 0 6px; font-size: 16px; font-weight: 700; opacity: 0.9; }
.clarity-section__body { margin: 0 0 10px; font-size: 15px; line-height: 1.55; opacity: 0.95; }

/* 2-column related-video grid */
.clarity-vid-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 10px 0 4px;
}
.clarity-vid-thumb {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: #fff;
  border-radius: 8px;
  overflow: hidden;
  background: #1c1c1c;
}
.clarity-vid-thumb img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  display: block;
}
.clarity-vid-thumb__label {
  font-size: 12px;
  line-height: 1.3;
  padding: 5px 6px 7px;
  opacity: 0.9;
}

/* Read More / Show Less toggle */
.clarity-readmore-btn {
  display: block;
  width: 100%;
  margin: 8px 0 12px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}
.clarity-readmore-btn:active { opacity: 0.7; }

/* Fade edge — sits between the visible grid and the button */
.clarity-fade-edge {
  height: 48px;
  margin-top: -48px;
  background: linear-gradient(to bottom, transparent, #111);
  pointer-events: none;
  position: relative;
  z-index: 1;
}

.clarity-outlink { display: inline-flex; margin-top: 8px; }

/* Clarity video controls — bottom-right of the video wrap, above the hook */
.clarity-controls {
  position: absolute;
  left: 16px;
  right: auto;
  bottom: 16px;
  z-index: 4;
}

/* After hook is dismissed: center controls vertically in the video area */
.clarity-card.is-expanded .clarity-controls {
  top: 50%;
  bottom: auto;
  left: 8px;
  right: auto;
  transform: translateY(-50%);
}

/* Hide sound hint when body panel is open */
.clarity-card.is-expanded .kp-sound-hint {
  display: none;
}

/* Expand button — anchored to bottom-right of the video wrap */
.expand-toggle { line-height: 0; padding: 8px 10px; }
.expand-toggle svg { width: 18px; height: 18px; fill: #fff; display: block; }
.clarity-expand-btn {
  position: absolute;
  right: 5px;
  bottom: 40px;
  z-index: 4;
  background: rgba(0,0,0,0.55);
  border-radius: 8px;
  padding: 7px 9px;
}

/* CSS fake-fullscreen — rotates video-wrap 90deg to simulate landscape */
.kp-clarity-fs-active .clarity-card__video-wrap {
  position: fixed !important;
  inset: auto !important;
  top: 50% !important;
  left: 50% !important;
  /* swap portrait dimensions: width=vh, height=vw fills the screen when rotated */
  width: calc(var(--kp-vh, 1vh) * 100) !important;
  height: 100vw !important;
  transform: translate(-50%, -50%) rotate(90deg) !important;
  z-index: 200 !important;
  background: #000 !important;
}
.kp-clarity-fs-active .clarity-hv {
  object-fit: contain !important;
}
/* Hide body panel and the (now-rotated) in-wrap expand button */
.kp-clarity-fs-active .clarity-card__body,
.kp-clarity-fs-active .clarity-expand-btn {
  display: none !important;
}
/* Fixed exit button rendered in normal portrait screen coordinates */
.kp-fs-exit-btn {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 201;
  background: rgba(0,0,0,0.65);
  border: none;
  border-radius: 8px;
  padding: 8px 10px;
  line-height: 0;
  cursor: pointer;
}
.kp-fs-exit-btn svg { width: 18px; height: 18px; fill: #fff; display: block; }
