:root {
    --bg-1: #eef4ff;
    --bg-2: #e8fbf4;
    --ink: #1f2d3d;
    --ink-soft: #5b6b7b;
    --card: rgba(255, 255, 255, 0.9);

    --primary-1: #4f8ff7;
    --primary-2: #2f6fe0;
    --accent-1: #ffa83d;
    --accent-2: #f57e20;
    --special-1: #a78bfa;
    --special-2: #7c3aed;
    --good-1: #34d399;
    --good-2: #0f9d6b;
    --bad-1: #fb7185;
    --bad-2: #e11d48;
    --slate-1: #9aa7b8;
    --slate-2: #647285;

    --radius: 12px;
    --shadow-sm: 0 2px 5px rgba(31, 45, 61, 0.14);
    --shadow-md: 0 4px 12px rgba(31, 45, 61, 0.18);
}

body, html {
    margin: 0;
    padding: 0;
    overflow-x: hidden;
}

/* The hidden attribute must win over explicit display rules below. */
[hidden] { display: none !important; }

body {
    font-family: "Baloo 2", "Trebuchet MS", Arial, sans-serif;
    text-align: center;
    color: var(--ink);
    background: linear-gradient(170deg, var(--bg-1), var(--bg-2));
    min-height: 100vh;
}

/* ---------------- Splash ---------------- */

#splash-screen {
    position: fixed;
    inset: 0;
    background: linear-gradient(125deg, #ffe1b0, #b4ecd0 45%, #b9def8);
    background-size: 300% 300%;
    animation: backgroundAnimation 16s ease infinite;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 10;
    transition: opacity 0.4s ease;
}

#splash-screen.fading {
    opacity: 0;
    pointer-events: none;
}

@keyframes backgroundAnimation {
    0%   { background-position: 0% 50%; }
    50%  { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

#splash-title {
    font-size: 62px;
    margin-bottom: 18px;
    font-family: 'Pacifico', cursive;
    transform: rotate(-5deg);
    background: linear-gradient(90deg, #ef6c2f, #7c3aed 55%, #2f6fe0);
    background-size: 220% 220%;
    animation: textGradientAnimation 6s ease infinite;
    color: transparent;
    background-clip: text;
    -webkit-background-clip: text;
}

@keyframes textGradientAnimation {
    0%   { background-position: 0% 50%; }
    50%  { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

#start-button {
    padding: 16px 44px;
    font-size: 1.5em;
    font-weight: 800;
    cursor: pointer;
    border: none;
    color: white;
    background: linear-gradient(180deg, var(--accent-1), var(--accent-2));
    border-radius: 999px;
    box-shadow: 0 6px 18px rgba(245, 126, 32, 0.45);
    transition: transform 0.12s ease, box-shadow 0.2s ease;
}

#start-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 9px 24px rgba(245, 126, 32, 0.55);
}

#start-button:active { transform: translateY(0); }

/* ---------------- Game layout ---------------- */

#game-container {
    display: none;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
    box-sizing: border-box;
    padding: 12px 12px 18px;
    position: relative;
}

#game-container.active {
    display: flex;
}

/* ---------------- Settings ---------------- */

#settings-button {
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 25;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid rgba(31, 45, 61, 0.12);
    background: var(--card);
    color: var(--ink-soft);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.25s ease, box-shadow 0.2s ease, color 0.2s ease;
}

#settings-button:hover {
    transform: rotate(40deg);
    box-shadow: var(--shadow-md);
    color: var(--primary-2);
}

#settings-panel {
    position: fixed;
    top: 64px;
    right: 12px;
    z-index: 25;
    width: 220px;
    background: #ffffff;
    border-radius: var(--radius);
    box-shadow: 0 10px 30px rgba(31, 45, 61, 0.22);
    border: 1px solid rgba(31, 45, 61, 0.08);
    padding: 12px 14px;
    text-align: left;
    animation: panelIn 0.18s ease-out;
}

@keyframes panelIn {
    from { opacity: 0; transform: translateY(-6px) scale(0.97); }
    to   { opacity: 1; transform: none; }
}

.settings-title {
    font-weight: 800;
    font-size: 0.95em;
    color: var(--ink);
    margin-bottom: 8px;
}

.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 0;
    font-size: 0.92em;
    color: var(--ink-soft);
    cursor: pointer;
}

.settings-row input { position: absolute; opacity: 0; pointer-events: none; }

.settings-row .switch {
    position: relative;
    width: 42px;
    height: 24px;
    border-radius: 999px;
    background: var(--slate-1);
    transition: background 0.2s ease;
    flex-shrink: 0;
}

.settings-row .switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
    transition: transform 0.2s ease;
}

.settings-row input:checked ~ .switch {
    background: linear-gradient(180deg, var(--good-1), var(--good-2));
}

