/* ==========================================================================
   GLOBAL APP STYLES & RESET
   ========================================================================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #121214;
    color: #e2e2e5;
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ==========================================================================
   SIDEBAR CONTROL PANEL LAYOUT
   ========================================================================== */
.sidebar {
    width: 350px;
    background-color: #0b0b0d;
    padding: 25px;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
    z-index: 50;
    transition: transform 0.3s ease;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.close-sidebar {
    display: none;
    background: none;
    border: none;
    color: #a0a0a5;
    font-size: 24px;
    cursor: pointer;
    padding: 0 8px;
}

.close-sidebar:hover {
    color: #ffffff;
}

h2 {
    color: #ffffff;
    font-size: 22px;
    border-bottom: 2px solid #2a2a30;
    padding-bottom: 10px;
    margin: 0;
}

h3 {
    margin: 10px 0 5px 0;
    font-size: 14px;
    color: #007bff;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

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

label {
    font-size: 12px;
    color: #a0a0a5;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

hr {
    border: 0;
    border-top: 1px solid #2a2a30;
    margin: 5px 0;
}

/* ==========================================================================
   MOBILE TOGGLE BUTTON
   ========================================================================== */
.mobile-toggle {
    display: none;
    position: fixed;
    top: 15px;
    left: 15px;
    z-index: 100;
    background: #0b0b0d;
    border: 1px solid #3a3a42;
    color: white;
    padding: 12px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 20px;
    transition: all 0.2s ease;
}

.mobile-toggle:hover {
    background: #1c1c21;
}

/* ==========================================================================
   FORM ELEMENTS, DROPDOWNS, & TIMELINE SLIDERS
   ========================================================================== */
select, input, button {
    padding: 12px;
    background-color: #1c1c21;
    border: 1px solid #3a3a42;
    color: #ffffff;
    border-radius: 6px;
    font-size: 14px;
    outline: none;
    transition: all 0.2s ease;
    width: 100%;
    
    /* Standard appearance property for compatibility */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

/* Custom dropdown arrow for select elements */
select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23a0a0a5' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

select:focus, input:focus {
    border-color: #007bff;
}

/* Custom styling for drop-down option groups */
optgroup {
    background-color: #0b0b0d;
    color: #a0a0a5;
    font-weight: bold;
    font-style: normal;
    padding: 5px;
}

option {
    background-color: #1c1c21;
    color: #ffffff;
    padding: 5px;
}

/* Range Sliders custom styling */
input[type="range"] {
    padding: 0;
    cursor: pointer;
    background: transparent;
    
    /* Standard appearance property for compatibility */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

input[type="range"]::-webkit-slider-runnable-track {
    width: 100%;
    height: 6px;
    background: #3a3a42;
    border-radius: 3px;
}

input[type="range"]::-webkit-slider-thumb {
    height: 18px;
    width: 18px;
    border-radius: 50%;
    background: #007bff;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    margin-top: -6px;
    transition: background 0.1s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
    background: #0069d9;
}

input[type="range"]:focus::-webkit-slider-runnable-track {
    background: #4e4e5a;
}

/* Firefox range slider styling */
input[type="range"]::-moz-range-track {
    width: 100%;
    height: 6px;
    background: #3a3a42;
    border-radius: 3px;
    border: none;
}

input[type="range"]::-moz-range-thumb {
    height: 18px;
    width: 18px;
    border-radius: 50%;
    background: #007bff;
    cursor: pointer;
    border: none;
    transition: background 0.1s ease;
}

input[type="range"]::-moz-range-thumb:hover {
    background: #0069d9;
}

/* ==========================================================================
   COLOR PICKER OPTIONS
   ========================================================================== */
.color-options {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    margin-top: 4px;
}

.color-btn {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 8px;
    border: 2px solid #3a3a42;
    cursor: pointer;
    padding: 0;
    transition: all 0.2s ease;
    min-height: 32px;
    
    /* Standard appearance property for compatibility */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.color-btn:hover {
    transform: scale(1.05);
    border-color: #ffffff;
}

.color-btn.active {
    border-color: #007bff;
    box-shadow: 0 0 12px rgba(0, 123, 255, 0.4);
    transform: scale(1.05);
}

/* ==========================================================================
   CHECKBOX CUSTOM STYLING
   ========================================================================== */
.checkbox-container {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 0;
}

.checkbox-container input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: #007bff;
    
    /* Standard appearance property for compatibility */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    
    /* Custom checkbox styling */
    background-color: #1c1c21;
    border: 2px solid #3a3a42;
    border-radius: 4px;
    position: relative;
    flex-shrink: 0;
}

.checkbox-container input[type="checkbox"]:checked {
    background-color: #007bff;
    border-color: #007bff;
}

.checkbox-container input[type="checkbox"]:checked::after {
    content: "✓";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 12px;
    font-weight: bold;
}

.checkbox-container input[type="checkbox"]:focus {
    outline: 2px solid rgba(0, 123, 255, 0.4);
    outline-offset: 2px;
}

.checkbox-container label {
    text-transform: none;
    cursor: pointer;
    font-weight: normal;
    margin: 0;
}

/* ==========================================================================
   BUTTON STYLES
   ========================================================================== */
button {
    cursor: pointer;
    
    /* Standard appearance property for compatibility */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

button:hover {
    background-color: #2a2a32;
}

button:active {
    transform: scale(0.98);
}

/* Utility Helpers */
.hidden {
    display: none !important;
}

/* ==========================================================================
   MAIN 3D VIEWPORT CONTAINER & HUD OVERLAY
   ========================================================================== */
.viewport-container {
    flex-grow: 1;
    position: relative;
    height: 100%;
    background-color: #121214;
}

#canvas3d {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
}

/* Animation smoothing for HUD values shifting */
#mathHUD * {
    transition: all 0.3s ease-in-out;
}

/* ==========================================================================
   RESPONSIVE DESIGN - TABLETS & MOBILE
   ========================================================================== */
@media (max-width: 1024px) {
    .sidebar {
        width: 300px;
        padding: 20px;
    }
}

@media (max-width: 768px) {
    body {
        flex-direction: column;
    }

    .mobile-toggle {
        display: block !important;
    }

    .close-sidebar {
        display: block !important;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 85%;
        max-width: 350px;
        height: 100vh;
        transform: translateX(-100%);
        z-index: 50;
        padding: 20px;
        box-shadow: 4px 0 30px rgba(0, 0, 0, 0.9);
        overflow-y: auto;
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    .viewport-container {
        width: 100%;
        height: 100vh;
    }

    #mathHUD {
        top: 70px !important;
        left: 10px !important;
        max-width: 200px !important;
        padding: 12px !important;
        font-size: 12px !important;
    }

    #mathHUD h3 {
        font-size: 13px !important;
    }

    #mathHUD p {
        font-size: 11px !important;
    }

    #mathHUD #hud-equation {
        font-size: 12px !important;
    }

    .color-options {
        grid-template-columns: repeat(5, 1fr);
        gap: 6px;
    }

    .color-btn {
        min-height: 28px;
    }
}

@media (max-width: 480px) {
    .sidebar {
        width: 90%;
        max-width: 320px;
        padding: 15px;
    }

    h2 {
        font-size: 18px;
    }

    select, input, button {
        padding: 10px;
        font-size: 13px;
    }

    #mathHUD {
        max-width: 160px !important;
        padding: 10px !important;
        top: 60px !important;
        left: 8px !important;
    }

    #mathHUD h3 {
        font-size: 11px !important;
    }

    #mathHUD p {
        font-size: 10px !important;
    }

    #mathHUD #hud-equation {
        font-size: 10px !important;
    }

    .color-options {
        grid-template-columns: repeat(5, 1fr);
        gap: 5px;
    }

    .color-btn {
        min-height: 24px;
        border-radius: 6px;
    }
}

/* Fix for very small screens */
@media (max-width: 360px) {
    #mathHUD {
        max-width: 130px !important;
        padding: 8px !important;
        top: 55px !important;
        left: 5px !important;
    }

    #mathHUD h3 {
        font-size: 10px !important;
        margin-bottom: 4px !important;
    }

    #mathHUD p {
        font-size: 9px !important;
        line-height: 1.2 !important;
    }

    #mathHUD #hud-equation {
        font-size: 9px !important;
        margin-top: 6px !important;
    }
}