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

body {
    overflow: hidden;
    background-color: #111;
    font-family: 'Inter', sans-serif;
}

#canvas-container {
    width: 100vw;
    height: 100dvh;
}

#loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 1.5rem;
    pointer-events: none;
    transition: opacity 0.5s;
    background: rgba(0, 0, 0, 0.5);
    padding: 20px 40px;
    border-radius: 12px;
    backdrop-filter: blur(5px);
    z-index: 10;
}

/* UI Overlay Layer */
#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100dvh;
    pointer-events: none;
    /* Let clicks pass through to the 3D canvas natively */
    z-index: 5;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

/* Make all custom interface elements clickable again */
.glass-panel,
.glass-btn {
    pointer-events: auto;
}

/* Glassmorphism Styles */
.glass-panel {
    background: rgba(14, 171, 67, 0.65);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.4);
    color: #e0e6ed;
    border-radius: 16px;
}

.glass-btn {
    background: rgba(255, 255, 255, 1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #000000;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s ease;
    backdrop-filter: blur(8px);
}

.glass-btn:hover {
    background: rgba(14, 171, 67, 0.15);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

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

/* Specific UI Elements */
#reset-view-btn {
    position: absolute;
    top: 20px;
    right: 20px;
}

.primary-btn {
    background: rgba(60, 130, 240, 0.4);
    border-color: rgba(60, 130, 240, 0.6);
}

.primary-btn:hover {
    background: rgba(60, 130, 240, 0.6);
}

#nav-bar {
    position: absolute;
    top: 30px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 15px;
    padding: 15px 25px;
    border-radius: 40px;
}

/* Detailed Information Panel */
#detail-panel {
    position: absolute;
    top: 20px;
    left: 20px;
    width: 320px;
    padding: 25px;
    background: rgba(58, 176, 255, 0.4);
    transform: translateX(0);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.4s ease;
}

#detail-panel.hidden {
    transform: translateX(-350px);
    opacity: 0;
    pointer-events: none;
}

#detail-title {
    margin-bottom: 15px;
    font-size: 1.5rem;
    font-weight: 600;
    color: #ffffff;
}

#detail-desc {
    font-size: 0.95rem;
    line-height: 1.5;
    margin-bottom: 20px;
    color: #ffffff;
}

#detail-extra-info {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 25px;
    font-size: 0.85rem;
    background: rgba(58, 176, 255, 0.7);
    padding: 15px;
    border-radius: 8px;
}

#detail-extra-info strong {
    color: #fff;
}

#close-panel-btn {
    width: 100%;
    background: rgba(75, 142, 183, 0.2);
    border-color: rgba(0, 174, 186, 0.4);
    color: #ffffff;
}


#close-panel-btn:hover {
    background: rgba(255, 80, 80, 0.4);
}

/* Hover Info Card */
#hover-card {
    position: absolute;
    pointer-events: none;
    /* Never intercept mouse */
    padding: 15px;
    width: 220px;
    transition: opacity 0.2s ease, transform 0.2s ease;
    /* initial placement logic handled via JS */
    opacity: 1;
    transform: translateY(0);
}

#hover-card.hidden {
    opacity: 0;
    transform: translateY(10px);
}

#hover-title {
    font-size: 1.1rem;
    margin-bottom: 5px;
    color: #fff;
}

#hover-desc {
    font-size: 0.85rem;
    color: #ffffff;
    line-height: 1.4;
}

/* Watermark */
#watermark {
    position: absolute;
    bottom: 15px;
    right: 25px;
    color: rgba(255, 255, 255, 0.35);
    font-size: 0.75rem;
    font-weight: 400;
    pointer-events: none;
    user-select: none;
    letter-spacing: 0.5px;
}

/* Responsive Adjustments for Mobile Landscape / Short Screens */
@media (max-height: 500px) {
    #nav-bar {
        top: 15px;
        padding: 5px 15px;
        gap: 8px;
        transform: translateX(-50%) scale(0.9);
    }

    #detail-panel {
        top: 10px;
        left: 10px;
        width: 260px;
        padding: 15px;
        bottom: 10px;
        overflow-y: auto;
    }

    #detail-title {
        font-size: 1.1rem;
        margin-bottom: 8px;
    }

    #detail-desc {
        font-size: 0.8rem;
        margin-bottom: 10px;
    }

    #detail-extra-info {
        padding: 10px;
        margin-bottom: 15px;
        gap: 4px;
    }

    #reset-view-btn {
        top: 15px;
        right: 15px;
        padding: 8px 12px;
        font-size: 12px;
    }

    /* Move hover card if panel is open to avoid overlay */
    #hover-card {
        transform: scale(0.85);
        z-index: 15; /* Above other UI */
    }
}

/* Responsive Adjustments for Mobile Portrait / Narrow Screens */
@media (max-width: 600px) {
    #nav-bar {
        width: 95%;
        top: 20px;
        overflow-x: auto;
        justify-content: flex-start;
        border-radius: 12px;
        padding: 12px;
        scrollbar-width: none; /* Hide scrollbar Firefox */
        -ms-overflow-style: none; /* Hide scrollbar IE/Edge */
    }

    #nav-bar::-webkit-scrollbar {
        display: none; /* Hide scrollbar Chrome/Safari */
    }

    #detail-panel {
        top: auto;
        bottom: calc(30px + env(safe-area-inset-bottom)); /* Increase spacing for safe area */
        left: 50%;
        width: calc(100% - 40px);
        max-height: 48dvh; /* slightly more height if possible */
        overflow-y: auto;
        z-index: 20;
        transform: translateX(-50%); /* Centering */
        padding-bottom: calc(20px + env(safe-area-inset-bottom)); /* Internal padding for button visibility */
    }


    #detail-panel.hidden {
        transform: translateX(-50%) translateY(100px);
        opacity: 0;
    }

    #hover-card {
        display: none; /* Mostly irrelevant on touch portrait */
    }
}

/* CAD Crosshair & Coordinate Tooltip */
#crosshair-x,
#crosshair-y {
    position: absolute;
    background: rgba(255, 255, 255, 0.4);
    pointer-events: none; /* Let clicks pass through */
    z-index: 100;
}

#crosshair-x {
    width: 100vw;
    height: 1px;
    top: -10px; /* Hide initially */
    left: 0;
}

#crosshair-y {
    width: 1px;
    height: 100vh;
    top: 0;
    left: -10px; /* Hide initially */
}

#coords-tooltip {
    position: absolute;
    pointer-events: none;
    z-index: 101;
    background: rgba(14, 171, 67, 0.8);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 8px 12px;
    border-radius: 8px;
    color: white;
    font-size: 13px;
    font-weight: 600;
    font-family: 'JetBrains Mono', 'Courier New', monospace; /* Use monospaced for numbers */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.2s;
}

.coords-label {
    opacity: 0.7;
    margin-right: 4px;
}

.coords-val {
    color: #fff;
}