@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: #0a0a0a;
    color: white;
    overflow: hidden;
    user-select: none;
}

/* Make the map fill the screen; all UI overlays the map now */
#game-container {
    position: relative;
    height: 100vh;
    width: 100vw;
}

#ui-panel {
    position: absolute;
    top: 16px;
    left: 16px;
    width: 300px;
    max-height: calc(100vh - 32px);
    overflow: auto;
    background: rgba(20, 20, 20, 0.92);
    backdrop-filter: blur(10px);
    border-right: none;
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 16px;
    border-radius: 12px;
    z-index: 50;
}

#title h1 {
    font-size: 28px;
    font-weight: 700;
    background: linear-gradient(135deg, #00ff88, #00aaff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 4px;
}

#title p {
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
}

#pixel-counter {
    background: rgba(255, 255, 255, 0.05);
    padding: 16px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Mode toggle */
#mode-toggle {
    display: flex;
    gap: 8px;
    margin: 12px 0 16px;
}

#mode-toggle button {
    flex: 1;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.15);
    background: rgba(255,255,255,0.06);
    color: #fff;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.15s ease;
}

#mode-toggle button:hover {
    background: rgba(255,255,255,0.12);
    transform: translateY(-1px);
}

#mode-toggle button.active {
    background: linear-gradient(135deg, #00ff88, #00aaff);
    color: #0a0a0a;
    border-color: transparent;
}

#pixel-count {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 8px;
    color: #00ff88;
}

#next-pixel {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.6);
}

#color-palette {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
}

.color-option {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    cursor: pointer;
    border: 2px solid rgba(255, 255, 255, 0.2);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.color-option:hover {
    transform: scale(1.1);
    border-color: rgba(255, 255, 255, 0.5);
}

.color-option.selected {
    border-color: #00ff88;
    box-shadow: 0 0 20px rgba(0, 255, 136, 0.3);
}

.color-option.eraser {
    background: linear-gradient(45deg, #333, #555);
    color: white;
}

#zoom-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#zoom-controls button {
    padding: 12px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 14px;
    font-weight: 500;
}

#zoom-controls button:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
}

#zoom-level {
    text-align: center;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.7);
    margin-top: 4px;
}

#coordinates {
    background: rgba(255, 255, 255, 0.05);
    padding: 12px;
    border-radius: 8px;
    font-size: 12px;
    font-family: 'Space Mono', monospace;
}

#coordinates div {
    margin-bottom: 4px;
}

/* Existing overlays remain overlays */
#map-container {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 0; /* map at the back */
}

#map {
    width: 100%;
    height: 100%;
}

/* Keep crosshair centered over the map above tiles */
#crosshair {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 24px;
    color: rgba(255, 255, 255, 0.8);
    pointer-events: none;
    text-shadow: 0 0 10px rgba(0, 0, 0, 0.8);
    z-index: 40;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: #1a1a1a;
    padding: 32px;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    max-width: 400px;
    text-align: center;
}

.modal-content h3 {
    margin-bottom: 16px;
    color: #00ff88;
}

.modal-content p {
    margin-bottom: 24px;
    color: rgba(255, 255, 255, 0.8);
}

.modal-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.modal-buttons button {
    padding: 12px 24px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s ease;
}

#confirm-place {
    background: #00ff88;
    color: black;
}

#confirm-place:hover {
    background: #00cc6a;
    transform: translateY(-1px);
}

#cancel-place {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

#cancel-place:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Top-right status panel */
#status-panel {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 60;
    background: rgba(20,20,20,0.92);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 12px;
    padding: 12px 14px;
    min-width: 220px;
    font-size: 13px;
    color: rgba(255,255,255,0.9);
    backdrop-filter: blur(10px);
}

#status-panel .status-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px dashed rgba(255,255,255,0.08);
}

#status-panel .status-row:last-child {
    border-bottom: none;
}

#status-panel .label {
    color: rgba(255,255,255,0.7);
}

#status-panel .exp-bar-row {
    align-items: center;
    gap: 10px;
}

#exp-bar-container {
    flex: 1;
    height: 10px;
    background: rgba(255,255,255,0.08);
    border-radius: 999px;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,0.1);
}

