:root {
    --bg-main: #E0F2F1;
    /* Light Teal */
    --primary: #009688;
    --secondary: #FF7043;
    --text: #37474F;
    --ocean: #B3E5FC;
    --land: #ECEFF1;
    --land-hover: #FFF9C4;
    --land-select: #C5E1A5;
}

body {
    font-family: 'Quicksand', sans-serif;
    margin: 0;
    background: var(--bg-main);
    overflow: hidden;
    user-select: none;
}

#app {
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Common UI */
.screen {
    position: absolute;
    width: 100%;
    height: 100%;
    background: var(--bg-main);
    display: none;
    z-index: 10;
}

.screen.active {
    display: flex;
    flex-direction: column;
}

/* Top Nav - Restructured */
.top-nav {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 95%;
    max-width: 600px;
    padding: 15px 20px;
    z-index: 500;
    /* Above everything */
    pointer-events: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: white;
    border-radius: 0 0 20px 20px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.top-nav * {
    pointer-events: auto;
}

/* In-Game Header specifically needed? */
.game-header {
    display: flex;
    justify-content: space-between;
    width: 100%;
}

.nav-left,
.nav-right {
    display: flex;
    gap: 15px;
}

.icon-btn,
.mini-btn {
    border: none;
    background: white;
    width: 55px;
    /* Bigger buttons */
    height: 55px;
    border-radius: 15px;
    font-size: 1.8rem;
    cursor: pointer;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    transition: transform 0.1s;
    display: flex;
    justify-content: center;
    align-items: center;
}

.icon-btn:hover,
.mini-btn:hover {
    transform: scale(1.1);
}

.icon-btn.active {
    border: 3px solid var(--primary);
    background: #E0F2F1;
}

.nav-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Fix for images inside buttons */
.icon-btn img {
    width: 25px;
    height: 25px;
    object-fit: contain;
    pointer-events: none;
}

/* Flash Msg - Moved Up */
.flash-msg {
    position: absolute;
    top: 20%;
    /* Higher up, avoiding center map */
    left: 50%;
    transform: translate(-50%, -50%) scale(0.5);
    background: white;
    color: var(--text);
    padding: 15px 30px;
    border-radius: 30px;
    font-size: 1.4rem;
    font-weight: bold;
    opacity: 0;
    pointer-events: none;
    z-index: 600;
    transition: all 0.2s;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    border: 3px solid #ff5252;
}

.flash-msg.active {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

/* Menu */
#menu-screen {
    align-items: center;
    justify-content: center;
    overflow-y: auto;
    padding: 20px;
}

/* Menu Content */
.menu-content {
    background: white;
    padding: 20px;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    text-align: center;
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    /* Limitar altura para permitir scroll */
    overflow-y: auto;
    /* Permitir scroll vertical */
    border: 3px solid var(--primary);
    position: relative;
    z-index: 10;
}

.game-logo {
    display: block;
    margin: 0 auto 8px auto;
    max-width: 100px;
    /* Más pequeño en móvil */
    height: auto;
}

.game-title {
    font-family: 'Fredoka', sans-serif;
    font-size: 2.2rem;
    /* Reducido para móvil */
    color: var(--primary);
    margin-bottom: 5px;
    line-height: 1;
    text-shadow: 2px 2px 0 #B2DFDB;
}

.subtitle {
    color: #777;
    margin-bottom: 15px;
    font-weight: bold;
    font-size: 1rem;
}

.game-desc {
    margin-bottom: 15px;
    color: #555;
    font-size: 0.9rem;
    line-height: 1.4;
    padding: 0 5px;
}

.mode-selector,
.region-selector {
    margin-bottom: 15px;
    /* Reducido */
    text-align: left;
}

h3 {
    margin: 0 0 8px 0;
    /* Reducido */
    color: var(--primary);
    font-size: 1rem;
    /* Reducido */
}

.mode-btns {
    display: flex;
    gap: 10px;
    /* Reducido */
}

.mode-btn {
    flex: 1;
    padding: 12px;
    /* Reducido */
    border: 2px solid #EEE;
    border-radius: 12px;
    background: #FAFAFA;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    transition: all 0.2s;
    font-size: 0.9rem;
    /* Reducido */
}

.mode-btn.active {
    border-color: var(--primary);
    background: #E0F2F1;
    color: var(--primary);
}

.region-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    /* Reducido */
}

