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

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: #0a0f1a;
    color: #e2e8f0;
    height: 100vh;
    overflow: hidden;
}

/* ---- App: full-screen map with overlays ---- */
#app {
    display: none;
    position: relative;
    width: 100%;
    height: 100vh;
}

#app.active {
    display: block;
}

/* ---- Map: fills everything ---- */
#map-container {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 20% 80%, rgba(99, 102, 241, 0.06), transparent 40%),
        radial-gradient(circle at 80% 20%, rgba(96, 165, 250, 0.05), transparent 45%),
        radial-gradient(ellipse at 50% 50%, #0a1628 0%, #03070f 70%, #000 100%);
    overflow: hidden;
}

#world-map {
    width: 100%;
    height: 100%;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

#world-map .ocean {
    /* fill set inline via gradient */
    pointer-events: none;
}

#world-map .graticule {
    fill: none;
    stroke: rgba(96, 165, 250, 0.18);
    stroke-width: 0.5;
}

#world-map path.land {
    fill: #2d4a6e;
    stroke: #15243a;
    stroke-width: 0.45;
    transition: fill 0.3s;
    cursor: grab;
}

#world-map path.land:hover {
    fill: #3b6092;
}

#world-map path.land.solved-correct {
    fill: #15803d;
    stroke: #052e16;
}

#world-map path.land.solved-wrong {
    fill: #991b1b;
    stroke: #450a0a;
}

#world-map path.land.highlight {
    fill: #ef4444;
    stroke: #fecaca;
    stroke-width: 0.7;
    animation: country-pulse 1.6s ease-in-out infinite;
}

#world-map path.land.highlight-correct {
    fill: #22c55e;
    stroke: #bbf7d0;
    stroke-width: 0.7;
}

#world-map path.land.highlight-wrong {
    fill: #dc2626;
    stroke: #fecaca;
    stroke-width: 0.7;
}

@keyframes country-pulse {
    0%, 100% { fill: #ef4444; }
    50% { fill: #f87171; }
}

/* ---- HUD: Top bar ---- */
#hud-top {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: linear-gradient(to bottom, rgba(10,15,26,0.9), transparent);
    z-index: 100;
    pointer-events: none;
}

#hud-top h1 {
    font-size: 1.3rem;
    font-weight: 700;
    background: linear-gradient(135deg, #60a5fa, #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    pointer-events: auto;
}

#score-board {
    font-size: 1.2rem;
    font-weight: 700;
    color: #94a3b8;
    pointer-events: auto;
}

#score {
    color: #4ade80;
    font-size: 1.4rem;
}

/* ---- HUD: Left panel (flag + controls) ---- */
#hud-left {
    position: absolute;
    left: 16px;
    top: 56px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(12px);
    border-radius: 16px;
    border: 1px solid rgba(51, 65, 85, 0.6);
    padding: 16px;
    width: 300px;
}

#flag-container {
    width: 268px;
    height: 180px;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
    border: 2px solid #334155;
    background: #1e293b;
}

#flag-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: opacity 0.3s;
}

#hint-text {
    font-size: 0.8rem;
    color: #64748b;
    min-height: 18px;
    text-align: center;
}

#mic-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    border: none;
    border-radius: 40px;
    background: linear-gradient(135deg, #3b82f6, #6366f1);
    color: white;
    cursor: pointer;
    transition: all 0.3s;
    width: 100%;
}

#mic-btn:hover {
    transform: scale(1.03);
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.5);
}

#mic-btn:active,
#mic-btn.listening {
    background: linear-gradient(135deg, #ef4444, #f97316);
    box-shadow: 0 0 30px rgba(239, 68, 68, 0.5);
}

#mic-btn.listening {
    animation: pulse-ring 1.5s infinite;
}

@keyframes pulse-ring {
    0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.6); }
    70% { box-shadow: 0 0 0 14px rgba(239, 68, 68, 0); }
    100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

#mic-icon {
    fill: white;
    flex-shrink: 0;
}

#mic-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#mic-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

#answer-form {
    display: flex;
    width: 100%;
    gap: 8px;
    align-items: center;
}

#answer-form.hidden { display: none; }

