:root {
    --bodyBg: #000;
    --bodyColor: #f0f0f0;
    --contentBg: #211f1d;
    --contentBg2: #20201f;
    --navBar: #1e1916;
    --navBarA: #fcd8a4;
    --navBarHomeHoverBg: #221612;
    --navBarAHoverBg: #ffe0d4;
    --navBarAHoverColor: #000;
    --navBarAActiveBg: #44331c;
    --navBarAActiveColor: #fff;
    --logoGold: #c99e4d;
    --textP: #fff7e8;
    --textGold: #ceae87;
    --textQuote: #fff9df;
    --textFooter:  #cdba9a;

    --citeBg: #2d2e2b;
    --citeColor: #f2edda;

    --oldBrown: #6d3522;
    --oldRed: #d76849;

    --base-font-size: 16px;
    font-size: 100%; /* Возвращаем к стандартному размеру */
}
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

@font-face {
    font-family: "Alice";
    src: url('/fonts/Alice-Regular.ttf');
}
@font-face {
    font-family: 'LoraMi';
    src: url('/fonts/Lora-MediumItalic.ttf');
}

html {
    background-color: var(--bodyBg);
    color: var(--bodyColor);
    font-size: 100%;
}

img, svg {
    filter: none !important;
}

body {
    margin: 0;
    padding: 0;

    height: 100vh;
    overflow: hidden;
    position: fixed; /* Фиксируем body, чтобы предотвратить прокрутку в Safari */
    width: 100%;
    left: 0;
    top: 0;

    font-size: 1rem;
    line-height: 1;
    font-family: 'LoraMi', 'Georgia Italic', 'Times New Roman Italic', 'Palatino Italic', serif;
    background-color: var(--bodyBg);
    color: var(--bodyColor);
}

.gcontainer {
    /* touch-action: manipulation — разрешает только панорамирование и масштабирование щипком (pinch-zoom), */ 
    /* но блокирует двойной тап для зума. Оптимальный вариант для отключения зума по двойному касанию. */
    touch-action: manipulation;

    display: grid;
    height: 100vh;
    max-height: 100%;
    width: 100%;
    margin: 0 auto;
    padding: 0;
    padding-top: env(safe-area-inset-top); /* Учёт адресной строки safari*/
    padding-bottom: env(safe-area-inset-bottom); /* Учёт панели навигации safari*/
    text-align: center;
    gap: 0;

    grid-template-areas:
    "mgrid-h1    mgrid-h1    mgrid-h1    mgrid-h1    mgrid-h1"
    "mgrid-but1  mgrid-but1  mgrid-but2  mgrid-but3  mgrid-but3"
    "mgrid-move  mgrid-move  mgrid-move  mgrid-art   mgrid-art"
    "mgrid-score mgrid-score mgrid-score mgrid-score mgrid-count"
    "mgrid-doska mgrid-doska mgrid-doska mgrid-doska mgrid-doska"
    "mgrid-niz   mgrid-niz   mgrid-niz   mgrid-niz   mgrid-niz";

    grid-template-columns: 3fr 3fr 3fr 3fr 3fr;
    grid-template-rows: auto auto auto auto 1fr auto;
    /* minmax(auto, max-content) = строка будет высотой как минимум AUTO, но не больше, чем нужно для полного отображения содержимого, т.е. у нас - картинка */
    box-sizing: border-box;

    background-image: url('/image/games/5goroshin/eshelet1920q80.jpg');
    background-repeat: no-repeat;
    background-position: top left;
    background-size: cover;
    /* BG-color set after image. If set before && image fails, can produce transparent BG */
    background-color: #d7aa63;
}
@supports (height: 100dvh) {
    .gcontainer {
        height: 100dvh; /* Современный подход для iPad */
    }
}
#game-h1div {
    grid-area: mgrid-h1;

    display: flex;
    align-items: center; /* Выравниваем элементы по вертикали по центру */
    justify-content: center; /* Центрируем содержимое контейнера по горизонтали */
    gap: 0; /* Убираем отступы между элементами */
    width: 100%; /* Занимаем всю доступную ширину */
    box-sizing: border-box;

    margin: 0.1rem auto 0.1rem auto;
}
#game-h1 {
    order: 0; /* Гарантируем, что h1 будет в центре */
    flex: 0 0 auto; /* Не растягиваем и не сжимаем, берём естественный размер */
    
    margin: 0 0.1rem;
    font-family: 'Alice', 'Georgia', 'Times New Roman', 'Palatino', serif;
    font-size: 1.375rem;
    font-weight: bold;
    color: #6d3522;
    padding: 0;
}
.game-h1img {
    flex: 0 1 auto; /* Элементы могут сжиматься, но не растягиваться*/

    max-width: 20%;
    max-height: 1.3rem;
    width: auto;
    height: auto;
    margin: 0;

    overflow: hidden;
}

