/* =========================================================
   LIVE GALLERY — 视觉志直播画廊
   设计：深空暗场 / 电影字幕排版 / 极细线框
   ========================================================= */
:root {
  --bg: #06070b;
  --ink: #f2f5fa;
  --dim: rgba(242, 245, 250, 0.52);
  --faint: rgba(242, 245, 250, 0.28);
  --line: rgba(255, 255, 255, 0.12);
  --accent: #63e6ff;
  --pad: clamp(20px, 3.6vw, 64px);
  --font: "SF Pro Display", -apple-system, "PingFang SC", "HarmonyOS Sans SC",
    "Source Han Sans SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
}

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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  cursor: none;
}
body:hover { cursor: default; }

#stage { position: fixed; inset: 0; isolation: isolate; }

#gl {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
  z-index: 1;
}

/* 全局胶片颗粒（DOM 层面极轻叠加，增加质感） */
.grain {
  position: absolute; inset: 0; z-index: 2;
  pointer-events: none;
  opacity: 0.16;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)' opacity='0.5'/></svg>");
  animation: grainShift 0.6s steps(2) infinite;
}
@keyframes grainShift {
  0% { transform: translate3d(0, 0, 0); }
  50% { transform: translate3d(-2%, 1.5%, 0); }
  100% { transform: translate3d(1.5%, -1%, 0); }
}

/* ---------- 装饰线框 ---------- */
.deco { position: absolute; inset: 0; z-index: 5; pointer-events: none; }
.edge { position: absolute; left: var(--pad); right: var(--pad); height: 1px;
  background: linear-gradient(90deg, transparent, var(--line) 12%, var(--line) 88%, transparent); }
.edge-t { top: calc(var(--pad) - 1px); }
.edge-b { bottom: calc(var(--pad) - 1px); }
.corner {
  position: absolute; width: 16px; height: 16px;
  border: 1px solid rgba(255, 255, 255, 0.22);
}
.corner.c1 { top: calc(var(--pad) - 8px); left: calc(var(--pad) - 8px); border-right: 0; border-bottom: 0; }
.corner.c2 { top: calc(var(--pad) - 8px); right: calc(var(--pad) - 8px); border-left: 0; border-bottom: 0; }
.corner.c3 { bottom: calc(var(--pad) - 8px); left: calc(var(--pad) - 8px); border-right: 0; border-top: 0; }
.corner.c4 { bottom: calc(var(--pad) - 8px); right: calc(var(--pad) - 8px); border-left: 0; border-top: 0; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: absolute; z-index: 6;
  top: var(--pad); left: var(--pad); right: var(--pad);
  display: flex; align-items: center; justify-content: space-between;
  pointer-events: none;
  transition: opacity 0.6s ease, transform 0.6s ease;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 16px var(--accent), 0 0 32px rgba(99, 230, 255, 0.4);
}
.brand-text {
  font-size: 11px; font-weight: 600; letter-spacing: 0.34em;
  color: rgba(242, 245, 250, 0.82);
}
.brand-sep { width: 26px; height: 1px; background: var(--line); }
.brand-sub {
  font-size: 12px; letter-spacing: 0.2em; color: var(--dim); font-weight: 300;
}

.topright { display: flex; align-items: center; gap: clamp(16px, 2.4vw, 40px); }
.onair {
  display: flex; align-items: center; gap: 8px;
  font-size: 10px; letter-spacing: 0.24em; color: rgba(255, 255, 255, 0.66);
  padding: 6px 12px; border: 1px solid rgba(255, 80, 80, 0.34); border-radius: 999px;
  background: rgba(255, 60, 60, 0.06);
}
.onair .dot {
  width: 6px; height: 6px; border-radius: 50%; background: #ff4d4d;
  box-shadow: 0 0 10px rgba(255, 77, 77, 0.9);
  animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.45; transform: scale(0.86); } }

.counter {
  font-size: 13px; letter-spacing: 0.14em;
  font-variant-numeric: tabular-nums;
  color: rgba(242, 245, 250, 0.9);
  font-weight: 300;
}
.counter i { font-style: normal; color: var(--faint); margin: 0 4px; }

