/* ============================================================
   礼物打赏审美：暖金 × 品红 × 深紫黑底
   规则：中性状态保持克制，只有表情触发时才让界面「亮起来」
   ============================================================ */

:root {
  --bg: #0a0710;
  --fg: #fff6ee;
  --dim: rgba(255, 246, 238, 0.58);
  --dimmer: rgba(255, 246, 238, 0.34);

  --gold: #ffd46b;
  --gold-deep: #ffab2e;
  --magenta: #ff3e8f;
  --cool: #6cc9ff;

  --glass: rgba(22, 14, 28, 0.52);
  --glass-strong: rgba(18, 11, 24, 0.78);
  --stroke: rgba(255, 220, 190, 0.14);
  --stroke-hot: rgba(255, 190, 120, 0.42);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  min-height: 100%;
  background: var(--bg);
  color: var(--fg);
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  min-height: 100svh;
  overflow: hidden;
  overscroll-behavior: none;
}

/* video 只是帧源：保持解码，但不参与视觉合成 */
#cam {
  position: absolute; top: 0; left: 0;
  width: 2px; height: 2px;
  opacity: 0; pointer-events: none;
}

#fx { position: absolute; inset: 0; display: block; }

.hidden { display: none !important; }

/* ============================ 直播间顶栏 ============================ */

#topbar {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
}
#topbar > * { pointer-events: auto; }

.anchor-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px 5px 5px;
  border-radius: 999px;
  background: rgba(14, 9, 20, 0.52);
  border: 1px solid var(--stroke);
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
}

.avatar {
  display: grid; place-items: center;
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--gold), var(--magenta));
  box-shadow: 0 0 0 1.5px rgba(255, 220, 180, 0.4);
}
.avatar i { font-style: normal; font-size: 16px; }

.anchor-meta { display: flex; flex-direction: column; gap: 1px; line-height: 1.25; }
.anchor-name { font-size: 12.5px; font-weight: 600; }
.anchor-sub { font-size: 10.5px; color: var(--dimmer); font-variant-numeric: tabular-nums; }
.anchor-sub b { color: var(--gold); font-weight: 600; }

.live-dot {
  margin-left: 2px;
  padding: 2.5px 7px;
  border-radius: 6px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #fff;
  background: linear-gradient(120deg, #ff2e63, #ff5f8f);
  box-shadow: 0 0 14px rgba(255, 46, 99, 0.6);
  animation: livePulse 1.8s ease-in-out infinite;
}
@keyframes livePulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.55; }
}

.top-right { display: flex; align-items: center; gap: 8px; }

.watchers {
  display: flex; align-items: center;
  padding: 4px 10px 4px 6px;
  border-radius: 999px;
  background: rgba(14, 9, 20, 0.5);
  border: 1px solid var(--stroke);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.wface {
  font-style: normal;
  font-size: 13px;
  margin-right: -6px;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5));
}
.watchers b { margin-left: 10px; color: var(--gold); font-weight: 700; }

.icon-btn {
  display: grid; place-items: center;
  width: 30px; height: 30px;
  font: inherit; font-size: 13px;
  border-radius: 50%;
  border: 1px solid var(--stroke);
  background: rgba(14, 9, 20, 0.5);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: var(--dim);
  cursor: pointer;
  transition: color .16s, border-color .16s;
}
.icon-btn[aria-pressed="true"] { color: var(--gold); border-color: var(--stroke-hot); }

/* ============================ 表情能量槽 ============================ */

#hud {
  position: absolute;
  top: calc(max(12px, env(safe-area-inset-top)) + 50px);
  left: max(12px, env(safe-area-inset-left));
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 11px 15px 12px;
  border-radius: 18px;
  background: var(--glass);
  border: 1px solid var(--stroke);
  backdrop-filter: blur(18px) saturate(1.2);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
  box-shadow: 0 14px 44px rgba(0, 0, 0, 0.42);
}

.hud-main { display: flex; align-items: center; gap: 10px; }

.state-icon {
  font-size: 20px;
  line-height: 1;
  filter: drop-shadow(0 0 10px rgba(255, 180, 90, 0.45));
}

.state-text {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: color 0.25s, text-shadow 0.25s;
}
.state-text.neutral { color: var(--dim); }
.state-text.smile   { color: var(--cool);    text-shadow: 0 0 18px rgba(108, 201, 255, 0.55); }
.state-text.laugh   { color: var(--gold);    text-shadow: 0 0 20px rgba(255, 190, 90, 0.7); }

.meters { display: flex; flex-direction: column; gap: 7px; }