#kusok-etc {
    grid-area: mgrid-niz;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    height: 10vh;
}
#kusok-doska{
    grid-area: mgrid-doska;
    width: 100%;
    margin: 0.4rem auto;
    /* Ограничиваем размер содержимого, чтобы блок мог сжиматься */
    width: min(100%, max-content);
}
#game-board {
    aspect-ratio: 1 / 1;
    max-height: 64vh;

    display: grid;
    padding: 0;
    margin: 0.5rem auto;
    
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    gap: 1.1%;

    background-color: #141311;
    background-size: cover;

    box-sizing: border-box;
}
.cell {
    filter: none !important;

    background-color: #5c4831;

    width: 100%;
    min-height: 0; /* Важно для Safari при вложенных Grid */
    height: 100%;
   
    aspect-ratio: 1 / 1;

    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    position: relative;

    border: none;
}
.topButtons {
    margin: 0 auto;
    padding: 0;

    max-height: 20vh;
    /* Ограничиваем размер содержимого, чтобы блок мог сжиматься */
    
    min-width: 0;
    min-height: 0; /* Позволяет сжиматься при нехватке места */
    /* height: min(100%, max-content); */

    cursor: pointer;

    display: flex;
    justify-content: center;
    align-items: center;
}
#settingsButton {
    grid-area: mgrid-but1;
}
#helpButton {
    grid-area: mgrid-but2;
    min-height: 1rem;
}
#exitButton {
    grid-area: mgrid-but3;
}
.butimg {
    display: block; /* Убирает лишний отступ под изображением */
    margin: 0 auto;

    object-fit: contain; /* Или contain — в зависимости от желаемого поведения */
    max-width: 100%;
    max-height: 90%;
    width: auto;
    height: auto;
}

#movediv {
    grid-area: mgrid-move;
}
#scorediv {
    grid-area: mgrid-score;
}
.score {
    margin-bottom: 20px;
}
.tablo {
    min-height: 0; /* Позволяет сжиматься при нехватке места */
    max-height: 25vh;
    margin: 0 auto;
    /* Ограничиваем размер содержимого, чтобы блок мог сжиматься */
    height: min(100%, max-content);

    margin: 0;
    padding: 0;
    display: flex;
    justify-content: left; /* horiz */
    align-items: center;
    /* overflow: hidden; */
}
.tabloimg {
    max-height: 2.5rem;
    width: auto;
    height: 100%; /* Сохраняет пропорции изображения */
    display: block; /* Убирает лишний отступ под изображением */
    object-fit: contain; /* Или contain — в зависимости от желаемого поведения */
    margin: 0;
    padding: 0.1rem 0 0.1rem 0;
}
#art {
    grid-area: mgrid-art;

    display: flex;
    justify-content: right  ; /* horiz */
    align-items: center;
    overflow: hidden;
    margin: 0;
}
#flag1 {
    opacity: 0;
    visibility: hidden;
    transform: translateX(100%);
    transition: opacity 0.5s ease, visibility 0.5s ease, transform 0.5s ease;

    max-height: 3rem;
    height: 90%;
    width: auto;
    aspect-ratio: 320 / 134;

    background-image: url('/image/games/5goroshin/flag1.svg');
    background-repeat: no-repeat;
    background-position: center right;
    background-size: contain;

    display: flex;
    justify-content: center ; /* horiz */
    align-items: center;
    overflow: hidden;
    margin: 0;
    padding: 0;
}
#flag1.visible {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
}
.flag1img {
    margin: 0;
    padding: 0;
    height: 80%;
}

