/* bubble-overlay.css — 聊天气泡式弹幕（OBS 浏览器源）
 *
 * 视觉参考 blivechat / YouTube 聊天的气泡结构：
 *   头像在左，昵称在上，白色气泡在右下，尾巴指向头像；
 *   舰长/提督/总督用不同底色，普通观众白底深字。
 *
 * 字体优先使用本机「带心的可爱字体」，没有时退回幼圆/微软雅黑。
 */

@layer page {
  /* 大航海配色令牌在 theme.css 的 :root 里（--guard-0/1/2/3），
   * 口径同 B 站：1 = 总督，2 = 提督，3 = 舰长，0 = 普通观众。
   * 这里的 var() 都带兜底值，免得 theme.css 没加载时气泡整个掉色。
   */

  html.is-overlay, html.is-overlay body {
    background: transparent !important;
    overflow: hidden;
  }

  /* 这张表在 overlay.css 之后加载，会把它的预览底色盖成透明；
     这里补回来，否则 ?preview=1 只剩一片白，没法肉眼调样式。 */
  html.is-preview, html.is-preview body {
    background: linear-gradient(135deg, #171130 0%, #2a2350 55%, #100b22 100%) !important;
  }

  .bubble-stage {
    --bubble-font: 19px;
    position: fixed;
    left: 28px;
    bottom: 26px;
    width: min(var(--bubble-width, 560px), calc(100vw - 56px));
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    gap: 12px;
    overflow: hidden;
    pointer-events: none;
    font-family: "Dainxin Cute", "带心的可爱字体", "幼圆", "Microsoft YaHei",
      "PingFang SC", "Noto Sans SC", sans-serif;
    color: #fff;
    -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 9%);
    mask-image: linear-gradient(to bottom, transparent 0, #000 9%);
  }
  .bubble-stage[data-side="right"] {
    left: auto;
    right: 28px;
    align-items: flex-end;
  }

  .bubble-card {
    --bubble-bg: #fff;
    --bubble-fg: #3a3a3a;
    --ring: var(--guard-0, #6ebcec);
    flex: 0 0 auto;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    max-width: 100%;
    animation: bubble-rise 380ms cubic-bezier(0.16, 1, 0.3, 1) both;
    transition: opacity 220ms ease, transform 220ms ease;
    will-change: opacity, transform;
  }
  .bubble-stage[data-side="right"] .bubble-card {
    flex-direction: row-reverse;
  }
  .bubble-card.is-leaving {
    opacity: 0;
    transform: translateY(-8px) scale(0.97);
  }

  @keyframes bubble-rise {
    from {
      opacity: 0;
      transform: translateY(22px) scale(0.98);
    }
    to {
      opacity: 1;
      transform: none;
    }
  }

  /* ── 头像 ─────────────────────────────────────────── */
  .bubble-avatar {
    position: relative;
    flex: 0 0 auto;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    padding: 2px;
    background: var(--ring);
    box-shadow: 0 4px 12px -5px rgba(0, 0, 0, 0.55);
  }
  .bubble-avatar img,
  .bubble-avatar__fallback {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    background: #f6efe3;
  }
  .bubble-avatar__fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #7c6752;
    font-size: 18px;
    font-weight: 700;
    text-transform: uppercase;
  }
  .bubble-avatar::after {
    content: "";
    position: absolute;
    right: 0;
    bottom: 0;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--ring);
    border: 2px solid rgba(255, 255, 255, 0.92);
  }

  /* ── 昵称 / 粉丝牌 / 舰长标 ───────────────────────── */
  .bubble-main {
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
  }
  .bubble-stage[data-side="right"] .bubble-main {
    align-items: flex-end;
  }
  .bubble-head {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    max-width: 100%;
    padding: 0 4px;
    line-height: 1.2;
  }
  .bubble-name {
    max-width: min(100%, 340px);
    overflow-wrap: anywhere;
    color: #fff;
    font-size: 16px;
    font-weight: 400;
    letter-spacing: 0.5px;
    line-height: 1.3;
    white-space: normal;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.65);
  }
  .bubble-medal,
  .bubble-guard {
    flex: 0 0 auto;
    padding: 1px 6px;
    border-radius: 999px;
    font-size: 11px;
    line-height: 1.35;
    white-space: nowrap;
  }
  .bubble-medal {
    color: #ffe7b0;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(255, 244, 219, 0.4);
  }
  .bubble-guard {
    color: #fff;
    background: var(--ring);
    box-shadow: 0 2px 6px -2px rgba(0, 0, 0, 0.4);
  }
  /* 大航海：头像框 + 右下角小圆点（--ring）与气泡底色一起跟着等级走 */
  .bubble-card[data-guard="1"] { --ring: var(--guard-1, #e4a45c); --bubble-bg: var(--guard-1, #e4a45c); --bubble-fg: #fff; }
  .bubble-card[data-guard="2"] { --ring: var(--guard-2, #a075d1); --bubble-bg: var(--guard-2, #a075d1); --bubble-fg: #fff; }
  .bubble-card[data-guard="3"] { --ring: var(--guard-3, #6ebcec); --bubble-bg: var(--guard-3, #6ebcec); --bubble-fg: #fff; }

  /* ── 气泡 ─────────────────────────────────────────── */
  .bubble-body {
    position: relative;
    max-width: min(460px, calc(100vw - 120px));
    padding: 10px 16px;
    border-radius: 20px;
    border-top-left-radius: 5px;
    background: var(--bubble-bg);
    color: var(--bubble-fg);
    box-shadow: 0 8px 24px -16px rgba(0, 0, 0, 0.65);
    font-size: var(--bubble-font);
    line-height: 1.55;
    letter-spacing: 0.4px;
    word-break: break-word;
    white-space: pre-wrap;
  }
  .bubble-stage[data-side="right"] .bubble-body {
    border-top-left-radius: 18px;
    border-top-right-radius: 5px;
  }
  .bubble-body::before {
    content: "";
    position: absolute;
    left: -8px;
    top: 14px;
    width: 14px;
    height: 14px;
    border-radius: 2px 0 2px 2px;
    background: var(--bubble-bg);
    transform: rotate(45deg);
  }
  .bubble-stage[data-side="right"] .bubble-body::before {
    left: auto;
    right: -8px;
    border-radius: 0 2px 2px 2px;
  }

  /* ── 礼物卡片 ─────────────────────────────────────── */
  .bubble-gift {
    align-items: center;
    gap: 9px;
    max-width: min(420px, calc(100vw - 100px));
    padding: 8px 12px 8px 8px;
    color: #3b2f56;
    background: linear-gradient(135deg, #fff9ec, #f4e4c3);
    border: 1px solid #ddcdf2;
    border-radius: 16px;
    box-shadow: 0 10px 24px -18px rgba(0, 0, 0, 0.6);
  }
  .gift-icon {
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    font-size: 19px;
    background: #fff3d7;
    border-radius: 12px;
  }
  .bubble-gift__main { gap: 0; align-items: flex-start; }
  .bubble-gift__head {
    gap: 5px;
    padding: 0;
    align-items: center;
    flex-wrap: wrap;
  }
  .bubble-gift .bubble-name {
    max-width: 280px;
    color: #3b2f56;
    font-size: 14px;
    text-shadow: none;
  }
  .bubble-gift__label { font-size: 12px; color: #7c6f9c; }
  .bubble-gift__name { font-size: 13px; font-weight: 700; color: #b3822f; }
  .bubble-gift__coin {
    padding: 1px 6px;
    font-size: 11px;
    color: #7c6f9c;
    background: #fff6df;
    border-radius: 999px;
  }

  /* ── 醒目留言（SC）───────────────────────────────── */
  .bubble-sc {
    --sc-color: #cfa85c;
    flex-direction: column;
    align-items: stretch;
    width: min(420px, calc(100vw - 100px));
    background: #fff;
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 14px 30px -20px rgba(0, 0, 0, 0.7);
  }
  .sc-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--sc-color);
    color: #fff;
  }
  .sc-head .bubble-avatar {
    width: 34px;
    height: 34px;
    padding: 1px;
    background: #fff;
    box-shadow: none;
  }
  .sc-head .bubble-avatar::after { display: none; }
  .sc-name {
    min-width: 0;
    overflow-wrap: anywhere;
    color: #fff;
    font-size: 15px;
    line-height: 1.3;
    white-space: normal;
  }
  .sc-price {
    margin-left: auto;
    flex: 0 0 auto;
    padding: 2px 10px;
    border-radius: 999px;
    background: #fff;
    color: var(--sc-color);
    font-size: 13px;
    transform: rotate(6deg);
    box-shadow: 0 3px 8px -4px rgba(0, 0, 0, 0.5);
  }
  .sc-body {
    padding: 10px 15px 12px;
    color: #3a3a3a;
    font-size: var(--bubble-font);
    line-height: 1.55;
    letter-spacing: 0.4px;
    word-break: break-word;
    white-space: pre-wrap;
  }
  .bubble-stage[data-side="right"] .bubble-sc {
    align-items: stretch;
  }

  /* ── 上舰卡片 ─────────────────────────────────────── */
  .bubble-guard-card {
    --guard-color: var(--guard-0, #6ebcec);
    max-width: min(400px, calc(100vw - 100px));
    padding: 10px 14px 10px 10px;
    background: linear-gradient(
      135deg,
      color-mix(in srgb, var(--guard-color) 22%, rgba(16, 12, 34, 0.92)),
      rgba(16, 12, 34, 0.88)
    );
    border: 1px solid color-mix(in srgb, var(--guard-color) 55%, transparent);
    border-radius: 18px;
    box-shadow: 0 14px 30px -22px rgba(0, 0, 0, 0.75);
  }
  .bubble-guard-card[data-guard="1"] { --guard-color: var(--guard-1, #e4a45c); }
  .bubble-guard-card[data-guard="2"] { --guard-color: var(--guard-2, #a075d1); }
  .bubble-guard-card[data-guard="3"] { --guard-color: var(--guard-3, #6ebcec); }
  .bubble-guard-card .bubble-avatar {
    width: 44px;
    height: 44px;
    background: var(--guard-color);
  }
  .bubble-guard-card .bubble-body {
    background: transparent;
    box-shadow: none;
    padding: 2px 2px 0;
    color: #fff;
    border-radius: 0;
    font-size: 15px;
  }
  .bubble-guard-card .bubble-body::before { display: none; }
  .bubble-guard-card .bubble-name { font-size: 15px; }

  /* ── 中控台发的管理员弹幕：全息箔 ─────────────────────
   * 只有 payload.admin 的卡片会带 .is-admin，普通观众和舰长/提督/总督不受影响。
   * 气泡是浅镭射渐变 + 深色字；另有一条柔光每 9 秒扫过一次。
   * 尾巴（::before）吃的是 --bubble-bg，所以这里给一个与渐变左端一致的颜色。
   */
  .bubble-card.is-admin {
    --bubble-bg: #c9b4ff;
    --bubble-fg: #241a3d;
    --ring: #c9b4ff;
  }
  .bubble-card.is-admin .bubble-body {
    position: relative;
    color: #241a3d;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.6);
    background: linear-gradient(
      112deg,
      #c9b4ff 0%,
      #a6dcff 20%,
      #bffbe2 38%,
      #ffecb0 54%,
      #ffc3d8 70%,
      #d6b8ff 86%,
      #c2adff 100%
    );
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.95),
      inset 0 0 0 1px rgba(255, 255, 255, 0.55),
      0 14px 32px -18px rgba(190, 165, 255, 0.95);
  }
  /* 斜向高光：用 background-position 动画，不能给气泡加 overflow:hidden，
     否则 ::before 那条指向头像的尾巴会被裁掉。 */
  .bubble-card.is-admin .bubble-body::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    background: linear-gradient(
      102deg,
      transparent 34%,
      rgba(255, 255, 255, 0.85) 48%,
      transparent 62%
    );
    background-size: 260% 100%;
    animation: admin-sheen 9s linear infinite;
  }
  @keyframes admin-sheen {
    from { background-position: 220% 0; }
    to { background-position: -80% 0; }
  }
  .bubble-card.is-admin .bubble-avatar {
    background: conic-gradient(from 200deg, #d9cbff, #b6e4ff, #fff2c9, #ffd6e4, #d9cbff);
    box-shadow:
      0 0 0 2px rgba(255, 255, 255, 0.5),
      0 8px 20px -10px rgba(200, 180, 255, 0.9);
    animation: admin-spin 20s linear infinite;
  }
  @keyframes admin-spin {
    to { transform: rotate(360deg); }
  }
  .bubble-card.is-admin .bubble-avatar::after {
    background: #ffd6e4;
    border-color: rgba(255, 255, 255, 0.95);
  }
  .bubble-admin-tag {
    flex: 0 0 auto;
    padding: 1px 7px;
    font-size: 11px;
    line-height: 1.35;
    color: #2a1f4d;
    background: linear-gradient(110deg, #c9b4ff, #a6dcff 35%, #ffecb0 65%, #ffc3d8);
    border: 1px solid rgba(255, 255, 255, 0.9);
    border-radius: 999px;
    white-space: nowrap;
  }
  /* 平静模式：停掉流动，只保留静态全息底 */
  html[data-motion="calm"] .bubble-card.is-admin .bubble-body::after,
  html[data-motion="calm"] .bubble-card.is-admin .bubble-avatar {
    animation: none;
  }
}
