/* ═══════════════════════════════════════════════════════════════
   SPEAKR — chat styles
   Shared by lobby and room (chat drawer).
   Includes: message bubbles, chat strip input, emoji picker.
   ═══════════════════════════════════════════════════════════════ */

/* ── Chat tab bar (Global / User) ──
   Used standalone only in the 'centred' layout (elsewhere the dm-dock's own
   header is the switcher). Styled to MATCH .dm-head / .dm-tab so the top bar
   reads identically across every layout: same header tint, same blue-pill
   active tabs. */
.chat-tab-bar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 9px 13px;
    background: rgba(255,255,255,0.035);
    border-bottom: 1px solid rgba(255,255,255,0.06);
    flex-shrink: 0;
}
.chat-tab {
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 0.73rem;
    font-family: "Exo 2", sans-serif;
    font-weight: 500;
    color: var(--text-secondary);
    background: none;
    border: none;
    cursor: pointer;
    line-height: 1;
    transition: background 0.12s, color 0.12s;
}
.chat-tab:hover { background: rgba(255,255,255,0.07); color: var(--text-primary); }
.chat-tab.active {
    background: var(--deep-blue);
    color: #fff;
}
/* Globe = the Global channel, pushed to the right of the bar to mirror the
   dm-dock header (where the globe sits at the far right). */
.chat-tab-globe {
    margin-left: auto;
    padding: 4px 7px;
    line-height: 0;
}
.chat-tab-globe svg { width: 16px; height: 16px; display: block; }
/* Global and User are two DISTINCT panes — each owns its own DOM, so there's
   no cross-channel message hiding. The active tab just shows its pane. Keeping
   them as separate elements (.chat-pane-global / .chat-pane-user) also means
   global can be restyled independently without touching user chat. */
#chat-area[data-chat-tab="global"] .chat-pane-user   { display: none; }
#chat-area[data-chat-tab="user"]   .chat-pane-global { display: none; }

/* Call tab active — badge on Global tab when global messages arrive during a call */
.chat-tab .chat-tab-badge {
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--primary); color: #04222b;
    font-size: 0.66rem; font-weight: 700;
    min-width: 16px; height: 16px; border-radius: 8px;
    margin-left: 5px; padding: 0 3px;
    line-height: 1;
}
.chat-tab .chat-tab-badge.hidden { display: none; }

/* ── Message bubbles ── */
.chat-message {
    display: flex;
    flex-direction: row;
    pointer-events: auto;
    padding: 2px 0;
}
.chat-message.mine   { justify-content: flex-end; }
.chat-message.theirs { justify-content: flex-start; }
.chat-message.system { justify-content: center; }

.message-content {
    max-width: 72%;
    padding: 8px 12px;
    border-radius: 16px;
    font-size: 0.84rem;
    line-height: 1.4;
    word-break: break-word;
}

/* Own messages: flat text on the right, marked by a faint full-width band
   (a translucent take on the old deep-blue 'mine' bubble) rather than a
   contained bubble. Partner messages are flat text too — matches global. */
.chat-message.mine {
    /* Faint deep-blue, concentrated on the right and fading to nothing by the
       left edge — no bubble, no rounded corners. The 5px right padding insets
       the content off the gradient's strong edge. */
    background: linear-gradient(to left, rgba(28, 72, 112, 0.3), transparent);
    padding-right: 5px;
}
.chat-message.mine .message-content {
    background: none;
    color: var(--text-primary);
    text-align: right;
    border-radius: 0;
    padding: 3px 4px;
    max-width: 82%;
}

.chat-message.theirs .message-content {
    background: none;
    color: var(--text-primary);
    border-radius: 0;
    padding: 3px 4px;
    max-width: 82%;
}

.chat-message.system .message-content {
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-style: italic;
    padding: 2px 8px;
    max-width: 100%;
}
/* Coloured intro lines: the icebreaker reads ice-blue; the new/guest/level
   identity line reads peach. Everything else stays muted. */
