:root {
    /* Color Palette - Neon Cyberpunk / Synthwave */
    --bg-dark: #0a0a0f;
    --bg-panel: rgba(18, 18, 25, 0.85);
    --border-glow: rgba(0, 255, 242, 0.4);
    
    --text-main: #e2e8f0;
    --text-dim: #94a3b8;
    
    --neon-blue: #00fff2;
    --neon-pink: #ff00ea;
    --neon-purple: #8a2be2;
    
    --font-ui: 'Inter', system-ui, sans-serif;
    --font-mono: 'Fira Code', monospace;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: var(--font-ui);
    height: 100vh;
    overflow: hidden;
    position: relative;
    background: radial-gradient(circle at 50% 120%, rgba(138, 43, 226, 0.15), var(--bg-dark) 80%);
}

.app-container {
    width: 100vw;
    height: 100vh;
    position: relative;
    filter: blur(5px);
    transition: filter 1s ease;
}

.app-container.ready {
    filter: blur(0);
}

/* INIT OVERLAY */
.init-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(10, 10, 15, 0.85);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(10px);
    transition: opacity 1s ease;
}

.init-content {
    text-align: center;
    background: var(--bg-panel);
    padding: 3rem 4rem;
    border-radius: 12px;
    border: 1px solid var(--border-glow);
    box-shadow: 0 0 40px rgba(0, 255, 242, 0.2);
}

.init-content h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    background: linear-gradient(90deg, var(--neon-blue), var(--neon-pink));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: 2px;
}

.init-content p {
    font-size: 1.2rem;
    color: var(--text-dim);
    margin-bottom: 2rem;
}

.massive-btn {
    font-size: 1.2rem;
    padding: 1rem 3rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 1.5rem;
}

/* CHARACTER PICKER GRID */
.character-grid {
    display: flex;
    gap: 1.5rem;
    justify-content: center;
    margin: 1.5rem 0 0.5rem;
    flex-wrap: wrap;
}

.character-card {
    background: rgba(255,255,255,0.04);
    border: 2px solid rgba(0,255,242,0.2);
    border-radius: 16px;
    padding: 1.5rem 1.8rem;
    cursor: pointer;
    text-align: center;
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
    min-width: 150px;
    animation: cardIn 0.5s ease both;
}

.character-card:nth-child(2) { animation-delay: 0.12s; }

@keyframes cardIn {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}

.character-card:hover {
    transform: translateY(-4px);
    border-color: var(--neon-blue);
    box-shadow: 0 0 24px rgba(0,255,242,0.25);
}

.character-card.selected {
    border-color: var(--neon-pink);
    box-shadow: 0 0 32px rgba(255,0,234,0.4);
    background: rgba(255,0,234,0.08);
}

.char-emoji {
    font-size: 3rem;
    margin-bottom: 0.5rem;
    line-height: 1;
}

.char-name {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 0.3rem;
}

.char-tagline {
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-bottom: 1rem;
    line-height: 1.4;
}

.char-select-btn {
    background: linear-gradient(135deg, var(--neon-blue), var(--neon-purple));
    color: #fff;
    border: none;
    padding: 0.5rem 1.2rem;
    border-radius: 30px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
}

.char-select-btn:hover { opacity: 0.85; }


/* BACKGROUND CANVAS */
.canvas-container {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
}

#webgl-canvas {
    width: 100%;
    height: 100%;
    z-index: 1;
}

.canvas-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        transparent 50%,
        rgba(0, 0, 0, 0.25) 50%
    );
    background-size: 100% 4px;
    z-index: 2;
    pointer-events: none;
    opacity: 0.1;
}

/* AI BRAIN CONSOLE - RIGHT SIDEBAR */
.ai-console {
    position: absolute;
    top: 6rem;
    right: 2rem;
    width: 400px;
    height: calc(100vh - 16rem); /* leave room for chat */
    background: var(--bg-panel);
    border: 1px solid var(--border-glow);
    border-radius: 8px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    backdrop-filter: blur(10px);
    z-index: 10;
    box-shadow: 0 0 30px rgba(0, 255, 242, 0.1);
}

.ai-console.hidden {
    display: none;
}

.top-actions {
    position: absolute;
    top: 2rem;
    right: 2rem;
    z-index: 100;
    display: flex;
    gap: 1rem;
}

.terminal-toggle {
    background: rgba(0, 255, 242, 0.1);
    border: 1px solid var(--neon-blue);
    color: var(--neon-blue);
    padding: 0.5rem 1rem;
    font-family: var(--font-ui);
    font-weight: 600;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.3s ease;
}

.terminal-toggle:hover {
    background: var(--neon-blue);
    color: var(--bg-dark);
}

/* SPEECH BUBBLE LAYER */
.speech-bubble {
    position: absolute;
    top: 25%;
    left: 55%;
    max-width: 320px;
    background: var(--bg-panel);
    border: 1px solid var(--neon-blue);
    padding: 1.5rem;
    border-radius: 16px;
    border-bottom-left-radius: 0px; /* Abstraction of a speech tail pointing left */
    box-shadow: 0 0 25px rgba(0, 255, 242, 0.3);
    z-index: 50;
    transition: opacity 0.3s cubic-bezier(0.25, 0.8, 0.25, 1), transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    backdrop-filter: blur(15px);
}

