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

:root {
    --primary: #6366f1;
    --primary-dim: rgba(99,102,241,0.14);
    --bg-main: #0d0f14;
    --bg-side: #13151c;
    --bg-card: #1a1d28;
    --bg-hover: rgba(255,255,255,0.04);
    --text-primary: #f0f2f8;
    --text-secondary: #7c8598;
    --border: #252836;
    --danger: #f43f5e;
    --success: #10b981;
    --warning: #f59e0b;
    --terminal-bg: #090b10;
}

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

body, html {
    margin: 0; padding: 0; height: 100%;
    background: var(--bg-main);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    overflow: hidden;
}

#toast {
    position: fixed; top: 20px; right: 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 11px 18px;
    border-radius: 10px;
    font-size: 13px; font-weight: 500;
    z-index: 9999;
    transform: translateY(-70px);
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1), opacity 0.25s ease;
    pointer-events: none;
    white-space: nowrap;
}
#toast.show { transform: translateY(0); opacity: 1; }

#home-screen {
    display: flex; flex-direction: column;
    height: 100dvh; width: 100vw;
    position: absolute; top: 0; left: 0; z-index: 1000;
    background: var(--bg-main);
}

.home-topbar {
    height: 62px;
    background: var(--bg-side);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center;
    padding: 0 24px; flex-shrink: 0;
}
.home-logo { height: 34px; border-radius: 7px; object-fit: contain; }

.home-body {
    flex: 1; display: flex;
    align-items: center; justify-content: center;
    overflow-y: auto; padding: 36px 20px;
}

.home-center {
    display: flex; flex-direction: column;
    align-items: center; gap: 14px;
    width: 100%; max-width: 430px;
}

.btn-bubble {
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 12px;
    background: var(--primary);
    color: #fff; border: none; cursor: pointer;
    border-radius: 22px; width: 100%;
    padding: 28px 20px;
    font-size: 16px; font-weight: 700;
    font-family: 'Inter', sans-serif;
    transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
    box-shadow: 0 8px 30px rgba(99,102,241,0.3);
}
.btn-bubble svg { width: 38px; height: 38px; }
.btn-bubble:hover { background: #5153cc; transform: translateY(-2px); box-shadow: 0 14px 40px rgba(99,102,241,0.4); }
.btn-bubble:active { transform: translateY(0); }

.home-row-btns { display: flex; gap: 10px; width: 100%; }

.btn-ghost {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 8px; background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-secondary); cursor: pointer;
    border-radius: 14px; padding: 16px 10px;
    font-size: 12px; font-weight: 600;
    font-family: 'Inter', sans-serif;
    transition: border-color 0.2s, color 0.2s, background 0.2s;
}
.btn-ghost svg { width: 20px; height: 20px; }
.btn-ghost:hover { border-color: var(--primary); color: var(--text-primary); background: var(--primary-dim); }

.project-list { width: 100%; margin-top: 6px; display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow-y: auto; }
.project-list-title { font-size: 10px; font-weight: 800; color: var(--text-secondary); letter-spacing: 0.1em; text-transform: uppercase; padding: 0 4px; margin-bottom: 2px; }
.project-item {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 12px; padding: 13px 15px; cursor: pointer;
    display: flex; align-items: center; justify-content: space-between;
    transition: border-color 0.2s, background 0.2s;
    font-size: 14px; font-weight: 500;
}
.project-item:hover { border-color: var(--primary); background: var(--primary-dim); }
.project-item-name { display: flex; align-items: center; gap: 10px; }

#editor-workspace { display: none; height: 100dvh; width: 100vw; flex-direction: row; }

#explorer {
    width: 255px; flex-shrink: 0;
    background: var(--bg-side);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    transition: left 0.3s ease;
}

.mobile-close-btn { display: none; }
.mobile-menu-btn { display: none; }

@media (max-width: 768px) {
    #explorer { position: fixed; left: -255px; height: 100%; z-index: 2000; }
    #explorer.active { left: 0; box-shadow: 20px 0 60px rgba(0,0,0,0.8); }
    .mobile-close-btn { display: flex !important; }
    .mobile-menu-btn { display: flex !important; }
}

