/* ==========================================================================
   AI PRO SUITE - THE ULTIMATE MASTER CSS ENGINE (V100)
   ========================================================================== */

:root {
    /* LIGHT MODE */
    --bg-base: #f1f5f9; 
    --bg-surface: #ffffff; 
    --primary: #8b5cf6; 
    --primary-glow: rgba(139, 92, 246, 0.4);
    --secondary: #3b82f6; 
    --secondary-glow: rgba(59, 130, 246, 0.4);
    --accent: #f43f5e; 
    --text-main: #0f172a; 
    --text-muted: #64748b;
    --border-light: rgba(0, 0, 0, 0.1);
    --glass-shadow: 0 10px 25px rgba(0, 0, 0, 0.05);
    --input-bg: #f8fafc;
    --app-font-scale: 1; 
}

/* DARK MODE */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-base: #020617; 
        --bg-surface: #0f172a; 
        --primary-glow: rgba(168, 85, 247, 0.6);
        --secondary-glow: rgba(56, 189, 248, 0.6);
        --text-main: #f8fafc; 
        --text-muted: #94a3b8;
        --border-light: rgba(255, 255, 255, 0.15);
        --glass-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
        --input-bg: #000000; 
    }
}

* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Poppins', 'Inter', sans-serif; -webkit-tap-highlight-color: transparent; }

body, input, textarea, select, button, .bubble, .card { font-size: calc(15px * var(--app-font-scale)); }
h1, h2, h3, .cardTitle, .appTitle, .dash-title { font-size: calc(20px * var(--app-font-scale)); }

/* --- 1. FULLSCREEN LOADER ENGINE --- */
#appLoader {
    position: fixed; inset: 0; background: var(--bg-base); z-index: 99999999; 
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    transition: opacity 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275), visibility 0.6s;
}
#appLoader.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.loader-logo {
    font-size: 32px; font-weight: 900; letter-spacing: 1px; margin-bottom: 40px;
    background: linear-gradient(90deg, var(--secondary), var(--primary), var(--accent)); 
    background-size: 200% auto; -webkit-background-clip: text; -webkit-text-fill-color: transparent; 
    animation: gradientShine 2s linear infinite;
}
.loader-bar-container { width: 250px; height: 6px; background: var(--input-bg); border-radius: 10px; overflow: hidden; border: 1px solid var(--border-light); box-shadow: inset 0 2px 5px rgba(0,0,0,0.1); position: relative; }
.loader-bar { width: 0%; height: 100%; border-radius: 10px; background: linear-gradient(90deg, var(--secondary), var(--primary)); transition: width 0.3s ease-out; box-shadow: 0 0 10px var(--primary-glow); }
.loader-text { margin-top: 25px; font-size: 13px; font-weight: 800; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; min-height: 20px; animation: heartbeat 1.5s infinite; }

/* --- 2. BACKGROUND --- */
html, body { height: 100dvh; width: 100vw; overflow: hidden; background-color: var(--bg-base); color: var(--text-main); transition: background-color 0.4s ease, color 0.4s ease; }
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: var(--primary); border-radius: 10px; }