/* ---------- 标题 ---------- */
.caption {
  position: absolute; z-index: 6;
  left: var(--pad); bottom: calc(var(--pad) + clamp(58px, 9vh, 104px));
  max-width: min(62vw, 880px);
  pointer-events: none;
}
.cap-line {
  width: 42px; height: 1px; margin-bottom: 20px;
  background: var(--accent);
  box-shadow: 0 0 12px rgba(99, 230, 255, 0.5);
}
.cap-title {
  font-size: clamp(30px, 4.2vw, 74px);
  line-height: 1.06;
  font-weight: 700;
  letter-spacing: -0.022em;
  text-shadow: 0 8px 40px rgba(0, 0, 0, 0.55);
  transition: opacity 0.5s ease, transform 0.7s cubic-bezier(0.16, 1, 0.3, 1);
}
.cap-sub {
  margin-top: 16px;
  font-size: clamp(11px, 1.05vw, 15px);
  font-weight: 300;
  letter-spacing: 0.26em;
  color: var(--dim);
  transition: opacity 0.5s ease 0.06s, transform 0.7s cubic-bezier(0.16, 1, 0.3, 1) 0.06s;
}
.caption.swap .cap-title,
.caption.swap .cap-sub { opacity: 0; transform: translateY(10px); }

/* ---------- 底部 ---------- */
.footer {
  position: absolute; z-index: 6;
  left: var(--pad); right: var(--pad); bottom: var(--pad);
  pointer-events: none;
}
.progress-wrap { margin-bottom: 18px; }
.progress-bar {
  position: relative; height: 1px; width: 100%;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}
.progress-bar span {
  position: absolute; left: 0; top: 0; height: 100%; width: 0;
  background: linear-gradient(90deg, rgba(99, 230, 255, 0.4), var(--accent));
  box-shadow: 0 0 10px rgba(99, 230, 255, 0.6);
}
.footer-row { display: flex; align-items: flex-end; justify-content: space-between; }
.meta { display: flex; gap: 10px; align-items: baseline; font-size: 10px; letter-spacing: 0.22em; color: var(--faint); }
.meta-dim { color: rgba(242, 245, 250, 0.34); letter-spacing: 0.1em; font-variant-numeric: tabular-nums; }

.clock { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.clock-time {
  font-size: clamp(16px, 1.6vw, 22px);
  font-weight: 300; letter-spacing: 0.12em;
  font-variant-numeric: tabular-nums;
  color: rgba(242, 245, 250, 0.86);
  line-height: 1;
}
.clock-date { font-size: 10px; letter-spacing: 0.24em; color: var(--faint); }

/* ---------- 提示 / 水印 ---------- */
.hint {
  position: absolute; z-index: 6; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--pad) + 2px);
  font-size: 10px; letter-spacing: 0.18em; color: rgba(242, 245, 250, 0.22);
  pointer-events: none;
  transition: opacity 0.6s ease;
}

.watermark {
  position: absolute; z-index: 4; right: calc(var(--pad) + 4px); bottom: calc(var(--pad) + 30px);
  font-size: 9px; letter-spacing: 0.14em;
  color: rgba(255, 255, 255, 0.16);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  user-select: none;
}

