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

html, body {
    margin: 0;
    padding: 0;
    overflow: hidden;
    height: 100%;
    height: 100dvh;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #6c9257 0%, #5a7a4a 100%);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    position: fixed;
    width: 100%;
}

#app-container {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    max-width: 100%;
    overflow: hidden;
}

#main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

#preview-section {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: linear-gradient(135deg, #6c9257 0%, #5a7a4a 100%);
    position: relative;
    min-height: 0;
    overflow: hidden;
    width: calc(100% - 1rem);
    height: calc(100% - 1rem);
    border-radius: 20px;
    margin: 0.5rem 0.5rem;
}

#three-canvas {
    width: 100%;
    height: 100%;
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 20px;
    box-sizing: border-box;
}

.cicg-logo {
    position: absolute;
    top: 1rem;
    left: 1rem;
    z-index: 20;
    padding: 0;
}

.ar-icon-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    padding: 0.5rem;
    background: linear-gradient(135deg, #6c9257 0%, #5a7a4a 100%);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(108, 146, 87, 0.3);
    transition: all 0.3s;
    z-index: 25;
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ar-icon-btn img {
    width: 70%;
    height: 70%;
    object-fit: contain;
    filter: brightness(0) invert(1);
}

.ar-icon-btn:hover {
    background: linear-gradient(135deg, #7ba868 0%, #6c9257 100%);
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(108, 146, 87, 0.5);
}

.ar-icon-btn.hidden {
    display: none;
}

.change-setup-btn {
    position: absolute;
    top: 1rem;
    left: 50%;
    transform: translateX(-50%);
    padding: 0.75rem 1.5rem;
    background: linear-gradient(135deg, #6c9257 0%, #5a7a4a 100%);
    color: white;
    border: none;
    border-radius: 25px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(108, 146, 87, 0.5);
    transition: all 0.3s;
    z-index: 25;
}

.change-setup-btn:hover {
    transform: translateX(-50%) translateY(-2px);
    box-shadow: 0 6px 20px rgba(108, 146, 87, 0.6);
}

.change-setup-btn:active {
    transform: translateX(-50%) translateY(0);
}

.change-setup-btn.hidden {
    display: none;
}

.cicg-logo img {
    width: 40px;
    height: 40px;
    display: block;
}

/* Level List - Bottom Center */
#level-list {
    position: absolute;
    bottom: 0.5rem;
    left: 50%;
    transform: translateX(-50%);
    display: none;
    flex-direction: row;
    gap: 0.5rem;
    z-index: 30;
}

#level-list.visible {
    display: flex;
}

.level-btn {
    padding: 0.75rem 1.25rem;
    background: rgba(255, 255, 255, 0.9);
    color: #6c9257;
    border: 2px solid #6c9257;
    border-radius: 12px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    min-width: 120px;
    margin: 0;
    position: relative;
}

.level-btn:hover {
    background: rgba(255, 255, 255, 1);
    transform: translateY(-5px);
    z-index: 1;
}

.level-btn.active {
    background: linear-gradient(135deg, #6c9257 0%, #5a7a4a 100%);
    color: white;
    border-color: #6c9257;
    z-index: 1;
    position: relative;
}

.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.9);
    z-index: 10;
    border-radius: 20px;
}

.loading-overlay.hidden {
    display: none;
}

.spinner {
    border: 4px solid rgba(108, 146, 87, 0.3);
    border-top: 4px solid #6c9257;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

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

.loading-overlay p {
    color: #6c9257;
    font-size: 1rem;
    font-weight: 500;
    margin: 0;
}

#model-viewer {
    width: 100%;
    height: 100%;
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 20px;
    background: white;
    box-sizing: border-box;
}

#control-panel {
    background: white;
    padding: 1rem 1.5rem;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom));
    border-top-left-radius: 25px;
    border-top-right-radius: 25px;
    box-shadow: 0 -5px 20px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
    height: auto;
    min-height: auto;
    max-height: none;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    overflow-x: hidden;
    overflow-y: visible;
}

#control-panel h3 {
    color: #333;
    margin-bottom: 1rem;
    font-size: 1.2rem;
    text-align: center;
}

.button-group {
    display: flex;
    justify-content: center;
    gap: 0.8rem;
    flex-wrap: nowrap;
    margin-bottom: 0;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: rgba(108, 146, 87, 0.3) transparent;
    padding-top: 5px;
    margin-top: -5px;
}

.button-group::-webkit-scrollbar {
    height: 4px;
}

.button-group::-webkit-scrollbar-track {
    background: transparent;
}

.button-group::-webkit-scrollbar-thumb {
    background: rgba(108, 146, 87, 0.3);
    border-radius: 2px;
}

.button-group .model-btn,
.button-group .room-btn {
    flex: 0 0 auto;
    min-width: 120px;
    box-sizing: border-box;
}