.speech-bubble.hidden {
    opacity: 0;
    transform: translateY(15px) scale(0.95);
    pointer-events: none;
}

#speech-text {
    font-size: 1.15rem;
    font-family: var(--font-ui);
    line-height: 1.5;
    color: var(--neon-blue);
    text-shadow: 0 0 8px rgba(0, 255, 242, 0.3);
    font-style: italic;
    font-weight: 500;
}

.console-header h2 {
    font-size: 1.2rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2px;
    background: linear-gradient(90deg, var(--neon-blue), var(--neon-pink));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.5rem;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-dim);
    letter-spacing: 1px;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.1);
    padding-bottom: 1rem;
    margin-bottom: 1rem;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--neon-blue);
    box-shadow: 0 0 8px var(--neon-blue);
}

.status-dot.active {
    background-color: var(--neon-pink);
    box-shadow: 0 0 10px var(--neon-pink);
    animation: flash 1s infinite alternate;
}

@keyframes flash {
    0% { opacity: 0.5; }
    100% { opacity: 1; }
}

.console-body {
    flex-grow: 1;
    overflow: hidden;
    position: relative;
    border-radius: 6px;
    background: #050508;
    border: 1px solid rgba(0, 255, 242, 0.2);
}

pre {
    padding: 1rem;
    height: 100%;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border-glow) transparent;
}

pre::-webkit-scrollbar { width: 6px; }
pre::-webkit-scrollbar-thumb { background: var(--border-glow); border-radius: 3px; }

.json-log {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--neon-blue);
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-all;
}


/* CHAT INTERFACE - BOTTOM CENTER */
.chat-interface {
    position: absolute;
    bottom: 3rem;
    left: 50%;
    transform: translateX(-50%);
    width: 60%;
    max-width: 800px;
    z-index: 20;
}

.chat-bar {
    display: flex;
    gap: 1rem;
    background: var(--bg-panel);
    padding: 1rem;
    border-radius: 12px;
    border: 1px solid var(--border-glow);
    backdrop-filter: blur(10px);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

#user-input {
    flex-grow: 1;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    padding: 0.8rem 1rem;
    color: var(--text-main);
    font-family: var(--font-ui);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.3s;
}

#user-input:focus {
    border-color: var(--neon-pink);
    box-shadow: inset 0 0 10px rgba(255, 0, 234, 0.1);
}

.action-btn {
    background: rgba(0, 255, 242, 0.1);
    border: 1px solid var(--neon-blue);
    color: var(--neon-blue);
    padding: 0 2rem;
    font-family: var(--font-ui);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.action-btn:hover {
    background: var(--neon-blue);
    color: var(--bg-dark);
    box-shadow: 0 0 20px rgba(0, 255, 242, 0.4);
}

.action-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: transparent;
    border-color: var(--text-dim);
    color: var(--text-dim);
}

/* ---- MOBILE RESPONSIVENESS ---- */
@media (max-width: 768px) {
    /* Prevent canvas from hijacking page touch-scroll events */
    canvas {
        touch-action: none;
        user-select: none;
        -webkit-user-select: none;
    }

    /* Stack top actions seamlessly */
    .top-actions {
        flex-direction: column;
        top: 0.75rem;
        right: 0.75rem;
        gap: 0.4rem;
    }
    
    /* Hide the AI Brain Console entirely on Mobile */
    #terminal-toggle-btn {
        display: none !important;
    }

    .ai-console {
        display: none !important;
    }

    /* Maximize chat interface flush against bottom — full width */
    .chat-interface {
        width: 100%;
        bottom: 0;
        left: 0;
        transform: none;
        border-radius: 0;
        border-bottom: none;
        padding: 0.6rem;
    }
    
    /* Keep chat-bar horizontal on mobile (input left, button right) */
    .chat-bar {
        flex-direction: row;
        gap: 0.5rem;
        padding: 0.5rem;
        align-items: center;
    }

    /* Full-width input, large enough font to prevent iOS auto-zoom */
    #user-input {
        flex: 1;
        font-size: 1rem; /* iOS zooms in if font-size < 16px */
        padding: 0.7rem;
        min-height: 48px; /* Apple HIG minimum tap target for kids */
    }
    
    /* Square send button — large tap target */
    .action-btn {
        min-width: 48px;
        min-height: 48px;
        padding: 0.7rem 1rem;
        font-size: 0.95rem;
        flex-shrink: 0;
    }

    /* Scale Down massive Start Screen */
    .init-content {
        padding: 2rem 1.2rem;
        width: 92%;
    }
    
    .init-content h1 {
        font-size: 1.6rem;
    }

    .massive-btn {
        padding: 1rem;
        font-size: 1rem;
        min-height: 56px; /* Extra large for kids */
    }

    /* Speech Bubble above chat bar on mobile */
    .speech-bubble {
        left: 50%;
        bottom: 90px; /* sits above the chat bar */
        top: auto;
        transform: translateX(-50%);
        width: 92%;
        max-width: 100%;
        text-align: center;
        border-bottom-left-radius: 16px;
    }

    .speech-bubble.hidden {
        transform: translate(-50%, 10px) scale(0.95);
    }
}
