@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300..700&display=swap');

:root {
    --bg-color: #EBEBEB;
    --text-primary: #004E98;
    --text-secondary: #3A6EA5;
    --card-bg: #FFFFFF;
    --accent-color: #FF6700;
    --border-color: #C0C0C0;
}

* {
    box-sizing: border-box;
}

body {
    font-family: "Space Grotesk", sans-serif;
    font-optical-sizing: auto;
    font-weight: 500;
    font-style: normal;
    background-color: var(--bg-color);
    color: var(--text-primary);
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* --- Layout --- */
.container {
    width: 100%;
    max-width: 95vw;
    margin: 0 auto;
    padding: 2rem;
    flex: 1;
}

/* --- Header & Nav --- */
header {
    padding: 0.25rem 0 0.5rem 0;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--card-bg);
}

h1.logo {
    font-size: 3.5rem;
    margin: 0 0 0.25rem 0;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--text-primary);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.75rem;
}

nav {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
}

nav a {
    text-decoration: none;
    color: var(--text-primary);
    background-color: var(--bg-color);
    padding: 0.5rem 1.5rem;
    font-weight: 600;
    font-size: 1.2rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    transition: all 0.2s ease;
}

nav a:hover {
    background-color: var(--text-secondary);
    color: var(--card-bg);
    border-color: var(--text-secondary);
}

nav a:active,
nav a.active {
    background-color: var(--accent-color);
    color: var(--card-bg);
    border-color: var(--accent-color);
}

.filter-btn {
    text-decoration: none;
    color: var(--text-primary);
    background-color: var(--bg-color);
    padding: 0.35rem 1rem;
    font-weight: 500;
    font-size: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    transition: all 0.2s ease;
    cursor: pointer;
    font-family: inherit;
}

.filter-btn:hover {
    background-color: var(--text-secondary);
    color: var(--card-bg);
    border-color: var(--text-secondary);
}

.filter-btn:active,
.filter-btn.active {
    background-color: var(--accent-color);
    color: var(--card-bg);
    border-color: var(--accent-color);
}

/* --- Page 1: Flag Grid --- */
.filter-controls {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 2rem;
}
.flag-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 1.5rem;
    margin-top: 2rem;
}

.flag-card {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.75rem;
    text-align: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.flag-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 15px rgba(0, 0, 0, 0.1);
}

.flag-card img {
    width: 100%;
    height: auto;
    aspect-ratio: 2560 / 1792;
    object-fit: cover;
    border: 1px solid var(--border-color);
    background-color: #fff;
    margin-bottom: 0.75rem;
    border-radius: 4px;
}

.flag-card h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

/* --- Page 2: Game Area --- */
.game-container {
    max-width: 600px;
    margin: 2rem auto;
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 2.5rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
    text-align: center;
}

.map-game-container {
    max-width: 1000px;
    margin: 1rem auto;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

/* Ensure the input keeps a readable width instead of stretching 1000px */
.map-game-container .input-group,
.map-game-container .game-controls {
    width: 100%;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

.game-flag-display {
    width: 100%;
    max-width: 320px; /* Make the actual footprint smaller as requested */
    margin: 0 auto;
    aspect-ratio: 640 / 448; /* Exact image ratio */
    display: flex;
    justify-content: center;
    align-items: center;
}

.game-flag-display img {
    width: 100%;
    height: 100%;
    object-fit: fill; /* Strech exactly to the hard container ratio */
    display: block;
}

.input-group {
    position: relative;
    margin-bottom: 1.5rem;
    text-align: left;
}

.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    font-size: 1.2rem;
}

.input-box {
    width: 100%;
    padding: 1rem;
    font-family: inherit;
    font-size: 1.2rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: var(--bg-color);
    color: var(--text-primary);
    outline: none;
    transition: box-shadow 0.2s, border-color 0.2s;
}

.input-box:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(255, 103, 0, 0.2);
}

/* Autocomplete Suggestions */
.suggestions-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background-color: var(--bg-color); /* Match page background instead of white */
    border: 1px solid var(--border-color);
    border-top: none;
    border-radius: 0 0 6px 6px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 10;
    display: none;
    margin: 0;
    padding: 0;
    list-style: none;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
}

.suggestions-list.active {
    display: block;
}

.suggestions-list li {
    padding: 0.8rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
}

.suggestions-list li:last-child {
    border-bottom: none;
}

.suggestions-list li:hover {
    background-color: var(--text-secondary);
    color: var(--card-bg);
}

.btn {
    font-family: inherit;
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--card-bg);
    background-color: var(--accent-color);
    padding: 1rem 2rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
    margin-top: 1rem;
    display: none;
    /* Hidden until selection */
}

