:root {
    --bg-dark: #121212;
    --text-light: #ffffff;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --correct: #10b981;
    --wrong: #ef4444;
    --round-progress: #a78bfa;
    --glass-bg: rgba(20, 20, 25, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-light);
    overflow: hidden;
}

#map {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1;
}

.leaflet-container {
    background-color: var(--bg-dark) !important;
}

#ui-overlay {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 600px;
    z-index: 1000; /* Above Leaflet */
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.5);
}

/* Shared grid so the round bar, score bar, and guess input all line up:
   label column | flexible bar/input column | two button columns. Each row
   places its items explicitly into these columns (see below) so alignment
   holds even when a row has fewer than four children. */
.hud-row {
    display: grid;
    grid-template-columns: 52px 1fr 82px 68px;
    align-items: center;
    gap: 10px;
}

.hud-label {
    grid-column: 1;
    font-size: 0.8rem;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.7);
}

.hud-row .mini-bar {
    grid-column: 2 / 4;
}

#btn-stop {
    grid-column: 4;
}

#btn-config {
    grid-column: 4;
}

.mini-bar {
    position: relative;
    height: 18px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 9px;
    overflow: hidden;
}

.mini-bar-fill {
    height: 100%;
    background: var(--round-progress);
    transition: width 0.4s ease;
}

.score-bar-track .mini-bar-fill {
    background: var(--correct);
}

.mini-bar-label {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.68rem;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
    pointer-events: none;
}

.btn {
    padding: 6px 12px;
    border: none;
    border-radius: 6px;
    font-family: 'Inter', sans-serif;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    background: rgba(255,255,255,0.1);
    color: white;
    border: 1px solid rgba(255,255,255,0.2);
}

.btn:hover {
    background: rgba(255,255,255,0.2);
}

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

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

#btn-config {
    font-size: 1.1rem;
    line-height: 1;
    padding: 6px 10px;
}

#game-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.input-container {
    position: relative;
    width: 100%;
}

.input-wrapper {
    position: relative;
    grid-column: 1 / 3;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 8px;
    overflow: hidden;
}

/* Depletes from full to empty over the round (drives off roundPotential),
   replacing the old separate zoom-timer bar and "+N" counter. Sits behind the
   transparent input so typed text stays legible over both filled and empty
   regions. */
.input-progress-fill {
    position: absolute;
    inset: 0;
    z-index: 0;
    width: 0%;
    background: linear-gradient(90deg, rgba(59, 130, 246, 0.32), rgba(59, 130, 246, 0.12));
    transition: width 0.4s ease;
}

#btn-reveal {
    grid-column: 3;
}

#btn-skip {
    grid-column: 4;
}

#country-guess {
    position: relative;
    z-index: 1;
    width: 100%;
    padding: 15px;
    font-size: 1.1rem;
    font-family: 'Inter', sans-serif;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    background: transparent;
    color: var(--text-light);
    outline: none;
    transition: all 0.3s ease;
}

#country-guess:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

#country-guess:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.3);
}

.autocomplete-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 5px;
    background: rgba(30, 30, 35, 0.95);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    list-style: none;
    max-height: 200px;
    overflow-y: auto;
    color: var(--text-light);
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    z-index: 1001;
}

.autocomplete-list li {
    padding: 12px 15px;
    cursor: pointer;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.autocomplete-list li.active {
    background: var(--accent);
    color: #fff;
}


.hidden {
    display: none !important;
}

/* Messages */
.message {
    text-align: center;
    font-size: 1.2rem;
    font-weight: 600;
    margin-top: 10px;
}
.message.correct { 
    color: var(--correct); 
    border-color: var(--correct); 
}
.message.wrong { 
    color: var(--wrong); 
    border-color: var(--wrong); 
}

/* Tooltip for played countries */
.played-tooltip {
    background: transparent !important;
    border: none !important;
    color: #60a5fa !important; /* Light blue */
    font-weight: 800;
    box-shadow: none !important;
    border-radius: 0;
    font-family: 'Inter', sans-serif;
    padding: 0;
    text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000, 0 0 5px rgba(0,0,0,0.8);
}
.played-tooltip::before {
    display: none !important;
}

.revealed-tooltip {
    background: transparent !important;
    border: none !important;
    color: #9ca3af !important; /* Light gray */
    font-weight: 800;
    box-shadow: none !important;
    border-radius: 0;
    font-family: 'Inter', sans-serif;
    padding: 0;
    text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000, 0 0 5px rgba(0,0,0,0.8);
}
.revealed-tooltip::before {
    display: none !important;
}

/* Shake Animation */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}
.shake {
    animation: shake 0.3s ease-in-out;
    border-color: var(--wrong) !important;
}

