:root {
    --ink: #0f172a;
    --ink-soft: #475569;
    --cream: #fefcf3;
    --cream-deep: #f8f0dc;
    --saffron: #eab308;
    --saffron-soft: #fef3c7;
    --jade: #10b981;
    --jade-soft: #d1fae5;
    --azure: #3b82f6;
    --azure-soft: #dbeafe;
    --coral: #f97316;
    --coral-soft: #ffedd5;
    --violet: #8b5cf6;
    --violet-soft: #ede9fe;
    
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;
    --space-7: 48px;
    
    --radius-1: 4px;
    --radius-2: 8px;
    --radius-3: 12px;
    --radius-4: 20px;
    
    --shadow-1: 0 1px 3px rgba(15, 23, 42, 0.08);
    --shadow-2: 0 4px 12px rgba(15, 23, 42, 0.12);
    --shadow-3: 0 12px 32px rgba(15, 23, 42, 0.18);
    
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Space Grotesk', -apple-system, BlinkMacSystemFont, sans-serif;
    background: linear-gradient(135deg, #fefcf3 0%, #f8f0dc 50%, #fef3c7 100%);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.app-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 2200px;
    margin: 0 auto;
    background: transparent;
}

.top-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-4) var(--space-6);
    background: rgba(254, 252, 243, 0.85);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(15, 23, 42, 0.08);
    z-index: 10;
}

.brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.brand-mark {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--ink) 0%, #1e293b 100%);
    border-radius: var(--radius-2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--cream);
    font-weight: 700;
    font-size: 16px;
    letter-spacing: -0.5px;
    box-shadow: var(--shadow-2);
}

.brand-name {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.5px;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

.keyboard-hint {
    display: flex;
    gap: var(--space-1);
    font-family: 'DM Mono', monospace;
    font-size: 12px;
    color: var(--ink-soft);
}

kbd {
    padding: 4px 8px;
    background: white;
    border: 1px solid rgba(15, 23, 42, 0.12);
    border-radius: var(--radius-1);
    box-shadow: 0 2px 0 rgba(15, 23, 42, 0.06);
    font-size: 11px;
    font-weight: 500;
}

.workspace {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr 320px;
    gap: var(--space-5);
    padding: var(--space-5);
    overflow: hidden;
    min-height: 0;
}

.panel {
    background: white;
    border-radius: var(--radius-4);
    box-shadow: var(--shadow-2);
    display: flex;
    flex-direction: column;
    min-width: 0;
    border: 1px solid rgba(15, 23, 42, 0.06);
    overflow: hidden;
    transition: transform 0.3s var(--ease-out), box-shadow 0.3s var(--ease-out);
}

.panel:hover {
    box-shadow: var(--shadow-3);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid rgba(15, 23, 42, 0.06);
    background: linear-gradient(to bottom, rgba(254, 252, 243, 0.5), transparent);
}

.panel-label {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.panel-icon {
    font-size: 18px;
    opacity: 0.6;
}

.panel-header h2 {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.3px;
    text-transform: uppercase;
    font-size: 12px;
    letter-spacing: 1px;
    color: var(--ink-soft);
}

.preset-container {
    display: flex;
    gap: var(--space-2);
}

.preset-chip {
    padding: 6px 14px;
    background: transparent;
    border: 1px solid rgba(15, 23, 42, 0.12);
    border-radius: 100px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    color: var(--ink-soft);
    cursor: pointer;
    transition: all 0.2s var(--ease-out);
}

.preset-chip:hover {
    border-color: var(--ink);
    color: var(--ink);
    transform: translateY(-1px);
}

.preset-chip:active {
    transform: translateY(0);
}

.editor-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    min-height: 0;
}

.editor-decoration {
    display: flex;
    gap: 6px;
    padding: var(--space-3) var(--space-5);
    background: linear-gradient(to bottom, #f8fafc, #f1f5f9);
    border-bottom: 1px solid rgba(15, 23, 42, 0.06);
}

.deco-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.deco-dot:nth-child(1) { background: #ef4444; }
.deco-dot:nth-child(2) { background: #f59e0b; }
.deco-dot:nth-child(3) { background: #10b981; }

#asciiInput {
    flex: 1;
    width: 100%;
    padding: var(--space-5);
    font-family: 'DM Mono', 'SF Mono', Monaco, monospace;
    font-size: 13px;
    line-height: 1.8;
    border: none;
    background: transparent;
    color: var(--ink);
    resize: none;
    outline: none;
    min-height: 0;
}

#asciiInput::placeholder {
    color: rgba(15, 23, 42, 0.3);
}

.action-buttons {
    display: flex;
    gap: var(--space-2);
}

.action-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-2);
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s var(--ease-out);
    border: none;
}

.ghost-btn {
    background: transparent;
    color: var(--ink-soft);
    border: 1px solid rgba(15, 23, 42, 0.12);
}

.ghost-btn:hover {
    border-color: var(--ink);
    color: var(--ink);
}

.primary-btn {
    background: var(--ink);
    color: var(--cream);
    box-shadow: var(--shadow-1);
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-2);
}

