:root {
    --bg-body: #121212;
    --bg-sidebar: #1e1e1e;
    --bg-input: #2d2d2d;
    --border-color: #3e3e3e;
    --text-main: #e0e0e0;
    --text-muted: #888888;
    --accent-color: #3794ff;
    --accent-hover: #1a7fd9;
    --active-bg: rgba(55, 148, 255, 0.15);
    --radius: 8px;
    --selected-gold: #FFD700;
    --sidebar-width: 320px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent; /* Bỏ highlight xanh khi tap trên mobile */
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    display: flex;
    font-size: 14px;
    touch-action: none; /* Chặn cuộn trang để ưu tiên canvas */
}

/* --- SIDEBAR --- */
#ui-container {
    width: var(--sidebar-width);
    flex-shrink: 0;
    height: 100%;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 20;
    transition: transform 0.3s ease-in-out;
}

/* Overlay che màn hình khi mở menu (mới) */
#menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0,0,0,0.6); 
    z-index: 15; 
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}
#menu-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

/* Header */
.app-header {
    padding: 20px 15px; 
    border-bottom: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 4px;
    position: relative;
}

.app-header h1 {
    font-size: 16px;
    font-weight: 700;
    color: var(--accent-color);
    line-height: 1.2;
    text-transform: uppercase;
}
.app-header span {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}

/* Scroll Area */
.scroll-area {
    flex-grow: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    -webkit-overflow-scrolling: touch;
}

.control-row { width: 100%; }

/* Forms & Inputs */
.form-select {
    width: 100%;
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 10px 12px;
    border-radius: var(--radius);
    font-size: 14px;
    outline: none;
    cursor: pointer;
    transition: border 0.2s, background 0.2s, color 0.2s;
}

.form-select:focus { border-color: var(--accent-color); }
select.has-value { color: var(--selected-gold); font-weight: 600; border-color: var(--selected-gold); }

/* Optgroup */
optgroup { color: #fff; background: #3a3a3a; font-weight: 700; padding: 5px; }
option { color: var(--text-main); background: var(--bg-sidebar); padding: 10px; }
option:checked { color: var(--selected-gold); background-color: #333; font-weight: 600; }

/* Image Tools Box */
.image-tools-box {
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: rgba(255, 255, 255, 0.02);
}

/* Buttons */
.button-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

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: 40px;
    user-select: none;
}

.btn-toggle { background-color: var(--bg-input); color: var(--text-muted); }
.btn-toggle:active { transform: scale(0.98); }
.btn-toggle.active { background-color: var(--active-bg); color: var(--accent-color); border: 1px solid var(--accent-color); }

.btn-primary { width: 100%; background-color: var(--accent-color); color: #fff; }
.btn-primary:hover { background-color: var(--accent-hover); }
.btn-primary:active { transform: scale(0.98); }

/* --- CANVAS AREA --- */
#canvas-container {
    flex-grow: 1;
    height: 100%;
    background-color: #000;
    position: relative;
    z-index: 1;
}

/* --- POPUP STYLES (MOBILE) --- */
#save-popup-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.8); z-index: 200;
    display: flex; align-items: center; justify-content: center;
}
#save-popup-overlay.hidden { display: none; }

.save-popup {
    background: var(--bg-sidebar); width: 90%; max-width: 320px;
    padding: 20px; border-radius: 12px; border: 1px solid var(--border-color);
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    display: flex; flex-direction: column; gap: 15px;
}
.save-popup h3 { text-align: center; color: var(--accent-color); margin-bottom: 5px; text-transform: uppercase; font-weight: 700; font-size: 14px; }
.save-popup label { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; display: block; }
.popup-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }


/* --- MOBILE SPECIFIC STYLES --- */
#mobile-menu-btn, #close-menu-btn, #quick-snap-btn, .mobile-only { display: none; }

/* Media Query cho màn hình nhỏ (Tablet & Mobile) */
@media (max-width: 768px) {
    /* Ẩn các thành phần Desktop */
    .desktop-only { display: none; }

    #mobile-menu-btn {
        display: flex;
        position: absolute; top: 15px; left: 15px; z-index: 100;
        width: 44px; height: 44px;
        background: rgba(30, 30, 30, 0.8);
        color: var(--text-main);
        font-size: 20px;
        border-radius: 50%;
        box-shadow: 0 2px 8px rgba(0,0,0,0.3);
        backdrop-filter: blur(4px);
    }

    #close-menu-btn {
        display: flex;
        position: absolute; top: 15px; right: 15px;
        width: 32px; height: 32px;
        background: transparent;
        color: var(--text-muted);
        font-size: 18px;
    }

    .mobile-only { display: flex; }
    
    #ui-container {
        position: absolute;
        left: 0; top: 0;
        width: 85%; /* Chiếm 85% màn hình */
        max-width: 320px;
        height: 100%;
        transform: translateX(-100%); /* Ẩn sang trái */
        box-shadow: 2px 0 15px rgba(0,0,0,0.5);
    }

    #ui-container.open {
        transform: translateX(0); /* Hiện ra */
    }
    
    /* Nút chụp nhanh */
    #quick-snap-btn {
        display: flex; align-items: center; justify-content: center;
        position: absolute; bottom: 20px; right: 20px; z-index: 50;
        width: 56px; height: 56px;
        border-radius: 50%;
        background: var(--accent-color);
        color: white;
        font-size: 24px;
        box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    }
    #quick-snap-btn:active { transform: scale(0.9); }

    /* Form to hơn cho dễ chạm */
    .form-select { font-size: 16px; }
}

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #444; border-radius: 2px; }