@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

:root {
    --bg: #0e0e16;
    --bg-panel: #13131c;
    --bg-card: #1a1a26;
    --bg-hover: #22222f;
    --border: rgba(255, 255, 255, 0.07);
    --text: #f0f0f8;
    --text-muted: #8888aa;
    --accent: #4F9BFF;
    --accent-glow: rgba(79, 155, 255, 0.2);
    --danger: #f5576c;
    --toolbar-h: 56px;
    --left-w: 240px;
    --right-w: 280px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* ============ TOOLBAR ============ */
.toolbar {
    height: var(--toolbar-h);
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 8px;
    flex-shrink: 0;
    z-index: 100;
}

.toolbar-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 800;
    font-size: 0.95rem;
    color: var(--text);
    text-decoration: none;
    padding-right: 12px;
    border-right: 1px solid var(--border);
    margin-right: 4px;
}

.toolbar-logo-icon {
    width: 28px;
    height: 28px;
    background: linear-gradient(135deg, #667eea, #f093fb);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
}

.toolbar-sep {
    width: 1px;
    height: 28px;
    background: var(--border);
    margin: 0 6px;
}

/* Toolbar Buttons */
.tbtn {
    height: 36px;
    min-width: 36px;
    padding: 0 10px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    transition: all 0.15s;
    white-space: nowrap;
}

.tbtn:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.tbtn.active {
    background: rgba(79, 155, 255, 0.15);
    color: var(--accent);
    border-color: rgba(79, 155, 255, 0.25);
}

.tbtn.btn-save {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.2), rgba(240, 147, 251, 0.2));
    color: #a090ff;
    border-color: rgba(102, 126, 234, 0.3);
}

.tbtn.btn-export {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border: none;
}

.tbtn.btn-export:hover {
    opacity: 0.9;
}

.tbtn.btn-danger:hover {
    color: var(--danger);
    background: rgba(245, 87, 108, 0.1);
}

.tbtn .icon {
    font-style: normal;
    font-size: 1rem;
}

.toolbar-spacer {
    flex: 1;
}

/* Mode group pills */
.mode-group {
    display: flex;
    background: var(--bg-card);
    border-radius: 10px;
    padding: 3px;
    gap: 2px;
    border: 1px solid var(--border);
}

.mode-group .tbtn {
    border-radius: 7px;
    border: none;
}

.mode-group .tbtn.active {
    background: var(--bg-hover);
    color: var(--accent);
}

/* Project name in toolbar */
.project-name-label {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-muted);
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ============ EDITOR BODY ============ */
.editor-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ============ LEFT SIDEBAR ============ */
.left-sidebar {
    width: var(--left-w);
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 12px 16px;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Sidebar Tabs */
.sidebar-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
}

.sidebar-tab {
    flex: 1;
    text-align: center;
    padding: 12px 10px;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    cursor: pointer;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    font-family: inherit;
    outline: none;
}

.sidebar-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    background: rgba(79, 155, 255, 0.05);
}

.sidebar-tab:hover:not(.active) {
    color: var(--text);
    background: var(--bg-hover);
}

.sidebar-header button {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--accent);
    font-size: 0.7rem;
    font-weight: 700;
    padding: 3px 8px;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s;
}

.sidebar-header button:hover {
    background: var(--bg-hover);
}

#block-list, #file-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

#block-list::-webkit-scrollbar, #file-list::-webkit-scrollbar {
    width: 4px;
}

#block-list::-webkit-scrollbar-track, #file-list::-webkit-scrollbar-track {
    background: transparent;
}

#block-list::-webkit-scrollbar-thumb, #file-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.block-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
    border: 1px solid transparent;
    margin-bottom: 2px;
}

.block-item:hover {
    background: var(--bg-hover);
}

.block-item.active {
    background: rgba(79, 155, 255, 0.08);
    border-color: rgba(79, 155, 255, 0.2);
}

.block-item-icon {
    font-size: 0.9rem;
    flex-shrink: 0;
}

.block-item-name {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.block-item-actions {
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity 0.15s;
    flex-shrink: 0;
}

.block-item:hover .block-item-actions {
    opacity: 1;
}

.block-item-actions button {
    width: 22px;
    height: 22px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.72rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.block-item-actions button:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.block-item-actions button.danger:hover {
    color: var(--danger);
    background: rgba(245, 87, 108, 0.1);
}

/* File List specific */
.file-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.82rem;
    color: var(--text);
    margin-bottom: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-item:hover {
    background: var(--bg-hover);
}

.file-item-icon {
    font-size: 1rem;
    flex-shrink: 0;
    opacity: 0.7;
}

.file-folder {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 800;
    padding: 14px 10px 4px;
    letter-spacing: 0.5px;
    user-select: none;
}

/* Add block button */
.add-block-btn {
    margin: 8px;
    padding: 10px;
    background: var(--bg-card);
    border: 1px dashed rgba(79, 155, 255, 0.25);
    border-radius: 10px;
    cursor: pointer;
    color: var(--accent);
    font-size: 0.82rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.2s;
    font-family: inherit;
}

.add-block-btn:hover {
    border-color: var(--accent);
    background: rgba(79, 155, 255, 0.08);
}

/* ============ CANVAS ============ */
.canvas-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: auto;
    position: relative;
    background: #1a1a28;
    padding: 0;
}

.canvas-wrapper.mobile-mode {
    background: #0e0e16;
    align-items: center;
    padding: 24px;
}

#canvas-iframe {
    border: none;
    display: block;
    background: white;
    width: 100%;
    flex: 1;
    min-height: calc(100vh - 56px);
}

