/*
--------------------------------------------------------------------------------
ROOTie Bot — Retro AI Assistant Widget
8bitRoot Design System
--------------------------------------------------------------------------------
*/

/* =========================================================
   FLOATING BUTTON (Bottom-right)
   ========================================================= */
.rootie-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9000;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: transform 0.3s ease;
}

.rootie-fab:hover {
    transform: scale(1.12);
}

.rootie-fab:hover .rootie-sprite-wrap {
    filter: drop-shadow(0 0 12px var(--color-primary));
}

.rootie-sprite-wrap {
    width: 52px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: rootie-bounce 2s ease-in-out infinite;
    transition: filter 0.3s ease;
}

.rootie-sprite-wrap svg {
    width: 44px;
    height: 44px;
}

/* Mood-based sprite animations */
.rootie-fab[data-mood="happy"] .rootie-sprite-wrap   { animation: rootie-bounce 1.5s ease-in-out infinite; }
.rootie-fab[data-mood="normal"] .rootie-sprite-wrap   { animation: rootie-bounce 2.5s ease-in-out infinite; }
.rootie-fab[data-mood="sad"] .rootie-sprite-wrap      { animation: rootie-sad 3s ease-in-out infinite; }
.rootie-fab[data-mood="sleeping"] .rootie-sprite-wrap  { animation: rootie-sleep 4s ease-in-out infinite; opacity: 0.5; }
.rootie-fab[data-mood="euphoric"] .rootie-sprite-wrap  { animation: rootie-euphoric 0.8s ease-in-out infinite; filter: drop-shadow(0 0 16px var(--color-primary)); }

/* Energy bar below sprite */
.rootie-energy-bar {
    width: 48px;
    height: 8px;
    background: rgba(0,0,0,0.5);
    border: 1px solid rgba(255,255,255,0.2);
    display: flex;
    gap: 1px;
    padding: 1px;
    image-rendering: pixelated;
}

.rootie-energy-segment {
    flex: 1;
    background: var(--color-primary);
    transition: background 0.3s ease, opacity 0.3s ease;
}

.rootie-energy-segment.empty {
    background: rgba(255,255,255,0.08);
}

.rootie-energy-bar[data-level="low"] .rootie-energy-segment:not(.empty) {
    background: var(--color-danger);
    animation: energy-blink 1s ease-in-out infinite;
}

/* Notification badge */
.rootie-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 14px;
    height: 14px;
    background: var(--color-secondary);
    border-radius: 50%;
    border: 2px solid var(--bg-main);
    animation: badge-pulse 2s ease-in-out infinite;
    display: none;
}

.rootie-badge.show { display: block; }

/* ZZZ indicator */
.rootie-zzz {
    position: absolute;
    top: -8px;
    right: -6px;
    font-family: var(--font-retro);
    font-size: 8px;
    color: var(--color-primary);
    opacity: 0;
    display: none;
}

.rootie-fab[data-mood="sleeping"] .rootie-zzz {
    display: block;
    animation: zzz-float 2s ease-in-out infinite;
}

/* =========================================================
   CHAT PANEL (RPG Dialog Box)
   ========================================================= */
.rootie-panel {
    position: fixed;
    bottom: 90px;
    right: 24px;
    width: 380px;
    max-height: 560px;
    z-index: 9001;
    display: flex;
    flex-direction: column;
    background: rgba(13, 17, 23, 0.96);
    -webkit-backdrop-filter: blur(16px);
    backdrop-filter: blur(16px);
    border: 2px solid rgba(0, 245, 212, 0.3);
    border-radius: 12px;
    box-shadow:
        0 0 0 1px rgba(0, 245, 212, 0.1),
        0 20px 60px rgba(0,0,0,0.7),
        inset 0 1px 0 rgba(255,255,255,0.05);
    overflow: hidden;
    transform: scale(0.9) translateY(20px);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s ease;
}

.rootie-panel.open {
    transform: scale(1) translateY(0);
    opacity: 1;
    pointer-events: all;
}

/* Panel Header */
.rootie-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    background: rgba(0,0,0,0.3);
}

.rootie-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.rootie-header-sprite svg {
    width: 28px;
    height: 28px;
}

.rootie-header-info {
    display: flex;
    flex-direction: column;
}

.rootie-header-name {
    font-family: var(--font-retro);
    font-size: 9px;
    color: var(--color-primary);
    letter-spacing: 1px;
}

.rootie-header-mood {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.rootie-user-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-family: var(--font-main);
    font-size: 0.65rem;
    color: #FBC02D;
    background: rgba(251,192,45,0.12);
    padding: 1px 6px;
    border-radius: 4px;
    margin-left: 6px;
    vertical-align: middle;
}

.rootie-user-badge svg {
    width: 10px;
    height: 10px;
}

