* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: #1a1a2e;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    font-family: 'Fredoka', sans-serif;
    animation: gradientShift 10s ease infinite alternate;
    background: linear-gradient(135deg, #1a1a2e, #16213e, #0f3460, #1a1a2e);
    background-size: 400% 400%;
}

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

#gc {
    display: block;
    border-radius: 8px;
    background: #3a3a3a;
}

#ui {
    text-align: center;
    margin: 8px 0 4px;
    color: #aaa;
    font-size: 13px;
}

#gameWrap {
    position: relative;
    display: inline-block;
}

#overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.75);
    border-radius: 8px;
}

#overlay h2 {
    color: #fff;
    font-size: 22px;
    font-weight: 500;
    margin: 0 0 16px;
}

#overlay p {
    color: #ccc;
    font-size: 14px;
    margin: 0 0 16px;
}

.overlay-btn {
    padding: 10px 28px;
    border: none;
    background: #f5c400;
    color: #1a1a2e;
    font-family: 'Fredoka', sans-serif;
    font-size: 15px;
    font-weight: 600;
    border-radius: 10px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
}

.overlay-btn:hover {
    background: #ffd700;
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(245,196,0,0.3);
}

#controls {
    display: flex;
    gap: 24px;
    justify-content: center;
    margin: 10px 0 4px;
}

.ctrl-btn {
    padding: 12px 32px;
    border: 1px solid #555;
    background: rgba(255,255,255,0.08);
    backdrop-filter: blur(4px);
    color: #fff;
    font-family: 'Fredoka', sans-serif;
    font-size: 20px;
    border-radius: 10px;
    cursor: pointer;
    user-select: none;
    touch-action: none;
    transition: background 0.2s, transform 0.15s;
}

.ctrl-btn:active {
    background: rgba(255,255,255,0.15);
    transform: scale(0.95);
}

#passwordScreen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: radial-gradient(ellipse at center, rgba(15,52,96,0.3), rgba(26,26,46,0.6));
}

#passwordScreen::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at 30% 40%, rgba(245,196,0,0.06) 0%, transparent 50%),
                radial-gradient(circle at 70% 60%, rgba(255,107,107,0.04) 0%, transparent 50%);
    pointer-events: none;
}

#passwordScreen::after {
    content: '✦ ✦ ✦';
    position: absolute;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255,255,255,0.08);
    font-size: 14px;
    letter-spacing: 12px;
    pointer-events: none;
}

#passwordCard {
    background: rgba(255,255,255,0.06);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 24px;
    padding: 40px 48px;
    text-align: center;
    position: relative;
    box-shadow: 0 8px 40px rgba(0,0,0,0.3);
}

#passwordCard h2 {
    color: #fff;
    font-size: 36px;
    font-weight: 600;
    margin: 0 0 6px;
}

#passwordCard p {
    color: rgba(255,255,255,0.6);
    font-size: 15px;
    margin: 0 0 28px;
}

#passwordCard input {
    padding: 14px 24px;
    border: 2px solid rgba(255,255,255,0.15);
    border-radius: 14px;
    background: rgba(255,255,255,0.06);
    color: #fff;
    font-family: 'Fredoka', sans-serif;
    font-size: 17px;
    text-align: center;
    width: 240px;
    outline: none;
    margin-bottom: 12px;
    transition: border-color 0.3s, box-shadow 0.3s;
}

#passwordCard input:focus {
    border-color: #f5c400;
    box-shadow: 0 0 24px rgba(245,196,0,0.2);
}

#passwordCard input::placeholder {
    color: rgba(255,255,255,0.25);
}

#passwordCard .error {
    color: #ff6b6b;
    font-size: 13px;
    margin: 0 0 12px;
    min-height: 18px;
}

#passwordCard .overlay-btn {
    margin-top: 4px;
    padding: 12px 44px;
    font-family: 'Fredoka', sans-serif;
    font-size: 17px;
    border-radius: 14px;
}

#hubScreen {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    text-align: center;
    padding: 40px 20px;
}

#hubTopBar {
    width: 100%;
    max-width: 500px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
}

#hubWelcome {
    color: #f5c400;
    font-size: 20px;
    font-weight: 600;
    text-shadow: 0 0 12px rgba(245,196,0,0.15);
}

#hubLogoutBtn {
    padding: 6px 18px;
    border: 1px solid #555;
    background: transparent;
    color: #aaa;
    font-family: 'Fredoka', sans-serif;
    font-size: 13px;
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
}

#hubLogoutBtn:hover {
    border-color: #f5c400;
    color: #f5c400;
}

.hub-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    max-width: 500px;
    width: 100%;
}

.hub-card {
    background: rgba(255,255,255,0.06);
    backdrop-filter: blur(4px);
    border-radius: 16px;
    padding: 28px 16px 22px;
    text-align: center;
    border: 1px solid rgba(255,255,255,0.1);
    transition: transform 0.25s, border-color 0.25s, box-shadow 0.25s;
}

.hub-card:not(.locked):hover {
    transform: translateY(-6px);
    border-color: #f5c400;
    box-shadow: 0 8px 30px rgba(245,196,0,0.15);
}

.hub-card.locked {
    opacity: 0.35;
}

.hub-icon {
    font-size: 46px;
    margin-bottom: 12px;
}

.hub-name {
    color: #fff;
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 6px;
}

.hub-desc {
    color: #999;
    font-size: 13px;
    margin-bottom: 16px;
    line-height: 1.3;
}

.hub-play-btn {
    padding: 10px 32px;
    border: none;
    background: #f5c400;
    color: #1a1a2e;
    font-family: 'Fredoka', sans-serif;
    font-size: 15px;
    font-weight: 600;
    border-radius: 10px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
}