.model-btn {
    padding: 0.75rem 1.25rem;
    background: linear-gradient(135deg, #6c9257 0%, #5a7a4a 100%);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s;
    min-width: 90px;
    box-shadow: 0 4px 15px rgba(108, 146, 87, 0.4);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
}

.room-btn {
    padding: 0.75rem 1.25rem;
    background: rgba(255, 255, 255, 0.9);
    color: #6c9257;
    border: 2px solid #6c9257;
    border-radius: 12px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    min-width: 90px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.model-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(108, 146, 87, 0.6);
}

.room-btn:hover {
    background: rgba(255, 255, 255, 1);
    transform: translateY(-5px);
    z-index: 1;
}

.model-btn:active {
    transform: translateY(0);
}

.room-btn:active {
    transform: translateY(0);
}

.model-btn.active {
    background: linear-gradient(135deg, #6c9257 0%, #5a7a4a 100%);
    color: white;
    border: 2px solid #6c9257;
    box-shadow: 0 4px 15px rgba(108, 146, 87, 0.5);
}

.room-btn.active {
    background: linear-gradient(135deg, #6c9257 0%, #5a7a4a 100%);
    color: white;
    border-color: #6c9257;
    z-index: 1;
    position: relative;
    font-weight: 600;
}

.btn-icon {
    font-size: 1.5rem;
}

.info-text {
    text-align: center;
    color: #666;
    font-size: 0.9rem;
    margin-top: 0.5rem;
}

.info-text p {
    margin: 0;
}

/* AR Button Styling */
.ar-button {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 1rem 2rem;
    background: linear-gradient(135deg, #6c9257 0%, #5a7a4a 100%);
    color: white;
    border: none;
    border-radius: 50px;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 8px 25px rgba(108, 146, 87, 0.5);
    transition: all 0.3s;
    z-index: 10;
}

.ar-button:hover {
    transform: translateX(-50%) translateY(-2px);
    box-shadow: 0 10px 30px rgba(108, 146, 87, 0.6);
}

.ar-button:active {
    transform: translateX(-50%) translateY(0);
}

/* Hide default model-viewer AR button if needed */
model-viewer::part(default-ar-button) {
    display: none;
}

@media (max-width: 1000px) {
    #preview-section {
        padding: 0.5rem;
    }

    #model-viewer {
        height: 100%;
        border-radius: 15px;
    }
    
    .cicg-logo img {
        width: 35px;
        height: 35px;
    }

    #level-list {
        position: absolute;
        bottom: 0.5rem;
        left: 0.5rem;
        right: 0.5rem;
        transform: none;
        display: none;
        flex-direction: row;
        gap: 0.25rem;
        flex-wrap: nowrap;
        justify-content: space-between;
        width: auto;
        max-width: none;
        padding: 0;
        box-sizing: border-box;
    }

    #level-list.visible {
        display: flex;
    }

    .level-btn {
        flex: 1 1 0;
        min-width: 0;
        max-width: none;
        padding: 0.5rem 0.2rem;
        font-size: 0.65rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    /* #control-panel {
        padding: 0.75rem 1rem;
        padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
        height: 140px;
        min-height: 140px;
        max-height: 140px;
    } */

    /* .button-group {
        gap: 0.5rem;
        justify-content: center;
        flex-wrap: wrap;
        overflow-x: visible;
    } */

    .button-group {
        justify-content: flex-start;
    }

    /* .button-group .model-btn,
    .button-group .room-btn {
        flex: 0 0 calc((100% - 1rem) / 3);
        min-width: 0;
        max-width: calc((100% - 1rem) / 3);
    } */
    
    .model-btn,
    .room-btn {
        padding: 0.6rem 0.8rem;
        font-size: 0.8rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        text-align: center;
    }
    
    /* Force Building button to full width on first row */
    #btn-building {
        flex: 0 0 100%;
        width: 100%;
        max-width: 100%;
        order: 1;
    }
    
    /* Force remaining 3 buttons to second row */
    #btn-rectangle,
    #btn-standard,
    #btn-theatre {
        flex: 1 1 calc(33.333% - 0.34rem);
        max-width: calc(33.333% - 0.34rem);
        order: 2;
    }

    .ar-button {
        padding: 0.75rem 1.5rem;
        font-size: 1rem;
        bottom: 15px;
    }
}

/* Landscape orientation */
@media (max-width: 1000px) and (orientation: landscape) {
    #main-content {
        flex-direction: row;
    }

    #preview-section {
        flex: 1;
        padding: 0;
        margin: 0.5rem 0.5rem;
        width: calc(100% - 1rem);
        height: calc(100% - 1rem);
    }
    
    .cicg-logo {
        top: 0.5rem;
        left: 0.5rem;
    }
    
    .cicg-logo img {
        width: 30px;
        height: 30px;
    }
    
    #control-panel {
        flex: 0 0 200px;
        width: 200px;
        padding: 0.5rem 1rem;
        padding-bottom: calc(0.5rem + env(safe-area-inset-bottom));
        height: auto;
        min-height: auto;
        max-height: none;
        margin: 0;
        border-top-left-radius: 25px;
        border-bottom-left-radius: 25px;
        border-top-right-radius: 0;
        border-bottom-right-radius: 0;
        box-shadow: none;
        overflow-y: auto;
        overflow-x: hidden;
    }

    #control-panel h3 {
        margin-bottom: 0.75rem;
        font-size: 1rem;
    }

    .button-group {
        flex-direction: column;
        gap: 0.5rem;
        justify-content: flex-start;
        flex-wrap: nowrap;
        overflow-x: visible;
        overflow-y: visible;
    }

    .button-group .model-btn,
    .button-group .room-btn {
        flex: 0 0 auto;
        width: 100%;
        min-width: 0;
        max-width: 100%;
    }

    .model-btn,
    .room-btn {
        font-size: 0.8rem;
        padding: 0.6rem 0.8rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    .model-btn {
        min-width: 0;
    }
}