/* Global Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(0deg, #ffffff 0%, #ffffff 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.container {
    background: rgb(234, 234, 234);
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    padding: 16px;
    max-width: 1100px;
    width: 100%;
}

/* Header Styles */
header {
    text-align: center;
    margin-bottom: 16px;
}

header h1 {
    color: #333;
    font-size: 1.8em;
    margin-bottom: 0;
}

/* Controls Bar */
.controls-bar {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 12px;
    background: #f9f9f9;
    border-radius: 8px;
    margin-bottom: 16px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

/* Visual Slot Selector */
.slot-selector-visual {
    display: flex;
    gap: 6px;
    padding: 4px;
    background: white;
    border-radius: 6px;
    border: 2px solid #ddd;
}

.slot-btn {
    width: 48px;
    height: 48px;
    border: 2px solid #ccc;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: white;
    padding: 2px;
    position: relative;
    overflow: hidden;
}

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

.slot-btn.active {
    border-color: #667eea;
    border-width: 3px;
    box-shadow: 0 0 8px rgba(102, 126, 234, 0.4);
}

.slot-canvas {
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

.slot-label {
    position: absolute;
    bottom: 2px;
    right: 2px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    font-size: 10px;
    padding: 1px 3px;
    border-radius: 2px;
    font-weight: bold;
}

/* Playing Animation State */
body.playing .controls-bar,
body.playing .palette-section {
    opacity: 0.3;
    pointer-events: none;
}

body.playing #play-btn {
    opacity: 1 !important;
    pointer-events: all !important;
}

/* Main Layout */
main {
    display: flex;
    gap: 16px;
    justify-content: center;
    align-items: flex-start;
}

/* Pixel Grid Section */
.grid-section {
    flex: 0 0 auto;
}

.pixel-grid {
    display: grid;
    grid-template-columns: repeat(32, 16px);
    grid-template-rows: repeat(32, 16px);
    gap: 0;
    background: #ffffff;
    border: 2px solid #333;
    border-radius: 0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    padding: 2px;
}

/* Palette Section */
.palette-section {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.color-palette {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
    transition: opacity 0.3s ease, filter 0.3s ease;
}

.color-palette.greyed-out {
    opacity: 0.3;
    filter: grayscale(100%);
    pointer-events: none;
}

.btn-rainbow {
    width: 100%;
    padding: 10px 12px;
}

/* Individual Pixel Styles */
.pixel {
    width: 16px;
    height: 16px;
    background-color: white;
    cursor: pointer;
    border: 1px solid rgba(200, 200, 200, 0.3); /* Subtle border */
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}

/* Hover effect for pixels */
.pixel:hover {
    transform: scale(1.15);
    box-shadow: 0 0 4px rgba(0, 0, 0, 0.4);
    z-index: 10;
    position: relative;
}

.color-option {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    cursor: pointer;
    border: 3px solid transparent;
    transition: transform 0.15s ease, border-color 0.15s ease;
}

.color-option:hover {
    transform: scale(1.08);
    border-color: #333;
}

.color-option.selected {
    border-color: #667eea;
    border-width: 4px;
    transform: scale(1.05);
}

/* Unified Controls Grid */
.unified-controls {
    flex-grow: 1;
}

.controls-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.controls-grid .slot-select {
    grid-column: span 3;
}

/* Button Styles */
.btn {
    padding: 10px 12px;
    border: none;
    border-radius: 6px;
    font-size: 1em;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
    background: linear-gradient(135deg, #23273a 0%, #764ba2 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 40px;
    white-space: nowrap;
}

.btn .icon {
    font-size: 1.2em;
}

.btn .label {
    font-size: 0.9em;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15);
}

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

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-icon {
    min-height: 40px;
}

.btn.active {
    background: linear-gradient(135deg, #00d2ff 0%, #3a7bd5 100%);
    box-shadow: 0 0 12px rgba(0, 210, 255, 0.6);
    transform: scale(1.05);
}

.btn-danger {
    background: linear-gradient(135deg, #5a3a43 0%, #2c2b26 100%);
}

/* Slot Selector */
.slot-select {
    padding: 10px 8px;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 0.9em;
    background: white;
    cursor: pointer;
    transition: border-color 0.2s ease;
    font-weight: 600;
}

.slot-select:hover {
    border-color: #667eea;
}

.slot-select:focus {
    outline: none;
    border-color: #764ba2;
}

/* Responsive Design */
@media (max-width: 900px) {
    main {
        flex-direction: column;
        align-items: center;
    }

    .palette-section {
        width: 100%;
    }

    .color-palette {
        grid-template-columns: repeat(6, 1fr);
    }

    .color-option {
        width: 40px;
        height: 40px;
    }

    .pixel-grid {
        grid-template-columns: repeat(32, 12px);
        grid-template-rows: repeat(32, 12px);
    }

    .pixel {
        width: 12px;
        height: 12px;
    }
}

@media (max-width: 600px) {
    .controls-bar {
        flex-wrap: wrap;
    }

    .controls-bar .slot-select {
        flex: 1 1 100%;
        max-width: none;
    }

    .pixel-grid {
        grid-template-columns: repeat(32, 10px);
        grid-template-rows: repeat(32, 10px);
    }

    .pixel {
        width: 10px;
        height: 10px;
    }

    header h1 {
        font-size: 1.5em;
    }

    .container {
        padding: 12px;
    }
}