.settings-row input:checked ~ .switch::after {
    transform: translateX(18px);
}

#reset-button {
    width: 100%;
    margin-top: 14px;
    padding: 15px 14px;
    border: none;
    border-radius: 11px;
    font: inherit;
    font-weight: 800;
    font-size: 1.05em;
    color: #fff;
    cursor: pointer;
    background: linear-gradient(180deg, var(--bad-1), var(--bad-2));
    box-shadow: var(--shadow-md);
    transition: transform 0.1s ease, box-shadow 0.2s ease;
}

#reset-button:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(225, 29, 72, 0.4); }
#reset-button:active { transform: translateY(0); }

/* ---------------- Counters ---------------- */

#counters {
    display: flex;
    justify-content: center;
    gap: 28px;
    margin: 4px 0 10px;
    flex: 0 0 auto;
}

.counter {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.counter-label {
    font-size: 0.8em;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--ink-soft);
    font-weight: 700;
}

/* ---------------- Roller (odometer digits) ---------------- */

.roller {
    display: inline-flex;
    gap: 3px;
    line-height: 1;
    font-size: 2.4em;
    font-weight: 800;
}

.roller-digit {
    position: relative;
    display: inline-block;
    width: 0.72em;
    height: 1.2em;
    overflow: hidden;
    border-radius: 0.16em;
    text-align: center;
    color: #fff;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.4),
        inset 0 -2px 0 rgba(0, 0, 0, 0.16),
        0 2px 4px rgba(0, 0, 0, 0.18);
}

.digit-roll {
    transition: transform 0.55s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.digit-roll span {
    display: block;
    height: 1.2em;
    line-height: 1.2em;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* Total: cool blue. Streak: escalates with level. */
.total-roller .roller-digit {
    background: linear-gradient(180deg, var(--primary-1), var(--primary-2));
}

.streak-roller .roller-digit {
    background: linear-gradient(180deg, #8ad0a0, #2e9e6b);
}

.streak-roller.streak-on-fire .roller-digit {
    background: linear-gradient(180deg, #ffc36b, #e6760f);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.4),
        inset 0 -2px 0 rgba(0, 0, 0, 0.16),
        0 0 7px rgba(255, 152, 0, 0.5),
        0 2px 4px rgba(0, 0, 0, 0.18);
}

.streak-roller.streak-blazing .roller-digit {
    background: linear-gradient(180deg, #ff8a5b, #c41f2d);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.4),
        inset 0 -2px 0 rgba(0, 0, 0, 0.16),
        0 0 11px rgba(255, 87, 34, 0.6),
        0 2px 5px rgba(0, 0, 0, 0.2);
}

.streak-roller.streak-legendary .roller-digit {
    background: linear-gradient(180deg, #f06ba8, #6a1b9a);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.45),
        inset 0 -2px 0 rgba(0, 0, 0, 0.2),
        0 0 15px rgba(233, 30, 99, 0.7),
        0 2px 6px rgba(0, 0, 0, 0.25);
    animation: streakPulse 1.6s ease-in-out infinite;
}

@keyframes streakPulse {
    0%, 100% { transform: translateY(0) scale(1); }
    50%      { transform: translateY(-1px) scale(1.06); }
}

/* ---------------- Map ---------------- */

#map {
    width: 100%;
    height: 30vh;
    height: 30dvh;
    min-height: 180px;
    max-height: 340px;
    margin: 0;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 14px;
    overflow: hidden;
    background: linear-gradient(180deg, #8ad2ee, #6bb8e0);
    box-shadow: 0 4px 14px rgba(40, 80, 120, 0.15);
    flex: 0 0 auto;
}

.map-svg {
    width: 100%;
    height: 100%;
    display: block;
}

/* Colours are applied as presentation attributes in JS; this only adds a
   smooth fade when a country is highlighted. */
.map-svg path {
    transition: fill 0.25s ease, stroke 0.2s ease;
}

/* ---------------- Question ---------------- */

#question-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin: 12px auto 6px;
    padding: 10px 16px;
    background: var(--card);
    border-radius: 14px;
    max-width: 600px;
    width: calc(100% - 8px);
    box-shadow: var(--shadow-sm);
    box-sizing: border-box;
    flex: 0 0 auto;
}

#country-flag {
    width: 70px;
    height: auto;
    border: 4px solid #ffffff;
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
    flex-shrink: 0;
    display: block;
}

#country {
    font-size: 1.2em;
    font-weight: 700;
    text-align: left;
    flex: 1;
    margin: 0;
    color: var(--ink);
}

/* ---------------- Result ---------------- */

#result {
    margin: 6px 0 4px;
    font-size: 1.15em;
    font-weight: 700;
    min-height: 1.4em;
    flex: 0 0 auto;
    transition: color 0.2s ease;
}

/* ---------------- Bottom buttons ---------------- */

#action-buttons {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: auto;
    padding-top: 10px;
    flex: 0 0 auto;
}

.action-button {
    padding: 12px 26px;
    font-size: 1.05em;
    font-weight: 700;
    cursor: pointer;
    border: none;
    border-radius: 10px;
    color: white;
    box-shadow: var(--shadow-sm);
    transition: transform 0.1s ease, box-shadow 0.2s ease, opacity 0.2s ease;
    min-width: 110px;
}

.action-button:not(:disabled):hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.action-button:not(:disabled):active { transform: translateY(0); }
.action-button:disabled { opacity: 0.5; cursor: default; }

.action-button-skip    { background: linear-gradient(180deg, var(--slate-1), var(--slate-2)); }
.action-button-primary { background: linear-gradient(180deg, var(--accent-1), var(--accent-2)); }
.action-button-capital { background: linear-gradient(180deg, var(--special-1), var(--special-2)); }

/* ---------------- Choice grids (continent + capital) ---------------- */

.choice-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-top: 10px;
    padding: 0 4px;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    flex: 0 0 auto;
}