.chat-message.system.ice .message-content         { color: #9bdcff; }
.chat-message.system.intro-peach .message-content { color: #ff9a52; }

/* Post-call rating notifications — opt-in via .rating-msg span passed in
   from rate.js. Bigger, not italic, semantic colour. Keeps subtle system
   lines (mic on/off, etc.) at the default look. */
.chat-message.system .rating-msg {
    font-size: 0.85rem;
    font-style: normal;
    font-weight: 500;
    line-height: 1.45;
    display: inline-block;
    padding: 4px 2px;
}
.chat-message.system .rating-msg.positive { color: #4ade80; }
.chat-message.system .rating-msg.negative { color: #fbbf24; }
.chat-message.system .rating-msg a {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.chat-message.system .rating-msg a:hover { opacity: 0.85; }

/* Links inside any chat bubble — white + subtle underline so they read
   cleanly against the deep blue (mine) and coral (theirs) bubbles. The
   existing .chat-message.system .rating-msg a rule overrides via higher
   specificity for the post-call rating system lines. */
.chat-message a {
    color: #fff;
    text-decoration: underline;
    text-underline-offset: 2px;
    transition: color 0.15s;
}
.chat-message a:hover { color: var(--primary); }

.message-content.emoji-only {
    background: transparent;
    font-size: 4.6rem;
    line-height: 1.1;
    padding: 2px 4px;
}

.message-image {
    max-width: 100%;
    max-height: 200px;
    border-radius: 10px;
    display: block;
    cursor: pointer;
}

/* ── Music file shared P2P during a call ──────────────────────────────────
   "Rainbow" player — markup + look nicked from the therob.lol html5 skin,
   adapted to sit in the dark chat bubble. Custom controls drive a hidden
   <audio> (see chat.js _wireAudioPlayer). ── */
.message-audio {
    display: flex;
    flex-direction: column;
    gap: 7px;
    min-width: 240px;
    max-width: 300px;
}
.chat-message.mine .message-audio { margin-left: auto; }   /* follow right-aligned own messages */
.message-audio-name {
    font-size: 0.82rem;
    font-weight: 600;
    /* inherits the bubble's --text-primary; truncate long names with an ellipsis */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}
.snd-rainbow .snd-controls {
    display: flex;
    align-items: center;
    height: 40px;
    padding: 7px 12px;
    box-sizing: border-box;
    border-radius: 9px;
    background: linear-gradient(45deg, #ff6b6b, #ffd93d, #6bcf7f, #4ecdc4, #4e89ae, #a77dc2);
    background-size: 300% 300%;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.25);
}
/* The signature animated rainbow — only while it's actually playing. */
.snd-rainbow.playing .snd-controls { animation: snd-rainbow-shift 4s ease-in-out infinite; }
@keyframes snd-rainbow-shift {
    0%   { background-position: 0% 50%; }
    50%  { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}
.snd-rainbow .snd-play-btn {
    flex: 0 0 auto;
    width: 20px;
    height: 20px;
    margin: 0 8px 0 0;
    padding: 0;
    border: none;
    background: none;
    color: #1a1a1a;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease;
}
.snd-rainbow .snd-play-btn:hover { transform: scale(1.12); color: #000; }
.snd-rainbow .snd-play-btn .ico-pause { display: none; }
.snd-rainbow.playing .snd-play-btn .ico-play  { display: none; }
.snd-rainbow.playing .snd-play-btn .ico-pause { display: block; }
.snd-rainbow .snd-progress {
    flex: 1;
    height: 6px;
    margin: 0 8px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.55);
    cursor: pointer;
    position: relative;
    touch-action: none;
}
.snd-rainbow .snd-progress-bar {
    height: 100%;
    width: 0%;
    border-radius: 3px;
    background: #1a1a1a;
    transition: width 0.1s linear;
}
.snd-rainbow .snd-progress-handle {
    position: absolute;
    top: 50%;
    left: 0;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid #1a1a1a;
    transform: translate(-50%, -50%);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
    opacity: 0;
    transition: opacity 0.15s ease;
}
.snd-rainbow .snd-progress:hover .snd-progress-handle,
.snd-rainbow .snd-progress.seeking .snd-progress-handle { opacity: 1; }
.snd-rainbow .snd-time {
    flex: 0 0 auto;
    min-width: 38px;
    text-align: right;
    font-size: 11px;
    font-weight: 600;
    color: #1a1a1a;
    font-variant-numeric: tabular-nums;
}
.snd-rainbow .snd-audio { display: none; }

/* ── Full-size image lightbox ── */
.chat-lightbox {
    position: fixed;
    inset: 0;
    z-index: 5000;
    background: rgba(0, 0, 0, 0.88);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
    cursor: zoom-out;
    animation: chat-lightbox-fade 0.15s ease-out;
    /* Pinch/drag are handled in JS (zoom + pan) — without this the
       browser eats the gestures as page-zoom/scroll. */
    touch-action: none;
    overflow: hidden;
}
.chat-lightbox.hidden { display: none; }
@keyframes chat-lightbox-fade {
    from { opacity: 0; }
    to   { opacity: 1; }
}
.chat-lightbox-img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
    cursor: default;
    will-change: transform;
    user-select: none;
    -webkit-user-select: none;
}
.chat-lightbox-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s;
}
.chat-lightbox-close:hover { background: rgba(255, 255, 255, 0.22); }

/* ── Chat strip (text input row) ── */
.chat-strip {
    position: relative;
    height: 52px;
    background: rgba(255,255,255,0.02);
    border-top: 1px solid rgba(255,255,255,0.07);
    display: flex;
    align-items: center;
    padding: 0 8px;
    gap: 5px;
    flex-shrink: 0;
}

.chat-text-input {
    flex: 1;
    min-width: 0;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    padding: 8px 12px;
    color: var(--text-primary);
    /* Integer px, NOT rem: 0.88rem (=14.08px) made Chrome-on-Android paint the
       caret stuck on the first character while typing (looked like typing
       backwards) when the strip is keyboard-flush. Bisected via /caret-test/ —
       the fractional computed font-size is the trigger; 14px/16px are clean. */
    font-size: 14px;
    font-family: "Exo 2", sans-serif;
    outline: none;
    transition: border-color 0.18s;
}
.chat-text-input:focus { border-color: rgba(255,255,255,0.22); background: rgba(255,255,255,0.07); }
.chat-text-input::placeholder { color: rgba(255,255,255,0.34); }
.chat-text-input.drag-over {
    border-color: rgba(255,255,255,0.3);
    background: rgba(255,255,255,0.08);
}

.chat-icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.09);
    color: var(--text-secondary);
    font-size: 0.95rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.14s, border-color 0.14s, color 0.14s;
    flex-shrink: 0;
}
.chat-icon-btn:hover { background: rgba(255,255,255,0.10); border-color: rgba(255,255,255,0.16); color: var(--text-primary); }
/* Toggled-on state for the admin stats button (📊). */
.chat-icon-btn.active {
    background: rgba(74, 222, 128, 0.25);
    color: #fff;
    border-color: rgba(74, 222, 128, 0.5);
}

/* Emoji picker — plain white outline smiley (SVG), not the colour glyph. */
.chat-emoji-btn { color: #fff; }
.chat-emoji-btn svg { width: 23px; height: 23px; display: block; }

/* Send button — white arrow on a subtle dark fill, no teal. */
.chat-send-btn { color: var(--text-primary); }
.chat-send-btn:hover { background: rgba(255,255,255,0.14); border-color: rgba(255,255,255,0.2); color: #fff; }

/* ── Unread badge (used by both pages, positioned by page-specific CSS) ── */
.unread-badge {
    background: var(--danger);
    color: #fff;
    border-radius: 50%;
    min-width: 18px;
    height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0 5px;
}

/* ── Emoji picker (anchored above chat strip) ── */
.emoji-picker {
    position: absolute;
    bottom: calc(100% + 8px);
    right: 48px;
    width: 300px;
    max-height: 200px;
    overflow-y: auto;
    background: var(--dark-panel);
    border: 1px solid var(--dark-border);
    border-radius: var(--radius);
    padding: 10px;
    z-index: 500;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
}

.emoji-item {
    background: none;
    border: none;
    font-size: calc(1.2rem + 2px);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: background 0.15s;
    line-height: 1;
}
.emoji-item:hover { background: rgba(255,255,255,0.1); }

/* Connect avatars — you + your partner pop in (small → large) at the top of the
   call chat the moment a call connects, before any text. */
.chat-connect-avatars {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    padding: 16px 0 18px;
}
.cca-av {
    width: 66px;
    height: 66px;
    border-radius: 50%;
    overflow: hidden;
    background: #161a26;
    flex-shrink: 0;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
    transform: scale(0.15);
    opacity: 0;
    animation: ccaPop 0.55s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
.cca-av:nth-child(2) { animation-delay: 0.14s; }   /* partner lands a beat after you */
.cca-av img, .cca-av svg { width: 100%; height: 100%; display: block; object-fit: cover; }
@keyframes ccaPop {
    0%   { transform: scale(0.15); opacity: 0; }
    100% { transform: scale(1);    opacity: 1; }
}

/* Bio messages — italic, slightly muted */
/* Partner bio intro — "in their own words:" label (regular font, like the
   bio text) over a literal ASCII box. No background, no rounded box. */
.bio-intro { text-align: left; max-width: 94%; }
/* Partner avatar + label share one line above the bio box. */
.bio-intro-head { display: flex; align-items: center; gap: 7px; margin-bottom: 4px; }
.bio-intro-avatar { flex: 0 0 auto; width: 26px; height: 26px; border-radius: 50%; overflow: hidden; background: #161a26; }
.bio-intro-avatar .av-img { width: 100%; height: 100%; display: block; }
.bio-intro-label {
    font-family: "Exo 2", sans-serif;
    font-size: 0.82rem;
    color: var(--text-secondary);
}
.bio-intro-box {
    font-family: 'Space Mono', ui-monospace, monospace;
    font-size: 0.72rem;
    line-height: 1.25;
    color: var(--text-primary);
    margin: 0;
    white-space: pre;
    /* No overflow scroller — the column count is measured to fit, so the box
       never exceeds the chat column (a few words = small box; lots = full). */
    overflow: visible;
}

/* Flag emoji shown on partner connect — large, centered, no bubble */
.message-content.flag {
    background: transparent;
    font-size: 3.6rem;
    line-height: 1;
    padding: 6px 0;
    text-align: center;
    text-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
    animation: jamFlagPop 0.5s ease-out;
}

@keyframes jamFlagPop {
    0%   { transform: scale(0.4); opacity: 0; }
    60%  { transform: scale(1.15); opacity: 1; }
    100% { transform: scale(1); }
}

/* ── Global lobby chat ── */
/* Global messages render with a sender header above the content so you can
   see who said what — peer chat doesn't need this because there are only
   two people. Stacked vertically (header + bubble) instead of just a bubble. */
.chat-message.global {
    flex-direction: column;
    /* Group start: a hairline divider between senders + breathing room. A
       continuation (.cont) from the same sender drops both so a run of
       messages reads as one block (Discord/Slack style). */
    padding: 7px 2px 2px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}
.chat-message.global:first-child { border-top: none; }
.chat-message.global.cont {
    border-top: none;
    padding-top: 1px;
}
.chat-message.global.mine   { align-items: flex-end; }
.chat-message.global.theirs { align-items: flex-start; }

.global-msg-head {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0 2px 2px;
    font-size: 0.7rem;
    color: var(--text-secondary);
    max-width: 100%;
}
/* Sender avatar on the group head — server-rendered SVG by user id. */
.global-msg-av { flex-shrink: 0; line-height: 0; }
.global-msg-av .av-img {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(255,255,255,0.06);
    display: block;
}
.global-msg-time {
    font-size: 0.66rem;
    color: var(--text-secondary);
    opacity: 0.65;
    flex-shrink: 0;
}
.global-msg-name {
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 160px;
}
.global-msg-level,
.global-msg-guest {
    font-size: 0.62rem;
    line-height: 1;
    padding: 2px 6px;
    border-radius: 999px;
    text-transform: lowercase;
    letter-spacing: 0.02em;
    flex-shrink: 0;
}
.global-msg-level {
    background: rgba(155, 89, 220, 0.18);
    color: #c9a8ff;
    border: 1px solid rgba(155, 89, 220, 0.3);
}
.global-msg-guest {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-secondary);
    border: 1px solid rgba(255, 255, 255, 0.16);
    text-transform: lowercase;
}
/* Star/crown rank — gold stars (the 👑 emoji is self-colored). Sits inline
   right after a username (chat, profile) or leading the partner-hint pill. */
.av-rank {
    color: #ffd24a;
    letter-spacing: 1px;
    font-size: 0.82em;
    white-space: nowrap;
    vertical-align: baseline;
}
/* Daily-call streak pill — 🔥 + day count, orange. Orthogonal to rank. */
.av-streak {
    display: inline-flex;
    align-items: center;
    gap: 1px;
    font-size: 0.72em;
    font-weight: 700;
    color: #ffb86b;
    background: rgba(255, 138, 0, 0.14);
    border: 1px solid rgba(255, 138, 0, 0.35);
    border-radius: 999px;
    padding: 0 5px;
    line-height: 1.5;
    white-space: nowrap;
    vertical-align: middle;
}
/* Profile-only "X to next level" progress bar under the level row. */
.level-progress { margin-top: 6px; max-width: 220px; }
.level-progress-track {
    height: 5px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    overflow: hidden;
}
.level-progress-track span {
    display: block;
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--primary, #22d3ee), #ffd24a);
}
.level-progress-label {
    margin-top: 4px;
    font-size: 0.7rem;
    color: var(--text-secondary, #9aa0aa);
}
/* Profile achievement badges — earned only (no locked/greyed placeholders). */
.profile-achievements { margin-top: 10px; }
.ach-head {
    display: flex; align-items: center; gap: 6px;
    font-size: 0.78rem; color: var(--text-secondary, #9aa0aa); margin-bottom: 6px;
}
.ach-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.ach {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 8px; border-radius: 999px;
    font-size: 0.72rem; border: 1px solid transparent;
}
.ach.earned {
    background: rgba(34, 211, 238, 0.12); color: #a5f3fc;
    border-color: rgba(34, 211, 238, 0.3);
}
.ach-emoji { font-size: 0.85rem; line-height: 1; }
.ach-best { margin-top: 8px; font-size: 0.74rem; color: #ffb86b; }

/* Bubble — same blue / peach as peer chat so global feels native to the
   panel. The sender header above the bubble is what distinguishes "this is
   from a stranger in the lobby" from "this is from my current call partner". */
.chat-message.global .message-content {
    max-width: 100%;
    font-size: 0.875rem;
    line-height: 1.45;
    word-break: break-word;
    padding: 1px 2px;
    background: none;
    border-radius: 0;
    color: var(--text-primary);
}
/* On phones the chat strip is narrow and the sender header above the bubble
   eats horizontal space; 72% causes early wraps. Give the bubble more room. */
@media (max-width: 600px) {
    .chat-message.global.mine .message-content { max-width: 90%; }
    /* Smaller ASCII bio box on phones so it never needs a scrollbar. */
    .bio-intro-box { font-size: 0.66rem; }
}
/* Own messages: flat text on the right, marked by a faint full-width band
   (translucent deep-blue) rather than a contained bubble. Everyone else's
   are flat text too — the feed reads clean + dense, like the reference. */
.chat-message.global.mine {
    background: linear-gradient(to left, rgba(28, 72, 112, 0.3), transparent);
    /* 5px right padding insets the whole column — header, text and reactions
       all shift left together, off the gradient's strong edge. */
    padding-right: 5px;
}
.chat-message.global.mine .message-content {
    max-width: 80%;
    padding: 1px 2px;
    background: none;
    color: var(--text-primary);
    border-radius: 0;
    text-align: right;
}
.chat-message.global.theirs .message-content {
    background: none;
    color: var(--text-primary);
    border-radius: 0;
    padding: 1px 2px;
}
/* Emoji-only lines stand alone (no box), a touch larger than text. */
.chat-message.global .message-content.emoji-only {
    font-size: 2rem;
    line-height: 1.15;
    padding: 1px 2px;
    background: none;
}

/* IRC-style /me action — third-person narration centered, no bubble.
   Reactions still appear below via the standard strip. */
.chat-message.global.action {
    align-items: center;
}
.global-msg-action {
    font-style: italic;
    font-size: 0.84rem;
    color: var(--text-secondary);
    line-height: 1.4;
    max-width: 84%;
    padding: 2px 8px;
    text-align: center;
    word-break: break-word;
}
.global-msg-action::before {
    content: '* ';
    opacity: 0.6;
    margin-right: 1px;
}
.global-msg-action .global-msg-name {
    font-style: normal;
    font-weight: 600;
    margin-right: 0.35em;
}
.global-msg-action-text { font-style: italic; }

/* ── Reactions (Signal-style) ── */
/* One shared box holds every reaction. The box (not each emoji) carries the
   dark-gray background + border + radius; it grows to fit each emoji and wraps
   only when it hits its max-width. Sits flush under the bubble (no top gap). */
/* Each reaction is its own bordered pill (separate boxes), in a flex row. */
.reaction-strip {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 5px;
    margin: 4px 2px 1px;
    max-width: 100%;
    padding: 0;
    background: none;
    border: 0;
}
.chat-message.global.mine   .reaction-strip { align-self: flex-end; }
.chat-message.global.theirs .reaction-strip { align-self: flex-start; }

/* Each emoji+count is a transparent clickable segment INSIDE the shared box —
   no own background/border. Hover + the "mine" flag get a subtle inset wash so
   you can still tell which segment removes your reaction on tap. */
.reaction-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.14);
    color: var(--text-primary);
    font-size: 0.78rem;
    line-height: 1.4;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s, transform 0.12s;
}
.reaction-chip:hover { background: rgba(255, 255, 255, 0.1); border-color: rgba(255, 255, 255, 0.22); }
.reaction-chip.mine {
    background: rgba(var(--primary-rgb), 0.16);
    border-color: rgba(var(--primary-rgb), 0.5);
}
.reaction-chip.mine:hover { background: rgba(var(--primary-rgb), 0.24); }
.reaction-chip-emoji { font-size: 0.95rem; line-height: 1; }
.reaction-chip-count { font-weight: 600; opacity: 0.9; }

/* Pulse when a chip first lands — draws the author's eye to the right side
   where their own message lives (otherwise easy to miss when typing). */
.reaction-chip.chip-pop {
    animation: reaction-chip-pop 0.45s cubic-bezier(.18,.89,.32,1.28);
}
@keyframes reaction-chip-pop {
    0%   { transform: scale(0.4); opacity: 0; }
    60%  { transform: scale(1.25); opacity: 1; }
    100% { transform: scale(1); }
}

/* Floating picker — appears above the bubble on long-press / right-click. */
/* Sender username is a moderation affordance for admins/mods — the feed
   gets .mod-enabled and the names become clickable (popover with delete /
   ban / ban IP). Regular users see plain colored names, no pointer. */
.mod-enabled .global-msg-name {
    cursor: pointer;
}
.mod-enabled .global-msg-name:hover {
    text-decoration: underline;
    text-underline-offset: 2px;
}

/* Moderation popover — opened from a username. Vertical button stack,
   same dark surface language as the reaction picker. */
.mod-popover {
    position: fixed;
    z-index: 1600;
    display: flex;
    flex-direction: column;
    min-width: 150px;
    padding: 6px;
    background: rgba(15, 23, 42, 0.97);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(6px);
    animation: reaction-picker-in 0.12s ease-out;
}
.mod-popover.hidden { display: none; }
.mod-popover-head {
    padding: 4px 8px 6px;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.mod-popover-btn {
    background: transparent;
    border: 0;
    color: var(--text-primary);
    text-align: left;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.82rem;
    transition: background 0.12s, color 0.12s;
}
.mod-popover-btn:hover { background: rgba(255, 255, 255, 0.08); }
.mod-popover-danger { color: #f87171; }
.mod-popover-danger:hover { background: rgba(248, 113, 113, 0.18); color: #fff; }

.reaction-picker {
    position: fixed;
    z-index: 1500;
    width: max-content;
    max-width: calc(100vw - 16px);
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    background: rgba(15, 23, 42, 0.96);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 24px;          /* pill when it's just the quick row, card when expanded */
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(6px);
    overflow: hidden;
    transform-origin: 50% 100%;
    animation: reaction-picker-in 0.14s ease-out;
}
.reaction-picker.hidden {
    display: none;
}
/* Quick pill row — the few common emoji + ＋ + Reply/Delete actions. */
.rp-quick {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px;
}
.rp-more-btn {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-secondary);
}
/* Full grid — collapsed to 0 height until ＋ adds .expanded, then slides open. */
.rp-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    padding: 0 6px;
    transition: max-height 0.22s ease, opacity 0.18s ease, padding 0.22s ease;
}
.reaction-picker.expanded .rp-grid {
    max-height: 196px;
    opacity: 1;
    overflow-y: auto;
    padding: 6px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.reaction-picker-btn {
    width: 36px;
    height: 36px;
    border: 0;
    background: transparent;
    color: inherit;
    font-size: 1.35rem;
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.12s, transform 0.12s;
    line-height: 1;
}
.reaction-picker-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(1.2);
}
@keyframes reaction-picker-in {
    from { opacity: 0; transform: scale(0.6); }
    to   { opacity: 1; transform: scale(1); }
}

/* Separator between the emoji row and the action buttons (Reply, Delete). */
.reaction-picker-sep {
    width: 1px;
    align-self: stretch;
    background: rgba(255, 255, 255, 0.12);
    margin: 4px 4px;
}
.reaction-action-btn {
    font-size: 1.05rem;
    color: var(--text-secondary);
}
.reaction-action-btn.delete-action {
    color: #f87171;
}
.reaction-action-btn.delete-action:hover {
    background: rgba(248, 113, 113, 0.18);
    color: #fff;
}
.reaction-action-btn.hidden { display: none; }

/* ── Reply preview (above chat input) ── */
.reply-preview {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    margin: 0 8px;
    background: rgba(var(--primary-rgb), 0.08);
    border-left: 3px solid var(--primary);
    border-radius: 6px;
    font-size: 0.78rem;
}
.reply-preview.hidden { display: none; }
.reply-preview-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
    overflow: hidden;
}
.reply-preview-label {
    color: var(--text-secondary);
    font-size: 0.7rem;
}
.reply-preview-label strong { color: var(--text-primary); }
.reply-preview-text {
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.reply-preview-close {
    background: transparent;
    border: 0;
    color: var(--text-secondary);
    font-size: 1rem;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    line-height: 1;
}
.reply-preview-close:hover { background: rgba(255, 255, 255, 0.08); color: var(--text-primary); }

/* ── Quoted reply inside a message bubble ── */
/* Same visual language as the reply-preview strip above the chat input: cyan
   tint + left border + small label. Keeps the "this is a reply" affordance
   consistent between "I'm composing a reply" and "I see a reply someone sent". */
.global-msg-quote {
    display: flex;
    flex-direction: column;
    gap: 1px;
    margin: 0 2px 4px;
    padding: 4px 10px;
    background: rgba(var(--primary-rgb), 0.10);
    border-left: 3px solid var(--primary);
    border-radius: 0 6px 6px 0;
    max-width: 72%;
    text-align: left;
    cursor: pointer;
    border-top: 0;
    border-right: 0;
    border-bottom: 0;
    font: inherit;
    color: inherit;
    transition: background 0.12s;
}
.global-msg-quote:hover { background: rgba(var(--primary-rgb), 0.18); }
.global-msg-quote-name {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--primary);
}
.global-msg-quote-text {
    font-size: 0.78rem;
    color: var(--text-primary);
    opacity: 0.85;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Swipe-to-reply visual feedback ── */
.chat-message.global { transition: transform 0.18s ease-out; }
.chat-message.global.swipe-ready {
    /* Small cyan glow on the left edge once swipe has crossed the trigger
       threshold — feedback that releasing will enter reply mode. */
    box-shadow: -4px 0 0 0 var(--primary);
}

/* Flash highlight when a reply-quote click scrolls to the original. */
.chat-message.global.flash-highlight .message-content {
    animation: msg-flash 1.5s ease-out;
}
@keyframes msg-flash {
    0%   { box-shadow: 0 0 0 0 rgba(var(--primary-rgb), 0.6); }
    35%  { box-shadow: 0 0 0 6px rgba(var(--primary-rgb), 0.35); }
    100% { box-shadow: 0 0 0 0 rgba(var(--primary-rgb), 0); }
}

/* ── Typing indicator (in-call peer chat — Signal-style) ──────────────────
   Appended last in #chat-messages-user when the partner is typing; removed
   on their next message, on stop, or via a safety timeout. */
.typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    width: fit-content;
    margin: 4px 0 6px;
    padding: 9px 13px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--dark-border);
    border-radius: 14px 14px 14px 4px;
}
.typing-indicator span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-secondary);
    animation: typing-bounce 1.3s infinite ease-in-out;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.18s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.36s; }
@keyframes typing-bounce {
    0%, 60%, 100% { transform: translateY(0);    opacity: 0.45; }
    30%           { transform: translateY(-4px); opacity: 1; }
}

/* ── Capacitor in-app attach gallery (Android wrap only) ───────────── */
.cap-attach-sheet { display: contents; }
.cap-attach-sheet.hidden .cap-attach-backdrop,
.cap-attach-sheet.hidden .cap-attach-panel { display: none; }

.cap-attach-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 900;
}
.cap-attach-panel {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 901;
    height: 55vh;
    background: #1a1a2e;
    border-top: 1px solid rgba(255,255,255,0.1);
    border-radius: 18px 18px 0 0;
    padding: 8px 0 env(safe-area-inset-bottom);
    display: flex;
    flex-direction: column;
    animation: sheet-up 0.22s ease;
}
@keyframes sheet-up {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
}
.cap-attach-tabs {
    display: flex;
    gap: 4px;
    padding: 4px 12px 8px;
    flex: 0 0 auto;
}
.cap-attach-tab {
    flex: 1;
    padding: 9px 0;
    background: none;
    border: none;
    border-radius: 10px;
    color: rgba(255,255,255,0.5);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.cap-attach-tab.active {
    background: rgba(255,255,255,0.08);
    color: #e0e0f0;
}
.cap-attach-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.cap-attach-body.hidden { display: none; }
.cap-attach-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 3px;
    padding: 0 3px;
}
.cap-attach-cell {
    position: relative;
    aspect-ratio: 1;
    padding: 0;
    border: none;
    border-radius: 6px;
    overflow: hidden;
    background: rgba(255,255,255,0.05);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.cap-attach-cell img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.cap-attach-cell.busy { opacity: 0.4; }
.cap-attach-cam {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    background: rgba(255,255,255,0.08);
}
.cap-attach-list {
    display: flex;
    flex-direction: column;
    padding: 0 8px;
}
.cap-attach-row {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    padding: 12px 14px;
    background: none;
    border: none;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    color: #e0e0f0;
    text-align: left;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.cap-attach-row:active { background: rgba(255,255,255,0.07); }
.cap-attach-row.busy { opacity: 0.4; }
.cap-attach-row-name {
    font-size: 0.95rem;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.cap-attach-row-meta {
    font-size: 0.78rem;
    color: rgba(255,255,255,0.4);
}
.cap-attach-empty {
    grid-column: 1 / -1;
    padding: 32px 16px;
    text-align: center;
    color: rgba(255,255,255,0.4);
    font-size: 0.92rem;
}
.cap-attach-banner {
    grid-column: 1 / -1;
    margin: 2px 4px 4px;
    padding: 10px 14px;
    background: rgba(120,90,255,0.16);
    border: 1px solid rgba(120,90,255,0.35);
    border-radius: 10px;
    color: #c9bfff;
    font-size: 0.85rem;
    text-align: left;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.cap-attach-banner:active { background: rgba(120,90,255,0.28); }

/* ── PiP mode (Android floating window) ─────────────────────────────── */
/* The page renders into a ~1/4-size window. Show ONLY the speaker avatar
   (which carries the voice ring + relocated call timer) and hide every
   other control — the buttons don't fit and Android provides its own
   close affordance on the PiP window. */
body.pip-mode nav,
body.pip-mode .side-drawer,
body.pip-mode .chat-drawer,
body.pip-mode .toast-container,
body.pip-mode #cap-attach-sheet { display: none !important; }

/* Lobby: keep .panel-left > .avatar-cluster, drop everything else. */
body.pip-mode .panel-left > :not(.avatar-cluster) { display: none !important; }
body.pip-mode .app-layout > :not(.panel-left) { display: none !important; }
body.pip-mode .app-layout,
body.pip-mode .panel-left {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 100vw;
    height: 100vh;
    margin: 0;
    padding: 0;
}

/* Group room: video grid only. */
body.pip-mode .room-topbar,
body.pip-mode .room-controls { display: none !important; }
