/* ==========================================================================
   Crapô - Arquivo Dedicado de Responsividade e Dispositivos (responsividade.css)
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Regra Geral de Zero Scroll (Impedir qualquer rolagem na página)
   -------------------------------------------------------------------------- */
html, body {
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  width: 100dvw;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  margin: 0;
  padding: 0;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

#mesa {
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  width: 100dvw;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* Espaçamento perfeitamente simétrico entre topo da tela e rodapé (footer 22px) */
#mododejogo {
  height: calc(100dvh - 22px);
  width: 100vw;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding-top: max(2px, env(safe-area-inset-top));
  padding-bottom: max(2px, env(safe-area-inset-bottom));
  margin: 0;
  box-sizing: border-box;
}

/* --------------------------------------------------------------------------
   2. Modo Vertical / Retrato (Alerta de Rotação para Celulares e Tablets)
   -------------------------------------------------------------------------- */
@media (orientation: portrait), (max-aspect-ratio: 1/1) and (max-width: 950px) {
  #rotateMessage {
    display: flex;
  }
  #mesa, .hamburger, .sidebar {
    display: none;
  }
}

/* --------------------------------------------------------------------------
   3. Smartphones Compactos em Modo Paisagem (Altura: < 400px)
   Exemplos: Galaxy Z Fold 5 (344px), iPhone SE (375px), iPhone 12 Pro (390px)
   -------------------------------------------------------------------------- */
@media screen and (orientation: landscape) and (max-height: 399px) {
  #mododejogo {
    padding-top: max(2px, env(safe-area-inset-top));
    padding-bottom: 2px;
    justify-content: space-between;
  }

  #mododejogo .jogador1, 
  #mododejogo .jogador2 {
    width: 84vw;
    max-width: 580px;
    height: auto;
    min-height: 0;
    padding: 2px 10px; /* Rigorosamente 2px acima e 2px abaixo */
    gap: 10px;
    border-radius: 8px;
    margin: 0;
    align-items: center;
  }

  #mododejogo .jogador1 p, 
  #mododejogo .jogador2 p {
    font-size: clamp(0.8rem, 3.4vh, 1.2rem);
    width: 35%;
    max-width: 35%;
  }

  #mododejogo .montes {
    gap: 8px;
  }

  #mododejogo .monte,
  #monteCrapoJ1, #monteCrapoJ2,
  #montePrincipalJ1, #montePrincipalJ2,
  #monteRestoJ1, #monteRestoJ2,
  #mododejogo .fundacao,
  #mododejogo .fundacao-carta {
    width: 8vh;
    height: 12vh;
  }

  #mododejogo .sequencia {
    width: auto;
    min-width: 8vh;
    height: 12vh;
    flex-wrap: nowrap;
  }

  #mododejogo .sequencia.esq {
    flex-direction: row-reverse;
    justify-content: flex-start;
  }

  #mododejogo .sequencia.dir {
    flex-direction: row;
    justify-content: flex-start;
  }

  #mododejogo .carta-aberta,
  #mododejogo .fundacao-carta,
  #mododejogo .imagem-carta,
  #mododejogo .sequencia img.carta-aberta,
  #monteCrapoJ1 img, #monteCrapoJ2 img,
  #montePrincipalJ1 img, #montePrincipalJ2 img,
  #monteRestoJ1 img, #monteRestoJ2 img {
    width: 8vh;
    height: 12vh;
    min-width: 8vh;
    flex-shrink: 0;
  }

  #mododejogo .carta-mini,
  #mododejogo .sequencia img.carta-mini {
    width: 1.5vh; /* 12vh / 8 -> proporção nativa simples 1:8 da fatia 20x160 */
    height: 12vh;
    min-width: 1.5vh;
    max-width: 1.5vh;
    flex-shrink: 0;
  }

  #areadojogo {
    flex: 1;
    min-height: 0;
    height: auto;
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-evenly;
    align-items: center;
    margin: 0;
    padding: 0;
    overflow: visible;
  }

  #mododejogo .linha {
    height: 12vh;
    width: fit-content;
    max-width: 96vw;
    justify-content: center;
    align-items: center;
    gap: 14px;
    margin: 0;
  }

  .sidebar.open {
    width: 200px;
  }
}

/* --------------------------------------------------------------------------
   4. Smartphones Médios/Grandes em Modo Paisagem (Altura: 400px a 520px)
   Exemplos: iPhone XR (896x414), iPhone 14 Pro Max (932x430), iPhone 15 Pro Max (955x440)
   -------------------------------------------------------------------------- */