.rootie-login-trigger {
    cursor: pointer;
    color: var(--text-muted);
    background: rgba(255,255,255,0.06);
    transition: all 0.2s ease;
}

.rootie-login-trigger:hover {
    color: var(--color-primary);
    background: rgba(0,245,212,0.1);
}

.rootie-header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Hearts display */
.rootie-hearts {
    display: flex;
    gap: 2px;
}

.rootie-hearts svg {
    width: 14px;
    height: 14px;
}

.rootie-hearts svg.heart-full { color: var(--color-secondary); }
.rootie-hearts svg.heart-empty { color: rgba(255,255,255,0.15); }

/* Header energy bar */
.rootie-header-energy {
    display: flex;
    align-items: center;
    gap: 4px;
}

.rootie-header-energy svg {
    width: 12px;
    height: 12px;
    color: var(--color-primary);
}

.rootie-header-energy-bar {
    width: 40px;
    height: 6px;
    background: rgba(255,255,255,0.08);
    border-radius: 0;
    overflow: hidden;
}

.rootie-header-energy-fill {
    height: 100%;
    background: var(--color-primary);
    transition: width 0.5s ease;
}

.rootie-header-energy-fill[data-low="true"] {
    background: var(--color-danger);
    animation: energy-blink 1s ease-in-out infinite;
}

/* Close button */
.rootie-close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    display: flex;
    transition: color 0.2s ease;
}

.rootie-close-btn:hover { color: var(--color-secondary); }
.rootie-close-btn svg { width: 16px; height: 16px; }

/* =========================================================
   MESSAGES AREA
   ========================================================= */
.rootie-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 200px;
    max-height: 300px;
}

.rootie-messages::-webkit-scrollbar { width: 4px; }
.rootie-messages::-webkit-scrollbar-track { background: transparent; }
.rootie-messages::-webkit-scrollbar-thumb { background: rgba(0,245,212,0.2); border-radius: 4px; }

/* Message bubbles */
.rootie-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.85rem;
    line-height: 1.5;
    animation: msg-appear 0.3s ease forwards;
}

.rootie-msg.bot {
    align-self: flex-start;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.08);
    color: #e6edf3;
    border-bottom-left-radius: 4px;
}

.rootie-msg.user {
    align-self: flex-end;
    background: linear-gradient(135deg, rgba(0,245,212,0.15), rgba(0,245,212,0.08));
    border: 1px solid rgba(0,245,212,0.25);
    color: #e6edf3;
    border-bottom-right-radius: 4px;
}

/* Typing indicator */
.rootie-typing {
    display: flex;
    gap: 4px;
    padding: 10px 14px;
    align-self: flex-start;
}

.rootie-typing span {
    width: 6px;
    height: 6px;
    background: var(--color-primary);
    border-radius: 0; /* pixel style */
    animation: typing-dot 1.4s ease-in-out infinite;
}

.rootie-typing span:nth-child(2) { animation-delay: 0.2s; }
.rootie-typing span:nth-child(3) { animation-delay: 0.4s; }

/* Blinking cursor after typewriter text */
.rootie-cursor {
    display: inline-block;
    width: 8px;
    height: 14px;
    background: var(--color-primary);
    margin-left: 2px;
    animation: cursor-blink 0.8s step-end infinite;
    vertical-align: text-bottom;
}

/* Continue indicator */
.rootie-continue {
    display: inline-block;
    font-family: var(--font-retro);
    font-size: 8px;
    color: var(--color-primary);
    animation: continue-blink 1s step-end infinite;
    margin-left: 4px;
}

/* Suggestions */
.rootie-suggestions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
}

.rootie-suggestion-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(0,245,212,0.06);
    border: 1px solid rgba(0,245,212,0.15);
    color: var(--color-primary);
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.8rem;
    font-family: var(--font-main);
    transition: all 0.2s ease;
    text-align: left;
}

.rootie-suggestion-btn:hover {
    background: rgba(0,245,212,0.12);
    border-color: rgba(0,245,212,0.3);
    transform: translateX(4px);
}

.rootie-suggestion-btn svg {
    width: 10px;
    height: 10px;
    flex-shrink: 0;
}

/* =========================================================
   CARE ACTIONS BAR (Tamagotchi)
   ========================================================= */
.rootie-care-bar {
    display: flex;
    justify-content: space-around;
    padding: 8px 16px;
    border-top: 1px solid rgba(255,255,255,0.06);
    background: rgba(0,0,0,0.2);
}

.rootie-care-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 8px;
    transition: all 0.2s ease;
    font-family: var(--font-main);
}

.rootie-care-btn:hover {
    color: var(--color-primary);
    background: rgba(0,245,212,0.08);
}

.rootie-care-btn:active {
    transform: scale(0.9);
}

.rootie-care-btn.on-cooldown {
    opacity: 0.3;
    pointer-events: none;
}

