:root {
    --primary-color: #3498db;
    --secondary-color: #2c3e50;
    --accent-color: #1abc9c;
    --dark-bg: #1a1a1a;
    --light-bg: #f8f9fa;
    --text-light: #ffffff;
    --text-dark: #333333;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    --shadow-hover: 0 6px 20px rgba(0, 0, 0, 0.2);
    --border-radius: 12px;
    --border-radius-sm: 8px;
    --transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);

    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-left: env(safe-area-inset-left, 0px);
    --safe-area-right: env(safe-area-inset-right, 0px);
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    overflow: hidden;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    height: 100vh;
    height: 100dvh;
    padding: var(--safe-area-top) var(--safe-area-right) var(--safe-area-bottom) var(--safe-area-left);

    /* Nascondi immediatamente il body */
    opacity: 0;
    visibility: hidden;

    /* Transizione graduale quando diventa visibile */
    transition: opacity 0.3s ease-in, visibility 0.3s ease-in;

    /* Previeni il flash di contenuto non stilizzato */
    background-color: #1a1a1a;
}

body.ready {
    opacity: 1 !important;
    visibility: visible !important;
}

#main-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    box-shadow: inset 0 0 100px rgba(0, 0, 0, 0.1);

    /* Eredita l'opacità dal body */
    opacity: inherit;
    visibility: inherit;
}

#sidebar {
    width: 100%;
    background: linear-gradient(135deg,
        rgba(45, 55, 72, 0.92),
        rgba(30, 41, 59, 0.98)
    );
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    color: var(--text-light);
    padding: calc(8px + var(--safe-area-top)) 16px 8px;
    box-sizing: border-box;
    overflow-x: auto;
    height: 70px;
    min-height: 70px;
    z-index: 100;
    position: relative;
    box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
    contain: layout style paint;

    /* Sidebar inizialmente nascosta */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease-in, visibility 0.3s ease-in;
}

#sidebar.visible {
    opacity: 1 !important;
    visibility: visible !important;
}

#model-list {
    display: flex;
    gap: 8px;
    padding: 2px 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
    transform: translateZ(0);
    will-change: transform;
    contain: content;
}

#model-list::-webkit-scrollbar {
    display: none;
}

.model-item {
    flex: 0 0 auto;
    padding: 8px 20px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 40px;
    cursor: pointer;
    white-space: nowrap;
    font-size: 14px;
    font-weight: 500;
    letter-spacing: 0.3px;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    position: relative;
    overflow: hidden;
    min-width: 90px;
    text-align: center;
    user-select: none;
    transform: translateZ(0);
    will-change: transform, background-color, box-shadow;
    color: rgba(255, 255, 255, 0.9);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.model-item::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    border-radius: 42px;
    background: linear-gradient(45deg,
        transparent 30%,
        rgba(255, 255, 255, 0.2) 50%,
        transparent 70%
    );
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: -1;
}

.model-item:hover {
    transform: translateY(-2px) scale(1.02);
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
    color: white;
}

.model-item:hover::before {
    opacity: 0.7;
}

.model-item:active {
    transform: scale(0.98);
    transition: transform 0.1s;
}

.model-item.active {
    background: linear-gradient(135deg,
        rgba(26, 188, 156, 0.9),
        rgba(52, 152, 219, 0.9)
    );
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.4);
    box-shadow: 0 8px 25px rgba(26, 188, 156, 0.5);
    font-weight: 600;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    animation: activePulse 2s ease-in-out infinite;
}

@keyframes activePulse {
    0%, 100% {
        box-shadow: 0 8px 25px rgba(26, 188, 156, 0.5);
        transform: scale(1);
    }
    50% {
        box-shadow: 0 12px 35px rgba(26, 188, 156, 0.8);
        transform: scale(1.02);
    }
}

#viewer-wrapper {
    flex: 1;
    position: relative;
    width: 100%;
    height: calc(100% - 70px);
    background: var(--dark-bg);
}

