/* ═══════════════════════════════════════════════════════════════════════════
   ChatBucket — visual reboot
   True-black theme, tight typography, modern surface hierarchy.
   No structural changes to the DOM contract — only classes/vars for polish.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── design tokens ─────────────────────────────────────────────────────── */
:root {
    /* True-black surface stack. Every step is neutral (no blue/grey tint). */
    --bg:            #000000;        /* app background — pure black */
    --surface-1:    #000000;         /* chat area                    */
    --surface-2:    #121212;         /* bubbles, inputs              */
    --surface-3:    #1a1a1a;         /* hovered surface              */
    --surface-4:    #242424;         /* raised interactive           */

    --border-1:      #333333;        /* subtle divider — brightened for visibility */
    --border-2:      #484848;        /* clearer divider on hover     */
    --border-3:      #666666;        /* focus                        */

    --text:          #f5f5f5;        /* primary                      */
    --text-2:        #c9c9c9;        /* secondary                    */
    --text-3:        #8f8f8f;        /* tertiary / hints             */
    --text-4:        #545454;        /* placeholder                  */

    --accent:        #ffffff;        /* used sparingly (own bubble text emphasis) */
    --accent-soft:   #e5e5e5;
    --link:          #7db9ff;        /* one blue slice, only for links */

    --danger:        #ff6b6b;
    --success:       #4ade80;
    --warn:          #fbbf24;

    --radius-xs:     6px;
    --radius-sm:     10px;
    --radius-md:     14px;
    --radius-lg:     20px;
    --radius-xl:     28px;
    --radius-pill:   999px;

    --shadow-1:      0 1px 2px rgba(0,0,0,0.6);
    --shadow-2:      0 4px 16px rgba(0,0,0,0.6);
    --shadow-3:      0 8px 32px rgba(0,0,0,0.7);

    --dur-fast:      120ms;
    --dur-med:       200ms;

    /* Own-message bubble — noticeably different so sender/receiver are
       easy to scan at a glance. Still dark, still on-brand. */
    --own-bubble:    #15202b;
    --own-bubble-brd: #3f5a7a;

    --font:          -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter",
                      Roboto, "Helvetica Neue", Arial, sans-serif;

    /* System monospace only — no webfont fetch, matches --font's own
       offline-first reasoning (this app runs over LAN/Tailscale and
       shouldn't depend on an external font CDN being reachable). Used
       sparingly: island time codes and its kind badge, for a hi-fi
       "readout" feel instead of the rest of the UI's proportional type. */
    --font-mono:     ui-monospace, "SF Mono", "Cascadia Code", "Roboto Mono",
                      Menlo, Consolas, "Liberation Mono", monospace;

    /* ── shell / tray shared tokens ─────────────────────────────────────
       Previously redeclared in msg-actions.css and shell-refine.css. Now
       defined ONCE, in the file that owns the token system. The overlay
       layers still reference them via `var()` — nothing changes for them,
       and if any layer ever loads out of order the tokens are still here. */
    --cb-spring:       cubic-bezier(0.16, 1, 0.30, 1);
    --cb-snap:         cubic-bezier(0.34, 1.4, 0.64, 1);
    --cb-exit:         cubic-bezier(0.4, 0, 1, 1);
    --cb-t-micro:      120ms;
    --cb-t-quick:      190ms;
    --cb-t-panel:      280ms;

    /* Pseudo-glass reserved strictly for FLOATING surfaces (tray, dock,
       toasts). Never applied to persistent chrome. */
    --cb-glass:        linear-gradient(180deg, rgba(255,255,255,0.055) 0%,
                                               rgba(255,255,255,0.022) 42%,
                                               rgba(255,255,255,0.008) 100%);
    --cb-smoke:        rgba(10, 10, 10, 0.72);
    --cb-lip:          inset 0 1px 0 rgba(255,255,255,0.10);
    --cb-cast:         0 18px 44px rgba(0,0,0,0.66), 0 2px 10px rgba(0,0,0,0.5);
    --cb-blur:         blur(20px) saturate(155%);
}

