/* =========================================
   1. CORE VARIABLES & RESET.
   ========================================= */
:root {
    --main-color: #33ff00; 
    --bg-color: #050505;   
    --panel-bg: #0a0a0a;   
    --panel-text: #33ff00; 
    --header-bg: #000000;
    --success-color: #ffd700;
    --warning-color: #ff3333; 
    
    /* CRT Variables */
    --glow-strength: 0.6;
    --scanline-opacity: 0.3;
    --blur-amount: 0.5px;
    --flicker-strength: 0.03;
    --jitter-x: 0px;
    --jitter-y: 0px;
    --vignette-opacity: 0.8;
    --aberration-offset: 2px;
    --rolling-bar-opacity: 0;
    --rolling-bar-speed: 8s;
    
    /* Geometry */
    --view-height: 100%; 
    
    /* Typography */
    --cjk-stack: "Noto Sans JP", "Noto Sans SC", "Noto Sans KR", "Microsoft YaHei", "Meiryo", "Malgun Gothic", sans-serif;
    --font-family: 'VT323', monospace; 
    --font-size: 24px;
    --letter-spacing: 1px;
    --line-height: 1.5;
}

* { box-sizing: border-box; font-family: inherit; }

body {
    margin: 0;
    background-color: #000;
    color: var(--main-color);
    font-family: var(--font-family), var(--cjk-stack); 
    overflow: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* =========================================
   2. SCROLLBARS
   ========================================= */
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: var(--bg-color); }
*::-webkit-scrollbar-corner { background: var(--bg-color); }
*::-webkit-scrollbar-thumb { 
    background: var(--main-color); 
    border-radius: 4px;
    opacity: 0.5;
    border: 1px solid var(--bg-color);
}
*::-webkit-scrollbar-thumb:hover { background: #fff; }
* { scrollbar-width: thin; scrollbar-color: var(--main-color) var(--bg-color); }

/* =========================================
   3. INPUTS & CONTROLS
   ========================================= */
input[type=range] {
    -webkit-appearance: none;
    appearance: none; 
    width: 50%;
    background: transparent;
    margin: 5px 0;
}
input[type=range]:focus { outline: none; }

input[type=range]::-webkit-slider-runnable-track {
    width: 100%; height: 4px; cursor: pointer; background: var(--main-color); opacity: 1; border-radius: 2px; border: none;
}
input[type=range]::-moz-range-track {
    width: 100%; height: 4px; cursor: pointer; background: var(--main-color); opacity: 1; border-radius: 2px; border: none;
}
input[type=range]::-webkit-slider-thumb {
    height: 14px; width: 14px; border-radius: 50%; background: var(--main-color); cursor: pointer; -webkit-appearance: none; margin-top: -5px; box-shadow: 0 0 5px var(--main-color);
}
input[type=range]::-moz-range-thumb {
    height: 14px; width: 14px; border: none; border-radius: 50%; background: var(--main-color); cursor: pointer; box-shadow: 0 0 5px var(--main-color);
}

input[type=checkbox] { 
    appearance: none; -webkit-appearance: none;
    width: 16px; height: 16px; border: 1px solid var(--main-color);
    background: transparent; cursor: pointer; position: relative; display: inline-block; vertical-align: middle;
}
input[type=checkbox]:checked { background: var(--main-color); }
input[type=checkbox]:checked::after {
    content: '✔'; position: absolute; top: -2px; left: 1px; color: var(--bg-color); font-size: 12px; font-weight: bold;
}

select, input[type=color], input[type=text] { 
    background: var(--bg-color); border: 1px solid var(--main-color); color: var(--main-color); padding: 4px; font-family: inherit; 
}
select:focus, input:focus { outline: 1px solid var(--main-color); }

/* =========================================
   4. LAYOUT & HEADER
   ========================================= */
header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 0 20px; border-bottom: 1px solid var(--main-color);
    background: var(--header-bg); z-index: 50; user-select: none;
    height: 40px; min-height: 40px; box-shadow: 0 0 10px var(--main-color);
    transition: background 0.3s;
}

