body {
  font-family: "Helvetica Neue", Arial, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start; /* Align to top for smaller screens */
  min-height: 100vh;
  margin: 0;
  padding-top: 10px; /* Reduced top padding */
  background-color: #faf8ef;
  color: #776e65;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  touch-action: none; /* Prevent default touch actions like scrolling */
  overflow: hidden; /* Prevent body scroll on mobile */
}

.game-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 90%;
  max-width: 500px; /* Max width for the game */
  user-select: none; /* Prevent text selection */
  -webkit-user-select: none;
  -moz-user-user-select: none;
  -ms-user-select: none;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  margin-bottom: 8px;
}

.title {
  font-size: clamp(1.8em, 7vw, 2.8em); /* Responsive font size, slightly smaller for longer title */
  font-weight: bold;
  margin: 0;
  white-space: nowrap; /* Prevent title from wrapping */
}

.controls-score {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.score-container {
  background-color: #bbada0;
  padding: 5px 15px;
  border-radius: 5px;
  font-size: clamp(0.9em, 3.5vw, 1.1em);
  text-align: center;
  color: #f9f6f2;
  min-width: 70px;
}

.score-container span {
  display: block;
  font-size: clamp(1.1em, 4.5vw, 1.4em);
  font-weight: bold;
  color: white;
}

#new-game-button {
  background-color: #8f7a66;
  color: white;
  padding: 7px 12px;
  border: none;
  border-radius: 5px;
  font-size: clamp(0.7em, 2.8vw, 0.9em);
  font-weight: bold;
  cursor: pointer;
  margin-top: 8px;
  transition: background-color 0.2s;
}

#new-game-button:hover {
  background-color: #776e65;
}

.difficulty-selector {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 8px;
  width: 100%;
}

.difficulty-btn {
  background-color: #cdc1b4;
  color: #776e65;
  padding: 5px 8px;
  border: 2px solid transparent;
  border-radius: 5px;
  font-size: clamp(0.65em, 2.2vw, 0.85em);
  font-weight: bold;
  cursor: pointer;
  transition: background-color 0.2s, border-color 0.2s;
}

.difficulty-btn:hover {
  background-color: #bbada0;
}

.difficulty-btn.active {
  background-color: #8f7a66;
  color: white;
  border-color: #776e65;
}

.easter-egg-lights {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px; /* Reduced gap */
  margin-bottom: 10px; /* Reduced margin */
  width: 100%;
}

.light-bulb-row-container {
  display: flex;
  align-items: center;
  gap: 6px; /* Reduced gap */
  font-size: clamp(0.65em, 2.2vw, 0.85em); /* Adjusted font size */
}

.light-bulb-label {
  color: #776e65;
  font-weight: bold;
}

.light-bulb-row {
  display: flex;
  gap: 5px; /* Reduced gap */
}

.light-bulb {
  width: 16px; /* Slightly smaller bulbs for 5 */
  height: 16px;
  background-color: #cdc1b4; /* Unlit color */
  border-radius: 50%;
  border: 1px solid #bbada0;
  transition: background-color 0.3s ease, box-shadow 0.3s ease;
  cursor: help; /* Indicate title attribute */
}

.light-bulb.lit {
  background-color: #f5e453; /* Lit color - yellow */
  box-shadow: 0 0 5px #f5e453, 0 0 8px #f5e453; /* Glow effect */
  border-color: #e8d54a;
}

.result-message {
  width: 100%;
  min-height: 1.5em; /* Prevent layout shift */
  font-size: clamp(0.9em, 3.5vw, 1.1em);
  font-weight: bold;
  color: #776e65;
  text-align: center;
  margin-bottom: 8px;
}

.grid-container {
  width: 100%;
  padding-bottom: 100%; /* Maintain aspect ratio 1:1 */
  position: relative;
  background-color: #bbada0;
  border-radius: 10px; /* Increased rounded corners for the main grid container */
  box-sizing: border-box;
  overflow: hidden; /* Important for tile positioning and animations */
}

.grid {
  position: absolute;
  top: 2.5%; /* Corresponds to gap percentage */
  left: 2.5%;
  width: 95%; /* (100% - 2.5%*2) */
  height: 95%;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 2.5%; /* Relative gap */
}

.grid-cell {
  background-color: #cdc1b4;
  border-radius: 8px; /* Increased rounded corners for individual cells */
}

.tile {
  position: absolute;
  /* width and height will be set by JS based on grid cell size */
  border-radius: 8px; /* Increased rounded corners for tiles */
  font-weight: bold;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: left 0.1s ease-out, top 0.1s ease-out, transform 0.1s ease-out;
  z-index: 2;
  box-sizing: border-box;
  overflow: hidden; /* Ensure content fits */
}

.tile-value {
  font-size: var(--tile-value-font-size, 1.8em); /* Default if var not set */
  line-height: 1;
}

.tile-life {
  font-size: var(--tile-life-font-size, 0.6em); /* Default if var not set */
  margin-top: 3px;
  line-height: 1;
}

/* Animations */
.tile-new {
  animation: appear 0.2s ease-out 0.05s backwards; /* Slight delay */
}
@keyframes appear {
  0% {
    transform: scale(0); /* Start from very small or invisible */
    opacity: 0;
  }
  60% {
    /* Quickly grow larger than final size */
    transform: scale(1.2);
    opacity: 1;
  }
  100% {
    /* Settle to normal size */
    transform: scale(1);
    opacity: 1;
  }
}

.tile-merged {
  animation: merge-pop 0.2s ease-out;
  z-index: 3;
}
@keyframes merge-pop {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.25);
  } /* Increased pop */
  100% {
    transform: scale(1);
  }
}

.tile-fragment-container {
  position: absolute;
  /* top, left, width, height set by JS */
  z-index: 1; /* Behind active tiles, but above grid cells */
  pointer-events: none; /* Don't interfere with input */
}

.tile-fragment {
  position: absolute;
  background-color: var(--tile-bg-color); /* Will be set by JS */
  border-radius: 4px; /* Smaller radius for fragments */
  transition: transform 0.5s cubic-bezier(0.19, 1, 0.22, 1), opacity 0.5s ease-out;
}

.instructions {
  margin-top: 10px; /* Reduced margin */
  font-size: clamp(0.75em, 2.8vw, 0.95em);
  text-align: center;
  color: #776e65;
}

/* Media query for very small screens if needed */
@media (max-width: 360px) {
  .title {
    font-size: 1.5em;
  }
  .score-container {
    padding: 3px 10px;
  }
  #new-game-button {
    padding: 6px 10px;
  }
  .difficulty-btn {
    padding: 5px 8px;
    font-size: 0.6em;
  }
  .light-bulb-row-container {
    font-size: 0.6em;
  }
  .light-bulb {
    width: 12px; /* Further reduced for 5 bulbs on small screens */
    height: 12px;
  }
}
