.game-page {
    flex: 1;
    overflow-x: hidden;
    overflow-y: auto;
    height: 100vh;
    
}

.game-page .game-wrapper {
    height: 100vh;
    display: flex;
    flex-direction: column;
}


.game-wrapper {
    display: none;
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
}

.menu {
    position: fixed;
    inset: 0;
    background: #0a0a0a;

    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;

    z-index: 999;
}

.menu h1 {
    font-size: 36px;
    margin-bottom: 30px;
    color: #4a9eff;
}

.menu button {
    width: 220px;
    margin: 10px;
    padding: 14px;

    background: #111;
    border: 1px solid #4a9eff;
    border-radius: 10px;

    color: white;
    font-size: 16px;
    cursor: pointer;

    transition: 0.2s;
}

.menu button:hover {
    background: #4a9eff;
}


/* ЛЕЙАУТ */
.game-layout {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 20px;
}

.side {
    display: flex;
    flex-direction: column;
    align-items: center;

    width: 100%;
    max-width: 600px;
    min-width: unset;
    padding: 0 10px;   /* 🔥 */
}

/* центр */
.center-area {
    width: 30%;
    display: flex;
    justify-content: center;
}

/* ПОЛЕ */
.grid {
    width: 320px;
    display: grid;
    grid-template-columns: repeat(3, 100px);
    gap: 6px;
    justify-content: center;
    margin: 0 auto 20px;
}


.cell {
    width: 100px;
    height: 100px;
    background: #1a1a1a;
    border: 1px solid #444;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: 0.2s;
}

.cell.valid-move {
    outline: 2px solid #4caf50;
    background: rgba(76, 175, 80, 0.15);
}

.cell.targetable {
    outline: 2px dashed #4a9eff;
    cursor: pointer;
}

.cell.selected {
    outline: 3px solid #ffd54f;
    background: rgba(255, 213, 79, 0.3);
}

.cell.valid-move:hover,
.cell.targetable:hover {
    transform: scale(1.05);
}

/* МАРКЕРЫ */
.marker {
    position: absolute;
    border-radius: 6px;
    border: 2px solid #fff;
    background: #fff;
    color: #12161c;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    box-shadow: 0 2px 6px rgba(0,0,0,0.6);
}

.marker.big {
    width: 70px;
    height: 70px;
    font-size: 32px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    
}

.marker.small {
    width: 42px;
    height: 42px;
    font-size: 18px;
    top: 50%;
    left: 20%;
    transform: translate(-50%, -50%);
    opacity: 0.7;
    
}

/* цвет первого игрока */
.cell.p1-owned .marker.big {
    background: #4a9eff;
}

/* цвет второго игрока */
.cell.p2-owned .marker.big {
    background: #D4537E;
}


.marker-counter {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: #111;
    border: 1px solid #444;
    border-radius: 10px;
    padding: 10px 14px;
    min-width: 80px;
}

.counter-value {
    font-size: 26px;
    font-weight: bold;
    color: #ffd93d;
}

.counter-label {
    font-size: 11px;
    color: #888;
}



/* РУКА */

.hand {
    display: flex;
    justify-content: center;
    align-items: center;

    gap: 8px;

    overflow: hidden;      /* убираем скрол */
    width: 100%;
}



/* КАРТЫ В ИГРЕ */
.card {
    width: 70px;
    height: 105px;

    background: #1a1a1a;
    border: 1px solid #444;
    border-radius: 12px;


    display: flex;
    align-items: center;
    justify-content: center;

    font-size: 18px;
    font-weight: bold;

    cursor: pointer;
    transition: 0.2s;

    flex: 1;              /* 👈 ключевой момент */
    max-width: 80px;      /* ограничение сверху */
    min-width: 40px;      /* чтобы не схлопнулись */
}

.card:hover {
    transform: scale(1.15);
    border-color: #4a9eff;
    z-index: 5;
}

.card-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.card-back-img {
    object-position: center;
    filter: saturate(1.08) contrast(1.08);
}

.card-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.card-controls button {
    width: 110px;
    height: 150px;

    background: #111;
    border: 1px solid #666;
    border-radius: 10px;

    color: #aaa;
    font-size: 14px;
    font-weight: bold;

    cursor: pointer;

    display: flex;
    align-items: center;
    justify-content: center;

    transition: 0.2s;

    box-shadow: 0 0 10px rgba(0,0,0,0.6);
}

