:root {
    color-scheme: dark;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: #050710;
    color: #f6f8ff;
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    background:
        radial-gradient(circle at 17% 5%, rgba(124, 92, 255, .14), transparent 34%),
        radial-gradient(circle at 88% 0%, rgba(41, 211, 162, .08), transparent 30%),
        #050710;
}

body {
    min-width: 0;
    min-height: 0;
}

.game-shell {
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    display: grid;
    place-items: center;
    padding: clamp(8px, 2.2vmin, 18px);
}

.tetris-layout {
    width: min(100%, 760px);
    height: min(100%, 650px);
    min-width: 0;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, auto) minmax(118px, .72fr);
    align-items: stretch;
    justify-content: center;
    gap: clamp(10px, 2.5vmin, 22px);
}

/*
 * Spielfeld bleibt exakt 1:2.
 * Seine Höhe wird vom verfügbaren iframe bestimmt. Das HUD nutzt den
 * ansonsten freien horizontalen Raum.
 */
.game-board-wrap {
    position: relative;
    height: 100%;
    width: auto;
    max-width: 100%;
    aspect-ratio: 1 / 2;
    justify-self: end;
    border: 1px solid rgba(255,255,255,.14);
    border-radius: clamp(12px, 2.3vmin, 20px);
    overflow: hidden;
    background: #070b15;
    box-shadow:
        0 24px 70px rgba(0,0,0,.42),
        inset 0 0 0 1px rgba(255,255,255,.025);
}

#gameCanvas {
    display: block;
    width: 100%;
    height: 100%;
    outline: none;
    touch-action: none;
}

.game-hud {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: clamp(8px, 1.8vmin, 14px);
    justify-content: center;
    align-self: stretch;
}

.hud-title,
.hud-stats article,
.next-card,
.controls-card {
    border: 1px solid rgba(255,255,255,.10);
    background: rgba(17, 23, 38, .80);
    box-shadow: 0 12px 32px rgba(0,0,0,.22);
}

.hud-title {
    padding: clamp(10px, 2vmin, 16px);
    border-radius: 14px;
}

.hud-kicker {
    display: block;
    color: #29d3a2;
    font-size: clamp(6px, 1.25vmin, 9px);
    font-weight: 900;
    letter-spacing: .14em;
}

.hud-title strong {
    display: block;
    margin-top: 4px;
    font-size: clamp(1rem, 3.6vmin, 1.7rem);
    letter-spacing: -.045em;
}

.hud-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.hud-stats article {
    min-width: 0;
    padding: clamp(8px, 1.8vmin, 13px);
    border-radius: 13px;
}

.hud-stats span,
.next-card > span,
.controls-card > span {
    display: block;
    color: #929db2;
    font-size: clamp(7px, 1.4vmin, 10px);
    font-weight: 800;
}

.hud-stats strong {
    display: block;
    margin-top: 4px;
    font-size: clamp(1rem, 3vmin, 1.5rem);
}

.next-card {
    display: grid;
    place-items: center;
    padding: clamp(8px, 1.8vmin, 14px);
    border-radius: 14px;
}

.next-card > span {
    justify-self: start;
    width: 100%;
}

#nextCanvas {
    display: block;
    width: min(100%, 104px);
    height: auto;
    aspect-ratio: 1;
    margin-top: 3px;
}

.controls-card {
    padding: clamp(9px, 1.8vmin, 14px);
    border-radius: 14px;
}

.controls-card dl,
.controls-card div,
.controls-card dt,
.controls-card dd {
    margin: 0;
}

.controls-card dl {
    display: grid;
    gap: clamp(3px, .9vmin, 7px);
    margin-top: 8px;
}

.controls-card div {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    color: #929db2;
    font-size: clamp(6px, 1.25vmin, 9px);
}

.controls-card dt {
    color: #f6f8ff;
    font-weight: 850;
}

.game-overlay {
    position: absolute;
    z-index: 6;
    inset: 0;
    display: grid;
    place-content: center;
    gap: 7px;
    padding: 24px;
    text-align: center;
    background: rgba(5, 7, 16, .72);
    backdrop-filter: blur(7px);
}

.game-overlay[hidden] {
    display: none;
}

.game-overlay strong {
    font-size: clamp(1.8rem, 7vmin, 3.6rem);
    line-height: .95;
    letter-spacing: -.06em;
}

.game-overlay span {
    max-width: 240px;
    color: #9aa6bc;
    font-size: clamp(.7rem, 2vmin, .9rem);
    line-height: 1.5;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/*
 * Ist das iframe sehr schmal, bleibt das Spielfeld vollständig sichtbar.
 * HUD-Informationen werden kompakt über die freie obere Spielfeldzone gelegt.
 */
@media (max-width: 390px) {
    .game-shell {
        padding: 6px;
    }

    .tetris-layout {
        position: relative;
        display: grid;
        grid-template-columns: 1fr;
        place-items: center;
        gap: 0;
    }

    .game-board-wrap {
        height: 100%;
        justify-self: center;
    }

    .game-hud {
        position: absolute;
        z-index: 4;
        top: 9px;
        left: 50%;
        width: min(calc(100% - 28px), 210px);
        transform: translateX(-50%);
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 6px;
        pointer-events: none;
    }

    .hud-title,
    .controls-card {
        display: none;
    }

    .hud-stats {
        grid-template-columns: 1fr 1fr;
        gap: 5px;
    }

    .hud-stats article,
    .next-card {
        background: rgba(7,11,21,.74);
        backdrop-filter: blur(7px);
    }

    .next-card {
        display: none;
    }
}

/*
 * Sehr flache Landscape-Player: HUD bleibt rechts, unwichtige Steuerungskarte
 * verschwindet und gibt dem Spielfeld den Platz.
 */
@media (max-height: 390px) {
    .game-shell {
        padding: 6px;
    }

    .tetris-layout {
        gap: 8px;
        grid-template-columns: minmax(0, auto) minmax(90px, .55fr);
    }

    .controls-card {
        display: none;
    }

    .hud-title {
        padding: 8px;
    }

    .next-card {
        padding: 6px;
    }

    #nextCanvas {
        width: min(100%, 72px);
    }
}