.explorer-header { padding: 13px 10px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.explorer-title-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.explorer-label { font-size: 10px; font-weight: 800; color: var(--text-secondary); letter-spacing: 0.1em; }
.explorer-actions { display: flex; gap: 2px; }

.icon-btn {
    background: transparent; border: none;
    color: var(--text-secondary); cursor: pointer;
    border-radius: 7px; padding: 6px;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.15s, color 0.15s;
}
.icon-btn svg { width: 15px; height: 15px; }
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.tree-container { flex: 1; overflow-y: auto; padding: 6px 5px; }

.tree-node {
    display: flex; align-items: center; justify-content: space-between;
    padding: 5px 7px; border-radius: 7px;
    cursor: pointer; margin-bottom: 1px;
    transition: background 0.12s;
    font-size: 13px;
}
.tree-node:hover { background: var(--bg-hover); }
.tree-node.active { background: var(--primary-dim); color: var(--primary); }

.node-label {
    display: flex; align-items: center; gap: 7px;
    flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
    min-width: 0;
}
.node-label span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

.dots-btn {
    opacity: 0; background: transparent; border: none;
    color: var(--text-secondary); cursor: pointer;
    border-radius: 5px; padding: 2px 6px;
    font-size: 13px; line-height: 1;
    transition: opacity 0.12s, background 0.12s;
    flex-shrink: 0;
}
.tree-node:hover .dots-btn { opacity: 1; }
.dots-btn:hover { background: var(--border); color: var(--text-primary); }

.folder-group {
    margin-left: 14px;
    border-left: 1px solid var(--border);
    padding-left: 2px;
    overflow: hidden;
}

.folder-group.collapsing {
    animation: folderClose 0.22s ease forwards;
}
.folder-group.expanding {
    animation: folderOpen 0.22s ease forwards;
}

@keyframes folderOpen {
    from { opacity: 0; max-height: 0; }
    to { opacity: 1; max-height: 600px; }
}
@keyframes folderClose {
    from { opacity: 1; max-height: 600px; }
    to { opacity: 0; max-height: 0; }
}

.dirty-dot { width: 7px; height: 7px; background: var(--warning); border-radius: 50%; flex-shrink: 0; }

#main-content { flex: 1; display: flex; flex-direction: column; min-width: 0; overflow: hidden; }

.top-bar {
    height: 48px; flex-shrink: 0;
    background: var(--bg-side);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center;
    justify-content: space-between; padding: 0 10px 0 6px; gap: 8px;
}
.topbar-left { display: flex; align-items: center; gap: 2px; flex: 1; min-width: 0; overflow: hidden; }
.topbar-right { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

#tabs-bar {
    display: flex; align-items: stretch;
    height: 48px; overflow-x: auto; overflow-y: hidden;
    flex: 1; min-width: 0;
    scrollbar-width: none;
}
#tabs-bar::-webkit-scrollbar { height: 0; }

.editor-tab {
    display: flex; align-items: center; gap: 6px;
    padding: 0 12px 0 10px;
    font-size: 12px; font-weight: 500;
    color: var(--text-secondary); cursor: pointer;
    white-space: nowrap;
    border-right: 1px solid var(--border);
    border-bottom: 2px solid transparent;
    background: transparent;
    transition: color 0.14s, background 0.14s;
    flex-shrink: 0; user-select: none;
}
.editor-tab:hover { color: var(--text-primary); background: var(--bg-hover); }
.editor-tab.active { color: var(--text-primary); border-bottom-color: var(--primary); background: var(--bg-main); }

.tab-close {
    display: flex; align-items: center; justify-content: center;
    width: 15px; height: 15px; border-radius: 4px;
    opacity: 0; transition: opacity 0.14s, background 0.14s;
    color: var(--text-secondary);
}
.editor-tab:hover .tab-close { opacity: 1; }
.tab-close:hover { background: var(--border); color: var(--text-primary); }
.tab-dirty { width: 7px; height: 7px; background: var(--warning); border-radius: 50%; flex-shrink: 0; }

.run-btn {
    display: flex; align-items: center; gap: 6px;
    background: rgba(16,185,129,0.1); border: 1px solid rgba(16,185,129,0.28);
    color: var(--success); border-radius: 8px; cursor: pointer;
    font-family: 'Inter', sans-serif; font-size: 12px; font-weight: 600;
    padding: 6px 13px; transition: background 0.2s, border-color 0.2s;
}
.run-btn svg { width: 12px; height: 12px; }
.run-btn:hover { background: rgba(16,185,129,0.18); border-color: rgba(16,185,129,0.45); }

#editor-area { flex: 1; display: flex; flex-direction: column; min-height: 0; position: relative; overflow: hidden; }

#no-file-screen {
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    height: 100%; width: 100%;
    gap: 14px; color: var(--text-secondary);
    position: absolute; inset: 0; z-index: 2;
    background: var(--bg-main);
}
#no-file-screen svg { width: 60px; height: 60px; opacity: 0.25; }
#no-file-screen p { font-size: 17px; font-weight: 600; margin: 0; opacity: 0.45; }
#no-file-screen.hidden { display: none; }