.region-btn {
    padding: 8px;
    /* Reducido */
    border: 2px solid #EEE;
    border-radius: 10px;
    background: #FAFAFA;
    cursor: pointer;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    /* Reducido */
}

.region-btn.active {
    border-color: var(--secondary);
    background: #FBE9E7;
    color: var(--secondary);
}

.start-btn {
    width: 100%;
    padding: 15px;
    /* Reducido */
    background: var(--primary);
    color: white;
    font-size: 1.3rem;
    /* Reducido */
    font-weight: bold;
    border: none;
    border-radius: 15px;
    cursor: pointer;
    box-shadow: 0 5px 0 #00796B;
    transition: transform 0.1s;
    margin-top: 5px;
    /* Añadido */
}

.start-btn:active {
    transform: translateY(4px);
    box-shadow: none;
}

/* Game Interface */
.hud-bar {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 95%;
    max-width: 600px;
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 500;
    /* Above all */
    background: white;
    border-radius: 20px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.15);
    border: 3px solid var(--primary);
    pointer-events: auto !important;
    /* Force interactive */
}

.stats-container {
    display: flex;
    gap: 15px;
    align-items: center;
}

.stat-box {
    background: #E0F2F1;
    padding: 8px 12px;
    border-radius: 12px;
    font-weight: bold;
    font-size: 1.1rem;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
}

.hidden {
    display: none !important;
}

/* Map */
#map-container {
    width: 100%;
    height: 100%;
    background: var(--ocean);
    z-index: 1;
}

.leaflet-container {
    background: var(--ocean);
    font-family: 'Quicksand', sans-serif;
}

.leaflet-control-zoom {
    bottom: 20px;
    right: 20px;
    top: auto !important;
    left: auto !important;
    border: none !important;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1) !important;
}

/* Question Bar */
.question-bar {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: white;
    padding: 15px 30px;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    gap: 20px;
    z-index: 500;
    width: 90%;
    max-width: 600px;
    border: 4px solid var(--primary);
}

.flag-container {
    width: 80px;
    height: 50px;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
    background: #EEE;
}

.flag-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.question-text {
    flex-grow: 1;
    text-align: left;
}

.question-text span {
    font-size: 0.9rem;
    color: #888;
    text-transform: uppercase;
    font-weight: bold;
}

.question-text h2 {
    margin: 5px 0 0 0;
    font-family: 'Fredoka', sans-serif;
    color: var(--text);
    font-size: 1.8rem;
    line-height: 1;
}


/* Modal */
.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.modal-overlay.active {
    display: flex;
    animation: fadeIn 0.3s;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 20px;
    text-align: center;
    width: 90%;
    max-width: 400px;
}

.action-btn {
    width: 100%;
    padding: 15px;
    margin-top: 10px;
    border: none;
    border-radius: 10px;
    font-size: 1.2rem;
    cursor: pointer;
    font-weight: bold;
    background: var(--primary);
    color: white;
}