#viewer {
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #2c3e50 0%, #3498db 100%);
}

#model-info {
    position: absolute;
    bottom: 15px;
    left: 12px;
    right: auto;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 10px 14px;
    border-radius: 10px;
    z-index: 99;
    font-size: 14px;
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    font-weight: 500;
    text-align: left;
    line-height: 1.4;
    max-width: 170px;
    margin: 0;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    gap: 3px;
}

#model-info strong {
    color: var(--accent-color);
    font-weight: 700;
    font-size: 14px;
}

#model-info span {
    font-weight: 400;
    font-size: 12px;
    opacity: 0.9;
    line-height: 1.3;
}

.control-panel {
    position: absolute;
    bottom: 15px;
    top: auto;
    right: 12px;
    left: 12px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 15px;
    background: rgba(20, 20, 30, 0.8);
    padding: 20px;
    border-radius: var(--border-radius);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-hover);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    opacity: 0;
    visibility: hidden;
    transform: scale(0.95) translateY(calc(100% + 100px));
    transform-origin: bottom right;
}

.control-panel:not(.collapsed) {
    opacity: 1;
    visibility: visible;
    transform: scale(0.95) translateY(0);
}

.control-panel.collapsed {
    opacity: 0;
    visibility: hidden;
    transform: scale(0.95) translateY(calc(100% + 100px));
}

.control-panel-version {
    text-align: center;
    margin-top: 5px;
    padding-top: 5px;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    color: #ffffff;
    font-size: 9px;
    font-family: monospace;
    letter-spacing: 0.5px;
    width: 100%;
    pointer-events: none;
    user-select: none;
    opacity: 0.8;
    font-weight: 400;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
    width: 100%;
}

.control-group > div {
    color: var(--text-light);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 5px;
    text-align: center;
    width: 100%;
}

.control-group-row {
    display: flex;
    gap: 10px;
    justify-content: center;
    width: 100%;
}

.explosion-slider-container {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.explosion-slider-value {
    color: var(--accent-color);
    font-weight: bold;
    min-width: 25px;
    text-align: center;
    font-size: 12px;
    text-shadow: 0 0 8px rgba(26, 188, 156, 0.5);
}

.control-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    color: var(--text-light);
    border: none;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    user-select: none;
    touch-action: manipulation;
    flex-shrink: 0;
}

.control-btn:active {
    transform: scale(0.92);
    background: rgba(255, 255, 255, 0.2);
}

.control-btn.active {
    background: rgba(26, 188, 156, 0.7);
    box-shadow: 0 0 20px rgba(26, 188, 156, 0.5);
}

#bg-color {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid rgba(255, 255, 255, 0.25);
    background: transparent;
    overflow: hidden;
    transition: var(--transition);
    touch-action: manipulation;
    flex-shrink: 0;
}

#bg-color:active {
    transform: scale(0.95);
}

.explosion-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 120px;
    height: 6px;
    background: rgba(255, 255, 255, 0.25);
    border-radius: 3px;
    outline: none;
    margin: 0;
    flex: 1;
    max-width: 140px;
}

.explosion-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent-color);
    cursor: pointer;
    border: 2px solid white;
    transition: var(--transition);
    box-shadow: 0 0 10px rgba(26, 188, 156, 0.5);
}

.explosion-slider::-webkit-slider-thumb:active {
    transform: scale(1.2);
    box-shadow: 0 0 15px rgba(26, 188, 156, 0.8);
}

.explosion-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent-color);
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 0 10px rgba(26, 188, 156, 0.5);
}

#toggle-panel {
    position: fixed;
    right: 15px;
    bottom: 15px;
    bottom: calc(15px + var(--safe-area-bottom));
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(52, 152, 219, 0.85) 0%, rgba(26, 188, 156, 0.85) 100%);
    color: white;
    border: none;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 2001;
    box-shadow: var(--shadow-hover);
    touch-action: manipulation;
    transition: var(--transition);
    border: 1px solid rgba(255, 255, 255, 0.25);
    user-select: none;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