/* ── reset ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html, body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    letter-spacing: -0.005em;
    margin: 0;
    padding: 0;
    height: 100dvh;
    overflow: hidden;
}

h1 { margin-top: 0; letter-spacing: -0.02em; }

::selection { background: rgba(255,255,255,0.16); color: var(--accent); }

/* Scrollbars — thin, black, unobtrusive */
* { scrollbar-width: thin; scrollbar-color: #2a2a2a transparent; }
*::-webkit-scrollbar         { width: 8px; height: 8px; }
*::-webkit-scrollbar-track   { background: transparent; }
*::-webkit-scrollbar-thumb   { background: #2a2a2a; border-radius: 4px; }
*::-webkit-scrollbar-thumb:hover { background: #3a3a3a; }

/* ── generic icon system ───────────────────────────────────────────────── */
/* .icon = a <img> tag that shows an SVG. currentColor is monochrome-tinted
   through a filter trick that maps white-on-transparent SVGs to the current
   colour. We render the SVGs as `stroke="currentColor"`, and use a CSS mask
   so the icon inherits the parent's color. Fallback: if the SVG fails to
   load, the alt-text hides gracefully because size stays fixed. */
.icon {
    display: inline-block;
    width: 20px;
    height: 20px;
    background: currentColor;
    -webkit-mask-position: center;
    mask-position: center;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-size: contain;
    mask-size: contain;
    flex-shrink: 0;
    color: var(--text-2);
    transition: color var(--dur-fast) ease, background var(--dur-fast) ease;
}
.icon.sm  { width: 16px; height: 16px; }
.icon.lg  { width: 24px; height: 24px; }
.icon.xl  { width: 32px; height: 32px; }
.icon.close       { -webkit-mask-image: url(/static/icons/close.svg);       mask-image: url(/static/icons/close.svg); }
.icon.copy        { -webkit-mask-image: url(/static/icons/copy.svg);        mask-image: url(/static/icons/copy.svg); }
.icon.check       { -webkit-mask-image: url(/static/icons/check.svg);       mask-image: url(/static/icons/check.svg); }
.icon.play        { -webkit-mask-image: url(/static/icons/play.svg);        mask-image: url(/static/icons/play.svg); }
.icon.file        { -webkit-mask-image: url(/static/icons/file.svg);        mask-image: url(/static/icons/file.svg); }
.icon.video       { -webkit-mask-image: url(/static/icons/video.svg);       mask-image: url(/static/icons/video.svg); }
.icon.attach      { -webkit-mask-image: url(/static/icons/attach.svg);      mask-image: url(/static/icons/attach.svg); }
.icon.send        { -webkit-mask-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjRweCIgdmlld0JveD0iMCAtOTYwIDk2MCA5NjAiIHdpZHRoPSIyNHB4IiBmaWxsPSIjZTNlM2UzIj48cGF0aCBkPSJNMTIwLTE2MHYtNjQwbDc2MCAzMjAtNzYwIDMyMFptODAtMTIwIDQ3NC0yMDAtNDc0LTIwMHYxNDBsMjQwIDYwLTI0MCA2MHYxNDBabTAgMHYtNDAwIDQwMFoiLz48L3N2Zz4K");        mask-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjRweCIgdmlld0JveD0iMCAtOTYwIDk2MCA5NjAiIHdpZHRoPSIyNHB4IiBmaWxsPSIjZTNlM2UzIj48cGF0aCBkPSJNMTIwLTE2MHYtNjQwbDc2MCAzMjAtNzYwIDMyMFptODAtMTIwIDQ3NC0yMDAtNDc0LTIwMHYxNDBsMjQwIDYwLTI0MCA2MHYxNDBabTAgMHYtNDAwIDQwMFoiLz48L3N2Zz4K"); }
.icon.arrow-down  { -webkit-mask-image: url(/static/icons/arrow-down.svg);  mask-image: url(/static/icons/arrow-down.svg); }
.icon.warning     { -webkit-mask-image: url(/static/icons/warning.svg);     mask-image: url(/static/icons/warning.svg); }
/* [FIX] GIF badge icon is inlined as a data-URI (same pattern as .icon.send /
   .icon.edit / .icon.trash). The external /static/icons/gif.svg 404s on some
   deployments, which collapsed the mask to nothing and exposed the cramped
   "GIF" text-chip fallback in the compose bar. Inlining removes the network
   dependency entirely — one less request, zero 404 surface. Slightly wider
   than square (28x20 viewBox) so the rounded badge reads clearly at 20px. */
.icon.gif         { -webkit-mask-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyOCAyMCI+PHJlY3QgeD0iMSIgeT0iMSIgd2lkdGg9IjI2IiBoZWlnaHQ9IjE4IiByeD0iNC41IiBmaWxsPSJub25lIiBzdHJva2U9IiNmZmYiIHN0cm9rZS13aWR0aD0iMi4yIi8+PHRleHQgeD0iMTQiIHk9IjEzLjgiIGZvbnQtZmFtaWx5PSJBcmlhbCxIZWx2ZXRpY2Esc2Fucy1zZXJpZiIgZm9udC1zaXplPSI4IiBmb250LXdlaWdodD0iNzAwIiB0ZXh0LWFuY2hvcj0ibWlkZGxlIiBmaWxsPSIjZmZmIj5HSUY8L3RleHQ+PC9zdmc+"); mask-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyOCAyMCI+PHJlY3QgeD0iMSIgeT0iMSIgd2lkdGg9IjI2IiBoZWlnaHQ9IjE4IiByeD0iNC41IiBmaWxsPSJub25lIiBzdHJva2U9IiNmZmYiIHN0cm9rZS13aWR0aD0iMi4yIi8+PHRleHQgeD0iMTQiIHk9IjEzLjgiIGZvbnQtZmFtaWx5PSJBcmlhbCxIZWx2ZXRpY2Esc2Fucy1zZXJpZiIgZm9udC1zaXplPSI4IiBmb250LXdlaWdodD0iNzAwIiB0ZXh0LWFuY2hvcj0ibWlkZGxlIiBmaWxsPSIjZmZmIj5HSUY8L3RleHQ+PC9zdmc+"); }
.icon.sticker     { -webkit-mask-image: url(/static/icons/sticker.svg);     mask-image: url(/static/icons/sticker.svg); }
.icon.folder      { -webkit-mask-image: url(/static/icons/folder.svg);      mask-image: url(/static/icons/folder.svg); }
.icon.add         { -webkit-mask-image: url(/static/icons/add.svg);         mask-image: url(/static/icons/add.svg); }
.icon.pause       { -webkit-mask-image: url(/static/icons/pause.svg);       mask-image: url(/static/icons/pause.svg); }
.icon.music       { -webkit-mask-image: url(/static/icons/music.svg);       mask-image: url(/static/icons/music.svg); }
.icon.edit  { -webkit-mask-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjRweCIgdmlld0JveD0iMCAwIDI0IDI0IiB3aWR0aD0iMjRweCIgZmlsbD0iI2UzZTNlMyI+PHBhdGggZD0iTTMgMTcuMjVWMjFoMy43NUwxNy44MSA5Ljk0bC0zLjc1LTMuNzVMMyAxNy4yNXpNMjAuNzEgNy4wNGMuMzktLjM5LjM5LTEuMDIgMC0xLjQxbC0yLjM0LTIuMzRhLjk5Ni45OTYgMCAwIDAtMS40MSAwbC0xLjgzIDEuODMgMy43NSAzLjc1IDEuODMtMS44M3oiLz48L3N2Zz4="); mask-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjRweCIgdmlld0JveD0iMCAwIDI0IDI0IiB3aWR0aD0iMjRweCIgZmlsbD0iI2UzZTNlMyI+PHBhdGggZD0iTTMgMTcuMjVWMjFoMy43NUwxNy44MSA5Ljk0bC0zLjc1LTMuNzVMMyAxNy4yNXpNMjAuNzEgNy4wNGMuMzktLjM5LjM5LTEuMDIgMC0xLjQxbC0yLjM0LTIuMzRhLjk5Ni45OTYgMCAwIDAtMS40MSAwbC0xLjgzIDEuODMgMy43NSAzLjc1IDEuODMtMS44M3oiLz48L3N2Zz4="); }
.icon.trash { -webkit-mask-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjRweCIgdmlld0JveD0iMCAwIDI0IDI0IiB3aWR0aD0iMjRweCIgZmlsbD0iI2UzZTNlMyI+PHBhdGggZD0iTTYgMTljMCAxLjEuOSAyIDIgMmg4YzEuMSAwIDItLjkgMi0yVjdINnYxMnpNMTkgNGgtMy41bC0xLTFoLTVsLTEgMUg1djJoMTRWNHoiLz48L3N2Zz4="); mask-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjRweCIgdmlld0JveD0iMCAwIDI0IDI0IiB3aWR0aD0iMjRweCIgZmlsbD0iI2UzZTNlMyI+PHBhdGggZD0iTTYgMTljMCAxLjEuOSAyIDIgMmg4YzEuMSAwIDItLjkgMi0yVjdINnYxMnpNMTkgNGgtMy41bC0xLTFoLTVsLTEgMUg1djJoMTRWNHoiLz48L3N2Zz4="); }

/* When the browser can't resolve the mask-image (very old fallback), the
   .icon renders as an invisible box — the ARIA label still communicates
   the meaning to assistive tech. This is the "fail gracefully" contract. */

/* ── join screen ───────────────────────────────────────────────────────── */
#join-screen {
    max-width: 420px;
    margin: 12vh auto;
    text-align: center;
    padding: 32px 24px;
    background: var(--surface-1);
    border: 1px solid var(--border-1);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-3);
}

#join-screen h1 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 24px;
    letter-spacing: -0.03em;
}

#join-screen input {
    display: block;
    width: 100%;
    margin: 12px 0;
    padding: 12px 14px;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border-2);
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-family: inherit;
    transition: border-color var(--dur-fast) ease, background var(--dur-fast) ease;
}
#join-screen input:focus {
    outline: none;
    border-color: var(--border-3);
    background: var(--surface-3);
}
#join-screen input::placeholder { color: var(--text-4); }

#join-screen button {
    width: 100%;
    padding: 12px;
    margin-top: 6px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-2);
    background: var(--surface-4);
    color: var(--text);
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.01em;
    cursor: pointer;
    transition: background var(--dur-fast) ease, border-color var(--dur-fast) ease, transform var(--dur-fast) ease;
}
#join-screen button:hover  { background: #2e2e2e; border-color: var(--border-3); }
#join-screen button:active { transform: translateY(1px); }

/* ── chat screen ───────────────────────────────────────────────────────── */
#chat-screen {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    width: 100vw;
    max-width: none;
    margin: 0;
    padding: 0;
    background: var(--bg);
}

/* ── header ────────────────────────────────────────────────────────────── */
#header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    background: var(--bg);
    border-bottom: 1px solid var(--border-1);
    flex-shrink: 0;
    position: relative;
    z-index: 5;
}

#chat-logo {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
}

#header h1 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: -0.015em;
    color: var(--text);
}

/* ── messages area ─────────────────────────────────────────────────────── */
#messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 12px 12px;
    background: var(--surface-1);
    border: none;
    border-radius: 0;
    min-height: 0;
    contain: strict;
    will-change: auto;
    scroll-behavior: auto;
}
/* Mobile audio tweaks live with the other mobile rules at the bottom of
   this file — one @media block per breakpoint, so nothing about the
   compose row is silently overridden hundreds of lines apart. */

/* ── bottom zone ───────────────────────────────────────────────────────── */
#bottom-zone {
    flex-shrink: 0;
    padding: 8px 12px 12px;
    background: var(--bg);
    border-top: 1px solid var(--border-1);
}

/* ── reply bar ─────────────────────────────────────────────────────────── */
#reply-bar {
    display: none;
    align-items: center;
    gap: 12px;
    background: var(--surface-2);
    border: 1px solid var(--border-2);
    border-left: 3px solid var(--text-2);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    margin-bottom: 8px;
}

#reply-bar-inner {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow: hidden;
}

#reply-bar-label {
    color: var(--text-3);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    font-weight: 600;
}

#reply-bar-user {
    font-weight: 600;
    color: var(--text);
    font-size: 12px;
}

#reply-bar-text {
    color: var(--text-2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 13px;
}

#reply-bar-close {
    background: none;
    border: none;
    color: var(--text-3);
    cursor: pointer;
    padding: 4px;
    line-height: 1;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-xs);
    transition: color var(--dur-fast) ease, background var(--dur-fast) ease;
}
#reply-bar-close:hover { color: var(--text); background: var(--surface-3); }

/* ── attachment preview ────────────────────────────────────────────────── */
#attachment-preview {
    display: none;
    align-items: flex-start;
    gap: 10px;
    background: var(--surface-2);
    border: 1px solid var(--border-1);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

#preview-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    flex: 1;
}

.preview-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface-3);
    border: 1px solid var(--border-1);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    max-width: 200px;
    transition: border-color var(--dur-fast) ease;
}
.preview-item:hover { border-color: var(--border-2); }