h1 {
    margin-bottom: 10px;
}
h2 {
    color: var(--textP);
    font-size: 1.25rem;
    text-align: center;
    margin: 1rem 0;
}
h3 {
    font-size: 1.125rem;
    color: var(--textGold);
}
p {
    margin: 0.5rem 1rem;
    text-align: left;
    font-size: 1rem;
    hyphens: auto;    /* Автоматический перенос */
    color: var(--textP);
}
.tablotxt {
    text-align: left;
    margin: 0 0 0.2rem 0.4rem;
    padding: 0;
    font-family: 'Alice', 'Georgia', 'Times New Roman', 'Palatino', serif;
    font-size: 2rem;
    font-weight: bold;
    color: #5f3c19
}
#countdown-div {
    grid-area: mgrid-count;
    margin: 0;
    padding: 0;
    max-height: 100%;

    display: none;
    justify-content: center ; /* horiz */
    align-items: center; /* vertical */

    background-image: url('/image/games/5goroshin/cell_zap5.svg');
    background-repeat: no-repeat;
    background-position: center center;
    background-size: contain;
}
#countdown-h2 {
    padding: 0 0 0.3rem 0;
    margin: 0;
    display: block;
    font-family: 'Alice', 'Georgia', 'Times New Roman', 'Palatino', serif;
    font-size: 2rem;
    font-weight: bold;
    color: #f4f4df
}

/* Базовый стиль для шарика -------------------------------- O -----------------*/
.ball {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    transition: transform 0.2s ease-in-out;
    position: relative;
    z-index: 5;
}
.temp-ball-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 101;
}
.temp-growing-ball {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 10px;
    height: 10px;
    opacity: 1;
    transform: translate(-50%, -50%);
    transition: none; /* Отключаем переход на старте */
}
/* Класс, запускающий анимацию */
.temp-growing-ball.animate {
    width: 100%;
    height: 100%;
    opacity: 1;
    transition: width 400ms ease-out, height 400ms ease-out, opacity 400ms ease-out;
}

.highlight-cross {
    animation: highlightCross 1s ease-in-out;
}
@keyframes highlightCross {
    0% {
        background-color: #3d2f20;
    }
    50% {
        background-color: #836a30;
    }
    100% {
        background-color: #3d2f20;
    }
}

.transforming-ball {
    animation: transformBall 1s ease-in-out;
    animation-fill-mode: forwards; /* Сохраняем конечное состояние */
    z-index: 102;
    position: relative;
}

@keyframes transformBall {
    0% {
        transform: scale(1) rotate(0deg);
    }
    50% {
        transform: scale(2) rotate(360deg);
    }
    100% {
        transform: scale(1) rotate(720deg);
    }
}

/* xxx---------- CSS для запретных клеток ------------xxx */
.forbidden-cell {
    box-shadow: inset 0.2rem 0.2rem 0.3rem -2px rgba(20, 19, 17, 0.7);
    background-image: url('/image/games/5goroshin/cell_zap6.svg');
    background-repeat: no-repeat;
    background-position: center center;
    background-size: cover;
    /* BG-color set after image. If set before && image fails, can produce transparent BG */
    background-color: rgb(31, 31, 31);
}
.forbidden-red {
    background-color: rgb(31, 31, 31);
    transition: background-color 1s ease-in;
}