#rt-toolbar {
    background: var(--header-bg); 
    border-bottom: 1px solid var(--main-color);
    padding: 5px 10px; 
    display: flex; 
    align-items: center; 
    gap: 8px; 
    flex-wrap: wrap;
    transition: all 0.3s; 
    overflow: hidden; 
    height: auto; 
    min-height: 40px; 
    z-index: 45;
}
#rt-toolbar.toolbar-hidden { display: none; }

.toolbar-group { display: flex; gap: 2px; align-items: center; }
.toolbar-sep { color: var(--main-color); opacity: 0.5; margin: 0 5px; font-family: monospace; }

#rt-toolbar button {
    background: transparent; border: 1px solid transparent; color: var(--main-color);
    cursor: pointer; font-family: 'Courier New', monospace; font-size: 14px;
    padding: 4px 8px; min-width: 25px; border-radius: 2px;
}

#rt-toolbar button:hover { border-color: var(--main-color); background: rgba(255,255,255,0.1); }

.close-panel-btn {
    margin-top: 20px;
    border-color: var(--warning-color); /* Gives it a subtle red border to differentiate from Save/Load */
    color: var(--warning-color);
}


#mobile-menu-btn {
    display: none; 
    background: transparent; border: none; color: var(--main-color);
    font-size: 24px; cursor: pointer; margin-right: 15px; padding: 0;
    line-height: 1;
    position: relative; top: -4px; 
}

.app-title {
    font-family: 'Press Start 2P', var(--cjk-stack);
    font-size: 14px; margin-right: 20px; white-space: nowrap;
    text-shadow: 0 0 5px var(--main-color); color: var(--main-color);
}

.stats-bar {
    display: flex; gap: 15px; font-family: 'Courier New', var(--cjk-stack);
    font-weight: bold; font-size: 14px; align-items: center; flex-grow: 1;
    color: var(--main-color);
}

.stat-input {
    background: transparent; border: 1px solid var(--main-color);
    color: var(--main-color); font-family: inherit; width: 50px;
    padding: 4px; text-align: center; font-weight: bold; font-size: 12px;
}
.stat-input::placeholder { color: var(--main-color); opacity: 0.5; }

#sprint-btn {
    background: transparent; border: 1px solid var(--main-color);
    color: var(--main-color); padding: 4px 8px; cursor: pointer;
    font-family: inherit; text-transform: uppercase; font-weight: bold; font-size: 12px;
}
#sprint-btn:hover { background: var(--main-color); color: var(--bg-color); }
#sprint-btn.active { background: var(--main-color); color: var(--bg-color); animation: pulse 1s infinite; }

.header-btn {
    background: transparent; border: 1px solid #444; color: #888;
    padding: 5px 15px; cursor: pointer; font-family: 'Courier New', var(--cjk-stack);
    font-weight: bold; transition: all 0.2s; margin-left: 5px;
}
.header-btn:hover { color: var(--main-color); border-color: var(--main-color); }
.header-btn.active { background: var(--main-color); color: var(--bg-color); border-color: var(--main-color); }
/* =========================================
   4.1STATUS OVERLAY (The Pop-up)
   ========================================= */
#status-overlay {
    position: fixed;
    top: 60px; /* Sits nicely below the header */
    left: 50%;
    transform: translateX(-50%); /* Centers it perfectly */
    background: var(--main-color);
    color: var(--bg-color);
    padding: 10px 20px;
    font-family: var(--font-family);
    font-weight: bold;
    text-transform: uppercase;
    z-index: 200; /* Stays on top of everything */
    pointer-events: none; /* Click through it */
    opacity: 0;
    transition: opacity 0.3s ease;
    box-shadow: 0 0 15px var(--main-color);
    border: 2px solid var(--bg-color);
}

.header-btn.active, 
.t-games.active {
    background: var(--main-color) !important;
    color: var(--bg-color) !important;
    border-color: var(--main-color) !important;
    box-shadow: 0 0 10px var(--main-color);
}
/* =========================================
   5. SETTINGS PANELS
   ========================================= */
#settings-container {
    position: absolute; /* Revert to absolute so it scrolls if needed */
    top: 40px; /* Matches Header Height exactly */
    right: 0;
    bottom: 60px; 
    width: 340px;
    background: var(--panel-bg); 
    border-left: 1px solid var(--main-color);
    border-top: 1px solid var(--main-color); /* Adds separation from header */
    transform: translateX(100%); 
    transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    z-index: 80; 
    overflow-y: auto; 
    display: flex; 
    flex-direction: column;
    color: var(--panel-text); 
    box-shadow: -5px 0 20px rgba(0,0,0,0.8);
}

