/* === CORREÇÃO COMPLETA DOS JOGOS/QUIZ === */

/* 1. Container principal dos jogos */
.games-section {
    position: relative;
    overflow: hidden;
    z-index: 1;
}

/* 2. Grid de jogos - corrigir sobreposição */
.games-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 30px;
    position: relative;
    z-index: 2;
}

/* 3. Cada card de jogo - evitar overflow */
.game-card {
    position: relative;
    background: white;
    border-radius: var(--borda-radius);
    overflow: visible !important;
    /* Mudar de hidden para visible */
    box-shadow: var(--sombra-media);
    transition: var(--transicao-media);
    display: flex;
    flex-direction: column;
    min-height: 400px;
    z-index: 3;
}

/* 4. Header do jogo */
.game-header {
    background: linear-gradient(135deg, var(--laranja), var(--laranja-hover));
    color: white;
    padding: 25px;
    text-align: center;
    position: relative;
    z-index: 4;
}

.game-header h3 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 10px;
    line-height: 1.3;
}

.game-difficulty {
    font-size: 14px;
    opacity: 0.9;
    background: rgba(255, 255, 255, 0.2);
    padding: 4px 12px;
    border-radius: 20px;
    display: inline-block;
}

/* 5. Conteúdo do jogo - corrigir sobreposição */
.game-content {
    padding: 30px;
    text-align: center;
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 5;
}

.game-description {
    color: var(--cinza-6);
    margin-bottom: 25px;
    line-height: 1.6;
    flex: 1;
}

/* 6. Estatísticas - garantir alinhamento */
.game-stats {
    display: flex;
    justify-content: space-around;
    margin: 20px 0;
    padding: 15px 0;
    border-top: 1px solid var(--cinza-2);
    border-bottom: 1px solid var(--cinza-2);
    position: relative;
    z-index: 6;
}

.stat {
    text-align: center;
    min-width: 80px;
}

.stat-number {
    font-size: 24px;
    font-weight: 700;
    color: var(--azul-principal);
    display: block;
    line-height: 1;
}

.stat-label {
    font-size: 12px;
    color: var(--cinza-5);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 5px;
    display: block;
}

/* 7. Botão do jogo */
.game-btn {
    background: var(--azul-principal);
    color: white;
    border: none;
    padding: 15px 20px;
    border-radius: 50px;
    font-weight: 600;
    font-size: 16px;
    cursor: pointer;
    transition: var(--transicao-media);
    width: 100%;
    margin-top: auto;
    /* Empurra para baixo */
    position: relative;
    z-index: 7;
}

.game-btn:hover {
    background: var(--azul-escuro);
    transform: translateY(-2px);
}

/* 8. Container do quiz (modal) - corrigir sobreposição */
.quiz-container {
    position: relative;
    z-index: 1000;
    background: white;
    padding: 30px;
    border-radius: var(--borda-radius);
    max-width: 500px;
    margin: 0 auto;
}