.preview-img {
    max-height: 64px;
    max-width: 64px;
    border-radius: var(--radius-xs);
    object-fit: cover;
    display: block;
}

.preview-icon {
    color: var(--text-2);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Video/audio attachment chip preview trigger — click to see/hear the
   staged file before sending (video opens the same full-screen viewer
   sent videos use; audio plays inline via the shared preview player).
   Image chips reuse .preview-img directly instead — no separate button
   needed there, the thumbnail itself is already the click target. */
.preview-media-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    padding: 0;
    background: var(--surface-4);
    border: 1px solid var(--border-2);
    border-radius: 50%;
    color: var(--text);
    cursor: pointer;
    transition: background var(--dur-fast) ease, transform var(--dur-fast) ease;
}
.preview-media-btn:hover { background: #333; transform: scale(1.06); }
.preview-media-btn .icon { color: inherit; }

.preview-item.is-playing { border-color: var(--success); }
.preview-item.is-playing .preview-media-btn {
    background: var(--success);
    border-color: var(--success);
    color: #06210f;
}

.preview-name {
    font-size: 12px;
    color: var(--text-2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 90px;
}

.preview-remove {
    position: absolute;
    top: -6px;
    right: -6px;
    background: var(--surface-4);
    border: 1px solid var(--border-2);
    color: var(--text);
    border-radius: 50%;
    width: 20px;
    height: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
    transition: background var(--dur-fast) ease, transform var(--dur-fast) ease;
}
.preview-remove:hover  { background: #333; transform: scale(1.08); }
.preview-remove .icon  { width: 12px; height: 12px; color: var(--text); }

/* [FIX] Pending/error states for the remote-GIF loading chip. Reuses
   .preview-item's shape/tokens so it sits visually identical to a normal
   attachment while it resolves. */
.preview-item.is-pending {
    color: var(--text-2);
    border-style: dashed;
    border-color: var(--border-2);
}

.preview-spinner {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    border-radius: 50%;
    border: 2px solid var(--border-2);
    border-top-color: var(--text-2);
    animation: preview-spin 0.7s linear infinite;
}
@keyframes preview-spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
    .preview-spinner { animation: none; opacity: 0.6; }
}

.preview-item.is-error {
    border-color: var(--danger);
}
.preview-item.is-error .preview-icon.warning { color: var(--danger); }
.preview-item.is-error .preview-name { color: var(--danger); }

/* Press-and-hold-then-move reordering — any attachment type. Pending/error
   GIF chips aren't real files yet, so they stay non-draggable. */
.preview-item:not(.is-pending):not(.is-error) {
    cursor: grab;
    touch-action: none;
}
.preview-item.is-dragging {
    cursor: grabbing;
    opacity: 0.6;
    border-color: var(--border-3);
    box-shadow: var(--shadow-2);
    z-index: 5;
}
body.attachment-dragging {
    user-select: none;
    -webkit-user-select: none;
}

#cancel-attach {
    background: transparent;
    border: 1px solid var(--border-2);
    border-radius: var(--radius-xs);
    color: var(--text-2);
    font-size: 12px;
    cursor: pointer;
    padding: 5px 10px;
    white-space: nowrap;
    align-self: flex-start;
    font-family: inherit;
    transition: color var(--dur-fast) ease, background var(--dur-fast) ease;
}
#cancel-attach:hover { color: var(--text); background: var(--surface-3); }

/* ── bottom bar (compose row) ──────────────────────────────────────────── */
#bottom-bar {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--border-1);
    border-radius: var(--radius-md);
    padding: 6px 6px 6px 10px;
    transition: border-color var(--dur-fast) ease;
}
#bottom-bar:focus-within { border-color: var(--border-3); }

/* Compose-row icon buttons — unified pill treatment */
#attach-btn,
#sticker-toggle-btn,
#gif-toggle-btn,
#music-toggle-btn,
#send-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    padding: 8px;
    cursor: pointer;
    color: var(--text-2);
    flex-shrink: 0;
    line-height: 1;
    height: 38px;
    min-width: 38px;
    font-family: inherit;
    transition: background var(--dur-fast) ease, color var(--dur-fast) ease;
}
#attach-btn:hover,
#sticker-toggle-btn:hover,
#gif-toggle-btn:hover,
#music-toggle-btn:hover { background: var(--surface-3); color: var(--text); }

/* Legacy `<img id="add">` inside #attach-btn — normalise size. */
#add { height: 20px; width: 20px; filter: brightness(0) invert(0.75); }
#attach-btn:hover #add,
#attach-btn:focus-visible #add { filter: brightness(0) invert(1); }

/* GIF / music toggles use .icon.gif / .icon.music (see the icon system block
   above). The old text-chip fallback is retired for .icon.gif: the badge is
   now inlined as a data-URI so it can never 404, and the cramped "GIF" chip
   it used to expose is gone. .icon.gif always paints the masked badge. */
#gif-toggle-btn .icon.gif { width: 22px; height: 22px; }

/* Send button — solid, primary action */
#send-btn {
    background: var(--surface-4);
    color: var(--text);
    padding: 8px 12px;
    border: 1px solid var(--border-2);
}
#send-btn:hover  { background: #2e2e2e; border-color: var(--border-3); }
#send-btn:active { transform: translateY(1px); }
#send-btn .icon  { color: var(--text); background-color: var(--text); }

/* Message input — invisible surface, borderless, textarea-like feel */
#message-input {
    flex: 1;
    background: transparent;
    color: var(--text);
    border: none;
    border-radius: var(--radius-sm);
    padding: 8px 6px;
    font-family: inherit;
    font-size: 15px;
    min-height: 22px;
    max-height: 140px;
    line-height: 1.45;
    overflow-y: auto;
    word-break: break-word;
    white-space: pre-wrap;
    outline: none;
}
#message-input:empty::before {
    content: attr(placeholder);
    color: var(--text-4);
    pointer-events: none;
}

button { padding: 6px 16px; font-size: 15px; cursor: pointer; font-family: inherit; }

/* ── messages ──────────────────────────────────────────────────────────── */
.message {
    margin-bottom: 2px;
    cursor: default;
    contain: layout style;
}

.message:not(.grouped)               { margin-top: 16px; }
#messages > .message:first-child     { margin-top: 4px; }

.username {
    font-size: 12px;
    font-weight: 600;
    margin-left: 10px;
    margin-bottom: 4px;
    line-height: 1;
    letter-spacing: 0.01em;
    color: var(--text-2);
}

.bubble {
    background: var(--surface-2);
    border: 1px solid var(--border-1);
    border-radius: var(--radius-md);
    padding: 8px 12px;
    display: inline-flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 78%;
    box-shadow: var(--shadow-1);
    transition: border-color var(--dur-fast) ease;
    position: relative;
}
.bubble:hover { border-color: var(--border-2); }

.bubble-text {
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.45;
    font-size: 14.5px;
    color: var(--text);
}

.timestamp {
    font-size: 10.5px;
    color: var(--text-3);
    flex-shrink: 0;
    line-height: 1;
    padding-bottom: 2px;
    letter-spacing: 0.01em;
    user-select: none;
}

/* Message action cluster (copy / edit / delete) — hover-revealed in the
   bubble's top-right corner, same corner .copy-btn always lived in.
   Generalized to a single container so every bubble type (text/file/
   sticker/audio/youtube) wires the same three buttons the same way,
   instead of each type reinventing its own action row. */
.msg-actions {
    position: absolute;
    top: 4px;
    right: 4px;
    display: flex;
    gap: 2px;
    opacity: 0;
    background: rgba(0,0,0,0.75);
    border: 1px solid var(--border-2);
    border-radius: var(--radius-xs);
    padding: 2px;
    z-index: 2;
    transition: opacity var(--dur-fast) ease;
}
.bubble:hover .msg-actions,
.bubble-file:hover .msg-actions,
.bubble-audio:hover .msg-actions,
.bubble-sticker:hover .msg-actions,
.bubble-youtube:hover .msg-actions {
    opacity: 1;
}
.msg-actions button {
    background: transparent;
    border: none;
    padding: 4px;
    cursor: pointer;
    color: var(--text-2);
    line-height: 0;
    border-radius: 4px;
    transition: color var(--dur-fast) ease, background var(--dur-fast) ease;
}
.msg-actions button:hover  { color: var(--text); background: rgba(255,255,255,0.08); }
.msg-actions .icon         { width: 13px; height: 13px; color: inherit; }
.msg-actions .copy-btn.copied .icon { color: var(--success); }

