/* ── Variables ─────────────────────────────────────── */
:root {
    --bg: #0d0d12;
    --bg-panel: #14141e;
    --bg-card: #1c1c2e;
    --bg-hover: #252540;
    --bg-input: #1e1e32;
    --border: #2a2a45;
    --text: #e4e4ef;
    --text-muted: #8888aa;
    --text-dim: #555570;
    --primary: #6366f1;
    --primary-hover: #818cf8;
    --success: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;
    --accent: #ec4899;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --mono: 'JetBrains Mono', 'Fira Code', monospace;
    --radius: 6px;
    --sidebar-w: 250px;
    --tools-w: 280px;
    --topbar-h: 48px;
}

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
    font-size: 13px;
}

/* ── Top Bar ──────────────────────────────────────── */
#topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--topbar-h);
    padding: 0 12px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    z-index: 100;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.topbar-left h1 {
    font-size: 16px;
    font-weight: 700;
    white-space: nowrap;
}

.topbar-center {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    justify-content: center;
}

.topbar-center input {
    width: 200px;
    text-align: center;
    font-weight: 600;
}

.topbar-center select {
    width: auto;
    min-width: 130px;
}

.topbar-right {
    display: flex;
    gap: 6px;
}

/* ── App Layout ───────────────────────────────────── */
#app {
    display: flex;
    height: calc(100vh - var(--topbar-h));
}

/* ── Sidebar ──────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    flex-shrink: 0;
    transition: width .2s, margin-left .2s;
}

.sidebar.collapsed {
    width: 0;
    overflow: hidden;
    margin-left: calc(var(--sidebar-w) * -1);
}

.sidebar-section {
    padding: 12px;
    border-bottom: 1px solid var(--border);
}

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

.sidebar-header h3 {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-muted);
}

.sidebar-filter {
    margin-bottom: 8px;
}

.sidebar-filter select {
    width: 100%;
}

.item-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: 300px;
    overflow-y: auto;
}

.item-card {
    padding: 8px 10px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background .1s;
    display: flex;
    align-items: center;
    gap: 8px;
}

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

.item-card.active {
    background: var(--primary);
    color: white;
}

.item-card .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.item-card .name {
    flex: 1;
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.item-card .count {
    font-size: 11px;
    color: var(--text-muted);
}

.item-card.active .count {
    color: rgba(255, 255, 255, .7);
}

.item-card .platform-tag {
    font-size: 10px;
    padding: 1px 5px;
    border-radius: 3px;
    background: var(--bg-input);
    color: var(--text-muted);
    flex-shrink: 0;
}

/* ── Canvas Area ──────────────────────────────────── */
#canvas-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #0a0a10;
    position: relative;
    overflow: hidden;
    /* Checkerboard for transparency */
    background-image:
        linear-gradient(45deg, #111 25%, transparent 25%),
        linear-gradient(-45deg, #111 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #111 75%),
        linear-gradient(-45deg, transparent 75%, #111 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

#canvas-wrapper {
    box-shadow: 0 0 60px rgba(0, 0, 0, .5);
    position: relative;
}

#zoom-controls {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 4px 12px;
}

#zoom-controls button {
    background: none;
    border: none;
    color: var(--text);
    font-size: 16px;
    cursor: pointer;
    padding: 4px 8px;
}

#zoom-level {
    font-size: 12px;
    color: var(--text-muted);
    min-width: 40px;
    text-align: center;
}

/* ── Tools Panel ──────────────────────────────────── */
.tools-panel {
    width: var(--tools-w);
    background: var(--bg-panel);
    border-left: 1px solid var(--border);
    overflow-y: auto;
    flex-shrink: 0;
}

.tool-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
}

.tool-tab {
    flex: 1;
    padding: 8px 4px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 11px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    font-family: var(--font);
}

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

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

.tab-content {
    display: none;
    padding: 12px;
}

.tab-content.active {
    display: block;
}

.tool-section {
    margin-bottom: 16px;
}

.tool-section h4 {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .5px;
    margin-bottom: 8px;
}

