:root {
    --bg-color: #050505;
    --terminal-bg: rgba(0, 0, 0, 0.85);
    --neon-green: #0f0;
    --dim-green: #003b00;
    --alert-red: #ff003c;
    --cyan-accent: #00f0ff;
    --text-white: #e0e0e0;
    --text-glow: 0 0 4px rgba(0, 255, 0, 0.4);
    --box-glow: 0 0 10px rgba(0, 255, 0, 0.2);
    --font-stack: 'Courier New', Courier, monospace;
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-white);
    font-family: var(--font-stack);
    line-height: 1.6;
    overflow: hidden;
    height: 100vh;
    
    /* Subtle grid background */
    background-image: 
        linear-gradient(rgba(0, 255, 0, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 255, 0, 0.03) 1px, transparent 1px);
    background-size: 20px 20px;
}

/* CRT Scanline Overlay - VERY SLIGHT */
body::after {
    content: " ";
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.1) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.03), rgba(0, 255, 0, 0.01), rgba(0, 0, 255, 0.03));
    z-index: 9999;
    background-size: 100% 3px, 3px 100%;
    pointer-events: none;
    opacity: 90;
}

/* Selection Styling */
::selection {
    background: var(--neon-green);
    color: #000;
}

/* --- Layout --- */

.container {
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 15px;
    max-width: 100%;
    margin: 0 auto;
    position: relative;
    z-index: 1;
}

.header {
    border-bottom: 1px solid var(--neon-green);
    padding-bottom: 10px;
    margin-bottom: 15px;
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    color: var(--neon-green);
    text-shadow: var(--text-glow);
}

#boot-sequence {
    font-size: 14px;
    opacity: 0.9;
    line-height: 1.2;
}

.main-layout {
    display: flex;
    gap: 20px;
    flex: 1;
    overflow: hidden;
}

/* --- Terminal Section --- */

.terminal-section {
    flex: 2;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
    border: 1px solid var(--dim-green);
    box-shadow: var(--box-glow);
    background: var(--terminal-bg);
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}
::-webkit-scrollbar-track {
    background: #000;
    border-left: 1px solid var(--dim-green);
}
::-webkit-scrollbar-thumb {
    background: var(--dim-green);
    border: 1px solid var(--neon-green);
}
::-webkit-scrollbar-thumb:hover {
    background: var(--neon-green);
    box-shadow: 0 0 10px var(--neon-green);
}

.terminal {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    font-size: 15px;
    color: var(--text-white);
}

#output {
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Output Log Colors */
.output-line { margin: 5px 0; }
.output-error { color: var(--alert-red); text-shadow: 0 0 5px var(--alert-red); }
.output-success { color: var(--cyan-accent); text-shadow: 0 0 5px var(--cyan-accent); }
.output-warning { color: #ffff00; }
.output-command { 
    color: var(--neon-green);
    opacity: 0.9; 
    border-left: 2px solid var(--neon-green); 
    padding-left: 8px; 
    text-shadow: var(--text-glow);
}

/* --- Input Area (Tactical Bar) --- */

.input-area {
    display: flex;
    align-items: flex-start;
    background: #000;
    padding: 10px 15px;
    border-top: 1px solid var(--neon-green);
    gap: 12px;
    flex-shrink: 0;
    /* Ensure the input area handles the height of the CodeMirror instance gracefully */
    min-height: 50px; 
}

.prompt {
    color: var(--cyan-accent);
    font-weight: bold;
    white-space: nowrap;
    text-shadow: 0 0 5px var(--cyan-accent);
    user-select: none;
    padding-top: 4px; /* Visual alignment with code text */
}

/* --- CODEMIRROR INPUT OVERRIDES --- */
/* This targets the wrapper editor.js creates */
.console-input-wrapper {
    flex: 1;
    min-width: 0; /* Flexbox fix */
}

/* Target the actual CodeMirror editor inside the input bar */
.console-input-wrapper .cm-editor {
    background: transparent !important;
    border: none !important;
    color: #fff !important;
    max-height: 9.5em; /* Limit to ~6 lines */
    overflow: hidden !important; /* Hide outer overflow */
}

.console-input-wrapper .cm-scroller {
    overflow-y: auto !important; /* Allow internal scrolling */
    font-family: var(--font-stack) !important;
}

/* HIDE gutter (line numbers) specifically in the input bar */
.console-input-wrapper .cm-gutters {
    display: none !important;
}

/* HIDE the active line background in input for cleaner look */
.console-input-wrapper .cm-activeLine,
.console-input-wrapper .cm-activeLineGutter {
    background: transparent !important;
}

.run-button {
    background: rgba(0, 50, 0, 0.8);
    border: 1px solid var(--neon-green);
    color: var(--neon-green);
    padding: 8px 20px;
    cursor: pointer;
    font-family: var(--font-stack);
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
    transition: all 0.2s ease;
    box-shadow: 0 0 5px rgba(0, 255, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    flex-shrink: 0;
    text-shadow: var(--text-glow);
    margin-top: 0; 
}

.run-button:hover {
    background: var(--neon-green);
    color: #000;
    box-shadow: 0 0 15px var(--neon-green);
    text-shadow: none;
}

.run-button:active {
    transform: translateY(1px);
}

.help-bar {
    padding: 5px 10px;
    font-size: 0.75em;
    opacity: 0.6;
    background: #020202;
    border-top: 1px dashed var(--dim-green);
    display: flex;
    gap: 15px;
    color: var(--neon-green);
}

/* --- Editors Section --- */

.editors-section {
    flex: 1.2;
    display: flex;
    flex-direction: column;
    gap: 15px;
    min-width: 0;
    transition: all 0.3s ease;
}

.editors-section.collapsed {
    display: none !important;
}

.editor-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--neon-green);
    background: rgba(0, 15, 0, 0.9);
    position: relative;
    overflow: hidden;
}

