/* =============================================================
   ENGINE BASE STRUTURE
   Contains: Layout, Grids, Components, and Responsive Logic
   ============================================================= */

:root {
    /* UI Dimensions */
    --side-panel-width: 280px;
    --bottom-panel-height: 180px;
    --ui-gap: 15px;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;

    /* Fallback Variables (In case no theme class is applied) */
    --bg-main: #000;
    --bg-panel: rgba(10, 10, 10, 0.9);
    --accent-primary: #ffffff;
    --accent-bright: #ffffff;
    --accent-dim: rgba(255, 255, 255, 0.1);
    --border-color: #333;
    --text-main: #eee;
    --text-dim: #666;
    --terminal-output: #fff;
}

/* --- RESET & BASE --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body, html {
    width: 100%;
    height: 100%;
    background: var(--bg-main);
    color: var(--text-main);
    font-family: var(--font-mono);
    overflow: hidden;
    text-transform: uppercase;
    font-size: 14px;
    transition: background 0.4s ease, color 0.4s ease;
}

#engine-canvas {
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    z-index: 1;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

/* --- OVERLAYS --- */
#vignette {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 5;
    background: radial-gradient(circle, transparent 40%, rgba(0,0,0,0.8) 140%);
}

#scanlines {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 11;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.1) 50%);
    background-size: 100% 3px;
    opacity: 0.2;
}

/* --- MAIN INTERFACE GRID --- */
#engine-interface {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: var(--side-panel-width) 1fr var(--side-panel-width);
    grid-template-rows: 1fr var(--bottom-panel-height);
    pointer-events: none;
    padding: var(--ui-gap);
    gap: var(--ui-gap);
}

/* --- SHARED PANEL STYLING --- */
.sidebar, .console-panel, .monitor-panel {
    background: var(--bg-panel);
    border: var(--ui-border-width, 1px) solid var(--border-color); /* Variable thickness */
    pointer-events: auto;
    position: relative;
    backdrop-filter: blur(8px);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);

    /* Use the variable defined in the theme, fallback to the original cut */
    clip-path: var(--ui-clip-path, polygon(0 0, 100% 0, 100% calc(100% - 15px), calc(100% - 15px) 100%, 0 100%));

    /* Apply theme-specific animations */
    animation: var(--panel-animation, none);
}
/* Corner Cut Aesthetic */
.sidebar, .monitor-panel {
    clip-path: polygon(0 0, 100% 0, 100% calc(100% - 15px), calc(100% - 15px) 100%, 0 100%);
}
.sidebar::before, .monitor-panel::before, .console-panel::before {
    display: var(--show-corners, block);
}


/* --- SIDEBAR COMPONENTS --- */
.sidebar {
    grid-row: 1 / 2;
    padding: 20px;
    border-left: 3px solid var(--accent-primary);
    overflow-y: auto;
}

.section-title {
    font-size: 0.7rem;
    color: var(--accent-primary);
    letter-spacing: 2px;
    margin-bottom: 15px;
    font-weight: 800;
    display: flex; align-items: center;
}

.section-title::after {
    content: ""; flex: 1; height: 1px; background: var(--border-color); margin-left: 10px;
}

.metric {
    display: flex; justify-content: space-between;
    font-size: 0.65rem; margin-bottom: 8px;
    padding: 6px 0; border-bottom: 1px solid rgba(255,255,255,0.03);
}

.metric span:last-child {
    color: var(--terminal-output);
    /* Bloom effect removed from here */
}

/* --- PERFORMANCE MONITOR --- */
.monitor-panel {
    grid-column: 3 / 4;
    align-self: start;
    padding: 15px;
}

.monitor-label { font-size: 9px; color: var(--accent-primary); margin-bottom: 8px; }

#fps-graph-canvas {
    width: 100%; height: 60px;
    background: rgba(0,0,0,0.4);
    border: 1px solid var(--border-color);
}

/* --- BOTTOM CONSOLE --- */
.console-panel {
    grid-column: 1 / 4;
    border-top: 2px solid var(--accent-primary);
    display: flex; flex-direction: column;
    overflow: hidden;
}

.console-header {
    background: var(--accent-dim);
    padding: 6px 15px;
    font-size: 10px;
    display: flex; justify-content: space-between;
    color: var(--accent-bright);
}

