:root {
    /* System Colors */
    --sys-bg: #ece9d8;
    --sys-text: #000000;
    --panel-header-bg: #d4d0c8;

    /* Grid Dimensions */
    --left-col-width: 190px;
    --right-col-width: 200px;
    --bottom-row-height: 160px;
    
    /* Minimized Sizes */
    --mini-width: 32px;
    --mini-height: 28px;

    /* Borders */
    --border-light: #ffffff;
    --border-shadow: #aca899;
    --border-dark: #404040;

    /* Accents */
    --num-badge-bg-1: #e8a2a2; --num-badge-text-1: #8b0000;
    --num-badge-bg-2: #a2a2e8; --num-badge-text-2: #00008b;
    --num-badge-bg-3: #e8d8a2; --num-badge-text-3: #8b6508;
    --num-badge-bg-4: #d8a2e8; --num-badge-text-4: #4b0082;
    --num-badge-bg-5: #a2e8a2; --num-badge-text-5: #006400;

    --font-ui: "Segoe UI", "Tahoma", sans-serif;
    --font-data: "Consolas", "Courier New", monospace;
}

* { box-sizing: border-box; }

body {
    margin: 0; padding: 0;
    background-color: var(--sys-bg);
    color: var(--sys-text);
    font-family: var(--font-ui);
    font-size: 11px;
    height: 100dvh;
    overflow: hidden; 
    user-select: none;
}

.interface-container {
    display: flex; flex-direction: column;
    height: 100%; padding: 4px;
}