/* ---------- 加载 ---------- */
.loader {
  position: absolute; inset: 0; z-index: 20;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 22px; background: var(--bg);
  transition: opacity 0.9s ease, visibility 0.9s;
}
.loader.hide { opacity: 0; visibility: hidden; }
.loader-ring {
  width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-top-color: var(--accent);
  animation: spin 1.1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader-text { font-size: 10px; letter-spacing: 0.5em; color: var(--faint); }

/* ---------- 音量 ---------- */
.audio-toggle {
  position: absolute; z-index: 7; right: var(--pad); bottom: calc(var(--pad) + 76px);
  width: 34px; height: 34px; border-radius: 50%;
  display: none; align-items: center; justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(10, 12, 18, 0.6);
  color: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  backdrop-filter: blur(8px);
}
.audio-toggle.show { display: flex; }
.audio-toggle.on { color: var(--accent); border-color: rgba(99, 230, 255, 0.4); }

/* ---------- clean 模式（OBS 采集） ---------- */
body.clean .topbar,
body.clean .caption,
body.clean .footer,
body.clean .hint,
body.clean .deco,
body.clean .watermark,
body.clean .audio-toggle { display: none !important; }
body.clean .grain { opacity: 0.1; }

/* 隐藏 UI 快捷键 */
body.bare .topbar,
body.bare .footer,
body.bare .hint,
body.bare .watermark,
body.bare .audio-toggle { opacity: 0; }

@media (max-width: 640px) {
  .brand-sub, .brand-sep, .onair { display: none; }
  .cap-sub { letter-spacing: 0.12em; }
  .clock-date { display: none; }
}

/* ---------- 竖屏 9:16 版式 ---------- */
body.portrait { --pad: clamp(14px, 4.4vw, 38px); }
body.portrait .topbar { top: 3.6vh; }
body.portrait .brand { gap: 9px; }
body.portrait .brand-text { font-size: 9px; letter-spacing: 0.3em; }
body.portrait .brand-sub,
body.portrait .brand-sep { display: none; }
body.portrait .topright { gap: 12px; flex-direction: column; align-items: flex-end; }
body.portrait .onair { font-size: 8px; letter-spacing: 0.2em; padding: 4px 9px; }
body.portrait .counter { font-size: 11px; }
body.portrait .caption {
  left: 6.5vw; right: 6.5vw; bottom: 12vh;
  max-width: none;
}
body.portrait .cap-line { width: 30px; margin-bottom: 12px; }
body.portrait .cap-title {
  font-size: clamp(26px, 7.4vw, 54px);
  line-height: 1.1;
  letter-spacing: -0.01em;
}
body.portrait .cap-sub {
  margin-top: 10px;
  font-size: clamp(9px, 2.5vw, 13px);
  letter-spacing: 0.2em;
}
body.portrait .footer { bottom: 3.2vh; }
body.portrait .progress-wrap { margin-bottom: 12px; }
body.portrait .clock-time { font-size: 15px; }
body.portrait .clock-date { font-size: 9px; }
body.portrait .meta { font-size: 10px; }
body.portrait .watermark {
  right: 5vw; bottom: calc(3.2vh + 22px);
  font-size: 8px; letter-spacing: 0.1em;
}
body.portrait .audio-toggle { right: 5vw; bottom: calc(3.2vh + 62px); }
body.portrait .hint {
  left: 50%; transform: translateX(-50%);
  bottom: 22vh; white-space: nowrap;
}

/* ---------- 无 WebGL 兜底（纯图片轮播） ---------- */
.soft-fallback {
  position: fixed; inset: 0; z-index: 3;
  display: none; align-items: center; justify-content: center;
  background: #05060a;
}
.soft-fallback.on { display: flex; }
.soft-fallback img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  transform: scale(1.02);
  transition: opacity 0.6s ease;
}
body.portrait .soft-fallback img { object-fit: cover; }
body.soft .soft-fallback.on #gl { display: none; }
body.portrait .soft-fallback img {
  width: auto; height: 96vh; max-width: 96vw;
  aspect-ratio: 9 / 16; object-fit: cover;
  border-radius: 2px;
}

/* ---------- 兜底层背景（模糊镜像，避免竖屏两侧纯黑） ---------- */
.soft-fallback .fb-bg {
  position: absolute; inset: -10%;
  background-size: cover; background-position: center;
  filter: blur(34px) saturate(1.15) brightness(0.75);
  transform: scale(1.1);
  opacity: 0.85;
}
body.soft .soft-fallback img {
  position: relative; z-index: 2;
  animation: fbKen 16s ease-in-out infinite alternate;
}
@keyframes fbKen {
  from { transform: scale(1.0); }
  to { transform: scale(1.05); }
}

/* ---------- 竖屏两侧的氛围背景（默认关闭，后台可开启） ---------- */
.stage-bg {
  position: fixed; inset: 0; z-index: 2; display: none; pointer-events: none;
  --stage-img: none;
}
body.portrait.amb .stage-bg { display: block; }
.bg-tile {
  position: absolute;
  background-image: var(--stage-img);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  filter: blur(16px) brightness(0.5) saturate(1.05);
  opacity: 0.9;
  /* 独立图层，避免和 WebGL 主层抢合成资源 */
  will-change: transform;
}
#bgLeft, #bgRight { top: 0; bottom: 0; }
#bgLeft { left: 0; }
#bgRight { right: 0; }
#bgTop, #bgBottom { left: 0; }
#bgTop { top: 0; }
#bgBottom { bottom: 0; }
body.soft .stage-bg { display: none !important; }

/* 竖屏铺满画布时，两侧氛围层与兜底图也跟着铺满 */
body.portrait.fill .stage-bg { display: none !important; }
body.soft.fill .soft-fallback img { width: 100vw !important; height: 100vh !important; object-fit: cover !important; aspect-ratio: auto !important; }