#answer-input {
    flex: 1;
    min-width: 0;
    padding: 12px 14px;
    border: 2px solid rgba(99, 102, 241, 0.4);
    border-radius: 10px;
    background: rgba(15, 23, 42, 0.8);
    color: #e2e8f0;
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#answer-input:focus {
    outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25);
}

#answer-input::placeholder {
    color: #64748b;
}

#answer-submit {
    padding: 12px 16px;
    border: none;
    border-radius: 10px;
    background: linear-gradient(135deg, #3b82f6, #6366f1);
    color: white;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.2s;
    font-family: inherit;
}

#answer-submit:hover {
    transform: scale(1.05);
    box-shadow: 0 0 16px rgba(99, 102, 241, 0.5);
}

#answer-submit:active { transform: scale(0.95); }

#result-text {
    font-size: 0.9rem;
    font-weight: 700;
    min-height: 20px;
    text-align: center;
    line-height: 1.3;
}

#result-text.correct { color: #4ade80; }
#result-text.wrong { color: #f87171; }

#next-btn {
    padding: 10px 24px;
    border: none;
    border-radius: 8px;
    background: #334155;
    color: #e2e8f0;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
}

#next-btn:hover { background: #475569; }

.hidden { display: none !important; }

/* ---- HUD: Right panel (stats) ---- */
#hud-right {
    position: absolute;
    right: 16px;
    top: 56px;
    bottom: 16px;
    z-index: 100;
    width: 200px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(12px);
    border-radius: 16px;
    border: 1px solid rgba(51, 65, 85, 0.6);
    padding: 14px;
    overflow: hidden;
}

.stats-section {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.stats-section h3 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
    padding-bottom: 5px;
    border-bottom: 1px solid #334155;
    flex-shrink: 0;
}

#stats-correct h3 { color: #4ade80; }
#stats-wrong h3 { color: #f87171; }

.stats-section h3 span {
    font-size: 0.85rem;
}

.stats-section ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 3px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.stats-section ul::-webkit-scrollbar {
    width: 3px;
}

.stats-section ul::-webkit-scrollbar-thumb {
    background: #475569;
    border-radius: 2px;
}

.stats-section li {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: #cbd5e1;
    padding: 3px 5px;
    border-radius: 5px;
    animation: stat-fade-in 0.3s ease;
    flex-shrink: 0;
}

.stats-section li img {
    width: 22px;
    height: 15px;
    border-radius: 2px;
    object-fit: cover;
    flex-shrink: 0;
}

#stats-correct li { background: rgba(74, 222, 128, 0.08); }
#stats-wrong li { background: rgba(248, 113, 113, 0.08); }

@keyframes stat-fade-in {
    from { opacity: 0; transform: translateX(10px); }
    to { opacity: 1; transform: translateX(0); }
}

/* ---- Flying flag ---- */
#flying-flag {
    position: fixed;
    width: 80px;
    height: 54px;
    border-radius: 6px;
    overflow: hidden;
    pointer-events: none;
    opacity: 0;
    z-index: 1000;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
    background-size: cover;
    background-position: center;
}

#flying-flag.animate {
    opacity: 1;
    transition: all 1.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* ---- Flag pins on map ---- */
.flag-pin {
    position: absolute;
    width: 28px;
    height: 19px;
    background-size: cover;
    background-position: center;
    border-radius: 3px;
    transform: translate(-50%, -50%) scale(0);
    pointer-events: auto;
    opacity: 0;
    z-index: 10;
    cursor: pointer;
    transition: transform 0.15s;
}

