@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@400;600;700;800&display=swap');

:root {
  --laranja: #ff8a3d;
  --azul-ceu: #a5d8ff;
  --verde: #2ecc71;
  --vermelho: #ff7675;
  --roxo: #a29bfe;
  --texto: #1f2937;
  --borda: rgba(255,255,255,0.75);
  --sombra: 0 14px 30px rgba(0,0,0,0.18);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  font-family: 'Fredoka', sans-serif;
  margin: 0;
  color: var(--texto);
  overflow-x: hidden;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  background-color: var(--azul-ceu);
}

/* --- PROTEÇÃO DE ORIENTAÇÃO --- */
#aviso-paisagem {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--azul-ceu);
  z-index: 99999;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
  color: #1f2937;
}
#aviso-paisagem h1 {
  font-size: 2.5rem;
  margin-bottom: 10px;
  text-shadow: 2px 3px 0px rgba(255,255,255,0.8);
}
@media (orientation: landscape) and (max-height: 500px) {
  #aviso-paisagem { display: flex; }
  body > *:not(#aviso-paisagem) { display: none !important; }
}

@keyframes piscar {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

.piscar-dica {
  animation: piscar 0.8s infinite;
  background: #ffeaa7 !important;
  color: #d63031 !important;
  border-color: #fdcb6e !important;
  transform: scale(1.1);
  z-index: 10;
}

/* --- BARRA SUPERIOR --- */
.topo {
  width: 100%;
  padding: 10px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(255,255,255,0.75);
  position: sticky;
  top: 0;
  z-index: 50;
}

.lado {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.lado.direita { justify-content: flex-end; }

.btn-sair, .btn-modo {
  text-decoration: none;
  color: white;
  padding: 8px 14px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.92rem;
  border: none;
  cursor: pointer;
  font-family: 'Fredoka', sans-serif;
  box-shadow: 0 8px 18px rgba(0,0,0,0.12);
  white-space: nowrap;
}

.btn-sair { background: var(--vermelho); }
.btn-modo { background: var(--roxo); }
.btn-sair:active, .btn-modo:active { transform: translateY(1px) scale(0.99); }

.progresso-container {
  width: clamp(120px, 28vw, 180px);
  height: 14px;
  background: rgba(0,0,0,0.07);
  border-radius: 999px;
  overflow: hidden;
  border: 2px solid rgba(255,255,255,0.9);
  box-shadow: inset 0 2px 0 rgba(255,255,255,0.9);
  flex: 0 0 auto;
}
#barra {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--verde), #8cf7b0);
  transition: width 0.45s ease;
}

.stats-grupo {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.stat-item {
  font-weight: 800;
  color: var(--laranja);
  font-size: 1rem;
  background: rgba(255,255,255,0.75);
  border: 1px solid rgba(255,255,255,0.85);
  padding: 6px 10px;
  border-radius: 999px;
  box-shadow: 0 8px 18px rgba(0,0,0,0.09);
  white-space: nowrap;
}
.timer-alerta { color: var(--vermelho) !important; animation: piscar 1s infinite; }

/* --- ÁREA PRINCIPAL --- */
main {
  width: 100%;
  display: flex;
  justify-content: center;
  /* Removido o espaço vazio gigante que estava empurrando tudo para fora */
  padding: 10px; 
  position: relative; 
  z-index: 20; 
}

.painel-jogo {
  background: rgba(255,255,255,0.92);
  border: 6px solid var(--laranja);
  border-radius: 26px;
  width: min(96vw, 600px);
  padding: 14px;
  text-align: center;
  box-shadow: var(--sombra);
  position: relative;
  overflow: hidden;
  margin: auto; /* Garante alinhamento central */
}

.titulo-mini {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 6px 8px 0;
  font-weight: 800;
  color: #4b5563;
  letter-spacing: 0.2px;
}

.chip-dica {
  margin: 6px auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(162,155,254,0.15);
  border: 1px solid rgba(162,155,254,0.25);
  color: #4b5563;
  font-weight: 700;
  font-size: 0.92rem;
}

/* --- GRID DO CAÇA-PALAVRAS --- */
#grid {
  --tam: 8;
  display: grid;
  grid-template-columns: repeat(var(--tam), 1fr);
  gap: 4px;
  margin: 10px auto;
  user-select: none;
  background: rgba(0,0,0,0.07);
  padding: 6px;
  border-radius: 16px;
  /* A medida chave: não passa da tela nem do painel */
  width: min(92vw, 520px, 48vh);
  aspect-ratio: 1 / 1;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.letra {
  width: 100%;
  aspect-ratio: 1 / 1;
  height: auto;
  background: rgba(255,255,255,0.98);
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: 900;
  border-radius: max(4px, 10%); /* Arredonda cantos de forma segura */
  cursor: pointer;
  /* Tamanho dinâmico para letras: não estoura o grid de 12 colunas */
  font-size: clamp(0.7rem, 2.5vw, 1.15rem);
  color: #2b2b2b;
  border: 1px solid rgba(0,0,0,0.06);
  box-shadow: 0 4px 10px rgba(0,0,0,0.08);
  transition: transform 0.08s ease, background 0.12s ease;
}

.letra.selecionada { background: #ffeb3b; transform: scale(0.96); border-color: #fbc531; }

.letra.encontrada {
  background: linear-gradient(180deg, var(--verde), #8cf7b0) !important;
  color: white !important;
  border-color: rgba(255,255,255,0.5) !important;
  box-shadow: 0 0 12px rgba(46, 204, 113, 0.6) !important;
}

.animacao-danca { animation: dancaLetra 400ms ease-in-out forwards; }

@keyframes dancaLetra {
  0% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-6px) scale(1.1); }
  100% { transform: translateY(0) scale(1.02); }
}

/* --- LISTA DE PALAVRAS --- */
#lista-palavras {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin: 8px auto 6px;
  max-height: 20svh;
  overflow: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
}

.palavra-item {
  padding: 6px 12px;
  background: rgba(255,255,255,0.8);
  border-radius: 999px;
  font-size: 0.86rem;
  font-weight: 900;
  border: 1px solid rgba(0,0,0,0.08);
  box-shadow: 0 6px 14px rgba(0,0,0,0.08);
  transition: all 0.3s ease;
}
.palavra-item.riscada {
  text-decoration: line-through;
  color: var(--verde);
  opacity: 0.5;
  order: 99;
}

#feedback-erro { height: 22px; font-size: 0.92rem; font-weight: 900; margin-top: 2px; }
.erro-flash { color: var(--vermelho) !important; transform: scale(1.05); transition: 0.15s; }

/* --- CONTROLES FLUTUANTES --- */
.controles-inferiores {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 100;
}
.btn-circular {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.95);
  cursor: pointer;
  font-size: 1.55rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.92);
  box-shadow: 0 14px 26px rgba(0,0,0,0.18);
}
.btn-som.ativo, .btn-musica.ativo { background: var(--verde); color: white; }

