:root {
    --bg-base: #f3f0ea; 
    --bg-panel: #ffffff; 
    --border: #e0dcd5;
    --text-main: #333333;
    --text-muted: #777777;
    --text-accent: #d9534f; 
    --btn-bg: #f8f9fa;
    --btn-hover: #e2e6ea;
    --btn-run: #212529; 
    --btn-run-hover: #000000;
    --font-ui: 'Segoe UI', system-ui, sans-serif;
    --font-code: 'Consolas', 'Fira Code', monospace;
    --hl-line-bg: rgba(217, 83, 79, 0.1);
    --hl-line-border: #d9534f;
    --block-bg: #e9ecef;
    --block-text: #212529;
    --shadow-card: 0 2px 8px rgba(0,0,0,0.05);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { background-color: var(--bg-base); color: var(--text-main); font-family: var(--font-ui); height: 100vh; display: flex; flex-direction: column; overflow: hidden; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cccccc; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #aaaaaa; }

/* --- HEADER & CONTROLS --- */
.header { display: flex; justify-content: space-between; align-items: center; padding: 12px 24px; background-color: var(--bg-panel); border-bottom: 1px solid var(--border); box-shadow: 0 1px 3px rgba(0,0,0,0.02); z-index: 10;}
.logo { font-size: 18px; font-weight: bold; color: var(--text-main); display: flex; align-items: center; gap: 8px; letter-spacing: -0.5px; }
.logo span { color: var(--text-accent); font-family: var(--font-code); }

.controls { display: flex; align-items: center; gap: 10px; }
.controls button, .controls select { background: var(--bg-panel); color: var(--text-main); border: 1px solid var(--border); padding: 8px 14px; border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 6px; transition: 0.2s; outline: none; box-shadow: 0 1px 2px rgba(0,0,0,0.02);}
.controls button:hover, .controls select:hover { background: var(--btn-hover); }
.controls button:disabled { opacity: 0.5; cursor: not-allowed; }
.controls .btn-run { background: var(--btn-run); color: white; border: none; }
.controls .btn-run:hover:not(:disabled) { background: var(--btn-run-hover); }



#loader { font-size: 13px; color: var(--text-muted); display: none; margin-right: 10px; font-weight: 600; }
.spinning { display: inline-block; animation: spin 1s linear infinite; }
@keyframes spin { 100% { transform: rotate(360deg); } }

/* --- MAIN LAYOUT --- */
.workspace { display: flex; flex: 1; overflow: hidden; padding: 20px; gap: 20px; max-width: 1400px; margin: 0 auto; width: 100%; }
.pane { background: var(--bg-panel); border: 1px solid var(--border); border-radius: 10px; display: flex; flex-direction: column; overflow: hidden; box-shadow: var(--shadow-card); }
.pane-left { flex: 5; display: flex; flex-direction: column; gap: 20px; background: transparent; border: none; }
.pane-right { flex: 4; }

.pane-header { padding: 12px 16px; font-size: 13px; font-weight: 700; color: var(--text-main); border-bottom: 1px solid var(--border); background: var(--bg-panel); letter-spacing: 0.2px; display: flex; align-items: center; gap: 8px; }

/* --- EDITOR --- */
.editor-container { flex: 2; display: flex; position: relative; background: var(--bg-panel); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; box-shadow: var(--shadow-card);}
.line-numbers { padding: 15px 10px; background: #fdfdfd; color: #adb5bd; text-align: right; font-family: var(--font-code); font-size: 14px; line-height: 24px; user-select: none; border-right: 1px solid var(--border); min-width: 45px; overflow-y: hidden; }
.textarea-wrapper { flex: 1; position: relative; overflow: hidden; background: transparent; }
#highlightLayer { position: absolute; top: 0; left: 0; width: 100%; height: 100%; padding: 15px 10px; margin: 0; border: none; background: transparent; font-family: var(--font-code); font-size: 14px; line-height: 24px; white-space: pre; overflow: hidden; pointer-events: none; z-index: 0; }
#highlightLayer code { font-family: var(--font-code); text-shadow: none !important; }
textarea#codeInput { position: absolute; top: 0; left: 0; width: 100%; height: 100%; padding: 15px 10px; border: none; background: transparent; color: transparent; caret-color: var(--text-main); font-family: var(--font-code); font-size: 14px; line-height: 24px; resize: none; outline: none; white-space: pre; overflow: auto; z-index: 2; }
textarea#codeInput::selection { background: rgba(0, 123, 255, 0.2); color: transparent; }
.prev-line { position: absolute; left: 0; right: 0; height: 24px; background: rgba(35, 134, 54, 0.1); border-left: 3px solid #238636; pointer-events: none; display: none; z-index: 1; transition: top 0.1s ease; }
.prev-line::before { content: ""; color: #238636; position: absolute; left: 6px; top: 2px; font-size: 10px; font-weight: bold; }

.active-line { position: absolute; left: 0; right: 0; height: 24px; background: var(--hl-line-bg); border-left: 3px solid var(--hl-line-border); pointer-events: none; display: none; z-index: 1; transition: top 0.1s ease; }
.active-line::before { content: ""; color: var(--hl-line-border); position: absolute; left: 6px; top: 2px; font-size: 10px; }

.error-line { position: absolute; left: 0; right: 0; height: 24px; background: rgba(220, 53, 69, 0.15); border-left: 3px solid #dc3545; pointer-events: none; display: none; z-index: 1; transition: top 0.1s ease; }
.error-line::before { content: ""; color: #dc3545; position: absolute; left: 4px; top: 2px; font-size: 12px; }
/* --- I/O AREA --- */
.io-wrapper { flex: 1; display: flex; gap: 20px; min-height: 200px; }
.io-pane { flex: 1; background: var(--bg-panel); border: 1px solid var(--border); border-radius: 10px; display: flex; flex-direction: column; box-shadow: var(--shadow-card); overflow: hidden; }
.io-content { flex: 1; padding: 12px 16px; font-family: var(--font-code); font-size: 13px; color: var(--text-main); background: #fafafa; border: none; outline: none; resize: none; overflow-y: auto; white-space: pre-wrap; }
textarea.io-content::placeholder { color: #adb5bd; font-style: italic; }
.text-err { color: #dc3545; font-weight: bold;}
.text-sys { color: #0d6efd; font-style: italic;}

/* --- CALL STACK & VISUALIZER (NEW CSS) --- */
.visualizer-area { flex: 1; padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; background: #fafafa; }

.memory-frame { background: #ffffff; border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px; box-shadow: 0 2px 5px rgba(0,0,0,0.03); display: flex; flex-direction: column; gap: 10px; }
.frame-header { font-size: 13px; font-weight: 700; color: var(--text-accent); padding-bottom: 8px; border-bottom: 2px solid var(--hl-line-bg); display: flex; align-items: center; gap: 6px; }
.frame-header.global { color: #0056b3; border-bottom-color: rgba(0, 86, 179, 0.1); }
.frame-header span { font-family: var(--font-code); background: rgba(0,0,0,0.04); padding: 2px 6px; border-radius: 4px; }

.var-row { display: flex; align-items: flex-start; gap: 12px; padding-bottom: 8px; border-bottom: 1px dashed var(--border); font-family: var(--font-code); }
.var-row:last-child { border-bottom: none; padding-bottom: 0; }
.var-name { width: 90px; text-align: right; font-weight: bold; color: #0056b3; padding-top: 6px; word-break: break-all; }
.var-eq { color: var(--text-muted); padding-top: 6px; font-weight: bold; }
.var-values { flex: 1; display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }

.var-block { background: var(--block-bg); color: var(--block-text); padding: 6px 12px; border-radius: 6px; font-size: 14px; border: 1px solid #ced4da; box-shadow: 0 1px 2px rgba(0,0,0,0.05); min-width: 30px; text-align: center; }
.var-symbol { color: var(--text-muted); font-size: 18px; font-weight: bold; }
.var-obj-box { background: #ffffff; border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; min-width: 150px; display: flex; flex-direction: column; gap: 6px; box-shadow: 0 2px 4px rgba(0,0,0,0.02); }
.var-obj-header { font-size: 11px; color: var(--text-muted); text-transform: uppercase; border-bottom: 1px dashed var(--border); padding-bottom: 6px; font-weight: bold; }
.var-obj-row { font-size: 13px; display: flex; gap: 8px; }
.var-obj-key { color: #0056b3; font-weight: 600; }

/* --- MODAL --- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.3); display: none; z-index: 999; backdrop-filter: blur(1px); }
.modal { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: var(--bg-panel); border: 1px solid var(--border); border-radius: 12px; width: 350px; z-index: 1000; box-shadow: 0 10px 40px rgba(0,0,0,0.15); display: none; overflow: hidden; }
.modal-header { padding: 15px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; font-weight: bold; background: #f8f9fa;}
.modal-header button { background: transparent; border: none; font-size: 18px; cursor: pointer; }
.modal-body { padding: 15px 20px; max-height: 300px; overflow-y: auto; }
.var-toggle-item { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid #f1f1f1; font-family: var(--font-code); font-size: 14px; }
.var-toggle-item:last-child { border: none; }
input[type="checkbox"] { accent-color: var(--text-accent); width: 16px; height: 16px; cursor: pointer; }

/* --- CSS CHO CÁC NÚT BẬT TẮT --- */
.hide-line { display: none !important; }
.btn-toggle-vis { background: #e0f7fa !important; color: #00838f !important; border-color: #b2ebf2 !important; }
.line-toggles { display: flex; flex-direction: column; gap: 4px; }
.btn-line { padding: 2px 8px !important; font-size: 10px !important; border-radius: 4px !important; height: 18px; line-height: 12px; }
.btn-line-red { background: rgba(217, 83, 79, 0.1) !important; color: #d9534f !important; border-color: #d9534f !important; }
.btn-line-green { background: rgba(35, 134, 54, 0.1) !important; color: #238636 !important; border-color: #238636 !important; }
.btn-line.disabled { opacity: 0.4; text-decoration: line-through; border-style: dashed !important;}

/* MA THUẬT: DI CHUYỂN I/O SANG PHẢI KHI TẮT VISUALIZER */
.workspace.hide-vis .pane-left { flex-direction: row; }
.workspace.hide-vis .editor-container { flex: 5; }
.workspace.hide-vis .io-wrapper { flex: 4; flex-direction: column; }

/* --- IDE FEATURES --- */
.search-box { position: absolute; top: 10px; right: 20px; background: var(--bg-panel); border: 1px solid var(--border); box-shadow: 0 4px 12px rgba(0,0,0,0.15); padding: 6px 10px; border-radius: 6px; display: none; align-items: center; gap: 8px; z-index: 100; font-size: 13px; }
.search-box input { border: 1px solid var(--border); border-radius: 4px; padding: 4px 8px; outline: none; font-family: var(--font-ui); font-size: 13px; width: 150px; }
.search-box button { background: var(--btn-bg); border: 1px solid var(--border); cursor: pointer; padding: 4px 8px; border-radius: 4px; transition: 0.2s; font-size: 12px;}
.search-box button:hover { background: var(--btn-hover); }
mark.search-match { background: rgba(255, 235, 59, 0.4); color: inherit; border-radius: 2px; }

.autocomplete-list { position: absolute; background: #252526; color: #d4d4d4; border: 1px solid #454545; box-shadow: 0 4px 12px rgba(0,0,0,0.5); border-radius: 4px; list-style: none; padding: 4px 0; margin: 0; z-index: 100; display: none; max-height: 200px; overflow-y: auto; min-width: 250px; font-family: var(--font-code); font-size: 13px; }
.autocomplete-list li { padding: 4px 12px; cursor: pointer; display: flex; align-items: center; gap: 8px; border-left: 2px solid transparent;}
.autocomplete-list li.active, .autocomplete-list li:hover { background: #04395e; color: #ffffff; border-left-color: #007acc; }
.suggest-icon { display: inline-block; width: 16px; height: 16px; line-height: 16px; text-align: center; font-size: 11px; font-weight: bold; border-radius: 3px; font-family: sans-serif; }
.icon-keyword { background: #b057b5; color: white; } 
.icon-variable { background: #007acc; color: white; } 
.suggest-text { flex: 1; }
.suggest-match { color: #569cd6; font-weight: bold; }

/* --- METRICS BAR --- */
.metrics-bar {
    display: flex; gap: 20px; padding: 8px 24px; background: #fdfdfd; 
    border-bottom: 1px solid var(--border); font-size: 13px; color: var(--text-muted);
    justify-content: flex-end;
}
.metrics-bar span { display: flex; align-items: center; gap: 5px; }
.metrics-value { font-weight: bold; color: var(--text-main); font-family: var(--font-code); }

/* --- ANIMATIONS CHO BIẾN --- */
@keyframes popNew {
    0% { opacity: 0; transform: translateY(10px) scale(0.8); }
    70% { transform: translateY(-2px) scale(1.05); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes highlightUpdate {
    0% { transform: scale(1); background-color: var(--block-bg); box-shadow: 0 0 0 rgba(255, 193, 7, 0); }
    30% { transform: scale(1.15); background-color: #fff3cd; border-color: #ffe69c; color: #664d03; box-shadow: 0 4px 12px rgba(255, 193, 7, 0.4); }
    100% { transform: scale(1); background-color: var(--block-bg); box-shadow: 0 0 0 rgba(255, 193, 7, 0); }
}

.var-new { animation: popNew 0.5s ease-out forwards; }

.var-updated .var-block, .var-updated .var-obj-box { 
    animation: highlightUpdate 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards; 
}
.var-updated .var-name {
    color: #d9534f; 
    transition: color 0.3s;
}

.btn-report {
    background: rgba(217, 83, 79, 0.1);
    color: var(--text-accent);
    border: 1px solid var(--text-accent); 
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    text-decoration: none;
    transition: 0.2s;
}

.btn-report:hover {
    background: var(--text-accent);
    color: #ffffff;
}

footer {
    background-color: var(--bg-panel); 
    border-top: 1px solid var(--border); 
    padding: 12px 24px;
    font-size: 13px;
    color: var(--text-muted);
    flex-shrink: 0; 
    z-index: 10;
}

.footer-content {
    display: flex;
    justify-content: space-between; 
    align-items: center;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
    font-weight: 500;
}

.footer-content span:last-child {
    color: var(--text-main);
}

/* --- BỔ SUNG CSS CHO DI ĐỘNG (MOBILE RESPONSIVE) --- */
@media screen and (max-width: 768px) {
    body {
        height: auto;
        overflow: auto; 
    }

    .header {
        flex-direction: column;
        gap: 12px;
        padding: 12px;
    }

    .controls {
        flex-wrap: wrap;
        justify-content: center;
        width: 100%;
    }

    .controls button, .controls select {
        flex: 1 1 calc(33% - 10px);
        justify-content: center;
        padding: 8px 5px;
    }

    .workspace {
        display: flex;
        flex-direction: column;
        padding: 10px;
        height: auto;
        overflow: visible;
    }

    .pane-right {
        order: 1;
        flex: none;
        width: 100%;
        min-height: 400px;
    }

    .pane-left {
        order: 2;
        flex: none;
        width: 100%;
        display: flex;
        flex-direction: column;
    }

    .editor-container {
        min-height: 350px; 
    }

    .io-wrapper {
        flex-direction: column;
        min-height: auto;
    }

    .io-pane {
        min-height: 150px;
    }

    .workspace.hide-vis .pane-left {
        flex-direction: column; 
    }
    .workspace.hide-vis .io-wrapper {
        flex-direction: column;
    }

    .modal {
        width: 90%;
        max-width: 350px;
    }

    .search-box {
        top: 40px; 
        right: 10px;
        left: 10px;
        justify-content: space-between;
    }

    .search-box input {
        flex: 1;
        width: auto;
    }

    .footer-content {
        flex-direction: column; 
        gap: 8px;
        text-align: center;
        justify-content: center;
    }
}