:root {
    --lego-yellow: #F2CD37;
    --dark-bg: #0a0a0a;
    --card-bg: #1a1a1a;
    --border-color: #333;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--dark-bg);
    color: var(--text-primary);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    touch-action: pan-x pan-y;
}

/* LEGO plate texture background */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: 
        repeating-linear-gradient(0deg, transparent, transparent 8px, rgba(255,255,255,0.01) 8px, rgba(255,255,255,0.01) 9px),
        repeating-linear-gradient(90deg, transparent, transparent 8px, rgba(255,255,255,0.01) 8px, rgba(255,255,255,0.01) 9px);
    pointer-events: none;
    z-index: 0;
}

.app {
    position: relative;
    z-index: 1;
    min-height: 100vh;
}

/* Header */
.header {
    padding: 1.5rem;
    background: var(--card-bg);
    border-bottom: 2px solid var(--lego-yellow);
}

.logo {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo-brick {
    width: 40px;
    height: 40px;
    background: var(--lego-yellow);
    border-radius: 4px;
    position: relative;
    box-shadow: 
        inset 0 -2px 4px rgba(0,0,0,0.3),
        inset 0 2px 4px rgba(255,255,255,0.3),
        0 4px 8px rgba(0,0,0,0.5);
}

.logo-brick::before,
.logo-brick::after {
    content: '';
    position: absolute;
    width: 10px;
    height: 10px;
    background: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.4), transparent 60%),
                radial-gradient(circle at center, var(--lego-yellow), #d4b02f);
    border-radius: 50%;
    box-shadow: 
        inset 0 -1px 2px rgba(0,0,0,0.4),
        inset 0 1px 2px rgba(255,255,255,0.4),
        0 1px 2px rgba(0,0,0,0.3);
    top: -5px;
}

.logo-brick::before {
    left: 8px;
}

.logo-brick::after {
    right: 8px;
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

/* Upload Section */
.upload-section {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 100px);
    padding: 2rem;
}

.upload-container {
    text-align: center;
    max-width: 500px;
    width: 100%;
}

.upload-icon {
    font-size: 5rem;
    margin-bottom: 1.5rem;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.upload-container h2 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.upload-container p {
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

.upload-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* Buttons */
.btn {
    padding: 1rem 2rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    touch-action: manipulation;
    min-height: 48px;
}

.btn-primary {
    background: var(--lego-yellow);
    color: #000;
    box-shadow: 0 4px 12px rgba(242, 205, 55, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(242, 205, 55, 0.4);
}

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

.btn-secondary {
    background: var(--card-bg);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
}

.btn-secondary:hover {
    border-color: var(--lego-yellow);
}

.btn-icon {
    padding: 0.75rem 1.5rem;
    background: var(--card-bg);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

/* Controls Section */
.controls-section {
    padding: 2rem;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
}

.controls-container {
    max-width: 600px;
    margin: 0 auto;
}

.control-group {
    margin-bottom: 2rem;
}

.control-group label {
    display: block;
    margin-bottom: 0.75rem;
    font-weight: 600;
    color: var(--lego-yellow);
}

.control-group input[type="range"] {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--border-color);
    outline: none;
    -webkit-appearance: none;
}

.control-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--lego-yellow);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(242, 205, 55, 0.4);
}

.control-group input[type="range"]::-moz-range-thumb {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--lego-yellow);
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 8px rgba(242, 205, 55, 0.4);
}

.style-buttons {
    display: flex;
    gap: 0.5rem;
}

.style-btn {
    flex: 1;
    padding: 0.75rem;
    background: var(--dark-bg);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    min-height: 48px;
}

.style-btn:hover {
    border-color: var(--lego-yellow);
}

