.project-barrage { position: fixed; bottom: 96px; right: 20px; z-index: 1200; }
.project-barrage[hidden] { display: none; }
.project-barrage-fab {
    position: relative; display: flex; align-items: center; justify-content: center;
    width: 44px; height: 44px; padding: 0; border: 0; border-radius: 50%;
    background: linear-gradient(135deg, #f472b6, #8b5cf6 55%, #3b82f6); color: #fff;
    box-shadow: 0 4px 14px rgba(139, 92, 246, 0.45);
    cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none;
}
.project-barrage-fab:hover, .project-barrage.open .project-barrage-fab { filter: brightness(1.08); box-shadow: 0 6px 20px rgba(139, 92, 246, 0.6); }
.project-barrage-fab:focus-visible { outline: 2px solid #8b5cf6; outline-offset: 3px; }
.project-barrage.dragging .project-barrage-fab { cursor: grabbing; transform: scale(1.06); }
/* Viewer count: a person icon + number pill under the horn, so it reads as "people here", not unread messages. */
.project-barrage-count {
    position: absolute; bottom: -7px; left: 50%; transform: translateX(-50%);
    display: inline-flex; align-items: center; gap: 2px; height: 14px; padding: 0 5px 0 4px; box-sizing: border-box;
    border-radius: 7px; background: rgba(255, 255, 255, 0.92); color: #6b7280; font-size: 10px; line-height: 14px; white-space: nowrap;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08); pointer-events: none;
}
.project-barrage-count svg { flex-shrink: 0; }
.project-barrage-count[hidden] { display: none; }
.project-barrage-panel {
    position: absolute; bottom: 54px; right: 0; width: min(320px, calc(100vw - 24px)); box-sizing: border-box;
    padding: 12px; border: 1px solid #e5e7eb; border-radius: 12px; background: #fff; color: #111827;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.16);
}
.project-barrage-panel[hidden] { display: none; }
.project-barrage.opens-right .project-barrage-panel { right: auto; left: 0; }
.project-barrage.opens-down .project-barrage-panel { bottom: auto; top: 54px; }
.project-barrage-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; min-width: 0; }
.project-barrage-head strong { flex-shrink: 0; font-size: 14px; }
.project-barrage-viewers { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; color: #6b7280; }
.project-barrage-close {
    flex-shrink: 0; align-self: center; width: 28px; height: 28px; margin: -4px -4px -4px 0; padding: 0;
    border: 0; border-radius: 50%; background: transparent; color: #6b7280; font-size: 20px; line-height: 28px; cursor: pointer;
}
.project-barrage-close:hover { background: rgba(107, 114, 128, 0.12); color: #111827; }
.project-barrage-backdrop { display: none; }
.project-barrage-input {
    display: block; width: 100%; box-sizing: border-box; padding: 8px; resize: none;
    border: 1px solid #d1d5db; border-radius: 8px; font: inherit; font-size: 14px; background: transparent; color: inherit;
}
.project-barrage-input:focus { outline: none; border-color: #8b5cf6; box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.15); }
.project-barrage-actions { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.project-barrage-status { flex: 1; min-width: 0; font-size: 12px; color: #6b7280; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-barrage-actions button { flex-shrink: 0; padding: 6px 12px; border-radius: 8px; font-size: 13px; cursor: pointer; }
.project-barrage-actions button:disabled { opacity: 0.55; cursor: not-allowed; }
.project-barrage-record { border: 1px solid #d1d5db; background: #fff; color: #374151; }
.project-barrage-record.recording { border-color: #ef4444; background: #fef2f2; color: #b91c1c; animation: project-barrage-pulse 1.2s ease-in-out infinite; }
.project-barrage-cancel { border: 1px solid #d1d5db; background: #fff; color: #374151; }
.project-barrage-cancel[hidden] { display: none; }
.project-barrage-send { border: 0; background: linear-gradient(135deg, #ec4899, #8b5cf6); color: #fff; }
@keyframes project-barrage-pulse { 50% { box-shadow: 0 0 0 5px rgba(239, 68, 68, 0.18); } }

/* The floating shouts. */
.project-barrage-stage { position: fixed; inset: 0; z-index: 100050; overflow: hidden; pointer-events: none; }
.project-barrage-item {
    --barrage-color: #a78bfa;
    position: absolute; left: 100%; display: inline-flex; align-items: center; gap: 8px;
    padding: 6px 16px 6px 6px; box-sizing: border-box; white-space: nowrap;
    border-radius: 999px; color: #fff; font-size: 17px; font-weight: 600; letter-spacing: 0.02em;
    background: linear-gradient(90deg, color-mix(in srgb, var(--barrage-color) 85%, #000) 0%, rgba(17, 24, 39, 0.78) 100%);
    border: 1px solid color-mix(in srgb, var(--barrage-color) 70%, #fff);
    box-shadow: 0 0 18px color-mix(in srgb, var(--barrage-color) 60%, transparent), inset 0 0 12px rgba(255, 255, 255, 0.12);
    text-shadow: 0 0 8px color-mix(in srgb, var(--barrage-color) 80%, #fff), 0 1px 2px rgba(0, 0, 0, 0.6);
    animation: project-barrage-fly linear forwards; will-change: transform;
}
/* A comet tail trailing to the right. */
.project-barrage-item::after {
    content: ""; position: absolute; top: 50%; left: 100%; width: 120px; height: 60%; transform: translateY(-50%);
    border-radius: 0 999px 999px 0; pointer-events: none;
    background: linear-gradient(90deg, color-mix(in srgb, var(--barrage-color) 55%, transparent), transparent);
    filter: blur(4px);
}
/* A light sweep across the pill. */
.project-barrage-item::before {
    content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
    background: linear-gradient(110deg, transparent 30%, rgba(255, 255, 255, 0.35) 45%, transparent 60%);
    background-size: 250% 100%; animation: project-barrage-shine 2.4s linear infinite;
}
.project-barrage-item.self { opacity: 0.85; }
.project-barrage-item.playable { pointer-events: auto; cursor: pointer; }
.project-barrage-item.playable:hover { animation-play-state: paused; }
.project-barrage-item.needs-tap { outline: 2px dashed rgba(255, 255, 255, 0.8); outline-offset: 2px; }
.project-barrage-avatar {
    flex-shrink: 0; display: flex; align-items: center; justify-content: center; width: 32px; height: 32px;
    border-radius: 50%; background: var(--barrage-color); color: #fff; font-size: 15px; text-shadow: none;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.85), 0 0 12px var(--barrage-color);
}
.project-barrage-name { flex-shrink: 0; font-size: 13px; font-weight: 500; opacity: 0.85; }
.project-barrage-name::after { content: "："; }
/* Never clipped: a long shout makes a longer pill that just takes longer to cross. */
.project-barrage-text { flex-shrink: 0; }
.project-barrage-wave { display: inline-flex; align-items: center; gap: 2px; height: 16px; flex-shrink: 0; }
.project-barrage-wave i { display: block; width: 3px; height: 30%; border-radius: 2px; background: #fff; }
.project-barrage-item.speaking .project-barrage-wave i { animation: project-barrage-wave 0.9s ease-in-out infinite; }
.project-barrage-item.speaking .project-barrage-wave i:nth-child(2) { animation-delay: 0.15s; }
.project-barrage-item.speaking .project-barrage-wave i:nth-child(3) { animation-delay: 0.3s; }
.project-barrage-item.speaking .project-barrage-wave i:nth-child(4) { animation-delay: 0.45s; }
@keyframes project-barrage-fly {
    0% { transform: translateX(0) scale(0.92); opacity: 0; }
    4% { opacity: 1; transform: translateX(calc(var(--barrage-distance) * 0.04)) scale(1); }
    96% { opacity: 1; }
    100% { transform: translateX(var(--barrage-distance)); opacity: 0; }
}
@keyframes project-barrage-shine { from { background-position: 150% 0; } to { background-position: -100% 0; } }
@keyframes project-barrage-wave { 0%, 100% { height: 30%; } 50% { height: 100%; } }
/* Phones and touch tablets (iPad) pop a soft keyboard over the page, so there the panel is a
   bottom sheet that rides above the keyboard, with a tap-to-close backdrop. */
@media (max-width: 768px), (hover: none) and (pointer: coarse) {
    .project-barrage-backdrop:not([hidden]) { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.32); }
    .project-barrage-panel, .project-barrage.opens-right .project-barrage-panel, .project-barrage.opens-down .project-barrage-panel {
        position: fixed; top: auto; left: 8px; right: 8px; bottom: calc(var(--barrage-keyboard, 0px) + 8px + env(safe-area-inset-bottom, 0px));
        width: auto; max-width: 560px; margin: 0 auto; max-height: calc(100dvh - var(--barrage-keyboard, 0px) - 16px); overflow-y: auto;
    }
    .project-barrage-input { font-size: 16px; }
    .project-barrage-actions button { padding: 8px 14px; }
}
@media (max-width: 768px) {
    .project-barrage-input { font-size: 16px; }
    .project-barrage-close { width: 36px; height: 36px; line-height: 36px; font-size: 24px; }
    .project-barrage-item { font-size: 15px; }
    .project-barrage-avatar { width: 28px; height: 28px; font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) {
    .project-barrage-item::before, .project-barrage-record.recording { animation: none; }
}

html[data-theme] .project-barrage-panel { border-color: var(--cf-line); background: var(--cf-raised); color: var(--cf-text); box-shadow: var(--cf-shadow-pop); }
html[data-theme] .project-barrage-viewers, html[data-theme] .project-barrage-status { color: var(--cf-text-2); }
html[data-theme] .project-barrage-close { color: var(--cf-text-2); }
html[data-theme] .project-barrage-close:hover { color: var(--cf-text); }
html[data-theme] .project-barrage-input { border-color: var(--cf-line-strong); }
html[data-theme] .project-barrage-record, html[data-theme] .project-barrage-cancel { border-color: var(--cf-line-strong); background: transparent; color: var(--cf-text); }
.project-barrage-item.play-failed { outline: 2px dotted rgba(255, 180, 180, 0.85); outline-offset: 2px; }
