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

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

:root {
    --bg-primary: #f4f7fa;
    --bg-panel: rgba(255, 255, 255, 0.95);
    --bg-card: rgba(250, 252, 255, 0.98);
    --bg-hover: rgba(220, 230, 245, 0.6);
    --bg-input: rgba(240, 245, 250, 0.8);
    --border: rgba(180, 200, 220, 0.8);
    --border-active: rgba(50, 130, 240, 0.8);
    --text-primary: #1a2b40;
    --text-secondary: #4a5a70;
    --text-dim: #70809a;
    --accent: #2c7ef0;
    --accent-glow: rgba(44, 126, 240, 0.25);
    --danger: #e63946;
    --success: #2a9d8f;
    --warning: #e76f51;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 8px 32px rgba(0,0,0,0.4);
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
    font-family: 'Inter', -apple-system, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    width: 100vw;
    height: 100vh;
}

#viewport {
    position: fixed;
    inset: 0;
    z-index: 0;
}

#viewport canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

/* ===== TOOLBAR ===== */
#toolbar {
    position: fixed;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--bg-panel);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
}

.logo {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-right: 8px;
    user-select: none;
}

.logo .material-icons-round { font-size: 22px; color: var(--accent); }

.logo h1 {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.3px;
    white-space: nowrap;
}

.logo h1 span { color: var(--accent); font-weight: 700; }

.toolbar-separator {
    width: 1px;
    height: 24px;
    background: var(--border);
    margin: 0 4px;
}

.toolbar-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.toolbar-btn .material-icons-round { font-size: 18px; }

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

.toolbar-btn.active {
    background: var(--accent-glow);
    color: var(--accent);
    border-color: var(--border-active);
}

.toolbar-btn.primary {
    background: linear-gradient(135deg, #4a9bff, #3a7be0);
    color: #fff;
    border: none;
    font-weight: 600;
}

.toolbar-btn.primary:hover {
    background: linear-gradient(135deg, #5aa5ff, #4a8bf0);
    box-shadow: 0 0 20px var(--accent-glow);
}

.toolbar-btn.danger:hover {
    background: rgba(255, 90, 106, 0.15);
    color: var(--danger);
}

#component-count {
    font-size: 11px;
    color: var(--text-dim);
    margin-left: 8px;
    white-space: nowrap;
}

/* ===== PANELS ===== */
.panel {
    position: fixed;
    top: 70px;
    width: 260px;
    max-height: calc(100vh - 110px);
    background: var(--bg-panel);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    z-index: 90;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.panel-left { left: 12px; }
.panel-right { right: 12px; }

.panel-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.panel-header .material-icons-round {
    font-size: 18px;
    color: var(--accent);
}

.panel-header h3 {
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.3px;
}

.panel-body {
    padding: 10px;
    overflow-y: auto;
    flex: 1;
}

.panel-body::-webkit-scrollbar { width: 4px; }
.panel-body::-webkit-scrollbar-track { background: transparent; }
.panel-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.empty-state {
    text-align: center;
    padding: 30px 10px;
    color: var(--text-dim);
}

.empty-state .material-icons-round {
    font-size: 36px;
    margin-bottom: 10px;
    opacity: 0.5;
}

.empty-state p { font-size: 12px; line-height: 1.6; }

/* Component list items */
.comp-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    margin-bottom: 4px;
}

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

.comp-item.selected {
    background: var(--accent-glow);
    border: 1px solid var(--border-active);
}

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

.comp-item .info { flex: 1; min-width: 0; }

.comp-item .info .name {
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.comp-item .info .type {
    font-size: 10px;
    color: var(--text-dim);
}

.comp-item .del-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 2px;
    border-radius: 4px;
    display: flex;
    opacity: 0;
    transition: var(--transition);
}

.comp-item:hover .del-btn { opacity: 1; }
.comp-item .del-btn:hover { color: var(--danger); background: rgba(255,90,106,0.1); }
.comp-item .del-btn .material-icons-round { font-size: 16px; }

/* Properties panel */
.prop-section {
    margin-bottom: 16px;
}

.prop-section h4 {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-dim);
    margin-bottom: 8px;
}

