/* ===============================
   RESET & BASE - OCEANO PROFUNDO
   =============================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  background: radial-gradient(circle at 20% 30%, #0a1928, #020c18, #000408);
  font-family: 'Segoe UI', 'Poppins', 'Arial', system-ui, -apple-system, sans-serif;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  position: relative;
  overflow-x: hidden;
}

/* Efeito de partículas/bolhas no fundo */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: 
    radial-gradient(2px 2px at 15% 40%, rgba(0, 255, 200, 0.15), transparent),
    radial-gradient(3px 3px at 75% 85%, rgba(64, 224, 208, 0.12), transparent),
    radial-gradient(1px 1px at 35% 20%, rgba(0, 255, 180, 0.1), transparent),
    radial-gradient(2px 2px at 90% 60%, rgba(72, 209, 204, 0.08), transparent);
  background-repeat: no-repeat;
  pointer-events: none;
  z-index: 0;
}

/* ===============================
   APP - PAINEL FLUTUANTE (GLASS)
   =============================== */
.app {
  position: relative;
  z-index: 2;
  text-align: center;
  padding: 30px 25px;
  max-width: 600px;
  width: 100%;
  background: rgba(8, 28, 41, 0.45);
  backdrop-filter: blur(12px);
  border-radius: 48px;
  border: 1px solid rgba(64, 224, 208, 0.25);
  box-shadow: 
    0 25px 45px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 0 0 0.5px rgba(0, 255, 200, 0.15);
  transition: all 0.3s ease;
}

.app:hover {
  border-color: rgba(0, 255, 200, 0.35);
  box-shadow: 0 30px 55px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

/* ===============================
   TÍTULO - LAB SINALIZADOR
   =============================== */
h1 {
  font-size: 2.2rem;
  font-weight: 600;
  letter-spacing: 3px;
  background: linear-gradient(135deg, #a0f0e8, #40e0d0, #00ffcc);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 12px rgba(0, 255, 200, 0.3);
  margin-bottom: 24px;
  text-transform: uppercase;
  position: relative;
  display: inline-block;
  padding-bottom: 8px;
}

h1::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 10%;
  width: 80%;
  height: 2px;
  background: linear-gradient(90deg, transparent, #00ffcc, #40e0d0, transparent);
  border-radius: 2px;
}

/* ===============================
   CONTROLES - PAINEL CIENTÍFICO
   =============================== */
.controls {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 28px;
}

button {
  padding: 10px 22px;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 1px;
  border: none;
  border-radius: 60px;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.2, 0.9, 0.4, 1.1);
  background: rgba(16, 42, 58, 0.7);
  backdrop-filter: blur(8px);
  color: #b8f2e8;
  text-transform: uppercase;
  border: 1px solid rgba(64, 224, 208, 0.4);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

button:hover {
  background: rgba(0, 255, 200, 0.18);
  border-color: #00ffcc;
  color: #ffffff;
  text-shadow: 0 0 5px rgba(0, 255, 200, 0.5);
  transform: translateY(-2px);
  box-shadow: 0 6px 14px rgba(0, 255, 200, 0.15);
}

button:active {
  transform: translateY(1px);
}

/* Destaque para o botão Iniciar */
.controls button:last-child {
  background: rgba(0, 200, 180, 0.2);
  border-color: #00ffcc;
  color: #ffffff;
  box-shadow: 0 0 10px rgba(0, 255, 200, 0.3);
}

.controls button:last-child:hover {
  background: rgba(0, 255, 200, 0.35);
  box-shadow: 0 0 18px rgba(0, 255, 200, 0.5);
}

/* ===============================
   PREVIEW - TELA SONAR
   =============================== */
#preview {
  width: min(85vw, 400px);
  aspect-ratio: 1 / 1;
  margin: 0 auto 20px;
  background-size: cover;
  background-position: center;
  border-radius: 28px;
  box-shadow: 
    0 12px 28px rgba(0, 0, 0, 0.5),
    inset 0 0 30px rgba(0, 255, 200, 0.15),
    0 0 0 2px rgba(64, 224, 208, 0.3);
  transition: all 0.3s;
  position: relative;
}

/* Efeito de scan no preview */
#preview::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(120deg, transparent 30%, rgba(0, 255, 200, 0.1) 50%, transparent 70%);
  pointer-events: none;
  border-radius: 28px;
}

