* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: #0d1b2a;
    color: #e0e0e0;
    user-select: none;
    -webkit-user-select: none;
}

#app {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* Screen system — .screen / .screen.active (NOT .overlay) */
.screen {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: none;
    flex-direction: column;
}

.screen.active {
    display: flex;
}

/* Map container — fills the game screen */
#map {
    position: absolute;
    inset: 0;
    z-index: 1;
    background: #b3d4f0;
    width: 100%;
    height: 100%;
}

/* Start screen */
#start-screen {
    background: rgba(13, 27, 42, 0.92);
    align-items: center;
    justify-content: center;
    overflow-y: auto;
}

.start-content {
    text-align: center;
    padding: 2rem 1rem;
    max-width: 500px;
    width: 100%;
}

.logo-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.logo-img {
    width: 120px;
    height: 120px;
    border-radius: 24px;
    object-fit: contain;
}

.logo-title {
    font-size: 2.2rem;
    font-weight: 800;
    color: #e53935;
    margin: 0;
    letter-spacing: 2px;
    text-shadow: 0 2px 10px rgba(229, 57, 53, 0.3);
}

.tagline {
    color: #90a4ae;
    font-size: 1rem;
    margin-bottom: 2rem;
}

.level-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 2rem;
}

.level-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
    padding: 1.5rem 1rem;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 1rem;
    color: #e0e0e0;
    cursor: pointer;
    transition: all 0.2s ease;
    backdrop-filter: blur(10px);
}

.level-card:hover,
.level-card:active {
    background: rgba(79, 195, 247, 0.15);
    border-color: #4fc3f7;
    transform: translateY(-2px);
}

.level-icon {
    font-size: 2.5rem;
}

.level-title {
    font-size: 1.3rem;
    font-weight: 700;
}

.level-desc {
    font-size: 0.85rem;
    color: #90a4ae;
}

.best-scores {
    color: #78909c;
    font-size: 0.85rem;
    line-height: 1.6;
}

.best-title {
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.best-item {
    display: flex;
    justify-content: space-between;
    padding: 0.2rem 0;
}

.best-val {
    color: #ffab40;
    font-weight: 600;
}

/* Game HUD — overlays the map */
#game-hud {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 20;
    pointer-events: none;
}

#game-hud .hud-top {
    pointer-events: auto;
}

#game-hud .hud-target {
    pointer-events: auto;
}

.hud-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem;
    background: rgba(13, 27, 42, 0.85);
    backdrop-filter: blur(10px);
}

.hud-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #e0e0e0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.hud-btn:hover {
    background: rgba(255, 80, 80, 0.3);
}

.hud-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
}

.hud-level {
    font-size: 0.75rem;
    color: #90a4ae;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.hud-progress {
    font-size: 1rem;
    font-weight: 600;
    color: #e0e0e0;
}

.hud-score {
    display: flex;
    align-items: center;
    gap: 0.2rem;
    background: rgba(0, 0, 0, 0.3);
    padding: 0.3rem 0.7rem;
    border-radius: 1rem;
    font-size: 0.9rem;
}

.score-label {
    color: #90a4ae;
    font-size: 0.75rem;
}

#hud-score {
    font-weight: 700;
    color: #ffab40;
}

.score-unit {
    color: #90a4ae;
    font-size: 0.75rem;
}

.hud-timer-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 48px;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 0.5rem;
    padding: 0.15rem 0.4rem;
}

.hud-timer {
    font-size: 1.1rem;
    font-weight: 700;
    color: #4fc3f7;
    transition: color 0.3s ease;
}

.hud-timer.timer-warning {
    color: #ff5252;
    animation: timer-pulse 0.5s ease-in-out infinite alternate;
}

@keyframes timer-pulse {
    from {
        transform: scale(1);
    }

    to {
        transform: scale(1.15);
    }
}

.hud-target {
    text-align: center;
    padding: 0.6rem 1rem;
    margin: 0.5rem auto;
    width: fit-content;
    max-width: 90%;
    background: rgba(13, 27, 42, 0.9);
    backdrop-filter: blur(10px);
    border-radius: 0 0 1rem 1rem;
    border: 1px solid rgba(79, 195, 247, 0.3);
    border-top: none;
}

