/* =========================================
   REGRAS PARA MOBILE (NÃO AFETA DESKTOP)
========================================= */

/* =========================================
   CONTROLES / SENSORES (Valendo para celular em pé ou deitado)
========================================= */
@media (max-width: 1366px) {

    .desktop-only,
    .keyboard-16bit {
        display: none !important;
    }

    .mobile-only {
        display: flex !important;
    }

    .mobile-sensors-group {
        flex-direction: column;
        align-items: center;
        gap: 20px;
        padding: 20px 10px;
        width: 100%;
    }

    #input-layout {
        height: auto !important;
        min-height: 250px;
        padding-bottom: 20px;
        display: flex;
        justify-content: center;
    }

    #gameCanvas.canvas-domino {
        width: 100vw !important;
        /* 100% da largura da tela */
        height: 76vh !important;
        /* 76% da altura da tela */
        border: none !important;
        /* Opcional: tira a borda verde no celular para ganhar mais espaço */
    }

    /* 1. Esconde a "barra" do cabeçalho para o jogo usar a tela toda */
    .game-header {
        background: transparent !important;
        border: none !important;
        height: 0;
        padding: 0;
        margin: 0;
    }

    /* 2. Transforma o botão antigo em um botão flutuante circular (Idêntico ao Pause) */
    .game-header .btn-exit {
        position: absolute !important;
        top: 20px !important;

        /* ⭐ A MÁGICA ACONTECE AQUI: */
        left: auto !important;
        /* Remove a trava da esquerda que vinha do desktop */
        right: 130px !important;
        /* Alinha perfeitamente ao lado do botão de Tela Cheia */

        width: 45px !important;
        height: 45px !important;
        z-index: 9999 !important;

        /* Visual "Glassmorphism" igual aos botões de Pause e Tela Cheia */
        background: rgba(0, 0, 0, 0.5) !important;
        backdrop-filter: blur(4px) !important;
        border: 1px solid rgba(255, 255, 255, 0.2) !important;
        border-radius: 50% !important;

        /* Centraliza o ícone que vamos criar */
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        padding: 0 !important;

        /* Esconde o texto longo "[ ESC ] EXIT TO DOS" */
        font-size: 0 !important;
        color: transparent !important;
        box-shadow: none !important;
        cursor: pointer;
    }

    /* 3. Cria um ícone de "X" no centro do botão */
    .game-header .btn-exit::after {
        content: "✕";
        /* Símbolo de fechar minimalista */
        font-family: Arial, sans-serif;
        font-size: 22px !important;
        color: white !important;
        font-weight: bold;
    }

    /* Efeito de afundar quando o dedo toca (Igual aos outros) */
    .game-header .btn-exit:active {
        background: rgba(255, 255, 255, 0.3) !important;
        transform: scale(0.95) !important;
    }
}