@media screen and (orientation: landscape) and (min-height: 400px) and (max-height: 520px) {
  #mododejogo {
    padding-top: max(2px, env(safe-area-inset-top));
    padding-bottom: 2px;
    justify-content: space-between;
  }

  #mododejogo .jogador1, 
  #mododejogo .jogador2 {
    width: 82vw;
    max-width: 620px;
    height: auto;
    min-height: 0;
    padding: 2px 12px; /* Rigorosamente 2px acima e 2px abaixo */
    gap: 12px;
    border-radius: 8px;
    margin: 0;
    align-items: center;
  }

  #mododejogo .jogador1 p, 
  #mododejogo .jogador2 p {
    font-size: clamp(0.85rem, 3.5vh, 1.3rem);
    width: 35%;
    max-width: 35%;
  }

  #mododejogo .montes {
    gap: 10px;
  }

  #mododejogo .monte,
  #monteCrapoJ1, #monteCrapoJ2,
  #montePrincipalJ1, #montePrincipalJ2,
  #monteRestoJ1, #monteRestoJ2,
  #mododejogo .fundacao,
  #mododejogo .fundacao-carta {
    width: 7.46vh;
    height: 11.2vh;
  }

  #mododejogo .sequencia {
    width: auto;
    min-width: 7.46vh;
    height: 11.2vh;
    flex-wrap: nowrap;
  }

  #mododejogo .sequencia.esq {
    flex-direction: row-reverse;
    justify-content: flex-start;
  }

  #mododejogo .sequencia.dir {
    flex-direction: row;
    justify-content: flex-start;
  }

  #mododejogo .carta-aberta,
  #mododejogo .fundacao-carta,
  #mododejogo .imagem-carta,
  #mododejogo .sequencia img.carta-aberta,
  #monteCrapoJ1 img, #monteCrapoJ2 img,
  #montePrincipalJ1 img, #montePrincipalJ2 img,
  #monteRestoJ1 img, #monteRestoJ2 img {
    width: 7.46vh;
    height: 11.2vh;
    min-width: 7.46vh;
    flex-shrink: 0;
  }

  #mododejogo .carta-mini,
  #mododejogo .sequencia img.carta-mini {
    width: 1.4vh; /* 11.2vh / 8 -> proporção nativa simples 1:8 da fatia 20x160 */
    height: 11.2vh;
    min-width: 1.4vh;
    max-width: 1.4vh;
    flex-shrink: 0;
  }

  #areadojogo {
    flex: 1;
    min-height: 0;
    height: auto;
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-evenly;
    align-items: center;
    margin: 0;
    padding: 0;
    overflow: visible;
  }

  #mododejogo .linha {
    height: 11.2vh;
    width: fit-content;
    max-width: 96vw;
    justify-content: center;
    align-items: center;
    gap: 16px;
    margin: 0;
  }
}

/* --------------------------------------------------------------------------
   5. Tablets e Telas Médias em Modo Paisagem (Altura: 521px a 768px)
   Exemplos: iPad Mini (768px), iPad Air (820px), Galaxy Tab
   -------------------------------------------------------------------------- */
@media screen and (orientation: landscape) and (min-height: 521px) and (max-height: 768px) {
  #mododejogo {
    padding-top: max(4px, env(safe-area-inset-top));
    padding-bottom: 4px;
    justify-content: space-between;
  }

  #mododejogo .jogador1, 
  #mododejogo .jogador2 {
    width: 78vw;
    max-width: 650px;
    height: auto;
    min-height: 0;
    padding: 2px 14px; /* Rigorosamente 2px acima e 2px abaixo */
    gap: 14px;
    border-radius: 10px;
    margin: 0;
    align-items: center;
  }

  #mododejogo .jogador1 p, 
  #mododejogo .jogador2 p {
    font-size: clamp(0.95rem, 3.6vh, 1.5rem);
    width: 38%;
    max-width: 38%;
  }

  #mododejogo .montes {
    gap: 12px;
  }

  #mododejogo .monte,
  #monteCrapoJ1, #monteCrapoJ2,
  #montePrincipalJ1, #montePrincipalJ2,
  #monteRestoJ1, #monteRestoJ2,
  #mododejogo .fundacao,
  #mododejogo .fundacao-carta {
    width: 9vh;
    height: 13.5vh;
  }

  #mododejogo .sequencia {
    width: auto;
    min-width: 9vh;
    height: 13.5vh;
    flex-wrap: nowrap;
  }

  #mododejogo .sequencia.esq {
    flex-direction: row-reverse;
    justify-content: flex-start;
  }

  #mododejogo .sequencia.dir {
    flex-direction: row;
    justify-content: flex-start;
  }

  #mododejogo .carta-aberta,
  #mododejogo .fundacao-carta,
  #mododejogo .imagem-carta,
  #mododejogo .sequencia img.carta-aberta,
  #monteCrapoJ1 img, #monteCrapoJ2 img,
  #montePrincipalJ1 img, #montePrincipalJ2 img,
  #monteRestoJ1 img, #monteRestoJ2 img {
    width: 9vh;
    height: 13.5vh;
    min-width: 9vh;
    flex-shrink: 0;
  }

  #mododejogo .carta-mini,
  #mododejogo .sequencia img.carta-mini {
    width: 1.68vh; /* 13.5vh / 8 -> proporção nativa simples 1:8 da fatia 20x160 */
    height: 13.5vh;
    min-width: 1.68vh;
    max-width: 1.68vh;
    flex-shrink: 0;
  }

  #areadojogo {
    flex: 1;
    min-height: 0;
    height: auto;
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-evenly;
    align-items: center;
    margin: 0;
    padding: 0;
    overflow: visible;
  }

  #mododejogo .linha {
    height: 13.5vh;
    width: fit-content;
    max-width: 96vw;
    justify-content: center;
    align-items: center;
    gap: 16px;
    margin: 0;
  }
}