.log-container {
    padding: 12px; font-size: 10px; color: var(--text-dim);
    overflow-y: auto; flex: 1;
}

.log-line {
    margin-bottom: 4px;
    border-left: 2px solid var(--border-color);
    padding-left: 8px;
}

/* --- BUTTONS & CONTROLS --- */
.ctrl-btn {
    width: 100%;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    color: var(--text-dim);
    padding: 10px;
    margin-bottom: 6px;
    cursor: pointer;
    font-family: var(--font-mono), sans-serif;
    font-size: 9px;
    transition: all 0.2s ease;
    text-align: left;
    outline: none;
}

.ctrl-btn:hover {
    background: var(--accent-dim);
    color: var(--text-main);
    border-color: var(--accent-bright);
}

.ctrl-btn.active {
    background: var(--accent-primary);
    color: var(--bg-main); /* Flips to background color for contrast */
    font-weight: 900;
    box-shadow: 0 0 15px var(--accent-dim);
}

/* --- RESPONSIVE LOGIC --- */
@media (max-width: 1024px) {
    :root { --side-panel-width: 220px; }
    #engine-interface { padding: 10px; gap: 10px; }
}

@media (max-width: 768px) {
    #engine-interface {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
        overflow-y: auto;
        pointer-events: none;
    }
    .sidebar { grid-column: 1 / 2; grid-row: 1 / 2; max-height: 200px;pointer-events: auto; }
    .monitor-panel { display: none; }
    .console-panel { grid-column: 1 / 2; grid-row: 3 / 4; height: 150px;pointer-events: auto; }
}

/* Scrollbar Styling */
::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-thumb { background: var(--accent-primary); }

/* --- UPDATED DROPDOWN UI (UPWARD) --- */
.theme-dropdown-container {
    position: relative;
    margin-top: 10px;
}
.dropdown-menu {
    position: absolute;
    bottom: calc(100% + 5px);
    left: 0;
    width: 100%;

    /* New Scrollable Logic */
    max-height: 200px;         /* Limits the height */
    overflow-y: auto;          /* Enables scrolling when content exceeds max-height */
    overflow-x: hidden;        /* Prevents horizontal twitching */

    /* Aesthetics */
    background: #080808 !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    border: 1px solid var(--border-color);
    display: none;
    flex-direction: column;
    z-index: 1000;
    box-shadow: 0 -15px 30px rgba(0, 0, 0, 0.8);
    border-bottom: 2px solid var(--accent-primary);
}

/* Ensure the scrollbar inside the dropdown matches your UI theme */
.dropdown-menu::-webkit-scrollbar {
    width: 4px; /* Slightly wider for easier grabbing in a small space */
}

.dropdown-menu::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.3);
}

.dropdown-menu::-webkit-scrollbar-thumb {
    background: var(--accent-primary);
    border-radius: 0; /* Keeps the sharp "engine" look */
}
/* Ensure options are also clearly visible */
.theme-opt {
    background: #080808;
    border: none;
    color: var(--text-dim);
    padding: 12px 10px;
    text-align: left;
    font-family: var(--font-mono), sans-serif;
    font-size: 9px;
    cursor: pointer;
    transition: 0.2s;
    text-transform: uppercase;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}



.theme-opt:last-child {
    border-bottom: none;
}

.theme-opt:hover {
    background: var(--accent-dim);
    color: var(--accent-bright); /* Use bright accent on hover for clarity */
}

/* Styling for the trigger when a theme is selected */
#theme-trigger.theme-active {
    border-color: var(--accent-primary);
    background: var(--accent-dim); /* Faint accent background */
    color: var(--text-main);
    box-shadow: inset 0 0 10px var(--accent-dim), 0 0 5px var(--accent-dim);
    transition: all 0.3s ease;
}

/* Optional: Add a small indicator dot or change the [>] color */
#theme-trigger.theme-active span {
    color: var(--accent-bright);
    text-shadow: 0 0 8px var(--accent-bright);
}

/* Highlight the active option in the dropdown */
.theme-opt.active-opt {
    color: var(--accent-primary);
    background: var(--accent-dim);
    border-left: 3px solid var(--accent-primary);
    padding-left: 7px; /* Adjust to compensate for border */
    font-weight: bold;
}