.panel h3 {
    font-family: 'Press Start 2P', cursive;
    font-size: 10px;
    margin-top: 30px;
    color: var(--main-color);
    text-transform: uppercase;
    text-align: center;
}



#settings-container.open { transform: translateX(0); }

#left-nav {
    position: absolute; top: 41px; right: 0; bottom: 0; width: 200px;
    background: var(--panel-bg); border-left: 1px solid var(--main-color);
    transform: translateX(100%); transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    z-index: 60; display: none; flex-direction: column; padding: 20px;
}
#left-nav.open { transform: translateX(0); }
#left-nav button {
    background: transparent; border: 1px solid var(--main-color); color: var(--main-color);
    padding: 15px; text-align: left; margin-bottom: 10px; font-family: 'Courier New', monospace;
    text-transform: uppercase; font-weight: bold; cursor: pointer;
}

.panel { display: none; padding: 20px; padding-bottom: 80px; }
.panel.active { display: block; }

.control-group { margin-bottom: 20px; border-bottom: 1px dashed var(--main-color); padding-bottom: 15px; }
.control-group h4 { margin: 0 0 10px 0; font-size: 14px; text-transform: uppercase; text-decoration: underline; font-family: var(--cjk-stack); }
label { display: flex; justify-content: space-between; align-items: center; font-size: 12px; margin-bottom: 8px; opacity: 0.9; }

/* =========================================
   6. CRT SCREEN & EDITOR
   ========================================= */
#screen-wrapper {
    position: relative; width: 100%; height: 100%; overflow: hidden;
    box-shadow: inset 0 0 150px rgba(0,0,0, var(--vignette-opacity)); 
    background-color: var(--bg-color);
    transform: translate(var(--jitter-x), var(--jitter-y)); 
}

#screen-wrapper::before {
    content: " "; display: block; position: absolute; top: 0; left: 0; bottom: 0; right: 0;
    background: radial-gradient(circle, rgba(255,255,255,0.02) 0%, rgba(0,0,0,0.1) 100%);
    pointer-events: none; z-index: 12;
}
#screen-wrapper::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, 1) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06));
    background-size: 100% 4px, 3px 100%; opacity: var(--scanline-opacity);
    pointer-events: none; z-index: 10;
}
#rolling-bar {
    position: absolute; top: 0; left: 0; width: 100%; height: 20%;
    background: linear-gradient(to bottom, transparent, rgba(255,255,255,0.1), transparent);
    opacity: var(--rolling-bar-opacity); animation: roll var(--rolling-bar-speed) linear infinite;
    pointer-events: none; z-index: 15;
}
@keyframes roll { from { top: -20%; } to { top: 120%; } }

#editor {
    /* PAGE DIMENSIONS */
    width: 100%; 
    max-width: none;          
    height: var(--view-height); /* Slider still controls height from the center */
    
    /* ALIGNMENT */
    text-align: justify;       
    
    /* APPEARANCE */
    background: transparent; 
    border: none; 
    outline: none; 
    color: var(--main-color); 
    font-family: var(--font-family), var(--cjk-stack); 
    font-size: var(--font-size); 
    letter-spacing: var(--letter-spacing); 
    line-height: var(--line-height);
    text-shadow: calc(var(--aberration-offset) * -1) 0 rgba(255,0,0,0.5), var(--aberration-offset) 0 rgba(0,0,255,0.5), 0 0 calc(var(--glow-strength) * 10px) var(--main-color);
    
    /* SPACING */
    padding: 0 40px; 
    padding-top: 40px;
    padding-bottom: 20px;
    
    box-sizing: border-box; 
    overflow-y: auto;
    white-space: pre-wrap; 
}
#rhythm-graph {
    height: 60px; 
    display: flex; 
    align-items: flex-end; 
    gap: 2px; /* Increased gap for better definition */
    opacity: 1; /* Ensure full visibility */
    overflow-x: auto; /* Allow scrolling if there are many sentences */
    padding-bottom: 2px;
}