/* --------------------------------------------------------------------------
   6. Notebooks e Desktops (Modo Paisagem - Altura: >= 769px)
   Exemplos: Notebooks 13", 14", 15", Monitores Full HD / 4K
   -------------------------------------------------------------------------- */
@media screen and (orientation: landscape) and (min-height: 769px) {
  #mododejogo {
    padding-top: 4px;
    padding-bottom: 4px;
    justify-content: space-between;
  }

  #mododejogo .jogador1, 
  #mododejogo .jogador2 {
    width: 65vw;
    max-width: 680px;
    height: auto;
    min-height: 0;
    padding: 2px 16px; /* Rigorosamente 2px acima e 2px abaixo */
    gap: 16px;
    border-radius: 12px;
    margin: 0;
    align-items: center;
  }

  #mododejogo .jogador1 p, 
  #mododejogo .jogador2 p {
    font-size: clamp(1.1rem, 3.8vh, 1.8rem);
    width: 38%;
    max-width: 38%;
  }

  #mododejogo .montes {
    gap: 14px;
  }

  #mododejogo .monte,
  #monteCrapoJ1, #monteCrapoJ2,
  #montePrincipalJ1, #montePrincipalJ2,
  #monteRestoJ1, #monteRestoJ2,
  #mododejogo .fundacao,
  #mododejogo .fundacao-carta {
    width: 9.3vh;
    height: 14vh;
  }

  #mododejogo .sequencia {
    width: auto;
    min-width: 9.3vh;
    height: 14vh;
    flex-wrap: nowrap;
  }

  #mododejogo .sequencia.esq {
    flex-direction: row-reverse;
    justify-content: flex-start;
  }

  #mododejogo .sequencia.dir {
    flex-direction: row;
    justify-content: flex-start;
  }

  #mododejogo .carta-aberta,
  #mododejogo .fundacao-carta,
  #mododejogo .imagem-carta,
  #mododejogo .sequencia img.carta-aberta,
  #monteCrapoJ1 img, #monteCrapoJ2 img,
  #montePrincipalJ1 img, #montePrincipalJ2 img,
  #monteRestoJ1 img, #monteRestoJ2 img {
    width: 9.3vh;
    height: 14vh;
    min-width: 9.3vh;
    flex-shrink: 0;
  }

  #mododejogo .carta-mini,
  #mododejogo .sequencia img.carta-mini {
    width: 1.75vh; /* 14vh / 8 -> proporção nativa simples 1:8 da fatia 20x160 */
    height: 14vh;
    min-width: 1.75vh;
    max-width: 1.75vh;
    flex-shrink: 0;
  }

  #areadojogo {
    flex: 1;
    min-height: 0;
    height: auto;
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-evenly;
    align-items: center;
    margin: 0;
    padding: 0;
    overflow: visible;
  }

  #mododejogo .linha {
    height: 14vh;
    width: fit-content;
    max-width: 96vw;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin: 0;
  }
}

/* --------------------------------------------------------------------------
   7. Modal de Estatísticas e Ranking Responsivo
   -------------------------------------------------------------------------- */
@media (max-width: 768px) or (max-height: 550px) {
  .modal-content {
    width: 96%;
    max-width: 780px;
    padding: 12px 14px;
    max-height: 92vh;
    max-height: 92dvh;
    margin: 1% auto;
  }

  #estatisticasTitulo {
    font-size: 1.25rem;
    margin-bottom: 8px;
  }

  .estat-resumo {
    gap: 6px;
    margin-bottom: 10px;
  }

  .estat-card {
    padding: 6px 8px;
    font-size: 0.8rem;
  }

  .ranking-titulo {
    font-size: 1rem;
    margin: 10px 0 6px 0;
    padding-bottom: 4px;
  }

  .ranking-tabela {
    font-size: 0.8rem;
    border-spacing: 4px 2px;
  }

  .ranking-tabela th, .ranking-tabela td {
    padding: 6px 6px;
  }
}
