/* ============================================================
   snake_mobile.css — Мобильная адаптация игры Змейка
   Все стили обёрнуты в @media (max-width: 768px).
   Основной snake.css НЕ модифицируется.
   ============================================================ */

@media (max-width: 768px) {

    /* === ХЕДЕР === */

    /* Скрываем стандартные элементы хедера */
    .snake-overlay .top-bar .user-pedestal,
    .snake-overlay .top-bar>div:first-child {
        display: none !important;
    }

    .snake-overlay .top-bar {
        padding: 6px 10px !important;
        margin-bottom: 2px !important;
        justify-content: center !important;
        position: relative;
    }

    .snake-overlay .top-bar-center {
        position: static !important;
        transform: none !important;
        font-size: 0.85rem;
    }

    .snake-overlay .top-bar-center div {
        font-size: 0.9rem !important;
    }

    /* Бургер-кнопка */
    #mobile-burger-btn {
        display: flex !important;
        position: absolute;
        left: 10px;
        top: 50%;
        transform: translateY(-50%);
        background: rgba(255, 255, 255, 0.2);
        border: 1px solid rgba(255, 255, 255, 0.3);
        border-radius: 8px;
        color: var(--cab-accent, #5d4037);
        font-size: 1.3rem;
        width: 36px;
        height: 36px;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: all 0.2s;
        z-index: 10;
    }

    #mobile-burger-btn:active {
        background: rgba(255, 255, 255, 0.4);
    }

    /* === ВЫДВИЖНОЙ ХЕДЕР === */
    #mobile-header-drawer {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        background: var(--cab-card-bg, rgba(255, 250, 240, 0.98));
        z-index: 100000;
        transform: translateY(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
        padding: 15px 20px;
        box-sizing: border-box;
        display: block !important;
        /* Гарантируем display */
    }

    #mobile-header-drawer.open {
        transform: translateY(0);
    }

    .mobile-drawer-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 12px;
        padding-bottom: 10px;
        border-bottom: 1px solid var(--cab-border, rgba(100, 80, 60, 0.2));
    }

    .mobile-drawer-header .mobile-back-btn {
        background: white;
        color: var(--cab-accent, #5d4037);
        border: 1px solid var(--cab-border, #ddd);
        padding: 8px 16px;
        border-radius: 50px;
        font-weight: 600;
        font-size: 0.9em;
        cursor: pointer;
    }

    .mobile-drawer-header .mobile-close-drawer {
        background: none;
        border: none;
        font-size: 1.5rem;
        color: var(--cab-text-muted, #6b4a28);
        cursor: pointer;
        padding: 5px;
    }

    .mobile-drawer-user {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 10px 0;
    }

    .mobile-drawer-user .mobile-user-avatar {
        width: 40px;
        height: 40px;
        background: white;
        border-radius: 10px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.3rem;
        border: 1px solid var(--cab-border, #ddd);
    }

    .mobile-drawer-user .mobile-user-info {
        flex: 1;
    }

    .mobile-drawer-user .mobile-user-name {
        font-weight: 700;
        color: var(--cab-accent, #5d4037);
        font-size: 1rem;
    }

    .mobile-drawer-user .mobile-user-email {
        font-size: 0.8rem;
        color: var(--cab-text-muted, #6b4a28);
    }

    .mobile-drawer-actions {
        display: flex;
        gap: 10px;
        margin-top: 10px;
    }

    .mobile-drawer-actions button {
        flex: 1;
        padding: 10px;
        border-radius: 10px;
        border: 1px solid var(--cab-border, #ddd);
        font-weight: 600;
        font-size: 0.85em;
        cursor: pointer;
        transition: all 0.2s;
    }

    .mobile-drawer-actions .mobile-cabinet-btn {
        background: var(--cab-accent, #5d4037);
        color: white;
        border-color: transparent;
    }

    .mobile-drawer-actions .mobile-logout-btn {
        background: white;
        color: #dc3545;
        border-color: #dc3545;
    }

    /* Оверлей для закрытия по тапу позади */
    #mobile-drawer-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 90000;
        /* Ниже драверов (100000), но выше основного контента */
        display: none;
        opacity: 0;
        transition: opacity 0.3s;
    }

    #mobile-drawer-overlay.open {
        display: block;
        opacity: 1;
    }

    /* === LAYOUT === */

    .snake-overlay .cabinet-container {
        padding: 5px !important;
    }

    .snake-overlay .game-wrapper {
        flex-direction: column !important;
        gap: 0 !important;
        padding: 0 5px !important;
    }

    /* Скрываем десктопные контролы */
    .snake-overlay .game-controls {
        display: none !important;
    }

    /* === ИГРОВОЙ КОНТЕЙНЕР === */

    .snake-overlay .game-container {
        width: 100% !important;
        max-width: 100% !important;
        padding: 4px 8px 5px !important;
        /* Уменьшаем внутренний отступ, так как джойстик снаружи */
        border-radius: 10px !important;
        box-shadow: none !important;
        margin-bottom: 120px !important;
        /* Отступ для джойстика и панели */
    }

    /* Общий прогресс */
    .snake-overlay .total-score-panel {
        padding: 4px 8px !important;
        border-radius: 10px !important;
    }

    .snake-overlay .total-score-panel .score-label {
        font-size: 0.7rem !important;
    }

    .snake-overlay .total-score-panel .score-value {
        font-size: 1rem !important;
    }

    /* Бегущая строка */
    #running-text-container {
        height: 24px !important;
        line-height: 24px !important;
        font-size: 0.75em !important;
        margin: 1px 0 2px !important;
    }

    /* Перевод */
    .snake-overlay #translation-display {
        font-size: 1.5em !important;
    }

    .snake-overlay .translation-bar {
        padding: 2px !important;
        margin-bottom: 2px !important;
    }

    /* Score bar — ультракомпактная сетка */
    .snake-overlay .score-bar {
        font-size: 0.65em !important;
        gap: 1px 4px !important;
        margin-bottom: 2px !important;
        padding: 3px 6px !important;
        display: grid !important;
        grid-template-columns: repeat(3, 1fr) !important;
    }

    .snake-overlay .score-bar>div {
        padding: 1px 2px !important;
        white-space: nowrap;
    }

    .snake-overlay #current-word-display {
        grid-column: 1 / -1 !important;
        font-size: 0.95em !important;
        padding: 2px 4px !important;
        margin-top: 1px !important;
    }

    /* Canvas — заполняет ширину */
    .snake-overlay canvas {
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 6px !important;
    }

    .snake-overlay .canvas-wrapper {
        width: 100% !important;
    }

    /* Оверлеи на Canvas */
    .snake-overlay #pause-screen {
        font-size: 2rem !important;
    }

    .snake-overlay #countdown-overlay {
        font-size: 4rem !important;
    }

    /* Стартовый экран */
    .start-prompt-title-main {
        font-size: 2rem !important;
        top: 20px !important;
    }

    .start-prompt-btn {
        font-size: 1.3rem !important;
        padding: 10px 30px !important;
    }

    .start-prompt-decor {
        font-size: 3rem !important;
    }

    .start-prompt-decor.left {
        left: 15px !important;
    }

    .start-prompt-decor.right {
        right: 15px !important;
    }

    #start-prompt-title {
        font-size: 1.1rem !important;
    }

    .start-prompt-content {
        margin-top: 30px !important;
    }

    .letter-item {
        font-size: 1.5rem !important;
    }

    /* Показываем кнопку автопилота, если она есть (админ) */
    #auto-pilot-btn {
        display: none;
        /* Будет переопределено js или другими правилами */
    }

    /* === КОНТЕЙНЕР ПОД ПОЛЕМ: кнопки ⚙️ и мессенджер === */
    .snake-overlay .canvas-wrapper {
        margin-bottom: 5px !important;
    }

    /* === ПАНЕЛЬ УПРАВЛЕНИЯ ВНИЗУ === */
    .mobile-bottom-bar {
        display: flex !important;
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 60px;
        background: var(--cab-card-bg, rgba(255, 250, 240, 0.95));
        backdrop-filter: blur(10px);
        border-top: 1px solid var(--cab-border, rgba(0, 0, 0, 0.1));
        z-index: 200000;
        align-items: center;
        justify-content: space-around;
        padding: 0 10px;
        box-sizing: border-box;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    }

    /* Кнопка Управление ⚙️ */
    #mobile-controls-btn {
        display: flex !important;
        position: static !important;
        width: 44px;
        height: 44px;
        background: var(--cab-accent, #5d4037) !important;
        color: white !important;
        border: none !important;
        border-radius: 12px !important;
        font-size: 1.3rem !important;
        align-items: center;
        justify-content: center;
        cursor: pointer !important;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2) !important;
        transition: all 0.2s;
    }

    /* Кнопка Пауза || */
    #mobile-pause-btn {
        display: flex !important;
        position: static !important;
        width: 50px;
        height: 50px;
        background: #007bff !important;
        color: white !important;
        border: 2px solid white !important;
        border-radius: 50% !important;
        font-size: 1.5rem !important;
        align-items: center;
        justify-content: center;
        cursor: pointer !important;
        box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3) !important;
        transition: all 0.2s;
        margin-top: -15px;
        /* Выпирает немного вверх */
    }

    /* Админская ракета (Автопилот) */
    #auto-pilot-btn {
        display: flex !important;
        position: static !important;
        width: 44px !important;
        height: 44px !important;
        background: linear-gradient(135deg, #ff9800, #f44336) !important;
        color: white !important;
        border: 2px solid white !important;
        border-radius: 50% !important;
        font-size: 1.3rem !important;
        align-items: center;
        justify-content: center;
        cursor: pointer !important;
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3) !important;
        transform: none !important;
        margin: 0 !important;
    }

    /* Мессенджер */
    .chat-floating-widget {
        position: static !important;
        width: 44px !important;
        height: 44px !important;
        background: #25d366 !important;
        border-radius: 12px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2) !important;
    }

    #mobile-pause-btn:active,
    #auto-pilot-btn:active,
    #mobile-controls-btn:active,
    #mobile-dpad-toggle:active {
        transform: scale(0.9) !important;
    }

    #mobile-dpad-toggle {
        display: flex !important;
        position: static !important;
        width: 44px;
        height: 44px;
        background: var(--cab-accent, #5d4037) !important;
        color: white !important;
        border: none !important;
        border-radius: 12px !important;
        font-size: 1.3rem !important;
        align-items: center;
        justify-content: center;
        cursor: pointer !important;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2) !important;
        transition: all 0.2s;
    }

    #mobile-dpad-toggle.active {
        background: #2196F3 !important;
        /* Подсвечиваем, когда активен */
    }

    /* === DPAD (Джойстик) === */
    .mobile-dpad {
        display: flex !important;
        flex-direction: column;
        align-items: center;
        gap: 5px;
        margin: 10px auto;
        padding-bottom: 70px;
        /* Чтобы не перекрывалось нижней панелью */
        transition: opacity 0.3s, transform 0.3s;
    }

    .mobile-dpad.hidden {
        display: none !important;
    }

    .dpad-middle {
        display: flex;
        gap: 40px;
    }

    .dpad-btn {
        width: 50px;
        height: 50px;
        background: rgba(255, 255, 255, 0.2) !important;
        border: 2px solid rgba(255, 255, 255, 0.4) !important;
        border-radius: 12px !important;
        color: var(--cab-accent, #5d4037) !important;
        font-size: 1.5rem !important;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: all 0.1s;
        box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
        touch-action: manipulation;
    }

    .dpad-btn:active {
        background: rgba(255, 255, 255, 0.5) !important;
        transform: scale(0.9);
    }

    /* Мессенджер */
    .chat-floating-widget {
        position: static !important;
        width: 44px !important;
        height: 44px !important;
        background: #25d366 !important;
        border-radius: 12px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2) !important;
        transform: none !important;
        left: auto !important;
        top: auto !important;
        opacity: 1 !important;
        z-index: 200000 !important;
    }

    .chat-floating-widget i {
        font-size: 20px !important;
        color: white !important;
    }

    /* === ВЫДВИЖНАЯ ПАНЕЛЬ УПРАВЛЕНИЯ (снизу) === */
    #mobile-controls-drawer {
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        max-height: 85vh;
        background: var(--container-bg, #ffffff);
        z-index: 100000;
        transform: translateY(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
        border-radius: 20px 20px 0 0;
        overflow-y: auto;
        padding: 0;
        box-sizing: border-box;
        display: block !important;
    }

    #mobile-controls-drawer.open {
        transform: translateY(0);
    }

    .mobile-controls-handle {
        width: 40px;
        height: 5px;
        background: #ccc;
        border-radius: 3px;
        margin: 10px auto;
    }

    .mobile-controls-content {
        padding: 0 15px 20px;
    }

    .mobile-controls-content h3 {
        margin: 10px 0 8px;
        color: var(--title-color, #0056b3);
        text-align: center;
        font-size: 1em;
        padding-bottom: 5px;
        border-bottom: 2px solid var(--bg-color, #f0f4f8);
    }

    .mobile-controls-buttons {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        margin-bottom: 10px;
    }

    .mobile-controls-buttons button {
        padding: 12px;
        font-size: 0.85em;
        font-weight: 700;
        border-radius: 10px;
        border: none;
        color: white;
        cursor: pointer;
        width: 100%;
    }

    .mobile-controls-close-row {
        text-align: center;
        padding: 10px 0;
    }

    .mobile-controls-close-row button {
        background: #6c757d;
        color: white;
        border: none;
        padding: 10px 30px;
        border-radius: 10px;
        font-weight: 600;
        cursor: pointer;
    }

    /* История в выдвижной панели */
    #mobile-history-container {
        max-height: 250px;
        overflow-y: auto;
        border: 2px solid #a8d1ff;
        border-radius: 12px;
        padding: 8px;
        text-align: left;
        background-color: var(--history-bg, #fdfdfd);
        font-size: 0.85em;
        box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
    }

    /* Модалки */
    .snake-overlay .modal-content {
        width: 95% !important;
        max-width: 95% !important;
        padding: 15px !important;
        border-radius: 14px !important;
    }

    /* Словарь */
    .hierarchical-word-selector-overlay {
        width: 95% !important;
        height: 90vh !important;
    }
}

/* === Стили для элементов, которые по умолчанию скрыты на десктопе === */
#mobile-burger-btn,
#mobile-header-drawer,
#mobile-drawer-overlay,
#mobile-controls-btn,
#mobile-controls-drawer,
.mobile-bottom-bar {
    display: none;
}