#exp-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #00ff88, #00aaff);
    transition: width 0.3s ease;
}

#exp-bar-label {
    min-width: 42px;
    text-align: right;
    color: rgba(255,255,255,0.8);
    font-variant-numeric: tabular-nums;
}

/* Popup avatar styling (Leaflet popups) */
.leaflet-popup-content .pixel-popup {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
}

.pixel-popup .avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #222;
    flex-shrink: 0;
    border: 1px solid rgba(255,255,255,0.15);
}

.pixel-popup .meta {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.pixel-popup .swatch {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 2px;
    border: 1px solid rgba(0,0,0,0.3);
    vertical-align: middle;
    margin-right: 6px;
}

/* Random teleport button under status */
#random-teleport-row {
    display: flex;
    justify-content: flex-end;
    padding-top: 8px;
    border-top: 1px dashed rgba(255,255,255,0.08);
    margin-top: 6px;
}
#random-teleport-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.2);
    background: rgba(255,255,255,0.06);
    color: #fff;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s ease;
    line-height: 28px;
    text-align: center;
    padding: 0;
}
#random-teleport-btn:hover {
    background: rgba(255,255,255,0.16);
    transform: translateY(-1px);
}

/* Version banner */
#version-banner {
    position: fixed;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    background: rgba(220, 60, 60, 0.95);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 10px;
    padding: 10px 14px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.35);
}
#version-banner.hidden { display: none; }
#version-banner .version-content {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
}
#version-banner #refresh-btn {
    margin-left: 8px;
    padding: 6px 10px;
    background: #ffffff;
    color: #c00;
    border: none;
    border-radius: 6px;
    font-weight: 700;
    cursor: pointer;
}
#version-banner.flash {
    animation: flashPulse 0.6s;
}
@keyframes flashPulse {
    0% { transform: translateX(-50%) scale(1); }
    50% { transform: translateX(-50%) scale(1.02); }
    100% { transform: translateX(-50%) scale(1); }
}

#players-online {
    position: absolute;
    bottom: 60px;
    right: 20px;
    background: rgba(0, 0, 0, 0.7);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.7);
    z-index: 70;
}

/* Countdown bar remains fixed overlay */
#countdown-bar {
    position: fixed;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(10,10,10,0.9);
    border: 1px solid rgba(255,255,255,0.1);
    padding: 10px 16px;
    border-radius: 999px;
    z-index: 80;
    font-size: 14px;
    color: rgba(255,255,255,0.9);
    box-shadow: 0 6px 24px rgba(0,0,0,0.4);
    pointer-events: none;
}

/* Game Over overlay */
#game-over-overlay {
    position: fixed;
    inset: 0;
    background: radial-gradient(80% 80% at 50% 50%, rgba(0,0,0,0.8), rgba(0,0,0,0.96));
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

#game-over-overlay.hidden {
    display: none;
}

#game-over-overlay .game-over-content {
    text-align: center;
    padding: 32px 40px;
    border-radius: 16px;
    background: rgba(20,20,20,0.8);
    border: 1px solid rgba(255,255,255,0.1);
    backdrop-filter: blur(6px);
}

#game-over-overlay .game-over-content h1 {
    font-size: 32px;
    background: linear-gradient(135deg, #ffffff, #bbbbbb);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* When game is over, dim everything underneath (overlay already blocks interactions) */
body.game-over #game-container {
    filter: blur(2px) saturate(0.8);
}

/* Responsive adjustments */
@media (max-width: 768px) {
    #ui-panel {
        width: calc(100% - 24px);
        left: 12px;
        right: 12px;
        top: auto;
        bottom: 80px;
        max-height: 40vh;
    }

    /* Make mode toggle sticky on small screens for easy access */
    #mode-toggle {
        position: sticky;
        top: 0;
        background: rgba(20,20,20,0.92);
        padding-top: 4px;
        z-index: 1;
    }

    #status-panel {
        top: 12px;
        right: 12px;
        min-width: 180px;
        font-size: 12px;
        padding: 10px 12px;
    }

    #players-online {
        bottom: 72px;
        right: 12px;
    }

    #countdown-bar {
        bottom: 8px;
        font-size: 12px;
        padding: 8px 12px;
    }
}