:root {
    /* Nền Gradient xám than chì thay vì đen tuyền */
    --bg-body-start: #232526;
    --bg-body-end: #414345;
    
    /* Màu kính mờ cho Sidebar */
    --bg-sidebar: rgba(45, 45, 45, 0.75); 
    --bg-input: rgba(255, 255, 255, 0.1);
    
    --border-color: rgba(255, 255, 255, 0.15);
    --text-main: #f0f0f0;
    --text-muted: #aaa;
    --accent-color: #3b82f6; /* Xanh dương hiện đại */
    --accent-hover: #2563eb;
    --active-bg: rgba(59, 130, 246, 0.2);
    --radius: 12px;
    --selected-gold: #fbbf24;
    --sidebar-width: 320px;
}

* {
    box-sizing: border-box;
    margin: 0; padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    /* Hiệu ứng nền Gradient */
    background: radial-gradient(circle at center, var(--bg-body-end), var(--bg-body-start));
    color: var(--text-main);
    height: 100vh; width: 100vw;
    overflow: hidden;
    display: flex;
    font-size: 14px;
    touch-action: none;
}

/* --- SIDEBAR GLASSMORPHISM --- */
#ui-container {
    width: var(--sidebar-width);
    flex-shrink: 0;
    height: 100%;
    
    /* Hiệu ứng kính mờ */
    background: var(--bg-sidebar);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    
    border-right: 1px solid var(--border-color);
    display: flex; flex-direction: column;
    z-index: 20;
    transition: transform 0.3s ease-in-out;
    box-shadow: 5px 0 25px rgba(0,0,0,0.3);
}

#menu-overlay {
    position: fixed; top: 0; left: 0;
    width: 100vw; height: 100vh;
    background: rgba(0,0,0,0.5); 
    z-index: 15; opacity: 0; pointer-events: none; transition: opacity 0.3s;
}
#menu-overlay.active { opacity: 1; pointer-events: auto; }

.app-header {
    padding: 24px 15px; 
    border-bottom: 1px solid var(--border-color);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 4px; position: relative;
    background: rgba(255,255,255,0.02);
}

.app-header h1 {
    font-size: 18px; font-weight: 700;
    color: var(--accent-color);
    letter-spacing: 0.5px;
    text-shadow: 0 0 10px rgba(59, 130, 246, 0.4);
}
.app-header span { font-size: 11px; color: var(--text-muted); font-weight: 500; letter-spacing: 1px; }

.scroll-area {
    flex-grow: 1; overflow-y: auto; overflow-x: hidden;
    padding: 20px; display: flex; flex-direction: column; gap: 16px;
}

.control-row { width: 100%; }

/* Inputs đẹp hơn */
.form-select {
    width: 100%;
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 12px;
    border-radius: var(--radius);
    font-size: 14px;
    outline: none; cursor: pointer;
    transition: all 0.2s;
}
.form-select:hover { background-color: rgba(255,255,255,0.15); }
.form-select:focus { border-color: var(--accent-color); box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2); }
select.has-value { color: var(--selected-gold); font-weight: 600; border-color: rgba(251, 191, 36, 0.5); }

optgroup { background: #333; color: #fff; }
option { background: #222; color: #fff; padding: 10px; }

.image-tools-box {
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 16px;
    display: flex; flex-direction: column; gap: 12px;
    background: rgba(0, 0, 0, 0.2);
}

.button-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

button {
    border: none; border-radius: var(--radius);
    cursor: pointer; font-family: inherit; font-size: 13px; font-weight: 600;
    transition: all 0.2s; display: flex; align-items: center; justify-content: center;
    height: 44px; user-select: none;
}

.btn-toggle { background-color: var(--bg-input); color: var(--text-muted); border: 1px solid transparent; }
.btn-toggle:hover { background-color: rgba(255,255,255,0.15); color: #fff; }
.btn-toggle.active { background-color: var(--active-bg); color: var(--accent-color); border-color: var(--accent-color); box-shadow: 0 0 10px rgba(59, 130, 246, 0.2); }

.btn-primary { 
    background: linear-gradient(135deg, var(--accent-color), var(--accent-hover)); 
    color: #fff; 
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(37, 99, 235, 0.4); }
.btn-primary:active { transform: translateY(0); }

.instructions {
    padding: 15px 20px;
    background: rgba(0,0,0,0.3);
    border-top: 1px solid var(--border-color);
    font-size: 11px; color: var(--text-muted);
}

.ins-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.ins-row:last-child { margin-bottom: 0; }

kbd {
    background: rgba(255,255,255,0.1);
    border: 1px solid var(--border-color);
    border-radius: 6px; padding: 4px 8px;
    font-family: monospace; font-size: 11px;
    min-width: 60px; text-align: center; color: #fff;
}

#canvas-container {
    flex-grow: 1; height: 100%;
    /* Canvas trong suốt để hiện nền gradient của body */
    background-color: transparent; 
    position: relative; z-index: 1;
}

/* --- POPUP (GLASSMORPHISM) --- */
#save-popup-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.7); backdrop-filter: blur(5px);
    z-index: 200; display: flex; align-items: center; justify-content: center;
}
#save-popup-overlay.hidden { display: none; }

.save-popup {
    background: rgba(30, 30, 30, 0.9);
    border: 1px solid rgba(255,255,255,0.2);
    width: 90%; max-width: 340px;
    padding: 24px; border-radius: 16px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.6);
    display: flex; flex-direction: column; gap: 16px;
}
.save-popup h3 { text-align: center; color: #fff; margin-bottom: 5px; text-transform: uppercase; font-weight: 700; font-size: 16px; letter-spacing: 1px; }

/* --- MOBILE SPECIFIC --- */
#mobile-menu-btn, #close-menu-btn, #quick-snap-btn, .mobile-only { display: none; }

@media (max-width: 768px) {
    .desktop-only { display: none; }
    .ins-row:not(.mobile-only) { display: none; }

    #mobile-menu-btn {
        display: flex; position: absolute; top: 15px; left: 15px; z-index: 100;
        width: 48px; height: 48px;
        background: rgba(40, 40, 40, 0.6);
        color: #fff; font-size: 22px; border-radius: 12px;
        border: 1px solid rgba(255,255,255,0.1);
        backdrop-filter: blur(10px);
        box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    }

    #close-menu-btn {
        display: flex; position: absolute; top: 15px; right: 15px;
        width: 32px; height: 32px; background: transparent; color: var(--text-muted); font-size: 20px;
    }

    .mobile-only { display: flex; }
    
    #ui-container {
        position: absolute; left: 0; top: 0;
        width: 85%; max-width: 320px; height: 100%;
        transform: translateX(-100%); 
        border-right: 1px solid rgba(255,255,255,0.1);
    }
    #ui-container.open { transform: translateX(0); }
    
    #quick-snap-btn {
        display: flex; align-items: center; justify-content: center;
        position: absolute; bottom: 25px; right: 25px; z-index: 50;
        width: 60px; height: 60px;
        border-radius: 50%;
        background: linear-gradient(135deg, #3b82f6, #2563eb);
        color: white; font-size: 24px;
        box-shadow: 0 8px 20px rgba(37, 99, 235, 0.5);
        border: 2px solid rgba(255,255,255,0.2);
    }
    #quick-snap-btn:active { transform: scale(0.95); }
    .form-select { font-size: 16px; padding: 14px; }
}