.target-label {
    color: #90a4ae;
    font-size: 0.8rem;
    margin-right: 0.5rem;
}

.target-name {
    font-size: 1.3rem;
    font-weight: 700;
    color: #4fc3f7;
}

/* Flag display — shows flag image on game screen */
.flag-display {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 15;
    background: rgba(13, 27, 42, 0.95);
    border: 2px solid rgba(79, 195, 247, 0.3);
    border-radius: 1rem;
    padding: 1rem;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.5);
    max-width: 90vw;
    max-height: 50vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.flag-image {
    display: block;
    max-width: 100%;
    max-height: 45vh;
    object-fit: contain;
    border-radius: 0.5rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

/* Flag answer buttons — 2x2 grid at bottom of game screen */
.flag-answers {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 15;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
    width: 90%;
    max-width: 400px;
}

.flag-answer {
    padding: 0.8rem 1rem;
    background: rgba(13, 27, 42, 0.92);
    border: 2px solid rgba(255, 255, 255, 0.15);
    border-radius: 0.8rem;
    color: #e0e0e0;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    backdrop-filter: blur(10px);
    text-align: center;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.flag-answer:hover,
.flag-answer:active {
    background: rgba(79, 195, 247, 0.15);
    border-color: #4fc3f7;
    transform: translateY(-2px);
}

.flag-answer.correct {
    background: rgba(76, 175, 80, 0.3);
    border-color: #4caf50;
    color: #4caf50;
}

.flag-answer.wrong {
    background: rgba(244, 67, 54, 0.3);
    border-color: #f44336;
    color: #f44336;
}

.flag-answer:disabled {
    opacity: 0.5;
    cursor: default;
    transform: none;
}

/* Hidden utility */
.hidden {
    display: none !important;
}

/* Result screen */
#result-screen {
    background: rgba(13, 27, 42, 0.95);
    align-items: center;
    justify-content: center;
    overflow-y: auto;
}

.result-content {
    text-align: center;
    padding: 1.5rem 1rem;
    max-width: 500px;
    width: 100%;
}

.result-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.8rem;
    margin-bottom: 1rem;
}

.result-logo {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    object-fit: contain;
}

#result-title {
    font-size: 1.8rem;
    margin: 0;
    color: #4fc3f7;
}

#result-canvas-wrap {
    margin-bottom: 1rem;
    border-radius: 1rem;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

#result-canvas {
    width: 100%;
    height: auto;
    display: block;
}


.rating-perfect {
    color: #4caf50;
}

.rating-great {
    color: #8bc34a;
}

.rating-good {
    color: #cddc39;
}

.rating-ok {
    color: #ffc107;
}

.rating-bad {
    color: #ff9800;
}

.rating-terrible {
    color: #f44336;
}

.result-actions {
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
}

