html,
body {
    width: 100%;
    height: 100%;
    min-height: 100%;
    overflow: hidden;
}

body {
    font-size: clamp(14px, 2vmax, 22px);
    overscroll-behavior: none;
}

button {
    min-width: 44px;
    min-height: 44px;
    touch-action: manipulation;
}

#gameShell {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    padding:
        env(safe-area-inset-top)
        env(safe-area-inset-right)
        env(safe-area-inset-bottom)
        env(safe-area-inset-left);
}

.game-logo {
    display: grid;
    grid-row: 1 / 2;
    grid-column: 1 / -1;
    place-items: center;
    min-height: 0;
    padding: 2vh 12px;
}

.game-logo img {
    display: block;
    width: min(90%, 620px);
    max-height: 24vh;
    object-fit: contain;
}

#mainMenu button {
    min-height: clamp(52px, 9vh, 82px);
    border-radius: 12px;
    font-size: clamp(1rem, 4.4vmin, 2.3rem);
}

#gameMenu,
#playerActions {
    padding: 4px;
}

#gameMenu > button,
#gameMenu .lobby-primary-action > button,
#playerActions > button {
    display: inline-flex;
    width: auto;
    min-width: 44px;
    min-height: 44px;
    height: auto;
    padding: 8px 12px;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
}

#playerHand.card-hand {
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    touch-action: none;
    -webkit-overflow-scrolling: touch;
}

#playerHand.card-hand > .game-card {
    flex: 0 0 auto;
    width: auto;
    max-width: none;
}

#playerHand.card-hand > span > img,
#playerHand.card-hand > .game-card > img,
.cards-only-mode > #playerHand > span > img,
.cards-only-mode > #playerHand > .game-card > img {
    display: block;
    width: auto;
    height: clamp(88px, 21dvh, 156px);
    min-width: 0;
    max-width: none;
    object-fit: contain;
    filter: none;
    -webkit-filter: none;
}

.dialog-container {
    padding: 12px;
    overflow-y: auto;
}

.dialog-window {
    width: min(100%, 560px);
    min-width: 0;
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
    border-radius: 12px;
    font-size: 1rem;
    overscroll-behavior: contain;
}

.dialogBody input,
.dialogBody select {
    min-height: 44px;
    max-width: 100%;
    font-size: 1rem;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

@media (max-width: 760px) and (orientation: portrait) {
    #gameShell {
        grid-template-columns: minmax(0, 2fr) minmax(78px, 1fr);
        grid-template-rows: auto minmax(0, 1fr) 0 auto minmax(100px, 0.8fr);
    }

    #gameMenu {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        justify-content: center;
        gap: 2px;
        min-width: 0;
        padding: 3px;
    }

    #gameMenu > button,
    #playerActions > button {
        float: none !important;
        flex: 0 1 auto;
        margin: 1px;
    }

    #gameMenu > #gameMetadata {
        flex: 1 0 100%;
        order: 1;
        font-size: 0.82rem;
        line-height: 1.25;
    }

    #gameTable,
    #playerList,
    #playerHand {
        min-width: 0;
        min-height: 0;
    }

    #gameTable {
        overflow: hidden;
    }

    #playerList {
        overflow-y: auto;
        font-size: 0.78rem;
    }

    #playerActions {
        display: flex;
        align-items: center;
        justify-content: space-between;
        min-width: 0;
        font-size: 0.85rem;
    }

    #playerHand.card-hand > span > img,
    #playerHand.card-hand > .game-card > img,
    .cards-only-mode > #playerHand > span > img,
    .cards-only-mode > #playerHand > .game-card > img {
        height: clamp(82px, 17dvh, 128px);
    }
}

@media (max-width: 760px) and (orientation: landscape) {
    #gameShell {
        grid-template-columns: minmax(120px, 1fr) minmax(0, 3fr) minmax(84px, 2fr);
        grid-template-rows: 54px minmax(0, 1fr) 56px minmax(92px, 0.65fr);
    }

    #gameMenu {
        grid-column: 2 / 4;
        grid-row: 1 / 2;
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        justify-content: center;
        gap: 2px;
    }

    #gameMenu > button,
    #gameMenu .lobby-primary-action > button,
    #playerActions > button {
        float: none !important;
        flex: 0 1 auto;
        min-width: 44px;
        width: auto;
        height: auto;
        margin: 0;
        padding: 8px 10px;
    }

    #gameMenu > #gameMetadata {
        flex: 1 0 100%;
        order: 1;
        font-size: 0.7rem;
        line-height: 1.1;
    }

    #playerActions {
        grid-column: 1 / 3;
        grid-row: 3 / 4;
        display: flex;
        align-items: center;
        justify-content: space-between;
        min-width: 0;
        font-size: 0.8rem;
    }

    #playerHand {
        grid-column: 1 / 3;
        grid-row: 4 / 5;
    }

    #playerHand.card-hand > span > img,
    #playerHand.card-hand > .game-card > img,
    .cards-only-mode > #playerHand > span > img,
    .cards-only-mode > #playerHand > .game-card > img {
        height: clamp(72px, 23dvh, 116px);
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
