/* ============================================================
   YE-AI V2 — THEME VARIABLES & BASE
   ============================================================ */
:root {
    /* DEFAULT DARK MODE */
    --bg-layer-0: #000000;      /* Lowest layer (backdrop menu) */
    --bg-layer-1: #0a0a0a;      /* App background */
    --bg-layer-2: #141414;      /* Floating elements/cards */
    --bg-layer-3: #222222;      /* Hover states/borders */
    --bg-layer-4: #333333;      /* Input outlines */
    
    --text-primary: #ffffff;
    --text-secondary: #999999;
    --text-tertiary: #666666;
    
    --accent: #ffffff;
    --accent-inv: #000000;
    
    --shadow-header: 0 10px 40px rgba(0,0,0,0.8);
    --shadow-app: -20px 0 50px rgba(0,0,0,0.9);
}

body.light-mode {
    --bg-layer-0: #dcdcdc;      
    --bg-layer-1: #f0f0f0;      
    --bg-layer-2: #ffffff;      
    --bg-layer-3: #e0e0e0;      
    --bg-layer-4: #cccccc;      
    
    --text-primary: #000000;
    --text-secondary: #666666;
    --text-tertiary: #999999;
    
    --accent: #000000;
    --accent-inv: #ffffff;
    
    --shadow-header: 0 10px 40px rgba(0,0,0,0.1);
    --shadow-app: -10px 0 30px rgba(0,0,0,0.2);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }

body {
    background: var(--bg-layer-0);
    color: var(--text-primary);
    font-family: 'Space Mono', monospace;
    -webkit-font-smoothing: antialiased;
    perspective: 1200px;
    transition: background 0.4s ease, color 0.4s ease;
}

/* ============================================================
   BACKDROP 3D MENU
   ============================================================ */
.backdrop-menu {
    position: fixed;
    top: 0; left: 0; width: 45%; height: 100%;
    padding: 60px 40px;
    display: flex; flex-direction: column;
    z-index: 10;
    opacity: 0;
    transform: translateX(-50px);
    transition: opacity 0.5s ease, transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
    pointer-events: none;
}
.backdrop-menu.active {
    opacity: 1;
    transform: translateX(0);
    pointer-events: auto;
}

.menu-title {
    font-size: 2.5rem; letter-spacing: -2px; font-weight: 700;
    margin-bottom: 30px; color: var(--text-primary);
}

.brutalist-btn {
    width: 100%; padding: 16px;
    background: var(--text-primary); color: var(--bg-layer-0);
    border: none; font-family: inherit; font-size: 1.1rem; font-weight: 700;
    letter-spacing: -1px; cursor: pointer; text-transform: uppercase;
    transition: transform 0.15s ease, opacity 0.2s;
    border-radius: 4px;
    margin-bottom: 24px;
}
.brutalist-btn:hover { transform: translateY(-2px); opacity: 0.9; }
.brutalist-btn:active { transform: translateY(2px); }

.chat-list {
    list-style: none; display: flex; flex-direction: column; gap: 8px;
    overflow-y: auto; max-height: 60vh;
    padding-right: 10px; scrollbar-width: none;
}
.chat-list::-webkit-scrollbar { display: none; }

.chat-item {
    font-size: 0.95rem; color: var(--text-secondary);
    padding: 12px 14px; cursor: pointer; border-radius: 4px;
    border-left: 2px solid transparent;
    display: flex; align-items: center; position: relative;
    transition: all 0.2s ease;
}
.chat-item:hover {
    color: var(--text-primary); background: var(--bg-layer-3);
}
.chat-item.active {
    color: var(--text-primary); border-left-color: var(--text-primary);
    background: var(--bg-layer-2); font-weight: 700;
}
.chat-title {
    flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 12px;
}
.chat-actions {
    display: none; position: absolute; right: 10px; gap: 8px;
}
.chat-item:hover .chat-actions { display: flex; }
.chat-action-btn {
    background: none; border: none; color: var(--text-secondary); cursor: pointer;
    transition: color 0.2s; padding: 2px;
}
.chat-action-btn:hover { color: var(--text-primary); }
.chat-action-btn.pin.pinned { color: var(--text-primary); display: block !important; }
.chat-item .chat-action-btn.pin.pinned { position: absolute; right: 12px; display: block; }
.chat-item:hover .chat-action-btn.pin.pinned { position: static; display: block; }