.btn-icon {
    font-size: 12px;
}

.canvas-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-5);
    background: linear-gradient(135deg, #fefcf3 0%, #f8f0dc 100%);
    position: relative;
    min-height: 0;
}

.canvas-frame {
    background: white;
    padding: var(--space-5);
    border-radius: var(--radius-3);
    box-shadow: var(--shadow-3);
    border: 1px solid rgba(15, 23, 42, 0.08);
    max-width: 100%;
    max-height: 100%;
    overflow: auto;
    position: relative;
    z-index: 2;
}

#canvas {
    display: block;
    max-width: 100%;
    height: auto;
}

.canvas-grid {
    position: absolute;
    inset: 0;
    background-image: 
        linear-gradient(rgba(15, 23, 42, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(15, 23, 42, 0.03) 1px, transparent 1px);
    background-size: 24px 24px;
    pointer-events: none;
    z-index: 1;
}

.controls-panel {
    background: white;
}

.controls-grid {
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
    padding: var(--space-5);
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.controls-grid::-webkit-scrollbar {
    width: 4px;
}

.controls-grid::-webkit-scrollbar-thumb {
    background: rgba(15, 23, 42, 0.15);
    border-radius: 2px;
}

.control-item {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.control-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.control-item label {
    font-size: 13px;
    font-weight: 500;
    color: var(--ink-soft);
}

.value-badge {
    padding: 4px 10px;
    background: var(--saffron-soft);
    color: var(--saffron);
    border-radius: 100px;
    font-size: 12px;
    font-weight: 600;
    font-family: 'DM Mono', monospace;
}

input[type="range"] {
    width: 100%;
    height: 8px;
    background: linear-gradient(to right, #e2e8f0 0%, #cbd5e1 100%);
    border-radius: 4px;
    outline: none;
    -webkit-appearance: none;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    background: white;
    border: 3px solid var(--ink);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: var(--shadow-1);
    transition: transform 0.15s var(--ease-bounce);
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.control-divider {
    height: 1px;
    background: linear-gradient(to right, transparent, rgba(15, 23, 42, 0.1), transparent);
    margin: var(--space-2) 0;
}

.color-group {
    gap: var(--space-3);
}

.color-swatches {
    display: flex;
    gap: var(--space-2);
}

.swatch {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-2);
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.2s var(--ease-out);
    position: relative;
    overflow: hidden;
}

.swatch:hover {
    transform: scale(1.1);
}

.swatch.active {
    border-color: var(--ink);
    box-shadow: var(--shadow-1);
}

.swatch.active::after {
    content: '✓';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 14px;
    font-weight: 700;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

.bg-swatch.active::after {
    color: var(--ink);
    text-shadow: none;
}

.big-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 16px 24px;
    background: linear-gradient(135deg, var(--ink) 0%, #1e293b 100%);
    color: var(--cream);
    border: none;
    border-radius: var(--radius-3);
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s var(--ease-out);
    box-shadow: var(--shadow-2);
    letter-spacing: -0.3px;
}

.big-action-btn:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-3);
}

.big-action-btn:active {
    transform: translateY(-1px);
}

.btn-circle {
    width: 28px;
    height: 28px;
    background: rgba(254, 252, 243, 0.15);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-3) var(--space-6);
    background: white;
    border-top: 1px solid rgba(15, 23, 42, 0.08);
    font-size: 12px;
    color: var(--ink-soft);
}

.status-left {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.status-dot {
    width: 8px;
    height: 8px;
    background: var(--jade);
    border-radius: 50%;
    animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.status-right {
    font-family: 'DM Mono', monospace;
}

@media (max-width: 1400px) {
    .workspace {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: 1fr auto;
    }
    
    .controls-panel {
        grid-column: 1 / -1;
        grid-row: 2;
    }
    
    .controls-grid {
        flex-direction: row;
        flex-wrap: wrap;
    }
    
    .control-item {
        flex: 1;
        min-width: 200px;
    }
    
    .color-group {
        flex: 1;
        min-width: 280px;
    }
    
    .big-action-btn {
        width: 100%;
    }
    
    .control-divider {
        display: none;
    }
}

@media (max-width: 900px) {
    .workspace {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
        overflow-y: auto;
    }
    
    .panel {
        min-height: 400px;
    }
    
    .controls-grid {
        flex-direction: column;
    }
    
    .control-item {
        min-width: 0;
    }
}