/* Delete: tap-to-arm, tap-again-to-confirm — no blocking dialog. */
.msg-actions .delete-btn.confirm-armed {
    background: var(--danger);
    color: #fff;
    animation: delete-armed-pulse 900ms ease-in-out infinite;
}
@keyframes delete-armed-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255,107,107,0.5); }
    50%      { box-shadow: 0 0 0 4px rgba(255,107,107,0); }
}

/* msg-actions.css universally hides .msg-actions on ALL pointer types (the
   in-bubble cluster was replaced by the long-press instrument tray).
   The touch fallback that used to live here was never reachable — cluster
   is display:none globally. Kept the definitions above only because the
   JS still builds the markup (buildMessageActionsHTML) and the delegated
   click handlers still fire; the visuals are simply never rendered. */

/* "(edited)" marker — a flag, not a version log; no prior text is kept. */
.edited-badge {
    font-size: 10px;
    color: var(--text-3);
    font-style: italic;
    margin-right: 4px;
    user-select: none;
}

/* Deleted tombstone — same node, same slot, content swapped. Compositor-
   only entrance (opacity/scale), never a layout/height animation, so a
   delete never reflows neighboring messages. */
.bubble-deleted {
    opacity: 0.6;
    animation: bubble-deleted-in 320ms cubic-bezier(0.22, 1, 0.36, 1) both;
}
.deleted-text { font-style: italic; color: var(--text-3); }
@keyframes bubble-deleted-in {
    from { opacity: 0; transform: scale(0.97); }
    to   { opacity: 0.6; transform: scale(1); }
}

/* Inline edit mode — the existing .bubble-text/.bubble-caption node itself
   becomes contenteditable in place; nothing is swapped out, nothing else
   in the message reflows. */
.bubble-text.editing,
.bubble-caption.editing {
    outline: 1px dashed var(--border-3);
    outline-offset: 3px;
    border-radius: 4px;
    background: rgba(255,255,255,0.03);
    cursor: text;
}
.edit-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 6px;
    font-size: 10.5px;
    color: var(--text-3);
}
.edit-remaining { font-variant-numeric: tabular-nums; }
.edit-hint { opacity: 0.7; }
@media (max-width: 640px) {
    .edit-hint { display: none; }
}

/* image bubbles */
.bubble-file {
    display: inline-block;
    position: relative;
    padding: 6px;
    background: var(--surface-2);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-1);
    box-shadow: var(--shadow-1);
    max-width: 78%;
}

