/* =========================================================
   Tetris Game — Mobile-only v3.0
   Las Casas © 2024
   ========================================================= */

.tetris-game-wrapper {
    position: relative;
    display: inline-block;
    width: 100%;
}

/* --- Кнопка открытия --- */
.tetris-open-btn {
    width: 100%;
    background: linear-gradient(135deg, #2c3e50, #1a2632);
    border: none;
    padding: 14px 20px;
    font-size: 16px;
    font-weight: 700;
    color: #ffffff;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: inherit;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
.tetris-open-btn:active {
    background: linear-gradient(135deg, #1abc9c, #16a085);
    transform: scale(0.98);
}

/* --- Темы --- */
.tetris-modal[data-theme="teal"]   { --t-accent: #1abc9c; --t-glow: rgba(26,188,156,0.35); }
.tetris-modal[data-theme="blue"]   { --t-accent: #6c9eff; --t-glow: rgba(108,158,255,0.35); }
.tetris-modal[data-theme="purple"] { --t-accent: #d96cd9; --t-glow: rgba(217,108,217,0.35); }
.tetris-modal[data-theme="orange"] { --t-accent: #f0a35e; --t-glow: rgba(240,163,94,0.35); }
.tetris-modal[data-theme="red"]    { --t-accent: #e66767; --t-glow: rgba(230,103,103,0.35); }
.tetris-modal[data-theme="yellow"] { --t-accent: #f7e476; --t-glow: rgba(247,228,118,0.35); }

/* =========================================================
   МОДАЛЬНОЕ ОКНО — полноэкранный overlay со скроллом
   ========================================================= */
.tetris-modal {
    --t-accent: #1abc9c;
    --t-glow: rgba(26,188,156,0.35);

    /* Покрываем весь экран */
    position: fixed;
    inset: 0;
    z-index: 10000;

    /* Скролл по всему оверлею */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* инерционный скролл iOS */
    overscroll-behavior: contain; /* скролл не пробрасывается на страницу */

    background: rgba(0,0,0,0.92);
    animation: tetrisFadeIn 0.2s ease;

    /* Контент выравниваем по верху с отступом */
    display: flex;
    align-items: flex-start;
    justify-content: center;
    /* снизу запас, чтобы кнопки не обрезались (+ жестовая полоса iPhone) */
    padding: 0 0 calc(40px + env(safe-area-inset-bottom, 0px)) 0;
}

@keyframes tetrisFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* Внутренний контейнер — НЕ фиксированный, течёт в документе */
.tetris-modal-content {
    background: linear-gradient(145deg, #0f172a, #0a0f1f);
    border-radius: 0 0 24px 24px;
    padding: 16px 14px 24px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.6);
    border: 1px solid rgba(45,58,94,0.6);
    border-top: none;
    width: 100%;
    max-width: 420px;
    /* Без min-height — пусть высота определяется контентом */
}

/* --- Шапка --- */
.tetris-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid #2d3a5e;
    /* Липкий заголовок чтобы кнопка закрытия всегда была видна */
    position: sticky;
    top: 0;
    background: #0f172a;
    z-index: 2;
    padding-top: 14px;
    margin-top: -16px;
    border-radius: 0;
}

.tetris-title {
    font-size: 20px;
    font-weight: 800;
    background: linear-gradient(135deg, #fff, var(--t-accent));
    background-clip: text;
    -webkit-background-clip: text;
    color: transparent;
    letter-spacing: 3px;
}

.tetris-close {
    background: none;
    border: none;
    font-size: 26px;
    cursor: pointer;
    color: #ff8a7a;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.15s;
}
.tetris-close:active { background: rgba(255,138,122,0.15); }

/* --- Игровая область --- */
.tetris-game-area {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    justify-content: center;
}

.tetris-canvas {
    background: #010514;
    border-radius: 10px;
    box-shadow: 0 0 0 2px #2a3a60;
    display: block;
    -webkit-user-select: none;
    user-select: none;
    touch-action: none; /* свайпы обрабатываем вручную */
    flex-shrink: 0;
}

/* --- Боковая панель --- */
.tetris-side-panel {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 82px;
}

.tetris-score-box,
.tetris-level-box,
.tetris-next-box {
    background: #010514;
    border-radius: 14px;
    padding: 10px 8px;
    text-align: center;
    border: 1px solid #2a3a60;
}

.tetris-score-label,
.tetris-next-label {
    font-size: 9px;
    letter-spacing: 1.5px;
    color: #7e90b0;
    text-transform: uppercase;
    margin-bottom: 5px;
}

.tetris-score-value {
    font-size: 24px;
    font-weight: 800;
    color: #b9fbc0;
    text-shadow: 0 0 8px #2aff6e;
    line-height: 1;
}

.tetris-level-value {
    font-size: 24px;
    font-weight: 800;
    color: var(--t-accent);
    text-shadow: 0 0 8px var(--t-glow);
    line-height: 1;
}

.tetris-next-canvas {
    background: #010514;
    border-radius: 6px;
    display: block;
    margin: 0 auto;
}

.tetris-reset-btn {
    background: #2c3f6b;
    border: none;
    padding: 9px 8px;
    border-radius: 40px;
    color: white;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    width: 100%;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    min-height: 42px;
}
.tetris-reset-btn:active { background: var(--t-accent); }

/* =========================================================
   КНОПКИ УПРАВЛЕНИЯ
   ========================================================= */
.tetris-controls {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-top: 14px;
}
.tetris-controls-bottom {
    margin-top: 8px;
}

.tetris-ctrl {
    background: #1f2c46;
    border: 1px solid #2a3a60;
    border-radius: 14px;
    color: white;
    font-size: 22px;
    font-weight: 700;
    cursor: pointer;

    /* Крупные зоны касания */
    min-width: 72px;
    min-height: 62px;
    display: flex;
    align-items: center;
    justify-content: center;

    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
    transition: background 0.08s, transform 0.08s;
}
.tetris-ctrl-wide {
    flex: 1;
    font-size: 15px;
    min-height: 54px;
}
.tetris-ctrl:active,
.tetris-ctrl.pressed {
    background: var(--t-accent);
    transform: scale(0.93);
}

/* Подсказка — скрыта (мобайл онли) */
.tetris-hint { display: none; }

/* =========================================================
   АДАПТИВ — маленькие экраны
   ========================================================= */
/* Телефоны: вписываем канвас в реальную видимую высоту (dvh),
   чтобы поле + кнопки управления умещались без обрезки;
   пропорции 1:2 сохраняются автоматически (width:auto) */
@media (max-width: 480px) {
    .tetris-canvas {
        max-height: min(500px, 52dvh);
        width: auto;
    }
}

@media (max-width: 360px) {
    .tetris-ctrl {
        min-width: 60px;
        min-height: 56px;
        font-size: 20px;
    }
    .tetris-side-panel { min-width: 70px; }
    .tetris-score-value,
    .tetris-level-value { font-size: 20px; }
}

/* Планшеты и десктоп — центрируем контент */
@media (min-width: 481px) {
    .tetris-modal {
        padding: 40px 0;
        align-items: center;
    }
    .tetris-modal-content {
        border-radius: 24px;
        border-top: 1px solid rgba(45,58,94,0.6);
    }
    .tetris-modal-header {
        position: static;
        margin-top: 0;
        padding-top: 0;
        background: transparent;
        border-radius: 24px 24px 0 0;
    }
    .tetris-hint {
        display: block;
        text-align: center;
        margin-top: 10px;
        font-size: 10px;
        color: #3d5080;
    }
}
