:root {
    --bg-color: #1e1e1e;
    --panel-bg: rgba(40, 40, 40, 0.85);
    --text-color: #ffffff;
    --primary-color: #007bff;
    --primary-hover: #0056b3;
    --border-color: #444444;
    --font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

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

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    height: 100vh;
    overflow: hidden;
    position: relative;
}

#ui-container {
    position: absolute;
    top: 20px;
    left: 20px;
    bottom: 20px;
    width: 320px;
    background-color: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    overflow-y: auto;
    box-shadow: 2px 0 5px rgba(0,0,0,0.5);
    z-index: 10;
    pointer-events: auto;
    backdrop-filter: blur(4px);
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
}

.header h1 {
    font-size: 1.2rem;
    font-weight: 600;
}

#lang-toggle {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 5px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: background 0.2s;
}

#lang-toggle:hover {
    background: rgba(255, 255, 255, 0.1);
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.control-group label {
    font-size: 0.9rem;
    font-weight: 500;
}

.control-group input[type="range"] {
    width: 100%;
}

.control-group span {
    font-size: 0.8rem;
    text-align: right;
    color: #aaa;
}

#download-btn-mobile {
    display: none; /* Nascosto su desktop */
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    transition: background 0.2s;
}

#download-btn-mobile:hover {
    background-color: var(--primary-hover);
}

#download-btn {
    margin-top: auto;
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    transition: background 0.2s;
}

#download-btn:hover {
    background-color: var(--primary-hover);
}

#scene-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1;
    background-color: transparent;
}

/* Scrollbar styling for a cleaner look */
#ui-container::-webkit-scrollbar {
    width: 6px;
}
#ui-container::-webkit-scrollbar-track {
    background: transparent;
}
#ui-container::-webkit-scrollbar-thumb {
    background: #666;
    border-radius: 3px;
}

.drawer-handle { display: none; }

@media (max-width: 768px) {
    body {
        height: 100dvh; /* Usa dynamic viewport height se supportato */
    }

    #ui-container {
        position: fixed; /* Evita i problemi di absolute con 100vh sfalsati */
        width: 100%;
        max-height: 60dvh;
        top: auto;
        bottom: 0;
        left: 0;
        padding: 60px 20px 20px;
        border-radius: 24px 24px 0 0;
        background: rgba(25, 25, 25, 0.98);
        backdrop-filter: blur(15px);
        -webkit-backdrop-filter: blur(15px);
        box-shadow: 0 -10px 30px rgba(0,0,0,0.6);
        pointer-events: auto;
        border: none;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        box-sizing: border-box;
        transition: max-height 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
        overflow-y: scroll;
    }
    
    #ui-container.collapsed {
        max-height: 130px; /* Increased to fit larger text and handle */
        overflow-y: hidden;
    }
    
    .drawer-handle {
        display: flex;
        align-items: center;
        justify-content: center;
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 80px; /* Roughly doubled */
        cursor: pointer;
        z-index: 20;
    }

    .handle-text {
        font-size: 14px;
        font-weight: 600;
        color: rgba(255, 255, 255, 0.7);
        text-transform: uppercase;
        letter-spacing: 1px;
        background: rgba(255, 255, 255, 0.1);
        padding: 8px 24px; /* Made the pill slightly bigger too */
        border-radius: 24px;
    }

    /* Fix header margin to make room for bigger handle */
    .header {
        margin-top: 10px;
    }

    button, input[type="range"], #lang-toggle {
        min-height: 48px;
        font-size: 14px;
        border-radius: 10px;
    }

    /* Nascondi il titolo su mobile per far spazio al tasto download */
    .desktop-title {
        display: none;
    }

    .desktop-only {
        display: none !important;
    }

    #download-btn-mobile {
        display: inline-block;
        margin-right: auto;
        position: relative;
        z-index: 30; /* Porta in primo piano rispetto all'area touch del drawer */
    }

    /* Assicurati che anche le bandiere lingua siano cliccabili sopra la linguetta */
    .header > div {
        position: relative;
        z-index: 30;
    }
}