.chat-image {
    display: block;
    /* Cap both dimensions and preserve the source aspect ratio.
       Previously `object-fit: cover` cropped portraits to square-ish; the
       user was seeing screenshots and photos with their tops/bottoms
       shaved. `contain` respects the intrinsic ratio, and the max-width/
       max-height cap keeps the bubble bounded. Portrait images therefore
       come out as tall thumbnails, landscape as wide, both un-cropped. */
    max-width: 320px;
    max-height: 340px;
    width: auto;
    height: auto;
    border-radius: var(--radius-sm);
    cursor: pointer;
    decoding: async;
    min-width: 60px;
    min-height: 60px;
    background: #151515;
    object-fit: contain;
    content-visibility: auto;
    transition: transform var(--dur-fast) ease, filter var(--dur-fast) ease;
}
.chat-image:hover { filter: brightness(1.08); }
.chat-image[src=""] { background: #151515; }
.chat-image.is-gif-element {
    width: 220px;
    height: 220px;
    max-width: 220px;
    max-height: 220px;
    min-width: 220px;
    min-height: 220px;
    object-fit: contain;
}
.keyboard-focused {
    outline: 2px solid var(--text) !important;
    outline-offset: -2px;
    box-shadow: 0 0 0 3px rgba(255,255,255,0.15);
}

/* audio bubbles */
.bubble-audio {
    display: inline-flex;
    position: relative;
    flex-direction: column;
    gap: 8px;
    max-width: 440px;
    background: var(--surface-2);
    border: 1px solid var(--border-1);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    box-shadow: var(--shadow-1);
}

.audio-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.audio-info {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.audio-name {
    font-size: 12px;
    color: var(--text-2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 340px;
}

.chat-audio {
    width: 360px;
    min-width: 360px;
    max-width: 360px;
    height: 44px;
    /* colorScheme=dark on <html> already gives the native <audio> element
       a dark-mode set of controls in every modern browser. The old
       `filter: invert() hue-rotate()` hack painted the whole player as an
       inverted image — every future control tweak Chrome/Safari made
       would land inverted too, and it never quite matched --surface-2.
       `color-scheme: dark` is the intended API for this. */
    color-scheme: dark;
}

.yt-inline-audio-preview .chat-audio {
    width: 360px;
    min-width: 360px;
    max-width: 360px;
}

.timestamp-block {
    display: block;
    text-align: right;
    margin-top: 5px;
    font-size: 10.5px;
    color: var(--text-3);
    letter-spacing: 0.01em;
    user-select: none;
}

/* file link */
.file-link {
    color: var(--link);
    text-decoration: none;
    word-break: break-all;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
}
.file-link .icon { color: var(--text-2); width: 18px; height: 18px; }
.file-link:hover { text-decoration: underline; }

.file-block {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* bubble caption */
.bubble-caption {
    font-size: 14px;
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.45;
    margin-top: 6px;
    padding: 0 4px;
    color: var(--text);
}

/* own messages — neutral off-black, NOT blue */
.own-message {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}
.own-message .username {
    text-align: right;
}
.own-message .bubble,
.own-message .bubble-file,
.own-message .bubble-audio {
    background: var(--own-bubble);
    border-color: var(--own-bubble-brd);
    box-shadow: 0 2px 10px rgba(0,0,0,0.35);
}

/* date separator */
.date-separator {
    display: flex;
    align-items: center;
    margin: 24px 0 16px;
    color: var(--text-3);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    user-select: none;
}
.date-separator::before,
.date-separator::after { content: ""; flex: 1; border-top: 1px solid var(--border-1); }
.date-separator::before { margin-right: 14px; }
.date-separator::after  { margin-left:  14px; }

/* ── media viewer ──────────────────────────────────────────────────────── */
/* #image-viewer no longer exists in the DOM — the previous selector was a
   dead-code orphan from an earlier iteration. Only #media-viewer is
   styled now. */
#media-viewer {
    position: fixed;
    inset: 0;
    width: 100vw; height: 100vh;
    background: rgba(0,0,0,0.94);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

#viewer-image, #viewer-video {
    max-width: 96%;
    max-height: 96%;
    border-radius: var(--radius-md);
    outline: none;
    box-shadow: var(--shadow-3);
}

/* ── video thumbnail ───────────────────────────────────────────────────── */
.video-thumbnail-container {
    position: relative;
    cursor: pointer;
    display: flex !important;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 8px;
    min-height: 92px;
    min-width: 220px;
    border-radius: var(--radius-sm);
    background: #0a0a0a !important;
    border: 1px solid var(--border-2) !important;
    padding: 16px !important;
    transition: background var(--dur-fast) ease, border-color var(--dur-fast) ease;
}
.video-thumbnail-container:hover {
    background: #141414 !important;
    border-color: var(--border-3) !important;
}
.video-thumbnail-container .icon.play {
    width: 34px; height: 34px;
    color: var(--text);
}
.video-thumbnail-container .video-name {
    font-size: 11px;
    color: var(--text-2);
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── grouped messages ──────────────────────────────────────────────────── */
.grouped { margin-bottom: 2px; }
.grouped .bubble          { border-top-left-radius: 6px; }
.grouped .bubble-file     { border-top-left-radius: 6px; }
.own-message.grouped .bubble,
.own-message.grouped .bubble-file {
    border-top-left-radius: var(--radius-md);
    border-top-right-radius: 6px;
}
.grouped + .message:not(.grouped) { margin-top: 16px; }

/* ── chat link ─────────────────────────────────────────────────────────── */
.chat-link { color: var(--link); text-decoration: none; word-break: break-all; }
.chat-link:hover { text-decoration: underline; }

/* ── reply quote (rendered inside bubble) ──────────────────────────────── */
.reply-quote {
    background: rgba(255,255,255,0.04);
    border-left: 3px solid var(--text-2);
    border-radius: var(--radius-xs);
    padding: 6px 10px;
    margin-bottom: 8px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 3px;
    max-width: 100%;
    transition: background var(--dur-fast) ease;
}
.reply-quote:hover { background: rgba(255,255,255,0.09); }

.reply-quote-user  { font-size: 11.5px; font-weight: 600; }
.reply-quote-text  {
    font-size: 12px;
    color: var(--text-2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* highlight flash on reply-jump — kept a simple transition (CPU-friendly) */
.highlight-flash .bubble,
.highlight-flash .bubble-file,
.highlight-flash .bubble-audio {
    background: rgba(255,255,255,0.14);
    transition: background 1.1s ease-out;
}

/* ── drag-and-drop overlay ─────────────────────────────────────────────── */
/* Drag-and-drop is a desktop-only affordance. Touch pointers never see
   the overlay or the per-panel dropzones (Section 26 of the design brief).
   Attach on touch is the '+ Add Sticker / GIF / Music File' button. */
#drop-overlay {
    display: none;
    position: fixed;
    inset: 0;
    width: 100vw; height: 100vh;
    background: rgba(0,0,0,0.72);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    border: 2px dashed var(--text-2);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    gap: 14px;
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
    pointer-events: none;
}
#drop-overlay .icon.attach { width: 44px; height: 44px; color: var(--text); }

/* Suppress D&D affordances on touch. The dropzones live inside each
   panel and their own display would otherwise leave a large empty band
   above the grid on phones. */
@media (hover: none), (pointer: coarse) {
    #drop-overlay,
    #gif-dropzone, #sticker-dropzone, #music-dropzone,
    .cb-panel-dropzone { display: none !important; }
}

/* ── mobile tweaks ─────────────────────────────────────────────────────── */
/* One @media block per breakpoint. Merged the mobile audio rules that
   previously lived hundreds of lines above (right after #messages), so
   every mobile-only override is now in one place. */
@media (max-width: 640px) {
    #chat-screen  { width: 100vw; }
    #header       { padding: 12px 14px; }
    #messages     { padding: 14px 12px 8px; }
    #bottom-zone  { padding: 6px 10px 10px; }
    .bubble       { max-width: 90%; }
    .bubble-file  { max-width: 90%; }
    .bubble-audio { max-width: 96%; }
    .chat-image   { max-width: 240px; }
    .audio-name   { max-width: 220px; }

.chat-audio,
.yt-inline-audio-preview .chat-audio {
    width: 360px;
    min-width: 360px;
    max-width: 360px;
    height: 44px;
    box-sizing: border-box;
}
}

/* ── upload progress ───────────────────────────────────────────────────── */
#upload-progress {
    width: 100%;
    height: 3px;
    border: none;
    background: var(--surface-2);
    appearance: none;
    margin-bottom: 6px;
    border-radius: var(--radius-pill);
    overflow: hidden;
}
#upload-progress::-webkit-progress-bar   { background: var(--surface-2); border-radius: var(--radius-pill); }
#upload-progress::-webkit-progress-value { background: var(--text-2); border-radius: var(--radius-pill); transition: width 120ms ease; }
#upload-progress::-moz-progress-bar      { background: var(--text-2); border-radius: var(--radius-pill); }

/* ═════════════════════════════════════════════════════════════════════════
   Sticker / GIF / Music drawer  (.cb-panel* family)
   ─────────────────────────────────────────────────────────────────────────
   The three drawers share a body layout: a header row on top (title or
   tabs on the left, upload + close on the right), then a two-pane body
   below (folder sidebar + content pane), or a single-column layout for
   the search tabs. Everything below is now class-driven — the panels no
   longer carry inline styles in index.html, and the `!important` sprawl
   this file used to need in order to overpower those inline styles is
   gone with it.
   ═════════════════════════════════════════════════════════════════════════ */

.cb-panel {
    display: flex;
    flex-direction: column;
    position: relative;
    background: var(--surface-1);
    border: 1px solid var(--border-1);
    border-bottom: none;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    padding: 14px;
    height: 340px;
    margin-bottom: 8px;
    gap: 12px;
    min-height: 0;
}

.cb-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-1);
    flex-shrink: 0;
}

.cb-panel-title {
    font-weight: 600;
    color: var(--text);
    font-size: 14px;
    letter-spacing: -0.01em;
}

.cb-panel-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* ── panel tabs ─────────────────────────────────────────────────────────
   State is now a class (.is-active) instead of inline styles, so a
   keyboard user hitting the tab twice, or a JS bug that fails to reset
   the previous tab, can't leave two tabs looking active at once. */
.cb-panel-tabs {
    display: flex;
    gap: 6px;
}

.cb-panel-tab {
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    background: transparent;
    color: var(--text-3);
    border: 1px solid transparent;
    cursor: pointer;
    font-family: inherit;
    transition: background var(--dur-fast) ease,
                color var(--dur-fast) ease,
                border-color var(--dur-fast) ease;
}
.cb-panel-tab:hover { color: var(--text-2); background: var(--surface-2); }
.cb-panel-tab.is-active {
    background: var(--surface-4);
    color: var(--text);
    border-color: var(--border-1);
}

/* ── panel body layouts ────────────────────────────────────────────── */
.cb-panel-body {
    display: flex;
    gap: 12px;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}
.cb-panel-body--column {
    flex-direction: column;
    gap: 10px;
}

.cb-panel-folders {
    width: 170px;
    overflow-y: auto;
    padding-right: 6px;
    border-right: 1px solid var(--border-1);
    flex-shrink: 0;
}

.cb-panel-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

.cb-panel-newfolder {
    width: 100%;
    padding: 7px;
    background: var(--surface-2);
    border: 1px solid var(--border-2);
    border-radius: var(--radius-sm);
    color: var(--text-2);
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 8px;
    cursor: pointer;
    font-family: inherit;
    transition: background var(--dur-fast) ease,
                color var(--dur-fast) ease,
                border-color var(--dur-fast) ease;
}
.cb-panel-newfolder:hover {
    background: var(--surface-3);
    border-color: var(--border-3);
    color: var(--text);
}

/* ── panel dropzone (desktop only — hidden on touch by the D&D block) ── */
.cb-panel-dropzone {
    text-align: center;
    margin-bottom: 10px;
    padding: 12px;
    font-size: 12px;
    color: var(--text-3);
    background: var(--surface-2);
    border: 2px dashed var(--border-2);
    border-radius: var(--radius-sm);
    transition: border-color var(--dur-fast) ease, background var(--dur-fast) ease;
}
.cb-panel-dropzone.is-active {
    border-color: var(--border-3);
    background: var(--surface-3);
    color: var(--text-2);
}

/* ── panel grids (image thumbs) & list (audio rows) ────────────────── */
.cb-panel-grid {
    display: grid;
    gap: 10px;
    overflow-y: auto;
    flex: 1;
    padding-right: 2px;
    align-content: start;
    min-height: 0;
}
.cb-panel-grid--sticker { grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); }
.cb-panel-grid--gif     { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
.cb-panel-grid--music,
.cb-panel-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow-y: auto;
    flex: 1;
    padding-right: 2px;
    min-height: 0;
}

/* ── panel search rows (Giphy / YouTube / yt-dlp) ──────────────────── */
.cb-panel-searchrow {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.cb-panel-search {
    flex: 1;
    padding: 8px 12px;
    background: var(--surface-2);
    border: 1px solid var(--border-2);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 13px;
    font-family: inherit;
    outline: none;
    transition: border-color var(--dur-fast) ease, background var(--dur-fast) ease;
}
.cb-panel-search:focus { border-color: var(--border-3); background: var(--surface-3); }
.cb-panel-search::placeholder { color: var(--text-4); }

.cb-panel-searchbtn {
    padding: 7px 16px;
    background: var(--surface-4);
    border: 1px solid var(--border-2);
    color: var(--text);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background var(--dur-fast) ease, border-color var(--dur-fast) ease;
}
.cb-panel-searchbtn:hover { background: #2e2e2e; border-color: var(--border-3); }

/* ── panel upload buttons (+ Add Sticker / GIF / Music File) ──────── */
.cb-panel-upload {
    background: var(--surface-4);
    color: var(--text);
    border: 1px solid var(--border-2);
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background var(--dur-fast) ease, border-color var(--dur-fast) ease;
}
.cb-panel-upload:hover { background: #2e2e2e; border-color: var(--border-3); }

/* Panel close (× glyph) — used in every panel header. */
.panel-close-btn {
    background: transparent;
    border: none;
    color: var(--text-3);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-xs);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--dur-fast) ease, color var(--dur-fast) ease;
}
.panel-close-btn:hover { background: var(--surface-3); color: var(--text); }

/* ── music: local file list rows ────────────────────────────────────────
   Audio has no natural thumbnail, so local mode is a list of rows
   (icon + name) rather than a grid — same folder-sidebar shell as GIF/
   sticker, different content-pane layout since a grid of blank squares
   would add nothing here. */
.music-local-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    background: var(--surface-2);
    border: 1px solid var(--border-1);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--dur-fast) ease, border-color var(--dur-fast) ease;
}
.music-local-item:hover { background: var(--surface-3); border-color: var(--border-2); }
.music-local-item .icon.file { color: var(--text-2); flex-shrink: 0; }