.rootie-care-btn svg { width: 20px; height: 20px; }

.rootie-care-label {
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* =========================================================
   INPUT AREA
   ========================================================= */
.rootie-input-area {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid rgba(255,255,255,0.06);
    background: rgba(0,0,0,0.2);
}

.rootie-input {
    flex: 1;
    background: rgba(255,255,255,0.05) !important;
    border: 1px solid rgba(255,255,255,0.1) !important;
    color: #e6edf3 !important;
    padding: 10px 14px !important;
    border-radius: 8px !important;
    font-size: 0.85rem !important;
    font-family: var(--font-main) !important;
    margin: 0 !important;
    outline: none;
    transition: border-color 0.2s ease;
}

.rootie-input:focus {
    border-color: var(--color-primary) !important;
    box-shadow: 0 0 8px rgba(0,245,212,0.15) !important;
    background: rgba(0,0,0,0.4) !important;
}

.rootie-input::placeholder { color: rgba(255,255,255,0.25); }

.rootie-send-btn {
    background: var(--color-primary);
    border: none;
    color: #000;
    width: 38px;
    height: 38px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.rootie-send-btn:hover { 
    background: #33f7dd;
    box-shadow: 0 0 12px rgba(0,245,212,0.4);
}

.rootie-send-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.rootie-send-btn svg { width: 18px; height: 18px; }

/* =========================================================
   SETUP WIZARD (First visit)
   ========================================================= */
.rootie-setup {
    padding: 24px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.rootie-setup-title {
    font-family: var(--font-retro);
    font-size: 10px;
    color: var(--color-primary);
    letter-spacing: 1px;
}

.rootie-setup-subtitle {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.rootie-setup-sprite svg {
    width: 64px;
    height: 64px;
    animation: rootie-bounce 2s ease-in-out infinite;
}

.rootie-setup-option {
    width: 100%;
    text-align: left;
}

.rootie-setup-option label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
    display: block;
}

.rootie-gender-btns {
    display: flex;
    gap: 10px;
}

.rootie-gender-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    font-family: var(--font-main);
    font-size: 0.85rem;
    transition: all 0.2s ease;
}

.rootie-gender-btn.selected {
    border-color: var(--color-primary);
    background: rgba(0,245,212,0.08);
    color: var(--color-primary);
}

.rootie-gender-btn svg { width: 16px; height: 16px; }

.rootie-color-grid {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.rootie-color-btn {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
}

.rootie-color-btn.selected {
    border-color: #fff;
    transform: scale(1.15);
    box-shadow: 0 0 10px currentColor;
}

.rootie-start-btn {
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, var(--color-primary), #33f7dd);
    border: none;
    color: #000;
    font-family: var(--font-retro);
    font-size: 9px;
    letter-spacing: 1px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.rootie-start-btn:hover {
    box-shadow: 0 0 20px rgba(0,245,212,0.4);
    transform: translateY(-2px);
}

/* =========================================================
   CARE ANIMATION OVERLAYS
   ========================================================= */
.rootie-care-anim {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 10;
    opacity: 0;
}

.rootie-care-anim.active {
    animation: care-pop 0.8s ease forwards;
}

/* =========================================================
   KEYFRAMES
   ========================================================= */
@keyframes rootie-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

@keyframes rootie-sad {
    0%, 100% { transform: translateY(0) rotate(-2deg); }
    50% { transform: translateY(-2px) rotate(2deg); }
}

@keyframes rootie-sleep {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-2px); }
}

@keyframes rootie-euphoric {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-8px) scale(1.1); }
}

@keyframes energy-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

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

@keyframes zzz-float {
    0% { opacity: 0; transform: translate(0, 0) scale(0.5); }
    50% { opacity: 1; transform: translate(6px, -12px) scale(1); }
    100% { opacity: 0; transform: translate(12px, -24px) scale(0.8); }
}

@keyframes msg-appear {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes typing-dot {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.3; }
    30% { transform: translateY(-4px); opacity: 1; }
}

@keyframes cursor-blink {
    0%, 50% { opacity: 1; }
    50.01%, 100% { opacity: 0; }
}

@keyframes continue-blink {
    0%, 50% { opacity: 1; }
    50.01%, 100% { opacity: 0; }
}

@keyframes care-pop {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
    50% { opacity: 1; transform: translate(-50%, -50%) scale(1.3); }
    100% { opacity: 0; transform: translate(-50%, -70%) scale(1); }
}

/* =========================================================
   RESPONSIVE (Mobile)
   ========================================================= */
@media (max-width: 768px) {
    .rootie-panel {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-height: 75vh;
        border-radius: 16px 16px 0 0;
        border-bottom: none;
    }

    .rootie-fab {
        bottom: 16px;
        right: 16px;
    }

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