.rhythm-bar {
    background: var(--main-color); 
    width: 6px; /* Slightly wider bars for visibility */
    min-height: 4px; /* Ensure even short sentences are visible */
    flex-shrink: 0;
    transition: height 0.3s ease;
}

/* =========================================
   7. LINTER & BOTTOM BAR
   ========================================= */
.lint-mark {
    text-decoration: underline wavy var(--main-color);
    text-decoration-thickness: 1px;
    text-underline-offset: 4px;
    
    /* FORCE normal weight and transparent background */
    font-weight: 400 !important;
    background-color: transparent !important;
    text-shadow: inherit; /* Ensure it blends with the CRT glow */
    
    display: inline;
}

.lint-mark:hover {
    background-color: rgba(255, 255, 255, 0.1) !important;
    cursor: help;
}
@keyframes flicker { 0% { opacity: 0.99; } 50% { opacity: calc(1 - var(--flicker-strength)); } 100% { opacity: 1; } }

#bottom-bar {
    height: 60px; background: var(--header-bg); position: relative;
    border-top: 1px solid var(--main-color); overflow: hidden; flex-shrink: 0; display: flex; align-items: center;
}
canvas#wave-bar { display: block; width: 100%; height: 100%; opacity: 0.5; }

#init-overlay {
    position: fixed; top:0; left:0; width:100%; height:100%;
    background: rgba(0,0,0,0.9); z-index: 100;
    display: flex; justify-content: center; align-items: center; flex-direction: column;
}
#init-btn { padding: 15px 30px; border: 2px solid var(--main-color); background: transparent; color: var(--main-color); cursor: pointer; text-transform: uppercase; }
#linter-options label {
    justify-content: flex-start; /* Aligns checkbox and text to the left */
    gap: 10px;                   /* Adds consistent space between box and text */
    cursor: pointer;
    text-align: left;
}

#linter-options input[type="checkbox"] {
    margin: 0;                   /* Removes any default browser margins */
    flex-shrink: 0;             /* Prevents the checkbox from squishing */
}
/* =========================================
   10. THE DYNAMIC WORKSPACE (THE FIX)
   ========================================= */

#workspace-flex {
    display: flex;
    width: 100%;
    height: 100%;
    align-items: stretch; /* Stretch to fill height */
    justify-content: flex-start;
    position: relative;
    z-index: 5;
    padding: 0; /* Remove padding to fill screen */
}

/* Updated Game Deck Panel for pop-out side panel behavior */
#game-deck-panel {
    width: 0; 
    height: 100%; 
    background: var(--bg-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.35s cubic-bezier(0.4, 0.0, 0.2, 1), opacity 0.2s;
    opacity: 0;
    flex-shrink: 0;
    z-index: 10;
}

/* Open state: Expands and borders the editor */
#game-deck-panel.panel-open {
    width: 50%; /* Takes up half the screen for full visibility */
    opacity: 1;
    border-right: 2px solid var(--main-color);
}

/* Alignment Logic for swapping sides */
.deck-right { order: 2; border-left: 2px solid var(--main-color) !important; border-right: none !important; }
.deck-left { order: -1; border-right: 2px solid var(--main-color) !important; border-left: none !important; }

/* Fixed Editor Container behavior */
#editor-container {
    flex: 1;
    width: 100%;
    position: relative;
    overflow: hidden;
    filter: blur(var(--blur-amount));
    animation: flicker 0.15s infinite;

    /* LAYOUT ENGINE */
    display: flex;
    flex-direction: column;    
    
    /* CHANGED: This moves the text box to the vertical middle */
    justify-content: center; 
}

.panel-hidden {
    display: none !important;
}

/* CRT Header/Footer for Game Deck */
.deck-header, .deck-footer {
    padding: 8px 15px;
    border-bottom: 1px solid var(--main-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--header-bg);
}
.deck-footer { border-top: 1px solid var(--main-color); border-bottom: none; }
.deck-title { font-family: 'Press Start 2P', monospace; font-size: 10px; }

