/* Reset e estilo básico */
* {
  box-sizing: border-box;
}
body {
  font-family: 'Comic Sans MS', cursive, sans-serif;
  margin: 0;
  padding: 0;
  background: linear-gradient(135deg, #a06a0c, #d1bfa7);
  color: #3a1a00;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  user-select: none;
  overflow-x: hidden;
}

/* Header */
header {
  margin: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  max-width: 600px;
  color: #fff8dc;
  text-shadow: 1px 1px 4px #663300;
}

header h1 {
  font-size: 1.8rem;
  margin: 0;
  flex: 1;
}

#btn-tutorial {
  font-size: 1.2rem;
  background: #f9a825;
  border: none;
  border-radius: 8px;
  padding: 0.5rem 1rem;
  cursor: pointer;
  box-shadow: 0 3px 8px #6e4707;
  color: #3a1a00;
  font-weight: 700;
  transition: background 0.3s ease;
  user-select: none;
}

#btn-tutorial:hover {
  background: #fbc02d;
}

/* HUD */
#hud {
  display: flex;
  justify-content: center;
  gap: 3rem;
  margin-bottom: 1rem;
  font-weight: bold;
  font-size: 1.4rem;
  color: #fff8dc;
  text-shadow: 2px 2px 5px #663300;
  max-width: 600px;
  width: 100%;
  padding: 0 1rem;
  user-select: none;
}

/* Board */
#board {
  display: grid;
  grid-template-columns: repeat(8, 70px);
  grid-template-rows: repeat(8, 70px);
  gap: 8px;
  background: linear-gradient(180deg, #e9c97a, #c08c16);
  border-radius: 16px;
  padding: 16px;
  box-shadow: inset 0 0 20px #613a00;
  position: relative;
  margin-bottom: 1rem;
  user-select: none;
}

/* Células */
.cell {
  background: transparent;
  border-radius: 16px;
  font-size: 2.5rem;
  line-height: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  position: relative;
  transition: transform 0.25s ease;
  user-select: none;
  box-shadow: none;
}

.cell:hover:not(.empty):not(.crown) {
  transform: scale(1.1);
  filter: drop-shadow(0 0 8px #f9d71c);
}

/* Pedra gráfica */
.stone {
  position: relative;
  width: 60px;
  height: 60px;
  border-radius: 14px;
  background: radial-gradient(circle at center, #725c1a 0%, #442f07 80%);
  box-shadow:
    inset 0 4px 10px rgba(255 255 255 / 0.15),
    inset 0 -4px 10px rgba(0 0 0 / 0.7),
    0 3px 5px rgba(0 0 0 / 0.8);
  overflow: visible;
  user-select: none;
}

.stone::before {
  content: "";
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: radial-gradient(circle, #f9d71c 0%, transparent 70%);
  top: 10px;
  left: 15px;
  box-shadow:
    15px 25px #f9d71c,
    30px 10px #fbc02d,
    40px 40px #fff176;
  animation: sparkle 3s infinite ease-in-out alternate;
  pointer-events: none;
  user-select: none;
}

@keyframes sparkle {
  0% {
    opacity: 0.4;
    transform: scale(0.8);
  }
  100% {
    opacity: 1;
    transform: scale(1.1);
  }
}

/* Vida */
.hp-bar {
  position: absolute;
  bottom: 6px;
  left: 6px;
  right: 6px;
  height: 8px;
  background: #ffd54f;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: inset 0 0 4px #a05e00;
}

.hp-fill {
  height: 100%;
  background: linear-gradient(90deg, #ff6f00, #fbc02d);
  transition: width 0.3s ease;
}

.cell.empty {
  cursor: default;
  box-shadow: none;
  background: transparent;
}

.cell.crown {
  font-size: 3rem !important;
  color: #ffdd57;
  text-shadow:
    0 0 10px #ffea00,
    0 0 20px #ffea00,
    0 0 30px #ffd600,
    0 0 40px #ffb300,
    0 0 50px #ffa200,
    0 0 60px #ff8f00,
    0 0 70px #ff7f00;
  user-select: none;
}

#hammer {
  position: fixed;
  font-size: 3.5rem;
  pointer-events: none;
  user-select: none;
  transition: left 0.1s ease, top 0.1s ease;
  text-shadow:
    0 0 5px #ffd54f,
    0 0 10px #ffd54f;
  z-index: 1000;
  filter: drop-shadow(0 0 6px #fbc02d);
}

.spark {
  position: fixed;
  font-size: 1.8rem;
  animation: sparkFade 0.6s ease forwards;
  user-select: none;
  pointer-events: none;
  z-index: 1050;
  filter: drop-shadow(0 0 6px #fbc02d);
}

@keyframes sparkFade {
  0% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-20px) scale(0.7); }
}

.toast-message {
  position: fixed;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: #f9a825;
  color: #3a1a00;
  padding: 0.6rem 1.4rem;
  border-radius: 16px;
  box-shadow: 0 5px 15px rgba(0,0,0,0.4);
  z-index: 1100;
  font-weight: 900;
  font-size: 1.1rem;
  animation: toastFadeIn 0.3s ease forwards;
  user-select: none;
}

@keyframes toastFadeIn {
  from { opacity: 0; transform: translateY(-10px) translateX(-50%); }
  to { opacity: 1; transform: translateY(0) translateX(-50%); }
}

#popup {
  position: fixed;
  top: 50%;
  left: 50%;
  width: 320px;
  max-width: 90vw;
  padding: 1.5rem 2rem;
  background: #fffde7;
  border-radius: 20px;
  box-shadow: 0 0 30px #f9a825;
  transform: translate(-50%, -50%);
  display: none;
  flex-direction: column;
  align-items: center;
  color: #3a1a00;
  font-family: 'Comic Sans MS', cursive, sans-serif;
  z-index: 1200;
  text-align: center;
}

#popup h2 {
  margin: 0 0 1rem;
  font-size: 1.6rem;
  font-weight: 700;
  color: #f9a825;
  text-shadow: 1px 1px 3px #663300;
}

#popup button {
  background: #f9a825;
  border: none;
  padding: 0.8rem 1.2rem;
  font-weight: 700;
  font-size: 1.1rem;
  border-radius: 12px;
  cursor: pointer;
  color: #3a1a00;
  box-shadow: 0 3px 7px #6e4707;
  margin: 0.5rem;
  user-select: none;
  transition: background 0.3s ease;
}