.choice-button {
    padding: 14px 16px;
    font-size: 1em;
    font-weight: 700;
    cursor: pointer;
    border: none;
    color: white;
    background: linear-gradient(180deg, var(--primary-1), var(--primary-2));
    border-radius: 10px;
    box-shadow: var(--shadow-sm);
    transition: transform 0.1s ease, box-shadow 0.2s ease, filter 0.2s ease;
    flex: 1 1 calc(33% - 8px);
    min-width: 95px;
    max-width: 220px;
}

.capital-choice {
    background: linear-gradient(180deg, var(--special-1), var(--special-2));
}

.choice-button:not(:disabled):hover { transform: translateY(-2px); box-shadow: var(--shadow-md); filter: brightness(1.05); }
.choice-button:not(:disabled):active { transform: translateY(0); }
.choice-button:disabled { cursor: default; opacity: 0.9; }

.choice-button.incorrect { background: linear-gradient(180deg, var(--bad-1), var(--bad-2)); }
.choice-button.correct {
    background: linear-gradient(180deg, var(--good-1), var(--good-2));
    box-shadow: 0 0 0 3px rgba(15, 157, 107, 0.3), var(--shadow-md);
}

/* ---------------- Animations ---------------- */

@keyframes flagEntrance {
    from { opacity: 0; transform: translateY(-8px) scale(0.92); }
    to   { opacity: 1; transform: none; }
}
#country-flag.entering { animation: flagEntrance 0.35s ease-out; }

@keyframes pulse {
    0%   { transform: scale(1); }
    40%  { transform: scale(1.12); }
    100% { transform: scale(1); }
}
.pulse { animation: pulse 0.45s ease-out; }

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-6px); }
    40%, 80% { transform: translateX(6px); }
}
.shake { animation: shake 0.35s ease-in-out; }

/* ---------------- Responsive ---------------- */

@media (min-width: 700px) {
    .choice-button { flex: 0 0 auto; min-width: 130px; }
    #game-container {
        max-width: 960px;
        margin: 0 auto;
        min-height: 0;
    }
    #action-buttons { margin-top: 16px; }
}

@media (max-width: 600px) {
    #splash-title { font-size: 46px; }
    #start-button { font-size: 1.25em; padding: 13px 34px; }
    #game-container { padding: 8px 8px 14px; }
    #counters { gap: 20px; margin: 2px 0 8px; }
    .roller { font-size: 2em; }
    #settings-button { width: 40px; height: 40px; }
    #map { height: 26vh; height: 26dvh; min-height: 170px; max-height: 260px; }
    #question-row { padding: 8px 12px; gap: 10px; margin: 10px auto 4px; }
    #country-flag { width: 56px; border-width: 3px; }
    #country { font-size: 1.02em; }
    #result { font-size: 1em; margin: 4px 0 2px; }
    .action-button { padding: 11px 20px; min-width: 86px; font-size: 1em; }
    .choice-button { padding: 12px 10px; font-size: 0.92em; min-width: 86px; flex: 1 1 calc(33% - 8px); }
}

@media (max-height: 700px) {
    #map { height: 24vh; height: 24dvh; min-height: 150px; }
    #counters { margin: 2px 0 6px; }
    #question-row { margin: 8px auto 2px; padding: 6px 12px; }
    #result { margin: 2px 0; min-height: 1.2em; }
    #action-buttons { padding-top: 6px; }
}

@media (prefers-reduced-motion: reduce) {
    #splash-screen, #splash-title, #country-flag, .choice-button,
    .action-button, #settings-button, #start-button, #settings-panel {
        animation: none !important;
        transition: none !important;
    }
    .pulse, .shake, #country-flag.entering, .streak-roller.streak-legendary .roller-digit {
        animation: none !important;
    }
}
