/* Global Variables */
:root {
    /* AVAX Red instead of yellows */
    --primary-color: #E84142;
    --primary-dark: #c52526;
    --primary-light: #ff5152;
    --bg-color: #1a1a1a;
    --text-color: #f0f0f0;
    --border-color: #444;
    --box-bg: #2a2a2a;
    --box-highlight: #3a3a3a;
}

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'VT323', monospace;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-size: 18px;
    line-height: 1.5;
    position: relative;
    background-image: url('img/background.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    min-height: 100vh;
}

h1, h2, h3, h4, h5, h6 {
    font-family: 'Press Start 2P', cursive;
    margin-bottom: 15px;
    color: var(--primary-color);
}

button {
    cursor: pointer;
    font-family: 'Press Start 2P', cursive;
    padding: 10px 15px;
    background-color: var(--primary-color);
    color: var(--text-color);
    border: none;
    border-radius: 4px;
    font-size: 14px;
    transition: background-color 0.3s;
}

button:hover {
    background-color: var(--primary-dark);
}

.hidden {
    display: none !important;
}

/* Navigation Bar */
.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 30px;
    background-color: rgba(26, 26, 26, 0.8);
    border-bottom: 2px solid var(--primary-color);
}

.navbar-left, .navbar-right {
    display: flex;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
    margin-right: 30px;
}

.logo span {
    font-family: 'Press Start 2P', cursive;
    font-size: 18px;
    color: var(--primary-color);
    margin-right: 8px;
}

.coin-icon {
    width: 24px;
    height: 24px;
}

.nav-menu {
    display: flex;
    list-style: none;
}

.nav-menu li {
    margin-right: 20px;
    font-family: 'Press Start 2P', cursive;
    font-size: 12px;
    cursor: pointer;
}

.nav-menu li:hover {
    color: var(--primary-color);
}

.navbar-right {
    gap: 15px;
}

.nav-button {
    font-size: 10px;
    padding: 8px 12px;
}