/* The Game Viewport */
.iframe-container { flex-grow: 1; background: #000; position: relative; }
#game-iframe { width: 100%; height: 100%; border: none; }

/* Button Styles for Deck */
#game-deck-panel button, #game-select {
    background: var(--bg-color); color: var(--main-color); border: 1px solid var(--main-color);
    font-family: 'VT323', monospace; font-size: 14px; cursor: pointer; padding: 2px 8px;
}
#game-deck-panel button:hover { background: var(--main-color); color: var(--bg-color); }

.deck-controls { display: flex; gap: 8px; }

/* =========================================
   8. MOBILE RESPONSIVE FIXES
   ========================================= */
@media (max-width:1200px) {
    /* Stack elements vertically instead of side-by-side */
    #workspace-flex {
        flex-direction: column !important;
    }

    /* Make the game deck take the top half of the screen on mobile */
    #game-deck-panel.panel-open {
        width: 100% !important;
        height: 50vh !important; /* Half viewport height */
        border-right: none !important;
        border-bottom: 2px solid var(--main-color) !important;
    }

    #editor-container {
        width: 100% !important;
        height: 50vh !important;
    }
}
/* =========================================
   10. FINAL WORKSPACE & ALIGNMENT FIXES (REFACTORED)
   ========================================= */

/* --- Main Layout Container --- */
#workspace-flex {
    display: flex;
    flex-direction: row; /* Default: Side-by-Side */
    width: 100vw;
    height: 100%;
    overflow: hidden;
    position: relative;
    z-index: 5;
    /* Smooth transition when switching orientation */
    transition: flex-direction 0.3s ease; 
}

/* Vertical Orientation Toggle (Triggered by JS) */
#workspace-flex.orient-vertical {
    flex-direction: column;
}

/* --- Editor Area --- */
#editor-container {
    flex: 1; /* Automatically fills whatever space is left */
    height: 100%;
    position: relative;
    min-width: 300px; 
    overflow: hidden;
    min-height: 0;
    z-index: 1;
}

/* --- Game Deck Panel --- */
#game-deck-panel {
    background: var(--bg-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 10;
    flex-shrink: 0;
    opacity: 0; /* Fades in */

    /* Transition both Width (Horizontal) and Height (Vertical) */
    transition: 
        width 0.35s cubic-bezier(0.4, 0.0, 0.2, 1),
        height 0.35s cubic-bezier(0.4, 0.0, 0.2, 1),
        opacity 0.2s ease,
        border 0.2s;

    /* Default Closed State */
    width: 0;
    height: 100%;
    border: none;
}

/* --- OPEN STATE: Horizontal (Default) --- */
#game-deck-panel.panel-open {
    width: 40%; /* Game takes 40% width */
    height: 100%;
    opacity: 1;
    /* Border logic handled by directional classes below */
}

/* --- OPEN STATE: Vertical (When T/B Swap is Active) --- */
#workspace-flex.orient-vertical #game-deck-panel {
    /* When vertical, closed state is height: 0, width: 100% */
    width: 100%;
    height: 0;
}

#workspace-flex.orient-vertical #game-deck-panel.panel-open {
    width: 100% !important;
    height: 40% !important; /* Game takes 40% height */
}

/* --- Positioning & Border Logic (The "Swap" Classes) --- */
/* Horizontal Modes */
.deck-left   { order: -1; border-right: 2px solid var(--main-color); border-left: none; border-bottom: none; border-top: none; }
.deck-right  { order: 2;  border-left: 2px solid var(--main-color); border-right: none; border-bottom: none; border-top: none; }

/* Vertical Modes */
.deck-top    { order: -1; border-bottom: 2px solid var(--main-color); border-top: none; border-left: none; border-right: none; }
.deck-bottom { order: 2;  border-top: 2px solid var(--main-color); border-bottom: none; border-left: none; border-right: none; }

/* Utility: Hard Hide */
.panel-hidden { display: none !important; }

/* --- Settings Menu Fixed Position --- */
#settings-container {
    position: fixed;
    top: 41px;
    right: 0;
    bottom: 60px;
    width: 340px;
    z-index: 80;
}

/* =========================================
   MOBILE RESPONSIVENESS (CLEANED)
   ========================================= */