.menu-footer {
    margin-top: auto; display: flex; gap: 16px; color: var(--text-tertiary);
    font-size: 0.85rem; font-weight: 700; padding-top: 20px;
}
.menu-footer a { color: var(--text-secondary); text-decoration: none; transition: color 0.2s; }
.menu-footer a:hover { color: var(--text-primary); text-decoration: underline; text-underline-offset: 4px; }

/* ============================================================
   MAIN APP 3D CONTAINER
   ============================================================ */
.app-container {
    width: 100%; height: 100%; background: var(--bg-layer-1);
    position: absolute; top: 0; left: 0; z-index: 20;
    display: flex; flex-direction: column;
    transform-origin: center right;
    box-shadow: var(--shadow-app);
    /* GSAP WILL HANDLE THE 3D TRANSFORM */
}
.app-overlay {
    position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    background: transparent; z-index: 100;
    pointer-events: none;
    cursor: pointer;
}
.app-overlay.active { pointer-events: auto; }

/* ============================================================
   FLOATING PILL HEADER
   ============================================================ */
.floating-header {
    position: absolute; top: 24px; left: 50%; transform: translateX(-50%);
    width: 90%; max-width: 800px;
    background: var(--bg-layer-2);
    border: 1px solid var(--bg-layer-3);
    border-radius: 100px;
    padding: 10px 20px;
    display: flex; justify-content: space-between; align-items: center;
    z-index: 50;
    box-shadow: var(--shadow-header);
    transition: background 0.4s, border-color 0.4s;
}

/* Left: Hamburger + Logo */
.header-left { display: flex; align-items: center; gap: 16px; }

/* Custom X menu button */
.menu-btn {
    width: 32px; height: 32px; background: none; border: none; cursor: pointer;
    position: relative; display: flex; justify-content: center; align-items: center;
}
.cross-line {
    position: absolute; width: 20px; height: 2px;
    background: var(--text-primary); border-radius: 2px;
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), background 0.4s;
}
.cross-line.one { transform: translateY(-4px); }
.cross-line.two { transform: translateY(4px); }

/* GSAP active states will be handled by classes */
.menu-btn.open .cross-line.one { transform: rotate(45deg); }
.menu-btn.open .cross-line.two { transform: rotate(-45deg); }

.header-logo {
    width: 32px; height: 32px; border-radius: 50%;
    object-fit: cover; filter: grayscale(100%) contrast(1.2);
    cursor: pointer;
}

/* Center: Persona Selector */
.header-center {
    display: flex; justify-content: center; flex: 1;
}
.persona-selector {
    display: flex; background: var(--bg-layer-1); border-radius: 100px;
    padding: 4px; border: 1px solid var(--bg-layer-3);
    gap: 4px;
}
.persona-btn {
    background: transparent; border: none; color: var(--text-secondary);
    font-family: inherit; font-size: 0.75rem; font-weight: 700;
    padding: 6px 16px; border-radius: 100px; cursor: pointer;
    transition: all 0.25s ease; letter-spacing: 1px;
}
.persona-btn:hover { color: var(--text-primary); }
.persona-btn.active {
    background: var(--text-primary); color: var(--bg-layer-0); box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}

/* Right: Theme Toggle & PFP */
.header-right { display: flex; align-items: center; gap: 16px; }

.theme-toggle {
    background: none; border: none; color: var(--text-primary);
    cursor: pointer; display: flex; align-items: center;
    transition: transform 0.2s ease, color 0.4s ease;
}
.theme-toggle:hover { transform: scale(1.1); }

.pfp-img {
    width: 32px; height: 32px; border-radius: 50%;
    object-fit: cover; border: 2px solid var(--bg-layer-4);
    transition: border-color 0.3s ease, transform 0.2s ease;
    filter: grayscale(30%);
}
.pfp-link:hover .pfp-img { border-color: var(--text-primary); transform: scale(1.08); }

/* ============================================================
   CHAT MAIN
   ============================================================ */
main {
    flex: 1; overflow-y: auto;
    padding: 100px 24px 140px; /* Top padding to account for floating header */
    display: flex; flex-direction: column; align-items: center; /* Center content horizontally */
    gap: 24px; scrollbar-width: none;
}
main::-webkit-scrollbar { display: none; }

