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

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    background: #0a0a0a;
    color: #ffffff;
    overflow: hidden;
    height: 100vh;
}

#game-container {
    width: 100vw;
    height: 100vh;
    position: relative;
}

#canvas {
    width: 100%;
    height: 100%;
    display: block;
    cursor: grab;
}

#canvas:active {
    cursor: grabbing;
}

/* HUD */
#hud {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    pointer-events: none;
    z-index: 100;
}

#hud > * {
    pointer-events: auto;
}

#submit-score-btn {
    margin: 0;
}


.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
}

.top-bar h1 {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: 2px;
    color: #ff6b6b;
    text-shadow: 0 0 20px rgba(255, 107, 107, 0.5);
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.3s;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.stats-bar {
    display: flex;
    gap: 20px;
    padding: 0 20px 20px 20px;
    flex-wrap: wrap;
}

.stat {
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 15px 20px;
    min-width: 240px;
}

.time-speed-control {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.time-speed-buttons {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 5px;
}

.time-btn {
    width: 30px;
    height: 30px;
    border-radius: 6px;
    background: rgba(78, 205, 196, 0.2);
    border: 1px solid rgba(78, 205, 196, 0.4);
    color: #4ecdc4;
    font-size: 1.2rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.time-btn:hover {
    background: rgba(78, 205, 196, 0.4);
    border-color: rgba(78, 205, 196, 0.6);
    transform: scale(1.1);
}

.time-btn:active {
    transform: scale(0.95);
}

.time-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.time-btn:disabled:hover {
    transform: none;
    background: rgba(78, 205, 196, 0.2);
}

.stat-label {
    display: block;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #888;
    margin-bottom: 5px;
}

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: #4ecdc4;
    overflow: hidden;
    position: relative;
    height: 1.8rem;
    transition: all 0.3s ease;
}

#score {
    color: #ffd700;
}

/* Region Panel */
#region-panel {
    position: fixed;
    background: rgba(0, 0, 0, 0.9);
    border: 2px solid #4ecdc4;
    border-radius: 15px;
    padding: 20px;
    min-width: 300px;
    max-width: 400px;
    z-index: 100;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    transition: left 0.3s ease, top 0.3s ease, opacity 0.2s ease;
    pointer-events: auto;
}

#region-panel h2 {
    font-size: 1.5rem;
    margin-bottom: 15px;
    color: #4ecdc4;
}

.region-stats {
    margin-bottom: 20px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.stat-row:last-child {
    border-bottom: none;
}

.stat-row span:first-child {
    color: #888;
}

.stat-row span:last-child {
    color: #fff;
    font-weight: 600;
}

/* Regions Overview Panel */
#regions-overview-panel {
    position: fixed;
    top: 160px;
    right: 0;
    z-index: 99;
    pointer-events: auto;
    transform: translateX(350px); /* Start off-screen (width of panel) */
    transition: transform 0.4s cubic-bezier(0.4, 0.0, 0.2, 1);
}

#regions-overview-panel.panel-visible {
    transform: translateX(0); /* Slide in */
}

.panel-toggle-btn {
    position: absolute;
    right: 350px; /* Position to the left of the panel */
    top: 0;
    background: linear-gradient(135deg, #1a1a2e, #16213e);
    border: 2px solid rgba(78, 205, 196, 0.4);
    border-right: none;
    border-radius: 8px 0 0 8px;
    padding: 15px 8px;
    color: #4ecdc4;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: -4px 0 16px rgba(0, 0, 0, 0.3);
    writing-mode: vertical-rl;
    text-orientation: mixed;
    display: flex;
    align-items: center;
    gap: 8px;
}

.panel-toggle-btn:hover {
    background: linear-gradient(135deg, #16213e, #1a1a2e);
    border-color: #4ecdc4;
}

#toggle-arrow {
    transition: transform 0.3s ease;
    transform: rotate(90deg); /* Point right when closed */
}

#toggle-arrow.rotated {
    transform: rotate(-90deg); /* Point left when open */
}