/* Floating RPG Score */
.floating-score {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 64px;
    font-weight: 800;
    color: var(--correct);
    text-shadow: 0 0 20px rgba(0,0,0,0.8), -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000, 2px 2px 0 #000;
    z-index: 2000;
    pointer-events: none;
    animation: floatUp 2.5s ease-out forwards;
    font-family: 'Inter', sans-serif;
}

@keyframes floatUp {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.5);
    }
    10% {
        opacity: 1;
        transform: translate(-50%, -60%) scale(1.2);
    }
    20% {
        transform: translate(-50%, -60%) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -200%) scale(1);
    }
}

/* Game Over Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 3000;
}

.modal-content {
    padding: 40px;
    border-radius: 16px;
    text-align: center;
    min-width: 350px;
}

.modal-content h2 {
    margin: 0 0 20px 0;
    font-size: 36px;
    color: #fff;
}

.modal-stats {
    margin-bottom: 30px;
}

.modal-stats p {
    font-size: 22px;
    margin: 10px 0;
    font-weight: 600;
    color: var(--text-light);
}

.modal-actions {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.modal-actions .btn {
    width: 100%;
    padding: 15px;
    font-size: 1.2rem;
}

/* Config Pane */
#main-menu-modal {
    flex-direction: column;
    background: rgba(10, 10, 15, 0.95);
    backdrop-filter: blur(20px);
}
#main-menu-modal h2 {
    font-size: 48px;
    margin-bottom: 25px;
    background: linear-gradient(135deg, #60a5fa, #3b82f6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}
.config-pane {
    display: flex;
    flex-direction: column;
    gap: 24px;
    width: 480px;
    max-width: 90vw;
    background: rgba(255, 255, 255, 0.03);
    padding: 30px;
    border-radius: 16px;
    border: 1px solid rgba(255,255,255,0.05);
}
.config-item {
    display: flex;
    flex-direction: column;
    text-align: left;
    gap: 10px;
}
.config-item label {
    font-weight: 600;
    font-size: 15px;
    color: var(--text-light);
    display: flex;
    justify-content: space-between;
}
.config-checkbox-item label {
    justify-content: flex-start;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}
.config-checkbox-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
    cursor: pointer;
}
.config-checkbox-sublabel {
    margin-left: 28px;
    font-size: 14px !important;
    color: rgba(255, 255, 255, 0.7);
}
.config-checkbox-sublabel:has(input:disabled) {
    color: rgba(255, 255, 255, 0.35);
    cursor: not-allowed;
}
.config-checkbox-sublabel input:disabled {
    cursor: not-allowed;
}
.filters-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px 20px;
    background: rgba(255, 255, 255, 0.05);
    padding: 24px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: inset 0 2px 10px rgba(0,0,0,0.2);
}
.filter-slider {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.filter-slider label {
    font-size: 14px;
    font-weight: 500;
    color: #e2e8f0;
    display: flex;
    justify-content: space-between;
}
.filter-slider span {
    color: var(--accent);
    font-weight: 700;
}
.glass-input {
    background: rgba(30, 30, 35, 0.6);
    border: 1px solid var(--glass-border);
    color: #fff;
    padding: 12px 15px;
    border-radius: 8px;
    font-size: 16px;
    font-family: 'Inter', sans-serif;
    outline: none;
}
.glass-input:focus {
    border-color: var(--accent);
}
.glass-select {
    background: rgba(30, 30, 35, 0.6);
    border: 1px solid var(--glass-border);
    color: #fff;
    padding: 12px 15px;
    border-radius: 8px;
    font-size: 16px;
    font-family: 'Inter', sans-serif;
    outline: none;
    cursor: pointer;
}
.glass-select:focus {
    border-color: var(--accent);
}
input[type=range] {
    -webkit-appearance: none;
    width: 100%;
    background: transparent;
}
input[type=range]:focus {
    outline: none;
}
input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 18px;
    width: 18px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    margin-top: -7px;
    box-shadow: 0 0 12px var(--accent);
    transition: transform 0.1s ease;
}
input[type=range]::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}
input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 2px;
}
.glass-button {
    background: var(--accent);
    color: white;
    border: none;
    padding: 15px;
    border-radius: 8px;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 10px;
}
.glass-button:hover {
    background: #2563eb;
    transform: translateY(-2px);
}
.glass-button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}
.glass-button:disabled:hover {
    background: var(--accent);
    transform: none;
}

.config-summary {
    margin-top: 4px;
    font-size: 15px;
    font-weight: 600;
    color: var(--accent);
    text-align: center;
}

/* Flags when the sort order doesn't match the single active filter — amber
   reads as "notice this," not "error" (red is already used for wrong guesses
   elsewhere, so it would wrongly imply this combination is invalid). */