.flag-pin.visible {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
    animation: pin-drop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.flag-pin:hover {
    transform: translate(-50%, -50%) scale(2);
    z-index: 20;
}

.flag-pin.pin-correct {
    border: 2px solid #4ade80;
    box-shadow: 0 0 8px rgba(74, 222, 128, 0.6);
}

.flag-pin.pin-wrong {
    border: 2px solid #f87171;
    box-shadow: 0 0 8px rgba(248, 113, 113, 0.6);
    filter: grayscale(0.4);
}

@keyframes pin-drop {
    0% { transform: translate(-50%, -200%) scale(0.5); opacity: 0; }
    60% { transform: translate(-50%, -40%) scale(1.1); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

/* ---- Start Screen ---- */
#start-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    gap: 20px;
    text-align: center;
    padding: 20px;
    background: #0a0f1a;
}

#start-screen h1 {
    font-size: 3rem;
    background: linear-gradient(135deg, #60a5fa, #a78bfa, #f472b6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

#start-screen p {
    font-size: 1.2rem;
    color: #94a3b8;
    max-width: 400px;
}

.section-label {
    font-size: 0.85rem !important;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #94a3b8 !important;
    margin: 4px 0 !important;
}

#input-type-toggle {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.input-type-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border: 2px solid rgba(99, 102, 241, 0.3);
    border-radius: 10px;
    background: rgba(30, 41, 59, 0.6);
    color: #cbd5e1;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.input-type-btn:hover {
    border-color: #6366f1;
    background: rgba(99, 102, 241, 0.18);
}

.input-type-btn.active {
    border-color: #6366f1;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.35), rgba(99, 102, 241, 0.35));
    color: #e2e8f0;
    box-shadow: 0 0 18px rgba(99, 102, 241, 0.35);
}

.input-icon {
    font-size: 1.2rem;
    line-height: 1;
}

#mode-buttons {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    justify-content: center;
    margin: 8px 0;
}

.mode-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 24px 28px;
    width: 240px;
    border: 2px solid rgba(99, 102, 241, 0.4);
    border-radius: 16px;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.15), rgba(99, 102, 241, 0.15));
    color: #e2e8f0;
    cursor: pointer;
    transition: all 0.25s;
    font-family: inherit;
}

.mode-btn:hover {
    transform: translateY(-4px);
    border-color: #6366f1;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.3), rgba(99, 102, 241, 0.3));
    box-shadow: 0 8px 24px rgba(99, 102, 241, 0.35);
}

.mode-icon {
    font-size: 2.6rem;
    line-height: 1;
}

.mode-title {
    font-size: 1.25rem;
    font-weight: 700;
    background: linear-gradient(135deg, #60a5fa, #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.mode-desc {
    font-size: 0.85rem;
    color: #94a3b8;
    text-align: center;
}

/* ---- Map mode tweaks ---- */
#app[data-mode="map"] #flag-container {
    display: none;
}

/* ---- Choice mode ---- */
#country-prompt {
    display: none;
    font-size: 1.5rem;
    font-weight: 800;
    text-align: center;
    padding: 14px 10px;
    color: #e2e8f0;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.22), rgba(99, 102, 241, 0.22));
    border: 1px solid rgba(99, 102, 241, 0.3);
    border-radius: 12px;
    width: 100%;
    line-height: 1.25;
    letter-spacing: 0.01em;
}

#choices-grid {
    display: none;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    width: 100%;
}

#app[data-mode="choice"] #flag-container,
#app[data-mode="choice"] #mic-btn,
#app[data-mode="choice"] #answer-form,
#app[data-mode="choice"] #hint-text {
    display: none !important;
}
#app[data-mode="choice"] #country-prompt { display: block; }
#app[data-mode="choice"] #choices-grid { display: grid; }

.choice-flag {
    aspect-ratio: 3 / 2;
    border-radius: 8px;
    border: 2px solid #334155;
    background-size: cover;
    background-position: center;
    background-color: #1e293b;
    cursor: pointer;
    padding: 0;
    transition: transform 0.15s, border-color 0.15s, box-shadow 0.2s, filter 0.2s;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.choice-flag:hover:not(:disabled) {
    transform: scale(1.04);
    border-color: #6366f1;
    box-shadow: 0 0 16px rgba(99, 102, 241, 0.5);
}

.choice-flag:active:not(:disabled) { transform: scale(0.97); }

.choice-flag:disabled { cursor: default; }

.choice-flag.choice-correct {
    border-color: #4ade80;
    box-shadow: 0 0 18px rgba(74, 222, 128, 0.65);
    animation: choice-flash-correct 0.5s ease;
}

.choice-flag.choice-wrong {
    border-color: #f87171;
    box-shadow: 0 0 16px rgba(248, 113, 113, 0.6);
    filter: grayscale(0.55) brightness(0.85);
}

.choice-flag.choice-dim {
    opacity: 0.45;
    filter: grayscale(0.35);
}

@keyframes choice-flash-correct {
    0%   { transform: scale(1); }
    40%  { transform: scale(1.12); }
    100% { transform: scale(1); }
}

body.device-tablet #country-prompt {
    font-size: 1.3rem;
    padding: 12px 8px;
}

