:root {
  --mesa-verde: #2b6b3e;
  --header-madeira: #4a2e1b;
  --btn-amarelo: #f0a500;
  --btn-amarelo-hover: #d18e00;
  --card-azul: #4a7c9d;
  --card-borda: #ffffff;
  --font-padrao: "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  height: 100dvh; width: 100%; font-family: var(--font-padrao);
  background-color: var(--mesa-verde); overflow: hidden;
  display: flex; flex-direction: column;
  background-size: cover; background-position: center;
}

.tela { display: none; width: 100%; height: 100%; flex-direction: column; }
.tela.ativa { display: flex; }

/* FUNDO ANIMADO */
#fundo-caindo { position: absolute; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.carta-caindo { position: absolute; font-size: 3rem; opacity: 0.15; animation: cair linear infinite; }
@keyframes cair {
  0% { transform: translateY(-100px) rotate(0deg); }
  100% { transform: translateY(110vh) rotate(360deg); }
}

/* TELA 1 (MENU INICIAL) */
#tela-inicio { align-items: center; justify-content: center; text-align: center; padding: 20px; position: relative; }
.menu-container { 
  position: relative; z-index: 10; background: rgba(0,0,0,0.7); padding: 30px; 
  border-radius: 20px; max-width: 500px; width: 100%; border: 1px solid rgba(255,255,255,0.2); 
  box-shadow: 0 10px 30px rgba(0,0,0,0.5); backdrop-filter: blur(4px);
}
.logo-titulo { font-size: 3rem; color: white; text-shadow: 2px 2px 4px black; margin-bottom: 10px; }
.subtitulo { color: #ccc; margin-bottom: 20px; }

.temas-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; margin-bottom: 25px; }
.btn-tema { 
  background: rgba(255,255,255,0.1); border: 2px solid rgba(255,255,255,0.2); border-radius: 10px; 
  padding: 15px; cursor: pointer; display: flex; flex-direction: column; align-items: center; 
  gap: 5px; color: white; transition: 0.2s; 
}
.btn-tema:hover { background: rgba(255,255,255,0.2); }
.btn-tema.selecionado { border-color: var(--btn-amarelo); background: rgba(240, 165, 0, 0.2); }
.btn-tema .icone { font-size: 2rem; }

.btn-jogar { 
  background: var(--btn-amarelo); color: #333; font-weight: bold; font-size: 1.2rem; 
  padding: 15px 40px; border: none; border-radius: 30px; cursor: pointer; 
  width: 100%; box-shadow: inset 0 -4px 0 rgba(0,0,0,0.2); 
}
.btn-jogar:hover { background: var(--btn-amarelo-hover); }

.btn-ranking-hub {
  background: transparent; color: var(--btn-amarelo); border: 2px solid var(--btn-amarelo);
  padding: 12px 20px; border-radius: 30px; cursor: pointer; width: 100%; font-size: 1rem; 
  margin-top: 10px; transition: 0.2s; text-transform: uppercase; font-weight: bold;
}
.btn-ranking-hub:hover { background: rgba(240, 165, 0, 0.2); }

.btn-sair-hub {
  background: transparent; color: #ccc; border: 1px solid #ccc; padding: 12px 20px;
  border-radius: 30px; cursor: pointer; width: 100%; font-size: 1rem; margin-top: 10px;
  transition: 0.2s; text-transform: uppercase; font-weight: bold;
}
.btn-sair-hub:hover { background: rgba(255,255,255,0.1); color: white; border-color: white; }