/* 1. Mobile em Paisagem (Deitado) - Ex: Celular virado */
@media (max-width: 1366px) and (orientation: landscape) {
    .game-grid {
        display: grid;
        /* Em landscape, temos espaço horizontal de sobra. Vamos usar 3 colunas! */
        grid-template-columns: repeat(3, 1fr);
        gap: 15px;
        width: 100%;
        max-width: 900px;
        /* Limita para não esticar infinitamente */
        padding: 10px;
        margin: 0 auto;
    }

    .game-card {
        width: 100%;
        max-width: none;
        /* Remove a limitação de largura que vem do Desktop */
    }

    .game-card[data-game="settings"] {
        position: fixed;
        bottom: 20px;
        right: 20px;
        width: auto;
        /* Sobrescreve a largura do desktop */
        padding: 5px 15px;
        background-color: #000;
        /* Fundo preto para não misturar com o fundo */
        z-index: 1000;

        /* Deixa o ícone e o título lado a lado para parecer um botão */
        display: flex;
        align-items: center;
        gap: 10px;
        grid-column: 2;
    }

    /* Esconde a descrição ("Sistema Global") para o botão não ficar gigante */
    .game-card[data-game="settings"] small {
        display: none;
    }

    /* Ajusta a margem do título no botão */
    .game-card[data-game="settings"] h3 {
        margin: 0;
        font-size: 1rem;
    }

    /* Mostra os sensores */
    .mobile-sensors-group {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 20px;
        padding: 15px;
    }

    /* Desenha um celular verde estilo wireframe */
    .smartphone-wireframe {
        width: 120px;
        height: 220px;
        border: 2px solid #0f0;
        /* Use sua variável var(--terminal-green) */
        border-radius: 15px;
        display: flex;
        justify-content: center;
        align-items: center;
        position: relative;

        /* Prepara para a animação 3D que o JavaScript vai aplicar */
        transform-style: preserve-3d;
        transition: transform 0.1s ease-out;
    }

    /* Um "botão home" falso no rodapé para dar cara de celular */
    .smartphone-wireframe::after {
        content: '';
        position: absolute;
        bottom: 10px;
        width: 30px;
        height: 6px;
        background-color: #0f0;
        border-radius: 3px;
    }

    /* A tela onde os números vão piscar */
    .screen-data {
        color: #0f0;
        font-size: 0.8rem;
        text-align: left;
        display: flex;
        flex-direction: column;
        gap: 5px;
    }

    .terminal-btn {
        background: transparent;
        color: #0f0;
        border: 1px solid #0f0;
        padding: 10px;
        font-family: inherit;
        cursor: pointer;
    }

    @keyframes blink {
        50% {
            opacity: 0;
        }
    }

    /* ⭐ ADICIONADOS: cursor, user-select e tap-highlight */
    .tg-car-card {
        cursor: pointer;
        user-select: none;
        -webkit-tap-highlight-color: transparent;
        border: 4px solid #333;
        border-radius: 8px;
        padding: 15px;
        text-align: center;
        background: #111;
        transition: 0.2s;
        box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.5);
    }

    .tg-car-card.active {
        border-color: #0050ff;
        background: #001133;
        transform: scale(1.05);
        box-shadow: 0px 0px 15px #0050ff;
    }

    .tg-car-color {
        width: 120px;
        height: 35px;
        margin: 15px auto;
        border-radius: 5px;
        border: 2px solid #fff;
    }
}

/* 2. Mobile em Retrato (Em pé) */
@media (max-width: 768px) and (orientation: portrait) {
    .game-grid {
        padding-top: 20px;
        display: grid;
        grid-template-columns: 1fr;
        /* 1 coluna para os cards não ficarem espremidos */
        gap: 15px;
        width: 90%;
        margin: 0 auto;

        /* ATIVA A ROLAGEM VERTICAL */
        max-height: 90vh;
        /* Limita a altura do grid (ajuste esse valor conforme o tamanho do seu cabeçalho/rodapé) */
        overflow-y: auto;
        /* Faz a barra de rolagem aparecer se o conteúdo for maior que o max-height */
        padding-right: 10px;
        /* Dá um espacinho para o texto não grudar na barra de rolagem */
    }

    /* =========================================
       CUSTOMIZAÇÃO DA BARRA DE ROLAGEM (ESTILO TERMINAL)
    ========================================= */

    /* Largura da barra */
    .game-grid::-webkit-scrollbar {
        width: 6px;
    }

    /* Fundo da trilha da barra (Preto) */
    .game-grid::-webkit-scrollbar-track {
        background: #000000;
        border-left: 1px solid #003300;
        /* Linha sutil separando a barra do conteúdo */
    }

    /* O "pegador" da barra de rolagem (Verde Terminal) */
    .game-grid::-webkit-scrollbar-thumb {
        background: #00ff00;
        /* Use a sua variável CSS de cor verde aqui se tiver, ex: var(--cor-terminal) */
        border-radius: 0px;
        /* Sem bordas arredondadas para manter o visual quadrado/retrô */
    }

    .game-grid::-webkit-scrollbar-thumb:hover {
        background: #00cc00;
    }
}

/* =========================================
   HUD Mobile - Botão Flutuante de Pausa
   ========================================= */