#toggle-panel:active {
    transform: scale(0.90);
}

.back-btn {
    position: absolute;
    top: 15px;
    top: calc(15px + var(--safe-area-top));
    left: 12px;
    z-index: 102;
    background: rgba(30, 30, 40, 0.7);
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: 25px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    font-weight: 500;
    transition: var(--transition);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    user-select: none;
    touch-action: manipulation;
    min-width: 120px;
    text-align: center;
    justify-content: center;
}

.back-btn:active {
    transform: scale(0.95);
}

#loader-container {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(30, 30, 40, 0.9);
    color: white;
    padding: 25px 20px;
    border-radius: var(--border-radius);
    z-index: 1000;
    width: 260px;
    max-width: 85vw;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: var(--shadow-hover);
}

#loader {
    width: 45px;
    height: 45px;
    border: 3px solid rgba(255, 255, 255, 0.25);
    border-top: 3px solid var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 12px;
}

#progress-text {
    font-size: 14px;
    margin-bottom: 10px;
    font-weight: 500;
}

#progress-bar-container {
    width: 100%;
    height: 5px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
    margin: 12px auto;
    overflow: hidden;
}

#progress-bar {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--accent-color));
    border-radius: 3px;
    transition: width 0.3s;
}

.error-message {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(231, 76, 60, 0.9);
    color: white;
    padding: 20px 16px;
    border-radius: var(--border-radius);
    z-index: 1000;
    display: none;
    text-align: center;
    width: 280px;
    max-width: 85vw;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: var(--shadow-hover);
}

.error-message button {
    background: rgba(255, 255, 255, 0.9);
    color: #c0392b;
    border: none;
    padding: 8px 16px;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    margin-top: 12px;
    font-weight: 600;
    transition: var(--transition);
    font-size: 14px;
    width: 100%;
}

.error-message button:active {
    transform: scale(0.98);
}

#dimensions-table {
    position: absolute;
    top: 20px;
    left: auto;
    right: 12px;
    background: rgba(255, 255, 255, 0.12);
    color: #000000;
    padding: 12px 18px;
    border-radius: var(--border-radius);
    z-index: 99;
    font-size: 14px;
    backdrop-filter: blur(15px) saturate(180%);
    -webkit-backdrop-filter: blur(15px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.15);
    display: none;
    min-width: 200px;
    max-width: 80vw;
    transition: all 0.3s ease;
    opacity: 0;
    transform: translateY(-30px);
}

#dimensions-table.visible {
    display: block;
    opacity: 1;
    transform: translateY(0);
}

#dimensions-table table {
    width: 100%;
    border-collapse: collapse;
}

#dimensions-table th {
    text-align: left;
    padding: 6px 12px 6px 0;
    font-weight: 700;
    color: #000000;
    font-size: 13px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.2);
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.8);
    letter-spacing: 0.3px;
}

#dimensions-table td {
    padding: 5px 12px 5px 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.15);
    font-size: 13px;
    font-weight: 600;
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.8);
    color: #000000;
}

#dimensions-table tr:last-child td {
    border-bottom: none;
}

#dimensions-table .dim-value {
    text-align: right;
    font-weight: 700;
    color: #000000;
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.8);
}

#dimensions-table .dim-unit {
    font-size: 11px;
    opacity: 0.8;
    margin-left: 3px;
    font-weight: 600;
    text-shadow: 0 1px 1px rgba(255, 255, 255, 0.8);
    color: #333333;
}