/* Preview button — plays the file inline via the shared preview player,
   independent of the row's own click-to-stage behavior (stopPropagation
   on the button itself keeps the two from firing together). */
.music-local-play-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    padding: 0;
    background: var(--surface-3);
    border: 1px solid var(--border-2);
    border-radius: 50%;
    color: var(--text-2);
    cursor: pointer;
    transition: background var(--dur-fast) ease, color var(--dur-fast) ease;
}
.music-local-play-btn:hover { background: var(--surface-4); color: var(--text); }

.music-local-item.is-playing { border-color: var(--success); }
.music-local-item.is-playing .music-local-play-btn {
    background: var(--success);
    border-color: var(--success);
    color: #06210f;
}

.music-local-item-name {
    font-size: 13px;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── music: YouTube / yt-dlp result cards ───────────────────────────────
   Deliberately NOT a thumbnail grid like Giphy — each result is a full-
   width card (title + channel + preview control) so there's room to
   actually identify the video before sending it, per spec: click the
   play button to preview, click anywhere else on the card to send.
   Column layout (not a single row) because yt-dlp's audio preview needs
   its own full-width row below the thumb+info row — see
   .yt-inline-audio-preview below for why. */
.yt-result-card {
    display: flex;
    flex-direction: column;
    padding: 8px;
    background: var(--surface-2);
    border: 1px solid var(--border-1);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--dur-fast) ease, border-color var(--dur-fast) ease;
}
.yt-result-card:hover { background: var(--surface-3); border-color: var(--border-2); }

.yt-result-card-main {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* yt-dlp preview audio row. A native <audio controls> bar needs real
   horizontal room to render its play/scrub/volume controls usably —
   cramming it into the 120px-wide video-thumbnail box (see
   .yt-result-thumb-wrap) crushed it into an unreadable sliver. Full card
   width instead, own row, clearly separated from the thumb+info row. */
.yt-inline-audio-preview {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border-1);
    cursor: default;
}


.yt-result-thumb-wrap {
    position: relative;
    flex-shrink: 0;
    width: 120px;
    height: 68px;
    border-radius: var(--radius-xs);
    overflow: hidden;
    background: #0a0a0a;
}
.yt-result-thumb-wrap img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
/* Once a preview player is mounted, the wrap holds a live iframe instead
   of the thumbnail — same box, no layout shift. (yt-dlp audio preview no
   longer goes here — see .yt-inline-audio-preview above.) */
.yt-result-thumb-wrap iframe {
    width: 100%;
    height: 100%;
    display: block;
    border: none;
}

/* [FIX] The 120×68 box above is a fine browsing-thumbnail size, but far
   too small to actually watch once a live player is mounted into it —
   video reduced to a postage stamp, controls unreadable. yt-card-live-
   preview is added in JS the instant a preview starts (buildYtResultCard)
   and switches ONLY that one card to a stacked, full-width 16:9 layout —
   every other card in the results list keeps its compact browsing size. */
.yt-result-card.yt-card-live-preview {
    border-color: var(--border-3);
    background: var(--surface-3);
}
.yt-result-card.yt-card-live-preview .yt-result-card-main {
    flex-direction: column;
    align-items: stretch;
}
.yt-result-card.yt-card-live-preview .yt-result-thumb-wrap {
    align-self: center;
    width: 100%;
    max-width: 240px;
    height: auto;
    aspect-ratio: 16 / 9;
}

/* "Video unavailable" replacement — shown in place of the thumbnail when
   the IFrame player's onError fires (most commonly: uploader disabled
   embedding for that specific video, common for official/label music
   videos). Same box as the thumbnail/live player, so no layout shift. */
.yt-embed-fallback {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    text-align: center;
    padding: 6px;
    font-size: 10.5px;
    color: var(--text-3);
    background: #0a0a0a;
}
.yt-embed-fallback a {
    color: var(--link);
    font-weight: 600;
    text-decoration: none;
}
.yt-embed-fallback a:hover { text-decoration: underline; }

.yt-preview-play-btn {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.35);
    border: none;
    padding: 0;
    cursor: pointer;
    transition: background var(--dur-fast) ease;
}
.yt-preview-play-btn:hover { background: rgba(0,0,0,0.55); }
.yt-preview-play-btn .icon.play {
    width: 28px;
    height: 28px;
    color: #fff;
    filter: drop-shadow(0 2px 6px rgba(0,0,0,0.7));
}

.yt-result-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.yt-result-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.yt-result-channel {
    font-size: 11.5px;
    color: var(--text-3);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.yt-result-hint {
    font-size: 10.5px;
    color: var(--text-3);
    letter-spacing: 0.02em;
}

/* "Load more results" — deliberate button, not auto-scroll. Each click
   is one more search.list call against a ~100-call/day quota shared by
   all 3 of you (see the response for why this is a button, not an
   IntersectionObserver on the list). */
.yt-load-more-wrap {
    display: block;
    width: 100%;
    padding: 10px;
    margin-top: 4px;
    background: var(--surface-2);
    border: 1px dashed var(--border-2);
    border-radius: var(--radius-sm);
    color: var(--text-2);
    font-size: 12.5px;
    font-weight: 600;
    text-align: center;
    cursor: pointer;
    font-family: inherit;
    flex-shrink: 0;
    transition: background var(--dur-fast) ease, border-color var(--dur-fast) ease, color var(--dur-fast) ease;
}
.yt-load-more-wrap:hover { background: var(--surface-3); border-color: var(--border-3); color: var(--text); }

/* ── music: chat bubble for YouTube (IFrame embed) shares ───────────────
   At rest: static thumbnail + play overlay, zero iframe cost (matches
   AnimatedMedia's "don't pay for it until it's visible/interacted-with"
   discipline). On click: swapped in-place for a live YT.Player. */
.bubble-youtube {
    display: inline-flex;
    position: relative;
    flex-direction: column;
    max-width: 340px;
    background: var(--surface-2);
    border: 1px solid var(--border-1);
    border-radius: var(--radius-md);
    padding: 6px;
    box-shadow: var(--shadow-1);
    gap: 6px;
}
.yt-bubble-thumb-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: #0a0a0a;
    cursor: pointer;
}
.yt-bubble-thumb-wrap img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.yt-bubble-thumb-wrap iframe {
    width: 100%;
    height: 100%;
    display: block;
    border: none;
}
.yt-bubble-play-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.30);
    transition: background var(--dur-fast) ease;
}
.yt-bubble-thumb-wrap:hover .yt-bubble-play-overlay { background: rgba(0,0,0,0.45); }
.yt-bubble-play-overlay .icon.play {
    width: 40px;
    height: 40px;
    color: #fff;
    filter: drop-shadow(0 2px 8px rgba(0,0,0,0.75));
}
.yt-bubble-meta {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 2px 6px 4px;
}
.yt-bubble-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.yt-bubble-channel-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
}
.yt-bubble-channel {
    font-size: 11px;
    color: var(--text-3);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── toast (repositioned + neutral treatment) ──────────────────────────── */
#toast-container {
    position: fixed;
    top: 22px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10000;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--surface-3);
    color: var(--text);
    border: 1px solid var(--border-2);
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    box-shadow: var(--shadow-3);
    opacity: 0;
    transform: translateY(-16px);
    transition: opacity var(--dur-med) ease, transform var(--dur-med) ease;
    max-width: 400px;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* ── stickers ──────────────────────────────────────────────────────────── */
.bubble-sticker {
    position: relative;
    background: transparent !important;
    padding: 0 !important;
    border: none !important;
    box-shadow: none !important;
}

.chat-sticker {
    width: 140px;
    height: 140px;
    object-fit: contain;
    cursor: pointer;
    filter: drop-shadow(0 4px 10px rgba(0,0,0,0.5));
    border-radius: var(--radius-sm);
    transition: transform var(--dur-fast) ease;
}
.chat-sticker:hover { transform: scale(1.03); }

.bubble-sticker .timestamp-block {
    text-shadow: 0 1px 3px rgba(0,0,0,0.95);
    color: #eee;
    margin-top: -18px;
    position: relative;
    z-index: 2;
    padding-right: 6px;
}

