/* ==========================================================================
   HGhub · 短剧  样式
   结构：设计变量 -> 基础 -> 顶栏 -> 底部导航 -> 通用组件 -> 竖屏 feed
         -> 列表/卡片 -> 详情弹窗 -> 播放器 -> 评论/分享面板 -> 工具类
   ========================================================================== */

/* ---------------------------- 设计变量 ---------------------------- */
:root {
  --bg: #0e0e11;
  --card: #1a1a1f;
  --card2: #22222a;
  --text: #f5f5f5;
  --muted: #9a9aa3;
  --line: #2a2a32;
  --accent: #ff2d55;
  --accent2: #ff6b81;
  --gold: #ffcf3d;
  --topbar-h: 58px;
  --bottomnav-h: 64px;
  --page-shift: 14px;
  --radius: 12px;
}

/* ---------------------------- 基础 ---------------------------- */
* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body.modal-open { overflow: hidden; }
body.modal-open header { display: none; }

[hidden] { display: none !important; }
section[hidden] { display: none; }

button { font-family: inherit; touch-action: manipulation; }

:focus-visible {
  outline: 2px solid var(--accent2);
  outline-offset: 2px;
}

/* ---------------------------- 顶栏 ---------------------------- */
header.topbar {
  position: fixed;
  top: var(--page-shift);
  left: 0;
  right: 0;
  height: var(--topbar-h);
  z-index: 90;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.logo {
  font-size: 21px;
  font-weight: 900;
  letter-spacing: .5px;
  color: #fff;
  white-space: nowrap;
  cursor: pointer;
  background: none;
  border: 0;
  padding: 0;
}
.logo b { color: var(--accent); }

.search { flex: 1; display: flex; gap: 6px; min-width: 0; }
.search input {
  flex: 1;
  min-width: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  padding: 8px 14px;
  font-size: 14px;
  outline: none;
  -webkit-appearance: none;
}
.search input:focus { border-color: #44444f; }
.search button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
}
.search button svg { width: 14px; height: 14px; }

/* ---------------------------- 底部导航 ---------------------------- */
.bottomnav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 90;
  display: flex;
  background: rgba(14, 14, 17, .97);
  border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.bottomnav button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 0;
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}
.bottomnav button.on { color: var(--accent); font-weight: 700; }
.bottomnav .ic { font-size: 18px; line-height: 1; display: block; }
.bottomnav .ic svg { width: 18px; height: 18px; display: block; }

/* 行内小图标：任何地方漏写尺寸也不会被撑成 300×150 */
.ic-svg { display: block; width: 14px; height: 14px; vertical-align: -2px; }

/* ---------------------------- 通用组件 ---------------------------- */
main {
  padding: calc(var(--topbar-h) + var(--page-shift)) 0 calc(var(--bottomnav-h) + 10px);
  max-width: 1100px;
  margin: 0 auto;
}

#view-cat, #view-rank, #view-me, #view-search { padding: 0 12px; }