@media (max-width: 1200px) {
    /* Force Vertical Layout regardless of settings */
    #workspace-flex {
        flex-direction: column !important;
    }

    /* Force Game Panel Dimensions */
    #game-deck-panel.panel-open {
        width: 100% !important;
        height: 45vh !important; /* Slightly larger for touch targets */
        border-right: none !important;
        border-left: none !important;
        border-bottom: 2px solid var(--main-color) !important;
        border-top: none !important;
        order: -1 !important; /* Always put game on top on mobile */
    }

    #editor-container {
        width: 100% !important;
        height: auto !important;
        flex: 1;
    }

    /* Ensure Iframe doesn't collapse */
    .iframe-container {
        height: 100%;
        min-height: 200px;
    }
}

/* =========================================
   UI COMPONENTS (INIT, SYSTEM, LOGS)
   ========================================= */

/* Header Buttons Active State */
.header-btn {
    background: transparent !important;
    color: var(--main-color) !important;
    border: 1px solid var(--main-color) !important;
    transition: all 0.2s ease;
}
.header-btn:hover { background: rgba(255, 255, 255, 0.1) !important; }
.header-btn.active, #btn-toggle-games.active {
    background: var(--main-color) !important;
    color: var(--bg-color) !important;
    box-shadow: 0 0 15px var(--main-color);
}

/* Init Overlay */
.init-content-wrapper {
    max-width: 600px; width: 90%; text-align: center;
    display: flex; flex-direction: column; align-items: center; gap: 20px;
}
#init-btn {
    font-family: 'Press Start 2P', monospace; font-size: 18px; padding: 20px 40px;
    border: 2px solid var(--main-color); background: rgba(0,0,0,0.8); color: var(--main-color);
    cursor: pointer; text-transform: uppercase;
    box-shadow: 0 0 10px var(--main-color), inset 0 0 10px var(--main-color); transition: all 0.2s;
}
#init-btn:hover { background: var(--main-color); color: var(--bg-color); box-shadow: 0 0 25px var(--main-color); }
.init-warning { color: var(--main-color); font-size: 14px; opacity: 0.8; max-width: 80%; text-shadow: 0 0 2px var(--main-color); }

/* Changelog */
#changelog-container {
    width: 100%; border: 1px solid var(--main-color); background: rgba(0, 0, 0, 0.5);
    padding: 15px; margin-top: 20px; text-align: left; font-family: 'Courier New', monospace;
}
.log-header { border-bottom: 1px dashed var(--main-color); padding-bottom: 5px; margin-bottom: 10px; font-size: 14px; font-weight: bold; }
.log-entry { font-size: 12px; line-height: 1.4; opacity: 0.9; }
.log-ver { font-weight: bold; margin-right: 10px; } 
.log-date { opacity: 0.7; margin-right: 10px; }

/* System Buttons */
.sys-button-row { display: flex; gap: 10px; }
.sys-button-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sys-button-grid .t-cp-clean { grid-column: span 2; }
.sys-btn {
    width: 100%; padding: 8px; background: transparent; border: 1px solid var(--main-color);
    color: var(--main-color); font-family: 'VT323', monospace; cursor: pointer; text-transform: uppercase;
}
.sys-btn:hover { background: var(--main-color); color: var(--bg-color); }

/* Config IO Areas */
.config-io-area {
    width: 100%; height: 100px; background: #000 !important; border: 1px solid var(--main-color);
    color: var(--main-color); font-family: 'Courier New', monospace; font-size: 10px;
    padding: 8px; margin-bottom: 10px; resize: none; display: block; overflow-y: auto;
}
.config-button-row { display: flex; gap: 8px; }
.config-button-row .sys-btn { flex: 1; font-size: 11px; padding: 6px 0; }



/* =========================================
   GAME DECK FOOTER STYLING
   ========================================= */
.deck-footer {
    padding: 10px;
    border-top: 1px solid var(--main-color);
    background: var(--header-bg);
    display: flex;
    flex-direction: column; /* Stack controls on very small screens */
    gap: 10px;
}

/* Row 1: The Cartridge Select and Load Button */
.cart-controls {
    display: flex;
    width: 100%;
    gap: 5px;
}

#game-select {
    flex-grow: 1; /* Takes up all available width */
    font-family: 'VT323', monospace;
    font-size: 14px;
    cursor: pointer;
}

