html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;          /* full viewport height */
    overflow: hidden;      /* prevent body scroll */
    box-sizing: border-box;
    font-family: sans-serif;
}

*,
*:before,
*:after {
    box-sizing: inherit;
}

.color-scroll-container {
    flex: 1 1 auto;  /* takes remaining space */
    overflow-y: auto; /* scroll only here */
}

/* -------------------- UI Panel -------------------- */
#ui {
    position: absolute;
    top: 20px;
    left: 20px;
    width: min(400px, 30vw);
    bottom: 10px;
    z-index: 10;

    display: flex;
    flex-direction: column;

    background: rgba(30, 30, 30, 0.85); /* dark, semi-transparent */
    color: #fff;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 8px 20px rgba(0,0,0,0.5);
    font-family: 'Segoe UI', 'Roboto', sans-serif;

    /* Desktop: fade-in animation */
    opacity: 0;
    transform: translateY(-20px);
    animation: fadeInPanel 0.5s forwards ease-out;
    transition: transform 0.35s ease, opacity 0.35s ease; /* mobile slide-in will also use this */
}

/* Fade-in animation for desktop */
@keyframes fadeInPanel {
    to { opacity: 1; transform: translateY(0); }
}

/* -------------------- Toggle button for mobile -------------------- */
#uiToggleBtn {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 20;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 6px;
    background: rgba(30,30,30,0.85);
    color: #fff;
    font-size: 24px;
    cursor: pointer;
    display: none;  /* hidden on desktop */
}

/* -------------------- Headings -------------------- */
#ui h3 {
    margin: 10px 0 5px 0;
    font-size: 14px;
    font-weight: 600;
    color: #eee;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