.explosion-particle {
    position: absolute;
    width: 4px;
    height: 4px;
    background: hsla(180, 80%, 65%, 0.7);
    border-radius: 50%;
    pointer-events: none;
    opacity: 0;
    z-index: 1000;
    filter: drop-shadow(0 0 3px rgba(100, 220, 220, 0.5));
    transition: opacity 0.2s;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes fadeIn {
    from { opacity: 0; transform: translate(-50%, -50%) scale(0.9); }
    to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.control-panel, #sidebar, #model-info, .back-btn {
    animation: fadeIn 0.4s ease-out;
}

@keyframes glow {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

@media (min-width: 601px) and (max-width: 900px) {
    #sidebar {
        height: 70px;
        min-height: 70px;
        background: linear-gradient(135deg,
            rgba(45, 55, 72, 0.92),
            rgba(30, 41, 59, 0.98)
        );
        padding: calc(8px + var(--safe-area-top)) 20px 8px;
    }

    #viewer-wrapper {
        height: calc(100% - 70px);
    }

    .model-item {
        padding: 8px 22px;
        min-width: 100px;
        font-size: 14px;
        background: rgba(255, 255, 255, 0.08);
    }

    .model-item:hover {
        transform: translateY(-2px) scale(1.02);
        background: rgba(255, 255, 255, 0.15);
    }

    .model-item.active {
        background: linear-gradient(135deg,
            rgba(26, 188, 156, 0.9),
            rgba(52, 152, 219, 0.9)
        );
    }

    .control-panel {
        left: 50%;
        transform: scale(0.92) translateX(-50%) translateY(calc(100% + 100px));
        width: 90%;
        max-width: 500px;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: space-around;
        gap: 12px;
        background: rgba(20, 20, 30, 0.8);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        z-index: 2000;
    }

    .control-panel:not(.collapsed) {
        transform: scale(0.92) translateX(-50%) translateY(0);
        opacity: 1;
        visibility: visible;
    }

    .control-panel.collapsed {
        transform: scale(0.92) translateX(-50%) translateY(calc(100% + 100px));
        opacity: 0;
        visibility: hidden;
    }

    .control-group {
        width: auto;
        min-width: 80px;
    }

    .explosion-slider-container {
        width: 100%;
        justify-content: center;
    }

    #model-info {
        bottom: 15px;
        left: 15px;
        max-width: 200px;
        padding: 10px 14px;
        font-size: 14px;
        background: rgba(0, 0, 0, 0.7);
    }

    #model-info strong {
        font-size: 14px;
    }

    #model-info span {
        font-size: 12px;
    }

    #dimensions-table {
        top: 15px;
        left: 50%;
        right: auto;
        transform: translateX(-50%) translateY(-30px);
        background: rgba(255, 255, 255, 0.1);
        min-width: 180px;
        backdrop-filter: blur(12px) saturate(180%);
        -webkit-backdrop-filter: blur(12px) saturate(180%);
    }

    #dimensions-table.visible {
        transform: translateX(-50%) translateY(0);
    }

    .control-panel-version {
        font-size: 9px;
        color: #ffffff;
        opacity: 0.8;
    }

    #toggle-panel {
        z-index: 2001;
    }
}