.meter {
  display: flex; align-items: center; gap: 9px;
  font-size: 11px; color: var(--dimmer);
  font-variant-numeric: tabular-nums;
}
.m-label { width: 26px; letter-spacing: 0.06em; }
.m-track {
  position: relative;
  width: 118px; height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.11);
  overflow: hidden;
}
.m-fill {
  position: absolute; inset: 0;
  transform: scaleX(0);
  transform-origin: left center;
  border-radius: 999px;
  will-change: transform;
}
.m-fill.cool { background: linear-gradient(90deg, #3f9fe0, var(--cool)); box-shadow: 0 0 10px rgba(108, 201, 255, 0.6); }
.m-fill.warm { background: linear-gradient(90deg, var(--gold), var(--magenta)); box-shadow: 0 0 12px rgba(255, 150, 90, 0.65); }
.m-val { width: 30px; text-align: right; }

/* ============================ 性能面板 ============================ */

#perf {
  position: absolute;
  top: calc(max(12px, env(safe-area-inset-top)) + 46px);
  right: max(12px, env(safe-area-inset-right));
  z-index: 5;
  min-width: 152px;
  padding: 12px 14px;
  border-radius: 16px;
  background: var(--glass);
  border: 1px solid var(--stroke);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.4);
}
.p-row {
  display: flex; justify-content: space-between; gap: 14px;
  padding: 2.5px 0;
  color: var(--dimmer);
}
.p-row b { color: var(--fg); font-weight: 600; }
.p-backend {
  margin-top: 5px; padding-top: 7px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.p-backend b { color: var(--gold); font-size: 10px; }

/* ============================ 校准浮层 ============================ */

#calib {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  z-index: 6;
  display: flex; align-items: center; gap: 16px;
  padding: 16px 22px 16px 16px;
  border-radius: 22px;
  background: var(--glass-strong);
  border: 1px solid var(--stroke-hot);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
#calib .ring { width: 54px; height: 54px; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: rgba(255, 255, 255, 0.12); stroke-width: 6; }
.ring-fg {
  fill: none;
  stroke: var(--gold);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 213.6;
  stroke-dashoffset: 213.6;
  filter: drop-shadow(0 0 6px rgba(255, 190, 90, 0.8));
  transition: stroke-dashoffset 0.12s linear;
}
.calib-text { display: flex; flex-direction: column; gap: 4px; }
.calib-text strong { font-size: 13px; font-weight: 600; }
.calib-text span { font-size: 11px; color: var(--dim); }
.calib-text i { font-style: normal; color: var(--dim); }
.calib-text b {
  color: var(--gold);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ============================ 礼物横幅 + 连击 ============================ */

/**
 * 直播礼物横幅：左进场、右侧连击数字弹跳。
 * 三档热度（base/warm/hot）随连击升级配色，形成「排面递进」。
 */
#gift {
  position: absolute;
  left: max(12px, env(safe-area-inset-left));
  bottom: max(88px, calc(env(safe-area-inset-bottom) + 76px));
  z-index: 7;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100% - 24px);
  padding: 8px 14px 8px 9px;
  border-radius: 999px;
  border: 1px solid var(--stroke-hot);
  background: linear-gradient(100deg, rgba(255, 120, 40, 0.42), rgba(22, 12, 28, 0.62) 72%);
  backdrop-filter: blur(16px) saturate(1.3);
  -webkit-backdrop-filter: blur(16px) saturate(1.3);
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.45);
}
#gift[data-tier="warm"] {
  background: linear-gradient(100deg, rgba(255, 90, 60, 0.52), rgba(30, 12, 30, 0.64) 72%);
}
#gift[data-tier="hot"] {
  background: linear-gradient(100deg, rgba(255, 46, 99, 0.62), rgba(120, 40, 200, 0.42) 58%, rgba(28, 10, 30, 0.64));
  border-color: rgba(255, 170, 200, 0.55);
}

.gift-icon {
  display: grid; place-items: center;
  width: 32px; height: 32px;
  border-radius: 50%;
  font-size: 17px;
  background: rgba(0, 0, 0, 0.28);
  box-shadow: inset 0 0 0 1px rgba(255, 220, 180, 0.22);
}
.gift-text { display: flex; flex-direction: column; gap: 1px; line-height: 1.25; }
.gift-text strong { font-size: 12.5px; font-weight: 700; }
.gift-text span { font-size: 10.5px; color: rgba(255, 246, 238, 0.66); }

.gift-combo {
  margin-left: 4px;
  font-size: 19px;
  font-weight: 800;
  font-style: italic;
  letter-spacing: -0.02em;
  color: #fff3d0;
  text-shadow: 0 0 14px rgba(255, 190, 90, 0.9), 0 2px 0 rgba(120, 40, 0, 0.5);
  font-variant-numeric: tabular-nums;
}