/* ============== подсветка выбранных шаров и клеток ================ */
.moving {
    z-index: 20;
    transform: scale(1);
}
.highlight {
    border: 3px solid rgb(255, 230, 0);
}
.highlight-red {
    border: 3px solid rgb(255, 81, 0);
    animation: flashRed 0.5s ease-in-out;
}
@keyframes flashRed {
    0% { border-color: rgb(240, 34, 34); }
    50% { border-color: #ff3333; }
    100% { border-color: red; }
}

/*                              _______________________                               */
/* -------------------======== [                       ]========--------------------- */
/* -------------------======== [ FOR LANDSCAPE SCREENS ]========--------------------- */
/* -------------------======== [                       ]========--------------------- */
/* @media screen and (orientation:landscape){ */
@media only screen and (min-aspect-ratio: 4/3) {
    .gcontainer {
        display: grid;
        height: 100vh;
        max-height: 100%;
        width: 100%;
        margin: 0 auto;
        padding: 0;
        padding-top: env(safe-area-inset-top); /* Учёт адресной строки safari*/
        padding-bottom: env(safe-area-inset-bottom); /* Учёт панели навигации safari*/
        text-align: center;
        gap: 0;
    
        grid-template-areas:
        "mgrid-h1    mgrid-h1    mgrid-h1    mgrid-doska"
        "mgrid-but1  mgrid-but2  mgrid-but3  mgrid-doska"
        "mgrid-move  mgrid-move  mgrid-art   mgrid-doska"
        "mgrid-score mgrid-score mgrid-count mgrid-doska"
        "mgrid-niz   mgrid-niz   mgrid-niz   mgrid-doska";
    
        grid-template-columns: 2fr 2fr 2fr 8fr;
        grid-template-rows: auto 4fr 3fr 3fr 10fr;
        /* minmax(auto, max-content) = строка будет высотой как минимум AUTO, но не больше, чем нужно для полного отображения содержимого, т.е. у нас - картинка */
        box-sizing: border-box;
    
        background-image: url('/image/games/5goroshin/eshelet1920q80.jpg');
        background-repeat: no-repeat;
        background-position: top left;
        background-size: cover;
        /* BG-color set after image. If set before && image fails, can produce transparent BG */
        background-color: #d7aa63;
    }
    @supports (height: 100dvh) {
        .gcontainer {
            height: 100dvh; /* Современный подход для iPad */
        }
    }
    
    #game-h1 {
        font-size: 1.25rem;
    }
    
    #kusok-etc {
        grid-area: mgrid-niz;
        display: flex;
        justify-content: center;
        align-items: center;
        overflow: hidden;
        height: 100%;
    }
    #kusok-doska{
        grid-area: mgrid-doska;
        margin: 0.4rem auto;
        /* Ограничиваем размер содержимого, чтобы блок мог сжиматься */
        width: min(100%, max-content);

        min-height: 0;
        height: auto;

        display: flex;
        justify-content: flex-start;
        align-items: center;
    }
    #game-board {
        aspect-ratio: 1 / 1;
        min-width: 0;
        max-width: 100%;
        max-height: 100%;
        height: min(82vh, 50vw);
    
        display: grid;
        padding: 0;
        margin: 1rem;
        
        grid-template-columns: repeat(8, 1fr);
        grid-template-rows: repeat(8, 1fr);
        gap: 1.1%;
    
        background-color: #141311;
        background-size: cover;
    
        box-sizing: border-box;
    }
    @supports (height: 96dvh) {
        #game-board {
            max-height: 96dvh;
        }
    }

    .topButtons {
        align-self: center; /* по вертикали для дочернего эл-та в grid */
        max-height: 5rem;
        min-height: 0;
        margin: 0;
        padding: 0;
        cursor: pointer;
        display: flex;
        justify-content: center;
        align-items: center;
    }
    .butimg {
        min-height: 0;
        min-width: 0;
        max-width: 100%;
        max-height: 3.5rem;
        max-height: calc((10vh + 10vw) / 2.5);
        padding: 0 0 0.1rem 0;
    }
    #movediv {
        margin: 0;
        padding: 0;
    }
    #scorediv {
        margin: 0;
        padding: 0;
    }
    .score {
        margin-bottom: 20px;
    }
  /* tablo - общий класс для scorediv & movediv */
    .tablo {
        display: flex;
        margin: 0;
        padding: 0;
        justify-content: left; /* horiz */
        align-items: center;
        overflow: hidden;
    }
    .tabloimg {
        height: 75%;
        max-height: 3.5rem;
        padding: 0;
        margin: 1rem 0 1rem 0;
    }
    .tablotxt {
        font-size: 2.3rem;
    }
    #art {
        grid-area: mgrid-art;

        display: flex;
        justify-content: right  ; /* horiz */
        align-items: center;
        overflow: hidden;
        margin: 0;
        padding: 0;
    }
    #flag1 {
        transform: none; /* сбрасываем transform, т.к. в пейзажной у нас только плавное появлние */
        transition: opacity 0.5s ease, visibility 0.5s ease; /* убираем transform из transition */
      
        max-height: 3.5rem;
        width: auto;
        aspect-ratio: 320 / 134;
    
        background-image: url('/image/games/5goroshin/flag2.svg');
        background-repeat: no-repeat;
        background-position: center center;
        background-size: contain;
    
        display: flex;
        justify-content: center ; /* horiz */
        align-items: center;
        
        overflow: hidden;
        margin: 0 auto;
        padding: 0;
    }
    #flag1.visible {
        transform: none; /* обязательно сбрасываем и здесь */
    }
    .flag1img {
        display: block;
        margin: 0 auto;
        padding: 0;
        width: 75%;
        height: auto;
    }
    #countdown-div {
        grid-area: mgrid-count;
        margin: auto 0;
        padding: 0;
        min-height: 0;
        height: 90%;
        width: auto;
   
        display: none;
    }
}