.hint { color: var(--muted); font-size: 13px; margin: 8px 2px; }
.empty { color: var(--muted); text-align: center; padding: 36px 12px; font-size: 14px; line-height: 1.7; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: linear-gradient(135deg, var(--accent), #ff7a59);
  color: #fff;
  border: 0;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  cursor: pointer;
}
.btn.ghost { background: var(--card2); border: 1px solid var(--line); color: #ddd; }
.btn.ghost.faved, .btn.faved { color: var(--gold); border-color: rgba(255, 207, 61, .45); }
.btn.watchall { background: linear-gradient(135deg, var(--gold), #ffb800); color: #221a00; font-weight: 800; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn svg.ic-svg { width: 14px; height: 14px; }

.rowbtns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.chip {
  background: var(--card);
  border: 1px solid var(--line);
  color: #ddd;
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 13px;
  cursor: pointer;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.sec-title { font-size: 16px; margin: 6px 0; }

/* ---------------------------- 竖屏 feed ---------------------------- */
#view-home {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--topbar-h) - var(--page-shift) - var(--bottomnav-h));
  height: calc(100dvh - var(--topbar-h) - var(--page-shift) - var(--bottomnav-h));
}

.feed {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  scroll-snap-type: y mandatory;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: transparent;
}

.slide {
  position: relative;
  height: 100%;
  overflow: hidden;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  background: linear-gradient(160deg, #2b2b35, #141419 60%, #20202a);
  cursor: pointer;
  opacity: .72;
  transition: opacity .2s ease;
}
.slide.active { opacity: 1; }

.slide img.cover {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #1c1c22;
  z-index: 0;
}
.slide video.bgvid {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: transparent;
  z-index: 1;
  border: 0;
}
/* 渐变压暗层：让白字在亮画面上也读得清 */
.slide .shade {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(0, 0, 0, .18) 0%, transparent 38%, transparent 52%, rgba(0, 0, 0, .88) 100%);
}

/* 底部信息 + 右侧操作栏：同一行 flex 底对齐，不再用 JS 量 rect 对齐 */
.slide .sfooter {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 16px 10px 16px 14px;
}
.slide .info { flex: 1; min-width: 0; }
.slide .info h3 { font-size: 19px; line-height: 1.35; margin-bottom: 6px; }
.slide .info .titlebtn {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  padding: 0;
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.slide .info p.syn {
  color: #d8d8de;
  font-size: 13px;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
  cursor: pointer;
}
.slide .info p.syn.expanded { display: block; -webkit-line-clamp: unset; }
.slide .info .meta { color: var(--muted); font-size: 12px; margin-top: 8px; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }

/* feed 卡片上的「看全集」黄按钮（和详情页同款） */
.slide .watchall {
  margin-top: 10px;
  background: linear-gradient(135deg, #ffcf3d, #ffb800);
  color: #221a00;
  border: 0;
  border-radius: 999px;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .45);
}

.slide .acts { display: flex; flex-direction: column; gap: 14px; align-items: center; flex: 0 0 auto; padding-bottom: 4px; }
.act { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.slide .acts button,
.detail-rail button {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .35);
  background: rgba(0, 0, 0, .45);
  color: #fff;
  cursor: pointer;
}
.slide .acts button svg { width: 19px; height: 19px; }
.slide .acts span, .detail-rail span { font-size: 12px; color: #fff; text-align: center; }
.slide .acts button.faved, .detail-rail button.faved { color: var(--gold); border-color: rgba(255, 207, 61, .6); }

.slide .mutebtn {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 4;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .35);
  background: rgba(0, 0, 0, .45);
  color: #fff;
  cursor: pointer;
}
.slide .mutebtn svg { width: 15px; height: 15px; }

.slide .prog {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 4px;
  background: rgba(255, 255, 255, .22);
  z-index: 4;
  cursor: pointer;
}
.slide .progfill { height: 100%; width: 0; background: var(--accent); }

.slide .centerflash {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  font-size: 64px;
  color: rgba(255, 255, 255, .9);
  text-shadow: 0 2px 12px rgba(0, 0, 0, .6);
  pointer-events: none;
  z-index: 5;
  opacity: 0;
}
.slide .centerflash.flashshow { animation: flashfade .7s ease forwards; }
@keyframes flashfade { 0% { opacity: 0 } 25% { opacity: 1 } 100% { opacity: 0 } }

.heartpop {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  font-size: 80px;
  color: var(--accent);
  pointer-events: none;
  animation: pop .7s ease forwards;
  z-index: 6;
}
@keyframes pop {
  0% { transform: translate(-50%, -50%) scale(.4); opacity: 0 }
  30% { transform: translate(-50%, -50%) scale(1.2); opacity: 1 }
  100% { transform: translate(-50%, -50%) scale(1) translateY(-30px); opacity: 0 }
}

/* 播放源加载失败：盖一层可点的重试条，而不是永远黑着 */
.slide .slideerr {
  position: absolute;
  inset: 0;
  z-index: 7;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  font-size: 14px;
  text-align: center;
  padding: 20px;
}
.slide .slideerr button { background: rgba(255, 255, 255, .16); border: 1px solid rgba(255, 255, 255, .4); color: #fff; border-radius: 999px; padding: 8px 20px; font-size: 14px; cursor: pointer; }

/* 起播缓冲中的小转圈 */
.slide.waiting::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 30px;
  height: 30px;
  margin: -15px 0 0 -15px;
  border: 2px solid rgba(255, 255, 255, .25);
  border-top-color: #fff;
  border-radius: 50%;
  z-index: 6;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg) } }

.feedend { display: flex; align-items: center; justify-content: center; height: 40%; color: var(--muted); font-size: 14px; scroll-snap-align: start; }
.feedretry {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  margin: 12px;
  border-radius: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  scroll-snap-align: start;
}
.newbanner {
  position: sticky;
  top: 8px;
  z-index: 40;
  margin: 8px auto;
  text-align: center;
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 14px;
  cursor: pointer;
  max-width: 320px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .5);
}

/* ---------------------------- 卡片 / 榜单 ---------------------------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; cursor: pointer; }
.card img { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; display: block; background: #222; }
.card .t { padding: 8px 10px; }
.card .t h4 { font-size: 14px; line-height: 1.35; height: 38px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.card .t p { color: var(--muted); font-size: 12px; margin-top: 4px; display: flex; align-items: center; gap: 3px; }

.rankrow {
  display: flex;
  gap: 12px;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  margin-bottom: 10px;
  cursor: pointer;
}
.rankrow .no { font-size: 20px; font-weight: 900; width: 30px; text-align: center; color: var(--accent); flex: 0 0 auto; }
.rankrow img { width: 64px; height: 86px; object-fit: cover; border-radius: 8px; flex: 0 0 auto; }
.rankrow h4 { font-size: 15px; line-height: 1.4; }
.rankrow p { color: var(--muted); font-size: 12px; margin-top: 4px; display: flex; align-items: center; gap: 3px; flex-wrap: wrap; }

/* ---------------------------- 我的 ---------------------------- */
.mebox { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.mebox h3 { font-size: 16px; margin-bottom: 10px; }
.mebox input, .mebox select {
  width: 100%;
  background: var(--card2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 10px;
  font-size: 14px;
  margin: 6px 0;
  outline: none;
}
.mebox label.hint { display: block; margin-top: 10px; }
.mebox .grid { margin-top: 4px; }

/* ---------------------------- 详情弹窗 ---------------------------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  overflow-y: auto;
  padding: 12px 12px calc(var(--bottomnav-h) + 20px);
  background: rgba(10, 10, 12, .985); /* 几乎不透明，避免背后 feed 文字透出来 */
}
.modal .box { max-width: 900px; margin: 0 auto; }
.modal .close {
  position: sticky;
  top: 6px;
  float: right;
  z-index: 2;
  width: 33px;
  height: 33px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .6);
  color: #fff;
  border: 1px solid #555;
  border-radius: 50%;
  cursor: pointer;
}
.modal h2 { font-size: 19px; line-height: 1.4; margin: 12px 0 6px; }
.modal .desc { color: #cfcfd6; font-size: 13px; line-height: 1.7; white-space: pre-wrap; }
.desc.clamped { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

.detailback { position: sticky; top: 0; z-index: 3; margin-bottom: 8px; }

.detail-cover {
  position: relative;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  border-radius: 16px;
  overflow: hidden;
  cursor: pointer;
  min-height: 200px;
  background: linear-gradient(160deg, #2b2b35, #141419);
}
.detail-cover img { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; display: block; background: #222; }

.detail-rail { position: absolute; right: 10px; bottom: 12px; display: flex; flex-direction: column; gap: 14px; align-items: center; z-index: 2; }
.detail-rail button { width: 41px; height: 41px; background: rgba(0, 0, 0, .55); }
.detail-rail button svg { width: 17px; height: 17px; }
.detail-rail span { text-shadow: 0 1px 4px rgba(0, 0, 0, .8); }

.detail-stats { display: flex; gap: 16px; flex-wrap: wrap; color: #d8d8de; font-size: 14px; margin: 10px 0; }
.detail-stats span { display: inline-flex; align-items: center; gap: 4px; }
.detail-stats b { color: #fff; }
.detail-tags { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }

.score-badge { display: inline-block; background: #f5c518; color: #111; border-radius: 6px; padding: 2px 8px; font-weight: 800; font-size: 13px; margin-right: 6px; }

.ep-range { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.ep-range button, .modal .eps button {
  background: var(--card2);
  border: 1px solid var(--line);
  color: #ddd;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
}
.ep-range button.on, .modal .eps button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.modal .eps { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.modal .eps button.watched { border-color: #3a7d4f; color: #9ed6a8; }
.modal .eps button.watched::after { content: ' ✓'; }

.detail-play { width: 100%; padding: 13px; font-size: 16px; margin: 12px 0; }
.backlink { background: none; border: 0; color: #ddd; font-size: 14px; cursor: pointer; padding: 8px 0; }
.btn.backlink { padding: 8px 16px; }

/* ---------------------------- 播放器 ---------------------------- */
.playerhead { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 4px 0 8px; }
.modal video { width: 100%; max-height: 62vh; background: #000; border-radius: var(--radius); display: block; }
.playerstatus { margin-top: 8px; font-size: 13px; color: var(--muted); }
.playerstatus.err { color: #ff8a9b; }

.ctl { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 10px 0; }
.ctl select { background: var(--card2); border: 1px solid var(--line); color: #eee; border-radius: 8px; padding: 8px; font-size: 13px; }

/* ---------------------------- 评论 / 分享面板 ---------------------------- */
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 80;
  max-height: 72dvh;
  padding: 6px 14px calc(var(--bottomnav-h) + 20px + env(safe-area-inset-bottom));
  background: var(--card);
  border-top: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
  overflow-y: auto;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, .6);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0 10px; position: sticky; top: 0; background: var(--card); z-index: 1; }
.sheet-head h3 { font-size: 16px; }
.sheet .close {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--card2);
  border: 1px solid var(--line);
  color: #fff;
  border-radius: 50%;
  cursor: pointer;
}
.sheet .close svg { width: 14px; height: 14px; }

.comment { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.comment .cav { width: 34px; height: 34px; border-radius: 50%; background: #33333d; color: #fff; display: flex; align-items: center; justify-content: center; font-size: 15px; flex-shrink: 0; }
.comment .cbody { flex: 1; min-width: 0; }
.comment .cbody b { font-size: 14px; }
.comment .cbody p { font-size: 14px; line-height: 1.6; margin-top: 2px; word-break: break-word; }
.cmeta { color: var(--muted); font-size: 12px; }

.commentbar { display: flex; gap: 8px; margin-top: 12px; }
.commentbar input {
  flex: 1;
  min-width: 0;
  background: var(--card2);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  padding: 10px 14px;
  font-size: 14px;
  outline: none;
}

.sharegrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 12px 0; }
.sharegrid button { background: var(--card2); border: 1px solid var(--line); border-radius: var(--radius); color: #eee; padding: 12px 4px; font-size: 13px; cursor: pointer; }
.sharegrid button .ic { font-size: 19px; display: block; margin-bottom: 4px; }
.sharegrid button .ic svg { width: 19px; height: 19px; margin: 0 auto; }
.sharelink { background: var(--card2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; font-size: 13px; word-break: break-all; color: #cfcfd6; }

/* ---------------------------- 提示 ---------------------------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bottomnav-h) + 20px);
  transform: translateX(-50%);
  max-width: min(86vw, 460px);
  background: #222;
  border: 1px solid var(--line);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  text-align: center;
  z-index: 99;
  display: none;
}

footer { color: var(--muted); font-size: 12px; text-align: center; padding: 18px 12px calc(var(--bottomnav-h) + 18px); }
body[data-view="home"] footer { display: none; }

@media (max-width: 640px) {
  .slide .info h3 { font-size: 17px; }
}

/* 尊重系统「减少动态效果」 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .feed { scroll-behavior: auto; }
}
