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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    /* Use normal document flow to allow vertical scrolling */
    display: block;
    padding: 20px;
}

.container {
    max-width: 1000px;
    width: 100%;
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: visible;
}

header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    text-align: center;
}

header h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
}

.subtitle {
    font-size: 1.2em;
    opacity: 0.9;
}

.game-container {
    padding: 20px 24px;
    /* Use a responsive grid so the map and controls can adapt to viewport size */
    display: grid;
    grid-template-columns: 1fr 360px;
    grid-template-rows: auto 1fr auto;
    gap: 18px 24px;
    align-items: start;
}

.level-selector {
    display: flex;
    gap: 10px;
    margin-bottom: 0;
    justify-content: center;
    grid-column: 1 / span 2;
}

.level-btn {
    padding: 12px 24px;
    border: 2px solid #667eea;
    background: white;
    color: #667eea;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1em;
    font-weight: bold;
    transition: all 0.3s ease;
}

.level-btn:hover {
    background: #f0f0f0;
}

.level-btn.active {
    background: #667eea;
    color: white;
}

.settings-container {
    display: flex;
    gap: 20px;
    justify-content: center;
    align-items: center;
    padding: 12px 16px;
    background: #fff8e1;
    border-radius: 10px;
    grid-column: 1 / span 2;
    flex-wrap: wrap;
}

.setting {
    display: flex;
    align-items: center;
    gap: 8px;
}

.setting label {
    font-weight: 600;
    color: #555;
}

.setting select,
.setting input[type="text"] {
    padding: 6px 12px;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 1em;
    background: white;
    cursor: pointer;
}

.setting input[type="text"] {
    width: 100px;
    cursor: text;
}

.setting input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
}

#timer-display {
    font-weight: 600;
    color: #667eea;
    margin-left: 8px;
}

.stats {
    display: flex;
    justify-content: space-around;
    margin-bottom: 0;
    padding: 12px 16px;
    background: #f8f9fa;
    border-radius: 10px;
    align-items: center;
    grid-column: 1 / span 2;
}

.stat {
    text-align: center;
}

.stat-label {
    font-size: 1em;
    color: #666;
    display: block;
    margin-bottom: 5px;
}

.stat-value {
    font-size: 2em;
    font-weight: bold;
    color: #667eea;
}

.map-container {
    background: linear-gradient(180deg, #f4f6f8 0%, #eef3f6 100%);
    border-radius: 10px;
    padding: 14px;
    margin-bottom: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    /* let the map expand; allow page to scroll if necessary */
    min-height: 300px;
    overflow: visible;
    grid-column: 1 / span 1;
}

#map {
    width: 100%;
    height: auto;
    display: block;
    /* limit max height so the map does not push controls offscreen */
    max-height: 100%;
}

.map-region {
    /* land: subtle earthy palette; actual fill comes from SVG gradient */
    stroke-linejoin: round;
    transition: transform 0.25s ease, opacity 0.25s ease;
    cursor: pointer;
    opacity: 0.98;
}

.map-region:hover {
    transform: translateY(-4px);
    opacity: 1;
    filter: drop-shadow(0 6px 10px rgba(0,0,0,0.08));
}

/* Disable hover transform on devices that don't support hover (touch devices) */
@media (hover: none) {
    .map-region:hover { transform: none; filter: none; }
}

.map-region.highlighted {
    /* marked province: solid black for strong contrast */
    fill: #000 !important;
    stroke: #222 !important;
    stroke-width: 1.5 !important;
}

.map-region-overlay {
    mix-blend-mode: multiply;
}

.province-label {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 10px;
    fill: #2b2b2b;
    pointer-events: none;
    text-shadow: 0 1px 0 #fff;
    opacity: 0.9;
}

/* label style when its province is highlighted */
.province-label.highlighted {
    fill: #fff;
    font-weight: 700;
    text-shadow: none;
}

.map-waterway {
    fill: none;
    transition: stroke-width 0.25s ease, opacity 0.25s ease;
    cursor: pointer;
    opacity: 0.95;
}

/* Filled water polygons (lakes, seas, estuaries) */
.map-waterbody {
    mix-blend-mode: multiply;
    transition: opacity 0.25s ease;
    stroke: rgba(255,255,255,0.18);
    stroke-width: 0.6;
    vector-effect: non-scaling-stroke;
    cursor: pointer;
}

.map-waterbody:hover {
    opacity: 1 !important;
}

.map-waterbody.highlighted {
    fill: #ff8a7a !important;
    opacity: 1 !important;
    filter: drop-shadow(0 6px 10px rgba(255, 138, 122, 0.15));
}

