/* General page styling */
body {
    position: relative; /* For positioning context */
    font-family: 'Courier New', Courier, monospace;
    background-color: #333;
    color: #eee;
    margin: 0;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

h1 {
    color: #ffaa00;
    text-align: center;
    margin: 0;
    margin-bottom: 20px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    position: absolute;
    top: 1em;
    left: 50%;
    transform: translateX(-50%);
}

/* Container for all game displays */
.game-container {
    position: relative; /* Establish positioning context for overlay */
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    border: 2px solid #444;
    padding: 15px;
    background-color: #222;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

/* Stats display (top) - matches game map width */
.stats-display {
    order: 1;
    border: 2px solid #666;
    background-color: #333;
    border-radius: 4px;
    box-sizing: border-box;
}

/* Main game display (middle) */
.game-display {
    order: 2;
    border: 2px solid #888;
    background-color: #000;
    border-radius: 4px;
}

/* Message display (bottom) - matches game map width */
.message-display {
    order: 3;
    border: 2px solid #666;
    background-color: #2a2a2a;
    border-radius: 4px;
    min-height: 80px;
    box-sizing: border-box;
}

/* ROT.js canvas styling */
canvas {
    display: block;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

/* Responsive design for smaller screens */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    
    .game-container {
        padding: 10px;
        gap: 8px;
    }
}

#main-wrapper {
    display: flex;
    justify-content: center;
    align-items: flex-start; /* Align items to the top */
    gap: 2rem; /* Add some space between the game and instructions */
    margin-top: 80px; /* Add space for the absolutely positioned title */
}

#controls-container {
    position: absolute;
    top: 1em;
    right: 1em;
    display: flex;
    gap: 10px;
}

#left-controls-container {
    position: absolute;
    top: 1em;
    left: 1em;
    display: flex;
    gap: 10px;
}

#music-toggle-button,
#instructions-toggle-button,
#about-toggle-button,
#leaderboard-button,
#projects-link {
    padding: 8px 16px;
    font-family: 'Courier New', Courier, monospace;
    background-color: #555;
    color: #eee;
    border: 2px solid #888;
    border-radius: 8px;
    cursor: pointer;
    text-decoration: none;
}

#music-toggle-button:hover,
#instructions-toggle-button:hover,
#about-toggle-button:hover,
#leaderboard-button:hover,
#projects-link:hover {
    background-color: #777;
}

/* Instructions overlay styling */
.instructions-overlay,
.about-overlay,
.leaderboard-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* Allow clicks to pass through when hidden */
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.instructions-overlay[style*="block"],
.about-overlay[style*="block"],
.leaderboard-overlay[style*="flex"] {
    pointer-events: auto; /* Enable clicks when visible */
}

.instructions-display,
.about-display {
    position: absolute !important;
    top: 20px !important;
    right: 20px !important;
    z-index: 1001 !important;
    background-color: rgba(0, 0, 0, 0.95) !important;
    backdrop-filter: blur(2px);
}

/* Leaderboard specific styling */
.leaderboard-overlay {
    background-color: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(3px);
}

.leaderboard-content {
    background-color: #2a2a2a;
    border: 3px solid #555;
    border-radius: 10px;
    padding: 20px;
    max-width: 90vw;
    max-height: 90vh;
    overflow-y: auto;
    font-family: 'Courier New', Courier, monospace;
    position: relative;
}

.leaderboard-header {
    position: relative;
    text-align: center;
    margin-bottom: 20px;
}

.leaderboard-list {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.leaderboard-header-row {
    display: grid;
    grid-template-columns: 50px 200px 100px 60px 1fr;
    gap: 10px;
    padding: 10px;
    background-color: #444;
    border-radius: 5px;
    font-weight: bold;
    color: #ffff44;
    border: 1px solid #666;
}

.leaderboard-row {
    display: grid;
    grid-template-columns: 50px 200px 100px 60px 1fr;
    gap: 10px;
    padding: 8px 10px;
    background-color: #333;
    border-radius: 3px;
    border: 1px solid #555;
    color: #eee;
}

.leaderboard-row:nth-child(even) {
    background-color: #3a3a3a;
}

.rank-col {
    text-align: center;
    font-weight: bold;
}

.name-col {
    color: #44ff44;
    font-weight: bold;
}

.score-col {
    color: #ffff44;
    font-weight: bold;
    text-align: right;
}

.level-col {
    color: #ff8844;
    text-align: center;
}

.stats-col {
    color: #cccccc;
    font-size: 12px;
}

/* Death screen styling */
.death-screen-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    font-family: 'Courier New', Courier, monospace;
}

.death-screen-content {
    background-color: #2a2a2a;
    border: 3px solid #555;
    border-radius: 10px;
    padding: 30px;
    text-align: center;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.8);
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
}

.name-input-container {
    margin: 20px 0;
    padding: 15px;
    background-color: #333;
    border-radius: 5px;
    border: 2px solid #666;
}

.name-input {
    padding: 10px;
    font-size: 16px;
    border: 2px solid #666;
    border-radius: 5px;
    background-color: #444;
    color: #eee;
    font-family: 'Courier New', Courier, monospace;
    width: 200px;
    text-align: center;
}

.name-input:focus {
    outline: none;
    border-color: #ffff44;
    background-color: #555;
}

.submit-score-btn {
    background: #44ff44;
    color: black;
    border: none;
    padding: 12px 24px;
    cursor: pointer;
    border-radius: 5px;
    font-weight: bold;
    font-family: 'Courier New', Courier, monospace;
    font-size: 14px;
    margin: 0 5px;
}

.submit-score-btn:hover {
    background: #66ff66;
}

.submit-score-btn:disabled {
    background: #666;
    color: #999;
    cursor: not-allowed;
}

.skip-submit-btn {
    background: #ff8844;
    color: white;
    border: none;
    padding: 12px 24px;
    cursor: pointer;
    border-radius: 5px;
    font-weight: bold;
    font-family: 'Courier New', Courier, monospace;
    font-size: 14px;
    margin: 0 5px;
}

.skip-submit-btn:hover {
    background: #ffaa66;
}

/* HTML Message Display styling */
.html-message-display {
    order: 3;
    border: 2px solid #666;
    background-color: #2a2a2a;
    border-radius: 4px;
    box-sizing: border-box;
}

/* HTML Stats Display styling */
.html-stats-display {
    order: 1;
    border: 2px solid #666;
    background-color: #333;
    border-radius: 4px;
    box-sizing: border-box;
    position: relative;
    z-index: 10;
}

/* Custom scrollbar for message display */
.html-message-display::-webkit-scrollbar {
    width: 8px;
}

.html-message-display::-webkit-scrollbar-track {
    background: #1a1a1a;
    border-radius: 4px;
}

.html-message-display::-webkit-scrollbar-thumb {
    background: #555;
    border-radius: 4px;
}

.html-message-display::-webkit-scrollbar-thumb:hover {
    background: #777;
}

/* Custom scrollbar for leaderboard */
.leaderboard-content::-webkit-scrollbar {
    width: 8px;
}

.leaderboard-content::-webkit-scrollbar-track {
    background: #1a1a1a;
    border-radius: 4px;
}

.leaderboard-content::-webkit-scrollbar-thumb {
    background: #555;
    border-radius: 4px;
}

.leaderboard-content::-webkit-scrollbar-thumb:hover {
    background: #777;
}
