/* ============================================================
   CSS Grid Playground — Cyan/Purple Dark Theme
   ============================================================ */
:root {
    --primary: #06B6D4;
    --primary-hover: #22D3EE;
    --primary-glow: rgba(6, 182, 212, .25);
    --secondary: #8B5CF6;
    --accent: #A5F3FC;
    --danger: #EF4444;
    --success: #10B981;
    --warning: #F59E0B;
    --bg-base: #0F172A;
    --bg-surface: #1E293B;
    --bg-elevated: #273548;
    --bg-hover: #334155;
    --bg-active: #3B4F66;
    --text-primary: #F1F5F9;
    --text-secondary: #94A3B8;
    --text-muted: #64748B;
    --border: rgba(255, 255, 255, .06);
    --border-hover: rgba(255, 255, 255, .12);
    --border-focus: var(--primary);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, .3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, .4);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, .5);
    --shadow-glow: 0 0 20px var(--primary-glow);
    --transition-fast: 150ms cubic-bezier(.4, 0, .2, 1);
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

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

html {
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

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

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background: radial-gradient(ellipse 80% 50% at 50% -20%, rgba(6, 182, 212, .06), transparent), radial-gradient(ellipse 60% 40% at 80% 100%, rgba(139, 92, 246, .05), transparent);
    pointer-events: none;
}

.app-container {
    position: relative;
    z-index: 1;
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px 60px;
}

/* Header */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 0 12px;
    gap: 14px;
    flex-wrap: wrap;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 14px;
}

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

.subtitle {
    font-size: .78rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.header-actions {
    display: flex;
    gap: 6px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: .82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

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

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: #fff;
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md), 0 0 16px var(--primary-glow);
}

.btn-ghost {
    background: var(--bg-elevated);
    color: var(--text-secondary);
    border-color: var(--border);
}

.btn-ghost:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-sm {
    padding: 5px 10px;
    font-size: .75rem;
}

.mono {
    font-family: var(--font-mono);
}

/* Split Layout */
.split-layout {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 16px;
    align-items: start;
}

/* Editor Panel */
.editor-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Controls */
.controls-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
    box-shadow: var(--shadow-sm);
}

.controls-title {
    font-size: .88rem;
    font-weight: 600;
    margin-bottom: 10px;
}

.controls-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 8px;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.control-label {
    font-size: .68rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .05em;
}

.control-input,
.control-select {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px 8px;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: .82rem;
    outline: none;
    transition: border-color var(--transition-fast);
}

.control-input:focus,
.control-select:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.control-select {
    cursor: pointer;
}

.control-select option {
    background: var(--bg-elevated);
}

.controls-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 10px;
    gap: 8px;
}

.item-count {
    font-size: .75rem;
    color: var(--text-muted);
}

/* Canvas */
.canvas-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.canvas-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
}

.canvas-title {
    font-size: .82rem;
    font-weight: 600;
}

.responsive-btns {
    display: flex;
    gap: 2px;
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    padding: 2px;
}

.resp-btn {
    padding: 4px 8px;
    border: none;
    background: transparent;
    border-radius: 4px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.resp-btn:hover {
    color: var(--text-primary);
}

.resp-btn.active {
    background: var(--primary);
    color: #fff;
}

.canvas-wrap {
    padding: 16px;
    overflow: auto;
    min-height: 300px;
    transition: max-width .3s ease;
}

.grid-canvas {
    width: 100%;
    min-height: 260px;
    border: 2px dashed var(--border);
    border-radius: var(--radius-md);
    transition: all .2s ease;
    position: relative;
}

/* Grid Items */
.grid-item {
    background: rgba(6, 182, 212, .12);
    border: 1px solid rgba(6, 182, 212, .3);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .78rem;
    font-weight: 500;
    color: var(--primary);
    cursor: pointer;
    transition: all var(--transition-fast);
    min-height: 40px;
    position: relative;
}

.grid-item:hover {
    background: rgba(6, 182, 212, .2);
    border-color: rgba(6, 182, 212, .5);
}

.grid-item.selected {
    background: rgba(139, 92, 246, .15);
    border-color: rgba(139, 92, 246, .5);
    color: var(--secondary);
    box-shadow: 0 0 12px rgba(139, 92, 246, .2);
}

.grid-item .item-label {
    pointer-events: none;
}

/* Item Editor */
.item-editor {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
    box-shadow: var(--shadow-sm);
}

.item-editor[hidden] {
    display: none;
}

.item-editor-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

/* Code Panel */
.code-panel {
    position: sticky;
    top: 16px;
}

.code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.code-title {
    font-size: .88rem;
    font-weight: 600;
}

.code-output {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    overflow-x: auto;
    max-height: 360px;
    overflow-y: auto;
    font-family: var(--font-mono);
    font-size: .78rem;
    line-height: 1.7;
    color: var(--accent);
    white-space: pre;
    tab-size: 2;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .6);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay[hidden] {
    display: none;
}

.modal {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    max-width: 600px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.modal-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

.templates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 10px;
}

.template-item {
    padding: 14px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    text-align: center;
    transition: all var(--transition-fast);
}

.template-item:hover {
    border-color: var(--border-hover);
    background: var(--bg-hover);
}

.template-item h4 {
    font-size: .82rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.template-item p {
    font-size: .72rem;
    color: var(--text-muted);
}

.template-mini {
    display: grid;
    gap: 3px;
    margin-bottom: 8px;
    height: 50px;
}

.template-mini div {
    background: rgba(6, 182, 212, .12);
    border: 1px solid rgba(6, 182, 212, .2);
    border-radius: 3px;
}

/* Toast */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 10px 16px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    font-size: .85rem;
    animation: toastSlide 300ms ease;
    max-width: 360px;
}

.toast.success {
    border-left: 3px solid var(--success);
}

.toast.error {
    border-left: 3px solid var(--danger);
}

.toast.info {
    border-left: 3px solid var(--primary);
}

.toast-exit {
    animation: toastExit 200ms ease forwards;
}

@keyframes toastSlide {
    from {
        transform: translateX(100%);
        opacity: 0
    }

    to {
        transform: translateX(0);
        opacity: 1
    }
}

@keyframes toastExit {
    from {
        opacity: 1
    }

    to {
        opacity: 0;
        transform: translateX(100%)
    }
}

::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--bg-active);
    border-radius: 3px;
}

@media(max-width:900px) {
    .split-layout {
        grid-template-columns: 1fr;
    }

    .code-panel {
        position: static;
    }
}

@media(max-width:480px) {
    .app-container {
        padding: 0 12px 40px;
    }

    .app-header h1 {
        font-size: 1.1rem;
    }

    .subtitle {
        display: none;
    }

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