/* --- Reset & Base --- */
:root {
    --bg-color: #1c1c1e;
    --board-bg: #2c2c2e;
    --cell-empty: #3a3a3c;
    --text-color: #ffffff;
    --accent-color: #007aff;
    --combo-color: #ff9500;
    --ad-color: #32d74b;
    
    --board-size: 90vw; 
    --cell-gap: 4px;
    --cell-size: calc((var(--board-size) - (7 * var(--cell-gap))) / 8);
}

body {
    background-color: var(--tg-theme-bg-color, var(--bg-color));
    color: var(--tg-theme-text-color, var(--text-color));
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    padding: 0;
    overflow: hidden;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: none; 
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    justify-content: space-between;
    align-items: center;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    position: relative;
    transform: translateZ(0);
}

/* [ОПТИМИЗАЦИЯ] Скрытие приложения при повороте экрана */
@media screen and (orientation: landscape) {
    #app {
        display: none !important;
    }
    #orientation-warning {
        display: flex !important;
    }
}

.rotate-icon {
    font-size: 48px;
    margin-bottom: 20px;
    animation: rotate-anim 2s infinite ease-in-out;
}

@keyframes rotate-anim {
    0% { transform: rotate(0deg); }
    25% { transform: rotate(-90deg); }
    50% { transform: rotate(-90deg); }
    100% { transform: rotate(0deg); }
}

/* --- Header --- */
.game-header {
    width: 90%;
    height: 15vh;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    position: relative; 
}

.score-container {
    display: flex;
    flex-direction: column;
    z-index: 5;
}

.score-container .label {
    font-size: 11px;
    opacity: 0.6;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}

.score-container .value {
    font-size: 28px;
    font-weight: 800;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
    transition: color 0.2s ease;
    will-change: transform;
}

.score-pulse {
    color: #32d74b !important; 
    transform: scale(1.05);
    display: inline-block;
    transition: transform 0.1s ease-out;
}

/* --- COMBO (Top Center) --- */
.streak-wrapper {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%); 
    z-index: 10;
    pointer-events: none;
    display: flex;
    justify-content: center;
    width: auto;
}

.streak-badge {
    background: var(--combo-color);
    color: white;
    padding: 6px 14px;
    border-radius: 20px;
    font-weight: 800;
    font-size: 16px;
    box-shadow: 0 4px 15px rgba(255, 149, 0, 0.4);
    opacity: 0;
    transform: scale(0.5); 
    transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    will-change: transform, opacity;
}

.streak-badge.visible {
    opacity: 1;
    transform: scale(1);
}

.streak-hit {
    animation: streak-pop 0.2s ease-out;
}

@keyframes streak-pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

/* --- EARN MORE BUTTON --- */
.btn-icon {
    background: rgba(255, 255, 255, 0.1);
    color: var(--accent-color);
    border: none;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    z-index: 5;
    transition: background 0.1s;
}

.btn-icon:active {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(0.95);
}

/* --- Board --- */
.board-wrapper {
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: center;
}

.game-board {
    width: var(--board-size);
    height: var(--board-size);
    background-color: var(--board-bg);
    border-radius: 4px;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    gap: var(--cell-gap);
    padding: var(--cell-gap);
    box-sizing: border-box;
    contain: layout paint;
    transform: translateZ(0);
}

/* --- Footer (Hand) --- */
.hand-wrapper {
    height: 30vh; 
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding-top: 2vh; 
    background: rgba(0,0,0,0.02);
    box-sizing: border-box;
    z-index: 5;
    contain: layout;
}

.hand-container {
    display: flex;
    gap: 15px;
    width: 95%;
    justify-content: space-around;
    align-items: center;
}

.hand-slot {
    width: 30%;
    height: 80px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    transition: opacity 0.2s;
    will-change: opacity;
}

.mini-shape {
    transform: scale(0.7); 
    display: grid;
    gap: 2px;
}

/* --- Utils --- */
.hidden {
    display: none !important;
}

/* --- GAME OVER MODAL STYLES --- */
.final-score-box {
    margin: 10px 0 30px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.earned-label {
    font-size: 14px;
    opacity: 0.7;
    margin-bottom: 5px;
}

.earned-value {
    font-size: 42px;
    font-weight: 800;
    color: var(--text-color);
}

/* Buttons */
.btn-primary, .btn-ad {
    width: 100%;
    padding: 16px 20px;
    border-radius: 12px;
    font-size: 17px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    margin-bottom: 12px;
    transition: transform 0.1s, opacity 0.1s;
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: var(--tg-theme-button-color, var(--accent-color));
    color: var(--tg-theme-button-text-color, #fff);
}

.btn-primary:active, .btn-ad:active {
    transform: scale(0.98);
    opacity: 0.9;
}

.btn-ad {
    justify-content: space-between; 
    padding-left: 24px; 
    padding-right: 16px;
}

.ad-content {
    flex-grow: 1;
    text-align: center;
}

.ad-badge {
    font-size: 11px;
    background: rgba(255,255,255,0.2); 
    color: #fff;
    padding: 3px 6px;
    border-radius: 6px;
    font-weight: 800;
    letter-spacing: 0.5px;
}