/* General Styles & Apple/Minimalist Typography */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap');

:root {
    --glass-bg: rgba(255, 255, 255, 0.75);
    --glass-border: rgba(255, 255, 255, 0.4);
    --text-primary: #1d1d1f;
    --text-secondary: #86868b;
    --apple-blue: #0071e3;
    --apple-blue-hover: #0077ED;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--text-primary);
    overflow: hidden; 
    background-color: #f5f5f7; 
}

/* 3D Container */
#canvas-container, #css2d-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1;
}

#css2d-container {
    z-index: 2;
    pointer-events: none; 
}

/* Glassmorphism Helper */
.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
    border-radius: 16px;
}

/* UI Structure */
.ui-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none; 
}

/* Desktop nav: centered pill shape */
.top-nav {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 580px;
    padding: 14px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    pointer-events: auto;
    /* Reserve space for the right-side circular button (48px + 20px margin + gap) */
    padding-right: 20px;
}

.top-nav h2 {
    font-size: 1.1rem;
    font-weight: 600;
    white-space: nowrap;
    margin-right: 12px;
    flex-shrink: 0;
}

/* Mobile: stack nav to left edge, leaving right side free for tool buttons */
@media (max-width: 500px) {
    .top-nav {
        top: 16px;
        left: 16px;
        right: 80px;
        width: auto;
        transform: none;
        max-width: none;
        padding: 10px 14px;
        gap: 10px;
    }

    .top-nav h2 {
        font-size: 0.95rem;
    }

    .btn-primary {
        padding: 8px 12px;
        font-size: 0.82rem;
        white-space: nowrap;
    }

    .floating-tools {
        bottom: 24px;
        right: 16px;
    }

    .side-panel {
        bottom: 20px;
        left: 12px;
        width: calc(100% - 24px);
        max-width: none;
    }
}

/* Side Panel Updates: Collapsible Structure */
.side-panel {
    position: absolute;
    bottom: 30px;
    left: 20px;
    width: calc(100% - 40px);
    max-width: 320px;
    pointer-events: auto;
    transition: opacity 0.3s ease, transform 0.3s ease;
    overflow: hidden;
}

.side-panel.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    cursor: pointer;
    background: rgba(255,255,255,0.4);
    border-bottom: 1px solid transparent;
}
.panel-header:hover { background: rgba(255,255,255,0.6); }

.panel-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: #1d1d1f;
    margin: 0;
}

.chevron {
    font-size: 0.9rem;
    color: var(--text-secondary);
    transition: transform 0.3s ease;
}

.panel-content {
    padding: 0 24px 24px 24px;
    margin-top: 16px; 
}

/* Inner Text Elements */
.side-panel h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: #1d1d1f;
}

.info-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.info-row .label { color: var(--text-secondary); }
.info-row .value { font-weight: 500; font-family: monospace; font-size: 1rem; }

.divider {
    height: 1px;
    background: rgba(0,0,0,0.1);
    margin: 20px 0;
}

/* Buttons */
.btn-primary {
    background-color: var(--apple-blue);
    color: white;
    padding: 10px 18px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
    border: none;
    outline: none;
}
.btn-primary:active { background-color: var(--apple-blue-hover); transform: scale(0.98); }

.btn-secondary {
    background-color: rgba(0,0,0,0.05);
    color: var(--text-primary);
    padding: 10px 16px;
    border-radius: 12px;
    font-size: 0.9rem;
    cursor: pointer;
    border: none;
    width: 100%;
    font-weight: 500;
    transition: background 0.2s;
}
.btn-secondary.active {
    background-color: var(--text-primary);
    color: white;
}
.btn-text {
    background: none; border: none; font-size: 0.85rem; color: #ff3b30; cursor: pointer; text-decoration: underline; margin-top: 10px; width:100%; text-align:center;
}
.btn-text.hidden { display: none; }

/* Floating Measurement Tool (Bottom Right, Draggable) */
.floating-tools {
    position: fixed;
    bottom: 30px;
    right: 20px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    pointer-events: auto;
    z-index: 20;
    user-select: none;
    -webkit-user-select: none;
}

.circular-btn {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.4rem;
    cursor: grab;
    border: 1px solid var(--glass-border);
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.15);
    transition: transform 0.15s, background 0.2s, box-shadow 0.2s;
    outline: none;
}
.circular-btn:active { transform: scale(0.96); }
.circular-btn.dragging {
    cursor: grabbing;
    box-shadow: 0 12px 32px rgba(0,0,0,0.25);
    transform: scale(1.08);
}
.circular-btn.active {
    background: var(--apple-blue);
    border-color: var(--apple-blue);
    color: white;
}

.measure-tips {
    margin-bottom: 12px;  /* appears above the circular button */
    padding: 12px 16px;
    text-align: right;
    transition: opacity 0.3s, transform 0.3s;
    order: -1; /* render above the button inside flex column-reverse */
}
.measure-tips.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(10px);
}

.tip-text { margin-top: 8px; font-size: 0.82rem; color: var(--text-secondary); text-align: right; }

/* CSS2D Label styles rendering IN 3D SPACE */
.measurement-label {
    background: rgba(255,255,255,0.85); /* Apple-like light tooltip */
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(0,0,0,0.1);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: bold;
    font-family: monospace;
    pointer-events: none;
    white-space: nowrap;
    transform: translate(-50%, -50%); 
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    text-align: left;
}

.measurement-label.multi-line .main-dist {
    font-size: 14px;
    color: var(--apple-blue);
    margin-bottom: 4px;
    border-bottom: 1px solid rgba(0,0,0,0.1);
    padding-bottom: 4px;
}

.measurement-label.multi-line .sub-dist {
    color: var(--text-secondary);
    font-size: 11px;
    line-height: 1.4;
}

/* Loader Screen & Mario Kart Animation */
.loader-bg {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(255,255,255,0.85); /* Frosty background to focus on Mario */
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    z-index: 999; display: flex; flex-direction: column; justify-content: center; align-items: center;
    transition: opacity 0.5s ease-out;
}
.loader-bg.hidden { opacity: 0; pointer-events: none; }

.mario-container {
    position: relative;
    width: 200px;
    height: 120px;
    margin-bottom: 16px;
    overflow: hidden; 
    border-radius: 12px;
}
.road {
    position: absolute;
    bottom: 10px;
    width: 400px; /* Double width to support seamless scrolling */
    height: 12px;
    background: repeating-linear-gradient(
        -45deg,
        #ffd700, #ffd700 20px,
        #333 20px, #333 40px
    );
    animation: roadScroll 0.8s linear infinite;
    border-radius: 6px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}
@keyframes roadScroll {
    0% { transform: translateX(0); }
    100% { transform: translateX(-56.5px); } /* Match the repeating gradient math perfectly */
}

.mario-kart {
    width: 90px;
    position: absolute;
    bottom: 20px;
    left: 55px; /* Stay fixed in the center while road moves */
    animation: kartBump 0.25s infinite alternate ease-in-out, driveIn 1s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    filter: drop-shadow(0px 8px 8px rgba(0,0,0,0.3));
}
@keyframes kartBump {
    0% { transform: translateY(0px) rotate(-3deg); }
    100% { transform: translateY(-10px) rotate(3deg); }
}
@keyframes driveIn {
    0% { left: -100px; transform: scale(0.5); }
    100% { left: 55px; transform: scale(1); }
}

.progress-text {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--apple-blue);
    font-family: 'Inter', monospace;
    margin-bottom: 6px;
}
#loader-text {
    color: var(--text-secondary);
    font-weight: 500;
}