body.device-phone #country-prompt {
    font-size: 1.15rem;
    padding: 8px 6px;
}

body.device-phone #choices-grid {
    gap: 8px;
}

#map-prompt {
    font-size: 1rem;
    font-weight: 600;
    color: #cbd5e1;
    text-align: center;
    line-height: 1.3;
    padding: 8px 4px;
}

.note {
    font-size: 0.85rem !important;
    color: #64748b !important;
}

/* ---- Game over screen ---- */
.game-over {
    position: fixed;
    inset: 0;
    background: rgba(5, 9, 19, 0.82);
    backdrop-filter: blur(14px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 6000;
    animation: game-over-fade 0.35s ease;
    padding: 20px;
}

.game-over-card {
    text-align: center;
    padding: 44px 56px;
    border-radius: 24px;
    background: linear-gradient(135deg, rgba(30, 58, 95, 0.65), rgba(15, 23, 42, 0.85));
    border: 1px solid rgba(99, 102, 241, 0.4);
    box-shadow:
        0 20px 60px rgba(0, 0, 0, 0.6),
        0 0 80px rgba(96, 165, 250, 0.2);
    animation: game-over-pop 0.45s cubic-bezier(0.16, 1, 0.3, 1);
    max-width: 90vw;
}

.game-over-title {
    font-size: clamp(2rem, 6vw, 3rem);
    font-weight: 900;
    background: linear-gradient(135deg, #60a5fa, #a78bfa, #f472b6);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 12px;
    letter-spacing: 0.02em;
}

.game-over-score {
    font-size: clamp(2.5rem, 8vw, 4rem);
    font-weight: 900;
    color: #fbbf24;
    text-shadow: 0 0 30px rgba(251, 191, 36, 0.5);
    margin-bottom: 28px;
    font-variant-numeric: tabular-nums;
}

.game-over-btn {
    padding: 14px 36px;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, #3b82f6, #6366f1);
    color: white;
    font-size: 1.05rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    font-family: inherit;
}

.game-over-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 0 24px rgba(99, 102, 241, 0.6);
}

.game-over-btn:active { transform: scale(0.98); }

@keyframes game-over-fade {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes game-over-pop {
    0%   { transform: scale(0.85) translateY(20px); opacity: 0; }
    100% { transform: scale(1)    translateY(0);   opacity: 1; }
}

/* ---- Streak celebrations ---- */
.celebration {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 5000;
}

.celebration-badge {
    text-align: center;
    transform-origin: center;
    will-change: transform, opacity;
}

.celebration-label {
    font-weight: 900;
    line-height: 1;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.celebration-sub {
    margin-top: 12px;
    font-size: 1.1rem;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.85);
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

/* Tier 1: 3 in a row — orange "Streak!" */
.celebration.tier-1 .celebration-label {
    font-size: clamp(2.5rem, 9vw, 5rem);
    color: #fb923c;
    text-shadow:
        0 0 20px rgba(251, 146, 60, 0.9),
        0 0 40px rgba(251, 146, 60, 0.5),
        0 4px 12px rgba(0, 0, 0, 0.6);
}
.celebration.tier-1 .celebration-badge {
    animation: tier1-pop 1.7s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* Tier 2: 10 in a row — fiery red "On fire!" with shake */
.celebration.tier-2 .celebration-label {
    font-size: clamp(3.5rem, 12vw, 7rem);
    color: #f97316;
    text-shadow:
        0 0 30px rgba(249, 115, 22, 0.95),
        0 0 60px rgba(239, 68, 68, 0.7),
        0 0 90px rgba(220, 38, 38, 0.4),
        0 6px 18px rgba(0, 0, 0, 0.7);
}
.celebration.tier-2 .celebration-badge {
    animation: tier2-pop 2.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* Tier 3: 25 in a row — gold "LEGENDARY!" with rotation */
.celebration.tier-3 .celebration-label {
    font-size: clamp(4.5rem, 16vw, 10rem);
    background: linear-gradient(135deg, #fde047, #fbbf24, #f59e0b, #fbbf24, #fde047);
    background-size: 200% 200%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: none;
    filter:
        drop-shadow(0 0 30px rgba(251, 191, 36, 0.9))
        drop-shadow(0 0 60px rgba(251, 191, 36, 0.6))
        drop-shadow(0 8px 24px rgba(0, 0, 0, 0.7));
    animation: tier3-shimmer 1.5s linear infinite;
}
.celebration.tier-3 .celebration-badge {
    animation: tier3-pop 2.8s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
.celebration.tier-3::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at center, rgba(251, 191, 36, 0.18), transparent 60%);
    animation: tier3-glow 2.8s ease-out forwards;
}

@keyframes tier1-pop {
    0%   { transform: scale(0)   rotate(-8deg); opacity: 0; }
    18%  { transform: scale(1.25) rotate(3deg); opacity: 1; }
    32%  { transform: scale(1)    rotate(0); }
    78%  { transform: scale(1)    rotate(0); opacity: 1; }
    100% { transform: scale(1.4)  rotate(0); opacity: 0; }
}

@keyframes tier2-pop {
    0%   { transform: scale(0)    rotate(-12deg); opacity: 0; }
    14%  { transform: scale(1.4)  rotate(6deg);   opacity: 1; }
    20%  { transform: scale(1.05) rotate(-3deg); }
    26%  { transform: scale(1.15) rotate(2deg); }
    32%  { transform: scale(1)    rotate(0); }
    82%  { transform: scale(1)    rotate(0); opacity: 1; }
    100% { transform: scale(1.6)  rotate(0); opacity: 0; }
}

@keyframes tier3-pop {
    0%   { transform: scale(0)   rotate(-25deg); opacity: 0; }
    12%  { transform: scale(1.7) rotate(10deg); opacity: 1; }
    20%  { transform: scale(0.9) rotate(-5deg); }
    28%  { transform: scale(1.2) rotate(3deg); }
    36%  { transform: scale(1)   rotate(0); }
    85%  { transform: scale(1)   rotate(0); opacity: 1; }
    100% { transform: scale(2)   rotate(0); opacity: 0; }
}

@keyframes tier3-shimmer {
    0%   { background-position: 0% 50%; }
    100% { background-position: 200% 50%; }
}

@keyframes tier3-glow {
    0%, 70% { opacity: 1; }
    100%    { opacity: 0; }
}

/* ---- Confetti ---- */
.confetti {
    position: fixed;
    width: 10px;
    height: 10px;
    border-radius: 2px;
    pointer-events: none;
    z-index: 2000;
    animation: confetti-fall 1.5s ease-out forwards;
}

@keyframes confetti-fall {
    0% { opacity: 1; transform: translateY(0) rotate(0deg); }
    100% { opacity: 0; transform: translateY(400px) rotate(720deg); }
}

/* ---- Responsive fallback (used if JS device detection hasn't applied a class yet) ---- */
@media (max-width: 700px) {
    #hud-left {
        left: 8px;
        top: 48px;
        width: 170px;
        padding: 10px;
    }
    #flag-container {
        width: 148px;
        height: 100px;
    }
    #hud-right {
        display: none;
    }
}

/* =====================================================
   Device-specific layouts
   The body class is set by detectDevice() in game.js:
     body.device-desktop  — default layout (no overrides needed)
     body.device-tablet   — compact side HUDs
     body.device-phone    — bottom HUD strip, stats hidden
   ===================================================== */

/* ---------- Tablet ---------- */
body.device-tablet #hud-left {
    width: 240px;
    padding: 12px;
    gap: 8px;
    top: 52px;
}

body.device-tablet #flag-container {
    width: 216px;
    height: 145px;
}