/* ----------- iPad 1, 2, Mini and Air PORTRAIT ----------- */
/* Стили для планшетов в портрете, включая крупные модели */
@media only screen 
  and (min-device-width: 768px) 
  and (max-device-width: 1024px) 
  and (orientation: portrait) {

    .gcontainer {
        grid-template-areas:
        "mgrid-but1  mgrid-but1  mgrid-but2  mgrid-but3  mgrid-but3"
        "mgrid-move  mgrid-move  mgrid-move  mgrid-count mgrid-art"
        "mgrid-score mgrid-score mgrid-score mgrid-count mgrid-art"
        "mgrid-doska mgrid-doska mgrid-doska mgrid-doska mgrid-doska"
        "mgrid-niz   mgrid-niz   mgrid-niz   mgrid-niz   mgrid-niz";
    
        grid-template-columns: 3fr 3fr 3fr 3fr 3fr;
        grid-template-rows: auto auto auto 1fr auto;
    }
    #countdown-div {
        grid-area: mgrid-count;
        min-height: 0;
        max-height: 90%;
        width: auto;
   
        display: none;
    }

}



/* ----------- iPad 1, 2, Mini and Air LANDSCAPE----------- */
@media only screen 
  and (min-device-width: 768px) 
  and (max-device-width: 1024px) 
  and (orientation: landscape) 
  and (-webkit-min-device-pixel-ratio: 1) {

    
}

/* ----------- Non-Retina Laptops ----------- */
@media only screen 
    and (min-device-width: 1200px)
    and (orientation: landscape) { 
    .tablotxt {
        font-size: 3rem;
    }

    #game-h1div {
        margin: 1rem 0 0 0;
    }
    #game-h1 {
        font-size: 1.5rem;
    }


}
