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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: #0a0a0a;
    color: #ffffff;
    overflow: hidden;
    height: 100vh;
}

.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: linear-gradient(135deg, #0a0a0a 0%, #1a1a1a 100%);
}

.header {
    padding: 1rem 2rem;
    background: rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
}

.title {
    font-size: 1.8rem;
    font-weight: 700;
    background: linear-gradient(135deg, #00ff88, #00ccff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.25rem;
}

.subtitle {
    font-size: 0.9rem;
    color: #888;
    font-weight: 400;
}

.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.sidebar {
    width: 320px;
    background: rgba(255, 255, 255, 0.02);
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    padding: 1.5rem;
    overflow-y: auto;
    backdrop-filter: blur(10px);
}

.sidebar h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: #fff;
}

.sidebar h4 {
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 0.75rem;
    color: #ccc;
}

.upload-area {
    border: 2px dashed rgba(0, 255, 136, 0.3);
    border-radius: 12px;
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: rgba(0, 255, 136, 0.02);
    margin-bottom: 2rem;
}

.upload-area:hover {
    border-color: rgba(0, 255, 136, 0.6);
    background: rgba(0, 255, 136, 0.05);
    transform: translateY(-2px);
}

.upload-area.dragover {
    border-color: #00ff88;
    background: rgba(0, 255, 136, 0.1);
    transform: scale(1.02);
}

.upload-icon {
    width: 48px;
    height: 48px;
    color: #00ff88;
    margin-bottom: 1rem;
}

.upload-area p {
    color: #ccc;
    font-size: 0.9rem;
}

.tools-section {
    margin-bottom: 2rem;
}

.tool-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.tool-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: #fff;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9rem;
}

.tool-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-1px);
}

.tool-btn.active {
    background: rgba(0, 255, 136, 0.2);
    border-color: #00ff88;
    color: #00ff88;
}

.tool-btn .icon {
    font-size: 1.1rem;
}

.grid-controls, .auto-controls {
    margin-top: 1rem;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.input-group {
    margin-bottom: 1rem;
}

.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    color: #ccc;
    font-weight: 500;
}

.input-group input {
    width: 100%;
    padding: 0.5rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    color: #fff;
    font-size: 0.9rem;
}

.input-group input:focus {
    outline: none;
    border-color: #00ff88;
    box-shadow: 0 0 0 2px rgba(0, 255, 136, 0.2);
}

.apply-btn {
    width: 100%;
    padding: 0.75rem;
    background: linear-gradient(135deg, #00ff88, #00ccff);
    border: none;
    border-radius: 6px;
    color: #000;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.apply-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 255, 136, 0.3);
}

.sprites-list {
    margin-bottom: 2rem;
}

.sprites-container {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.02);
}

.sprite-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    cursor: pointer;
    transition: all 0.2s ease;
}

.sprite-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.sprite-item.selected {
    background: rgba(0, 255, 136, 0.1);
    border-color: #00ff88;
}

.sprite-thumbnail {
    width: 32px;
    height: 32px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    image-rendering: pixelated;
}

.sprite-info {
    flex: 1;
    font-size: 0.8rem;
}

.sprite-info .name {
    color: #fff;
    font-weight: 500;
}

.sprite-info .dimensions {
    color: #888;
}

.export-formats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

.export-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.8rem;
}

.export-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-1px);
}

.main-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.canvas-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
}

.canvas-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.zoom-btn {
    padding: 0.5rem 0.75rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 40px;
}

.zoom-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.zoom-level {
    font-size: 0.9rem;
    color: #ccc;
    min-width: 60px;
    text-align: center;
}

.canvas-info {
    font-size: 0.9rem;
    color: #888;
}

.canvas-wrapper {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: #000;
    background-image: 
        linear-gradient(45deg, #111 25%, transparent 25%),
        linear-gradient(-45deg, #111 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #111 75%),
        linear-gradient(-45deg, transparent 75%, #111 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

#mainCanvas {
    display: block;
    max-width: 100%;
    max-height: 100%;
    margin: auto;
    image-rendering: pixelated;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.selection-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.selection-box {
    position: absolute;
    border: 2px solid #00ff88;
    background: rgba(0, 255, 136, 0.1);
    pointer-events: all;
    cursor: move;
}

.selection-box::before {
    content: attr(data-index);
    position: absolute;
    top: -24px;
    left: 0;
    background: #00ff88;
    color: #000;
    padding: 2px 6px;
    font-size: 0.7rem;
    font-weight: 600;
    border-radius: 3px;
}

.animation-preview {
    height: 350px;
    background: rgba(255, 255, 255, 0.02);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    overflow: auto;
    min-height: 350px;
}

.preview-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-shrink: 0;
}

.preview-btn {
    padding: 0.5rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    font-size: 1.2rem;
}

.speed-control {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.speed-control label {
    font-size: 0.8rem;
    color: #ccc;
}

.speed-control input {
    width: 100px;
}

#fpsValue {
    font-size: 0.8rem;
    color: #fff;
    min-width: 20px;
}

#previewCanvas {
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: #000;
    image-rendering: pixelated;
    margin-bottom: 1rem;
    flex-shrink: 0;
    width: 128px;
    height: 128px;
}

.code-output {
    position: fixed;
    top: 5%;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 1000px;
    height: 85%;
    background: rgba(20, 20, 20, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    backdrop-filter: blur(20px);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
}

.output-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 12px 12px 0 0;
}

.copy-btn, .close-btn {
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    transition: all 0.2s ease;
}

.close-btn {
    padding: 0.5rem 0.75rem;
    font-size: 1.2rem;
}

.copy-btn:hover, .close-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

#codeContent {
    flex: 1;
    padding: 1.5rem;
    font-family: 'Space Mono', 'Courier New', monospace;
    font-size: 0.85rem;
    line-height: 1.5;
    color: #fff;
    background: transparent;
    overflow: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
    min-height: 200px;
    max-height: calc(85vh - 100px);
    margin: 0;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 6px;
}

::-webkit-scrollbar-thumb {
    background: rgba(0, 255, 136, 0.3);
    border-radius: 6px;
    border: 2px solid rgba(255, 255, 255, 0.05);
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 255, 136, 0.5);
}