.btn-primary,
.btn-secondary {
    padding: 0.9rem 1.5rem;
    border: none;
    border-radius: 0.8rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-primary {
    background: linear-gradient(135deg, #4fc3f7, #29b6f6);
    color: #0d1b2a;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: #e0e0e0;
    border: 1px solid rgba(255, 255, 255, 0.15);
}

/* Toast */
.toast {
    position: fixed;
    bottom: auto;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.8);
    background: rgba(13, 27, 42, 0.95);
    color: #e0e0e0;
    padding: 1rem 2rem;
    border-radius: 3rem;
    font-size: 1.6rem;
    font-weight: 700;
    z-index: 9999;
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
    max-width: 90vw;
    white-space: nowrap;
    text-align: center;
    border: 1px solid rgba(79, 195, 247, 0.3);
}

.toast.show {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
}


.toast.hit {
    border-color: #4caf50;
    color: #4caf50;
}

.toast.miss {
    border-color: #ffab40;
    color: #ffab40;
}

/* Mobile portrait: compact toast */
@media (max-width: 480px) {
    .toast {
        font-size: 1.3rem;
        padding: 0.7rem 1.2rem;
        border-radius: 2rem;
        max-width: 92vw;
        white-space: nowrap;
    }
}

/* Mobile landscape: also compact */
@media (max-height: 480px) {
    .toast {
        font-size: 1.1rem;
        padding: 0.5rem 1rem;
        border-radius: 1.5rem;
        max-width: 85vw;
        white-space: nowrap;
    }
}

/* Leaflet overrides */
.leaflet-container {
    background: #2f353b !important;
}

/* No tile layer is used — only GeoJSON country polygons.
   This gives a clean map with no labels for the game. */

/* Attribution is hidden, but just in case */
.leaflet-control-attribution {
    display: none !important;
}

.leaflet-control-zoom {
    display: none !important;
}

/* Map markers */
.click-marker {
    background: #ff5252;
    border: 2px solid #fff;
    border-radius: 50%;
    box-shadow: 0 0 8px rgba(255, 82, 82, 0.8);
}

.target-marker {
    background: #00e676;
    border: 3px solid #fff;
    border-radius: 50%;
    box-shadow: 0 0 16px rgba(0, 230, 118, 1), 0 0 32px rgba(0, 230, 118, 0.6);
    animation: target-pulse 1.2s ease-in-out infinite;
}

@keyframes target-pulse {

    0%,
    100% {
        box-shadow: 0 0 16px rgba(0, 230, 118, 1), 0 0 32px rgba(0, 230, 118, 0.6);
    }

    50% {
        box-shadow: 0 0 24px rgba(0, 230, 118, 1), 0 0 48px rgba(0, 230, 118, 0.8);
    }
}

/* Loading overlay */
.loading {
    position: fixed;
    inset: 0;
    background: #0d1b2a;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    flex-direction: column;
    gap: 1rem;
}

.loading.hidden {
    display: none;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(79, 195, 247, 0.2);
    border-top-color: #4fc3f7;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-text {
    color: #90a4ae;
    font-size: 0.9rem;
}

/* Mobile portrait: compact HUD */
@media (max-width: 480px) {
    #start-screen {
        justify-content: flex-start;
        padding-top: 1rem;
    }

    .start-content {
        padding-top: 0.5rem;
    }

    .logo-img {
        width: 72px;
        height: 72px;
    }

    .logo-title {
        font-size: 1.6rem;
    }

    .hud-top {
        padding: 0.3rem 0.4rem;
        gap: 0.2rem;
    }

    .hud-btn {
        width: 30px;
        height: 30px;
        font-size: 0.9rem;
    }

    .hud-info {
        gap: 0;
    }

    .hud-level {
        font-size: 0.6rem;
    }

    .hud-progress {
        font-size: 0.8rem;
    }

    .hud-score {
        padding: 0.2rem 0.5rem;
        font-size: 0.75rem;
        gap: 0.1rem;
    }

    .score-label {
        font-size: 0.6rem;
    }

    #hud-score {
        font-size: 0.85rem;
    }

    .score-unit {
        font-size: 0.6rem;
    }

    .hud-timer-wrap {
        min-width: 48px;
        flex-shrink: 0;
        background: rgba(0, 0, 0, 0.4);
        border-radius: 0.5rem;
        padding: 0.15rem 0.4rem;
    }

    .hud-timer {
        font-size: 1.2rem;
        font-weight: 900;
        color: #4fc3f7;
        text-shadow: 0 0 8px rgba(79, 195, 247, 0.5);
        display: block;
        text-align: center;
    }

    .hud-timer.timer-warning {
        color: #ff1744;
        text-shadow: 0 0 12px rgba(255, 23, 68, 0.8);
    }

    .hud-target {
        padding: 0.4rem 0.8rem;
    }

    .target-label {
        font-size: 0.7rem;
    }

    .target-name {
        font-size: 1rem;
    }
}

/* Mobile landscape: even more compact */
@media (max-height: 480px) {
    .hud-top {
        padding: 0.2rem 0.4rem;
    }

    .hud-score {
        font-size: 0.7rem;
        padding: 0.15rem 0.4rem;
    }

    #hud-score {
        font-size: 0.8rem;
    }

    .hud-target {
        padding: 0.3rem 0.6rem;
        margin: 0.2rem auto;
    }

    .target-name {
        font-size: 0.9rem;
    }
}

/* Desktop: level cards in a row */
@media (min-width: 600px) {
    .level-cards {
        display: flex;
        flex-direction: row;
    }

    .level-card {
        flex: 1;
    }
}