body.device-tablet #hud-right {
    width: 170px;
    padding: 12px;
    top: 52px;
}

body.device-tablet #hud-top h1 {
    font-size: 1.15rem;
}

body.device-tablet .mode-btn {
    width: 220px;
    padding: 20px 22px;
}

/* ---------- Phone ---------- */
/* HUD-left becomes a bottom panel; HUD-right stats hidden; bigger touch targets. */

body.device-phone #hud-top {
    padding: 8px 12px;
}

body.device-phone #hud-top h1 {
    font-size: 1rem;
}

body.device-phone #score-board {
    font-size: 1rem;
}

body.device-phone #score {
    font-size: 1.15rem;
}

body.device-phone #hud-left {
    left: 0;
    right: 0;
    top: auto;
    bottom: 0;
    width: 100%;
    padding: 10px 12px max(12px, env(safe-area-inset-bottom));
    border-radius: 16px 16px 0 0;
    border-bottom: none;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
}

body.device-phone #flag-container {
    width: min(180px, 50vw);
    height: 110px;
    margin: 0 auto;
}

body.device-phone #app[data-mode="map"] #flag-container {
    display: none;
}

body.device-phone #map-prompt {
    font-size: 0.9rem;
    padding: 4px 0;
}

body.device-phone #hud-right {
    display: none;
}

