:root {
    --bg-color: #121212;
    --panel-color: #1e1e1e;
    --card-color: #252525;
    --accent-color: #007aff;
    --danger-color: #ff3b30;
    --text-color: #e4e4e4;
    --text-dim: #a0a0a0;
    --border-radius: 12px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    overflow-x: hidden;
}

.app-container {
    padding: 20px;
    max-width: 1600px;
    margin: 0 auto;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    text-align: center;
    margin-bottom: 20px;
    flex-shrink: 0;
}

header h1 { margin: 0; font-size: 28px; letter-spacing: -0.5px; }
header p { margin: 5px 0 0; color: var(--text-dim); font-size: 14px; }

.editor-layout {
    display: flex;
    gap: 24px;
    flex: 1;
    min-height: 0; /* Important for inner scroll */
}

/* Sidebar */
.sidebar-controls {
    width: 320px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    flex-shrink: 0;
    overflow-y: auto;
    padding-right: 4px;
}

.step-card {
    background: var(--card-color);
    padding: 20px;
    border-radius: var(--border-radius);
    position: relative;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.step-number {
    position: absolute;
    top: -10px;
    left: -10px;
    width: 28px;
    height: 28px;
    background: var(--accent-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 14px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.step-card h3 {
    margin: 0 0 15px;
    font-size: 15px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-dim);
}

.input-pair {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.drop-zone {
    border: 2px dashed #444;
    border-radius: 8px;
    padding: 15px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background-color: rgba(255,255,255,0.03);
}

.drop-zone:hover, .drop-zone.dragover {
    border-color: var(--accent-color);
    background-color: rgba(0, 122, 255, 0.1);
}

.drop-zone p { margin: 0; font-size: 13px; }

/* Canvas Area */
.canvas-area {
    flex: 1;
    background: #111;
    border-radius: var(--border-radius);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    box-shadow: inset 0 0 40px rgba(0,0,0,0.8);
    border: 1px solid #333;
    min-width: 400px;
}

.canvas-container-outer {
    position: relative;
    background-color: #000;
}

.canvas-wrapper {
    box-shadow: 0 0 30px rgba(0,0,0,0.5);
    background-color: #222;
    border: 1px solid #444;
}

/* UI Controls */
.control-group { margin-bottom: 12px; }
.control-group label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 4px; }
.control-group input[type="range"] { width: 100%; height: 4px; }
.control-group select {
    width: 100%;
    background: #333;
    color: #fff;
    border: 1px solid #444;
    border-radius: 4px;
    padding: 6px;
    font-size: 13px;
    outline: none;
}
.control-group select:focus { border-color: var(--accent-color); }

.btn-group { display: flex; gap: 8px; margin-top: 12px; }
.btn-group.vertical { flex-direction: column; }

button {
    padding: 10px 14px;
    border: none;
    border-radius: 6px;
    background: #444;
    color: #fff;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

button:hover { filter: brightness(1.2); }
button.primary { background: var(--accent-color); }
button.secondary { background: #3a3a3a; }
button.danger { background: var(--danger-color); }

/* Loader */
.loader-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(4px);
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(255,255,255,0.1);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 12px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.mini-btns { margin-bottom: 15px; }
.mini-btns button {
    flex: 1;
    padding: 6px;
    font-size: 11px;
    background: #333;
}

.layer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}
.layer-header h3 { margin-bottom: 0; }

.count-badge {
    font-size: 11px;
    background: #444;
    padding: 2px 8px;
    border-radius: 10px;
    color: var(--text-dim);
}

.z-order-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
}
.z-order-group button {
    padding: 8px 4px;
    font-size: 11px;
}

.size-selector {
    display: flex;
    gap: 10px;
    background: rgba(0,0,0,0.2);
    padding: 8px;
    border-radius: 6px;
    margin-bottom: 8px;
}
.size-selector label {
    font-size: 11px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 0;
    color: var(--text-color);
}

.info-text {
    font-size: 11px;
    color: var(--text-dim);
    margin-bottom: 8px;
    background: rgba(0,0,0,0.2);
    padding: 4px 8px;
    border-radius: 4px;
}

/* Layer List */
.layer-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 250px;
    overflow-y: auto;
}

.layer-item {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255,255,255,0.05);
    padding: 6px;
    border-radius: 6px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s;
}

.layer-item:hover {
    background: rgba(255,255,255,0.1);
}

.layer-item.active {
    border-color: var(--accent-color);
    background: rgba(0, 122, 255, 0.15);
}

.layer-thumb {
    width: 40px;
    height: 40px;
    background: #000;
    background-image: 
        linear-gradient(45deg, #222 25%, transparent 25%),
        linear-gradient(-45deg, #222 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #222 75%),
        linear-gradient(-45deg, transparent 75%, #222 75%);
    background-size: 10px 10px;
    background-position: 0 0, 0 5px, 5px 5px, 5px 0;
    border-radius: 4px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.layer-thumb img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain; /* Ensure full image is visible */
}

.layer-name {
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

/* Responsive */
@media (max-width: 1000px) {
    .app-container { height: auto; }
    .editor-layout { flex-direction: column; }
    .sidebar-controls { width: 100%; flex-direction: row; flex-wrap: wrap; }
    .step-card { flex: 1; min-width: 250px; }
    .canvas-area { min-height: 500px; }
}