.card-controls button:hover {
    border-color: #4a9eff;
    color: #fff;
    transform: scale(1.05);
}

#cardPopup .popup {
    transform: scale(1.1);
}

#popupCardValue {
    color: #ffd93d;
    margin-bottom: 10px;
}

.card-popup {
    position: fixed;
    width: 240px;
    background: #111;
    border: 1px solid #4a9eff;
    border-radius: 10px;
    padding: 10px;
    display: none;
    z-index: 1000;
}

.card-popup.visible {
    display: block;
}

.card-popup img {
    width: 100%;
    border-radius: 8px;
}

.popup-info {
    margin-top: 8px;
    font-size: 12px;
}

/* сыгранная карта */
.played-card {
    width: 140px;
    height: 200px;

    border: 2px solid rgba(0,150,255,0.4);
    box-shadow: 0 0 12px rgba(0,150,255,0.3);
}


.discard {
    margin-top: 20px;
    font-size: 12px;
    color: #aaa;
}

.discard-view {
    min-height: 40px;
    font-size: 12px;
    color: #aaa;
}


/* ИГРОКИ */
.players {
    display: grid;
    grid-template-columns: minmax(200px, 1fr) auto minmax(200px, 1fr);
    gap: 20px;
    max-width: 900px;
    margin: 0 auto 16px;
    align-items: stretch;
}

.player-panel {
    background: #1a1a1a;
    border: 1px solid #444;
    border-radius: 10px;
    padding: 12px;
}

.player-row {
    display: grid;
    grid-template-columns: 60px 1fr 60px;
    align-items: center;    
}


.player-panel.active {
    box-shadow: 0 0 10px rgba(74, 158, 255, 0.4);
    border: 2px solid #4a9eff;
}

.player-panel.p2.active {
    border: 2px solid #D4537E;
}

.player-panel.active .played-card {
    border: 2px solid #4a9eff;
}

.player-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    text-align: center;
}