/* Wrapper for messages to constrain width centrally */
.messages-wrapper {
    width: 100%; max-width: 50rem; display: flex; flex-direction: column; gap: 24px;
}

/* ===== WELCOME ===== */
.welcome {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    text-align: center; padding: 60px 24px 40px; gap: 20px; opacity: 0;
    width: 100%; max-width: 50rem;
}
.glitch-wrapper {
    position: relative; line-height: 0;
}
.welcome-logo {
    width: 140px; height: 140px; border-radius: 20px;
    object-fit: cover; filter: grayscale(100%) contrast(1.3);
    border: 3px solid var(--bg-layer-3); cursor: pointer;
}
.welcome h2 {
    font-size: 2.5rem; font-weight: 700; letter-spacing: -2px; color: var(--text-primary);
}
.welcome p {
    font-size: 1rem; color: var(--text-secondary); max-width: 300px; line-height: 1.5;
}
.prompt-suggestions {
    display: flex; flex-direction: column; width: 100%; max-width: 400px; gap: 10px; margin-top: 20px;
}
.split-btn {
    background: var(--bg-layer-2); border: 1px solid var(--bg-layer-3);
    color: var(--text-secondary); font-family: inherit; font-size: 0.85rem; font-weight: 700;
    padding: 14px 20px; border-radius: 8px; cursor: pointer; transition: all 0.2s ease;
    text-align: left;
}
.split-btn:hover {
    background: var(--bg-layer-3); color: var(--text-primary); transform: translateX(4px);
    border-color: var(--text-secondary);
}

/* ===== MESSAGES ===== */
.message {
    display: flex; gap: 16px; width: 100%; max-width: 50rem;
    opacity: 0; filter: blur(8px); transform: translateY(20px) scale(0.97);
}
/* Both user and AI face left to stay perfectly aligned with input bar */
.ai-msg { align-self: center; }
.user-msg { align-self: center; }

.msg-avatar {
    width: 36px; height: 36px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; overflow: hidden;
}
.ai-msg .msg-avatar { border: 1px solid var(--bg-layer-4); }
.ai-msg .msg-avatar img { width: 100%; height: 100%; object-fit: cover; filter: grayscale(100%) contrast(1.2); }

.user-msg .msg-avatar {
    background: var(--text-primary); color: var(--bg-layer-0);
    font-size: 0.9rem; font-weight: 700; border: none; text-transform: uppercase;
}
.msg-body { font-size: 1rem; line-height: 1.7; width: 100%; }

.ai-msg .msg-body { color: var(--text-primary); padding-top: 6px; }
.user-msg .msg-body {
    padding: 16px 20px; background: var(--text-primary); color: var(--bg-layer-0);
    font-weight: 600; border-radius: 12px; display: inline-block;
}

/* ===== THINKING CARD ===== */
.thinking-card {
    align-self: center; width: 100%; max-width: 50rem;
    background: var(--bg-layer-2); border: 1px dashed var(--bg-layer-4);
    border-radius: 12px; padding: 16px 20px;
    display: flex; align-items: center; gap: 16px;
    opacity: 0; filter: blur(8px); transform: translateY(20px);
}
.glitch-loader {
    width: 32px; height: 32px; flex-shrink: 0; position: relative;
    border-radius: 6px; overflow: hidden;
}
.glitch-loader img {
    width: 100%; height: 100%; object-fit: cover; filter: grayscale(100%) contrast(1.4);
}

/* Glitch animation handled by GSAP randomly offsetting x/y and scaling */

.thinking-text-stream {
    font-size: 0.85rem; color: var(--text-secondary); font-style: italic; opacity: 0.8;
}

/* ===== FETCHED IMAGE & MOCK IMAGE GEN ===== */
.fetched-image {
    max-width: 100%; max-height: 500px;
    border-radius: 8px; border: 2px solid var(--bg-layer-4);
    margin: 20px 0 10px; display: block; object-fit: contain;
    background: var(--bg-layer-0); opacity: 0; filter: blur(10px);
    transition: none; /* GSAP handles */
}