.quiz-diagrama {
    margin: 20px 0;
    padding: 20px;
    background: var(--cinza-1);
    border-radius: var(--borda-radius);
    position: relative;
    min-height: 150px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.quiz-opcoes {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    margin: 20px 0;
}

.quiz-opcoes button {
    padding: 15px;
    border: 2px solid var(--cinza-3);
    background: white;
    color: var(--cinza-7);
    border-radius: var(--borda-radius);
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    transition: var(--transicao-rapida);
}

.quiz-opcoes button:hover {
    border-color: var(--azul-principal);
    color: var(--azul-principal);
    transform: translateY(-2px);
}

/* 9. Identificador de notas */
.identificador-container {
    position: relative;
    z-index: 1000;
}

/* 10. Para evitar sobreposição em mobile */
@media (max-width: 768px) {
    .games-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .game-card {
        min-height: auto;
    }

    .quiz-opcoes {
        grid-template-columns: 1fr;
    }

    .game-stats {
        flex-direction: column;
        gap: 15px;
    }

    .stat {
        min-width: auto;
    }
}

/* 11. Correção de z-index geral para jogos */
.games-section * {
    position: relative;
}

.games-section>* {
    z-index: auto !important;
}

/* ═══════════════════════════════════════════════════════════
   CIFRATURN — BUGFIXES PATCH
   Bug 1: XP Firebase (ver bugfixes_games_xp.js)
   Bug 2: Medalha 3º lugar sobreposta à foto
   Bug 3: Miniplayer antes da cifra em mobile
   Bug 4: Scroll horizontal em perfil.html e cifra.html
   ═══════════════════════════════════════════════════════════ */

/* ─────────────────────────────────────────────
   BUG 2 — MEDALHA DO PÓDIO
   O .podium-rank estava saindo por cima da imagem.
   Garantimos que o item tem overflow: visible e que
   a medalha fica sempre acima (z-index correto).
───────────────────────────────────────────────── */
.ranking-podium {
    overflow: visible !important;
    padding-top: 40px !important;
    /* espaço para as medalhas não serem cortadas */
}

.podium-item {
    overflow: visible !important;
    /* ESSENCIAL — sem isso a medalha some */
    position: relative !important;
}

/* Medalha posicionada acima do card, não sobre a foto */
.podium-rank {
    position: absolute !important;
    top: -20px !important;
    /* sobe acima do card */
    left: 50% !important;
    transform: translateX(-50%) !important;
    z-index: 10 !important;
    background: white !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
}

/* Garante que o avatar-wrap não sobrepõe a medalha */
.podium-avatar-wrap {
    position: relative !important;
    margin-top: 8px !important;
    /* afasta do topo onde está a medalha */
}

/* Coroa do 1º lugar: fica acima do avatar, não conflita com a medalha */
.podium-crown {
    position: absolute !important;
    top: -18px !important;
    right: -8px !important;
    font-size: 20px !important;
    z-index: 5 !important;
}

/* Mobile — pódio mais compacto sem sobreposição */
@media (max-width: 768px) {
    .ranking-podium {
        padding-top: 36px !important;
        gap: 10px !important;
    }

    .podium-item.gold {
        height: 200px !important;
    }

    .podium-item.silver,
    .podium-item.bronze {
        height: 170px !important;
    }
}

@media (max-width: 480px) {
    .ranking-podium {
        padding-top: 32px !important;
        gap: 8px !important;
    }

    .podium-item {
        max-width: 100px !important;
        padding: 38px 10px 16px !important;
    }

    .podium-avatar-wrap {
        width: 56px !important;
        height: 56px !important;
    }

    .podium-name {
        font-size: 11px !important;
    }

    .podium-score {
        font-size: 10px !important;
        padding: 3px 10px !important;
    }
}


/* ─────────────────────────────────────────────
   BUG 3 — MINIPLAYER ANTES DA CIFRA (MOBILE)
   Em mobile (≤960px) o sidebar fica embaixo da
   cifra (order:2). Queremos que o vídeo apareça
   ANTES da cifra, não depois.
   Solução: tiramos o vídeo do fluxo normal do
   sidebar e usamos order negativo específico.
───────────────────────────────────────────────── */
@media (max-width: 960px) {

    /* O wrapper principal vira flex-column */
    .cifra-page-wrapper {
        display: flex !important;
        flex-direction: column !important;
        gap: 12px !important;
        padding: 12px 14px 40px !important;
    }

    /* Coluna lateral: grid 1 coluna, sem position sticky */
    .cifra-side-col {
        position: static !important;
        display: contents !important;
        /* os filhos participam diretamente do flex pai */
    }

    /* Ordem dos blocos de cima para baixo:
       1. Toolbar          (order 1)
       2. Vídeo sidebar    (order 2)  ← miniplayer ANTES da cifra
       3. Song header      (order 3)
       4. Painel videoaula (order 4)
       5. Corpo da cifra   (order 5)
       6. Acordes sidebar  (order 6)
       7. Ferramentas      (order 7, hidden)
    */

    /* Song header card */
    .song-header-card {
        order: 3 !important;
    }

    /* Toolbar mobile */
    .cifra-toolbar {
        order: 1 !important;
    }

    /* Painel de videoaula (aberto via botão) */
    #painel-videoaula {
        order: 4 !important;
    }

    /* Corpo principal da cifra */
    .cifra-body-card {
        order: 5 !important;
    }

    /* Vídeo preview (miniplayer) — VEM ANTES DA CIFRA */
    #video-preview-area {
        order: 2 !important;
        width: 100% !important;
    }

    /* Acordes usados */
    #sidebar-acordes-section {
        order: 6 !important;
        width: 100% !important;
    }

    /* Ferramentas desktop — esconder */
    .sidebar-tools-card {
        display: none !important;
    }

    /* Cifra main col sem order conflitante */
    .cifra-main-col {
        display: contents !important;
        /* mesma lógica — filhos ficam no flex pai */
    }
}

