/* ───────────────────────────────────────────────────────────────
   sprite-chat.css — AI Sprite + Chat Dialog styles
─────────────────────────────────────────────────────────────── */

/* Sprite container (floating bottom-right, above music player) */
#sprite-container {
    position: fixed;
    bottom: 120px;
    right: 20px;
    width: 120px;
    height: 120px;
    z-index: 3000;
    pointer-events: auto;
    cursor: grab;
    filter: drop-shadow(0 0 18px rgba(108, 99, 255, 0.4));
    transition: filter 0.3s ease;
}

/* The canvas is rendered larger than its box — that overflow is the halo.
   Centre it, or the grab area sits up-and-left of the sprite you can see:
   its lower-right corner would be unclickable and its top-left corner would
   be empty space that drags. Matters now that the box is a drag handle. */
#sprite-container > canvas {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}

/* Shown when WebGL is unavailable — it still opens the chat and still drags. */
.sprite-fallback {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3.2rem;
    user-select: none;
}

#sprite-container:hover {
    filter: drop-shadow(0 0 28px rgba(108, 99, 255, 0.7));
}

#sprite-clock {
    position: fixed;
    right: 12px;
    bottom: 26px;
    /* The scaling anchor: every size below is in `em`, so setting this one
       value resizes date, time and meta together and in proportion. */
    font-size: 1rem;
    min-width: 8.5em;
    padding: 0.45em 0.65em 0.5em;
    border-radius: 0.75em;
    border: 1px solid rgba(132, 148, 255, 0.35);
    background: rgba(9, 12, 28, 0.72);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 8px 22px rgba(12, 16, 38, 0.45);
    z-index: 2998;
    /* Was `none` while it was purely decorative. It has a grip now. */
    pointer-events: auto;
    cursor: grab;
    text-align: center;
}

.sprite-clock-date {
    color: #cfd6ff;
    font-family: var(--font-display);
    font-size: 0.72em;
    letter-spacing: 0.06em;
    opacity: 0.92;
    margin-bottom: 0.2em;
}

.sprite-clock-time {
    color: #f4f6ff;
    font-family: var(--font-mono);
    font-size: 1.05em;
    line-height: 1;
    letter-spacing: 0.04em;
    font-weight: 700;
    text-shadow: 0 0 12px rgba(144, 161, 255, 0.45);
}

.sprite-clock-meta {
    color: #9ba8da;
    margin-top: 0.3em;
    font-size: 0.62em;
    line-height: 1.1;
    white-space: nowrap;
    max-width: 18em;
    overflow: hidden;
    text-overflow: ellipsis;
}

#sprite-clock.tick {
    animation: clockTick 380ms ease;
}

@keyframes clockTick {
    0% {
        transform: translateY(0) scale(1);
        border-color: rgba(132, 148, 255, 0.35);
    }

    35% {
        transform: translateY(-1px) scale(1.015);
        border-color: rgba(162, 180, 255, 0.58);
    }

    100% {
        transform: translateY(0) scale(1);
        border-color: rgba(132, 148, 255, 0.35);
    }
}

/* ── Chat Dialog ─────────────────────────────────────────────── */
.chat-dialog {
    position: fixed;
    bottom: 160px;
    right: 160px;
    width: 360px;
    /* The second term is the floor on a short window (or a phone in
       landscape): 520px of panel on a 400px viewport can only hang off the
       screen, whatever the positioning code does about it. */
    max-height: min(520px, calc(100vh - 2rem));
    background: rgba(8, 8, 18, 0.92);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid rgba(108, 99, 255, 0.25);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 2999;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(108, 99, 255, 0.1);
    transform: scale(0.9) translateY(10px);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
}

.chat-dialog.open {
    transform: scale(1) translateY(0);
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.chat-dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid rgba(108, 99, 255, 0.15);
    background: rgba(108, 99, 255, 0.08);
}

.chat-dialog-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: #c8c8f0;
}

.chat-dialog-close {
    background: none;
    border: none;
    color: #666;
    font-size: 1.2rem;
    transition: color 0.2s;
}

.chat-dialog-close:hover {
    color: #ccc;
}

.chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    /* Reaching the end of a reply must not hand the rest of the wheel gesture
       to the page underneath — the dialog is a fixed overlay, so the page
       scrolling out from behind it is pure disorientation. */
    overscroll-behavior: contain;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    scrollbar-width: thin;
    scrollbar-color: rgba(108, 99, 255, 0.3) transparent;
}

.msg {
    max-width: 85%;
    padding: 0.6rem 0.85rem;
    border-radius: 12px;
    font-size: 0.85rem;
    line-height: 1.55;
}

.msg-user {
    align-self: flex-end;
    background: rgba(108, 99, 255, 0.25);
    border: 1px solid rgba(108, 99, 255, 0.3);
}

.msg-ai {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0.6rem 0.85rem;
    align-self: flex-start;
}

.typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    animation: typingBounce 1.2s infinite ease-in-out;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {

    0%,
    80%,
    100% {
        transform: scale(0.8);
        opacity: 0.4;
    }

    40% {
        transform: scale(1.2);
        opacity: 1;
    }
}

.chat-dialog-footer {
    padding: 0.75rem;
    border-top: 1px solid rgba(108, 99, 255, 0.15);
    display: flex;
    gap: 0.5rem;
}

#chat-input {
    flex: 1;
    padding: 0.55rem 0.85rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(108, 99, 255, 0.2);
    border-radius: 999px;
    font-size: 0.85rem;
    color: var(--text-1);
    transition: border-color 0.2s;
}

#chat-input:focus {
    border-color: rgba(108, 99, 255, 0.5);
    outline: none;
}

#chat-send {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    color: #fff;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

#chat-send:hover {
    background: #7c74ff;
    transform: scale(1.08);
}

/* ── Mobile adjustments ──────────────────────────────────────── */
@media (max-width: 768px) {
    .chat-dialog {
        width: calc(100vw - 2rem);
        right: 1rem;
        left: 1rem;
        bottom: 150px;
    }

    #sprite-container {
        bottom: 90px;
        width: 90px;
        height: 90px;
    }

    #sprite-clock {
        right: 10px;
        bottom: 16px;
        /* One knob, same as the resize handle uses. */
        font-size: 0.88rem;
    }
}

.chat-dialog-actions {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.chat-mini-btn {
    border: 1px solid rgba(108, 99, 255, 0.35);
    background: rgba(108, 99, 255, 0.12);
    color: #d6d4ff;
    border-radius: 999px;
    font-size: 0.72rem;
    padding: 0.25rem 0.55rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.chat-mini-btn:hover {
    background: rgba(108, 99, 255, 0.26);
    border-color: rgba(108, 99, 255, 0.65);
}