.notification-icon {
    position: relative;
    width: 24px;
    height: 24px;
    background-color: var(--box-bg);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background-color: var(--primary-color);
    color: white;
    border-radius: 50%;
    width: 16px;
    height: 16px;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.user-icon {
    width: 30px;
    height: 30px;
    background-color: var(--box-bg);
    border-radius: 50%;
    overflow: hidden;
}

.user-avatar {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.wallet-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

.connect-button, .logout-button {
    font-size: 12px;
}

.logout-button {
    background-color: var(--primary-dark);
    color: var(--text-color);
}

.logout-button:hover {
    background-color: #a01e1f;
}

.account-address {
    font-family: 'VT323', monospace;
    background-color: var(--box-bg);
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 16px;
}

/* Main Content Layout */
.main-content {
    display: flex;
    padding: 20px;
    gap: 30px;
    justify-content: space-between;
    max-width: 1600px;
    margin: 0 auto;
}

/* Dashboard Panel (Left Side) */
.dashboard-panel {
    display: flex;
    flex-direction: column;
    gap: 10px; /* Further reduced gap between dashboard boxes */
    width: 35%;
    max-width: 450px;
    margin-left: 10px;
}

.dashboard-box {
    background-color: var(--box-bg);
    border: 3px solid var(--primary-color);
    border-radius: 8px;
    padding: 12px; /* Reduced padding */
    box-shadow: 0 0 10px rgba(232, 65, 66, 0.5);
}

/* Tabs Navigation */
.tabs {
    display: flex;
    border-bottom: 2px solid var(--primary-color);
    margin-bottom: 10px; /* Reduced margin */
}

.tab-btn {
    background: none;
    border: none;
    padding: 8px 15px; /* Increased padding */
    font-family: 'Press Start 2P', cursive;
    font-size: 14px; /* Bigger font */
    color: var(--text-color);
    cursor: pointer;
    margin-right: 5px; /* Increased margin */
    border-radius: 4px 4px 0 0;
}

.tab-btn.active {
    background-color: var(--primary-color);
    color: var(--text-color);
}

/* Resources Tab */
.resource-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 3px; /* Further reduced margin */
    padding: 3px; /* Further reduced padding */
    background-color: var(--box-highlight);
    border-radius: 4px;
}

.resource-label {
    font-family: 'Press Start 2P', cursive;
    font-size: 14px; /* Bigger font */
}

.resource-value {
    font-family: 'VT323', monospace;
    font-size: 22px; /* Bigger font */
    color: var(--primary-color); /* Highlighted in red */
    font-weight: bold;
}

/* Stats Box */
.stats-header {
    display: flex;
    align-items: center;
    margin-bottom: 5px; /* Further reduced margin */
}

.stats-header h3 {
    margin-bottom: 0;
    margin-right: 10px;
    font-size: 18px;
}

.mode-label {
    color: var(--primary-color);
    font-size: 16px;
}

.stats-content {
    display: flex;
    flex-direction: column;
    gap: 6px; /* Reduced gap */
}

.stat-item {
    font-family: 'VT323', monospace;
    font-size: 16px;
    background-color: var(--box-highlight);
    padding: 6px; /* Reduced padding */
    border-radius: 4px;
    word-break: break-word;
}

/* Enhanced highlight for numeric values in stats */
.stat-item strong,
.stat-item span:last-child,
.stat-item span:not(:first-child),
.stat-item span[data-value],
.stat-item b,
.stat-item em {
    color: var(--primary-color); /* Red color */
    font-size: 20px; /* Bigger font for numbers */
    font-weight: bold;
}

/* Claim Box */
.claim-content {
    display: flex;
    flex-direction: column;
    gap: 10px; /* Reduced gap */
}

.mined-amount-container {
    background-color: var(--box-highlight);
    padding: 10px; /* Reduced padding */
    border-radius: 4px;
    font-family: 'VT323', monospace;
    font-size: 20px;
    margin-bottom: 6px; /* Reduced margin */
}

/* Highlight the mined amount with red */
.mined-amount-container span {
    color: var(--primary-color);
    font-size: 24px;
    font-weight: bold;
}

.claim-button {
    background-color: var(--primary-color);
    color: white;
    font-size: 16px; /* Bigger font */
    padding: 15px; /* Increased padding */
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.3s;
    align-self: center;
    width: 100%;
    font-weight: bold;
}

.claim-button:hover {
    background-color: var(--primary-dark);
}

/* Facility Panel (Right Side) */
.facility-panel {
    width: 60%; /* Increased by 20% as requested */
    max-width: 950px;
    margin-right: 10px; /* Reduced margin */
}

.console-container {
    position: relative;
    width: 100%;
    aspect-ratio: 4/3;
    background-image: url('img/console.png');
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    display: flex;
    align-items: center;
    justify-content: center;
}

.facility-display {
    position: relative;
    width: 85%; /* Slightly larger proportion of console */
    height: 85%; /* Slightly larger proportion of console */
    border-radius: 8px;
    overflow: hidden;
}

.facility-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.miners-grid {
    position: absolute;
    /* Repositioned to bottom-left */
    bottom: 0;
    left: 0;
    /* Smaller size with space from top and right */
    width: 60%;
    height: 50%;
    display: grid;
    pointer-events: all;
    z-index: 5;
}

.miner-item {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 10;
    cursor: pointer;
}

.miner-image {
    width: 90%;
    height: 90%;
    object-fit: contain;
    image-rendering: pixelated;
    transition: transform 0.2s ease;
}

.miner-item:hover .miner-image {
    transform: scale(1.1);
}

.facility-label {
    position: absolute;
    bottom: 10px;
    right: 10px;
    font-family: 'Press Start 2P', cursive;
    font-size: 12px;
    color: var(--primary-color);
    background-color: rgba(0, 0, 0, 0.5);
    padding: 5px 10px;
    border-radius: 4px;
}

/* Grid Cell Styling - Visible by default */
.grid-cell {
    border: 2px dashed rgba(255, 255, 255, 0.7);
    background-color: transparent;
    cursor: pointer;
    transition: all 0.3s;
    position: relative;
    z-index: 5;
}

.grid-cell:hover {
    background-color: rgba(255, 255, 255, 0.1);
    border: 2px dashed rgba(255, 255, 255, 0.9);
}

/* Hide grid cells when the open-grids button is not active */
.grid-cell.hidden-cell {
    border: 2px dashed rgba(255, 255, 255, 0);
    background-color: transparent;
}

.grid-cell.hidden-cell:hover {
    background-color: rgba(255, 255, 255, 0.05);
    border: 2px dashed rgba(255, 255, 255, 0.2);
}

/* Open Grids Button */
.open-grids-button {
    position: absolute;
    top: 10px;
    right: 10px;
    padding: 8px 12px;
    font-family: 'Press Start 2P', cursive;
    font-size: 10px;
    background-color: var(--primary-color);
    color: var(--text-color);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    z-index: 10;
    box-shadow: 0 0 8px rgba(0, 0, 0, 0.5);
}

.open-grids-button:hover {
    background-color: var(--primary-dark);
}

.open-grids-button.active {
    background-color: var(--primary-dark);
    box-shadow: 0 0 12px rgba(232, 65, 66, 0.7);
}

/* Selected Tile Styles */
.selected-tile-info {
    padding: 10px;
    background-color: var(--box-highlight);
    border-radius: 6px;
}

.selected-tile-info h3 {
    font-size: 14px;
    margin-bottom: 10px;
    color: var(--primary-color);
}

.selected-tile-info p {
    margin-bottom: 8px;
    font-size: 16px;
}

.empty-tile-actions {
    margin-top: 15px;
}

.empty-tile-actions select {
    width: 100%;
    padding: 8px;
    margin-bottom: 10px;
    background-color: var(--box-bg);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    font-family: 'VT323', monospace;
}

.sell-miner-btn {
    width: 100%;
    margin-top: 10px;
}

/* Transaction Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background-color: var(--box-bg);
    border: 3px solid var(--primary-color);
    border-radius: 8px;
    padding: 30px;
    text-align: center;
    max-width: 400px;
    width: 100%;
}

.loader {
    border: 5px solid var(--box-highlight);
    border-top: 5px solid var(--primary-color);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Facility Purchase Container */
.facility-purchase-container {
    max-width: 80%;
    margin: 0 auto 20px auto;
    padding: 15px;
    background-color: var(--box-bg);
    border: 3px solid var(--primary-color);
    border-radius: 8px;
    text-align: center;
    position: relative;
    z-index: 5;
}

.facility-purchase-container h2 {
    font-size: 16px;
    margin-bottom: 10px;
}

.facility-purchase-container p {
    font-size: 16px;
    margin-bottom: 10px;
}

.referrer-input {
    margin: 10px 0;
    text-align: left;
}

.referrer-input input {
    width: 100%;
    padding: 10px;
    background-color: var(--box-highlight);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-color);
    font-family: 'VT323', monospace;
    font-size: 16px;
    margin-top: 5px;
}