/* ── presence bar ──────────────────────────────────────────────────────── */
#presence-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    margin-left: auto;
    padding: 0;
    font-size: 11.5px;
    color: var(--text-2);
}
.presence-pill {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    background: var(--surface-2);
    border: 1px solid var(--border-1);
    border-radius: var(--radius-pill);
    font-weight: 500;
}
.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}
.status-dot.online  { background: var(--success); box-shadow: 0 0 6px rgba(74,222,128,0.5); }
.status-dot.offline { background: #555; }

/* ── system messages / unread divider / typing indicator ───────────────── */
.system-message {
    display: flex;
    align-items: center;
    gap: 10px;
    text-align: center;
    color: var(--text-3);
    font-size: 11px;
    margin: 10px 0;
    user-select: none;
    letter-spacing: 0.03em;
}
.system-message::before,
.system-message::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--border-1);
}

.unread-divider {
    display: flex;
    align-items: center;
    gap: 10px;
    text-align: center;
    color: var(--text-2);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    margin: 12px 0;
    user-select: none;
}
.unread-divider::before,
.unread-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--text-2);
    opacity: 0.4;
}

#typing-indicator {
    height: 20px;
    font-size: 12px;
    color: var(--text-3);
    font-style: italic;
    padding: 0 8px;
    line-height: 20px;
    min-height: 20px;
    letter-spacing: 0.01em;
}

/* ── scroll-to-bottom button ───────────────────────────────────────────── */
#scroll-to-bottom-btn {
    position: fixed;
    bottom: 96px;
    right: 24px;
    z-index: 200;
    background: var(--surface-3) !important;
    color: var(--text) !important;
    border: 1px solid var(--border-2) !important;
    border-radius: var(--radius-pill) !important;
    padding: 8px 16px !important;
    font-size: 12.5px !important;
    font-weight: 600 !important;
    cursor: pointer;
    box-shadow: var(--shadow-3);
    display: none;
    align-items: center;
    gap: 8px;
    letter-spacing: 0.01em;
    font-family: inherit;
    transition: background var(--dur-fast) ease, transform var(--dur-fast) ease;
}
#scroll-to-bottom-btn:hover  { background: var(--surface-4) !important; transform: translateY(-1px); }
#scroll-to-bottom-btn:active { transform: translateY(0); }
#scroll-to-bottom-btn .icon.arrow-down { width: 14px; height: 14px; color: var(--text); }

/* ── connection banner ─────────────────────────────────────────────────── */
#conn-banner {
    display: flex !important;
    align-items: center;
    justify-content: center;
    gap: 8px;
    position: sticky;
    top: 0; left: 0; right: 0;
    z-index: 50;
    padding: 6px 0 !important;
    font-size: 11.5px !important;
    text-align: center;
    background: #1a0e0e !important;
    color: var(--danger) !important;
    letter-spacing: 0.03em;
    border-bottom: 1px solid #3a1616;
}
#conn-banner .icon.warning { width: 14px; height: 14px; color: var(--danger); }

/* ═════════════════════════════════════════════════════════════════════════
   Animated-media visibility controller — CSS support
   Companion to the AnimatedMedia module in app.js. Off-screen GIFs/WebPs
   are frozen by overlaying an absolutely-positioned <canvas> on top of the
   <img>, so the container needs to be a positioning context.
   ═════════════════════════════════════════════════════════════════════════ */

.gif-container {
    position: relative;
    display: inline-block;
    line-height: 0;         /* prevent baseline gap under the <img> */
    max-width: 100%;
}

/* The frozen-frame canvas sits precisely on top of the <img>. Positioned
   inline in JS (position:absolute; inset:0), sized to match the container. */
.gif-poster {
    display: none;          /* only shown while the element is off-screen */
    background: transparent;
}
.unread-divider {
    /* ...existing rules... */
    opacity: 1;
    transition: opacity 350ms ease;
}
.unread-divider-fading {
    opacity: 0;
    pointer-events: none;
}

/* ═════════════════════════════════════════════════════════════════════════
   Now-playing island
   Persistent, top-anchored playback control for sent audio/ytdlp/YouTube
   bubbles. Lives outside #messages entirely (position:fixed against the
   viewport, not the scroll container) — the whole point is staying
   reachable regardless of scroll position. Driven exclusively through
   NowPlaying/Island in index.js; nothing else should toggle these classes
   directly. "Live" (--success green, same convention as .is-playing on
   music-panel rows and the online status dot) means audibly playing right
   now; the pill itself persists whether playing or paused, so pausing and
   scrolling away doesn't lose the session.

   Two states, one element. Collapsed is the original compact pill —
   thumbnail, title, playpause, close. Clicking the pill (or tapping, on
   touch) morphs it into a full playback surface: the same header on top,
   a big playpause, a real seekbar, and a "Go to message" button revealed
   underneath. The morph is a single .np-expanded class toggle; every
   dimension that changes (height/width/border-radius/padding/the art's
   own size+shape) is an explicit, fixed target on both ends so the
   transition is a plain, reliable CSS animation rather than anything
   measured/animated to "auto" at runtime.
   ═════════════════════════════════════════════════════════════════════════ */
.np-island {
    position: fixed;
    top: 74px;
    left: 50%;
    transform: translateX(-50%) translateY(-14px);
    z-index: 400;
    display: flex;
    flex-direction: column;
    min-width: 220px;
    max-width: 360px;
    height: 52px;
    padding: 6px 8px 6px 6px;
    border-radius: var(--radius-pill);
    background: rgba(12,12,12,0.82);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255,255,255,0.09);
    box-shadow: 0 12px 34px rgba(0,0,0,0.55), 0 1px 0 rgba(255,255,255,0.04) inset;
    opacity: 0;
    pointer-events: none;
    transition:
        opacity 260ms ease,
        transform 260ms cubic-bezier(0.34, 1.56, 0.64, 1),
        width 420ms cubic-bezier(0.16, 1, 0.3, 1),
        height 420ms cubic-bezier(0.16, 1, 0.3, 1),
        border-radius 420ms cubic-bezier(0.16, 1, 0.3, 1),
        padding 420ms cubic-bezier(0.16, 1, 0.3, 1),
        gap 420ms cubic-bezier(0.16, 1, 0.3, 1),
        box-shadow 420ms ease;
    overflow: hidden;
}
.np-island.np-visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(-50%) translateY(0);
}
.np-island:hover { border-color: rgba(255,255,255,0.16); }

/* Faint fractal-noise grain on the glass — keeps the blurred surface from
   reading as a flat gradient plate, the same reason iOS/macOS "material"
   surfaces carry grain. Deliberately subtle: this is texture, not a
   pattern anyone should consciously notice. z-index:0 + the row/expanded
   panel below sitting at z-index:1 keeps it strictly behind content
   regardless of DOM/paint-order specifics for positioned vs in-flow boxes. */
.np-island::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    opacity: 0.035;
    mix-blend-mode: overlay;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.np-island-row {
    position: relative;
    z-index: 1;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

.np-island-art {
    position: relative;
    flex-shrink: 0;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    overflow: visible;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-3);
    transition: width 420ms cubic-bezier(0.16, 1, 0.3, 1),
                height 420ms cubic-bezier(0.16, 1, 0.3, 1),
                border-radius 420ms cubic-bezier(0.16, 1, 0.3, 1);
}
.np-island-thumb {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    display: block;
    -webkit-user-drag: none;
    user-drag: none;
    -webkit-touch-callout: none;
    transition: border-radius 420ms cubic-bezier(0.16, 1, 0.3, 1);
}

/* Fallback "art" when a session has no thumbnail (local audio, ytdlp
   audio without one) — a small equalizer instead of a generic file icon,
   since "now playing" is exactly what this glyph already means to anyone
   who's used a music app. Bars only animate while .np-live is set; at
   rest (paused) they sit still at a low resting height. */
.np-island-eq {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 3px;
    width: 100%;
    height: 100%;
}
.np-island-eq span {
    width: 3px;
    height: 6px;
    border-radius: 2px;
    background: var(--text-2);
    animation: np-eq-bounce 1.1s ease-in-out infinite;
    animation-play-state: paused;
}
.np-island.np-live .np-island-eq span { animation-play-state: running; }
.np-island-eq span:nth-child(1) { animation-delay: -0.9s; }
.np-island-eq span:nth-child(2) { animation-delay: -0.5s; }
.np-island-eq span:nth-child(3) { animation-delay: -0.7s; }
.np-island-eq span:nth-child(4) { animation-delay: -0.2s; }
@keyframes np-eq-bounce {
    0%, 100% { height: 5px; }
    50%      { height: 16px; }
}

/* Pulse ring around the art circle — the "this is live" signal, reusing
   --success (the same green already meaning "actively playing" on
   .music-local-item.is-playing / .preview-item.is-playing, and "online"
   on the presence dots) rather than introducing a new accent color. */