.player-label-p1 { color: #4a9eff; font-size: 13px; font-weight: bold; margin-bottom: 4px; }
.player-label-p2 { color: #D4537E; font-size: 13px; font-weight: bold; margin-bottom: 4px; }

.player-score {
    font-size: 28px;
    font-weight: bold;
    line-height: 1;
}


.player-score-label {
    font-size: 12px;
    color: #888;
}


.play-area {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin-top: 20px;
}



.roll-btn {
    width: 50px;
    height: 50px;

    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;

    border-radius: 10px;
    background: #1f3a5f;
}

.roll-btn:hover:not(:disabled) { background: #333; }
.roll-btn:disabled { opacity: 0.4; cursor: not-allowed; }


.dice-result {
    font-size: 18px;
    font-weight: bold;
    margin-top: 4px;
    color: #ffd93d;
}

#diceChoice button {
    font-size: 24px;
    margin: 10px;
    padding: 15px 25px;
}

/* TURN */
.turn-area { margin-bottom: 10px; }
.turn-badge {
    display: inline-block;
    padding: 4px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: bold;
    background: #0d2a4a;
    color: #4a9eff;
}
.turn-badge.p2 {
    background: #3a1020;
    color: #D4537E;
}

#log { font-size: 13px; color: #aaa; min-height: 20px; margin-bottom: 16px; }



/* POPUP победы */
.overlay {
    display: none; /* по умолчанию скрыто */
    position: fixed;
    inset: 0;

    justify-content: center;
    align-items: center;
    gap: 10px;

    background: rgba(0,0,0,0.6);
    z-index: 1000;
}

.overlay.visible { display: flex; }
.popup {
    background: #1a1a1a;
    border: 1px solid #555;
    border-radius: 14px;
    padding: 2rem 2.5rem;
    text-align: center;
    max-width: 300px;
    width: 90%;
}
.popup-title { font-size: 26px; font-weight: bold; margin-bottom: 8px; }
.popup-sub { font-size: 15px; color: #aaa; margin-bottom: 1.5rem; }
.popup-btn {
    padding: 10px 28px;
    border-radius: 8px;
    border: 1px solid #555;
    background: #222;
    color: white;
    cursor: pointer;
    font-size: 14px;
}
.popup-btn:hover { background: #333; }

.top-zone {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.player-side {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.effect-view {
    min-height: 40px;
    color: #ccc;
    text-align: center;
}

.bottom-zone {
    display: flex;
    justify-content: space-between;
    margin-top: 15px;
}

/* зона игрока */
.player-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 30%;
}

/* панель действий */
.action-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
}

.win-popup {
    position: fixed;
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #111;
    border: 2px solid #fff;
    padding: 20px;
    text-align: center;
    z-index: 1000;
}

.card.disabled {
    opacity: 0.4;
    pointer-events: none;
}

.zone-card {
    width: 120px;
    height: 180px;

    border: 2px solid rgba(255,255,255,0.2);
    border-radius: 10px;

    display: flex;
    align-items: center;
    justify-content: center;

    background: rgba(255,255,255,0.03);
    cursor: pointer;

    transition: 0.2s;
}

.zone-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 8px;
}

.zone-card span {
    font-size: 14px;
    color: #ccc;
}

.zone-card:hover {
    transform: scale(1.05);
    border-color: rgba(0,150,255,0.6);
}



.overlay button {
    font-size: 20px;
    padding: 10px 15px;
    cursor: pointer;
}



/* =========================================================
   TERAX GAME — MOBILE ORIENTATION SUPPORT
   This section is appended to the existing game.css.
   Desktop styles above remain unchanged.
   ========================================================= */

.rotate-phone-prompt[hidden] {
    display: none !important;
}

.rotate-phone-prompt {
    display: none;
}

@media screen and (max-width: 950px) and (orientation: portrait) {
    .rotate-phone-prompt:not([hidden]) {
        position: fixed;
        inset: 0;
        z-index: 10000;
        display: flex;
        align-items: center;
        justify-content: center;
        box-sizing: border-box;
        padding: 20px;
        background: rgba(7, 10, 15, 0.98);
        color: #f5f7fa;
        text-align: center;
    }

    .rotate-phone-card {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 12px;
        width: 100%;
        max-width: 360px;
        box-sizing: border-box;
        padding: 24px 20px;
        border: 1px solid #31516e;
        border-radius: 16px;
        background: #111820;
        box-shadow: 0 0 28px rgba(74, 158, 255, 0.15);
    }

    .rotate-phone-icon {
        color: #4a9eff;
        font-size: 54px;
        line-height: 1;
    }

    .rotate-phone-card h2 {
        margin: 0;
        font-size: 24px;
    }

    .rotate-phone-card p {
        margin: 0;
        color: #bac5d0;
        font-size: 15px;
        line-height: 1.5;
    }

    .rotate-phone-card button {
        width: 100%;
        min-height: 44px;
        padding: 10px 14px;
        border: 1px solid #4a9eff;
        border-radius: 9px;
        background: #17314b;
        color: #fff;
        font-size: 15px;
        cursor: pointer;
    }

    .rotate-phone-card button.secondary {
        border-color: #4b5662;
        background: #202831;
        color: #d5dce3;
    }
}

@media screen and (max-width: 950px) and (orientation: landscape) {
    .rotate-phone-prompt {
        display: none !important;
    }

    html,
    body.game-page {
        width: 100%;
        min-width: 0;
        min-height: 100%;
        height: auto;
        margin: 0;
        overflow-x: hidden;
        overflow-y: auto;
    }

    body.game-page .game-wrapper {
        display: flex;
        flex-direction: column;
        box-sizing: border-box;
        width: 100%;
        max-width: none;
        min-height: 100vh;
        height: auto;
        padding: 3px 6px 8px;
        overflow: visible;
    }

    .game-wrapper > h1 {
        margin: 0 0 2px;
        text-align: center;
        font-size: clamp(16px, 3.3vh, 23px);
        line-height: 1.05;
    }

    #btnMenu {
        align-self: center;
        min-height: 26px;
        margin: 0 0 3px;
        padding: 2px 9px;
        font-size: 12px;
    }

    .players {
        display: grid;
        width: 100%;
        max-width: 760px;
        grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
        gap: 6px;
        margin: 0 auto 3px;
        align-items: stretch;
    }

    .player-panel {
        min-width: 0;
        padding: 4px 6px;
        border-radius: 8px;
    }

    .player-label-p1,
    .player-label-p2 {
        margin-bottom: 1px;
        font-size: 10px;
    }

    .player-row {
        display: grid;
        grid-template-columns: 32px minmax(0, 1fr) 32px;
        align-items: center;
    }

    .roll-btn {
        width: 30px;
        height: 30px;
        min-width: 30px;
        min-height: 30px;
        font-size: 15px;
    }

    .player-score {
        font-size: clamp(17px, 3.8vh, 23px);
    }

    .player-score-label {
        font-size: 9px;
    }

    .dice-result {
        margin-top: 1px;
        font-size: 12px;
    }

    .marker-counter {
        min-width: 48px;
        padding: 3px 6px;
        border-radius: 8px;
    }

    .counter-value { font-size: 18px; }
    .counter-label { font-size: 8px; }

    .turn-area {
        margin: 1px 0;
        text-align: center;
        font-size: 11px;
    }

    #turn-badge {
        padding: 1px 6px;
        font-size: 10px;
    }

    #log {
        min-height: 0;
        margin: 0 0 3px;
        text-align: center;
        font-size: 9px;
        line-height: 1.15;
    }

    .dice-hud-panel {
        box-sizing: border-box;
        width: min(100%, 350px);
        max-width: 350px;
        margin: 2px auto 4px;
        padding: 3px 5px;
    }

    .dice-hud-faces {
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        justify-content: center;
        gap: 4px;
    }

    .dice-face {
        box-sizing: border-box;
        width: clamp(24px, 5.5vh, 34px);
        height: clamp(24px, 5.5vh, 34px);
        flex: 0 1 34px;
    }

    .dice-face img {
        width: 100%;
        height: 100%;
        object-fit: contain;
    }

    .game-layout {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr) minmax(0, 1fr);
        grid-template-areas: "p1 board p2";
        gap: 6px;
        width: 100%;
        min-width: 0;
        align-items: start;
    }

    .game-layout > .player-zone:first-child {
        grid-area: p1;
    }

    .game-layout > .center-area {
        grid-area: board;
        display: flex;
        width: 100%;
        min-width: 0;
        justify-content: center;
        align-items: flex-start;
    }

    .game-layout > .player-zone:last-child {
        grid-area: p2;
    }

    .player-zone {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        width: 100%;
        min-width: 0;
        gap: 3px;
    }

    .player-zone .action-bar {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 3px;
        width: 100%;
        align-items: stretch;
    }

    .zone-card,
    .played-card {
        box-sizing: border-box;
        width: 100%;
        min-width: 0;
        height: auto;
        aspect-ratio: 2 / 3;
        max-height: 62px;
        border-radius: 4px;
    }

    .zone-card span {
        font-size: 8px;
        text-align: center;
    }

    .zone-card img {
        width: 100%;
        height: 100%;
        object-fit: contain;
    }

    .hand {
        display: flex;
        box-sizing: border-box;
        width: 100%;
        min-width: 0;
        justify-content: flex-start;
        align-items: flex-start;
        gap: 3px;
        padding: 2px 1px 4px;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }

    .card {
        box-sizing: border-box;
        flex: 0 0 clamp(25px, 5.8vw, 40px);
        width: clamp(25px, 5.8vw, 40px);
        min-width: clamp(25px, 5.8vw, 40px);
        max-width: clamp(25px, 5.8vw, 40px);
        height: clamp(38px, 8.7vw, 60px);
        border-radius: 4px;
        font-size: 11px;
    }

    .center-area .grid {
        display: grid;
        box-sizing: border-box;
        width: min(100%, 43vh, 260px);
        max-width: 100%;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 3px;
        margin: 0 auto;
    }

    .cell {
        box-sizing: border-box;
        width: 100%;
        height: auto;
        min-width: 0;
        aspect-ratio: 1 / 1;
        border-radius: 4px;
    }

    .marker.big {
        width: 68%;
        height: 68%;
        border-width: 1px;
        font-size: clamp(14px, 2.8vh, 21px);
    }

    .marker.small {
        width: 38%;
        height: 38%;
        border-width: 1px;
        font-size: clamp(9px, 1.8vh, 13px);
    }

    .card:hover,
    .cell.valid-move:hover,
    .cell.targetable:hover,
    .zone-card:hover {
        transform: none;
    }

    .card-popup {
        box-sizing: border-box;
        width: min(210px, calc(100vw - 16px));
        max-height: 78vh;
        overflow-y: auto;
    }

    #diceChoice {
        box-sizing: border-box;
        padding: 6px;
        flex-wrap: wrap;
    }

    #diceChoice button,
    .overlay button {
        min-height: 36px;
        margin: 3px;
        padding: 6px 10px;
        font-size: 15px;
    }

    .popup {
        box-sizing: border-box;
        padding: 14px;
    }
}