/* -------------------- Buttons -------------------- */
button {
    width: 100%;
    padding: 8px 10px;
    margin: 5px 0;
    border: none;
    border-radius: 6px;
    background: linear-gradient(135deg, #4CAF50, #2E8B57);
    color: #fff;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

button:hover {
    background: linear-gradient(135deg, #6DD175, #36A36D);
    transform: translateY(-1px);
}

/* -------------------- Color Pickers -------------------- */
input[type="color"] {
    width: 100%;
    height: 32px;
    border: none;
    border-radius: 6px;
    padding: 0;
    margin: 5px 0 15px 0;
    cursor: pointer;
    -webkit-appearance: none;
}

input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

input[type="color"]::-webkit-color-swatch {
    border-radius: 6px;
    border: none;
}

.randomize-section {
    flex: 0 0 auto;     /* stay at bottom */
    text-align: center;
    border-top: 1px solid #ccc;
    margin-top: 10px;
    padding-top: 10px;
}

.randomize-btn {
    padding: 12px 12px;
    font-size: 16px;
    background: linear-gradient(135deg, #ff6b6b, #ff8e8e);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    box-shadow: 0 4px 12px rgba(255, 107, 107, 0.4);
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.randomize-btn:hover {
    background: linear-gradient(135deg, #ff5252, #ff6b6b);
    box-shadow: 0 6px 16px rgba(255, 107, 107, 0.6);
    transform: translateY(-2px);
}

.randomize-btn:active {
    transform: translateY(0);
}

.color-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(30px, 1fr));
    gap: 4px;          /* spacing between swatches */
    padding: 4px;       /* extra space inside the container */
    margin-bottom: 6px;
}

.color-swatch {
    width: 30px;
    height: 30px;
    border-radius: 3px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform 0.15s, border 0.15s;
}

.color-swatch:hover {
    transform: scale(1.1);
}

.color-selected {
    border: 2px solid white;
    box-shadow: 0 0 6px rgba(0, 0, 0, 0.4);
}

.color-swatch.selected {
    outline: 3px solid #FFD700; /* gold highlight, can tweak */
    box-shadow: 0 0 5px #FFD700;
}

.style-row {
    display: flex;
    gap: 10px;  /* Space between columns */
    width: 100%;
}

.style-column {
    flex: 1;  /* Equal width - each takes 50% */
    display: flex;
    flex-direction: column;
}

.style-column h3 {
    margin: 0 0 10px 0;
    text-align: center;
}

.style-buttons {
    display: flex;
    flex-direction: column;  /* Stack buttons vertically */
    gap: 8px;
}

.style-buttons button {
    flex: 1;  /* Buttons take equal height within column */
    padding: 6px;
    font-size: 16px;
    border: none;
    border-radius: 8px;
    background: linear-gradient(135deg, #4CAF50, #2E8B57);
    /*cursor: pointer;*/
    transition: all 0.2s;
}

.style-buttons button:hover {
    background: linear-gradient(135deg, #6DD175, #36A36D);
    transform: translateY(-1px);
}

.style-buttons button.selected {
    border: 2px solid #FFD700;
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.9);
    transform: scale(1.05);
}

.style-buttons button:active {
    transform: translateY(0);
}

.add-to-cart-section {
    padding: 2px 0;
    border-top: 2px solid #333;
    margin-top: 5px;
}

.add-to-cart-btn {
    width: 100%;
    padding: 18px 24px;
    font-size: 20px;
    font-weight: 700;
    background: linear-gradient(135deg, #28a745, #20c997);
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 6px 20px rgba(40, 167, 69, 0.4);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.add-to-cart-btn:hover {
    background: linear-gradient(135deg, #218838, #1ea085);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(40, 167, 69, 0.5);
}

.add-to-cart-btn:active {
    transform: translateY(0);
}



/* Toggle button for mobile */
#uiToggleBtn {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 20;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 6px;
    background: rgba(30,30,30,0.85);
    color: #fff;
    font-size: 24px;
    cursor: pointer;
    display: none;  /* hidden on desktop */
}

/* Mobile color debug panel */
#mobileColorDebug {
    position: fixed;
    top: 15px;
    right: 15px;
    background: rgba(30,30,30,0.85);
    color: white;
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 13px;
    z-index: 15;
    backdrop-filter: blur(6px);
    line-height: 1.4;
    display: none;
}

#loadingOverlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #B2BEB5; /* same as scene bg */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

#loadingBarContainer {
    width: 70%;
    height: 20px;
    background: #ccc;
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 10px;
}

#loadingBar {
    width: 0%;
    height: 100%;
    background: #35E047; /* green accent */
    transition: width 0.3s;
}

#loadingText {
    font-family: sans-serif;
    font-size: 18px;
    color: #333;
}

.add-to-cart-btn .price {
    margin-left: 10px;
    font-weight: 700;
    font-size: 18px;
    display: inline-flex;
    align-items: center;
    gap: 6px; /* space between old and new price */
}

.add-to-cart-btn .old-price {
    text-decoration: line-through;
    color: #fff;       /* white for contrast */
    opacity: 0.7;      /* slightly faded */
    font-size: 16px;
}

.add-to-cart-btn .new-price {
    background: #fff;       /* white background */
    color: #28a745;         /* green text for new price */
    font-weight: 700;
    padding: 2px 6px;       /* padding inside price box */
    border-radius: 4px;
    font-size: 18px;
    position: relative;     /* needed for badge positioning */
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.add-to-cart-btn .sale-badge {
    background: #ff3b3b;   /* red badge */
    color: #fff;
    font-size: 10px;
    font-weight: bold;
    padding: 2px 4px;
    border-radius: 3px;
    text-transform: uppercase;
}

/* Only show on mobile */
@media (max-width: 768px) {
    #mobileColorDebug {
        display: block;
    }
}

/* ---------------- Responsive tweaks ---------------- */
@media (max-height: 1000px) {
    .color-swatch {
        width: 28px;
        height: 28px;
    }

    .color-grid {
        gap: 4px;
    }
}

@media (max-height: 860px) {
    #ui h3 {
        font-size: 12px;
    }
    .color-swatch {
        width: 20px;
        height: 20px;
    }
    .color-grid {
        gap: 3px;
    }
    button {
        padding: 6px 8px;
        font-size: 12px;
    }
    .randomize-btn {
        padding: 10px 18px;
        font-size: 14px;
    }
}

@media (max-width: 768px) {
    #uiToggleBtn {
        display: block; /* show button on mobile */
    }

    #ui {
        top: 0;
        left: 0;
        bottom: 0;
        width: 280px;
        transform: translateX(-100%); /* hide panel offscreen */
        opacity: 1; /* keep visible for mobile slide animation */
        animation: none; /* disable desktop fade-in */
        padding-top: 60px; /* space for the hamburger button */
    }

    #ui.visible {
        transform: translateX(0); /* slide in */
    }
    .color-grid {
        grid-template-columns: repeat(10, 1fr);
        gap: 3px;
    }

    .color-swatch {
        width: 100%;
        height: auto;
        aspect-ratio: 1 / 1;
    }
}