/*
 * Floating chat widget.
 *
 * Colours are custom properties with fallbacks, so this stylesheet stands alone
 * and can be rethemed by overriding a property on any ancestor. Values derived
 * from the accent — glows, hover tints — use color-mix() against the same
 * property, so a single override carries through instead of leaving a pink glow
 * around a blue widget. See the Theming section of README.md.
 *
 * color-mix() needs Chrome 111 / Safari 16.2 / Firefox 113 (all 2023).
 */
/* ═══════════════════════════════════════════════
   Arcade Chat Widget — Floating bottom-right chat
   ═══════════════════════════════════════════════ */

/* ── Widget Container ──────────────────────────────────────────────────── */

.acw {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: 'Courier Prime', monospace;
    color: var(--acw-cream, #f0ead8);
    width: 48px;
}

.acw.expanded {
    width: auto;
}

/* ── Floating Button (collapsed) ─────────────────────────────────────── */

.acw-bar {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    background: var(--acw-bg, #1a1028);
    border: 2px solid var(--acw-accent, #ff2e9c);
    border-radius: 12px;
    cursor: pointer;
    box-shadow: 0 0 16px color-mix(in srgb, var(--acw-accent, #ff2e9c) 30%, transparent);
    transition: transform 0.15s, box-shadow 0.15s, border-radius 0.2s, border-color 0.2s;
    user-select: none;
}

.acw-bar:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 24px color-mix(in srgb, var(--acw-accent, #ff2e9c) 50%, transparent);
    border-color: var(--acw-accent-hover, #ff5ab5);
}

.acw.expanded .acw-bar {
    border-radius: 12px 12px 0 0;
    border-bottom-color: transparent;
}

/* ── Speech Bubble Icon ─────────────────────────────────────────────── */

.acw-icon {
    width: 20px;
    height: 16px;
    background: var(--acw-accent, #ff2e9c);
    border-radius: 4px;
    position: relative;
    flex-shrink: 0;
}

.acw-icon::after {
    content: '';
    position: absolute;
    bottom: -5px;
    left: 4px;
    width: 0;
    height: 0;
    border-left: 5px solid var(--acw-accent, #ff2e9c);
    border-right: 5px solid transparent;
    border-top: 5px solid var(--acw-accent, #ff2e9c);
    border-bottom: 5px solid transparent;
}

/* ── Online Count (below bubble) ────────────────────────────────────── */

.acw-online-count {
    font-family: 'Press Start 2P', monospace;
    font-size: 6px;
    color: var(--acw-online, #39ff6e);
    margin-top: 6px;
    line-height: 1;
    text-shadow: 0 0 4px color-mix(in srgb, var(--acw-online, #39ff6e) 40%, transparent);
}

/* ── Badge (unread overlay) ─────────────────────────────────────────── */

.acw-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--acw-accent, #ff2e9c);
    color: var(--acw-ink-on-accent, #0a0612);
    font-family: 'Press Start 2P', monospace;
    font-size: 7px;
    min-width: 14px;
    height: 14px;
    padding: 0 3px;
    border-radius: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: acw-pulse 1s ease-in-out infinite;
    line-height: 1;
}

@keyframes acw-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

/* ── Expanded Header ────────────────────────────────────────────────── */

.acw-header {
    background: var(--acw-accent, #ff2e9c);
    color: var(--acw-ink-on-accent, #0a0612);
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    letter-spacing: 0.1em;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    padding: 0 12px;
    border-left: 2px solid var(--acw-accent, #ff2e9c);
    border-right: 2px solid var(--acw-accent, #ff2e9c);
    border-bottom: 2px solid var(--acw-accent, #ff2e9c);
    border-top: none;
    transition: max-height 0.3s ease, opacity 0.2s ease, padding 0.3s ease;
}

.acw.expanded .acw-header {
    max-height: 40px;
    opacity: 1;
    padding: 8px 12px;
    width: 320px;
    box-sizing: border-box;
}

.acw.minimized .acw-header {
    max-height: 0;
    opacity: 0;
    padding: 0 12px;
}

.acw-header-title {
    letter-spacing: 0.1em;
}

.acw-minimize {
    background: none;
    border: none;
    color: var(--acw-ink-on-accent, #0a0612);
    font-size: 14px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.acw-minimize:hover {
    opacity: 0.7;
}

/* ── Expanded Window ───────────────────────────────────────────────── */

.acw-window {
    background: var(--acw-bg-panel, #150b29);
    border: 2px solid var(--acw-border, #3a2d5c);
    border-top: none;
    border-radius: 0 0 12px 12px;
    overflow: hidden;
    max-height: 0;
    opacity: 0;
    transition: max-height 0.3s ease, opacity 0.2s ease;
    display: flex;
    flex-direction: column;
}

.acw.expanded .acw-window {
    max-height: 450px;
    opacity: 1;
    width: 320px;
}

.acw.minimized .acw-window {
    max-height: 0;
    opacity: 0;
}

/* ── Name Row ──────────────────────────────────────────────────────── */

.acw-name-row {
    padding: 6px 12px;
    border-bottom: 1px solid var(--acw-border, #3a2d5c);
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.acw-my-name {
    font-size: 14px;
    color: var(--acw-online, #39ff6e);
    font-family: 'Courier Prime', monospace;
}

.acw-edit-name,
.acw-pick-color {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    padding: 2px;
    color: var(--acw-text-dim, #8a7fa8);
}

.acw-edit-name:hover,
.acw-pick-color:hover {
    opacity: 0.7;
}

/* ── Name Input ────────────────────────────────────────────────────── */

.acw-name-input {
    background: var(--acw-ink-on-accent, #0a0612);
    border: 1px solid var(--acw-online, #39ff6e);
    color: var(--acw-text, #f0f8ff);
    font-family: 'Courier Prime', monospace;
    font-size: 16px;
    padding: 6px 8px;
    border-radius: 2px;
    width: 140px;
    max-width: 140px;
    outline: none;
}

/* ── Color Picker ──────────────────────────────────────────────────── */

.acw-color-popup {
    position: absolute;
    right: 12px;
    background: var(--acw-bg-panel, #150b29);
    border: 1px solid var(--acw-border, #3a2d5c);
    border-radius: 4px;
    padding: 8px;
    z-index: 100;
    min-width: 180px;
}

.acw-color-strip {
    width: 100%;
    height: 20px;
    border-radius: 3px;
    cursor: crosshair;
    position: relative;
    margin-bottom: 8px;
    background: linear-gradient(to right,
        hsl(0,100%,50%), hsl(30,100%,50%), hsl(60,100%,50%),
        hsl(90,100%,50%), hsl(120,100%,50%), hsl(150,100%,50%),
        hsl(180,100%,50%), hsl(210,100%,50%), hsl(240,100%,50%),
        hsl(270,100%,50%), hsl(300,100%,50%), hsl(330,100%,50%),
        hsl(360,100%,50%));
}

.acw-color-preview-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--acw-text-dim, #8a7fa8);
}

.acw-color-preview {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 1px solid var(--acw-border, #3a2d5c);
}

.acw-color-reset-btn {
    background: none;
    border: 1px solid var(--acw-border, #3a2d5c);
    color: var(--acw-text-dim, #8a7fa8);
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 3px;
    cursor: pointer;
    margin-left: auto;
}

.acw-color-reset-btn:hover {
    border-color: var(--acw-accent, #ff2e9c);
    color: var(--acw-accent, #ff2e9c);
}

/* ── Tabs ──────────────────────────────────────────────────────────── */

.acw-tabs {
    display: flex;
    border-bottom: 1px solid var(--acw-border, #3a2d5c);
    flex-shrink: 0;
}

.acw-tab {
    flex: 1;
    background: none;
    border: none;
    color: var(--acw-text-muted, #5a5a6a);
    font-family: 'Press Start 2P', monospace;
    font-size: 7px;
    padding: 8px;
    cursor: pointer;
    transition: color 0.15s, background 0.15s;
    letter-spacing: 0.05em;
}

.acw-tab:hover {
    color: var(--acw-text-dim, #8a7fa8);
}

.acw-tab.active {
    color: var(--acw-accent, #ff2e9c);
    background: color-mix(in srgb, var(--acw-accent, #ff2e9c) 10%, transparent);
    border-bottom: 2px solid var(--acw-accent, #ff2e9c);
}

/* ── Messages ──────────────────────────────────────────────────────── */

.acw-messages {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px;
    min-height: 120px;
    max-height: 280px;
    scrollbar-width: thin;
    scrollbar-color: var(--acw-border, #3a2d5c) transparent;
}

.acw-messages::-webkit-scrollbar {
    width: 6px;
}

.acw-messages::-webkit-scrollbar-track {
    background: transparent;
}

.acw-messages::-webkit-scrollbar-thumb {
    background: var(--acw-border, #3a2d5c);
    border-radius: 3px;
}

.acw-msg {
    font-size: 16px;
    color: var(--acw-text-dim, #8a7fa8);
    margin-bottom: 4px;
    line-height: 1.4;
}

.acw-msg.system {
    color: var(--acw-text-muted, #5a5a6a);
    font-style: italic;
    font-size: 14px;
}

.acw-msg .chat-name {
    font-weight: bold;
}

/* ── Online Panel ──────────────────────────────────────────────────── */

.acw-online-panel {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px;
    max-height: 280px;
    min-height: 120px;
}

.acw-online-user {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.acw-online-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.acw-online-name {
    font-family: 'Courier Prime', monospace;
    font-size: 14px;
    color: var(--acw-text, #f0f8ff);
}

.acw-online-status {
    font-size: 12px;
    color: var(--acw-text-muted, #5a5a6a);
    margin-left: auto;
}

/* Connected, but their page says nobody is at it. Still listed — they are in
   the room and may come back — but dimmed, and left out of the header count. */
.acw-online-user.acw-away .acw-online-name,
.acw-online-user.acw-away .acw-online-status {
    opacity: 0.45;
}

.acw-online-user.acw-away .acw-online-dot {
    opacity: 0.3;
}

/* ── Typing Indicator ──────────────────────────────────────────────── */

.acw-typing {
    font-size: 12px;
    color: var(--acw-text-muted, #5a5a6a);
    padding: 4px 12px;
    font-style: italic;
    flex-shrink: 0;
}

/* ── Input ─────────────────────────────────────────────────────────── */

.acw-input {
    display: flex;
    border-top: 1px solid var(--acw-border, #3a2d5c);
    flex-shrink: 0;
}

.acw-input input {
    flex: 1;
    background: var(--acw-ink-on-accent, #0a0612);
    border: none;
    padding: 10px 12px;
    color: var(--acw-text, #f0f8ff);
    font-family: 'Courier Prime', monospace;
    font-size: 16px;
    outline: none;
}

.acw-input input::placeholder {
    color: var(--acw-text-muted, #5a5a6a);
}

.acw-input input:focus {
    background: var(--acw-bg-input, #0f0a1a);
}

.acw-input button {
    background: var(--acw-accent, #ff2e9c);
    border: none;
    padding: 10px 16px;
    color: var(--acw-ink-on-accent, #0a0612);
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s;
}

.acw-input button:hover {
    background: var(--acw-accent-hover, #ff5ab5);
}

/* ── Disconnected State ────────────────────────────────────────────── */

.acw.disconnected .acw-bar {
    border-color: var(--acw-text-muted, #5a5a6a);
    opacity: 0.7;
}

.acw.disconnected .acw-icon {
    background: var(--acw-text-muted, #5a5a6a);
}

.acw.disconnected .acw-icon::after {
    border-left-color: var(--acw-text-muted, #5a5a6a);
    border-top-color: var(--acw-text-muted, #5a5a6a);
}

/* ── Mobile ────────────────────────────────────────────────────────── */

@media (max-width: 600px) {
    .acw {
        bottom: 16px;
        right: 16px;
        left: auto;
        width: 48px;
    }

    .acw-bar {
        border-radius: 14px;
    }

    .acw.expanded .acw-bar {
        border-radius: 14px 14px 0 0;
    }

    .acw-window {
        border-radius: 0 0 14px 14px;
        max-height: 0;
    }

    .acw.expanded .acw-window {
        max-height: 60vh;
    }

    .acw-messages {
        max-height: 40vh;
    }

    .acw-online-panel {
        max-height: 40vh;
    }

    /* larger touch targets */
    .acw-header-btn { padding: 6px 8px; font-size: 16px; }
    .acw-minimize { padding: 6px 8px; font-size: 16px; }
    .acw-edit-name,
    .acw-pick-color { padding: 8px; font-size: 16px; }
    .acw-tab { padding: 12px 8px; }
    .acw-input button { padding: 12px 20px; }
}