/* Free Miner Section */
.free-miner-section {
    max-width: 600px;
    margin: 30px auto;
    padding: 20px;
    background-color: var(--box-bg);
    border: 3px solid var(--primary-color);
    border-radius: 8px;
}

.miner-position {
    margin: 15px 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.miner-position select {
    padding: 8px;
    background-color: var(--box-highlight);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-color);
    font-family: 'VT323', monospace;
}

/* No Facility Overlay */
.no-facility-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 10;
}

.no-facility-text {
    font-family: 'Press Start 2P', cursive;
    font-size: 16px;
    color: var(--text-color);
    text-align: center;
    margin-bottom: 20px;
    text-shadow: 0 0 10px rgba(0, 0, 0, 0.8);
}

.buy-facility-button {
    background-color: var(--box-bg);
    color: var(--primary-color);
    border: 3px solid var(--primary-color);
    border-radius: 4px;
    padding: 12px 20px;
    font-family: 'Press Start 2P', cursive;
    font-size: 14px;
    cursor: pointer;
    box-shadow: 0 0 20px rgba(232, 65, 66, 0.5);
    transition: all 0.3s;
}

.buy-facility-button:hover {
    background-color: var(--primary-color);
    color: var(--text-color);
}

/* Space Tab Content */
.space-tab-content {
    padding: 10px;
}