@media (min-width: 901px) {
    #main-container {
        flex-direction: row;
    }

    #sidebar {
        width: 260px;
        height: 100vh;
        overflow-y: auto;
        padding: 30px 20px;
        background: linear-gradient(135deg,
            rgba(45, 55, 72, 0.95),
            rgba(30, 41, 59, 0.98)
        );
        backdrop-filter: blur(20px) saturate(180%);
        -webkit-backdrop-filter: blur(20px) saturate(180%);
        border-right: 1px solid rgba(255, 255, 255, 0.12);
        border-bottom: none;
        box-shadow: 10px 0 30px -10px rgba(0, 0, 0, 0.5);
    }

    #model-list {
        display: block;
        overflow-x: visible;
        gap: 12px;
    }

    .model-item {
        display: block;
        margin-bottom: 12px;
        width: 100%;
        white-space: normal;
        padding: 12px 20px;
        min-width: auto;
        text-align: left;
        font-size: 15px;
        background: rgba(255, 255, 255, 0.06);
        border-radius: 12px;
        border: 1px solid rgba(255, 255, 255, 0.08);
        transition: all 0.3s cubic-bezier(0.34, 1.56, 64, 1);
        position: relative;
        overflow: hidden;
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    }

    .model-item::before {
        content: '';
        position: absolute;
        top: 0;
        left: -100%;
        width: 100%;
        height: 100%;
        background: linear-gradient(90deg,
            transparent,
            rgba(255, 255, 255, 0.08),
            transparent
        );
        transition: left 0.5s ease;
        border-radius: 12px;
    }

    .model-item:hover {
        transform: translateX(8px) translateY(-2px);
        background: rgba(255, 255, 255, 0.12);
        border-color: rgba(255, 255, 255, 0.2);
        box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
    }

    .model-item:hover::before {
        left: 100%;
    }

    .model-item.active {
        background: linear-gradient(135deg,
            rgba(26, 188, 156, 0.9),
            rgba(52, 152, 219, 0.9)
        );
        border: 1px solid rgba(255, 255, 255, 0.4);
        box-shadow: 0 10px 30px -5px rgba(26, 188, 156, 0.5);
        transform: translateX(8px);
        font-weight: 600;
        animation: activePulse 2s ease-in-out infinite;
    }

    .model-item.active::before {
        display: none;
    }

    #viewer-wrapper {
        height: 100%;
    }

    #model-info {
        left: 20px;
        right: auto;
        bottom: 20px;
        max-width: 300px;
        text-align: left;
        padding: 14px 18px;
        background: rgba(20, 20, 30, 0.7);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        font-size: 15px;
    }

    #model-info strong {
        font-size: 15px;
    }

    #model-info span {
        font-size: 13px;
    }

    .control-panel {
        position: absolute;
        right: 20px;
        top: 20px;
        bottom: auto;
        left: auto;
        flex-direction: column;
        flex-wrap: nowrap;
        width: auto;
        transform: scale(0.9) translateX(calc(100% + 30px));
        padding: 12px;
        gap: 8px;
        background: rgba(20, 20, 30, 0.8);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border: 1px solid rgba(255, 255, 255, 0.12);
        transform-origin: top right;
        z-index: 2000;
    }

    .control-panel:not(.collapsed) {
        transform: scale(0.9) translateX(0);
        opacity: 1;
        visibility: visible;
    }

    .control-panel.collapsed {
        transform: scale(0.9) translateX(calc(100% + 30px));
        opacity: 0;
        visibility: hidden;
    }

    .control-group {
        min-width: auto;
        flex: none;
        width: auto;
    }

    .explosion-slider-container {
        width: auto;
    }

    .control-btn {
        width: 38px;
        height: 38px;
        font-size: 16px;
        background: rgba(255, 255, 255, 0.12);
    }

    .control-btn:hover {
        background: rgba(255, 255, 255, 0.2);
        transform: scale(1.1);
    }

    .control-btn.active {
        background: rgba(26, 188, 156, 0.7);
    }

    #bg-color {
        width: 38px;
        height: 38px;
    }

    #bg-color:hover {
        transform: scale(1.1);
        border-color: rgba(255, 255, 255, 0.4);
    }

    .explosion-slider {
        width: 120px;
    }

    #toggle-panel {
        position: absolute;
        top: 20px;
        right: 20px;
        bottom: auto;
        width: 50px;
        height: 50px;
        font-size: 20px;
        background: linear-gradient(135deg, rgba(52, 152, 219, 0.85) 0%, rgba(26, 188, 156, 0.85) 100%);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        z-index: 2001;
    }

    #toggle-panel:hover {
        transform: scale(1.1) rotate(90deg);
    }

    .back-btn {
        left: 20px;
        min-width: auto;
        font-size: 15px;
        background: rgba(30, 30, 40, 0.7);
        backdrop-filter: blur(15px);
        -webkit-backdrop-filter: blur(15px);
        z-index: 102;
    }

    .back-btn:hover {
        transform: translateY(-2px);
        background: rgba(40, 40, 50, 0.8);
    }

    #dimensions-table {
        top: 25px;
        left: 50%;
        right: auto;
        transform: translateX(-50%) translateY(-30px);
        background: rgba(255, 255, 255, 0.1);
        min-width: 180px;
        padding: 10px 16px;
        backdrop-filter: blur(12px) saturate(180%);
        -webkit-backdrop-filter: blur(12px) saturate(180%);
    }

    #dimensions-table.visible {
        transform: translateX(-50%) translateY(0);
    }

    .control-panel-version {
        display: none !important;
    }
}

