*, *::before, *::after {
    box-sizing: border-box;
}

:root {
    --mc-bg: #c6c6c6;
    --mc-dark: #373737;
    --mc-light: #ffffff;
    --mc-shadow: #8b8b8b;
    --mc-text: #404040;
    --mc-slot: #8b8b8b;
}

.viewport{
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

body {
    background-color: #1a1a1a; /* World background */
    color: var(--mc-text);
    font-family: 'VT323', monospace;
    font-size: 20px;
    margin: 0;
    padding: 20px;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* The "GUI Window" Container */
.mc-gui {
    background-color: var(--mc-bg);
    border: 4px solid var(--mc-bg);
    /* The Classic Bevel Effect */
    box-shadow: 
        inset 2px 2px 0px var(--mc-light),
        inset -2px -2px 0px var(--mc-dark);
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 10px;
}

.mc-header {
    margin-bottom: 10px;
    font-size: 1.5rem;

    position: relative; 
    display: flex;
    align-items: center;
    height: 30px;
}

h1.mc-title {
    z-index: 1;
}

/* --- 2. LAYOUT --- */
.workspace {
    display: flex;
    gap: 10px;
    flex: 1;
    overflow: hidden;
}

.sidebar {
    width: 250px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    overflow-y: auto;
}

.viewport {
    flex: 1;
    background-color: #000;
    border: 2px solid var(--mc-shadow);
    border-right-color: var(--mc-light);
    border-bottom-color: var(--mc-light);
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    align-content: flex-start;
    justify-content: center;
}

/* --- 3. UI COMPONENTS --- */

::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

::-webkit-scrollbar-track {
    background: #202020; /* Dark inner track */
    border-left: 1px solid var(--mc-shadow);
}

::-webkit-scrollbar-thumb {
    background: var(--mc-slot); /* The grey "handle" */
    border: 2px solid var(--mc-bg); /* Padding effect */
}

::-webkit-scrollbar-thumb:hover {
    background: #a0a0a0; /* Slightly lighter on hover */
}

/* Firefox Scrollbar Support */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--mc-slot) #202020;
}

.mc-btn {
    background-color: var(--mc-bg);
    border: 2px solid;
    border-color: var(--mc-light) var(--mc-dark) var(--mc-dark) var(--mc-light);
    color: var(--mc-text);
    padding: 8px 12px;
    font-family: inherit;
    font-size: 1.2rem;
    outline: none; /* Remove focus ring */
    cursor: pointer;
    text-align: center;
    box-sizing: border-box;
    position: relative;
}

.mc-btn span {
    display: block;
    position: relative;
    pointer-events: none; /* Let clicks pass through to button */
}

.mc-btn:active {
    border-color: var(--mc-dark) var(--mc-light) var(--mc-light) var(--mc-dark);
}

.mc-btn:active span {
    top: 1px;
    left: 1px;
}

.mc-btn:disabled {
    color: var(--mc-shadow);
    cursor: not-allowed;
}

.mc-btn:focus-visible {
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.7);
    outline: none;
}


/* --- HELPER CLASSES (NEW) --- */
.flex-1 { flex: 1; }
.flex-align-center { display: flex; align-items: center; }
.flex-between-center { display: flex; justify-content: space-between; align-items: center; }
.flex-gap-5 { display: flex; gap: 5px; }

.mt-2 { margin-top: 2px; }
.mb-2 { margin-bottom: 2px; }
.mt-5 { margin-top: 5px; }
.mt-10 { margin-top: 10px; }
.mb-5 { margin-bottom: 5px; }
.mb-10 { margin-bottom: 10px; }

.text-right { text-align: right; }
.text-center { text-align: center; }
.text-small { font-size: 0.7em; }
.font-normal { font-size: 1em; }
.opacity-80 { opacity: 0.8; }

.vertical-m{ vertical-align: middle; }

/* --- SPECIFIC UI ELEMENTS (NEW) --- */

.btn-full { width: 100%; }
.btn-half { width: 50%; }
.btn-tiny { width: 20%; padding: 0;}


.btn-add-layer {
    width: 150px;
    height: 150px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    cursor: pointer;
}

.btn-add-layer::before {
    content: '';
    position: absolute;
    width: 20%;       /* Length of the line relative to button */
    height: 5%;      /* Thickness of the line */
    background-color: var(--mc-text); /* Uses your variable color */
}

/* The Vertical Line */
.btn-add-layer::after {
    content: '';
    position: absolute;
    height: 20%;      /* Length of the line relative to button */
    width: 5%;       /* Thickness of the line */
    background-color: var(--mc-text); /* Uses your variable color */
}

.icon-display-fuel {
    width: 20px;
    height: 20px;
    margin-right: 5px;
    background: transparent;
}

.icon-display-fluid {
    width: 20px;
    height: 20px;
    margin-right: 5px;
    border: 1px solid #888;
    background: transparent;
}

.info-text {
    font-size: 0.8rem;
}

.info-grid {
    font-size: 0.75rem;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px;
}

/* --- TANK STYLES (NEW) --- */
.tank-group {
    display: flex;
    justify-content: space-around;
    margin-top: 10px;
}

.tank-wrapper {
    text-align: center;
}
 
.tank-label {
    font-size: 0.8em;
    margin-bottom: 2px;
}

.fluid-tank {
    width: 60px;
    height: 100px;
    position: relative;
    border: 2px solid #555;
    background-color: #222;
    background-image: url('textures/tank_gui.png');
    background-size: cover;
}

.tank-fill {
    position: absolute;
    bottom: 0;
    width: 100%;
    height: 0%; /* JS will update this */
    transition: height 0.2s;
}