/* ===== INPUT ===== */
.input-area {
    position: absolute; bottom: 0; left: 0; right: 0;
    padding: 0 24px 32px; 
    background: linear-gradient(to top, var(--bg-layer-1) 75%, transparent); z-index: 50;
    display: flex; justify-content: center;
}
.input-wrapper {
    width: 100%; max-width: 50rem;
    display: flex; align-items: center; background: var(--bg-layer-2); border: 2px solid var(--bg-layer-3);
    border-radius: 100px; padding: 8px 8px 8px 24px; transition: border-color 0.3s ease, box-shadow 0.3s ease;
    box-shadow: 0 20px 40px rgba(0,0,0,0.5);
}
.input-wrapper:focus-within {
    border-color: var(--text-secondary);
}
input {
    flex: 1; border: none; outline: none; background: transparent; color: var(--text-primary);
    font-size: 1rem; font-family: inherit; font-weight: 500;
}
input::placeholder { color: var(--text-tertiary); }
#sendBtn {
    width: 44px; height: 44px; border-radius: 50%; border: none; background: var(--text-primary); color: var(--bg-layer-0);
    display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0;
    transition: transform 0.15s ease, opacity 0.25s ease;
}
#sendBtn:hover { transform: scale(1.05); }
#sendBtn:active { transform: scale(0.92); }
#sendBtn:disabled { opacity: 0.15; cursor: not-allowed; transform: none; }

.error-msg {
    color: #ff4444; font-size: 0.85rem; padding: 12px 16px; margin-top: 10px;
    background: rgba(255,68,68,0.1); border: 1px dashed rgba(255,68,68,0.3); border-radius: 8px; font-weight: 700;
}

/* ===== MARKDOWN ===== */
.md-content { font-size: 1rem; line-height: 1.8; color: var(--text-primary); }
.md-content p { margin-bottom: 16px; }
.md-content p:last-child { margin-bottom: 0; }
.md-content strong { color: var(--text-primary); font-weight: 700; }
.md-content em { font-style: italic; color: var(--text-secondary); }
.md-content h1, .md-content h2, .md-content h3 {
    color: var(--text-primary); font-weight: 700; margin: 24px 0 12px; letter-spacing: -1px; text-transform: uppercase;
}
.md-content h1 { font-size: 1.5rem; }
.md-content h2 { font-size: 1.25rem; }
.md-content h3 { font-size: 1.1rem; }
.md-content ul, .md-content ol { padding-left: 24px; margin: 12px 0; }
.md-content li { margin-bottom: 8px; }
.md-content li::marker { color: var(--text-secondary); }
.md-content code {
    background: var(--bg-layer-3); padding: 4px 8px; border-radius: 4px; font-size: 0.9em; color: var(--text-primary);
}
.md-content pre {
    background: var(--bg-layer-2); border: 1px solid var(--bg-layer-4); border-radius: 8px; padding: 20px; overflow-x: auto; margin: 16px 0;
}
.md-content pre code { background: none; padding: 0; }
.md-content blockquote {
    border-left: 4px solid var(--text-primary); padding-left: 16px; color: var(--text-secondary); margin: 16px 0; font-style: italic; font-weight: 700;
}
.md-content a { color: var(--text-primary); text-decoration: underline; text-underline-offset: 4px; }
.md-content hr { border: none; border-top: 1px dashed var(--bg-layer-4); margin: 24px 0; }

/* ============================================================
   MOBILE OPTIMIZATIONS
   ============================================================ */
@media (max-width: 768px) {
    .floating-header {
        width: 95%; padding: 8px 14px; top: 12px;
    }
    .persona-btn { padding: 6px 10px; font-size: 0.65rem; }
    
    .menu-title { font-size: 2rem; margin-bottom: 20px; }
    .backdrop-menu { width: 85%; padding: 40px 24px; }
    
    main { padding: 100px 16px 120px; gap: 16px; }
    .welcome-logo { width: 100px; height: 100px; }
    .welcome h2 { font-size: 1.8rem; }
    .welcome p { font-size: 0.9rem; }
    
    .message { gap: 12px; }
    .msg-avatar { width: 30px; height: 30px; font-size: 0.8rem; }
    .user-msg .msg-body { padding: 12px 16px; font-size: 0.95rem; }
    .ai-msg .msg-body { font-size: 0.95rem; }
    
    .input-area { padding: 0 16px 20px; }
    .input-wrapper { padding: 6px 6px 6px 16px; border-width: 1px; }
    input { font-size: 0.95rem; }
    #sendBtn { width: 38px; height: 38px; }
}