/* CORREZIONE MENU STRUMENTI MOBILE LANDSCAPE */
@media (max-height: 500px) and (orientation: landscape) {
    #sidebar {
        height: 55px;
        min-height: 55px;
        padding: calc(4px + var(--safe-area-top)) 16px 4px;
        background: linear-gradient(135deg,
            rgba(45, 55, 72, 0.92),
            rgba(30, 41, 59, 0.98)
        );
    }

    #viewer-wrapper {
        height: calc(100% - 55px);
    }

    .model-item {
        padding: 6px 14px;
        min-width: 70px;
        font-size: 12px;
        background: rgba(255, 255, 255, 0.08);
    }

    .model-item:hover {
        transform: translateY(-1px) scale(1.01);
    }

    .model-item.active {
        background: linear-gradient(135deg,
            rgba(26, 188, 156, 0.9),
            rgba(52, 152, 219, 0.9)
        );
    }

    /* CORREZIONE: Menu centrato con margini corretti */
    .control-panel {
        position: absolute;
        left: 50% !important;
        right: auto !important;
        bottom: 10px !important;
        transform: scale(0.88) translateX(-50%) translateY(calc(100% + 100px)) !important;
        width: 90% !important;
        max-width: 500px !important;
        margin: 0 auto !important;
        flex-direction: row !important;
        flex-wrap: wrap !important;
        justify-content: space-around !important;
        background: rgba(20, 20, 30, 0.95) !important;
        z-index: 2000 !important;
    }

    .control-panel:not(.collapsed) {
        transform: scale(0.88) translateX(-50%) translateY(0) !important;
        opacity: 1 !important;
        visibility: visible !important;
    }

    .control-panel.collapsed {
        transform: scale(0.88) translateX(-50%) translateY(calc(100% + 100px)) !important;
        opacity: 0 !important;
        visibility: hidden !important;
    }

    .control-group {
        width: auto;
        min-width: 70px;
    }

    .explosion-slider-container {
        width: 100%;
    }

    .control-btn {
        width: 34px;
        height: 34px;
        font-size: 14px;
        background: rgba(255, 255, 255, 0.12);
    }

    #bg-color {
        width: 34px;
        height: 34px;
    }

    .explosion-slider {
        width: 70px;
        margin: 0 5px;
    }

    #model-info {
        bottom: 8px;
        left: 8px;
        max-width: 140px;
        padding: 6px 10px;
        font-size: 12px;
        background: rgba(20, 20, 30, 0.7);
    }

    #model-info strong {
        font-size: 12px;
    }

    #model-info span {
        font-size: 10px;
    }

    .back-btn {
        top: 8px;
        left: 8px;
        padding: 6px 12px;
        font-size: 12px;
        min-width: 100px;
        background: rgba(30, 30, 40, 0.7);
        z-index: 102;
    }

    #toggle-panel {
        width: 45px;
        height: 45px;
        font-size: 20px;
        bottom: 10px;
        right: 10px;
        background: linear-gradient(135deg, rgba(52, 152, 219, 0.85) 0%, rgba(26, 188, 156, 0.85) 100%);
        z-index: 2001;
    }

    #dimensions-table {
        top: 10px;
        left: auto;
        right: 8px;
        transform: translateY(-30px);
        padding: 8px 12px;
        min-width: 160px;
        background: rgba(255, 255, 255, 0.1);
        backdrop-filter: blur(10px) saturate(180%);
        -webkit-backdrop-filter: blur(10px) saturate(180%);
    }

    #dimensions-table.visible {
        transform: translateY(0);
    }

    .control-panel-version {
        font-size: 8px;
        color: #ffffff;
        opacity: 0.8;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