.action-btn.secondary {
    background: #90A4AE;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes popIn {
    from {
        transform: scale(0.8);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.modal-overlay.active .modal-content {
    animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-content {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}

/* Mobile Tweaks */
@media (max-width: 600px) {
    #menu-screen {
        padding: 10px;
        /* Reducir padding en móvil */
    }

    .menu-content {
        padding: 15px;
        /* Más compacto */
        width: 95%;
        /* Usar más espacio */
    }

    .game-logo {
        max-width: 80px;
        /* Más pequeño en móvil */
    }

    .game-title {
        font-size: 2rem;
        /* Más pequeño */
    }

    .subtitle {
        font-size: 0.9rem;
        margin-bottom: 10px;
    }

    .game-desc {
        font-size: 0.85rem;
    }

    h3 {
        font-size: 0.9rem;
    }

    .mode-btn {
        padding: 10px;
        font-size: 0.85rem;
    }

    .region-btn {
        padding: 6px;
        font-size: 0.8rem;
    }

    .start-btn {
        padding: 12px;
        font-size: 1.1rem;
    }

    .question-bar {
        bottom: 80px;
        padding: 10px 15px;
        width: 95%;
    }

    .question-text h2 {
        font-size: 1.4rem;
    }

    .flag-container {
        width: 60px;
        height: 40px;
    }

    .leaflet-control-zoom {
        bottom: 160px;
    }

    /* Move zoom above question bar on mobile */
    .hud-bar {
        top: 10px;
        width: 98%;
        padding: 8px 15px;
    }

    .stat-box {
        font-size: 0.9rem;
        padding: 5px 8px;
    }

    .icon-btn,
    .mini-btn {
        width: 45px;
        height: 45px;
        font-size: 1.5rem;
    }
}

/* Map Hints */
@keyframes pulseGreen {
    0% {
        fill-opacity: 0.5;
        stroke-width: 1;
    }

    50% {
        fill-opacity: 0.9;
        stroke-width: 4;
        stroke: #00E676;
    }

    100% {
        fill-opacity: 0.5;
        stroke-width: 1;
    }
}

.highlight-correct {
    animation: pulseGreen 0.5s 3;
    fill: #00C853 !important;
    fill-opacity: 1 !important;
}

/* =========================================
   RANKINGS STYLES
   ========================================= */

/* Rankings Button in Menu */
button.rankings-btn {
    /* Increased specificity */
    width: 100%;
    padding: 15px !important;
    border: none !important;
    border-radius: 15px !important;
    cursor: pointer;
    font-weight: bold;
    font-family: 'Quicksand', sans-serif;
    transition: transform 0.1s;
    box-shadow: 0 5px 0 #CC8800 !important;
    margin-top: 15px !important;
    color: #37474F !important;
    text-transform: uppercase;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

button.rankings-btn:active {
    transform: translateY(4px);
    box-shadow: none !important;
}

/* Rankings Screen Container */
#rankings-screen {
    background: var(--bg-main);
    padding: 20px;
    padding-top: 100px;
    /* Space for Top Nav */
    overflow-y: auto;
    display: none;
    /* Default hidden */
}

#rankings-screen.active {
    display: flex;
    /* Override display: none when active */
    flex-direction: column;
}

.rankings-content {
    width: 95%;
    max-width: 800px;
    margin: 0 auto;
    background: white;
    border-radius: 20px;
    padding: 25px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
}

.rankings-header {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 3px solid var(--primary);
}

.rankings-header h2 {
    flex: 1;
    text-align: center;
    color: var(--primary);
    margin: 0;
    font-family: 'Fredoka', sans-serif;
    font-size: 2rem;
}

/* Filters */
.rankings-filters {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 25px;
    padding: 20px;
    background: #F5F5F5;
    border-radius: 15px;
    border: 1px solid #EEE;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.filter-group label {
    font-weight: 700;
    color: var(--text);
    font-size: 0.95rem;
    margin-left: 5px;
}

.filter-group select {
    padding: 12px 15px;
    border: 2px solid #E0E0E0;
    border-radius: 12px;
    background: white;
    font-family: 'Quicksand', sans-serif;
    font-size: 1rem;
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s;
    appearance: none;
    /* Custom Arrow for select */
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 15px center;
    background-size: 15px;
}

.filter-group select:hover {
    border-color: #B2DFDB;
}

.filter-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(0, 150, 136, 0.1);
}