/* =========================================================
   TERAX GAME — COMPACT TOUCHSCREEN LANDSCAPE
   Target touch devices in landscape even when the browser reports
   a large CSS viewport. Desktop mouse layouts remain unchanged.
   ========================================================= */

@media (orientation: landscape) and (pointer: coarse) {
    html,
    body.game-page {
        width: 100%;
        height: auto;
        min-height: 100%;
        margin: 0;
        overflow-x: hidden;
        overflow-y: auto;
    }

    body.game-page .game-wrapper {
        box-sizing: border-box;
        width: 100%;
        max-width: none;
        min-height: 100vh;
        height: auto;
        padding: 2px 5px 6px;
        overflow: visible;
        gap: 0;
    }

    .game-wrapper > h1 {
        margin: 0 0 1px;
        font-size: clamp(16px, 3.2vh, 22px);
        line-height: 1;
        text-align: center;
    }

    #btnMenu {
        align-self: center;
        min-height: 23px;
        margin: 0 0 2px;
        padding: 1px 8px;
        font-size: 11px;
        line-height: 1.1;
    }

    .players {
        width: 100%;
        max-width: 900px;
        grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
        gap: 5px;
        margin: 0 auto 2px;
        align-items: stretch;
    }

    .player-panel {
        min-width: 0;
        padding: 3px 6px;
        border-radius: 7px;
    }

    .player-label-p1,
    .player-label-p2 {
        margin: 0 0 1px;
        font-size: 10px;
        line-height: 1.1;
    }

    .player-row {
        display: grid;
        grid-template-columns: 28px minmax(0, 1fr) 28px;
        align-items: center;
    }

    .roll-btn {
        width: 27px;
        height: 27px;
        min-width: 27px;
        min-height: 27px;
        padding: 0;
        border-radius: 6px;
        font-size: 14px;
    }

    .player-score {
        font-size: clamp(16px, 3.2vh, 22px);
        line-height: 1;
    }

    .player-score-label { font-size: 8px; line-height: 1.1; }
    .dice-result { margin-top: 1px; font-size: 11px; line-height: 1.1; }

    .marker-counter {
        min-width: 42px;
        padding: 3px 5px;
        border-radius: 7px;
    }

    .counter-value { font-size: 17px; line-height: 1; }
    .counter-label { font-size: 8px; line-height: 1.1; }

    .turn-area {
        margin: 1px 0;
        text-align: center;
        font-size: 10px;
        line-height: 1.1;
    }

    #turn-badge { padding: 1px 5px; font-size: 10px; }
    #log { min-height: 0; margin: 0 0 2px; font-size: 9px; line-height: 1.1; }

    .dice-hud-panel {
        box-sizing: border-box;
        width: min(72vw, 330px);
        max-width: 330px;
        margin: 2px auto 4px;
        padding: 2px 4px;
        border-radius: 7px;
    }

    .dice-hud-faces {
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        justify-content: center;
        gap: 3px;
    }

    .dice-face {
        box-sizing: border-box;
        width: clamp(22px, 4.8vh, 30px);
        height: clamp(22px, 4.8vh, 30px);
        flex: 0 1 30px;
        padding: 1px;
    }

    .dice-face img { width: 100%; height: 100%; object-fit: contain; }

    .game-layout {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 0.9fr) minmax(0, 1fr);
        grid-template-areas: "p1 board p2";
        align-items: start;
        justify-content: stretch;
        gap: 5px;
        width: 100%;
        min-width: 0;
    }

    .game-layout > .player-zone:first-child { grid-area: p1; }
    .game-layout > .center-area {
        grid-area: board;
        display: flex;
        width: 100%;
        min-width: 0;
        justify-content: center;
        align-items: flex-start;
    }
    .game-layout > .player-zone:last-child { grid-area: p2; }

    .player-zone {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        width: 100%;
        min-width: 0;
        gap: 2px;
    }

    .player-zone .action-bar {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        align-items: stretch;
        justify-content: stretch;
        gap: 2px;
        width: 100%;
    }

    .zone-card,
    .played-card {
        box-sizing: border-box;
        width: 100%;
        min-width: 0;
        height: auto;
        aspect-ratio: 2 / 3;
        max-height: 48px;
        border-width: 1px;
        border-radius: 4px;
        box-shadow: none;
    }

    .zone-card span { font-size: 8px; line-height: 1.05; text-align: center; }
    .zone-card img { width: 100%; height: 100%; object-fit: contain; }

    .hand {
        display: flex;
        box-sizing: border-box;
        width: 100%;
        min-width: 0;
        justify-content: flex-start;
        align-items: flex-start;
        gap: 2px;
        padding: 1px 0 3px;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }

    .card {
        box-sizing: border-box;
        flex: 0 0 clamp(23px, 4.2vw, 34px);
        width: clamp(23px, 4.2vw, 34px);
        min-width: clamp(23px, 4.2vw, 34px);
        max-width: clamp(23px, 4.2vw, 34px);
        height: clamp(34px, 6.3vw, 51px);
        padding: 0;
        border-radius: 3px;
        font-size: 10px;
    }

    .center-area .grid {
        display: grid;
        box-sizing: border-box;
        width: min(100%, 37vh, 220px);
        max-width: 100%;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 2px;
        margin: 0 auto;
    }

    .cell {
        box-sizing: border-box;
        width: 100%;
        height: auto;
        min-width: 0;
        aspect-ratio: 1 / 1;
        border-radius: 4px;
    }

    .marker.big {
        width: 66%;
        height: 66%;
        border-width: 1px;
        font-size: clamp(12px, 2.2vh, 18px);
    }

    .marker.small {
        width: 36%;
        height: 36%;
        border-width: 1px;
        font-size: clamp(8px, 1.5vh, 12px);
    }

    .card:hover,
    .cell.valid-move:hover,
    .cell.targetable:hover,
    .zone-card:hover { transform: none; }

    .card-popup {
        box-sizing: border-box;
        width: min(180px, calc(100vw - 12px));
        max-height: 75vh;
        overflow-y: auto;
    }

    #diceChoice { box-sizing: border-box; padding: 5px; flex-wrap: wrap; }
    #diceChoice button,
    .overlay button {
        min-height: 32px;
        margin: 2px;
        padding: 5px 8px;
        font-size: 14px;
    }

    .popup { box-sizing: border-box; padding: 12px; }
}