.np-island-ring {
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 1.5px solid var(--success);
    opacity: 0;
    pointer-events: none;
    transition: inset 420ms cubic-bezier(0.16, 1, 0.3, 1);
}
.np-island.np-live .np-island-ring {
    animation: np-ring-pulse 1.8s ease-out infinite;
}
@keyframes np-ring-pulse {
    0%   { transform: scale(0.85); opacity: 0.55; }
    70%  { transform: scale(1.35); opacity: 0; }
    100% { transform: scale(1.35); opacity: 0; }
}

.np-island-meta {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
    flex: 1;
}
/* Small mono "kind" readout — YouTube / YT Audio / Local Audio — shown
   only when expanded, where there's room for it. Monospace + tracked-out
   caps reads as a hardware/hi-fi display label, distinct from the
   proportional type everywhere else, without needing a webfont fetch
   (see --font-mono). */
.np-island-kind {
    display: none;
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: var(--text-3);
}
.np-island-title {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: -0.005em;
    transition: font-size 420ms cubic-bezier(0.16, 1, 0.3, 1);
}
.np-island-subtitle {
    font-size: 10.5px;
    color: var(--text-3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: font-size 420ms cubic-bezier(0.16, 1, 0.3, 1);
}

.np-island-playpause,
.np-island-close {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: var(--surface-4);
    color: var(--text);
    cursor: pointer;
    transition: background var(--dur-fast) ease, transform var(--dur-fast) ease;
}
.np-island-playpause:hover,
.np-island-close:hover { background: #333; }
.np-island-playpause:active,
.np-island-close:active { transform: scale(0.94); }
.np-island-playpause .icon { color: var(--text); }
.np-island-close {
    width: 26px;
    height: 26px;
    background: transparent;
    color: var(--text-3);
    transition: background var(--dur-fast) ease, color var(--dur-fast) ease,
                width 420ms cubic-bezier(0.16, 1, 0.3, 1), height 420ms cubic-bezier(0.16, 1, 0.3, 1);
}
.np-island-close:hover { background: var(--surface-3); color: var(--text); }

.np-island-progress {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    height: 2px;
    background: transparent;
    z-index: 2;
    opacity: 1;
    transition: opacity var(--dur-med) ease;
}
.np-island-progress-fill {
    height: 100%;
    width: 0%;
    background: var(--success);
    transition: width 480ms linear;
}

/* ── Expanded panel ───────────────────────────────────────────────────────
   Sits below .np-island-row at all times in the DOM — while collapsed
   it's simply clipped off by the root's fixed 52px height + overflow:
   hidden, no display:none needed for the visual side. It IS marked inert
   while collapsed (toggled in JS alongside the class) so a keyboard user
   tabbing through the page can't land focus on controls that aren't
   visibly there. */
.np-island-expanded {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    width: 100%;
    opacity: 0;
    transition: opacity 200ms ease;
}
.np-island.np-expanded .np-island-expanded {
    opacity: 1;
    transition: opacity 220ms ease 160ms; /* settles in just after the card has finished most of its growth */
}

.np-island-playpause-lg {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 54px;
    height: 54px;
    border-radius: 50%;
    border: none;
    background: var(--surface-4);
    color: var(--text);
    cursor: pointer;
    transition: background var(--dur-fast) ease, transform var(--dur-fast) ease, box-shadow var(--dur-med) ease;
}
.np-island-playpause-lg:hover { background: #333; }
.np-island-playpause-lg:active { transform: scale(0.94); }
.np-island-playpause-lg .icon { color: var(--text); }
.np-island.np-live .np-island-playpause-lg {
    box-shadow: 0 0 0 1px rgba(74,222,128,0.35), 0 0 18px rgba(74,222,128,0.18);
}

.np-island-seekrow {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}
.np-time {
    flex-shrink: 0;
    min-width: 30px;
    font-family: var(--font-mono);
    font-size: 10.5px;
    color: var(--text-3);
    font-variant-numeric: tabular-nums;
}
.np-time-current { text-align: right; }
.np-time-duration { text-align: left; }

/* Custom range input — thin filled track + small thumb, themed to match
   rather than the browser default. --np-seek-pct is written from JS
   (index.js: _setSeekFillPct) alongside .value on every update, since a
   native range input has no CSS-only way to know how "full" it is. */
.np-island-seek {
    --np-seek-pct: 0%;
    flex: 1;
    min-width: 0;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    height: 16px;
    margin: 0;
    cursor: pointer;
}
.np-island-seek::-webkit-slider-runnable-track {
    height: 4px;
    border-radius: 2px;
    background: linear-gradient(to right,
        var(--success) var(--np-seek-pct),
        rgba(255,255,255,0.16) var(--np-seek-pct));
}
.np-island-seek::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    margin-top: -4px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(255,255,255,0.12), 0 1px 3px rgba(0,0,0,0.5);
    transition: transform 120ms ease;
}
.np-island-seek:active::-webkit-slider-thumb { transform: scale(1.15); }
.np-island-seek::-moz-range-track {
    height: 4px;
    border-radius: 2px;
    background: rgba(255,255,255,0.16);
}
.np-island-seek::-moz-range-progress {
    height: 4px;
    border-radius: 2px;
    background: var(--success);
}
.np-island-seek::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border: none;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(255,255,255,0.12), 0 1px 3px rgba(0,0,0,0.5);
}
.np-island-seek:disabled { opacity: 0.4; cursor: default; }
.np-island-seek:focus-visible::-webkit-slider-thumb,
.np-island-seek:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 3px var(--success); }

.np-island-goto {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255,255,255,0.1);
    background: var(--surface-4);
    color: var(--text-2);
    font-size: 12.5px;
    font-weight: 600;
    letter-spacing: -0.005em;
    cursor: pointer;
    transition: background var(--dur-fast) ease, color var(--dur-fast) ease,
                border-color var(--dur-fast) ease, transform var(--dur-fast) ease;
}
.np-island-goto:hover { background: #2e2e2e; color: var(--text); border-color: var(--border-2); }
.np-island-goto:active { transform: scale(0.98); }
.np-goto-icon { width: 13px; height: 13px; color: currentColor; flex-shrink: 0; }

/* ── State: expanded ──────────────────────────────────────────────────── */
.np-island.np-expanded {
    width: 320px;
    height: 244px;
    gap: 14px;
    padding: 16px 18px;
    border-radius: var(--radius-xl);
    box-shadow: 0 20px 48px rgba(0,0,0,0.6), 0 1px 0 rgba(255,255,255,0.05) inset;
}
.np-island.np-expanded .np-island-art { width: 58px; height: 58px; border-radius: 16px; }
.np-island.np-expanded .np-island-thumb { border-radius: 16px; }
.np-island.np-expanded .np-island-ring { inset: -6px; }
.np-island.np-expanded .np-island-eq { gap: 4px; }
.np-island.np-expanded .np-island-eq span { width: 4px; }
.np-island.np-expanded .np-island-kind { display: block; }
.np-island.np-expanded .np-island-meta { gap: 3px; }
.np-island.np-expanded .np-island-title { font-size: 15px; }
.np-island.np-expanded .np-island-subtitle { font-size: 12px; }
.np-island.np-expanded .np-island-playpause { display: none; }
.np-island.np-expanded .np-island-close { width: 30px; height: 30px; }
.np-island.np-expanded .np-island-progress { opacity: 0; }

@media (prefers-reduced-motion: reduce) {
    .np-island { transition: opacity 150ms ease; }
    .np-island-eq span { animation: none; height: 10px; }
    .np-island-ring { animation: none; opacity: 0; }
    .np-island-art,
    .np-island-thumb,
    .np-island-title,
    .np-island-subtitle,
    .np-island-close,
    .np-island-expanded { transition: none; }
}

@media (max-width: 640px) {
    .np-island {
        top: 64px;
        min-width: 0;
        max-width: calc(100vw - 24px);
        height: 48px;
        gap: 8px;
        padding: 5px 6px 5px 5px;
    }
    .np-island-row { gap: 8px; }
    .np-island-art { width: 34px; height: 34px; }
    .np-island-title { font-size: 12px; }
    .np-island-subtitle { font-size: 10px; }
    .np-island-playpause { width: 30px; height: 30px; }

    .np-island.np-expanded {
        width: calc(100vw - 24px);
        max-width: 340px;
        height: 228px;
        padding: 14px 16px;
    }
    .np-island.np-expanded .np-island-art { width: 50px; height: 50px; }
    .np-island.np-expanded .np-island-playpause-lg { width: 48px; height: 48px; }
}