.btn:hover {
    background-color: #e65c00;
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

.btn:active {
    transform: translateY(0);
    box-shadow: none;
}

.btn.visible {
    display: block;
}

.feedback {
    margin-top: 1.5rem;
    font-size: 1.5rem;
    font-weight: 700;
    min-height: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.feedback.success {
    color: #004E98; /* New Deep Blue from palette */
}

.feedback.error {
    color: var(--accent-color);
}

.game-controls {
    margin-top: 2rem;
    min-height: 3.5rem;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

.btn-secondary {
    background-color: var(--bg-color);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background-color: var(--border-color);
}

.btn-reveal {
    background-color: var(--bg-color); /* Same as page background to make it less prominent */
    color: var(--accent-color);
    border: 1px solid var(--accent-color);
}

.btn-reveal:hover {
    background-color: var(--accent-color);
    color: var(--card-bg);
}

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

/* --- Footer --- */
footer {
    text-align: center;
    padding: 2rem;
    border-top: 1px solid var(--border-color);
    background-color: transparent; /* blended with body background */
    margin-top: auto;
    font-weight: 600;
}

footer p {
    margin: 0.5rem 0;
}

footer a {
    color: var(--accent-color);
    text-decoration: none;
    font-weight: 700;
}

footer a:hover {
    text-decoration: underline;
}

/* --- MapGuessr SVG Styles --- */
#full-width-map-wrapper,
#full-width-flag-wrapper {
    width: 100%;
    display: flex;
    justify-content: center;
    padding: 1rem 1rem 0 1rem; /* Adjust top padding to match */
}

#map-container {
    width: 100%;
    max-width: 1000px;
    aspect-ratio: 2 / 1; /* Typical for equirectangular/natural earth projections */
    background-color: #A9D6E5; /* Light retro ocean blue to fit theme better */
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    position: relative;
    cursor: grab;
}

#map-container:active {
    cursor: grabbing;
}

/* Zoom Reset Button */
.btn-reset-zoom {
    position: absolute;
    bottom: 0.75rem;
    right: 0.75rem;
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    color: var(--text-primary);
    transition: all 0.2s ease;
    z-index: 10;
}

.btn-reset-zoom:hover {
    background-color: var(--bg-color);
    transform: scale(1.05);
}

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

.country-path {
    fill: var(--card-bg); /* Matches the card styling for land */
    stroke: var(--border-color);
    stroke-width: 0.5px;
    vector-effect: non-scaling-stroke;
    transition: fill 0.3s ease;
}

.country-path.highlight {
    fill: var(--accent-color); /* The red accent for the highlighted country */
    stroke: var(--card-bg);
    stroke-width: 1.5px;
}

/* --- Responsive Media Queries --- */
@media (max-width: 768px) {

    /* Header & Nav */
    h1.logo {
        font-size: 2rem;
    }

    nav {
        gap: 0.6rem; 
    }

    nav a {
        font-size: 0.75rem;
        padding: 0.4rem 0.4rem;
        text-align: center;
        white-space: nowrap;
    }

    .container {
        padding: 1rem 0.5rem;
    }

    /* Page 1: Flag Grid */
    .filter-controls {
        flex-direction: row; 
        justify-content: center;
        width: 100%;
        gap: 0.3rem;
    }

    .filter-btn {
        width: auto;
        flex: 1;
        text-align: center;
        font-size: 0.7rem; 
        padding: 0.4rem 0.2rem;
        white-space: nowrap;
    }

    .flag-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 1rem;
        margin-top: 1.5rem;
    }

    .flag-card {
        padding: 0.5rem;
    }

    .flag-card h3 {
        font-size: 0.9rem;
    }

    /* Page 2: Game Area */
    .game-container {
        padding: 1.5rem;
        margin: 1rem auto;
    }

    #full-width-flag-wrapper {
        padding: 1.5rem 1.5rem 0 1.5rem; /* Add top padding so it doesn't touch header */
        width: 100vw;
        max-width: 100vw;
    }

    .game-flag-display {
        width: 100%;
        max-width: 250px; /* Reduce max-width on mobile to shrink the flag further */
        height: auto;
        margin: 0 auto; /* Remove all top and bottom vertical margin */
        aspect-ratio: 640 / 448;
    }
    
    .game-flag-display img {
        width: 100%;
        height: 100%;
        max-width: 100%;
        object-fit: fill;
    }

    .input-box {
        font-size: 1rem;
        padding: 0.75rem;
    }

    .input-group label {
        font-size: 1rem;
    }

    .btn {
        font-size: 1rem;
        padding: 0.75rem 1.5rem;
    }

    .feedback {
        font-size: 1.2rem;
        min-height: 2rem;
    }

    /* Footer */
    footer {
        padding: 1rem;
    }

    .credits {
        font-size: 0.8rem !important;
    }

    /* Map Expansion for Mobile */
    .game-container.map-game-container {
        padding: 0;
        margin: 0;
        border: none;
        box-shadow: none;
    }

    #full-width-map-wrapper {
        padding: 0;
        width: 100vw;
        max-width: 100vw;
    }

    #map-container {
        width: 100vw;
        max-width: 100vw;
        margin-left: 0;
        margin-right: 0;
        border: none;
        border-radius: 0;
        aspect-ratio: 1 / 1.2; /* Taller height on mobile per user request */
    }

    .btn-reset-zoom {
        width: 26px;
        height: 26px;
        bottom: 0.5rem;
        right: 0.5rem;
        padding: 4px; /* Ensure SVG fits */
    }

    .btn-reset-zoom svg {
        width: 14px;
        height: 14px;
    }
}