:root {
    --bg-dark: #111827;
    --surface: #1F2937;
    --border: #374151;
    
    --primary: #3B82F6;
    --primary-hover: #2563EB;
    --secondary: #4B5563;
    --secondary-hover: #6B7280;
    
    --text-main: #F9FAFB;
    --text-muted: #9CA3AF;
    --text-dim: #6B7280;
    
    --radius-lg: 12px;
    --radius-md: 8px;
    --radius-sm: 4px;
    
    --transition: 200ms ease;
}

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

body {
    font-family: 'Inter', system-ui, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    line-height: 1.5;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Utilities */
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.text-muted { color: var(--text-muted); }
.text-dim { color: var(--text-dim); }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.text-center { text-align: center; }

/* Header */
.app-header {
    height: 60px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    flex-shrink: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--primary);
}

.logo h1 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-main);
}

/* Layout */
.app-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 320px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.card {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.card h2 {
    font-size: 0.875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

/* Dropzone */
.dropzone {
    border: 2px dashed var(--border);
    border-radius: var(--radius-md);
    padding: 2rem 1rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    background: rgba(0,0,0,0.2);
}

.dropzone:hover, .dropzone.dragover {
    border-color: var(--primary);
    background: rgba(59, 130, 246, 0.05);
}

.dropzone svg {
    margin-bottom: 0.5rem;
}

.dropzone p {
    font-size: 0.9rem;
    font-weight: 500;
}

/* Image List */
.image-list {
    margin-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 200px;
    overflow-y: auto;
}

.img-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(0,0,0,0.2);
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    font-size: 0.8rem;
    cursor: grab;
}

.img-item:active { cursor: grabbing; }

.img-item-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    overflow: hidden;
}

.img-thumb {
    width: 24px;
    height: 24px;
    object-fit: contain;
    background: #fff; /* or checkered */
    border-radius: 2px;
}

.img-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 160px;
}

.btn-remove-img {
    background: transparent;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 2px;
}
.btn-remove-img:hover { color: #EF4444; }

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    margin-bottom: 0.4rem;
    color: var(--text-main);
}

.form-group input[type="number"],
.form-group input[type="text"] {
    width: 100%;
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.5rem;
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.9rem;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    margin-bottom: 0;
}

/* Tabs & Code */
.tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1rem;
}

.tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    padding: 0.5rem;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
}

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

.code-container {
    background: #000;
    border-radius: var(--radius-sm);
    padding: 1rem;
    height: 200px;
    overflow: auto;
    border: 1px solid var(--border);
    margin-bottom: 1rem;
}

.code-container pre {
    font-family: 'Fira Code', monospace;
    font-size: 0.75rem;
    color: #A5B4FC;
    white-space: pre-wrap;
    word-break: break-all;
}

.export-actions {
    display: flex;
    gap: 0.5rem;
}
.export-actions .btn { flex: 1; }

/* Main Workspace */
.workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-dark);
    position: relative;
    overflow: hidden;
}

.workspace-header {
    height: 50px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    background: rgba(0,0,0,0.2);
}

.workspace-header h2 {
    font-size: 0.9rem;
    font-weight: 500;
}

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

.canvas-wrapper {
    flex: 1;
    overflow: auto;
    padding: 2rem;
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;
    position: relative;
}

.checkered-bg {
    background-image: 
        linear-gradient(45deg, rgba(255,255,255,0.05) 25%, transparent 25%), 
        linear-gradient(-45deg, rgba(255,255,255,0.05) 25%, transparent 25%), 
        linear-gradient(45deg, transparent 75%, rgba(255,255,255,0.05) 75%), 
        linear-gradient(-45deg, transparent 75%, rgba(255,255,255,0.05) 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

#spriteCanvas {
    /* Box shadow to outline the exact extent of the canvas */
    box-shadow: 0 0 0 1px rgba(255,255,255,0.2), 0 10px 40px rgba(0,0,0,0.5);
    background: transparent;
    display: none; /* hidden until generated */
    transform-origin: top left;
}

.empty-state {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: var(--text-dim);
    pointer-events: none;
}

.empty-state svg {
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state p {
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--text-muted);
}

.empty-state span {
    font-size: 0.85rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid transparent;
}

.btn-sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); }

.btn-secondary {
    background: var(--secondary);
    color: #fff;
}
.btn-secondary:hover { background: var(--secondary-hover); }

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

.btn-outline {
    background: transparent;
    color: var(--text-main);
    border-color: var(--border);
}
.btn-outline:hover { background: rgba(255,255,255,0.05); }

/* Toast */
.toast {
    position: fixed;
    bottom: -50px;
    left: 50%;
    transform: translateX(-50%);
    background: #10B981;
    color: #fff;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-md);
    font-weight: 500;
    font-size: 0.9rem;
    box-shadow: 0 10px 25px rgba(16, 185, 129, 0.3);
    transition: bottom 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 1000;
}

.toast.show {
    bottom: 2rem;
}
