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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    color: #fff;
    overflow: hidden;
}

#canvas-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* Reference Panel (Left) */
.reference-panel {
    position: fixed;
    left: -350px;
    top: 20px;
    width: 350px;
    max-height: calc(100vh - 40px);
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(10px);
    border-radius: 0 15px 15px 0;
    padding: 20px;
    z-index: 10;
    overflow-y: auto;
    transition: left 0.3s ease;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.reference-panel.open {
    left: 0;
}

.reference-toggle {
    position: fixed;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(138, 85, 254, 0.8);
    color: white;
    border: none;
    padding: 15px 10px;
    border-radius: 0 8px 8px 0;
    cursor: pointer;
    z-index: 11;
    font-size: 1.2rem;
    transition: all 0.3s ease;
}

.reference-toggle:hover {
    background: rgba(138, 85, 254, 1);
    padding-right: 15px;
}

.metal-ref-card {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 15px;
    font-size: 0.85rem;
}

.metal-ref-name {
    font-weight: 700;
    color: #ffd700;
    margin-bottom: 12px;
    font-size: 1rem;
    text-align: center;
    border-bottom: 1px solid rgba(255, 215, 0, 0.3);
    padding-bottom: 8px;
}

.metal-states-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.metal-state {
    background: rgba(0, 0, 0, 0.3);
    padding: 8px;
    border-radius: 6px;
}

.metal-state-title {
    font-size: 0.7rem;
    color: #aaa;
    margin-bottom: 6px;
    text-align: center;
    font-weight: 600;
}

.metal-ref-swatches {
    display: grid;
    grid-template-rows: 1fr 1fr;
    gap: 4px;
    margin-bottom: 6px;
}

.metal-ref-swatch {
    height: 24px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.metal-ref-swatch-label {
    font-size: 0.65rem;
    color: #888;
    text-align: center;
    margin-top: 2px;
}

.metal-ref-info {
    font-size: 0.65rem;
    line-height: 1.3;
    color: #bbb;
    text-align: center;
}

.color-display {
    margin-top: 8px;
    padding: 8px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 6px;
    text-align: center;
}

.color-preview {
    width: 100%;
    height: 40px;
    border-radius: 6px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    margin-bottom: 6px;
}

.color-rgb-text {
    font-size: 0.85rem;
    color: #fff;
    font-weight: 600;
    font-family: 'Courier New', monospace;
    opacity: 0.9;
}

/* Control Panel (Right) */
.ui-panel {
    position: fixed;
    right: 20px;
    top: 20px;
    width: 320px;
    max-height: calc(100vh - 40px);
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    border-radius: 15px;
    padding: 25px;
    z-index: 10;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    transition: transform 0.3s ease;
}

/* Mobile drawer handle */
.ui-panel::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
    display: none;
}

.ui-panel::-webkit-scrollbar,
.reference-panel::-webkit-scrollbar {
    width: 8px;
}

.ui-panel::-webkit-scrollbar-track,
.reference-panel::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.ui-panel::-webkit-scrollbar-thumb,
.reference-panel::-webkit-scrollbar-thumb {
    background: rgba(138, 85, 254, 0.6);
    border-radius: 4px;
}

h1 {
    font-size: 1.5rem;
    margin-bottom: 10px;
    color: #fff;
}

h2 {
    font-size: 1.2rem;
    margin-bottom: 15px;
    color: #fff;
}

.subtitle {
    font-size: 0.85rem;
    color: #aaa;
    margin-bottom: 25px;
}

.header-with-reset {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 15px;
}

.reset-btn {
    background: rgba(138, 85, 254, 0.3);
    color: #fff;
    border: 1px solid rgba(138, 85, 254, 0.5);
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.reset-btn:hover {
    background: rgba(138, 85, 254, 0.5);
    border-color: rgba(138, 85, 254, 0.8);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(138, 85, 254, 0.3);
}

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

.control-group {
    margin-bottom: 20px;
}

.control-label {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 0.9rem;
    color: #ddd;
}

.control-value {
    color: #fff;
    font-weight: 600;
    opacity: 0.9;
}

input[type="range"] {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    outline: none;
    border-radius: 3px;
    -webkit-appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: #ffffff;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.9);
}

input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: #ffffff;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.9);
}

.color-hsv-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.color-slider-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.color-slider-row label {
    font-size: 0.8rem;
    color: #aaa;
    font-weight: 500;
}

/* Hue slider - rainbow gradient */
.slider-hue {
    background: linear-gradient(to right,
        #ff0000 0%,
        #ffff00 16.67%,
        #00ff00 33.33%,
        #00ffff 50%,
        #0000ff 66.67%,
        #ff00ff 83.33%,
        #ff0000 100%) !important;
}

/* Saturation slider - gray to current hue */
.slider-saturation {
    background: linear-gradient(to right, #808080, #ff0000) !important;
}

/* Value slider - black to white */
.slider-value {
    background: linear-gradient(to right, #000000, #ffffff) !important;
}

.presets {
    margin-top: 30px;
}

.presets h3 {
    font-size: 1rem;
    margin-bottom: 12px;
    color: #fff;
}

.preset-section {
    margin-bottom: 20px;
}

.preset-section-title {
    font-size: 0.85rem;
    color: #fff;
    margin-bottom: 8px;
    font-weight: 600;
    opacity: 0.9;
}

.preset-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.preset-btn {
    padding: 10px 8px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: #fff;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.8rem;
    font-weight: 500;
}

.preset-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.lighting-section,
.geometry-section,
.texture-section {
    margin-top: 20px;
    padding: 15px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.lighting-title,
.section-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: #fff;
    margin-bottom: 10px;
}

.toggle-btn {
    width: 100%;
    padding: 10px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: #fff;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.85rem;
    font-weight: 500;
}

.toggle-btn.active {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.4);
}

.toggle-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

.geometry-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.geometry-btn,
.environment-btn {
    padding: 10px 8px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: #fff;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.8rem;
    font-weight: 500;
}

.geometry-btn.active,
.environment-btn.active {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.4);
}

.geometry-btn:hover,
.environment-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
}

.texture-section input[type="file"] {
    width: 100%;
    padding: 8px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: #fff;
    font-size: 0.8rem;
    cursor: pointer;
    margin-bottom: 8px;
}

.texture-section input[type="file"]::file-selector-button {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    border-radius: 4px;
    padding: 6px 12px;
    color: #fff;
    cursor: pointer;
    margin-right: 10px;
}

.texture-section input[type="file"]::file-selector-button:hover {
    background: rgba(255, 255, 255, 0.25);
}

.clear-btn {
    width: 100%;
    padding: 8px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 500;
    transition: all 0.3s ease;
    margin-bottom: 8px;
}

.clear-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

.texture-info {
    font-size: 0.75rem;
    color: #aaa;
    text-align: center;
    padding: 8px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
}

.info {
    margin-top: 20px;
    padding: 15px;
    background: rgba(255, 255, 255, 0.05);
    border-left: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    font-size: 0.8rem;
    line-height: 1.6;
    color: #ccc;
}

@media (max-width: 768px) {
    /* Mobile: Split screen - top 50% for 3D view, bottom 50% for UI */
    #canvas-container {
        height: 50vh;
        top: 0;
    }

    .ui-panel {
        right: 0;
        top: 50vh;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 50vh;
        max-height: 50vh;
        border-radius: 0;
        padding: 15px;
        transform: none;
        transition: none;
    }

    /* Hide drawer handle on mobile split view */
    .ui-panel::before {
        display: none;
    }

    /* Larger touch targets for mobile */
    .preset-btn,
    .geometry-btn,
    .environment-btn {
        padding: 12px 10px;
        font-size: 0.85rem;
        min-height: 44px; /* iOS recommended touch target */
    }

    /* Single column layout for better readability */
    .preset-grid,
    .geometry-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    /* Larger sliders for touch */
    input[type="range"] {
        height: 8px;
    }

    input[type="range"]::-webkit-slider-thumb {
        width: 24px;
        height: 24px;
    }

    input[type="range"]::-moz-range-thumb {
        width: 24px;
        height: 24px;
    }

    /* Reference panel full screen on mobile */
    .reference-panel {
        left: -100%;
        width: 100%;
        top: 0;
        max-height: 100vh;
        border-radius: 0;
        padding: 60px 20px 20px;
    }

    .reference-panel.open {
        left: 0;
    }

    /* Toggle button more accessible */
    .reference-toggle {
        left: 10px;
        top: 10px;
        transform: none;
        padding: 12px 15px;
        border-radius: 8px;
        font-size: 1.5rem;
    }

    .reference-toggle:hover {
        padding: 12px 15px;
    }

    /* Adjust title sizes for mobile */
    h1 {
        font-size: 1.3rem;
    }

    .subtitle {
        font-size: 0.8rem;
        margin-bottom: 15px;
    }

    /* Optimize spacing */
    .control-group {
        margin-bottom: 18px;
    }

    .lighting-section,
    .geometry-section,
    .texture-section {
        margin-top: 15px;
        padding: 12px;
    }
}

@media (max-width: 480px) {
    /* Extra small screens: even more compact */
    .ui-panel {
        max-height: 65vh;
        padding: 15px;
    }

    h1 {
        font-size: 1.2rem;
    }

    .preset-btn,
    .geometry-btn,
    .environment-btn {
        font-size: 0.8rem;
        padding: 10px 8px;
    }

    /* Horizontal scroll for environment buttons if needed */
    .geometry-section:has(.environment-btn) .geometry-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
}

/* Landscape mobile optimization */
@media (max-width: 768px) and (orientation: landscape) {
    .ui-panel {
        max-height: 80vh;
        right: 0;
        left: auto;
        width: 320px;
        border-radius: 15px 0 0 15px;
    }

    .reference-panel {
        width: 300px;
        left: -300px;
    }
}