.no-file-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 6px; }
.no-file-actions button {
    display: flex; align-items: center; gap: 7px;
    background: var(--bg-card); border: 1px solid var(--border);
    color: var(--text-secondary); border-radius: 10px;
    padding: 9px 16px; font-family: 'Inter', sans-serif;
    font-size: 13px; font-weight: 600; cursor: pointer;
    transition: border-color 0.2s, color 0.2s, background 0.2s;
}
.no-file-actions button svg { width: 15px; height: 15px; }
.no-file-actions button:hover { border-color: var(--primary); color: var(--text-primary); background: var(--primary-dim); }

#cm-wrapper { flex: 1; min-height: 0; height: 100%; overflow: hidden; display: flex; flex-direction: column; }
#cm-wrapper .CodeMirror { flex: 1; height: 100%; font-family: 'Fira Code', monospace; font-size: 14px; line-height: 1.65; background: var(--bg-main) !important; }
#cm-wrapper .CodeMirror-scroll { height: 100%; }
#cm-wrapper .CodeMirror-gutters { background: rgba(0,0,0,0.18) !important; border-right: 1px solid var(--border) !important; }
#cm-wrapper .CodeMirror-linenumber { color: var(--text-secondary) !important; font-size: 12px; }
#cm-wrapper .CodeMirror-activeline-background { background: rgba(255,255,255,0.025) !important; }
#cm-wrapper .CodeMirror-cursor { border-left-color: var(--primary) !important; }
#cm-wrapper .CodeMirror-selected { background: rgba(99,102,241,0.18) !important; }

#terminal-panel {
    flex-shrink: 0; height: 210px;
    display: none; flex-direction: column;
    background: var(--terminal-bg);
    border-top: 1px solid var(--border);
}
#terminal-panel.visible { display: flex; }

.terminal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 10px; background: var(--bg-side);
    border-bottom: 1px solid var(--border);
    height: 36px; flex-shrink: 0;
}
.terminal-tabs { display: flex; height: 100%; }
.term-tab {
    background: transparent; border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary); font-family: 'Inter', sans-serif;
    font-size: 12px; font-weight: 600;
    padding: 0 13px; cursor: pointer;
    transition: color 0.14s, border-color 0.14s;
}
.term-tab:hover { color: var(--text-primary); }
.term-tab.active { color: var(--text-primary); border-bottom-color: var(--primary); }
.terminal-actions { display: flex; gap: 2px; }
.terminal-btn {
    background: transparent; border: none; color: var(--text-secondary);
    cursor: pointer; border-radius: 6px; padding: 5px;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.14s, color 0.14s;
}
.terminal-btn svg { width: 13px; height: 13px; }
.terminal-btn:hover { background: var(--border); color: var(--text-primary); }

#console-output {
    flex: 1; overflow-y: auto; padding: 10px 14px;
    font-family: 'Fira Code', monospace;
    font-size: 13px; line-height: 1.6; color: #8da0b8;
}
.console-line { display: flex; align-items: flex-start; gap: 8px; padding: 2px 0; word-break: break-all; font-size: 12.5px; }
.console-err { color: #fc8181; }
.console-warn { color: var(--warning); }
.console-info { color: #63b3ed; }
.console-ok { color: var(--success); }
.console-prefix { color: var(--text-secondary); flex-shrink: 0; font-size: 12px; margin-top: 1px; }

#preview-output { flex: 1; overflow: hidden; display: flex; flex-direction: column; }
#preview-frame { width: 100%; height: 100%; border: none; background: #fff; flex: 1; }

.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.72);
    display: none; align-items: center; justify-content: center;
    z-index: 5000; backdrop-filter: blur(4px);
}
.modal-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 18px; padding: 26px;
    width: 90%; max-width: 350px;
    animation: modalIn 0.22s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes modalIn { from { opacity:0; transform:scale(0.93) translateY(10px); } to { opacity:1; transform:scale(1) translateY(0); } }