/* ===============================
   MINIATURA DE REFERÊNCIA (DENTRO DO FLUXO)
   =============================== */
.thumbnail {
  position: relative;
  display: inline-block;
  width: 80px;
  height: 80px;
  margin: 0 auto 15px;
  border-radius: 16px;
  background-size: cover;
  background-position: center;
  border: 2px solid rgba(64, 224, 208, 0.7);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  transition: all 0.2s ease;
}

.thumbnail:hover {
  transform: scale(1.05);
  border-color: #00ffcc;
  box-shadow: 0 6px 16px rgba(0, 255, 200, 0.4);
}

/* ===============================
   PUZZLE - GRADE DE CRISTAL
   =============================== */
#puzzle {
  width: min(85vw, 400px);
  aspect-ratio: 1 / 1;
  display: grid;
  margin: 0 auto;
  gap: 3px;
  background: rgba(0, 20, 30, 0.5);
  padding: 6px;
  border-radius: 24px;
  box-shadow: 
    0 8px 20px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

/* ===============================
   PEÇAS - VIDRO AQUÁTICO
   =============================== */
.tile {
  background-size: 100% 100%;
  cursor: pointer;
  border-radius: 12px;
  transition: all 0.18s ease;
  box-shadow: 
    0 1px 3px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(0px);
  border: 1px solid rgba(64, 224, 208, 0.2);
}

.tile:hover {
  transform: scale(0.97);
  filter: brightness(1.08) contrast(1.05);
  box-shadow: 0 2px 6px rgba(0, 200, 180, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.15);
  border-color: rgba(0, 255, 200, 0.6);
}

/* PEÇA VAZIA */
.empty {
  background: radial-gradient(circle at 30% 35%, #0a1c24, #031016);
  box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.6);
  border: 1px dashed rgba(64, 224, 208, 0.4);
  position: relative;
}

.empty::after {
  content: '⌗';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.8rem;
  opacity: 0.25;
  color: #00ffcc;
  font-weight: 300;
}

/* ===============================
   VITÓRIA - SINAL BIOLUMINESCENTE
   =============================== */
#win {
  margin-top: 25px;
  padding: 18px 22px;
  background: rgba(0, 40, 45, 0.75);
  backdrop-filter: blur(16px);
  border-radius: 60px;
  font-size: 1.5rem;
  font-weight: bold;
  color: #d0fff0;
  text-shadow: 0 0 8px #00ffcc;
  border: 1px solid #00ffcc;
  box-shadow: 0 0 25px rgba(0, 255, 200, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.2);
  letter-spacing: 1px;
  animation: pulseGlow 1.8s infinite;
}

#win button {
  margin-left: 18px;
  background: rgba(0, 255, 200, 0.2);
  border-color: #00ffcc;
  padding: 6px 18px;
  font-size: 0.9rem;
}

#win button:hover {
  background: #00ffcc22;
  transform: scale(1.02);
}

/* Animação de brilho pulsante */
@keyframes pulseGlow {
  0% {
    box-shadow: 0 0 10px rgba(0, 255, 200, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.1);
    border-color: rgba(0, 255, 200, 0.6);
  }
  100% {
    box-shadow: 0 0 24px rgba(0, 255, 200, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.25);
    border-color: #00ffcc;
  }
}

/* ===============================
   UTILITÁRIOS
   =============================== */
.hidden {
  display: none;
}

/* ===============================
   TIMER
   =============================== */
#timer {
  margin-bottom: 12px;
  font-size: 1rem;
  color: #b8f2e8;
  font-weight: 600;
  letter-spacing: 1px;
  text-shadow: 0 0 6px rgba(0, 255, 200, 0.3);
}

/* ===============================
   AJUSTE INICIAL: PREVIEW E PUZZLE ESCONDIDOS
   =============================== */
#preview,
#puzzle {
  display: none;
}

#preview.active {
  display: block;
}

#puzzle.active {
  display: grid;
}

/* ===============================
   BOTÃO DE DIFICULDADE ATIVO
   =============================== */