.facility-level-info {
    background-color: var(--box-highlight);
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 15px;
}

.facility-level-info p {
    margin-bottom: 8px;
    font-size: 16px;
    display: flex;
    justify-content: space-between;
}

.facility-upgrade-info {
    background-color: var(--box-highlight);
    padding: 15px;
    border-radius: 8px;
    margin-top: 15px;
}

.upgrade-button {
    background-color: var(--primary-color);
    color: white;
    width: 100%;
    margin-top: 10px;
    padding: 10px;
    border: none;
    border-radius: 4px;
    font-family: 'Press Start 2P', cursive;
    font-size: 12px;
    cursor: pointer;
}

.upgrade-button:hover {
    background-color: var(--primary-dark);
}

.max-level-badge {
    background-color: var(--primary-color);
    color: var(--text-color);
    font-family: 'Press Start 2P', cursive;
    font-size: 10px;
    padding: 5px 10px;
    border-radius: 4px;
    display: inline-block;
    margin-top: 10px;
}

/* Facility Info */
.facility-info {
    max-width: 600px;
    margin: 30px auto;
    padding: 20px;
    background-color: var(--box-bg);
    border: 3px solid var(--primary-color);
    border-radius: 8px;
}

.facility-stats {
    margin-bottom: 20px;
}

.facility-stats p {
    display: flex;
    justify-content: space-between;
    padding: 8px;
    background-color: var(--box-highlight);
    border-radius: 4px;
    margin-bottom: 8px;
}

.facility-upgrade {
    padding: 15px;
    background-color: var(--box-highlight);
    border-radius: 4px;
}

/* Miners Sections - Redesigned as dashboards */
.miners-section {
    width: 100%;
    margin: 0 0 15px 0;
    padding: 15px;
    background-color: var(--box-bg);
    border: 3px solid var(--primary-color);
    border-radius: 8px;
}

/* Base miners grid settings for all facilities */
.facility-display .miners-grid {
    display: grid;
    position: absolute;
    pointer-events: all;
    z-index: 5;
}

/* Facility Level 1 grid positioning with slant from top left for V-shaped room */
#miners-grid-level1 {
    top: 50%;
    left: 41%;
    width: 22%;
    height: 22%;
    grid-template-rows: 1fr 1fr !important; /* Force 2 equal rows for 2x2 grid */
    transform: rotate(26.9deg) skewX(-35deg);
    transform-origin: top left;
}

/* Facility Level 2 grid positioning with 45-degree angle */
#miners-grid-level2 {
    top: 40%;
    left: 44%;
    width: 30%;
    height: 30%;
    grid-template-rows: 1fr 1fr 1fr !important; /* Force 3 equal rows for 3x3 grid */
    transform: rotate(27.9deg) skewX(-35deg);
    transform-origin: top left;
}

/* Facility Level 3 grid positioning with 45-degree angle */
#miners-grid-level3 {
    bottom: 10%;
    left: 20%;
    width: 60%;
    height: 60%;
    grid-template-rows: 1fr 1fr 1fr 1fr !important; /* Force 4 equal rows for 4x4 grid */
    transform: rotate(45deg);
    transform-origin: bottom left;
}

/* Force counter-rotation specifically for each level's miners */
#miners-grid-level1 .miner-item {
    /* Counter-rotate against level 1's rotation (26.9deg with -35deg skew) */
    transform: rotate(-48deg)  !important;
    height: 120%;
    width: 120%;
    transform-origin: center center !important;
    transform-style: preserve-3d !important;
    transform-box: view-box !important;
    position: relative !important;
    z-index: 100 !important;
}

#miners-grid-level2 .miner-item {
    /* Counter-rotate against level 2's 45-degree rotation */
    transform: rotate(-45deg) !important;
    transform-origin: center center !important;
    transform-style: preserve-3d !important;
    transform-box: view-box !important;
    position: relative !important;
    z-index: 100 !important;
}