/* Default Colors (JS can override) */
.cold-fill { background-color: rgba(50, 150, 255, 0.6); }
.hot-fill { background-color: rgba(255, 100, 50, 0.6); }

.tank-text {
    position: absolute;
    width: 100%;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.7em;
    text-shadow: 1px 1px 1px #000;
    word-break: break-all;
    color: white;
}

/* --- HEAT BAR --- */
#bar-heat {
    background: #ff3300; /* Moved from HTML style */
}

/* Inventory Slot Style */
.slot-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
}

.slot {
    width: 48px;
    height: 48px;
    background-color: var(--mc-slot);
    border: 2px solid;
    border-color: var(--mc-dark) var(--mc-light) var(--mc-light) var(--mc-dark);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.slot:hover {
    background-color: #9b9b9b;
}

.slot.selected {
    outline: 2px solid #ff0000;
    z-index: 10;
}

/* The Item inside the slot */
.block-icon {
    width: 32px;
    height: 32px;
    border: 1px solid rgba(0,0,0,0.2);
}

/* --- 4. LAYER EDITOR --- */
.layer-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: #2a2a2a;
    padding: 10px;
    border: 2px solid var(--mc-shadow);
}

.layer-header {
    color: #fff;
    margin-bottom: 5px;
    display: flex;
    gap: 10px;
}

.grid-editor {
    display: grid;
    /* Clamp ensures it doesn't get too small or huge */
    width: clamp(150px, 20vw, 300px); 
    height: clamp(150px, 20vw, 300px);
    background-color: #111;
    border: 1px solid #555;
    cursor: crosshair;
}

.cell {
    border: 1px solid rgba(255,255,255,0.05);
}
.cell:hover {
    border: 1px solid rgba(255,255,255,0.5);
}

/* --- 5. STATS PANEL --- */
.stats-panel {
    background-color: var(--mc-bg);
    border: 2px solid;
    border-color: var(--mc-dark) var(--mc-light) var(--mc-light) var(--mc-dark);
    padding: 10px;
    font-size: 1rem;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
}

.progress-bar {
    height: 12px;
    background: #555;
    border: 1px solid #000;
    width: 100%;
    position: relative;
    margin-top: 2px;
}
.progress-fill {
    height: 100%;
    width: 0%;
    background-color: #4db8ff;
    transition: width 0.05s;
}

/* --- UTILS --- */
input, select, textarea, button {
    font-family: inherit; /* Inherits VT323 */
    font-size: 1rem;      /* Matches the sidebar text size */
}

input[type="number"], select {
    background-color: var(--mc-dark); /* #373737 */
    color: var(--mc-light);           /* #ffffff */
    border: 2px solid;
    border-color: var(--mc-shadow) var(--mc-light) var(--mc-light) var(--mc-shadow); /* Inset effect */
    padding: 2px;
}

input:focus, select:focus {
    outline: 2px solid #ffffff;
    outline-offset: -2px;
}

.tooltip {
    position: absolute;
    background: #100010;
    color: white;
    border: 2px solid #2a00aa;
    padding: 4px;
    font-size: 0.8rem;
    pointer-events: none;
    display: none;
    z-index: 100;
}

.cell, .block-icon {
    background-size: cover;
    background-position: center;
    image-rendering: pixelated;
}

input[type="number"] {
    text-align: right;
    width: 50px;
}

input[type=number]::-webkit-inner-spin-button, 
input[type=number]::-webkit-outer-spin-button { 
    -webkit-appearance: none; 
    margin: 0; 
}

input[type=number] {
    -moz-appearance: textfield; /* Firefox */
    appearance: textfield;      /* Standard */
}

#header-error-msg {
    font-size: 1rem;
    position: absolute;
    left: 0;
    width: 100%;      
    text-align: center; 
    color: #ff3333;    
    pointer-events: none;
    font-family: monospace;
}

#import-error {
    font-size: 1.2rem;
    position: absolute;
    left: 0;
    width: 100%;      
    text-align: center; 
    color: #ff3333;    
    pointer-events: none;
    margin-top: 10px;
}

.pixelated {
    image-rendering: -moz-crisp-edges;      /* Firefox */
    image-rendering: -o-crisp-edges;        /* Opera */
    image-rendering: -webkit-optimize-contrast; /* Webkit (Chrome/Safari) */
    image-rendering: pixelated;             /* Standard */
    -ms-interpolation-mode: nearest-neighbor; /* IE (if needed) */
}

img, .cell, .block-icon, .fluid-tank, .icon-display {
    image-rendering: pixelated;
}

/* NEW: Import Modal Styling */
.mc-dialog {
    background-color: var(--mc-bg);
    border: 4px solid var(--mc-bg);
    box-shadow: 
        inset 2px 2px 0px var(--mc-light),
        inset -2px -2px 0px var(--mc-dark);
    color: var(--mc-text);
    padding: 0;
    width: 300px;
    font-family: 'VT323', monospace;
}


.mc-dialog::backdrop {
    background: rgba(0, 0, 0, 0.65); 
    backdrop-filter: blur(2px);       
}

.dialog-header {
    background: var(--mc-dark);
    color: white;
    padding: 5px 10px;
    font-size: 1.1rem;
}

.dialog-body {
    padding: 15px;
}

.mc-input-text {
    width: 100%;
    background: #000;
    border: 1px solid #555;
    color: #fff;
    font-family: inherit;
    font-size: 1rem;
    padding: 5px;
    outline: none;
}

h1.mc-title {
    display: inline;
    font-size: inherit;
    font-weight: inherit;
    margin: 0; 
    padding: 0;
    line-height: inherit;
}

.sidebar h2 {
    display: block;
    font-size: inherit;
    font-weight: inherit;
    margin: 0;
    padding: 0;

    margin-bottom: 5px;
}

.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;
}