/* --- 3. TOPBAR & API TRACKER --- */
.topbar {
    position: fixed; top: 0; left: 0; right: 0; height: 70px;
    background: var(--bg-surface); border-bottom: 1px solid var(--border-light);
    display: flex; align-items: center; padding: 0 20px; z-index: 100;
    box-shadow: var(--glass-shadow); animation: slideDown 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.appTitle { 
    font-weight: 900; letter-spacing: 1px; font-size: 22px;
    background: linear-gradient(90deg, var(--secondary), var(--primary), var(--accent)); 
    background-size: 200% auto; -webkit-background-clip: text; -webkit-text-fill-color: transparent; 
    margin-left: 15px; animation: gradientShine 3s linear infinite;
}
.menuBtn { font-size: 28px; cursor: pointer; color: var(--text-main); transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
.menuBtn:hover { transform: scale(1.2) rotate(5deg); color: var(--primary); }

.apiTracker {
    position: fixed; top: 70px; left: 0; right: 0; height: 35px;
    background: var(--bg-surface); border-bottom: 1px solid var(--border-light); z-index: 99;
    display: flex; justify-content: space-evenly; align-items: center;
    font-size: 12px; font-weight: 800; color: var(--text-muted);
    overflow: hidden; transition: all 0.5s ease;
}
.apiTracker.resetting {
    background: linear-gradient(90deg, #ef4444, #f59e0b, #ef4444) !important;
    background-size: 200% auto; color: white !important; border: none !important;
    box-shadow: 0 0 25px rgba(239, 68, 68, 0.8) !important;
    animation: trackerFlash 0.5s infinite alternate, gradientShine 2s linear infinite !important;
}
.apiTracker.resetting::after {
    content: '🚨 API RESETS VALID FOR 30 SECONDS 🚨'; position: absolute; left: 100%; white-space: nowrap;
    font-size: 14px; font-weight: 900; letter-spacing: 2px; color: white;
    animation: slideTextMarquee 6s linear infinite;
}

/* --- 4. PAGE LAYOUT FIX (HUGE SCROLL SPACE) --- */
.page {
    position: relative; width: 100%; height: 100dvh;
    padding-top: 120px; padding-left: 15px; padding-right: 15px; padding-bottom: 150px; 
    overflow-y: auto; -webkit-overflow-scrolling: touch; animation: slideInUp 0.4s ease-out;
}
.chat-page-layout { display: flex !important; flex-direction: column; padding: 0 !important; padding-top: 105px !important; }
.chat-scroll-area { 
    flex: 1; overflow-y: auto; padding: 15px; 
    padding-bottom: 280px !important; /* Forces scroll above input box */
    margin-top: 0 !important; scroll-behavior: smooth;
}

/* --- 5. DASHBOARD CARDS & SWEEPING SHINE --- */
.dashboard-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 20px; }
.card, .dashboard-grid > div {
    background: linear-gradient(145deg, var(--bg-surface), var(--input-bg));
    border: 1px solid var(--border-light); border-radius: 24px; padding: 25px;
    box-shadow: var(--glass-shadow); transition: all 0.4s; text-align: center; cursor: pointer;
    position: relative; overflow: hidden; animation: popInCard 0.5s ease backwards;
}
.card::after {
    content: ''; position: absolute; top: -50%; left: -50%; width: 200%; height: 200%;
    background: linear-gradient(to bottom right, rgba(255,255,255,0) 0%, rgba(255,255,255,0.1) 50%, rgba(255,255,255,0) 100%);
    transform: rotate(45deg) translateY(-100%); transition: 0.6s;
}
.card:hover::after { transform: rotate(45deg) translateY(100%); }
.dashboard-grid > div:nth-child(1) { animation-delay: 0.1s; }
.dashboard-grid > div:nth-child(2) { animation-delay: 0.15s; }
.dashboard-grid > div:nth-child(3) { animation-delay: 0.2s; }
.card:hover { transform: translateY(-8px) scale(1.02); border-color: var(--primary); box-shadow: 0 15px 35px var(--primary-glow); }
.dash-icon { font-size: calc(80px * var(--app-font-scale)); margin-bottom: 15px; display: inline-block; animation: floatIcon 3s ease-in-out infinite; }
.card:hover .dash-icon { transform: scale(1.25) translateY(-10px) rotate(8deg); filter: drop-shadow(0 10px 15px var(--primary-glow)); }

/* --- 6. PREMIUM BUTTONS & INPUTS --- */
.btn {
    background: linear-gradient(135deg, var(--primary), var(--secondary)); color: white !important; border: none; padding: 14px 24px; border-radius: 16px; font-weight: 800;
    cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; box-shadow: 0 5px 15px var(--primary-glow); transition: all 0.3s; text-transform: uppercase; letter-spacing: 1px;
}
.btn:hover { transform: translateY(-4px) scale(1.05); box-shadow: 0 10px 25px var(--secondary-glow); filter: brightness(1.15); }
.btn.blue { background: linear-gradient(135deg, #0ea5e9, #2563eb) !important; box-shadow: 0 5px 15px rgba(14, 165, 233, 0.4); }
.btn.red { background: linear-gradient(135deg, #ef4444, #b91c1c) !important; box-shadow: 0 5px 15px rgba(239, 68, 68, 0.4); }
.btn.green { background: linear-gradient(135deg, #10b981, #047857) !important; box-shadow: 0 5px 15px rgba(16, 185, 129, 0.4); }
input, textarea, select, .standard { width: 100%; background: var(--input-bg) !important; border: 2px solid var(--border-light) !important; border-radius: 16px; color: var(--text-main) !important; padding: 16px; outline: none; transition: all 0.3s; }
input:focus, textarea:focus, select:focus { border-color: var(--primary) !important; transform: translateY(-2px); box-shadow: 0 5px 15px var(--primary-glow); }

/* --- 7. CAMERA UI --- */
.cameraModal { position: fixed; inset: 0; background: #000; z-index: 999999 !important; display: none; flex-direction: column; }
.cameraModal.active { display: flex; animation: zoomIn 0.4s ease; }
#cameraVideo, #standaloneVideo { width: 100%; height: 100%; object-fit: cover; }
.cameraControls { position: absolute; bottom: 0; left: 0; right: 0; height: 140px; background: linear-gradient(transparent, rgba(0,0,0,0.9)); display: flex; justify-content: space-evenly; align-items: center; padding-bottom: 20px; z-index: 9999999 !important; pointer-events: auto !important;}
.cameraCircle { width: 80px; height: 80px; border-radius: 50%; border: 4px solid white; cursor: pointer; transition: 0.3s; box-shadow: 0 0 15px rgba(255,255,255,0.5); background: rgba(255,255,255,0.1); display: grid; place-items: center; animation: pulseCamera 2s infinite alternate; }
.cameraCircle::after { content: "📸"; font-size: 35px; }
.cameraCircle:active { transform: scale(0.7); background: rgba(255,255,255,0.4); box-shadow: 0 0 40px white; }
.cam-icon-btn, #toggleFlashBtn, #standaloneFlashBtn { width: 60px; height: 60px; border-radius: 50%; background: rgba(0,0,0,0.6) !important; border: 2px solid white !important; color: white !important; font-size: 24px !important; cursor: pointer !important; display: grid !important; place-items: center !important; z-index: 9999999 !important; pointer-events: auto !important; box-shadow: 0 0 15px rgba(255,255,255,0.3) !important; }
.cameraModal .closeBtn, .camera-top-bar .closeBtn { position: absolute !important; top: 30px !important; left: 20px !important; z-index: 9999999 !important; pointer-events: auto !important; background: #ef4444 !important; border: 2px solid white !important; box-shadow: 0 0 20px rgba(239, 68, 68, 0.6) !important; width: 50px; height: 50px; border-radius: 50%; font-size: 20px; color: white; display: grid; place-items: center; }

/* --- 8. FONT SIZE DOCK --- */
.font-size-dock { position: fixed; right: 20px; bottom: 130px; top: auto; z-index: 9998; display: flex; flex-direction: column-reverse; align-items: flex-end; gap: 15px; }
.font-size-toggle { width: 65px; height: 65px; border-radius: 50%; border: 3px solid var(--bg-surface); background: linear-gradient(135deg, var(--secondary), var(--primary)); color: white; font-weight: 900; font-size: 22px; cursor: pointer; box-shadow: 0 5px 20px var(--primary-glow); animation: floatIcon 3s infinite; }
.font-size-panel { width: 320px; background: var(--bg-surface); border: 2px solid var(--primary); border-radius: 20px; padding: 20px; box-shadow: 0 15px 40px rgba(0,0,0,0.5); display: none; transform-origin: bottom right; }
.font-size-dock.active .font-size-panel { display: block; animation: springUpPanel 0.4s ease; }
.font-size-options { display: flex; gap: 8px; }
.font-size-option { flex: 1; padding: 12px 0; border: 2px solid var(--border-light); border-radius: 12px; background: var(--input-bg); color: var(--text-main); font-weight: 800; cursor: pointer; font-size: 13px; transition: 0.3s; }
.font-size-option.active, .font-size-option:hover { background: var(--primary); color: white; transform: translateY(-4px); box-shadow: 0 5px 15px var(--primary-glow); border-color: var(--primary); }

/* --- 9. TUTOR & GUI MODAL FIXES --- */
.infoModal { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.75); backdrop-filter: blur(8px); z-index: 9999999; display: none; align-items: center; justify-content: center; padding: 20px; animation: fadeInPage 0.3s ease; }
.infoModal.active { display: flex; }
.infoModal .card { width: 100%; max-width: 600px; max-height: 85vh; overflow-y: auto; background: var(--bg-surface) !important; color: var(--text-main) !important; border: 2px solid var(--primary) !important; box-shadow: 0 15px 50px rgba(0,0,0,0.5) !important; padding: 25px; border-radius: 24px; position: relative; animation: popInCard 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
.infoModal .outputBox, div[id*="tutor"], div[class*="tutor"] { background: var(--input-bg) !important; border: 1px solid var(--border-light) !important; border-radius: 16px; padding: 15px; margin-bottom: 20px; font-size: 15px; line-height: 1.6; color: var(--text-main) !important; }

/* ==========================================================================
   🔥 10. CHAT BUBBLES: ZERO SQUISH & BUTTONS FORCED VISIBLE 🔥
   ========================================================================== */
.chat-msg { 
    display: flex; 
    width: 100%; 
    margin-bottom: 30px; 
    padding-left: 15px;  /* <--- THIS FIXES THE AI BUBBLE */
    padding-right: 15px; /* <--- THIS FIXES THE USER BUBBLE */
    animation: bounceInBubble 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275); 
}
.chat-user { justify-content: flex-end; }
.chat-ai { justify-content: flex-start; }
.bubble { max-width: 92%; padding: 22px; border-radius: 24px; line-height: 1.8; position: relative; transition: transform 0.3s ease; }
.bubble:hover { transform: translateY(-2px); }

.chat-user .bubble { background: linear-gradient(135deg, var(--primary), var(--secondary)); color: white; border-bottom-right-radius: 6px; box-shadow: 0 8px 25px var(--primary-glow); }
.chat-ai .bubble { background: var(--bg-surface); border: 1px solid var(--border-light); color: var(--text-main); border-bottom-left-radius: 6px; box-shadow: var(--glass-shadow); display: flex !important; flex-direction: column !important; }

/* Badge pushes text down */
.api-badge { display: inline-block !important; position: relative !important; align-self: flex-start; background: var(--input-bg) !important; border: 1px solid var(--primary) !important; color: var(--primary) !important; padding: 8px 16px !important; border-radius: 14px !important; font-size: 11px !important; font-weight: 900 !important; margin-bottom: 20px !important; box-shadow: 0 4px 10px var(--primary-glow) !important; }
.chat-ai .bubble div[id^="text_"], .chat-ai .bubble p { margin-top: 0 !important; width: 100% !important; box-sizing: border-box !important; overflow-x: auto !important; }

/* Buttons forced to grid */
.chat-ai .bubble div[style*="border-top"], .chat-ai .bubble div[style*="display: flex"], .chat-ai .bubble div[style*="display:flex"], .chat-ai .bubble .action-buttons-container { display: flex !important; flex-wrap: wrap !important; gap: 10px !important; justify-content: flex-start !important; margin-top: 25px !important; padding-top: 15px !important; border-top: 1px solid var(--border-light) !important; width: 100% !important; }
.chat-ai .bubble button { background: linear-gradient(145deg, var(--bg-surface), var(--input-bg)) !important; color: var(--primary) !important; border: 1px solid var(--primary) !important; padding: 10px 16px !important; border-radius: 12px !important; font-size: 13px !important; font-weight: 800 !important; cursor: pointer !important; flex: 1 1 auto !important; min-width: 80px !important; text-align: center !important; display: inline-flex !important; align-items: center !important; justify-content: center !important; gap: 8px !important; opacity: 1 !important; visibility: visible !important; box-shadow: 0 4px 10px rgba(0,0,0,0.05) !important; transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) !important; }
.chat-ai .bubble button:hover { background: var(--primary) !important; color: white !important; transform: translateY(-4px) scale(1.05) !important; box-shadow: 0 8px 20px var(--primary-glow) !important; }
.bubble-img { max-width: 100%; border-radius: 16px; margin-bottom: 20px; border: 2px solid var(--border-light); box-shadow: var(--glass-shadow); }

/* --- 11. CHAT INPUT AREA (CLEAN GLOW, NO RGB) --- */
.chat-input-area { position: fixed; bottom: 0; left: 0; right: 0; padding: 15px; background: var(--bg-surface); border-top: 1px solid var(--border-light); z-index: 100; display: flex; gap: 10px; flex-direction: column; animation: slideInUp 0.5s ease-out; box-shadow: 0 -10px 30px rgba(0,0,0,0.1); }
.chat-input-wrapper { display: flex; align-items: flex-end; width: 100%; gap: 12px; background: var(--input-bg); border-radius: 24px; padding: 8px; border: 2px solid var(--border-light); transition: all 0.3s ease; box-shadow: var(--glass-shadow); }
.chat-input-wrapper:focus-within { border-color: var(--primary) !important; box-shadow: 0 8px 25px var(--primary-glow) !important; transform: translateY(-2px); }
.chat-input-wrapper textarea { border: none; background: transparent; box-shadow: none; resize: none; min-height: 45px; padding: 12px; margin: 0; font-weight: 500; color: var(--text-main); font-size: 15px; }
.chat-action-btn { width: 55px; height: 55px; border-radius: 50%; border: none; background: var(--border-light); color: var(--text-main); font-size: 22px; cursor: pointer; flex-shrink: 0; transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
.chat-action-btn.send { background: linear-gradient(135deg, var(--secondary), var(--primary)); color: white; box-shadow: 0 5px 15px var(--primary-glow); animation: heartbeat 2s infinite; }
.chat-action-btn.send:hover { transform: scale(1.2) rotate(15deg); box-shadow: 0 8px 30px var(--secondary-glow); animation: none; }

/* --- 12. SIDEBAR WITH X BUTTON --- */
.sidebar { position: fixed; top: 0; left: -100%; width: 300px; height: 100dvh; background: var(--bg-surface); border-right: 1px solid var(--border-light); z-index: 10000; padding: 20px; padding-top: 80px; display: flex; flex-direction: column; gap: 12px; transition: left 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); box-shadow: 15px 0 40px rgba(0,0,0,0.3); overflow-y: auto; }
.sidebar.active { left: 0; }
.sidebar button { background: transparent; color: var(--text-muted); border: none; padding: 16px; border-radius: 16px; font-weight: 700; display: flex; align-items: center; gap: 15px; cursor: pointer; transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
.sidebar button:hover, .sidebar button.active { background: var(--input-bg); color: var(--primary); transform: translateX(10px); border-left: 4px solid var(--primary); box-shadow: 0 4px 15px rgba(0,0,0,0.05); }
.sidebar-close-btn { background: rgba(239, 68, 68, 0.1) !important; color: #ef4444 !important; border: 2px solid rgba(239, 68, 68, 0.3) !important; justify-content: center !important; font-size: 15px !important; font-weight: 900 !important; margin-bottom: 15px !important; text-transform: uppercase; letter-spacing: 1px; }
.sidebar-close-btn:hover { background: #ef4444 !important; color: white !important; transform: scale(1.05) !important; border-left: 2px solid #ef4444 !important;}

/* --- 13. HISTORY PAGE (GLASS SHINE EFFECTS) --- */
#historyList { display: flex; flex-direction: column; gap: 15px; }
#historyList > div { background: linear-gradient(135deg, var(--bg-surface) 0%, var(--input-bg) 100%) !important; border: 1px solid var(--border-light) !important; border-left: 6px solid var(--primary) !important; border-right: 1px solid var(--border-light) !important; border-radius: 20px !important; padding: 25px !important; box-shadow: 0 10px 30px rgba(0,0,0,0.05) !important; transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) !important; position: relative; cursor: pointer; overflow: hidden; animation: slideInUp 0.5s ease backwards; }
#historyList > div::before { content: ''; position: absolute; top: 0; left: -100%; width: 50%; height: 100%; background: linear-gradient(90deg, transparent, rgba(255,255,255,0.05), transparent); transform: skewX(-20deg); transition: 0.5s; }
#historyList > div:hover::before { left: 150%; }
#historyList > div:nth-child(1) { animation-delay: 0.1s; } #historyList > div:nth-child(2) { animation-delay: 0.2s; } #historyList > div:nth-child(3) { animation-delay: 0.3s; }
#historyList > div:hover { transform: translateY(-8px) scale(1.02) !important; border-color: var(--primary) !important; box-shadow: 0 15px 40px var(--primary-glow) !important; }
#historyList > div strong { color: var(--text-main) !important; font-size: 20px !important; font-weight: 900 !important; margin-bottom: 10px !important; display: flex !important; align-items: center !important; gap: 10px !important; }
#historyList > div span { display: inline-flex !important; align-items: center !important; gap: 6px !important; background: var(--border-light) !important; color: var(--text-muted) !important; padding: 8px 14px !important; border-radius: 12px !important; font-size: 12px !important; font-weight: 700 !important; border: 1px solid rgba(255,255,255,0.05) !important; }

/* --- 14. KEYFRAME ANIMATIONS --- */
@keyframes fadeInPage { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideDown { from { opacity: 0; transform: translateY(-30px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideInUp { from { opacity: 0; transform: translateY(50px); } to { opacity: 1; transform: translateY(0); } }
@keyframes bounceInBubble { 0% { opacity: 0; transform: scale(0.8) translateY(30px); } 60% { opacity: 1; transform: scale(1.02) translateY(-5px); } 100% { opacity: 1; transform: scale(1) translateY(0); } }
@keyframes popInCard { 0% { opacity: 0; transform: translateY(30px) scale(0.9); } 100% { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes springUpPanel { 0% { opacity: 0; transform: scale(0.8) translateY(20px); } 100% { opacity: 1; transform: scale(1) translateY(0); } }
@keyframes floatIcon { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-12px); } }
@keyframes pulseCamera { 0% { box-shadow: 0 0 10px rgba(255,255,255,0.3); } 100% { box-shadow: 0 0 30px rgba(255,255,255,0.8); } }
/* Used by the shared "AI is thinking" three-dot indicator (appendAiLoading in
   main.js, and inline retry/convert loaders). Was missing here, so the dots
   just sat still on every page that doesn't define its own local copy. */
@keyframes pulse { 0% { opacity: 0.35; transform: scale(0.85); } 100% { opacity: 1; transform: scale(1.15); } }
.thinking-dots { display: inline-flex; align-items: center; gap: 6px; padding: 4px 0; }
.thinking-dots span { width: 9px; height: 9px; border-radius: 50%; background: var(--primary); animation: pulse 0.9s infinite alternate; }
.thinking-dots span:nth-child(2) { background: #f43f5e; animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { background: #10b981; animation-delay: 0.4s; }
@keyframes gradientShine { 0% { background-position: 0% 50%; } 100% { background-position: 200% 50%; } }
@keyframes slideTextMarquee { 0% { left: 100%; } 100% { left: -150%; } }
@keyframes trackerFlash { 0% { filter: brightness(1); } 100% { filter: brightness(1.3); } }
@keyframes heartbeat { 0% { transform: scale(1); } 15% { transform: scale(1.15); } 30% { transform: scale(1); } 45% { transform: scale(1.15); } 60% { transform: scale(1); } }

/* --- 15. OVERRIDES FOR APPS (QUIZ, YT) --- */
#questionText, h3[style*="color: white"], div[style*="color: white"], .result-card { color: var(--text-main) !important; }
#quizSubjectSelector, #quizTopicSelector { background: var(--input-bg) !important; color: var(--text-main) !important; border: 2px solid var(--border-light) !important; }
#networkStatus { position: fixed; top: 70px; left: 50%; transform: translateX(-50%); background: #ef4444; color: white; padding: 4px 12px; border-radius: 15px; font-size: 11px; font-weight: bold; display: none; z-index: 1000; }
#fabScroll { position: fixed; bottom: 150px; right: 20px; background: var(--bg-surface); border: 1px solid var(--border-light); color: var(--text-main); width: 40px; height: 40px; border-radius: 50%; display: none; justify-content: center; align-items: center; cursor: pointer; box-shadow: var(--glass-shadow); z-index: 999; }
.option-btn { background: var(--input-bg) !important; color: var(--text-main) !important; border: 2px solid var(--border-light) !important; font-weight: 700 !important; }
.option-btn:hover { border-color: var(--primary) !important; transform: translateY(-2px); }
.option-btn.selected { background: var(--primary) !important; color: white !important; border-color: var(--primary) !important; box-shadow: 0 5px 15px var(--primary-glow) !important; }
.subj-btn { background: var(--input-bg) !important; color: var(--text-main) !important; border: 2px solid var(--border-light) !important; }
.subj-btn:hover { background: var(--primary) !important; color: white !important; }
.stat-box, .result-card, .outputBox { background: var(--input-bg) !important; border: 2px solid var(--border-light) !important; color: var(--text-main) !important; }
div[style*="color: white"], div[style*="color: #fff"], span[style*="color: white"], b[style*="color: white"], strong[style*="color: white"] { color: var(--text-main) !important; }
.yt-meta, .yt-author { font-weight: 900 !important; color: var(--secondary) !important; font-size: 13px !important; margin-top: 5px !important; display: block !important; }
/* ==========================================================================
   🔥 16. IMAGE PREVIEW CHIP (CAMERA FIX) 🔥
   ========================================================================== */
.image-preview-chip {
    display: none; 
    width: 75px; 
    height: 75px; 
    border-radius: 14px; 
    background-size: cover; 
    background-position: center; 
    position: relative; 
    margin-left: 15px; 
    margin-bottom: 10px; 
    border: 2px solid var(--primary); 
    box-shadow: 0 5px 15px var(--primary-glow); 
    animation: bounceInBubble 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 101;
}

.image-preview-close {
    position: absolute; 
    top: -10px; 
    right: -10px; 
    background: #ef4444 !important; 
    color: white !important; 
    border-radius: 50%; 
    width: 26px; 
    height: 26px; 
    display: flex !important; 
    justify-content: center !important; 
    align-items: center !important; 
    font-size: 12px !important; 
    font-weight: 900 !important; 
    cursor: pointer !important; 
    border: 2px solid var(--bg-surface) !important; 
    box-shadow: 0 4px 10px rgba(239, 68, 68, 0.5) !important; 
    transition: transform 0.3s ease !important;
}

.image-preview-close:hover {
    transform: scale(1.2) rotate(90deg) !important;
}
/* Make long MathJax equations scrollable horizontally */
mjx-container[display="true"] {
    overflow-x: auto !important;
    overflow-y: hidden !important;
    max-width: 100% !important;
    
    /* Adds a tiny bit of space so the scrollbar doesn't cover the bottom of the equation */
    padding-bottom: 8px !important; 
    padding-top: 5px !important;
}

/* Ensure inline equations can break properly if needed */
mjx-container:not([display="true"]) {
    white-space: normal;
}

/* Ensure the chat bubble itself doesn't stretch past the screen */
.bubble {
    max-width: 100%;
    overflow-x: hidden;
}
#networkStatus { position: fixed; top: 70px; left: 50%; transform: translateX(-50%); background: #ef4444; color: white; padding: 4px 12px; border-radius: 15px; font-size: 11px; font-weight: bold; display: none; z-index: 1000; }
#fabScroll { position: fixed; bottom: 150px; right: 20px; background: var(--bg-surface); border: 1px solid var(--border-light); color: var(--text-main); width: 40px; height: 40px; border-radius: 50%; display: none; justify-content: center; align-items: center; cursor: pointer; box-shadow: var(--glass-shadow); z-index: 999; }

/* MULTI-IMAGE */
.img-thumb { width: 60px; height: 60px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border-light); }
.img-thumb-container { position: relative; display: inline-block; margin-right: 10px; }
.img-thumb-remove { position: absolute; top: -5px; right: -5px; background: #ef4444; color: white; border-radius: 50%; width: 20px; height: 20px; font-size: 12px; display: flex; justify-content: center; align-items: center; cursor: pointer; border: none; }
/* VIDEO TUTOR DARK/LIGHT MODE FIX */
body.dark-mode #youtubePage,
body.dark-mode .video-container,
body.dark-mode .yt-result-card {
    color: var(--text-main) !important;
}

body.dark-mode .yt-result-card h3,
body.dark-mode .yt-result-card p {
    color: #ffffff !important;
}
/* =======================================================
   MASTER UI FIXES: Scrollbar Back to Right, No Double Scroll
======================================================= */

/* 🛑 Nuke double scrollbar: body is locked, only chat area scrolls */
body {
    overflow: hidden !important; 
}

/* 🛑 Scrollbar Back to Right & Gap Removal */
.chat-scroll-area {
    overflow-y: auto !important;
    padding-left: 0;
    padding-right: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    /* 🛑 Removed left-side hacks (direction: rtl; is GONE) */
}

/* Ensure text inside the chat area reads normally (L-to-R) */
.chat-scroll-area > * {
    /* 🛑 Removed left-side text hacks (direction: ltr; is GONE) */
}

/* Dark Mode Smart Bold Rule (Kept) */
body.dark-mode b, 
body.dark-mode strong,
.dark-mode .chat-msg b,
.dark-mode .chat-msg strong {
    font-weight: normal !important; /* Removes bold in black theme */
    color: var(--text-main); /* Ensure it matches normal text color */
}

body:not(.dark-mode) b, 
body:not(.dark-mode) strong,
:not(.dark-mode) .chat-msg b,
:not(.dark-mode) .chat-msg strong {
    font-weight: 800 !important; /* Keeps it strictly bold in white theme */
}

/* Fix floating badge overlaps on AI chat bubbles (Kept) */
.chat-msg.chat-ai {
    position: relative; /* Allows absolute positioned elements inside to stay contained */
    margin-top: 15px; 
}
/* Fix for Cloudflare Image Generation overflowing */
.creator-output-img {
    max-width: 100%;
    max-height: 55vh;
    object-fit: contain;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

/* Fix for Video Titles invisible in White Mode */
body:not(.dark-mode) .yt-grid .card div[style*="color: #f8fafc"] {
    color: var(--text-main) !important;
}

/* Hide TTS Player smoothly when done */
.tts-mini-player {
    display: none;
    align-items: center;
    gap: 10px;
    background: var(--bg-surface);
    padding: 10px 20px;
    border-radius: 30px;
    position: fixed;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%);
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    z-index: 10000;
    border: 1px solid var(--primary);
}
/* ==========================================================================
   📱 DYNAMIC COMPACT FLEX LAYOUT MATRIX FOR COMPACT MOBILE TIERS
   ========================================================================== */
@media (max-width: 480px) {
    .topbar {
        padding: 10px 12px !important;
        gap: 6px !important;
    }

    .app-title {
        font-size: 14px !important;
        letter-spacing: 0px !important;
        display: inline-block;
        max-width: 80px;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
    }

    /* Collapse excess buttons into standard dashboard viewport context boxes */
    .topbar button[onclick="toggleShareMode()"] {
        display: none !important;
    }

    /* Constrain the account profile pop-up window bounds so it never cuts off */
    #userAccountDashboardMenu {
        right: -10px !important;
        top: 45px !important;
        width: 270px !important;
        max-width: calc(100vw - 20px) !important;
        box-sizing: border-box !important;
        position: absolute !important;
    }

    #userAvatarImg {
        width: 28px !important;
        height: 28px !important;
    }

    #googleBtnWrapperDiv {
        transform: scale(0.85);
        transform-origin: right center;
    }
}