:root {
    --bg: #0f1115;
    --panel: #151924;
    --panel-2: #111522;
    --text: #e6e9ef;
    --muted: #aab3c5;
    --primary: #6aa9ff;
    --accent: #6cf0c2;
    --danger: #ff6b6b;
    --grid-cell: #232a3b;
    --area: #6aa9ff22;
    --area-border: #6aa9ff;
    --border: #1f2433;
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
}

body {
    margin: 0;
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, Apple Color Emoji, Segoe UI Emoji;
    color: var(--text);
    background: radial-gradient(1200px 800px at 10% -10%, #1b2233 0%, #0f1115 40%, #0b0d12 100%);
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, #121724, #0f131e);
    position: sticky;
    top: 0;
    z-index: 10;
}

.app-header h1 {
    margin: 0;
    font-size: 18px;
    letter-spacing: 0.3px;
}

.controls {
    display: flex;
    gap: 12px;
    align-items: end;
    flex-wrap: wrap;
}

label {
    display: grid;
    gap: 6px;
    font-size: 12px;
    color: var(--muted);
}

input, select, button {
    height: 32px;
    border-radius: 8px;
    border: 1px solid #283049;
    background: #0f1422;
    color: var(--text);
    padding: 0 10px;
}

button {
    background: linear-gradient(180deg, #1c78ff, #1556cc);
    border: none;
    padding: 0 14px;
    cursor: pointer;
}

button.secondary {
    background: #1a2133;
    border: 1px solid #2a3658;
}

button.danger {
    background: #2a1a1a;
    border: 1px solid #5a2a2a;
    color: #ff6b6b;
}

button.danger:hover {
    background: #3a2222;
    border-color: #6a3a3a;
}

button:active { transform: translateY(1px); }

.app-main {
    display: grid;
    grid-template-columns: 1fr 420px;
    gap: 0;
    height: calc(100% - 66px);
}

.canvas-panel {
    padding: 20px;
    display: grid;
    grid-template-rows: 1fr auto;
}

.grid-container {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    display: grid;
    gap: 8px;
    position: relative;
    min-height: 520px;
    user-select: none;
}

.grid-bg {
    position: absolute;
    inset: 12px;
    display: grid;
    pointer-events: none;
    z-index: 0;
}

.grid-bg .cell {
    background: linear-gradient(180deg, #121727, #0f1420);
    border: 1px dashed #2a3555;
    border-radius: 6px;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.grid-bg .cell:hover {
    background: linear-gradient(180deg, #1a1f32, #151a28);
    border-color: #3d4a6b;
}

.grid-area-item {
    position: relative;
    background: var(--area);
    border: 2px solid var(--area-border);
    border-radius: 10px;
    box-shadow: 0 0 0 1px #0004, inset 0 0 16px 2px #6aa9ff22;
    transition: transform .12s ease, box-shadow .2s ease, background-color .2s ease, outline-color .2s ease, border-color .2s ease;
}

.grid-area-item.selected {
    outline: 2px solid var(--accent);
}

.grid-area-item:hover {
    box-shadow: 0 0 0 1px #0006, inset 0 0 22px 4px #6aa9ff33;
}

.grid-area-item.dragging {
    transform: scale(1.02);
}

.handle {
    position: absolute;
    width: 12px;
    height: 12px;
    background: var(--accent);
    border-radius: 4px;
    right: 6px;
    bottom: 6px;
    cursor: nwse-resize;
}

.handle { transition: transform .12s ease, box-shadow .12s ease; }
.handle:hover { transform: scale(1.15); box-shadow: 0 2px 6px #6cf0c255; }

.grid-container.dragging { cursor: crosshair; }

.creating-preview {
    position: relative;
    background: transparent;
    border: 2px dashed var(--area-border);
    border-radius: 10px;
    box-shadow: inset 0 0 0 9999px #6aa9ff11;
    animation: ants 8s linear infinite;
}

@keyframes ants {
    from { border-color: var(--area-border); }
    50% { border-color: #9bc6ff; }
    to { border-color: var(--area-border); }
}

.hint {
    margin-top: 12px;
    color: var(--muted);
    font-size: 12px;
}

.code-panel {
    border-left: 1px solid var(--border);
    background: var(--panel-2);
    display: grid;
    grid-template-rows: auto 1fr;
}

.code-controls {
    display: flex;
    gap: 10px;
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.code-output {
    padding: 16px;
    overflow: auto;
}

.code-output h2 {
    margin: 10px 0 8px 0;
    font-size: 13px;
    color: var(--muted);
}

.code {
    background: #0b0e18;
    border: 1px solid #1a2140;
    border-radius: 10px;
    padding: 12px;
    white-space: pre;
    overflow: auto;
    min-height: 120px;
}

.code[contenteditable="true"] {
    outline: none;
    caret-color: var(--text);
}

.code[contenteditable="true"]:focus {
    box-shadow: 0 0 0 2px #1f2a4f inset, 0 0 0 1px #2a3658;
    border-color: #2a3658;
}

.app-footer {
    padding: 10px 16px;
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: 12px;
}

/* Loading states */
button.loading {
    opacity: 0.6;
    pointer-events: none;
    position: relative;
}

button.loading::after {
    content: '';
    position: absolute;
    width: 12px;
    height: 12px;
    top: 50%;
    left: 50%;
    margin-left: -6px;
    margin-top: -6px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* Error message */
.error-message {
    position: fixed;
    left: 50%;
    bottom: 22px;
    transform: translateX(-50%);
    padding: 10px 16px;
    background: var(--danger);
    color: white;
    border-radius: 8px;
    font-size: 12px;
    z-index: 1001;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* Editable label */
.area-label-editable {
    cursor: text;
    user-select: text;
    padding: 2px 4px;
    border-radius: 4px;
    min-width: 40px;
    display: inline-block;
}

.area-label-editable:hover {
    background: rgba(255,255,255,0.1);
}

.area-label-editing {
    background: rgba(255,255,255,0.15) !important;
    outline: 2px solid var(--accent);
}

/* Shortcuts modal */
.shortcuts-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.shortcuts-modal.active {
    display: flex;
}

.shortcuts-content {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    max-width: 500px;
    max-height: 80vh;
    overflow: auto;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.shortcuts-content h3 {
    margin: 0 0 16px 0;
    color: var(--text);
}

.shortcut-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.shortcut-item:last-child {
    border-bottom: none;
}

.shortcut-key {
    background: var(--panel-2);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-family: monospace;
    border: 1px solid var(--border);
}