#mobile-pause-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 45px;
    height: 45px;
    z-index: 9999;

    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    color: white;

    touch-action: none;
    user-select: none;

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

#mobile-pause-btn svg {
    width: 24px;
    height: 24px;
}

#mobile-pause-btn:active {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(0.95);
}

/* Posiciona o botão de fullscreen ao lado do pause */
#mobile-fullscreen-btn {
    position: absolute;
    top: 20px;
    right: 75px;
    /* Fica 55px à esquerda do botão de pause */
    width: 45px;
    height: 45px;
    z-index: 9999;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    color: white;
    touch-action: none;
    user-select: none;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
}

#mobile-fullscreen-btn svg {
    width: 24px;
    height: 24px;
}

#mobile-fullscreen-btn:active {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(0.95);
}

#mobile-settings-btn,
#mobile-cafe-btn {
    position: absolute;
    right: 20px;
    /* Alinhado à direita junto com o Pause */
    width: 45px;
    height: 45px;
    z-index: 9999;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    color: white;
    touch-action: none;
    user-select: none;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
}

#mobile-settings-btn svg,
#mobile-cafe-btn svg {
    width: 24px;
    height: 24px;
}

#mobile-settings-btn:active,
#mobile-cafe-btn:active {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(0.95);
}

/* Empilhamento vertical! */
#mobile-settings-btn {
    top: 75px;
}

/* Abaixo do Pause (20px + 45px altura + 10px margem) */
#mobile-cafe-btn {
    top: 130px;
}

/* Tela preta de aviso de rotação (Portrait) */
#orientation-warning {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #000;
    color: #33ff00;
    /* Usando o verde clássico do seu portal */
    z-index: 99999;
    /* Fica acima de tudo, inclusive do pause */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    font-family: 'VT323', monospace;
    /* Sua fonte padrão */
    font-size: 24px;
}

#orientation-warning svg {
    width: 64px;
    height: 64px;
    margin-bottom: 20px;
    color: #fff;
    animation: rotatePhone 2s infinite ease-in-out;
}

@keyframes rotatePhone {
    0% {
        transform: rotate(0deg);
    }

    50% {
        transform: rotate(-90deg);
    }

    100% {
        transform: rotate(-90deg);
    }
}

/* =========================================
   UI DO SMARTPHONE 16-BITS (DEITADO)
========================================= */
.smartphone-16bit {
    width: 280px;
    /* Mais largo */
    height: 140px;
    /* Mais baixo */
    border: 4px solid var(--terminal-dim);
    border-radius: 20px;
    background: #050505;
    display: flex;
    flex-direction: row;
    /* Elementos lado a lado agora! */
    align-items: center;
    padding: 10px 15px;

    box-shadow:
        inset 0 0 15px rgba(0, 255, 0, 0.05),
        0 0 20px rgba(0, 255, 0, 0.1);

    transform-style: preserve-3d;
    transition: transform 0.1s ease-out;
}

/* Alto-falante agora fica na lateral esquerda */
.phone-speaker {
    width: 8px;
    height: 40px;
    border: 2px solid var(--terminal-dim);
    border-radius: 10px;
    margin-right: 15px;
}

/* O botão físico fica na lateral direita */
.phone-button {
    width: 30px;
    height: 30px;
    border: 2px solid var(--terminal-dim);
    border-radius: 50%;
    margin-left: 15px;
}

.phone-screen {
    width: auto;
    height: 100%;
    flex-grow: 1;
    /* Ocupa todo o centro */
    border: 2px solid #0f0;
    background: #020a02;
    padding: 10px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 10px;
    box-shadow: inset 0 0 15px rgba(0, 255, 0, 0.2);
}

.phone-screen .screen-title {
    text-align: center;
    font-size: 16px;
    border-bottom: 1px dashed #0f0;
    padding-bottom: 5px;
    color: #0ff;
    margin-bottom: 5px;
}

.phone-screen .screen-data {
    font-size: 18px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    color: #0f0;
}