::-webkit-scrollbar-corner {
    background: rgba(255, 255, 255, 0.05);
}

/* Firefox scrollbar styling */
* {
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 255, 136, 0.3) rgba(255, 255, 255, 0.05);
}

/* Loading animation */
@keyframes pulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

.loading {
    animation: pulse 1.5s ease-in-out infinite;
}

/* Responsive design */
@media (max-width: 768px) {
    .sidebar {
        width: 280px;
    }
    
    .export-formats {
        grid-template-columns: 1fr;
    }
    
    .code-output {
        width: 95%;
        height: 90%;
        top: 5%;
    }
    
    .animation-preview {
        height: 300px;
    }
    
    #codeContent {
        font-size: 0.8rem;
        padding: 1rem;
    }
}

/* Responsive improvements for scrollable areas */
@media (max-width: 768px) {
    .sidebar {
        width: 280px;
    }
    
    .export-formats {
        grid-template-columns: 1fr;
    }
    
    .code-output {
        width: 95%;
        height: 90%;
        top: 5%;
    }
    
    .animation-preview {
        height: 300px;
    }
    
    #codeContent {
        font-size: 0.8rem;
        padding: 1rem;
    }
}

/* Improved focus indicators for better accessibility */
.animation-packs-list:focus-within,
#codeContent:focus-within {
    outline: 2px solid rgba(0, 255, 136, 0.5);
    outline-offset: 2px;
}

.animation-packs {
    margin-top: 1rem;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    flex: 1;
    overflow: auto;
    display: flex;
    flex-direction: column;
    min-height: 150px;
}

.animation-packs h4 {
    margin-bottom: 1rem;
    flex-shrink: 0;
}

.pack-controls {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.pack-select {
    position: relative;
    padding: 0.5rem;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: #fff;
    font-size: 0.9rem;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
}

.pack-select:focus {
    outline: none;
    border-color: #00ff88;
    box-shadow: 0 0 0 2px rgba(0, 255, 136, 0.2);
}

.pack-select option {
    background: #1a1a1a;
    color: #fff;
    padding: 0.5rem;
    border: none;
}

.pack-select option:hover {
    background: rgba(0, 255, 136, 0.2);
}

/* Custom dropdown styling */
.custom-select {
    position: relative;
    display: inline-block;
    min-width: 120px;
}

.custom-select-trigger {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: #fff;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.custom-select-trigger:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.3);
}

.custom-select-trigger::after {
    content: '▼';
    font-size: 0.7rem;
    color: #888;
    transition: transform 0.2s ease;
}

.custom-select.open .custom-select-trigger::after {
    transform: rotate(180deg);
}

.custom-select.open .custom-select-trigger {
    border-color: #00ff88;
    box-shadow: 0 0 0 2px rgba(0, 255, 136, 0.2);
}

.custom-select-options {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: rgba(20, 20, 20, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    backdrop-filter: blur(10px);
    z-index: 100;
    max-height: 200px;
    overflow-y: auto;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s ease;
}

.custom-select.open .custom-select-options {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.custom-select-option {
    padding: 0.5rem;
    color: #fff;
    cursor: pointer;
    transition: all 0.2s ease;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.custom-select-option:last-child {
    border-bottom: none;
}

.custom-select-option:hover {
    background: rgba(0, 255, 136, 0.2);
    color: #00ff88;
}

.custom-select-option.selected {
    background: rgba(0, 255, 136, 0.1);
    color: #00ff88;
}

.pack-input {
    flex: 1;
    min-width: 120px;
    padding: 0.5rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    color: #fff;
    font-size: 0.9rem;
}

.pack-input:focus {
    outline: none;
    border-color: #00ff88;
    box-shadow: 0 0 0 2px rgba(0, 255, 136, 0.2);
}

.add-pack-btn {
    padding: 0.5rem 1rem;
    background: linear-gradient(135deg, #00ff88, #00ccff);
    border: none;
    border-radius: 6px;
    color: #000;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9rem;
}

.add-pack-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 255, 136, 0.3);
}

.animation-packs-list {
    flex: 1;
    overflow-y: auto;
    min-height: 100px;
    padding-right: 0.5rem;
    max-height: 200px;
}

.pack-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem;
    margin-bottom: 0.5rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.pack-info {
    flex: 1;
}

.pack-name {
    font-weight: 500;
    color: #00ff88;
    font-size: 0.9rem;
}

.pack-details {
    font-size: 0.75rem;
    color: #888;
}

.remove-pack-btn {
    padding: 0.25rem 0.5rem;
    background: rgba(255, 100, 100, 0.2);
    border: 1px solid rgba(255, 100, 100, 0.3);
    border-radius: 4px;
    color: #ff6464;
    cursor: pointer;
    font-size: 0.75rem;
}

.remove-pack-btn:hover {
    background: rgba(255, 100, 100, 0.3);
}