.canvas-wrapper.mobile-mode #canvas-iframe {
    width: 375px;
    border-radius: 24px;
    flex: none;
    min-height: 700px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

/* Canvas placeholder while loading */
.canvas-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ============ RIGHT PANEL ============ */
.right-panel {
    width: var(--right-w);
    background: var(--bg-panel);
    border-left: 1px solid var(--border);
    overflow-y: auto;
    flex-shrink: 0;
}

.right-panel::-webkit-scrollbar {
    width: 4px;
}

.right-panel::-webkit-scrollbar-track {
    background: transparent;
}

.right-panel::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.panel-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    height: 100%;
    min-height: 300px;
    color: var(--text-muted);
    text-align: center;
    padding: 32px;
}

.panel-empty-icon {
    font-size: 2.5rem;
    opacity: 0.5;
}

.panel-empty p {
    font-size: 0.85rem;
    line-height: 1.6;
}

.panel-content {
    padding: 0;
}

.panel-section {
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.panel-section:last-child {
    border-bottom: none;
}

.panel-title {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    color: var(--text-muted);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.panel-label {
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.panel-input {
    width: 100%;
    padding: 9px 12px;
    background: var(--bg-card);
    border: 1.5px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-family: inherit;
    font-size: 0.88rem;
    outline: none;
    transition: border-color 0.2s;
}

.panel-input:focus {
    border-color: var(--accent);
}

.panel-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.panel-row .form-group {
    flex: 1;
}

/* Panel color input */
.color-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.color-row input[type=color] {
    width: 36px;
    height: 36px;
    padding: 2px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    background: var(--bg-card);
    cursor: pointer;
    flex-shrink: 0;
}

.color-row .panel-input {
    flex: 1;
}

/* Panel select */
.panel-select {
    width: 100%;
    padding: 9px 12px;
    background: var(--bg-card);
    border: 1.5px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-family: inherit;
    font-size: 0.88rem;
    outline: none;
    cursor: pointer;
    appearance: none;
}

/* Panel button group */
.btn-group {
    display: flex;
    gap: 4px;
}

.btn-group .tbtn {
    flex: 1;
    height: 32px;
    border: 1.5px solid var(--border);
    border-radius: 6px;
}

.btn-group .tbtn.active {
    background: rgba(79, 155, 255, 0.15);
    border-color: rgba(79, 155, 255, 0.3);
    color: var(--accent);
}

/* Panel action button */
.btn-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 9px 12px;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text);
    transition: all 0.15s;
    margin-bottom: 8px;
}

.btn-panel:hover {
    background: var(--bg-hover);
}

.btn-panel.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.btn-panel.btn-primary:hover {
    opacity: 0.9;
}

.btn-panel.btn-danger {
    color: var(--danger);
    border-color: rgba(245, 87, 108, 0.2);
    background: rgba(245, 87, 108, 0.05);
}

.btn-panel.btn-danger:hover {
    background: rgba(245, 87, 108, 0.12);
}

/* ============ ADD BLOCK MODAL ============ */
.add-block-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.add-block-modal.open {
    opacity: 1;
    pointer-events: all;
}

.add-block-modal .modal-box {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 32px;
    width: 500px;
    max-width: 96vw;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 40px 80px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
}

.add-block-modal.code-editor-modal .modal-box {
    width: 900px;
    height: 85vh;
}

.code-editor-textarea {
    flex: 1;
    width: 100%;
    background: #0b0c10;
    color: #f8f8f2;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    padding: 16px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 13px;
    line-height: 1.5;
    resize: none;
    outline: none;
    margin-bottom: 16px;
    white-space: pre;
    overflow: auto;
    tab-size: 4;
}

.block-library {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-top: 20px;
}

.library-item {
    padding: 16px;
    background: var(--bg-card);
    border: 1.5px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.library-item:hover {
    border-color: var(--accent);
    background: rgba(79, 155, 255, 0.06);
}

.library-item-icon {
    font-size: 1.8rem;
    margin-bottom: 8px;
}

.library-item-name {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
}

.library-item-desc {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ============ TOAST ============ */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    background: #22222f;
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 22px;
    border-radius: 50px;
    font-size: 0.88rem;
    font-weight: 500;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 9999;
    white-space: nowrap;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
}

.toast.success {
    border-color: rgba(52, 199, 89, 0.3);
}

/* ============ SCROLLBAR ============ */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #2a2a3a;
    border-radius: 4px;
}