.modal-center { text-align: center; }
.modal-card h3 { margin: 0 0 4px; font-size: 17px; }
.modal-card p { color: var(--text-secondary); font-size: 13px; margin: 6px 0 18px; }
.modal-input {
    width: 100%; padding: 10px 13px;
    background: var(--bg-main); border: 1px solid var(--border);
    border-radius: 9px; color: var(--text-primary);
    font-family: 'Inter', sans-serif; font-size: 14px;
    outline: none; margin: 12px 0;
    transition: border-color 0.2s;
}
.modal-input:focus { border-color: var(--primary); }
.modal-footer { display: flex; gap: 8px; margin-top: 4px; }
.btn-confirm {
    flex: 1; padding: 10px;
    background: var(--primary); color: #fff;
    border: none; border-radius: 9px;
    font-family: 'Inter', sans-serif; font-size: 14px; font-weight: 600;
    cursor: pointer; transition: background 0.2s;
}
.btn-confirm:hover { background: #5153cc; }
.btn-confirm.btn-danger { background: var(--danger); }
.btn-confirm.btn-danger:hover { background: #dc2626; }
.btn-cancel {
    flex: 1; padding: 10px; background: transparent;
    color: var(--text-secondary); border: 1px solid var(--border);
    border-radius: 9px; font-family: 'Inter', sans-serif;
    font-size: 14px; font-weight: 600; cursor: pointer;
    transition: background 0.2s, color 0.2s;
}
.btn-cancel:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-danger-outline {
    padding: 10px; background: transparent;
    color: var(--danger); border: 1px solid rgba(244,63,94,0.35);
    border-radius: 9px; font-family: 'Inter', sans-serif;
    font-size: 14px; font-weight: 600; cursor: pointer;
    transition: background 0.2s;
}
.btn-danger-outline:hover { background: rgba(244,63,94,0.1); }

.warn-icon { width: 48px; height: 48px; stroke: var(--danger); margin-bottom: 14px; }
.option-path { word-break: break-all; color: var(--primary); font-size: 12px; font-family: 'Fira Code', monospace; margin: 0 0 14px; }
.options-list { display: flex; flex-direction: column; gap: 7px; }
.btn-option {
    display: flex; align-items: center; gap: 9px;
    background: var(--bg-main); border: 1px solid var(--border);
    color: var(--text-primary); border-radius: 9px;
    padding: 10px 13px; font-family: 'Inter', sans-serif;
    font-size: 13px; font-weight: 500; cursor: pointer;
    transition: background 0.14s, border-color 0.14s;
}
.btn-option svg { width: 15px; height: 15px; flex-shrink: 0; }
.btn-option:hover { background: var(--bg-hover); border-color: var(--primary); }
.btn-option-danger { color: var(--danger); }
.btn-option-danger:hover { border-color: var(--danger); background: rgba(244,63,94,0.07); }

#autocomplete-box {
    position: fixed; z-index: 8000;
    background: #1e2130; border: 1px solid #2e3555;
    border-radius: 10px; box-shadow: 0 8px 32px rgba(0,0,0,0.6);
    min-width: 220px; max-width: 340px;
    max-height: 240px; overflow-y: auto;
    display: none;
    scrollbar-width: thin; scrollbar-color: var(--border) transparent;
    font-family: 'Fira Code', monospace;
    font-size: 13px;
}
#autocomplete-box::-webkit-scrollbar { width: 5px; }
#autocomplete-box::-webkit-scrollbar-track { background: transparent; }
#autocomplete-box::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.ac-item {
    display: flex; align-items: center; gap: 10px;
    padding: 7px 12px; cursor: pointer;
    transition: background 0.1s;
    color: var(--text-primary);
}
.ac-item:first-child { border-radius: 9px 9px 0 0; }
.ac-item:last-child { border-radius: 0 0 9px 9px; }
.ac-item:hover, .ac-item.selected { background: rgba(99,102,241,0.18); }
.ac-item.selected { background: rgba(99,102,241,0.22); }
.ac-icon { width: 22px; height: 22px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.ac-label { color: #b8d4f8; font-weight: 500; }
.ac-hint { color: var(--text-secondary); font-size: 11px; margin-left: auto; white-space: nowrap; padding-left: 8px; }