.controls button.active {
  background: linear-gradient(135deg, rgba(0, 200, 180, 0.35), rgba(0, 255, 200, 0.25));
  border-color: #00ffcc;
  color: #ffffff;
  text-shadow: 0 0 8px rgba(0, 255, 200, 0.6);
  box-shadow: 0 0 15px rgba(0, 255, 200, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.15);
  transform: scale(1.02);
  position: relative;
}

.controls button.active::before {
  content: '▶';
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.7rem;
  color: #00ffcc;
  opacity: 0.8;
}

.controls button.active {
  padding-left: 28px;
}

/* ===============================
   LIGHTBOX (IMAGEM AMPLIADA)
   =============================== */
.lightbox-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  cursor: pointer;
  animation: fadeIn 0.2s ease;
}

.lightbox-image {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 28px;
  border: 2px solid #00ffcc;
  box-shadow: 0 0 40px rgba(0, 255, 200, 0.4);
  cursor: default;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ===============================
   RESPONSIVIDADE - SENSOR DE PROFUNDIDADE
   =============================== */
@media (max-width: 520px) {
  .app {
    padding: 20px 18px;
    border-radius: 36px;
  }

  h1 {
    font-size: 1.7rem;
    letter-spacing: 2px;
  }

  button {
    padding: 7px 16px;
    font-size: 0.75rem;
  }

  .tile {
    border-radius: 8px;
  }

  #win {
    font-size: 1.1rem;
    padding: 12px 16px;
  }
  
  .empty::after {
    font-size: 1.2rem;
  }

  .thumbnail {
    width: 60px;
    height: 60px;
    margin-bottom: 10px;
  }
}

/* Esconder título durante o jogo */
.app.game-active h1 {
  display: none;
}

/* ===============================
   TELA INICIAL (HERO MODE)
   =============================== */

.app:not(.game-active) {
  padding: 50px 30px;
  border-radius: 60px;
  background: rgba(8, 28, 41, 0.55);
  box-shadow:
    0 35px 80px rgba(0, 0, 0, 0.6),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

/* Título mais impactante na tela inicial */
.app:not(.game-active) h1 {
  font-size: 2.8rem;
  letter-spacing: 4px;
  margin-bottom: 35px;
  text-shadow:
    0 0 15px rgba(0, 255, 200, 0.4),
    0 0 40px rgba(0, 255, 200, 0.15);
}

/* Centraliza melhor os controles no início */
.app:not(.game-active) .controls {
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

/* Botões maiores e mais “game start feeling” */
.app:not(.game-active) .controls button {
  width: 220px;
  font-size: 0.95rem;
  padding: 12px 20px;
}

/* Destaque máximo no botão INICIAR */
.app:not(.game-active) .controls button:last-child {
  background: linear-gradient(135deg, #00ffcc, #00bfa6);
  color: #001b1a;
  font-weight: 800;
  box-shadow:
    0 0 25px rgba(0, 255, 200, 0.35),
    0 10px 25px rgba(0, 0, 0, 0.4);
  transform: scale(1.05);
}

/* Hover do iniciar mais “game feel” */
.app:not(.game-active) .controls button:last-child:hover {
  transform: scale(1.1);
  box-shadow:
    0 0 35px rgba(0, 255, 200, 0.55),
    0 12px 30px rgba(0, 0, 0, 0.5);
}

/* Esconde timer e preview na tela inicial */
.app:not(.game-active) #timer,
.app:not(.game-active) #preview,
.app:not(.game-active) #puzzle,
.app:not(.game-active) #thumbnail {
  display: none;
}

/* ===============================
   BOTÃO MENU LATERAL
   =============================== */
/* ===============================
   BOTÃO MENU LATERAL (POSIÇÃO CORRETA)
   =============================== */

#backMenu {
  position: absolute;
  top: 20px;
  left: 20px;

  z-index: 999;

  padding: 12px 14px;
  border-radius: 14px;

  background: rgba(8, 28, 41, 0.6);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(0, 255, 200, 0.3);

  color: #b8f2e8;
  font-size: 0.85rem;
  font-weight: 600;

  cursor: pointer;

  transition: all 0.25s ease;
}

#backMenu {
  transform: translateY(0) scale(1);
  will-change: transform;
  transition: transform 0.25s ease, box-shadow 0.25s ease, background 0.25s ease, border-color 0.25s ease, color 0.25s ease;
}