.style-btn.active {
    background: var(--lego-yellow);
    color: #000;
    border-color: var(--lego-yellow);
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(10, 10, 10, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    gap: 1rem;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--lego-yellow);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Mosaic Section */
.mosaic-section {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.mosaic-header {
    padding: 1rem;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.mosaic-tabs {
    display: flex;
    gap: 0.5rem;
}

.tab-btn {
    padding: 0.75rem 1.5rem;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    border-bottom: 2px solid transparent;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    min-height: 48px;
}

.tab-btn:hover {
    color: var(--text-primary);
}

.tab-btn.active {
    color: var(--lego-yellow);
    border-bottom-color: var(--lego-yellow);
}

.tab-content {
    display: none;
    flex: 1;
}

.tab-content.active {
    display: block;
}

/* Mosaic Viewport */
.mosaic-viewport {
    position: relative;
    overflow: auto;
    flex: 1;
    touch-action: pan-x pan-y pinch-zoom;
    -webkit-overflow-scrolling: touch;
    padding: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 500px;
}

.mosaic-grid {
    display: inline-grid;
    gap: 2px;
    background: #0a0a0a;
    padding: 4px;
    border-radius: 4px;
    transform-origin: center;
    transition: transform 0.3s ease;
}

/* LEGO Stud - REALISTIC rendering */
.lego-stud {
    width: 100%;
    height: 100%;
    min-width: 24px;
    min-height: 24px;
    border-radius: 2px;
    position: relative;
    cursor: pointer;
    transition: all 0.2s ease;
    /* Base brick shadow */
    box-shadow: 
        inset 0 -2px 4px rgba(0,0,0,0.3),
        inset 0 2px 4px rgba(255,255,255,0.2),
        0 2px 4px rgba(0,0,0,0.3);
}

.lego-stud:active {
    transform: scale(0.95);
}

/* The iconic LEGO stud on top */
.lego-stud::before {
    content: '';
    position: absolute;
    width: 40%;
    height: 40%;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    /* Realistic stud gradient - light from top-left */
    background: 
        radial-gradient(circle at 30% 30%, rgba(255,255,255,0.5), transparent 50%),
        radial-gradient(circle at center, inherit, color-mix(in srgb, currentColor 80%, black));
    box-shadow: 
        inset 0 -1px 2px rgba(0,0,0,0.4),
        inset 0 1px 2px rgba(255,255,255,0.3),
        0 1px 3px rgba(0,0,0,0.4);
}

/* Hover effect */
.lego-stud:hover {
    filter: brightness(1.1);
    z-index: 10;
}

/* Mosaic Info Tooltip */
.mosaic-info {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--card-bg);
    border: 2px solid var(--lego-yellow);
    border-radius: 12px;
    padding: 1rem 1.5rem;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    z-index: 100;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translate(-50%, 20px);
    }
    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}

.info-content {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.info-color {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    box-shadow: 
        inset 0 -2px 4px rgba(0,0,0,0.3),
        inset 0 2px 4px rgba(255,255,255,0.2);
}

.info-name {
    font-weight: 600;
    color: var(--lego-yellow);
}

.info-part {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Instructions */
.instructions-container {
    padding: 2rem;
    max-width: 800px;
    margin: 0 auto;
}

.layer-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2rem;
    margin-bottom: 2rem;
}

.layer-view {
    display: inline-grid;
    gap: 2px;
    background: #0a0a0a;
    padding: 4px;
    border-radius: 4px;
    margin: 0 auto 2rem;
}

.layer-legend {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    background: var(--dark-bg);
    border-radius: 6px;
}

.legend-color {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    box-shadow: 
        inset 0 -2px 4px rgba(0,0,0,0.3),
        inset 0 2px 4px rgba(255,255,255,0.2);
}

.legend-info {
    flex: 1;
}

.legend-name {
    font-weight: 600;
    color: var(--lego-yellow);
}

.legend-count {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Parts List */
.parts-container {
    padding: 2rem;
    max-width: 800px;
    margin: 0 auto;
}

.parts-summary {
    text-align: center;
    margin-bottom: 2rem;
    padding: 2rem;
    background: var(--card-bg);
    border-radius: 12px;
    border: 2px solid var(--lego-yellow);
}

.parts-summary h3 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.total-parts {
    font-size: 1.25rem;
    color: var(--text-secondary);
}

.total-parts span {
    color: var(--lego-yellow);
    font-weight: 700;
}

.parts-list {
    display: grid;
    gap: 1rem;
}

.part-item {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 1.5rem;
    background: var(--card-bg);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    transition: all 0.3s ease;
}

.part-item:hover {
    border-color: var(--lego-yellow);
    transform: translateX(4px);
}

.part-color {
    width: 48px;
    height: 48px;
    border-radius: 4px;
    flex-shrink: 0;
    box-shadow: 
        inset 0 -2px 4px rgba(0,0,0,0.3),
        inset 0 2px 4px rgba(255,255,255,0.2),
        0 2px 8px rgba(0,0,0,0.3);
}

.part-details {
    flex: 1;
}

.part-name {
    font-weight: 600;
    color: var(--lego-yellow);
    margin-bottom: 0.25rem;
}

.part-number {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.part-count {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    min-width: 60px;
    text-align: right;
}

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

/* Mobile Optimizations */
@media (max-width: 768px) {
    .logo h1 {
        font-size: 1.25rem;
    }
    
    .upload-container h2 {
        font-size: 1.5rem;
    }
    
    .upload-buttons {
        flex-direction: column;
        width: 100%;
    }
    
    .btn {
        width: 100%;
        justify-content: center;
    }
    
    .mosaic-header {
        flex-direction: column;
        align-items: stretch;
    }
    
    .mosaic-tabs {
        justify-content: center;
    }
    
    .tab-btn {
        flex: 1;
        text-align: center;
    }
    
    .lego-stud {
        min-width: 20px;
        min-height: 20px;
    }
}

@media (max-width: 480px) {
    .header {
        padding: 1rem;
    }
    
    .upload-icon {
        font-size: 4rem;
    }
    
    .mosaic-viewport {
        padding: 1rem;
    }
}