/* Row 2: The Buttons (Data & Layout) */
.deck-btn-group {
    display: flex;
    justify-content: space-between; /* Spreads buttons across the bottom */
    width: 100%;
    gap: 5px;
}

.deck-btn {
    flex: 1; /* Buttons share equal width */
    background: var(--bg-color);
    color: var(--main-color);
    border: 1px solid var(--main-color);
    font-family: 'VT323', monospace;
    font-size: 13px;
    cursor: pointer;
    text-align: center;
    padding: 4px 0;
}
.deck-btn:hover {
    background: var(--main-color);
    color: var(--bg-color);
}

.deck-sep {
    color: var(--main-color);
    opacity: 0.5;
    padding: 0 5px;
    display: flex;
    align-items: center;
}

#btn-stop-game:hover {
    background: #ff0000 !important; /* Brighter red on hover */
    color: #fff !important;
}

/* =========================================
   RESPONSIVE STEPPED LOGIC
   ========================================= */

/* STEP 1: Remove Title on Medium Screens (< 1000px) */
@media (max-width: 1000px) {
    .app-title {
        display: none; /* Hides "FOCUSED SCRIBE" */
    }
    
    /* Adjust header padding since title is gone */
    header {
        padding: 0 10px;
    }
    #left-nav {
        display: flex !important;
        /* Ensure it sits on top of the game panel */
        z-index: 200; 
        /* Ensure background is solid so it covers content */
        background: var(--bg-color); 
    }
}

/* STEP 2: Mobile/Vertical Stack (< 800px) */
/* Replaces previous 1200px rule */
@media (max-width: 800px) {
    #workspace-flex {
        flex-direction: column !important;
    }

    /* Force Game Panel to top half */
    #workspace-flex.orient-vertical #game-deck-panel.panel-open,
    #game-deck-panel.panel-open {
        width: 100% !important;
        height: 50vh !important;
        border-right: none !important;
        border-bottom: 2px solid var(--main-color) !important;
        order: -1;
    }

    #editor-container {
        width: 100% !important;
        height: auto !important;
        flex: 1;
    }
/* 1. HIDE the L/R Swap Button on Mobile */
    #btn-swap-side {
        display: none !important;
    }

    /* 2. Adjust button group width since one button is gone */
    .deck-btn-group .deck-sep {
        display: none; /* Hide the separator too if it looks weird */
    }

    /* 3. Force Vertical Layout Logic */
    #workspace-flex {
        flex-direction: column !important;
    }

    /* Default: Game on TOP (Order -1) */
    #game-deck-panel.panel-open {
        order: -1; 
        width: 100% !important;
        height: 50vh !important;
        border-right: none !important;
        border-bottom: 2px solid var(--main-color) !important;
    }

    /* Allow Swapping to BOTTOM (Order 2) */
    /* This overrides the default mobile behavior if the user clicks T/B */
    #workspace-flex.orient-vertical #game-deck-panel.deck-bottom {
        order: 2 !important;
        border-top: 2px solid var(--main-color) !important;
        border-bottom: none !important;
    }
}

/* =========================================
   RESPONSIVE HEADER & LAYOUT CONTROL
   ========================================= */

/* Default: Hide Mobile Menu Button on Desktop */
#mobile-menu-btn {
    display: none;
    background: transparent;
    border: 1px solid var(--main-color);
    color: var(--main-color);
    font-size: 20px;
    cursor: pointer;
    padding: 5px 10px;
    margin-right: 15px;
    position: relative; top: -5px; 
}

/* --- STEP 1: TABLET / COMPACT LAPTOP (< 1000px) --- */
@media (max-width: 1000px) {
    /* 1. Hide the Title to save space */
    .app-title {
        display: none;
    }

    /* 2. Hide Desktop Navigation Buttons */
    .tab-buttons {
        display: none !important;
    }

    /* 3. Show Hamburger Menu Button */
    #mobile-menu-btn {
        display: block;
    }

    /* 4. Ensure Header doesn't wrap weirdly */
    header {
        justify-content: flex-start;
        padding: 0 10px;
    }
    
    /* Move stats to the right since buttons are gone */
    .stats-bar {
        margin-left: auto;
        justify-content: flex-end;
    }
}