.badge {
  position: absolute; top: -6px; right: -6px; background: var(--vermelho); color: white;
  font-size: 0.75rem; font-weight: 900; width: 22px; height: 22px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; border: 2px solid white;
}
.btn-dica:disabled { opacity: 0.5; cursor: not-allowed; filter: grayscale(1); }

/* --- OVERLAYS E MENUS --- */
.overlay {
  position: fixed; inset: 0; z-index: 200;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 18px; background: rgba(165, 216, 255, 0.6); backdrop-filter: blur(16px);
}
.card-info {
  background: rgba(255,255,255,0.96); border: 8px solid var(--laranja); border-radius: 36px;
  padding: 24px; max-width: 480px; width: 95%; box-shadow: var(--sombra); max-height: 90vh; overflow-y: auto; scrollbar-width: none;
}
.titulo-3d { color: var(--laranja); margin: 0 0 14px 0; font-size: 2.2rem; text-shadow: 2px 4px 0px rgba(0,0,0,0.15); }
.config-grupo { margin-bottom: 14px; text-align: left; }
.config-grupo label { display: block; font-weight: 800; color: #4b5563; margin-bottom: 6px; font-size: 0.95rem; }
.config-select { width: 100%; padding: 12px; border-radius: 16px; border: 2px solid rgba(0,0,0,0.1); font-weight: 700; font-size: 1rem; color: var(--texto); background: #f9fafb; outline: none; }
.caixa-instrucao { margin-top: 8px; font-size: 0.9rem; color: #4b5563; font-weight: 600; background: #f3f4f6; padding: 12px; border-radius: 12px; border-left: 5px solid var(--verde); }
.btn-acao { background: var(--verde); color: white; border: none; padding: 14px 24px; font-size: 1.1rem; border-radius: 999px; cursor: pointer; font-weight: 900; width: 100%; margin: 7px 0; }
.btn-dif { display: block; width: 100%; margin: 9px 0; padding: 14px; border-radius: 22px; border: none; color: white; font-weight: 900; font-size: 1.05rem; cursor: pointer; }

#confetes { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 300; display: none; }
.confete { position: absolute; top: -10px; width: 10px; height: 14px; border-radius: 4px; animation: cair 1100ms ease-out forwards; }
@keyframes cair { to { transform: translateY(calc(100svh + 20px)) rotate(360deg); opacity: 1; } }
::-webkit-scrollbar { width: 0px; background: transparent; }

/* ========================================================= */
/* AJUSTES FINOS PARA CADA TIPO DE TELA (CORREÇÃO 1366x768)  */
/* ========================================================= */

/* Monitores Full HD e 4K */
@media (min-width: 1400px) {
  .painel-jogo { width: min(96vw, 750px); }
  #grid { width: min(92vw, 650px, 55vh); }
  .letra { font-size: 1.4rem; }
}

/* Telas de Notebook (A área útil do Chrome em 1366x768 é aprox. 620px) */
@media (max-height: 768px) {
  main { padding: 5px 10px 10px; } /* Zera qualquer sobra embaixo */
  .painel-jogo { padding: 8px; border-width: 4px; border-radius: 20px; }
  .titulo-mini { padding-top: 0; }
  .chip-dica { margin: 4px auto; padding: 4px 10px; font-size: 0.8rem; }
  
  #grid {
    width: min(92vw, 420px, 45vh); /* O grid se espreme baseado na altura */
    gap: 3px; 
    margin: 6px auto;
  }
  
  .letra { font-size: clamp(0.65rem, 2vh, 0.95rem); } /* Fonte menor para caber 12 letras de boa */
  
  #lista-palavras { max-height: 14vh; margin: 4px auto; }
  .palavra-item { padding: 4px 8px; font-size: 0.75rem; }
  
  /* Ajuste dos controles da direita para não sumirem na borda */
  .controles-inferiores { bottom: 10px; right: 10px; }
  .btn-circular { width: 48px; height: 48px; font-size: 1.3rem; }
}

/* Telas muito espremidas na altura (ex: aba de favoritos aberta, celular deitado) */
@media (max-height: 600px) {
  #grid { width: min(92vw, 380px, 42vh); gap: 2px;}
  #lista-palavras { max-height: 12vh; }
}