/* TELA 2 (JOGO) */
.header-jogo { 
  background-color: var(--header-madeira); height: 60px; display: flex; justify-content: space-between; 
  align-items: center; padding: 0 20px; box-shadow: 0 4px 6px rgba(0,0,0,0.3); z-index: 50; flex-shrink: 0; 
}
.logo-text { color: #fff; font-size: 1.5rem; font-weight: 800; text-shadow: 2px 2px 4px rgba(0,0,0,0.5); display: flex; align-items: center; gap: 10px; }
.logo-icone-teste { 
  width: 30px; height: 30px; border-radius: 50%; border: 2px solid white; 
  background: #e94560; display: flex; align-items: center; justify-content: center; 
  font-size: 0.8rem; font-weight: bold; 
}
.header-botoes { display: flex; gap: 10px; align-items: center; }
.btn-topo { 
  background-color: var(--btn-amarelo); color: #333; border: 1px solid #b37c00; padding: 8px 20px; 
  border-radius: 20px; font-weight: 800; font-size: 0.9rem; cursor: pointer; 
  box-shadow: inset 0 -3px 0 rgba(0,0,0,0.15); text-transform: uppercase; display: flex; align-items: center; gap: 5px; 
}
.btn-topo:hover { background-color: var(--btn-amarelo-hover); }
.btn-icone-topo { 
  width: 40px; height: 40px; border-radius: 10px; background-color: var(--btn-amarelo); color: #333; 
  border: 1px solid #b37c00; display: flex; align-items: center; justify-content: center; 
  font-size: 1.2rem; cursor: pointer; box-shadow: inset 0 -3px 0 rgba(0,0,0,0.15); 
}

/* TABULEIRO */
.area-tabuleiro { flex: 1; display: flex; justify-content: center; align-items: center; padding: 10px; overflow: hidden; position: relative; }
.tabuleiro-wrapper { transition: transform 0.2s ease; transform-origin: center center; width: 100%; max-width: 1200px; }
.tabuleiro { display: grid; grid-template-columns: repeat(12, 1fr); gap: 8px; width: 100%; }
.carta { 
  aspect-ratio: 3 / 4; background-color: var(--card-azul); border-radius: 6px; border: 2px solid var(--card-borda); 
  position: relative; cursor: pointer; box-shadow: 0 4px 8px rgba(0,0,0,0.3); 
  background-image: linear-gradient(45deg, rgba(255,255,255,0.1) 25%, transparent 25%, transparent 75%, rgba(255,255,255,0.1) 75%, rgba(255,255,255,0.1)), linear-gradient(45deg, rgba(255,255,255,0.1) 25%, transparent 25%, transparent 75%, rgba(255,255,255,0.1) 75%, rgba(255,255,255,0.1)); 
  background-size: 20px 20px; background-position: 0 0, 10px 10px;
  transition: opacity 0.4s ease, visibility 0.4s ease;
}
.carta img { width: 100%; height: 100%; object-fit: contain; border-radius: 4px; display: none; }
.carta.revelada { background: #fff; background-image: none; }
.carta.revelada img { display: block; }
.carta.combinada { opacity: 0 !important; visibility: hidden !important; pointer-events: none !important; }

/* FOOTER */
.footer-jogo { 
  background-color: rgba(0,0,0,0.5); height: 45px; display: flex; justify-content: space-between; 
  align-items: center; padding: 0 20px; color: white; font-size: 1rem; font-weight: 700; 
  z-index: 50; flex-shrink: 0; 
}
.footer-jogo span { color: #f0a500; }
.zoom-controle { display: flex; align-items: center; gap: 10px; }
.zoom-controle input { width: 100px; cursor: pointer; }

/* POPUPS GERAIS */
.overlay { 
  position: fixed; inset: 0; z-index: 100; display: none; align-items: center; 
  justify-content: center; background: rgba(0,0,0,0.7); backdrop-filter: blur(4px); 
}
.overlay.ativo { display: flex; }
.popup-card { 
  background: #fff; padding: 25px; border-radius: 12px; width: 90%; 
  max-width: 450px; text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,0.5); 
}
.popup-card h2 { color: #333; margin-bottom: 10px; }
.popup-card p { color: #666; margin-bottom: 15px; }
.popup-card input { 
  width: 100%; padding: 12px; border: 2px solid #ddd; border-radius: 8px; 
  margin-bottom: 15px; font-size: 1rem; text-align: center; outline: none; 
}
.popup-card input:focus { border-color: var(--btn-amarelo); }
.popup-botoes { display: flex; gap: 10px; flex-direction: column; }
.btn-principal { background: var(--btn-amarelo); color: #333; font-weight: bold; border: none; padding: 12px; border-radius: 8px; cursor: pointer; font-size: 1rem; transition: 0.2s; }
.btn-principal:hover { background: var(--btn-amarelo-hover); }
.btn-secundario { background: #eee; color: #333; font-weight: bold; border: none; padding: 12px; border-radius: 8px; cursor: pointer; font-size: 1rem; transition: 0.2s; }
.btn-secundario:hover { background: #ddd; }

/* POPUP AJUDA E VITÓRIA */
.lista-ajuda {
  text-align: left;
  margin: 15px 0 20px 20px;
  color: #555;
  line-height: 1.6;
  font-size: 0.95rem;
}

.stats-vitoria {
  background: #f9f9f9;
  padding: 15px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 1.1rem;
  color: #333;
  border: 1px solid #eee;
  margin-bottom: 15px;
}
.stats-vitoria strong { color: #000; }

/* MENU SANDUÍCHE */
.overlay-bg { position: absolute; inset: 0; }
.menu-sanduiche-box { 
  position: absolute; top: 55px; left: 50%; transform: translateX(-50%); 
  background-color: #1e1e1e; border-radius: 6px; width: 280px; 
  box-shadow: 0 10px 25px rgba(0,0,0,0.5); color: white; padding: 15px 0; 
  display: flex; flex-direction: column; z-index: 101; 
}
.menu-sanduiche-box::before { 
  content: ''; position: absolute; top: -8px; left: 50%; transform: translateX(-50%); 
  border-left: 8px solid transparent; border-right: 8px solid transparent; border-bottom: 8px solid #1e1e1e; 
}
.menu-item { 
  background: none; border: none; color: white; padding: 12px 20px; font-size: 1rem; 
  font-weight: 700; text-transform: uppercase; text-align: left; cursor: pointer; 
  display: flex; align-items: center; gap: 15px; transition: background 0.2s; 
}
.menu-item:hover { background-color: #333; }
.menu-item.destaque { border-top: 1px solid #333; margin-top: 10px; padding-top: 15px; }

/* CONFIGURAÇÕES */
.config-box { 
  background: #f4f4f4; border-radius: 8px; width: 95%; max-width: 700px; 
  box-shadow: 0 10px 30px rgba(0,0,0,0.5); color: #333; display: flex; 
  flex-direction: column; max-height: 90vh; 
}
.config-header { 
  background: #d9c5a9; padding: 15px 20px; display: flex; justify-content: space-between; 
  align-items: center; position: relative; flex-shrink: 0; border-radius: 8px 8px 0 0; 
}
.config-tabs { display: flex; gap: 10px; }
.tab-btn { 
  background: transparent; border: 2px solid transparent; padding: 6px 18px; 
  border-radius: 20px; font-size: 1rem; font-weight: 700; color: #555; cursor: pointer; 
}
.tab-btn.ativo { background: #3e2723; color: white; }
.btn-fechar-config { background: none; border: none; font-size: 1.8rem; color: #555; cursor: pointer; position: absolute; right: 15px; top: 10px; }
.config-body { padding: 15px 20px; background: #fff; border-radius: 0 0 8px 8px; overflow: hidden; display: flex; flex-direction: column; gap: 10px; }
.dark-mode-row { display: flex; justify-content: flex-end; align-items: center; gap: 10px; font-weight: 800; font-size: 0.9rem; color: #555; }

/* Switch */
.switch { position: relative; display: inline-block; width: 40px; height: 20px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; transition: .4s; border-radius: 20px; }
.slider:before { position: absolute; content: ""; height: 16px; width: 16px; left: 2px; bottom: 2px; background-color: white; transition: .4s; border-radius: 50%; }
input:checked + .slider { background-color: #f0a500; }
input:checked + .slider:before { transform: translateX(20px); }

/* Grid de Fundos */
.grid-fundos { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; width: 100%; }
.btn-imagem { 
  aspect-ratio: 1.2 / 1; border-radius: 4px; cursor: pointer; border: 2px solid transparent; 
  background-size: cover; background-position: center; background-color: #ddd; 
  display: flex; align-items: center; justify-content: center; font-size: 0.65rem; 
  font-weight: bold; color: white; text-shadow: 1px 1px 2px black; 
}
.btn-imagem.selecionado { border-color: #f0a500; }
.btn-imagem.fundo-padrao { background-color: #2b6b3e; text-align: center; }

/* Paleta de Cores */
.paleta-cores { display: grid; grid-template-columns: repeat(12, 1fr); gap: 6px; padding-top: 10px; border-top: 1px solid #eee; }
.btn-cor { aspect-ratio: 1 / 1; border-radius: 4px; border: 2px solid transparent; cursor: pointer; }
.btn-cor.selecionado { border-color: #333; }

/* RESPONSIVIDADE */
@media (max-width: 900px) { 
  .tabuleiro { grid-template-columns: repeat(8, 1fr); gap: 5px; } 
}

@media (max-width: 600px) { 
  .header-jogo { padding: 0 10px; height: 50px; }
  .logo-text { font-size: 1rem; }
  .btn-topo { padding: 6px 12px; font-size: 0.75rem; }
  .btn-topo span { display: none; }
  .btn-icone-topo { width: 32px; height: 32px; font-size: 1rem; }
  
  .tabuleiro { grid-template-columns: repeat(6, 1fr); gap: 4px; } 
  
  .footer-jogo { height: 40px; font-size: 0.75rem; padding: 0 10px; }
  .zoom-controle input { width: 60px; }
  .info-jogo { display: none; }
  
  .menu-sanduiche-box { width: 200px; }
  .config-box { width: 98%; }
  
  .grid-fundos { grid-template-columns: repeat(6, 1fr); gap: 4px; }
  .btn-imagem { aspect-ratio: 1 / 1; font-size: 0; }
  .btn-imagem.fundo-padrao { font-size: 0.6rem; }
  .paleta-cores { grid-template-columns: repeat(12, 1fr); gap: 3px; }
  
  .logo-titulo { font-size: 2rem; }
  .temas-grid { grid-template-columns: repeat(2, 1fr); }
}

/* TABELA DO RANKING */
#tabelaRanking table { margin-top: 15px; font-size: 0.95rem; color: #333; }
#tabelaRanking th { padding-bottom: 8px; border-bottom: 2px solid #ccc; color: #555; font-weight: bold; }
#tabelaRanking td { padding: 8px 0; }