.order-mismatch {
    color: #f59e0b;
}

.creator-link {
    margin-top: 16px;
    font-size: 13px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.45);
    text-decoration: none;
    transition: color 0.2s ease;
}
.creator-link:hover {
    color: var(--accent);
}

#freeroam-hint {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}

/* Fact Card */
#fact-card {
    position: absolute;
    top: 50%;
    right: 40px;
    transform: translateY(-50%);
    width: 320px;
    padding: 25px;
    z-index: 2500;
    transition: opacity 0.3s ease, transform 0.3s ease;
    display: flex;
    flex-direction: column;
    gap: 15px;
    cursor: pointer;
}
#fact-card:hover {
    border-color: rgba(255,255,255,0.3);
}
#fact-country-name {
    margin: 0;
    font-size: 28px;
    color: var(--accent);
}
.fact-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.fact-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-bottom: 8px;
}
.fact-item-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px; /* guaranteed minimum — space-between alone leaves ~0px for the longest label ("GDP per Capita (PPP):") */
}
.fact-value-wrap {
    display: flex;
    align-items: baseline;
    gap: 6px;
}
/* Replaces the old plain divider: its fill length shows the country's rank
   for this stat (out of all 194), so the line does double duty instead of
   adding a new element. One neutral color — there's no "good" direction for
   area/population/GDP, so only position (not color) carries meaning. */
.fact-rank-bar {
    width: 100%;
    height: 3px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    overflow: hidden;
}
.fact-rank-bar-fill {
    height: 100%;
    width: 0%;
    background: var(--accent);
    transition: width 0.4s ease;
}
.fact-rank {
    font-size: 11px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.5);
    white-space: nowrap;
}
.fact-label {
    font-size: 14px;
    color: rgba(255,255,255,0.7);
}
.fact-value {
    font-size: 16px;
    font-weight: 600;
    color: #fff;
}
#btn-next-round {
    position: relative;
    overflow: hidden;
    margin-top: 10px;
    background: var(--correct);
}
#btn-next-round:hover {
    background: #16a34a;
}

/* Drains from full to empty over the fact card's 6s auto-advance window —
   so it's obvious the card will move on by itself if you don't click. A
   solid, distinctly darker green (not a translucent wash) so the covered vs.
   revealed regions read as two clearly different shades, not a subtle tint. */
.next-round-fill {
    position: absolute;
    inset: 0;
    z-index: 0;
    width: 100%;
    background: #065f46;
    pointer-events: none;
}

.btn-next-label {
    position: relative;
    z-index: 1;
}

/* ----- Mobile (kept last so it overrides the desktop rules above; does not affect desktop) ----- */
@media (max-width: 600px) {
    #ui-overlay {
        top: 10px;
        width: 94%;
        gap: 10px;
    }
    .glass-panel {
        padding: 14px;
    }
    .hud-row {
        grid-template-columns: 34px 1fr 56px 50px;
        gap: 8px;
    }
    .hud-label {
        font-size: 0.7rem;
    }
    .mini-bar {
        height: 15px;
    }
    .mini-bar-label {
        font-size: 0.6rem;
    }
    .btn {
        padding: 6px 10px;
        font-size: 0.85rem;
    }
    #country-guess {
        padding: 12px;
        font-size: 1rem;
    }

    /* Config menu */
    #main-menu-modal h2 {
        font-size: 2rem;
        margin-bottom: 16px;
    }
    .config-pane {
        padding: 20px;
        gap: 18px;
    }
    .filters-grid {
        padding: 16px;
        gap: 18px 14px;
    }

    /* Modals: drop the fixed min-width/padding so they never overflow the screen */
    .modal-content {
        min-width: 0;
        width: 92vw;
        padding: 28px 20px;
    }
    .modal-content h2 {
        font-size: 28px;
    }
    .modal-stats p {
        font-size: 18px;
    }
    .modal-actions .btn {
        padding: 13px;
        font-size: 1.05rem;
    }

    /* Fact card: dock to the bottom so the centered country stays visible */
    #fact-card {
        top: auto;
        bottom: 20px;
        transform: none;
        left: 12px;
        right: 12px;
        width: auto;
        padding: 18px;
    }
    #fact-country-name {
        font-size: 22px;
    }

    /* Trim the Next button's footprint — its own margin-top was stacking on
       top of the card's flex gap (redundant double-spacing), and the padding/
       font-size had room to shrink without dropping below a comfortable tap
       target. */
    #btn-next-round {
        padding: 10px 15px;
        margin-top: 0;
        font-size: 16px;
    }

    #freeroam-hint {
        font-size: 12px;
        padding: 8px 12px;
        max-width: 92vw;
        text-align: center;
    }
}