/* --- STEP 2: MOBILE STACK (< 800px) --- */
@media (max-width: 800px) {
    /* 1. HIDE the L/R Swap Button (User Request) */
    #btn-swap-side {
        display: none !important;
    }
    .deck-sep { display: none !important; }

    /* 2. FORCE Vertical Stack Layout */
    #workspace-flex {
        flex-direction: column !important;
    }

    /* 3. DEFAULT STATE (Horizontal/Left Logic -> Maps to TOP) */
    /* This ensures it starts at the Top when you first load mobile */
    #game-deck-panel.panel-open {
        order: -1 !important; /* Top */
        width: 100% !important;
        height: 50vh !important;
        border-right: none !important;
        border-left: none !important;
        border-bottom: 2px solid var(--main-color) !important;
        border-top: none !important;
    }

    /* 4. SWAPPED STATE (Vertical/Top Logic -> Maps to BOTTOM) */
    /* When user clicks "T/B", JS adds .orient-vertical & .deck-top. */
    /* We map that state to the BOTTOM position for mobile utility. */
    #workspace-flex.orient-vertical #game-deck-panel.panel-open {
        order: 2 !important; /* Bottom */
        border-bottom: none !important;
        border-top: 2px solid var(--main-color) !important;
    }

    #editor-container {
        width: 100% !important;
        height: auto !important;
        flex: 1;
        min-height: 0;
    }
}
    
    /* Fix Footer Buttons on Mobile */
    .deck-footer {
        padding: 5px;
    }
    .deck-btn-group {
        flex-wrap: wrap;
}

/* =========================================
   10. CHANGELOG & ACCESSIBILITY
   ========================================= */

/* A box that only shows a few lines but scrolls with the theme vars */
.changelog-box {
    width: 100%;
    max-height: 100px; /* Limits height to a few lines */
    overflow-y: auto;  /* Enables vertical scrolling */
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--main-color);
    color: var(--panel-text);
    padding: 8px;
    font-family: 'Courier New', monospace;
    font-size: 11px;
    white-space: pre-line; /* Preserves line breaks */
    margin-bottom: 15px;
    scrollbar-width: thin; /* Firefox support */
    scrollbar-color: var(--main-color) var(--bg-color);
}

/* Standard "Screen Reader Only" class */
/* Hides text visually but keeps it readable for AT (Assistive Tech) */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* =========================================
   11. VERSION LOG STYLES (THEME FIX)
   ========================================= */

#changelog-container {
    margin-bottom: 20px;
    border: 1px solid var(--main-color);
    background: var(--panel-bg); /* Matches panel background instead of generic rgba */
}

.log-header {
    background: var(--main-color);
    color: var(--bg-color); /* Creates the "Inverse" look */
    margin: 0;
    padding: 5px 10px;
    font-size: 12px;
    font-family: 'Press Start 2P', monospace;
    text-transform: uppercase;
}

.log-body {
    max-height: 150px;
    overflow-y: auto;
    padding: 10px;
    font-family: 'Courier New', monospace;
    font-size: 11px;
    color: var(--panel-text); /* FORCE theme text color */
    
    /* Scrollbar Logic */
    scrollbar-width: thin;
    scrollbar-color: var(--main-color) var(--panel-bg);
}

.log-entry {
    margin-bottom: 15px;
    /* Use main-color for the divider so it matches the theme (e.g. pink line for pink theme) */
    border-bottom: 1px dashed var(--main-color); 
    opacity: 0.8; /* Slight dim for divider */
    padding-bottom: 10px;
}
.log-entry:last-child { border-bottom: none; }

.log-ver {
    color: var(--success-color); /* Uses the gold/green success variable */
    font-weight: bold;
    margin-right: 10px;
}

.log-ver {
    color: var(--panel-text); /* Matches the menu/panel text color */
    font-weight: bold;
    margin-right: 10px;
}

.log-entry p {
    margin: 4px 0 0 15px;
    color: var(--panel-text); /* Ensure paragraph text matches theme */
    opacity: 0.9;
    line-height: 1.3;
}

/* Custom Scrollbar for Webkit to match theme */
.log-body::-webkit-scrollbar { width: 6px; }
.log-body::-webkit-scrollbar-track { background: var(--panel-bg); }
.log-body::-webkit-scrollbar-thumb { background: var(--main-color); border-radius: 3px; }