/* Shoreline rim for water polygons */
.map-waterbody-shore {
    fill: none;
    stroke: rgba(255,255,255,0.9);
    stroke-width: 1.6;
    stroke-linejoin: round;
    stroke-linecap: round;
    opacity: 0.95;
    pointer-events: none;
    filter: drop-shadow(0 1px 0 rgba(255,255,255,0.06));
}

.map-waterway:hover {
    opacity: 1;
    stroke-width: 10;
}

.map-waterway.highlighted {
    stroke: #ff8a7a !important;
    stroke-width: 14 !important;
    filter: drop-shadow(0 6px 10px rgba(255, 138, 122, 0.15));
}

@keyframes pulse {
    0%, 100% {
        fill: #ff6b6b;
    }
    50% {
        fill: #ff4444;
    }
}

@keyframes landPulse {
    0%, 100% { fill: #ffb4a2; }
    50% { fill: #ffa08b; }
}

@keyframes pulseWaterway {
    0%, 100% {
        stroke: #ff6b6b;
        stroke-width: 12;
    }
    50% {
        stroke: #ff4444;
        stroke-width: 14;
    }
}

.question-container {
    text-align: center;
    margin-bottom: 0;
    grid-column: 2 / span 1;
    align-self: start;
    padding-left: 6px;
}

.question-container h2 {
    color: #2c3e50;
    margin-bottom: 20px;
    font-size: 1.5em;
}

/* Mobile-specific map height cap and smoother scrolling */
@media (max-width: 600px) {
    .map-container {
        min-height: 220px;
        max-height: 48vh; /* cap to viewport height so controls remain visible */
        overflow: auto;
        -webkit-overflow-scrolling: touch;
    }

    #map { max-height: 100%; }

    /* Make control buttons full width on small screens */
    .controls { flex-direction: column; gap: 12px; }
    .controls button, .level-btn { width: 100%; padding: 14px 18px; }

    #answer-input { font-size: 1.05em; padding: 12px; }
}

/* Improve tap targets and reduce highlight flash */
button, .level-btn { touch-action: manipulation; -webkit-tap-highlight-color: rgba(0,0,0,0.05); }

#answer-input {
    width: 100%;
    max-width: 400px;
    padding: 15px;
    font-size: 1.1em;
    border: 2px solid #ddd;
    border-radius: 8px;
    margin-bottom: 15px;
    transition: border-color 0.3s ease;
}

#answer-input:focus {
    outline: none;
    border-color: #667eea;
}

.controls {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    grid-column: 2 / span 1;
}

button {
    padding: 15px 30px;
    font-size: 1.1em;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.3s ease;
}

#submit-btn {
    background: #667eea;
    color: white;
}

#submit-btn:hover {
    background: #5568d3;
}

#start-btn, #next-btn, #restart-btn {
    background: #51cf66;
    color: white;
}

#start-btn:hover, #next-btn:hover, #restart-btn:hover {
    background: #40c057;
}

.feedback {
    margin-top: 15px;
    padding: 15px;
    border-radius: 8px;
    font-size: 1.1em;
    font-weight: bold;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.feedback.correct {
    background: #d4edda;
    color: #155724;
    border: 2px solid #c3e6cb;
}

.feedback.incorrect {
    background: #f8d7da;
    color: #721c24;
    border: 2px solid #f5c6cb;
}

.feedback.hidden {
    display: none;
}

footer {
    background: #2c3e50;
    color: white;
    text-align: center;
    padding: 20px;
}

footer p {
    font-size: 0.9em;
    opacity: 0.8;
}

footer p.practice-link {
    margin-top: 10px;
    font-size: 0.85em;
}

footer a {
    color: #51cf66;
    text-decoration: none;
    font-weight: 600;
    transition: color 0.3s ease;
}

footer a:hover {
    color: #40c057;
    text-decoration: underline;
}

@media (max-width: 768px) {
    header h1 {
        font-size: 2em;
    }

    .game-container {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto 1fr auto;
        max-height: none;
    }

    .level-selector {
        flex-direction: row;
        gap: 8px;
        justify-content: center;
        grid-column: 1 / span 1;
    }

    .level-btn {
        width: auto;
    }

    .map-container {
        order: 3;
        min-height: 280px;
        max-height: none;
    }

    .question-container {
        grid-column: 1 / span 1;
        padding: 12px 8px;
    }

    .stat-value {
        font-size: 1.5em;
    }

    .question-container h2 {
        font-size: 1.15em;
    }
}