/* ── Forms ────────────────────────────────────────── */
.form-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.form-row label {
    font-size: 12px;
    color: var(--text-muted);
    min-width: 70px;
    flex-shrink: 0;
}

input,
select,
textarea {
    padding: 6px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
    width: 100%;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
}

input[type="color"] {
    width: 36px;
    height: 30px;
    padding: 2px;
    cursor: pointer;
    border-radius: var(--radius);
}

input[type="range"] {
    -webkit-appearance: auto;
}

input[type="number"] {
    width: 80px;
}

/* ── Buttons ──────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    border: none;
    border-radius: var(--radius);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s;
    font-family: var(--font);
    background: var(--bg-input);
    color: var(--text);
    border: 1px solid var(--border);
    white-space: nowrap;
}

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

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

.btn-xs {
    padding: 3px 8px;
    font-size: 11px;
}

.btn-primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

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

.btn-success {
    background: var(--success);
    color: white;
    border-color: var(--success);
}

.btn-danger {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}

.full-w {
    width: 100%;
    justify-content: center;
    margin-bottom: 4px;
}

.btn-group-sm {
    display: flex;
    gap: 4px;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text);
    cursor: pointer;
    font-size: 18px;
    padding: 4px;
    line-height: 1;
}

.icon-btn.small {
    font-size: 16px;
}

/* ── Shapes Grid ──────────────────────────────────── */
.shape-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
}

.shape-btn {
    aspect-ratio: 1;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-input);
    color: var(--text);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .1s;
}

.shape-btn:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* ── Layers ───────────────────────────────────────── */
.layer-actions {
    display: flex;
    gap: 4px;
    margin-bottom: 8px;
}

.layers-list {
    max-height: 200px;
    overflow-y: auto;
}

.layer-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}

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

.layer-item.active {
    background: rgba(99, 102, 241, .2);
    color: var(--primary);
}

.layer-icon {
    font-size: 14px;
    flex-shrink: 0;
}

.layer-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Assets Grid ──────────────────────────────────── */
.assets-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    max-height: 400px;
    overflow-y: auto;
}

.asset-thumb {
    aspect-ratio: 1;
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color .1s;
    position: relative;
}

.asset-thumb:hover {
    border-color: var(--primary);
}

.asset-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.asset-thumb .delete-asset {
    position: absolute;
    top: 2px;
    right: 2px;
    background: rgba(0, 0, 0, .7);
    color: var(--danger);
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 12px;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
}

.asset-thumb:hover .delete-asset {
    display: flex;
}

/* ── Color Presets ────────────────────────────────── */
.color-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 8px;
}

.color-swatch {
    width: 28px;
    height: 28px;
    border-radius: 4px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all .1s;
}

.color-swatch:hover {
    border-color: white;
    transform: scale(1.1);
}

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

.modal-overlay.open {
    display: flex;
}

.modal {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 420px;
    max-width: 90vw;
    max-height: 80vh;
    overflow-y: auto;
}

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

.modal-header h3 {
    font-size: 16px;
}

.modal-body {
    padding: 20px;
}

.modal-body .form-row {
    margin-bottom: 12px;
}

.modal-body .form-row label {
    min-width: 80px;
}

.modal-body .btn {
    margin-top: 12px;
}

/* ── Toast ────────────────────────────────────────── */
#toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 10px 18px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    animation: slideIn .25s ease;
    max-width: 340px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, .4);
}

.toast.success {
    background: rgba(34, 197, 94, .9);
    color: white;
}

.toast.error {
    background: rgba(239, 68, 68, .9);
    color: white;
}

.toast.info {
    background: rgba(99, 102, 241, .9);
    color: white;
}

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

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

/* ── Placeholder ──────────────────────────────────── */
.placeholder-text {
    color: var(--text-dim);
    font-size: 12px;
    font-style: italic;
    padding: 8px 0;
}

/* ── Scrollbar ────────────────────────────────────── */
::-webkit-scrollbar {
    width: 5px;
}

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

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

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ── Responsive ───────────────────────────────────── */
@media (max-width: 900px) {
    .sidebar {
        display: none;
    }

    .tools-panel {
        width: 220px;
    }
}