#gift.pop { animation: giftIn .42s cubic-bezier(.16,1.2,.3,1); }
#gift.pop .gift-combo { animation: comboPop .42s cubic-bezier(.16,1.6,.3,1); }
/* 入场用纵向位移 + 缩放而非横向位移：
   横向 translateX 起始帧会让横幅越过左边界，页面切后台导致动画暂停时会留下裁切残影 */
@keyframes giftIn {
  from { opacity: 0; transform: translateY(14px) scale(0.92); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes comboPop {
  0%   { transform: scale(0.6) rotate(-8deg); }
  55%  { transform: scale(1.38) rotate(3deg); }
  100% { transform: scale(1) rotate(0); }
}

/* ============================ 飘心流 ============================ */

#hearts {
  position: absolute;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(96px, calc(env(safe-area-inset-bottom) + 84px));
  width: 60px; height: 200px;
  z-index: 6;
  pointer-events: none;
  overflow: hidden;
}
.heart {
  position: absolute;
  right: 12px; bottom: 0;
  font-size: 17px;
  font-style: normal;
  opacity: 0;
  will-change: transform, opacity;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.4));
}
.heart.fly { animation: heartFly var(--dur, 1.8s) ease-out forwards; }
@keyframes heartFly {
  0%   { opacity: 0;    transform: translate(0, 0) scale(0.6); }
  18%  { opacity: 0.95; transform: translate(calc(var(--dx) * 0.3), -34px) scale(1.06); }
  100% { opacity: 0;    transform: translate(var(--dx), -190px) scale(0.82); }
}

/* ============================ 底部控制（直播输入条） ============================ */

#controls {
  position: absolute;
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  bottom: max(18px, calc(env(safe-area-inset-bottom) + 10px));
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 9px;
}

/* 假评论框：直播间的形状记忆点，不接受输入，只负责「像直播间」 */
.fake-input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid var(--stroke);
  background: rgba(14, 9, 20, 0.48);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  font-size: 12.5px;
  color: var(--dimmer);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.round-btn {
  flex: 0 0 auto;
  display: grid; place-items: center;
  width: 40px; height: 40px;
  font: inherit; font-size: 17px;
  border-radius: 50%;
  border: 1px solid var(--stroke);
  background: rgba(14, 9, 20, 0.5);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  cursor: pointer;
  transition: transform .12s, filter .14s, border-color .16s;
}
.round-btn:active { transform: scale(0.92); }
.round-btn:hover { border-color: var(--stroke-hot); }

.round-gift {
  border-color: transparent;
  background: linear-gradient(135deg, #ffe49a, var(--gold) 40%, var(--gold-deep) 78%, #ff7a3d);
  box-shadow: 0 6px 22px rgba(255, 160, 60, 0.42);
  animation: giftBreathe 2.6s ease-in-out infinite;
}
.round-gift:hover { filter: brightness(1.07); }
@keyframes giftBreathe {
  0%, 100% { box-shadow: 0 6px 22px rgba(255, 160, 60, 0.42); }
  50%      { box-shadow: 0 6px 30px rgba(255, 190, 90, 0.72); }
}

/* ============================ Toast ============================ */

#toast {
  position: absolute;
  left: 50%;
  bottom: max(140px, calc(env(safe-area-inset-bottom) + 128px));
  transform: translate(-50%, 8px);
  z-index: 7;
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--glass-strong);
  border: 1px solid var(--stroke);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  font-size: 12px;
  color: var(--fg);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
  white-space: nowrap;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ============================ 启动页 ============================ */

#gate {
  position: absolute; inset: 0; z-index: 10;
  display: grid; place-items: center;
  padding: max(22px, env(safe-area-inset-top)) max(22px, env(safe-area-inset-right)) max(22px, env(safe-area-inset-bottom)) max(22px, env(safe-area-inset-left));
  background: #0a0710;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* 背景的礼物金光：静态渐变 + 极慢呼吸，不占主线程 */
.glow-bg {
  position: absolute; inset: -20%;
  background:
    radial-gradient(38% 30% at 22% 18%, rgba(255, 178, 64, 0.30), transparent 70%),
    radial-gradient(42% 34% at 82% 26%, rgba(255, 62, 143, 0.26), transparent 72%),
    radial-gradient(60% 46% at 50% 92%, rgba(120, 60, 220, 0.20), transparent 76%);
  filter: blur(18px);
  animation: breathe 9s ease-in-out infinite;
}
@keyframes breathe {
  0%, 100% { opacity: 0.85; transform: scale(1); }
  50%      { opacity: 1;    transform: scale(1.05); }
}

.card {
  position: relative;
  width: min(468px, 100%);
  padding: 30px 28px 26px;
  border-radius: 28px;
  background: rgba(16, 10, 22, 0.80);
  border: 1px solid var(--stroke-hot);
  backdrop-filter: blur(26px) saturate(1.3);
  -webkit-backdrop-filter: blur(26px) saturate(1.3);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.66), inset 0 1px 0 rgba(255, 220, 180, 0.12);
}