/* Tap the score → opens a full-screen sheet of guessed / missed lists. */
body.device-phone #score-board {
    pointer-events: auto;
    cursor: pointer;
    padding: 4px 12px;
    border-radius: 16px;
    background: rgba(51, 65, 85, 0.45);
    border: 1px solid rgba(99, 102, 241, 0.35);
    transition: background 0.15s;
    user-select: none;
    -webkit-user-select: none;
}

body.device-phone #score-board::after {
    content: ' 📊';
    font-size: 0.85rem;
    opacity: 0.8;
}

body.device-phone #score-board:active {
    background: rgba(99, 102, 241, 0.4);
}

body.device-phone #hud-right.open {
    display: flex;
    position: fixed;
    inset: 0;
    width: auto;
    height: auto;
    top: 0;
    right: 0;
    bottom: 0;
    border-radius: 0;
    border: none;
    padding: 60px 14px max(16px, env(safe-area-inset-bottom));
    background: rgba(10, 15, 26, 0.96);
    backdrop-filter: blur(16px);
    z-index: 4000;
    flex-direction: column;
    gap: 14px;
    overflow: hidden;
    animation: stats-sheet-in 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

body.device-phone #hud-right.open .stats-section {
    flex: 1;
}

body.device-phone #hud-right.open .stats-section ul {
    max-height: 100%;
}

@keyframes stats-sheet-in {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Close button: only visible on phone, only when sheet is open. */
.stats-close {
    display: none;
    position: absolute;
    top: 12px;
    right: 12px;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: rgba(51, 65, 85, 0.85);
    color: #e2e8f0;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    z-index: 1;
    transition: background 0.15s, transform 0.15s;
}

.stats-close:hover { background: rgba(99, 102, 241, 0.6); }
.stats-close:active { transform: scale(0.92); }

body.device-phone #hud-right.open .stats-close {
    display: block;
}

body.device-phone #mic-btn {
    padding: 14px 16px;
    border-radius: 32px;
}

body.device-phone #mic-icon {
    width: 26px;
    height: 26px;
}

body.device-phone #mic-label {
    font-size: 0.75rem;
}

body.device-phone #hint-text {
    font-size: 0.75rem;
    min-height: 14px;
}

body.device-phone #result-text {
    font-size: 0.9rem;
}

body.device-phone #next-btn {
    padding: 12px 20px;
    font-size: 0.9rem;
}

body.device-phone #start-screen h1 {
    font-size: 2rem;
}

body.device-phone #start-screen p {
    font-size: 1rem;
}

body.device-phone #mode-buttons {
    flex-direction: column;
    gap: 12px;
    width: 100%;
    align-items: center;
}

body.device-phone .mode-btn {
    width: min(320px, 86vw);
    padding: 18px 20px;
}

body.device-phone .mode-icon {
    font-size: 2.2rem;
}

body.device-phone .mode-title {
    font-size: 1.1rem;
}

body.device-phone .mode-desc {
    font-size: 0.8rem;
}

body.device-phone #answer-input {
    padding: 12px 12px;
    font-size: 16px; /* >=16px stops iOS zoom-on-focus */
}

body.device-phone #answer-submit {
    padding: 12px 14px;
}

body.device-phone #input-type-toggle {
    gap: 8px;
    width: 100%;
}

body.device-phone .input-type-btn {
    flex: 1;
    justify-content: center;
}