/* Decorative corner clips */
.editor-container::before {
    content: "";
    position: absolute;
    top: 0; right: 0;
    width: 0; height: 0;
    border-style: solid;
    border-width: 0 20px 20px 0;
    border-color: transparent var(--neon-green) transparent transparent;
    z-index: 2;
}

.editor-header {
    background: rgba(0, 50, 0, 0.6);
    color: var(--neon-green);
    padding: 8px 15px;
    font-size: 0.9em;
    border-bottom: 1px solid var(--neon-green);
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-shadow: var(--text-glow);
    flex-shrink: 0; /* Prevent header from squashing */
}

/* Styling CodeMirror in Side Panels (Keep Default behaviors here) */
.editor-container .cm-editor {
    /* FIX: Changed from height: 100% to flex: 1 */
    height: auto !important; 
    flex: 1;
    min-height: 0; /* Allows flex child to shrink below content size so scroll works */
}

.code-editor {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-white);
    font-family: var(--font-stack);
    font-size: 0.95em;
    padding: 15px;
    resize: none;
    outline: none;
    line-height: 1.4;
}

.code-editor::placeholder {
    color: rgba(0, 255, 0, 0.3);
    font-style: italic;
}

.editor-button {
    background: transparent;
    border: none;
    border-top: 1px solid var(--neon-green);
    color: var(--neon-green);
    padding: 10px;
    cursor: pointer;
    font-family: var(--font-stack);
    text-transform: uppercase;
    font-size: 0.8em;
    transition: background 0.2s;
    text-shadow: var(--text-glow);
    flex-shrink: 0; /* FIX: Prevent button from disappearing */
}

.editor-button:hover {
    background: rgba(0, 255, 0, 0.2);
}

/* --- Floating Windows & Overlays --- */

.restore-panel-btn {
    position: absolute;
    top: 50px;
    right: 0;
    background: #000;
    border: 1px solid var(--neon-green);
    border-right: none;
    color: var(--neon-green);
    padding: 10px 15px;
    cursor: pointer;
    font-family: var(--font-stack);
    z-index: 100;
    box-shadow: -2px 0 10px rgba(0, 255, 0, 0.2);
    font-weight: bold;
}

.frontend-window {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    min-width: auto;
    min-height: auto;
    background: #000;
    border: 2px solid var(--neon-green);
    box-shadow: 0 0 30px rgba(0, 255, 0, 0.2);
    z-index: 10000;
    display: flex;
    flex-direction: column;
}

.window-titlebar {
    background: var(--neon-green);
    color: #000;
    padding: 8px 12px;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: move;
}

.window-close {
    background: #000;
    border: 1px solid #000;
    color: var(--neon-green);
    width: 20px;
    height: 20px;
    cursor: pointer;
    font-weight: bold;
    line-height: 18px;
}

.window-close:hover {
    background: var(--alert-red);
    color: #fff;
    border-color: var(--alert-red);
}

/* Help Button */
.help-button {
    position: fixed;
    top: 10px;
    right: 20px;
    width: 30px;
    height: 30px;
    border: 1px solid var(--neon-green);
    color: var(--neon-green);
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    border-radius: 50%;
    transition: all 0.3s;
    z-index: 9000;
    background: #000;
}

.help-button:hover {
    box-shadow: 0 0 15px var(--neon-green);
    transform: rotate(90deg);
}

/* --- Animations --- */

@keyframes flicker {
    0% { opacity: 0.97; }
    50% { opacity: 0.95; }
    100% { opacity: 0.98; }
}

@keyframes blink {
    0%, 49% { opacity: 1; }
    50%, 100% { opacity: 0; }
}

.cursor {
    display: inline-block;
    width: 10px;
    height: 1em;
    background: var(--neon-green);
    animation: blink 1s infinite;
    vertical-align: text-bottom;
}

/* --- Preloader --- */
#reveal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100vh;
    background: #000;
    z-index: 99998;
    transition: opacity 0.3s ease;
}
body.revealed #reveal-overlay { opacity: 0; pointer-events: none; }

#preloader {
    position: fixed;
    inset: 0;
    background: #000;
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
}
#preloader-text {
    color: var(--neon-green);
    font-size: 10px;
    white-space: pre;
    text-shadow: var(--text-glow);
}
#preloader.fade-out { opacity: 0; visibility: hidden; }

#reveal-block {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 120px;
    background: #000;
    z-index: 99999;
    border-top: 2px solid var(--neon-green);
    box-shadow: 0 -5px 20px var(--neon-green);
}

/* Hide Mobile Logic for Desktop View */
.mobile-only { display: none; }
.desktop-only { display: inline; }

/* Collapse Logic */
.panel-toggle-btn {
    background: none;
    border: 1px solid transparent;
    color: var(--neon-green);
    cursor: pointer;
    font-size: 24px;
    font-weight: bold;
    line-height: 1;
    padding: 0 5px;
}
.panel-toggle-btn:hover {
    text-shadow: 0 0 8px var(--neon-green);
    transform: scale(1.1);
}