* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    background: #1a1a1a;
    color: white;
    overflow: hidden;
}

.game-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    box-sizing: border-box;
}

#gameCanvas {
    border: 2px solid #444;
    background: #f5deb3;
    max-width: 100%;
    max-height: calc(100vh - 160px);
    width: 500px;
    height: 500px;
}

.prize-ball {
    position: absolute;
    top: 30px;
    left: 50%;
    transform: translateX(-50%);
    width: 120px;
    height: 120px;
    border: 3px solid #ffd700;
    border-radius: 50%;
    background: rgba(255, 215, 0, 0.1);
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.prize-fill {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 0%;
    background: linear-gradient(to top, #27ae60, #2ecc71);
    border-radius: 0 0 50% 50%;
    transition: height 2s ease-in-out;
}

.prize-text {
    position: relative;
    z-index: 2;
    font-weight: bold;
    font-size: 18px;
    color: #ffd700;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
}

.controls {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 15px;
}

#startButton, #restartButton {
    padding: 12px 30px;
    font-size: 18px;
    background: #e74c3c;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.3s;
}

#startButton:hover, #restartButton:hover {
    background: #c0392b;
}

#startButton:disabled, #restartButton:disabled {
    background: #666;
    cursor: not-allowed;
}

#skipCollectionButton {
    background: #e74c3c;
}

#skipCollectionButton:hover {
    background: #c0392b;
}

#speedUpCollectionButton {
    background: #3498db;
}

#speedUpCollectionButton:hover {
    background: #2980b9;
}

#speedUpCollectionButton:disabled {
    background: #666;
    cursor: not-allowed;
}

.countdown {
    font-size: 48px;
    font-weight: bold;
    color: #e74c3c;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
    position: absolute;
    top: -70px;
    left: 50%;
    transform: translateX(-50%);
}

.hidden {
    display: none;
}

.player-grid {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 700px; /* Adjusted to accommodate rotated grid */
    height: 700px; /* Adjusted to accommodate rotated grid */
    background: rgba(0, 0, 0, 0.9);
    border: 2px solid #444;
    border-radius: 10px;
    display: none;
    flex-direction: column;
    z-index: 100;
    overflow: hidden; /* Hide parts of rotated grid that extend beyond the square bounding box */
}

.grid-header {
    padding: 15px;
    background: #333;
    border-bottom: 1px solid #555;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.grid-header span {
    font-size: 18px;
    font-weight: bold;
}

.close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
}

.grid-container-for-rotation {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(45deg);
    width: 480px; /* 16 * 30px tile size */
    height: 480px; /* 16 * 30px tile size */
    box-sizing: border-box;
    padding: 5px; /* Padding inside the rotated container */
}

.grid-content {
    width: 100%;
    height: 100%;
    overflow: auto; /* Allow scrolling for more players than 16x16 */
    display: grid;
    grid-template-columns: repeat(16, 1fr);
    grid-template-rows: repeat(16, 1fr);
    gap: 3px; /* Smaller gap */
    padding: 5px; /* Padding for the grid content itself */
}

.player-tile {
    width: 30px; /* Fixed size for square cells */
    height: 30px; /* Fixed size for square cells */
    background: #3498db;
    border-radius: 50%; /* Keeps player representation as a circle */
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 8px; /* Smaller font for smaller tiles */
    font-weight: bold;
    color: white;
    cursor: pointer;
    transition: all 0.3s;
    border: 2px solid transparent;
    box-sizing: border-box; /* Ensure border is included in 30x30px */
}

.player-tile:hover {
    transform: scale(1.1);
    border-color: #2980b9;
}

.player-tile.dead {
    background: #7f8c8d;
    border-color: #c0392b;
    border-width: 3px;
}

.player-tile.survived {
    border-color: #27ae60;
    border-width: 3px;
}

.player-tile.fade-out {
    opacity: 0;
    transform: scale(0.8);
}

.stats-panel {
    position: absolute;
    top: 50%;
    right: 10px;
    transform: translateY(-50%);
    width: 250px;
    max-height: 80vh;
    background: rgba(0, 0, 0, 0.9);
    border: 2px solid #444;
    border-radius: 10px;
    display: none;
    flex-direction: column;
    z-index: 101;
}

.stats-header {
    padding: 15px;
    background: #333;
    border-bottom: 1px solid #555;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.stats-content {
    padding: 15px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    padding: 5px 0;
    border-bottom: 1px solid #444;
}

.stat-label {
    font-weight: bold;
    color: #bdc3c7;
}

.stat-value {
    color: #3498db;
}

.stat-bar {
    width: 100%;
    height: 6px;
    background: #444;
    border-radius: 3px;
    overflow: hidden;
    margin-top: 3px;
}

.stat-fill {
    height: 100%;
    background: linear-gradient(to right, #e74c3c, #f39c12, #f1c40f, #2ecc71);
    transition: width 0.3s;
}

#nextGameButton {
    padding: 12px 30px;
    font-size: 18px;
    background: #27ae60;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.3s;
}

#nextGameButton:hover {
    background: #219a52;
}

.export-ui {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 400px;
    background: rgba(0, 0, 0, 0.95);
    border: 2px solid #444;
    border-radius: 10px;
    z-index: 102;
    padding: 20px;
}

.export-header {
    text-align: center;
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 20px;
    color: #3498db;
}

.export-content {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.export-status {
    text-align: center;
    color: #bdc3c7;
    font-size: 14px;
}

.export-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.export-actions button {
    padding: 10px 20px;
    background: #3498db;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.3s;
}

.export-actions button:hover {
    background: #2980b9;
}

#exportData {
    width: 100%;
    height: 150px;
    background: #2c3e50;
    color: #ecf0f1;
    border: 1px solid #444;
    border-radius: 5px;
    padding: 10px;
    font-family: monospace;
    font-size: 12px;
    resize: vertical;
}

.import-ui {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 400px;
    background: rgba(0, 0, 0, 0.95);
    border: 2px solid #444;
    border-radius: 10px;
    z-index: 102;
    padding: 20px;
}

.import-header {
    text-align: center;
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 20px;
    color: #3498db;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.import-content {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.import-status {
    text-align: center;
    color: #bdc3c7;
    font-size: 14px;
}

#importData {
    width: 100%;
    height: 150px;
    background: #2c3e50;
    color: #ecf0f1;
    border: 1px solid #444;
    border-radius: 5px;
    padding: 10px;
    font-family: monospace;
    font-size: 12px;
    resize: vertical;
}

.import-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.import-actions button,
.import-actions .custom-file-upload {
    padding: 10px 20px;
    background: #3498db;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.3s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.import-actions button:hover,
.import-actions .custom-file-upload:hover {
    background: #2980b9;
}