:root {
    --bg-color: #121212;
    --surface-color: #1e1e24;
    --surface-hover: #2a2a35;
    --border-color: #333;
    --primary-color: #3b82f6;
    /* Electric Blue */
    --accent-color: #f59e0b;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.6);
    --font-ui: 'Inter', 'Segoe UI', system-ui, sans-serif;
}

* {
    box-sizing: border-box;
    user-select: none;
}

body {
    margin: 0;
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-ui);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Header */
header {
    height: 60px;
    padding: 0 20px;
    background: rgba(30, 30, 36, 0.8);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 100;
}

.brand {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand span {
    color: var(--primary-color);
}

.header-controls {
    display: flex;
    gap: 10px;
}

/* Buttons */
.btn {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn:hover {
    background: var(--surface-hover);
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: var(--primary-color);
    border-color: transparent;
    color: white;
}

.btn-primary:hover {
    background: #2563eb;
    box-shadow: 0 0 12px rgba(59, 130, 246, 0.4);
}

.btn-icon {
    padding: 8px;
    width: 36px;
    height: 36px;
    justify-content: center;
}

/* Main Workspace */
#workspace {
    flex: 1;
    display: grid;
    grid-template-columns: 80px 1fr 280px;
    /* Toolbar | Canvas | Panels */
    overflow: hidden;
    position: relative;
}

/* Left Toolbar */
#toolbar {
    background: var(--surface-color);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px 0;
    gap: 8px;
    overflow-y: auto;
}

.tool-btn {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-secondary);
    font-size: 1.4rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.tool-btn:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}

.tool-btn.active {
    background: rgba(59, 130, 246, 0.15);
    color: var(--primary-color);
    border-color: rgba(59, 130, 246, 0.3);
}

.tool-btn::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 60px;
    background: #000;
    color: #fff;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    white-space: nowrap;
    z-index: 99;
}

.tool-btn:hover::after {
    opacity: 1;
}

/* Canvas Area */
#viewport {
    background: #0d0d0d;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background-image:
        radial-gradient(#222 1px, transparent 1px);
    background-size: 24px 24px;
}

#canvas-container {
    position: relative;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
    background: white;
    /* Base canvas bg */
}

canvas {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    image-rendering: pixelated;
    touch-action: none;
}

/* Right Sidebar (Panels) */
#panels {
    background: var(--surface-color);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.panel-section {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
}

.panel-header {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    margin-bottom: 12px;
    font-weight: 700;
}

/* Color Picker */
.color-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
    margin-bottom: 12px;
}

.swatch {
    aspect-ratio: 1;
    border-radius: 4px;
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.swatch:hover {
    transform: scale(1.1);
    z-index: 2;
}

.color-inputs {
    display: flex;
    gap: 8px;
    align-items: center;
}

input[type="color"] {
    -webkit-appearance: none;
    appearance: none;
    border: none;
    width: 32px;
    height: 32px;
    cursor: pointer;
    padding: 0;
    background: none;
}

input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

input[type="color"]::-webkit-color-swatch {
    border: 1px solid var(--border-color);
    border-radius: 4px;
}

/* Layer Panel */
#layers-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column-reverse;
    /* Stack like layers usually do */
    gap: 2px;
    padding: 8px 0;
    max-height: 300px;
}

.layer-item {
    padding: 8px 12px;
    background: var(--surface-hover);
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    border: 1px solid transparent;
}

.layer-item:hover {
    background: #333340;
}

.layer-item.active {
    background: rgba(59, 130, 246, 0.1);
    border-color: rgba(59, 130, 246, 0.4);
}

.layer-preview {
    width: 32px;
    height: 32px;
    background: white;
    border: 1px solid #555;
}

.layer-name {
    flex: 1;
    font-size: 0.9rem;
}

.layer-vis {
    cursor: pointer;
    opacity: 0.6;
}

.layer-vis:hover {
    opacity: 1;
}

.layer-vis.hidden {
    opacity: 0.3;
    text-decoration: line-through;
}

/* Range Sliders */
.control-row {
    margin-bottom: 10px;
}

.control-row label {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    margin-bottom: 4px;
    color: var(--text-secondary);
}

input[type=range] {
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
    background: #333;
    height: 4px;
    border-radius: 2px;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.1s;
}

input[type=range]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

/* Status Bar */
#statusbar {
    height: 24px;
    background: var(--bg-color);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    font-size: 0.7rem;
    color: var(--text-secondary);
}

@media (max-width: 800px) {
    #workspace {
        grid-template-columns: 60px 1fr;
    }

    #panels {
        display: none;
        position: absolute;
        right: 0;
        top: 0;
        bottom: 0;
        width: 260px;
        z-index: 50;
        box-shadow: -5px 0 20px rgba(0, 0, 0, 0.5);
    }

    #panels.open {
        display: flex;
    }
}.text-tool-input {
    background: transparent;
    resize: both;
    line-height: 1.2;
    white-space: pre;
}