#popup button:hover {
  background: #fbc02d;
}

/* Tutorial dialog */
dialog {
  border-radius: 16px;
  padding: 1.5rem 2rem;
  font-family: 'Comic Sans MS', cursive, sans-serif;
  box-shadow: 0 0 25px #f9a825;
  max-width: 360px;
  width: 90vw;
  background: #fffde7;
  color: #3a1a00;
}

dialog button {
  margin-top: 1rem;
  background: #f9a825;
  border: none;
  padding: 0.7rem 1.3rem;
  font-weight: bold;
  border-radius: 12px;
  cursor: pointer;
  width: 100%;
  user-select: none;
  transition: background 0.3s ease;
}

dialog button:hover {
  background: #fbc02d;
}

/* Responsivo */
@media (max-width: 480px) {
  body {
    padding: 0 10px;
    overflow-x: hidden;
  }

  header {
    flex-direction: column;
    gap: 8px;
    margin: 1rem 0;
    text-align: center;
  }

  header h1 {
    font-size: 1.4rem;
    margin: 0;
  }

  #btn-tutorial {
    font-size: 1rem;
    padding: 0.4rem 0.8rem;
    width: 100%;
    max-width: 220px;
    margin: 0 auto;
    box-shadow: 0 1px 4px #6e4707;
  }

  main {
    max-width: 100%;
  }

  #hud {
    flex-direction: column;
    gap: 8px;
    font-size: 1.1rem;
    margin-bottom: 0.8rem;
  }

  #board {
    grid-template-columns: repeat(8, 32px);
    grid-template-rows: repeat(8, 32px);
    gap: 4px;
    width: fit-content;
    max-width: 100vw;
    margin: 0 auto;
    box-shadow: inset 0 0 10px #613a00;
    border-radius: 10px;
    user-select: none;
  }

  .cell {
    font-size: 1.5rem !important;
    padding: 0 !important;
    width: 32px !important;
    height: 32px !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    box-sizing: border-box !important;
    line-height: 1 !important;
    vertical-align: middle !important;
    cursor: pointer;
  }

  .cell:hover:not(.empty) {
    transform: none;
  }

  #hammer {
    font-size: 2.2rem;
  }

  .hp-bar {
    height: 4px;
    bottom: 4px;
    left: 4px;
    right: 4px;
  }

  .hp-fill {
    transition: width 0.25s ease;
  }

  #popup {
    width: 90vw;
    max-width: 320px;
    padding: 1rem;
    border-radius: 12px;
    box-sizing: border-box;
    font-size: 0.9rem;
  }

  #popup h2 {
    font-size: 1.2rem;
  }

  #popup button {
    font-size: 1rem;
    padding: 0.6rem;
  }

  dialog#tutorial-dialog {
    width: 90vw;
    max-width: 320px;
    padding: 1rem;
    font-size: 0.9rem;
  }

  dialog#tutorial-dialog button {
    font-size: 1rem;
    padding: 0.6rem;
  }
}

.btn-voltar {
  display: inline-block;
  margin: 1.5rem auto 2rem;
  padding: 0.8rem 1.8rem;
  background: linear-gradient(135deg, #f9a825, #f57f17);
  color: #3a1a00;
  font-weight: 700;
  font-size: 1.2rem;
  text-decoration: none;
  border-radius: 25px;
  box-shadow: 0 6px 12px rgba(249, 168, 37, 0.5);
  transition: background 0.3s ease, box-shadow 0.3s ease, transform 0.2s ease;
  user-select: none;
  text-align: center;
  cursor: pointer;
  border: 2px solid #d48806;
  max-width: 200px;
  width: 100%;
}

.btn-voltar:hover,
.btn-voltar:focus {
  background: linear-gradient(135deg, #fbc02d, #f9a825);
  box-shadow: 0 8px 16px rgba(249, 188, 56, 0.75);
  transform: translateY(-3px);
  outline: none;
}

.btn-voltar:active {
  transform: translateY(0);
  box-shadow: 0 4px 8px rgba(249, 168, 37, 0.4);
}