.hub-play-btn:hover {
    background: #ffd700;
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(245,196,0,0.3);
}

.hub-locked-label {
    font-size: 28px;
    margin-top: 6px;
}

#gameArea {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px 0;
}

#gameToolbar {
    width: 360px;
    display: flex;
    justify-content: flex-start;
    margin-bottom: 4px;
}

#backBtn {
    padding: 8px 18px;
    border: 1px solid #555;
    background: transparent;
    color: #aaa;
    font-family: 'Fredoka', sans-serif;
    font-size: 13px;
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
}

#backBtn:hover {
    border-color: #f5c400;
    color: #f5c400;
}

#quizBackBtn {
    padding: 8px 18px;
    border: 1px solid #555;
    background: transparent;
    color: #aaa;
    font-family: 'Fredoka', sans-serif;
    font-size: 13px;
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
}

#quizBackBtn:hover {
    border-color: #f5c400;
    color: #f5c400;
}

#modeScreen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    text-align: center;
    padding: 20px;
}

#modeTitle {
    color: #fff;
    font-size: 28px;
    font-weight: 600;
    margin-bottom: 32px;
    text-shadow: 0 2px 16px rgba(245,196,0,0.1);
}

.mode-cards {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    justify-content: center;
    max-width: 520px;
    width: 100%;
}

.mode-card {
    background: rgba(255,255,255,0.06);
    backdrop-filter: blur(4px);
    border-radius: 16px;
    padding: 32px 20px 24px;
    text-align: center;
    border: 1px solid rgba(255,255,255,0.1);
    flex: 1;
    min-width: 140px;
    max-width: 160px;
    cursor: pointer;
    transition: transform 0.25s, border-color 0.25s, box-shadow 0.25s;
}

.mode-card:hover {
    transform: translateY(-6px);
    border-color: #f5c400;
    box-shadow: 0 8px 30px rgba(245,196,0,0.12);
}

.mode-icon {
    font-size: 40px;
    margin-bottom: 10px;
}

.mode-name {
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
}

.mode-desc {
    color: #aaa;
    font-size: 11px;
    margin-bottom: 14px;
    line-height: 1.4;
}

.mode-btn {
    padding: 8px 22px;
    border: none;
    background: #f5c400;
    color: #1a1a2e;
    font-family: 'Fredoka', sans-serif;
    font-size: 13px;
    font-weight: 600;
    border-radius: 10px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
}

.mode-btn:hover {
    background: #ffd700;
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(245,196,0,0.3);
}

#modeBackBtn {
    margin-top: 28px;
    padding: 8px 18px;
    border: 1px solid #555;
    background: transparent;
    color: #aaa;
    font-family: 'Fredoka', sans-serif;
    font-size: 13px;
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
}

#modeBackBtn:hover {
    border-color: #f5c400;
    color: #f5c400;
}

#quizArea {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 0 20px;
    position: relative;
}

#quizToolbar {
    width: 360px;
    max-width: 90%;
    display: flex;
    justify-content: flex-start;
    margin-bottom: 8px;
}

#quizHUD {
    width: 360px;
    max-width: 90%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    color: #ccc;
    font-size: 14px;
}

.hud-score {
    color: #fff;
}

#timerDisplay {
    display: flex;
    align-items: center;
    gap: 6px;
}

#timerText {
    color: #f5c400;
    font-weight: 600;
    min-width: 30px;
}

#timerBarBg {
    width: 80px;
    height: 8px;
    background: #444;
    border-radius: 4px;
    overflow: hidden;
}

#timerBar {
    height: 100%;
    background: #f5c400;
    border-radius: 4px;
    transition: width 0.3s;
    width: 100%;
}

#livesDisplay {
    font-size: 16px;
}

#mapContainer {
    width: 240px;
    height: 200px;
    background: #f5f5f5;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
    overflow: hidden;
    border: 2px solid #555;
}

.map-loading, .map-na {
    color: #888;
    font-size: 13px;
    text-align: center;
}

#flagGrid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    width: 360px;
    max-width: 90%;
}

.flag-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 8px 10px;
    border: 2px solid #555;
    border-radius: 10px;
    background: #333;
    cursor: pointer;
    transition: transform 0.1s, border-color 0.1s;
}

.flag-btn:hover:not(:disabled) {
    border-color: #f5c400;
    transform: translateY(-2px);
}

.flag-btn:disabled {
    cursor: default;
    opacity: 0.8;
}

.flag-btn.correct {
    border-color: #2ecc40;
    background: #1a3a1a;
}

.flag-btn.wrong {
    border-color: #ff4136;
    background: #3a1a1a;
}

.flag-img {
    width: 80px;
    height: 48px;
    object-fit: cover;
    border-radius: 4px;
    margin-bottom: 6px;
    border: 1px solid #555;
}

.flag-name {
    color: #fff;
    font-size: 11px;
    text-align: center;
    line-height: 1.2;
}

#quizOverlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.85);
    z-index: 10;
}

#quizOverlay h2 {
    color: #fff;
    font-size: 24px;
    font-weight: 500;
    margin: 0 0 14px;
}

#quizOverlay p {
    color: #ccc;
    font-size: 14px;
    margin: 0 0 20px;
    text-align: center;
}

@media (max-width: 480px) {
    .mode-cards {
        flex-direction: column;
        align-items: center;
    }
    .mode-card {
        max-width: 260px;
        width: 100%;
    }
    #mapContainer {
        width: 200px;
        height: 170px;
    }
    #flagGrid {
        width: 300px;
    }
    .flag-img {
        width: 70px;
        height: 42px;
    }
}

.screen-enter {
    animation: fadeIn 0.35s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}