.badge {
  display: inline-block;
  margin-bottom: 16px;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--stroke-hot);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--gold);
}

.card h1 {
  margin: 0 0 14px;
  font-size: 29px;
  line-height: 1.28;
  letter-spacing: -0.01em;
  font-weight: 700;
}
.card h1 em {
  font-style: normal;
  background: linear-gradient(100deg, var(--gold) 10%, var(--magenta) 92%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sub {
  margin: 0 0 18px;
  font-size: 13px;
  line-height: 1.78;
  color: var(--dim);
}

.facts {
  margin: 0 0 22px;
  padding: 0;
  list-style: none;
  display: flex; flex-direction: column; gap: 9px;
}
.facts li {
  position: relative;
  padding-left: 15px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--dimmer);
}
.facts li::before {
  content: '';
  position: absolute; left: 0; top: 7px;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--gold), var(--magenta));
}
.facts b { color: var(--fg); font-weight: 600; margin-right: 4px; }

#btnStart {
  width: 100%;
  font: inherit; font-size: 15.5px; font-weight: 700;
  color: #2a1400;
  padding: 15px;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(120deg, #ffe49a, var(--gold) 38%, var(--gold-deep) 72%, #ff8f4d);
  box-shadow: 0 10px 34px rgba(255, 160, 60, 0.36);
  cursor: pointer;
  transition: filter .14s, transform .12s, opacity .14s;
}
#btnStart:hover { filter: brightness(1.06); }
#btnStart:active { transform: scale(0.985); }
#btnStart:disabled { opacity: 0.6; cursor: progress; }

.msg {
  min-height: 0;
  margin: 12px 0 0;
  font-size: 12px;
  line-height: 1.65;
  color: #ffb366;
}
.msg:empty { display: none; }

.tip {
  margin: 14px 0 0;
  font-size: 11px;
  line-height: 1.6;
  color: rgba(255, 246, 238, 0.28);
  text-align: center;
}

/* ============================ 自适应 ============================ */

@media (max-width: 600px) {
  #gate {
    place-items: start center;
    padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  }
  .card {
    width: min(100%, 430px);
    margin: auto 0;
    padding: 24px 20px 20px;
    border-radius: 24px;
  }
  .card h1 { font-size: clamp(24px, 7vw, 29px); }
  #hud {
    top: calc(max(10px, env(safe-area-inset-top)) + 48px);
    left: max(10px, env(safe-area-inset-left));
    right: max(10px, env(safe-area-inset-right));
    padding: 10px 14px 11px;
  }
  .m-track { width: auto; flex: 1; }
  .meter { gap: 8px; }
  #perf { display: none !important; }
  #topbar {
    top: max(10px, env(safe-area-inset-top));
    left: max(10px, env(safe-area-inset-left));
    right: max(10px, env(safe-area-inset-right));
  }
  .anchor-name { font-size: 12px; }
  .wface:nth-child(3) { display: none; }
  #gift {
    left: max(10px, env(safe-area-inset-left));
    bottom: max(78px, calc(env(safe-area-inset-bottom) + 68px));
    padding: 7px 12px 7px 8px;
  }
  .gift-combo { font-size: 17px; }
  #hearts {
    bottom: max(86px, calc(env(safe-area-inset-bottom) + 76px));
    height: 170px;
  }
  #controls {
    bottom: max(12px, calc(env(safe-area-inset-bottom) + 8px));
    gap: 8px;
  }
  .fake-input { padding: 9px 14px; font-size: 12px; }
  .round-btn { width: 38px; height: 38px; font-size: 16px; }
  #calib {
    width: calc(100% - 32px - env(safe-area-inset-left) - env(safe-area-inset-right));
    max-width: 360px;
    padding: 14px 16px 14px 14px;
  }
  #toast {
    max-width: calc(100% - 32px);
    white-space: normal;
    text-align: center;
  }
}

@media (max-height: 700px) and (max-width: 600px) {
  .card { margin: 0; padding: 18px 18px 16px; }
  .badge { margin-bottom: 10px; }
  .card h1 { margin-bottom: 9px; font-size: 23px; line-height: 1.2; }
  .sub { margin-bottom: 11px; font-size: 12px; line-height: 1.55; }
  .facts { margin-bottom: 14px; gap: 5px; }
  .facts li { font-size: 11px; line-height: 1.45; }
  #btnStart { padding: 12px; }
  .tip { margin-top: 9px; }
}

@media (max-width: 360px) {
  .card { padding-inline: 16px; }
  .facts li { padding-left: 12px; }
  .anchor-sub { display: none; }
  .watchers { display: none; }
  .gift-text span { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .glow-bg { animation: none; }
}