#miners-grid-level3 .miner-item {
    /* Counter-rotate against level 3's 45-degree rotation */
    transform: rotate(-45deg) !important;
    transform-origin: center center !important;
    transform-style: preserve-3d !important;
    transform-box: view-box !important;
    position: relative !important;
    z-index: 100 !important;
}

/* Ensure miner images are completely straight */
.miner-image {
    width: 90%;
    height: 90%;
    object-fit: contain;
    image-rendering: pixelated;
    transition: transform 0.2s ease;
    display: block !important;
    position: relative !important;
    transform: none !important;
}

/* Preserve straightness even during hover */
#miners-grid-level1 .miner-item:hover .miner-image,
#miners-grid-level2 .miner-item:hover .miner-image,
#miners-grid-level3 .miner-item:hover .miner-image {
    transform: scale(1.1) !important;
}

/* Different style for miners listing in dashboard */
.miners-section .miners-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-top: 10px;
}

.miner-card {
    background-color: var(--box-highlight);
    border-radius: 6px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    font-size: 14px;
}

.miner-stats {
    margin-bottom: 10px;
}

.miner-stats p {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
    font-size: 14px;
}

.action-button {
    background-color: var(--primary-color);
    color: white;
    padding: 8px 12px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-family: 'Press Start 2P', cursive;
    font-size: 12px;
    margin-top: auto;
}

.action-button:hover {
    background-color: var(--primary-dark);
}

/* Miners Popup for buying miners */
.miners-popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.miners-popup-content {
    background-color: var(--box-bg);
    border: 3px solid var(--primary-color);
    border-radius: 8px;
    padding: 20px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
}

.miners-popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--primary-color);
}

.miners-popup-header h3 {
    font-size: 18px;
    margin-bottom: 0;
}

.close-popup {
    font-size: 24px;
    cursor: pointer;
    color: var(--primary-color);
}

.close-popup:hover {
    color: var(--primary-light);
}

.selected-position {
    font-family: 'Press Start 2P', cursive;
    font-size: 12px;
    padding: 10px;
    background-color: var(--box-highlight);
    border-radius: 4px;
    margin-bottom: 15px;
}

.miners-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 15px;
}

.miner-option {
    background-color: var(--box-highlight);
    border: 2px solid var(--border-color);
    border-radius: 6px;
    padding: 15px;
    transition: border-color 0.3s;
    cursor: pointer;
    display: flex;
    flex-direction: column;
}

.miner-option:hover {
    border-color: var(--primary-color);
}

.miner-option-image {
    width: 100%;
    height: 100px;
    object-fit: contain;
    margin-bottom: 10px;
    image-rendering: pixelated;
}

.miner-option-details {
    flex-grow: 1;
    margin-bottom: 10px;
}

.miner-option-details p {
    margin-bottom: 5px;
    font-size: 16px;
    display: flex;
    justify-content: space-between;
}

.miner-option-details p span:first-child {
    font-weight: bold;
    color: var(--primary-color);
}

.buy-miner-button {
    width: 100%;
    font-size: 12px;
    padding: 8px;
}

/* Pixel Art Styling Effects */
/* Adding pixelated borders and shadows for retro feel */
.dashboard-box, .facility-display, .console-container {
    image-rendering: pixelated;
}

/* Animation for mining counter */
@keyframes pulse-update {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.pulse-update {
    animation: pulse-update 0.3s ease-in-out;
}

/* Responsive Styling */
@media (max-width: 1200px) {
    .main-content {
        flex-direction: column;
        align-items: center;
    }
    
    .dashboard-panel, .facility-panel {
        width: 90%;
        max-width: 800px;
        margin: 0 auto 30px;
    }
}

@media (max-width: 768px) {
    .navbar {
        flex-direction: column;
        gap: 15px;
    }
    
    .nav-menu {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .tab-btn {
        font-size: 10px;
        padding: 6px 10px;
    }
}