.prop-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.prop-row label {
    font-size: 11px;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.prop-row input {
    width: 90px;
    padding: 5px 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 12px;
    text-align: right;
    outline: none;
    transition: var(--transition);
}

.prop-row input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.prop-color {
    display: flex;
    align-items: center;
    gap: 8px;
}

.prop-color input[type="color"] {
    width: 32px;
    height: 24px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: none;
    cursor: pointer;
    padding: 0;
}

/* ===== MODAL ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

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

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 24px 80px rgba(0,0,0,0.5);
    width: 540px;
    max-width: 92vw;
    max-height: 85vh;
    overflow-y: auto;
    animation: modalIn 0.25s ease;
}

.modal-sm { width: 380px; }

@keyframes modalIn {
    from { transform: translateY(20px) scale(0.97); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}

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

.modal-header h2 { font-size: 16px; font-weight: 600; }

.modal-close {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    display: flex;
    transition: var(--transition);
}

.modal-close:hover { color: var(--text-primary); background: var(--bg-hover); }

.modal-body { padding: 20px 22px; }

/* Type grid */
.type-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 20px;
}

.type-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 16px 10px;
    background: var(--bg-input);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.type-card:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: rgba(74, 155, 255, 0.3);
}

.type-card.selected {
    background: var(--accent-glow);
    border-color: var(--accent);
    color: var(--accent);
}

.type-card svg {
    width: 44px;
    height: 44px;
}

/* Param section */
.param-section { border-top: 1px solid var(--border); padding-top: 18px; }
.param-section.hidden { display: none; }
.param-section h3 { font-size: 13px; font-weight: 600; margin-bottom: 14px; }

.param-field {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.param-field label { font-size: 12px; color: var(--text-secondary); }

.param-field input {
    width: 100px;
    padding: 7px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 13px;
    text-align: right;
    outline: none;
    transition: var(--transition);
}

.param-field input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.btn-create {
    width: 100%;
    padding: 11px;
    margin-top: 16px;
    background: linear-gradient(135deg, #4a9bff, #3a7be0);
    border: none;
    border-radius: var(--radius-sm);
    color: #fff;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: var(--transition);
}

.btn-create:hover {
    box-shadow: 0 0 24px var(--accent-glow);
    transform: translateY(-1px);
}

.btn-create.hidden { display: none; }

/* ===== TRIM OVERLAY ===== */
.trim-overlay {
    position: fixed;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 150;
    animation: trimSlideUp 0.25s ease;
}

.trim-overlay.hidden { display: none; }

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

.trim-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 18px;
    background: var(--bg-panel);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.35);
}

.trim-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-right: 6px;
}

.trim-btn {
    padding: 7px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

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

.trim-btn.primary {
    background: linear-gradient(135deg, #4a9bff, #3a7be0);
    color: #fff;
    border: none;
    font-weight: 600;
}

.trim-btn.primary:hover {
    box-shadow: 0 0 16px var(--accent-glow);
}

.trim-btn.danger {
    color: var(--danger);
    border-color: rgba(230, 57, 70, 0.3);
}

.trim-btn.danger:hover {
    background: rgba(230, 57, 70, 0.1);
}

/* ===== STATUS BAR ===== */
#status-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    background: rgba(240, 245, 250, 0.9);
    border-top: 1px solid var(--border);
    z-index: 100;
    font-size: 11px;
    color: var(--text-dim);
}

#status-bar .status-accent { color: var(--accent); }

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
    .panel { width: 200px; }
    .type-grid { grid-template-columns: repeat(2, 1fr); }
    #toolbar { flex-wrap: wrap; justify-content: center; }
    .toolbar-btn span:not(.material-icons-round) { display: none; }
}

@media (max-width: 600px) {
    .panel-left, .panel-right { display: none; }
    #toolbar { width: calc(100% - 24px); }
}