/* Extra compact for phones with especially short landscape height */
@media (orientation: landscape) and (pointer: coarse) and (max-height: 430px) {
    .game-wrapper > h1 { font-size: 15px; }
    #btnMenu { min-height: 20px; font-size: 10px; }
    .players { margin-bottom: 1px; }
    .player-panel { padding: 2px 4px; }
    .dice-hud-panel { margin: 1px auto 2px; padding: 1px 3px; }
    .dice-face { width: 20px; height: 20px; flex-basis: 20px; }
    .center-area .grid { width: min(100%, 32vh, 175px); }
    .zone-card, .played-card { max-height: 40px; }
    .card { flex-basis: 22px; width: 22px; min-width: 22px; max-width: 22px; height: 32px; }
}



/* =========================================================
   TERAX GAME — FIXED MOBILE LANDSCAPE LAYOUT
   Overrides the earlier mobile rules below, without changing desktop.
   ========================================================= */
@media screen and (orientation: landscape) and (pointer: coarse) {
    html,
    body.game-page {
        width: 100%;
        min-width: 0;
        height: auto !important;
        min-height: 100%;
        margin: 0;
        overflow-x: hidden !important;
        overflow-y: auto !important;
    }

    body.game-page .game-wrapper {
        display: flex;
        position: relative;
        box-sizing: border-box;
        width: 100% !important;
        max-width: none !important;
        height: auto !important;
        min-height: 100vh;
        margin: 0;
        padding: 2px 5px 8px;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        overflow: visible !important;
    }

    body.game-page .game-wrapper > h1 {
        flex: 0 0 auto;
        margin: 0;
        padding: 0;
        font-size: clamp(15px, 3.4vh, 22px);
        line-height: 1.05;
        text-align: center;
    }

    body.game-page #btnMenu {
        align-self: center;
        flex: 0 0 auto;
        min-height: 20px;
        margin: 1px 0 3px;
        padding: 1px 8px;
        font-size: 11px;
        line-height: 1.1;
    }

    body.game-page .players {
        display: grid;
        box-sizing: border-box;
        width: 100%;
        max-width: 900px;
        margin: 0 auto 3px;
        padding: 0;
        grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
        gap: 5px;
        align-items: stretch;
    }

    body.game-page .player-panel {
        box-sizing: border-box;
        min-width: 0;
        padding: 3px 5px;
        border-radius: 7px;
    }

    body.game-page .player-label-p1,
    body.game-page .player-label-p2 {
        margin: 0 0 1px;
        font-size: 10px;
        line-height: 1.1;
    }

    body.game-page .player-row {
        display: grid;
        grid-template-columns: 27px minmax(0, 1fr) 27px;
        align-items: center;
    }

    body.game-page .roll-btn {
        box-sizing: border-box;
        width: 25px;
        height: 25px;
        min-width: 25px;
        min-height: 25px;
        padding: 0;
        font-size: 13px;
        border-radius: 5px;
    }

    body.game-page .player-score {
        font-size: clamp(16px, 3.2vh, 22px);
        line-height: 1;
    }

    body.game-page .player-score-label,
    body.game-page .counter-label {
        font-size: 8px;
        line-height: 1.1;
    }

    body.game-page .dice-result {
        margin-top: 1px;
        font-size: 10px;
        line-height: 1.1;
    }

    body.game-page .marker-counter {
        box-sizing: border-box;
        min-width: 40px;
        padding: 3px 5px;
        border-radius: 7px;
    }

    body.game-page .counter-value {
        font-size: 16px;
        line-height: 1;
    }

    body.game-page .turn-area {
        flex: 0 0 auto;
        margin: 1px 0;
        text-align: center;
        font-size: 10px;
        line-height: 1.1;
    }

    body.game-page #turn-badge {
        padding: 1px 5px;
        font-size: 10px;
    }

    body.game-page #log {
        flex: 0 0 auto;
        min-height: 0;
        margin: 0 0 2px;
        text-align: center;
        font-size: 9px;
        line-height: 1.1;
    }

    body.game-page .dice-hud-panel {
        box-sizing: border-box;
        flex: 0 0 auto;
        width: min(72vw, 320px);
        max-width: 320px;
        margin: 2px auto 4px;
        padding: 2px 4px;
        border-radius: 7px;
    }

    body.game-page .dice-hud-faces {
        display: flex;
        flex-flow: row nowrap;
        justify-content: center;
        gap: 3px;
    }

    body.game-page .dice-face {
        box-sizing: border-box;
        flex: 0 1 28px;
        width: clamp(20px, 4.5vh, 28px);
        height: clamp(20px, 4.5vh, 28px);
        min-width: 0;
        padding: 1px;
    }

    body.game-page .dice-face img {
        display: block;
        width: 100%;
        height: 100%;
        object-fit: contain;
    }

    /* Three genuinely separate columns: player 1 | board | player 2 */
    body.game-page .game-layout {
        display: grid !important;
        position: relative;
        box-sizing: border-box;
        width: 100% !important;
        min-width: 0 !important;
        margin: 0;
        padding: 0;
        grid-template-columns: minmax(0, 1fr) minmax(0, 0.9fr) minmax(0, 1fr);
        grid-template-rows: auto;
        grid-template-areas: "player-one board player-two";
        align-items: start;
        justify-content: stretch;
        gap: 5px;
        overflow: visible;
    }

    body.game-page .game-layout > .player-zone:first-child {
        grid-area: player-one;
    }

    body.game-page .game-layout > .center-area {
        grid-area: board;
        display: flex;
        position: relative;
        box-sizing: border-box;
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100%;
        margin: 0;
        padding: 0;
        justify-content: center;
        align-items: flex-start;
        overflow: visible;
    }

    body.game-page .game-layout > .player-zone:last-child {
        grid-area: player-two;
    }

    body.game-page .game-layout > .player-zone {
        display: flex;
        position: relative;
        box-sizing: border-box;
        flex-direction: column;
        align-items: stretch;
        justify-content: flex-start;
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100%;
        margin: 0;
        padding: 0;
        gap: 3px;
        overflow: hidden;
    }

    body.game-page .game-layout .action-bar {
        display: grid;
        position: relative;
        box-sizing: border-box;
        width: 100% !important;
        min-width: 0;
        margin: 0;
        padding: 0;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 2px;
        align-items: stretch;
        justify-content: stretch;
    }

    body.game-page .game-layout .zone-card,
    body.game-page .game-layout .played-card {
        display: flex;
        position: relative;
        box-sizing: border-box;
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100%;
        height: auto !important;
        max-height: none;
        aspect-ratio: 2 / 3;
        margin: 0;
        padding: 0;
        border-width: 1px;
        border-radius: 4px;
        box-shadow: none;
        overflow: hidden;
    }

    body.game-page .game-layout .zone-card span {
        font-size: clamp(7px, 1.7vh, 10px);
        line-height: 1.05;
        text-align: center;
        overflow-wrap: anywhere;
    }

    body.game-page .game-layout .zone-card img {
        display: block;
        width: 100%;
        height: 100%;
        object-fit: contain;
    }

    body.game-page .game-layout .hand {
        display: flex;
        position: relative;
        box-sizing: border-box;
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100%;
        margin: 0;
        padding: 2px 0 4px;
        justify-content: flex-start;
        align-items: flex-start;
        gap: 2px;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }

    body.game-page .game-layout .card {
        position: relative;
        box-sizing: border-box;
        flex: 0 0 clamp(22px, 4vw, 32px);
        width: clamp(22px, 4vw, 32px) !important;
        min-width: clamp(22px, 4vw, 32px) !important;
        max-width: clamp(22px, 4vw, 32px);
        height: clamp(33px, 6vw, 48px) !important;
        min-height: 0;
        margin: 0;
        padding: 0;
        border-radius: 3px;
        font-size: 10px;
    }

    body.game-page .game-layout .center-area .grid {
        display: grid;
        position: relative;
        box-sizing: border-box;
        width: min(100%, 34vh, 190px) !important;
        min-width: 0 !important;
        max-width: 100%;
        margin: 0 auto;
        padding: 0;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 2px;
    }

    body.game-page .game-layout .center-area .cell {
        position: relative;
        box-sizing: border-box;
        width: 100% !important;
        min-width: 0 !important;
        height: auto !important;
        aspect-ratio: 1 / 1;
        margin: 0;
        padding: 0;
        border-radius: 4px;
    }

    body.game-page .game-layout .marker.big {
        width: 66%;
        height: 66%;
        border-width: 1px;
        font-size: clamp(12px, 2.2vh, 17px);
    }

    body.game-page .game-layout .marker.small {
        width: 36%;
        height: 36%;
        border-width: 1px;
        font-size: clamp(8px, 1.5vh, 11px);
    }

    body.game-page .game-layout .card:hover,
    body.game-page .game-layout .cell.valid-move:hover,
    body.game-page .game-layout .cell.targetable:hover,
    body.game-page .game-layout .zone-card:hover {
        transform: none;
    }

    body.game-page .card-popup {
        box-sizing: border-box;
        width: min(180px, calc(100vw - 12px));
        max-height: 75vh;
        overflow-y: auto;
    }

    body.game-page #diceChoice {
        box-sizing: border-box;
        padding: 5px;
        flex-wrap: wrap;
    }

    body.game-page #diceChoice button,
    body.game-page .overlay button {
        min-height: 32px;
        margin: 2px;
        padding: 5px 8px;
        font-size: 14px;
    }

    body.game-page .popup {
        box-sizing: border-box;
        padding: 12px;
    }
}

@media screen and (orientation: landscape) and (pointer: coarse) and (max-height: 430px) {
    body.game-page .game-wrapper > h1 { font-size: 15px; }
    body.game-page .players { margin-bottom: 1px; }
    body.game-page .player-panel { padding: 2px 4px; }
    body.game-page .dice-hud-panel { margin: 1px auto 2px; padding: 1px 3px; }
    body.game-page .dice-face { width: 19px; height: 19px; flex-basis: 19px; }
    body.game-page .game-layout .center-area .grid { width: min(100%, 29vh, 155px) !important; }
    body.game-page .game-layout .zone-card,
    body.game-page .game-layout .played-card { max-height: none; }
    body.game-page .game-layout .card {
        flex-basis: 21px;
        width: 21px !important;
        min-width: 21px !important;
        max-width: 21px;
        height: 31px !important;
    }
}