#backMenu:hover {
  transform: scale(1.08);
  background: rgba(0, 255, 200, 0.15);
  border-color: #00ffcc;
  box-shadow: 0 0 18px rgba(0, 255, 200, 0.25);
  color: #ffffff;
}

/* Esconde o botão MENU na tela inicial */
.app:not(.game-active) #backMenu {
  display: none;
}

/* ===============================
   ANIMAÇÃO DE ENTRADA DO TABULEIRO
   =============================== */

#puzzle.active {
  animation: puzzleEnter 0.5s ease-out both;
}

@keyframes puzzleEnter {
  0% {
    opacity: 0;
    transform: scale(0.85) translateY(20px);
    filter: blur(6px);
  }

  60% {
    opacity: 1;
    transform: scale(1.02) translateY(-4px);
    filter: blur(0px);
  }

  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
    filter: blur(0px);
  }
}

/* ===============================
   ESCONDE TODOS OS BOTÕES DURANTE O JOGO
   =============================== */

.app.game-active .controls {
  display: none;
}

#win {
  display: none;
}

#win.active {
  position: fixed;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(0,10,20,0.75);
  backdrop-filter: blur(12px);
  z-index: 999;
}

/* caixa principal */
.win-content {
  text-align: center;
  padding: 40px 32px;

  background: rgba(8, 28, 41, 0.6);
  border: 1px solid rgba(0, 255, 200, 0.35);
  border-radius: 28px;

  box-shadow:
    0 0 30px rgba(0, 255, 200, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);

  transform: scale(0.9);
  animation: popWin 0.5s ease forwards;
}

/* título */
.win-title {
  font-size: 2rem;
  font-weight: 800;
  color: #00ffcc;
  text-shadow: 0 0 12px rgba(0, 255, 200, 0.5);
  margin-bottom: 10px;
  letter-spacing: 2px;
}

/* subtítulo */
.win-subtitle {
  font-size: 1rem;
  color: #b8f2e8;
  margin-bottom: 25px;
  opacity: 0.9;
}

/* botão */
#win button {
  padding: 12px 22px;
  border-radius: 50px;
  border: 1px solid #00ffcc;

  background: rgba(0, 255, 200, 0.15);
  color: #ffffff;

  font-weight: 700;
  letter-spacing: 1px;

  cursor: pointer;
  transition: 0.25s ease;

  box-shadow: 0 0 15px rgba(0, 255, 200, 0.2);
}

#win button:hover {
  transform: scale(1.08);
  background: rgba(0, 255, 200, 0.3);
  box-shadow: 0 0 25px rgba(0, 255, 200, 0.4);
}

/* animações */
@keyframes winFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes popWin {
  0% {
    transform: scale(0.7);
    opacity: 0;
  }
  60% {
    transform: scale(1.05);
    opacity: 1;
  }
  100% {
    transform: scale(1);
  }
}

#win {
  display: flex !important;
  position: fixed !important;
  inset: 0 !important;
  background: rgba(0,10,20,0.9) !important;
  backdrop-filter: blur(12px) !important;
  z-index: 9999 !important;
  justify-content: center !important;
  align-items: center !important;
}

#win.hidden {
  display: none !important;
}

#changeImage {
  position: absolute;
  top: 20px;
  right: 20px;

  z-index: 999;

  padding: 12px 14px;
  border-radius: 14px;

  background: rgba(8, 28, 41, 0.6);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(0, 255, 200, 0.3);

  color: #b8f2e8;
  font-size: 0.85rem;
  font-weight: 600;

  cursor: pointer;

  transition: 0.25s ease;
}

#changeImage:hover {
  transform: scale(1.08);
  background: rgba(0, 255, 200, 0.15);
  border-color: #00ffcc;
  box-shadow: 0 0 18px rgba(0, 255, 200, 0.25);
  color: #ffffff;
}

/* esconder no menu inicial */
.app:not(.game-active) #changeImage {
  display: none;
}