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

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

  .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: #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, 231, 176, 0.4);
  }
  .bubble-guard {
    color: #fff;
    background: var(--ring);
    box-shadow: 0 2px 6px -2px rgba(0, 0, 0, 0.4);
  }
  .bubble-card[data-guard="1"] { --ring: #e4a45c; }
  .bubble-card[data-guard="2"] { --ring: #a075d1; }
  .bubble-card[data-guard="3"] { --ring: #6ebcec; }
  .bubble-card[data-guard="1"] { --bubble-bg: #e4a45c; --bubble-fg: #fff; }
  .bubble-card[data-guard="2"] { --bubble-bg: #a075d1; --bubble-fg: #fff; }
  .bubble-card[data-guard="3"] { --bubble-bg: #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: #5a4326;
    background: linear-gradient(135deg, #fff9ec, #f4e4c3);
    border: 1px solid #e8d3a8;
    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: #5a4326;
    font-size: 14px;
    text-shadow: none;
  }
  .bubble-gift__label { font-size: 12px; color: #9a7b4f; }
  .bubble-gift__name { font-size: 13px; font-weight: 700; color: #b3822f; }
  .bubble-gift__coin {
    padding: 1px 6px;
    font-size: 11px;
    color: #9a7b4f;
    background: #fff6df;
    border-radius: 999px;
  }

  /* ── 醒目留言（SC）───────────────────────────────── */
  .bubble-sc {
    --sc-color: #6ebcec;
    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: #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(18, 20, 16, 0.92)),
      rgba(18, 20, 16, 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: #e4a45c; }
  .bubble-guard-card[data-guard="2"] { --guard-color: #a075d1; }
  .bubble-guard-card[data-guard="3"] { --guard-color: #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; }
}