/* Garante que o miniplayer fixo não atrapalha o scroll */
@media (max-width: 768px) {
    #youtube-miniplayer-container {
        width: calc(100% - 20px) !important;
        max-width: 320px !important;
        right: 10px !important;
        bottom: 10px !important;
    }
}


/* ─────────────────────────────────────────────
   BUG 4 — SCROLL HORIZONTAL EM MOBILE
   perfil.html e cifra.html
───────────────────────────────────────────────── */

/* Reset global anti-overflow */
html,
body {
    overflow-x: hidden !important;
    max-width: 100% !important;
}

*,
*::before,
*::after {
    box-sizing: border-box !important;
}

/* perfil.html — painéis de tab e seções */
@media (max-width: 768px) {

    /* Tabs bar não ultrapassa a tela */
    .profile-tabs-bar {
        max-width: 100% !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        scrollbar-width: none !important;
    }

    .profile-tabs-bar::-webkit-scrollbar {
        display: none;
    }

    /* Tab panels com padding seguro */
    .tab-panel {
        padding: 0 12px !important;
        margin: 14px auto !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
    }

    /* Section cards não transbordam */
    .section-card {
        max-width: 100% !important;
        overflow-x: hidden !important;
    }

    /* Store grid 2 colunas, não estoura */
    .store-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        width: 100% !important;
    }

    /* Inventory grid 3 colunas contidas */
    .inv-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        width: 100% !important;
    }

    /* Ranking podium contido */
    .ranking-container {
        max-width: 100% !important;
        padding: 0 !important;
        overflow-x: hidden !important;
    }

    /* Tabela do ranking responsiva */
    .lb-card {
        overflow-x: auto !important;
    }

    .lb-row {
        min-width: 0 !important;
    }

    /* Hero do perfil sem overflow lateral */
    .profile-hero {
        max-width: 100% !important;
        overflow-x: hidden !important;
    }

    .profile-hero-inner {
        max-width: 100% !important;
    }

    /* Avatar ring não sai da tela */
    .avatar-ring {
        flex-shrink: 0 !important;
    }

    /* Stats row wrap seguro */
    .profile-stats-row {
        flex-wrap: wrap !important;
        max-width: 100% !important;
    }

    /* Deals horizontal scroll contido */
    .deals-wrap {
        max-width: 100% !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    /* Banner URL row não estoura */
    .banner-url-row {
        flex-direction: column !important;
        gap: 8px !important;
        width: 100% !important;
    }

    .banner-url-row input,
    .btn-banner-save {
        width: 100% !important;
    }
}

/* cifra.html — containers que podiam causar scroll lateral */
@media (max-width: 768px) {

    /* Breadcrumb não estoura */
    .cifra-breadcrumb-inner {
        max-width: 100% !important;
        overflow: hidden !important;
        flex-wrap: nowrap !important;
    }

    /* Song header card */
    .song-header-card {
        max-width: 100% !important;
        overflow-x: hidden !important;
    }

    /* Cifra conteúdo: scroll interno, não externo */
    .cifra-body-card {
        max-width: 100% !important;
        overflow-x: hidden !important;
    }

    .cifra-conteudo {
        overflow-x: auto !important;
        /* scroll INTERNO na cifra, não na página */
        max-width: 100% !important;
        width: 100% !important;
    }

    /* Toolbar scroll interno */
    .cifra-toolbar {
        max-width: 100% !important;
        overflow-x: auto !important;
        flex-wrap: nowrap !important;
    }

    /* Footer da cifra */
    .cifra-footer-row {
        flex-wrap: wrap !important;
        max-width: 100% !important;
    }

    /* Relacionadas grid */
    .relacionadas-grid {
        max-width: 100% !important;
    }

    /* Modal acordes não estoura */
    .modal-acordes-overlay,
    .modal-overlay {
        padding: 12px !important;
    }

    .modal-acordes-box,
    .modal-content,
    #modal-content {
        max-width: 100% !important;
        width: 100% !important;
    }
}

@media (max-width: 480px) {

    /* perfil.html — store em 2 colunas mínimas */
    .store-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 8px !important;
    }

    .inv-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    /* cifra.html — body card padding menor */
    .cifra-body-card {
        padding: 12px 10px !important;
    }

    /* Song header compacto */
    .song-header-top {
        gap: 10px !important;
    }

    .artist-avatar {
        width: 50px !important;
        height: 50px !important;
    }

    /* Cifra conteúdo menor */
    .cifra-conteudo {
        font-size: 13px !important;
    }
}