.regions-list {
    background: linear-gradient(135deg, #1a1a2e, #16213e);
    border: 2px solid rgba(78, 205, 196, 0.4);
    border-right: none;
    border-radius: 0;
    max-height: 600px;
    overflow-y: auto;
    width: 350px;
    box-shadow: -8px 8px 32px rgba(0, 0, 0, 0.5);
}

.region-item {
    padding: 12px 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    cursor: pointer;
    transition: background 0.2s ease;
}

.region-item:hover {
    background: rgba(78, 205, 196, 0.1);
}

.region-item:last-child {
    border-bottom: none;
}

.region-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.region-item-name {
    font-weight: 600;
    color: #4ecdc4;
    font-size: 0.95rem;
}

.region-item-population {
    color: #fff;
    font-size: 0.85rem;
}

.region-item-disasters {
    display: flex;
    gap: 4px;
    font-size: 0.8rem;
    color: #ff6b6b;
}

.region-item-status {
    font-size: 0.75rem;
    color: #888;
}

.region-extinct {
    opacity: 0.5;
}

.region-extinct .region-item-name {
    color: #666;
    text-decoration: line-through;
}

/* Disaster Buttons */
.disaster-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.disaster-btn {
    padding: 12px;
    background: rgba(255, 107, 107, 0.2);
    border: 2px solid rgba(255, 107, 107, 0.4);
    border-radius: 8px;
    color: white;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    text-align: center;
}

.disaster-btn:hover {
    background: rgba(255, 107, 107, 0.4);
    border-color: rgba(255, 107, 107, 0.6);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(255, 107, 107, 0.4);
}

.disaster-btn:active {
    transform: translateY(0);
}

.disaster-btn.active {
    background: rgba(255, 107, 107, 0.6);
    border-color: rgba(255, 107, 107, 0.8);
}

.disaster-btn:disabled {
    background: rgba(100, 100, 100, 0.2);
    border-color: rgba(100, 100, 100, 0.3);
    color: rgba(255, 255, 255, 0.3);
    cursor: not-allowed;
    opacity: 0.5;
}

.disaster-btn:disabled:hover {
    transform: none;
    box-shadow: none;
    background: rgba(100, 100, 100, 0.2);
}

/* Instructions */
#instructions {
    position: absolute;
    bottom: 50%;
    left: 50%;
    transform: translate(-50%, 50%);
    text-align: center;
    font-size: 1.5rem;
    color: rgba(255, 255, 255, 0.8);
    pointer-events: none;
    z-index: 50;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(8px);
}

.modal-content {
    background: linear-gradient(135deg, #1a1a2e, #16213e);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 40px;
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    text-align: center;
}

.modal-content h2 {
    font-size: 2.5rem;
    margin-bottom: 20px;
    color: #ff6b6b;
    text-shadow: 0 0 20px rgba(255, 107, 107, 0.5);
}

.game-over-content {
    max-width: 1000px;
    width: 95%;
}

/* Event Modal */
.event-content {
    max-width: 700px;
    padding: 50px;
    background: linear-gradient(135deg, #2c1810, #1a1a2e);
    border: 3px solid rgba(255, 107, 107, 0.4);
}

.event-content h2 {
    font-size: 2.2rem;
    margin-bottom: 25px;
    color: #ff8c42;
    text-shadow: 0 0 20px rgba(255, 140, 66, 0.6);
    line-height: 1.3;
}

.event-content p {
    font-size: 1.15rem;
    line-height: 1.8;
    margin-bottom: 30px;
    color: #e0e0e0;
    text-align: left;
}

#event-continue-btn {
    width: 200px;
    padding: 15px;
    font-size: 1.1rem;
}

.name-entry {
    display: flex;
    gap: 10px;
    margin: 25px 10rem;
    align-items: center;
}

.name-entry input {
    flex: 1;
}

.leaderboard-display {
    margin: 30px 0;
}

.leaderboard-display h3 {
    font-size: 1.8rem;
    margin-bottom: 20px;
    color: #ffd700;
}

.leaderboard-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.leaderboard-column {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    padding: 20px;
}

.leaderboard-column h4 {
    color: #4ecdc4;
    margin-bottom: 15px;
    font-size: 1.2rem;
}

.leaderboard-column > div {
    max-height: 300px;
    overflow-y: auto;
}

.final-stats {
    background: rgba(0, 0, 0, 0.4);
    border-radius: 12px;
    padding: 30px;
    margin: 0 10rem;
}

.final-stats .stat-row {
    font-size: 1.2rem;
    padding: 12px 0;
}

.final-stats .stat-row span:last-child {
    color: #4ecdc4;
    font-size: 1.3rem;
}

#player-name {
    width: 100%;
    padding: 15px;
    font-size: 1.1rem;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: white;
    text-align: center;
}

#player-name:focus {
    outline: none;
    border-color: #4ecdc4;
}

.btn-primary,
.btn-secondary {
    padding: 15px 30px;
    font-size: 1.1rem;
    font-weight: 600;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: all 0.3s;
    margin: 5px;
}

.btn-primary {
    background: linear-gradient(135deg, #ff6b6b, #ee5a6f);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 107, 107, 0.4);
}

.btn-primary:disabled {
    background: rgba(100, 100, 100, 0.3);
    color: rgba(255, 255, 255, 0.4);
    cursor: not-allowed;
    opacity: 0.5;
}

.btn-primary:disabled:hover {
    transform: none;
    box-shadow: none;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    color: white;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.2);
}

.modal-actions {
    margin-top: 20px;
}

/* Leaderboard */
.leaderboard-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    justify-content: center;
}

