.md-game-sec {
    scroll-margin-top: 1.5rem;
}

.md-game {
    width: 100%;
    overflow: hidden;
    border: 1px solid rgba(44, 35, 29, .12);
    border-radius: 1.25rem;
    background: #fff;
    box-shadow: 0 .75rem 2rem rgba(44, 35, 29, .08);
}

.md-game-intro {
    padding: clamp(1rem, 3vw, 1.75rem) clamp(1.25rem, 4vw, 2.5rem);
    color: #2c231d;
    text-align: center;
    background: linear-gradient(135deg, #fffaf0, #eaf9fb);
}

.md-game-intro h2 {
    margin: 0;
    font-size: clamp(1.2rem, 2.8vw, 1.75rem);
    font-weight: 900;
    letter-spacing: .08em;
}

.md-game-intro p {
    margin: .5rem 0 0;
    color: #766b62;
    font-size: clamp(.875rem, 1.8vw, 1rem);
    line-height: 1.7;
}

.md-game-stage {
    position: relative;
    width: 100%;
    aspect-ratio: 8 / 3;
    min-height: 0;
    overflow: hidden;
    background: linear-gradient(180deg, #00b1fd 0%, #71c7ff 100%);
}

.md-game-canvas {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    overflow: hidden;
    touch-action: none;
}

.md-game-canvas canvas {
    position: absolute;
    top: 50%;
    left: 50%;
    display: block;
    width: 100% !important;
    height: auto !important;
    max-height: 100%;
    image-rendering: pixelated;
    transform: translate(-50%, -50%);
}

.md-game-overlay {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: clamp(1rem, 4vw, 2.5rem);
    background: linear-gradient(90deg, rgba(20, 42, 50, .48), rgba(20, 42, 50, .18), rgba(20, 42, 50, .48));
    transition: opacity .25s ease, visibility .25s ease;
}

.md-game-overlay:not(.is-visible) {
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
}

.md-game-panel {
    display: flex;
    align-items: center;
    flex-direction: column;
    gap: .7rem;
    width: min(100%, 480px);
    padding: clamp(1.25rem, 4vw, 2rem);
    color: #2c231d;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, .65);
    border-radius: 1.25rem;
    background: rgba(255, 255, 255, .92);
    box-shadow: 0 .75rem 2rem rgba(0, 0, 0, .2);
    backdrop-filter: blur(5px);
}

.md-game-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: .3rem .8rem;
    color: #fff;
    font-size: .75rem;
    font-weight: 900;
    letter-spacing: .12em;
    border-radius: 999px;
    background: #168f9b;
}

.md-game-panel h3 {
    margin: 0;
    font-size: clamp(1.25rem, 3vw, 1.8rem);
    font-weight: 900;
}

.md-game-panel p {
    margin: 0;
    color: #766b62;
    font-size: .9375rem;
    line-height: 1.7;
}

.md-game-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 192px;
    margin-top: .35rem;
    padding: .8rem 1.5rem;
    color: #fff;
    font-size: 1rem;
    font-weight: 900;
    letter-spacing: .05em;
    border: 0;
    border-radius: 999px;
    background: #d51d29;
    box-shadow: 0 .35rem .8rem rgba(213, 29, 41, .25);
    cursor: pointer;
    transition: transform .2s ease, background-color .2s ease, opacity .2s ease;
}

.md-game-action:hover:not(:disabled),
.md-game-action:focus-visible {
    background: #b3121d;
    transform: translateY(-.125rem);
}

.md-game-action:focus-visible {
    outline: .1875rem solid #f6ab0d;
    outline-offset: .1875rem;
}

.md-game-action:disabled {
    opacity: .55;
    cursor: wait;
    transform: none;
}

.md-game-hud {
    position: absolute;
    top: clamp(.75rem, 2vw, 1.25rem);
    left: clamp(.75rem, 2vw, 1.25rem);
    z-index: 4;
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    pointer-events: none;
}

.md-game-hud[hidden] {
    display: none !important;
}

.md-game-hud span {
    padding: .45rem .75rem;
    color: #2c231d;
    font-size: clamp(.75rem, 1.8vw, .9375rem);
    font-weight: 700;
    border: 1px solid rgba(44, 35, 29, .12);
    border-radius: 999px;
    background: rgba(255, 255, 255, .85);
    backdrop-filter: blur(4px);
}

.md-game-hud b {
    color: #d51d29;
}

.md-game-change-city {
    pointer-events: auto;
    padding: .45rem .75rem;
    color: #2c231d;
    font: inherit;
    font-size: clamp(.75rem, 1.8vw, .9375rem);
    font-weight: 800;
    border: 1px solid rgba(44, 35, 29, .18);
    border-radius: 999px;
    background: rgba(255, 255, 255, .92);
    cursor: pointer;
}

.md-game-change-city:hover,
.md-game-change-city:focus-visible {
    color: #fff;
    border-color: #168f9b;
    background: #168f9b;
}

.md-game-change-city:focus-visible {
    outline: .1875rem solid #f6ab0d;
    outline-offset: .1875rem;
}

.md-game-secondary-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 192px;
    padding: .65rem 1.25rem;
    color: #766b62;
    font: inherit;
    font-size: .9rem;
    font-weight: 800;
    border: 1px solid rgba(44, 35, 29, .2);
    border-radius: 999px;
    background: rgba(255, 255, 255, .82);
    cursor: pointer;
}

.md-game-secondary-action:hover,
.md-game-secondary-action:focus-visible {
    color: #168f9b;
    border-color: #168f9b;
    background: #fff;
}

.md-game-secondary-action:focus-visible {
    outline: .1875rem solid #f6ab0d;
    outline-offset: .1875rem;
}

.md-game-help {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: .75rem clamp(1rem, 3vw, 1.75rem);
    color: #766b62;
    font-size: .8125rem;
    line-height: 1.6;
    background: #fff;
}

@media (max-width: 900px) {
    /* Narrow activity-page columns need room for the login/city overlay.
       The actual Phaser canvas keeps its own 8:3 ratio and is not stretched. */
    .md-game-stage {
        aspect-ratio: 16 / 9;
    }
}

@media (max-width: 600px) {
    .md-game-stage {
        /* Keep extra vertical room for the login/city panel. The Phaser
           canvas stays at its 8:3 ratio and is centered without distortion. */
        aspect-ratio: 16 / 9;
        min-height: 0;
    }

    .md-game-help {
        align-items: center;
        flex-direction: column;
        gap: .15rem;
        text-align: center;
    }

    .md-game-panel {
        width: min(92%, 400px);
        gap: .45rem;
        padding: .8rem;
    }

    .md-game-panel h3 {
        font-size: 1.15rem;
    }

    .md-game-panel p {
        font-size: .8125rem;
        line-height: 1.5;
    }
}
