/* ============================================================
   CSS Grid Generator (Visual) — Styles
   Modern dark-first design, purple primary
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
    --primary: #8B5CF6;
    --primary-light: #A78BFA;
    --primary-dark: #7C3AED;
    --bg: #0F172A;
    --bg-elevated: #1E293B;
    --bg-surface: #334155;
    --bg-card: #1E293B;
    --bg-hover: #2D3B55;
    --text-primary: #F1F5F9;
    --text-secondary: #94A3B8;
    --text-muted: #64748B;
    --border: #334155;
    --cell-color: rgba(139, 92, 246, .15);
    --cell-border: rgba(139, 92, 246, .4);
    --cell-active: rgba(139, 92, 246, .35);
    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 4px 16px rgba(0, 0, 0, .3);
    --transition: 200ms ease;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

[data-theme="light"] {
    --bg: #F8FAFC;
    --bg-elevated: #FFFFFF;
    --bg-surface: #F1F5F9;
    --bg-card: #FFFFFF;
    --bg-hover: #E2E8F0;
    --text-primary: #0F172A;
    --text-secondary: #475569;
    --text-muted: #94A3B8;
    --border: #E2E8F0;
    --cell-color: rgba(139, 92, 246, .08);
    --cell-border: rgba(139, 92, 246, .25);
    --cell-active: rgba(139, 92, 246, .2);
    --shadow: 0 4px 16px rgba(0, 0, 0, .06);
}

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

html {
    font-size: 16px;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

.app {
    max-width: 1100px;
    margin: 0 auto;
    padding: 24px 16px 80px;
}

/* --- Header --- */
.header {
    text-align: center;
    padding: 32px 0 20px;
}

.header-icon {
    font-size: 2.5rem;
    display: block;
    margin-bottom: 8px;
}

.header h1 {
    font-size: 1.75rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header p {
    color: var(--text-secondary);
    font-size: .9rem;
    margin-top: 4px;
}

/* --- Toolbar --- */
.toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: .85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

.btn:hover {
    background: var(--bg-hover);
}

.btn:active {
    transform: scale(.97);
}

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

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

.btn-sm {
    padding: 6px 12px;
    font-size: .8rem;
}

/* --- Controls Panel --- */
.controls-panel {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 20px;
}

.control-group label {
    display: block;
    font-size: .75rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: .5px;
}

.control-input {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: .85rem;
    outline: none;
}

.control-input:focus {
    border-color: var(--primary);
}

select.control-input {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%2394A3B8'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    padding-right: 24px;
}

/* --- Main Layout --- */
.main-layout {
    display: grid;
    grid-template-columns: 1fr 360px;
    gap: 20px;
}

/* --- Grid Canvas --- */
.grid-canvas-container {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 400px;
    overflow: auto;
}

.grid-canvas {
    display: grid;
    gap: 8px;
    width: 100%;
    max-width: 600px;
}

.grid-cell {
    background: var(--cell-color);
    border: 2px dashed var(--cell-border);
    border-radius: var(--radius-sm);
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition);
    font-size: .75rem;
    color: var(--text-muted);
    position: relative;
}

.grid-cell:hover {
    background: var(--cell-active);
    border-color: var(--primary);
}

.grid-cell.selected {
    background: var(--cell-active);
    border: 2px solid var(--primary);
    color: var(--primary);
    font-weight: 600;
}

.grid-cell.named {
    background: var(--cell-active);
    border-style: solid;
}

.cell-name-input {
    background: transparent;
    border: none;
    color: var(--primary);
    font-family: var(--font-mono);
    font-size: .75rem;
    text-align: center;
    width: 80%;
    outline: none;
}

/* --- Code Panel --- */
.code-panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.code-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    font-size: .85rem;
    font-weight: 700;
}

.code-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
}

.code-tab {
    padding: 8px 16px;
    font-size: .8rem;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
    font-family: var(--font);
    transition: all var(--transition);
}

.code-tab:hover {
    color: var(--text-primary);
}

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

.code-body {
    flex: 1;
    overflow: auto;
    padding: 16px;
}

.code-display {
    font-family: var(--font-mono);
    font-size: .8rem;
    line-height: 1.7;
    white-space: pre;
    color: var(--text-primary);
    min-height: 200px;
}

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

/* --- Toast --- */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 20px;
    font-size: .85rem;
    box-shadow: var(--shadow);
    opacity: 0;
    pointer-events: none;
    transition: all var(--transition);
    z-index: 200;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .main-layout {
        grid-template-columns: 1fr;
    }

    .controls-panel {
        grid-template-columns: 1fr 1fr;
    }

    .header h1 {
        font-size: 1.4rem;
    }
}

@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: .01ms !important;
        transition-duration: .01ms !important;
    }
}

:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}