.tab-btn {
    padding: 10px 20px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: white;
    cursor: pointer;
    transition: all 0.3s;
}

.tab-btn.active {
    background: #4ecdc4;
    border-color: #4ecdc4;
    color: #000;
}

#leaderboard-list {
    max-height: 400px;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
}

.leaderboard-entry {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    margin-bottom: 10px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    transition: all 0.3s;
    min-height: 68px;
}

.leaderboard-entry:hover {
    background: rgba(255, 255, 255, 0.1);
}

.leaderboard-entry.player-entry {
    background: linear-gradient(135deg, rgba(78, 205, 196, 0.3), rgba(78, 205, 196, 0.2));
    border: 2px solid #4ecdc4;
    animation: pulse-glow 2s infinite;
}

@keyframes pulse-glow {
    0%, 100% { box-shadow: 0 0 10px rgba(78, 205, 196, 0.3); }
    50% { box-shadow: 0 0 20px rgba(78, 205, 196, 0.6); }
}

.leaderboard-rank {
    font-size: 1.5rem;
    font-weight: bold;
    width: 50px;
    color: #ffd700;
}

.leaderboard-name {
    flex: 1;
    text-align: left;
    margin: 0 20px;
}

.leaderboard-score {
    font-weight: bold;
    color: #4ecdc4;
}

/* Welcome Modal */
.welcome-content {
    max-width: 1100px;
    width: 95%;
}

.welcome-text {
    margin: 20px 0;
    font-size: 1.05rem;
    line-height: 1.5;
}

.welcome-text p {
    margin: 12px 0;
    color: #ccc;
}

.welcome-text .warning {
    color: #ff6b6b;
    font-weight: 600;
    font-style: italic;
    margin-top: 15px;
}

.welcome-layout-full {
    display: flex;
    flex-direction: column;
    gap: 25px;
    margin: 25px 0;
}

.controls-info-compact {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    padding: 20px;
    text-align: left;
}

.controls-info-compact h3 {
    margin-bottom: 15px;
    color: #4ecdc4;
    font-size: 1.1rem;
    text-align: center;
}

.controls-info-compact ul {
    list-style: none;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.controls-info-compact li {
    padding-left: 20px;
    position: relative;
    color: #ccc;
    font-size: 0.95rem;
}

.controls-info-compact li:before {
    content: '▸';
    position: absolute;
    left: 0;
    color: #4ecdc4;
}

.controls-info-compact strong {
    color: #fff;
}

.welcome-leaderboard-full {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    padding: 25px;
}

.welcome-leaderboard-full h3 {
    margin-bottom: 20px;
    color: #ffd700;
    font-size: 1.5rem;
    text-align: center;
}

.welcome-leaderboard-full .leaderboard-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.welcome-leaderboard-full .leaderboard-column {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    padding: 15px;
}

.welcome-leaderboard-full .leaderboard-column h4 {
    color: #4ecdc4;
    margin-bottom: 15px;
    font-size: 1.1rem;
}

.welcome-leaderboard-full .leaderboard-column > div {
    max-height: 250px;
    overflow-y: auto;
}

.btn-large {
    font-size: 1.3rem;
    padding: 18px 40px;
    margin-top: 10px;
}

/* NERKTEK Footer */
.nerktek-footer {
    text-align: center;
    margin-top: 30px;
}

.nerktek-footer a {
    color: #888;
    text-decoration: none;
    font-size: 0.85rem;
    letter-spacing: 1px;
    transition: color 0.3s;
}

.nerktek-footer a:hover {
    color: #4ecdc4;
}

/* Footer for main game HUD */
.game-footer {
    position: fixed;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 90;
    pointer-events: none;
}

.game-footer a {
    color: #666;
    text-decoration: none;
    font-size: 0.75rem;
    letter-spacing: 1px;
    transition: color 0.3s;
    pointer-events: auto;
}

.game-footer a:hover {
    color: #4ecdc4;
}

/* Utility */
.hidden {
    display: none !important;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .top-bar h1 {
        font-size: 1.5rem;
    }
    
    .stats-bar {
        flex-direction: column;
        gap: 10px;
    }
    
    .stat {
        min-width: auto;
    }
    
    #region-panel {
        bottom: 10px;
        right: 10px;
        left: 10px;
        width: auto;
    }
    
    .disaster-grid {
        grid-template-columns: 1fr;
    }
    
    .modal-content {
        padding: 20px;
    }
    
    .welcome-layout-full {
        gap: 15px;
    }
    
    .controls-info-compact ul {
        grid-template-columns: 1fr;
    }
    
    .welcome-leaderboard-full .leaderboard-columns {
        grid-template-columns: 1fr;
    }
    
    .leaderboard-columns {
        grid-template-columns: 1fr;
    }
    
    .name-entry {
        flex-direction: column;
    }
    
    .name-entry input,
    .name-entry button {
        width: 100%;
    }
}