/* --- HEADER --- */
.top-bar {
    display: flex; justify-content: space-between; align-items: center;
    padding: 4px 8px;
    background: linear-gradient(to bottom, #fff 0%, #ece9d8 100%);
    border-bottom: 1px solid var(--border-shadow);
    margin-bottom: 4px;
    height: 36px; flex-shrink: 0;
}

.brand-section h1 {
    margin: 0; font-size: 16px; font-weight: 900;
    color: #333; text-transform: uppercase; letter-spacing: 0.5px;
    display: inline-block;
}

.version {
    font-family: var(--font-data); color: #666;
    margin-left: 10px; padding-left: 10px; border-left: 1px solid #999;
}

.top-indicators {
    display: flex; gap: 12px; font-size: 10px; font-weight: bold;
    color: #555; align-items: center;
}

.led {
    display: inline-block; width: 8px; height: 8px;
    border-radius: 50%; background: #555; margin-right: 4px;
    border: 1px solid #888; box-shadow: inset 1px 1px 1px rgba(0,0,0,0.5);
}
.led.on { background: #00ff00; box-shadow: 0 0 4px #0f0; }

/* --- GRID SYSTEM --- */
.main-grid {
    display: grid;
    grid-template-columns: var(--left-col-width) 1fr var(--right-col-width);
    grid-template-rows: 1fr var(--bottom-row-height);
    gap: 4px;
    flex-grow: 1;
    overflow: hidden;
    padding-bottom: 2px;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

/* --- PANELS --- */
.panel {
    background: var(--sys-bg);
    border: 2px solid;
    border-color: var(--border-light) var(--border-shadow) var(--border-shadow) var(--border-light);
    display: flex; flex-direction: column;
    overflow: hidden;
}

.panel-header {
    background: linear-gradient(to right, #e0e0e0, #d0d0c0);
    padding: 2px 4px;
    border-bottom: 1px solid var(--border-shadow);
    font-weight: bold;
    display: flex; align-items: center;
    color: #333;
    height: 24px;
    white-space: nowrap;
    overflow: hidden;
    cursor: default;
    flex-shrink: 0;
}

.panel-num {
    display: inline-block; width: 18px; text-align: center;
    margin-right: 6px; font-family: var(--font-data);
    border: 2px outset var(--border-light);
    font-weight: bold; font-size: 10px; line-height: 14px;
    flex-shrink: 0;
    cursor: pointer;
    transition: transform 0.1s;
}

.panel-num:hover { filter: brightness(1.1); border-color: #fff; }
.panel-num:active { border-style: inset; transform: translateY(1px); }

#panel-1 .panel-num { background: var(--num-badge-bg-1); color: var(--num-badge-text-1); }
#panel-2 .panel-num { background: var(--num-badge-bg-2); color: var(--num-badge-text-2); }
#panel-3 .panel-num { background: var(--num-badge-bg-3); color: var(--num-badge-text-3); }
#panel-4 .panel-num { background: var(--num-badge-bg-4); color: var(--num-badge-text-4); }
#panel-5 .panel-num { background: var(--num-badge-bg-5); color: var(--num-badge-text-5); }

.panel-title-text {
    flex-grow: 1; overflow: hidden; text-overflow: ellipsis;
}

.panel-content {
    padding: 8px; overflow-y: auto; flex-grow: 1;
    position: relative; scrollbar-width: none;
}
.panel-content.no-padding { padding: 0; background: #808080; }

/* --- MINIMIZED --- */
.panel.minimized .panel-content { display: none; }
.panel.minimized .panel-title-text { display: none; }
.panel.minimized .panel-header { padding: 0; justify-content: center; }
.panel.minimized .panel-num { margin: 0; }
.panel.minimized .panel-controls { display: none; }
#panel-3.minimized .logo-wrapper { display: none; }
.completely-hidden { display: none !important; }

/* --- GRID ASSIGNMENTS --- */
#panel-1 { grid-column: 1; grid-row: 1; } 
#panel-3 { grid-column: 1; grid-row: 2; } 
#panel-2 { grid-column: 2 / 4; grid-row: 1; } 
#panel-4 { grid-column: 2; grid-row: 2; } 
#panel-5 { grid-column: 3; grid-row: 2; } 

iframe#main-frame {
    width: 100%; height: 100%; border: none; background: #fff; display: block;
}

fieldset { border: 1px solid var(--border-shadow); padding: 6px; margin: 0 0 10px 0; border-radius: 2px; }
legend { color: #000080; padding: 0 4px; }
.radio-group label { display: block; padding: 3px 0; cursor: pointer; border: 1px solid transparent; }
.radio-group label:hover { background-color: #e0e0ff; border-color: #d0d0ff; }
.radio-group input { margin-right: 6px; }

button {
    background: var(--sys-bg); border: 2px outset var(--sys-bg);
    color: black; padding: 2px 8px; font-family: var(--font-ui);
    font-size: 11px; cursor: pointer; margin-right: 4px;
}
button:active { border-style: inset; }
button.btn-xs { font-size: 9px; padding: 0 4px; margin-left: auto; }
button.btn-link { display: block; width: 100%; text-align: left; margin-bottom: 4px; text-decoration: none; color: black; }

textarea#console-output {
    width: 100%; height: 100%; background: #fff; border: none;
    font-family: var(--font-data); font-size: 10px; resize: none;
    padding: 4px; color: #000; outline: none; border-top: 1px solid #888;
}

.status-strip {
    border-top: 1px solid var(--border-light); padding: 2px;
    display: flex; background: var(--sys-bg); gap: 2px; height: 24px; flex-shrink: 0;
    align-items: center;
}
.status-strip .field {
    border: 2px inset var(--sys-bg); padding: 0 6px; font-size: 11px;
    line-height: 18px; background: var(--sys-bg); white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
    flex-shrink: 0; /* Prevent shrinking */
}

.btn-donate {
    text-decoration: none; color: #000;
    background: var(--sys-bg);
    cursor: pointer;
    font-weight: bold;
    transition: background 0.1s;
}
.btn-donate:hover { background: #e0e0e0; }
.btn-donate:active { border-style: inset; }

/* ============================
   GREEN CHARACTER LCD FOOTER
   ============================ */

#loading-container {
    flex-grow: 1;
    position: relative;
    height: 20px;
    min-width: 140px;

    display: flex;
    align-items: center;
    padding: 2px 6px;

    /* Plastic module frame */
    background: linear-gradient(to bottom, #6b6f29 0%, #4f531b 40%, #3c3f14 100%);
    border: 1px solid #22230b;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.25),
        inset 0 -1px 0 rgba(0, 0, 0, 0.7),
        0 1px 0 rgba(255, 255, 255, 0.5),
        0 0 0 1px #000;
}

/* Inner PCB-like border around the glass */
#loading-container::before {
    content: "";
    position: absolute;
    inset: 1px;
    border: 1px solid rgba(0, 0, 0, 0.6);
    box-shadow:
        inset 0 0 0 1px rgba(160, 180, 80, 0.4);
    pointer-events: none;
}

/* LCD glass screen */
#loading-container .lcd-screen {
    position: relative;
    flex: 1;
    height: 14px;
    background:
        linear-gradient(to bottom, #071b00 0%, #183f00 45%, #112f00 100%);
    margin: 0 2px;
    box-shadow:
        inset 0 0 2px #000,
        inset 0 0 6px rgba(0, 0, 0, 0.9);
    overflow: hidden;
}

/* Horizontal scanlines */
#loading-container .lcd-screen::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image:
        repeating-linear-gradient(
            to bottom,
            rgba(0, 0, 0, 0.25) 0px,
            rgba(0, 0, 0, 0.25) 1px,
            transparent 1px,
            transparent 2px
        );
    opacity: 0.7;
    pointer-events: none;
}

/* Slight glass glare on top edge */
#loading-container .lcd-screen::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    height: 5px;
    background: linear-gradient(
        to bottom,
        rgba(255, 255, 255, 0.28),
        rgba(255, 255, 255, 0) 100%
    );
    mix-blend-mode: screen;
    pointer-events: none;
}

/* Character line */
#loading-container .lcd-line {
    position: absolute;
    top: 50%;
    left: 0;
    white-space: nowrap;

    transform: translate(0, -50%);
    font-family: "DM Mono", "Consolas", "Courier New", monospace;
    font-size: 11px;
    letter-spacing: 0.09em;

    color: #c8ff9a;
    text-shadow:
        0 0 2px #8fff5a,
        0 0 4px rgba(114, 255, 114, 0.7);
}


.info-block {
    background: #ffffcc; border: 1px solid #999; padding: 6px; margin-top: 10px;
    box-shadow: 2px 2px 2px rgba(0,0,0,0.1);
}

#panel-3 .logo-wrapper {
    display: flex; justify-content: center; align-items: center;
    padding: 12px; background-color: var(--sys-bg); height: 100%; overflow: hidden;
}
.inset-frame {
    background-color: #fff; width: 100%; height: 100%;
    display: flex; justify-content: center; align-items: center;
    border: 2px solid; border-color: #808080 #fff #fff #808080;
    box-shadow: inset 1px 1px 0px #000000; padding: 4px;
}
.retro-logo {
    width: 100%; height: 100%; object-fit: contain; 
    image-rendering: pixelated; display: block;
}

@media (max-width: 800px) {
    .main-grid { 
        display: flex; flex-direction: column; overflow-y: auto; -webkit-overflow-scrolling: touch;
        height: auto; flex-grow: 1;
    }
    .panel { 
        width: 100%; margin-bottom: 2px; flex-shrink: 0; flex-grow: 0;   
        grid-column: auto !important; grid-row: auto !important; min-height: 0; height: auto;
    }
    #panel-2 { flex-grow: 1; height: auto !important; display: flex; flex-direction: column; }
    #panel-2 iframe { flex-grow: 1; height: 100%; min-height: 300px; }
    .panel-content { max-height: 40vh; }
    #panel-2 .panel-content { max-height: none; }

    /* Footer Mobile Adjustments */
    .status-strip {
        gap: 4px;
        padding: 2px 4px;
    }
    .status-strip .field {
        font-size: 10px;
        padding: 0 4px;
    }
    #loading-container {
        /* Allow shrinking if absolutely necessary, but keep other items visible */
        flex-basis: 20px;
    }

    .panel.minimized { flex-grow: 0; height: auto; }
    .panel.minimized .panel-title-text { display: block !important; opacity: 0.6; font-style: italic; }
    .panel.minimized .panel-header { justify-content: flex-start !important; padding: 2px 4px !important; }
    .panel.minimized .panel-num { margin-right: 6px !important; }
    
    .brand-section h1 { font-size: 14px; }
    .version { display: none; }
}