/* List */
.rankings-list {
    max-height: 500px;
    overflow-y: auto;
    padding-right: 5px;
}

/* Scrollbar Style */
.rankings-list::-webkit-scrollbar {
    width: 8px;
}

.rankings-list::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.rankings-list::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

.rankings-list::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}

.ranking-item {
    display: flex;
    align-items: center;
    padding: 15px;
    margin-bottom: 10px;
    background: #FAFAFA;
    border-radius: 12px;
    transition: transform 0.2s, background 0.2s;
    border: 2px solid transparent;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.ranking-item:hover {
    transform: translateX(5px);
    background: white;
    border-color: #B2DFDB;
}

/* Medals / Top 3 */
.ranking-item.top-1 {
    background: linear-gradient(135deg, #FFF8E1 0%, #FFECB3 100%);
    border-color: #FFC107;
}

.ranking-item.top-2 {
    background: linear-gradient(135deg, #F5F5F5 0%, #E0E0E0 100%);
    border-color: #BDBDBD;
}

.ranking-item.top-3 {
    background: linear-gradient(135deg, #FBE9E7 0%, #FFCCBC 100%);
    border-color: #FF7043;
}

.rank-position {
    font-size: 1.3rem;
    font-weight: 800;
    min-width: 50px;
    text-align: center;
    color: #546E7A;
}

.rank-flag {
    margin: 0 15px;
    flex-shrink: 0;
}

.rank-nickname {
    flex: 1;
    font-weight: 700;
    color: var(--text);
    font-size: 1.1rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rank-score {
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--primary);
    margin-right: 15px;
    font-family: 'Fredoka', sans-serif;
}

.rank-date {
    font-size: 0.85rem;
    color: #90A4AE;
    margin-left: 10px;
}

/* Nickname Screen */
#nickname-screen {
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

#nickname-screen.active {
    display: flex;
}

.nickname-content {
    background: white;
    padding: 40px;
    border-radius: 25px;
    text-align: center;
    max-width: 450px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
    0% {
        transform: scale(0.8);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.nickname-emoji {
    font-size: 5rem;
    margin-bottom: 20px;
    animation: bounce 2s infinite;
}

.nickname-form input {
    width: 100%;
    padding: 15px;
    margin-bottom: 15px;
    border: 3px solid #E0E0E0;
    border-radius: 12px;
    font-size: 1.2rem;
    font-family: 'Quicksand', sans-serif;
    text-align: center;
    box-sizing: border-box;
    transition: border-color 0.2s;
}

.nickname-form input:focus {
    outline: none;
    border-color: var(--primary);
}

/* Mobile Adjustments */
@media (max-width: 600px) {
    #rankings-screen {
        padding-top: 85px;
        /* Top Nav height */
        padding-left: 10px;
        padding-right: 10px;
    }

    .rankings-content {
        padding: 15px;
        width: 100%;
        box-sizing: border-box;
    }

    .rankings-filters {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .ranking-item {
        padding: 10px;
    }

    .rank-date {
        display: none;
        /* Hide date on mobile */
    }

    .rank-nickname {
        font-size: 1rem;
    }

    .rank-position {
        font-size: 1.1rem;
        min-width: 35px;
    }
}

/* Mobile Menu Adjustments */
@media (max-width: 600px) {

    /* Narrower Menu */
    .menu-content {
        width: 80% !important;
        max-width: 350px !important;
        padding: 15px !important;
    }

    /* Wider Play Button (relative to menu) with more impact */
    .start-btn {
        width: 100% !important;
        padding: 16px !important;
        font-size: 1.4rem !important;
        margin-top: 10px !important;
    }

    /* Narrower Rankings Button */
    button.rankings-btn {
        width: 70% !important;
        margin: 15px auto 5px auto !important;
        padding: 10px 15px !important;
        font-size: 1rem !important;
        border-radius: 25px !important;
        /* Estilo píldora */
    }
}