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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
  background: rgb(26 26 26);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.game-container {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
}

.game-header {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
  max-width: 280px;
  margin-left: auto;
  margin-right: auto;
}

.flag-button {
  width: 100%;
  background: linear-gradient(145deg, #ff9999, #ff7777);
  border: none;
  border-radius: 16px;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
  border: 2px solid rgba(255, 255, 255, 0.8);
}

.flag-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

.flag-button:active {
  transform: translateY(0);
}

.flag-button.active {
  background: linear-gradient(145deg, #81c784, #66bb6a);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
}

.flag-icon {
  font-size: 32px;
  line-height: 1;
}

.flag-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: flex-start;
}

.flag-label {
  font-size: 12px;
  font-weight: 600;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.flag-status {
  font-size: 28px;
  font-weight: bold;
  color: #d32f2f;
  line-height: 1;
}

.flag-button.active .flag-status {
  color: #2e7d32;
}

.game-over-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.overlay-content {
  background: linear-gradient(145deg, #ffffff, #f5f5f5);
  border-radius: 24px;
  padding: 40px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  border: 3px solid rgba(255, 255, 255, 0.8);
  max-width: 90%;
  width: 400px;
  animation: slideUp 0.4s ease;
}

@keyframes slideUp {
  from {
    transform: translateY(30px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.overlay-icon {
  font-size: 80px;
  margin-bottom: 20px;
  animation: bounce 0.6s ease;
}

@keyframes bounce {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.2);
  }
}

.overlay-title {
  font-size: 32px;
  font-weight: bold;
  color: #d32f2f;
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.overlay-message {
  font-size: 18px;
  color: #666;
  margin-bottom: 30px;
  font-weight: 500;
}

.restart-button {
  background: linear-gradient(145deg, #64b5f6, #42a5f5);
  border: none;
  border-radius: 16px;
  padding: 18px 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
  border: 2px solid rgba(255, 255, 255, 0.8);
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.restart-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(66, 165, 245, 0.4);
  background: linear-gradient(145deg, #42a5f5, #2196f3);
}

.restart-button:active {
  transform: translateY(0);
}

.restart-icon {
  font-size: 24px;
  line-height: 1;
}

.restart-label {
  font-size: 16px;
  font-weight: 600;
}

#board {
  width: 100%;
  max-width: 480px;
  aspect-ratio: 1;
  background: linear-gradient(145deg, #ffffff, #f5f5f5);
  border-radius: 20px;
  padding: 12px;
  display: flex;
  flex-wrap: wrap;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  border: 3px solid rgba(255, 255, 255, 0.8);
}

#board div {
  width: 12.5%;
  height: 12.5%;
  border: 0.5px solid rgba(200, 200, 200, 0.4);
  margin: -0.5px;
  font-size: clamp(20px, 5vw, 28px);
  display: flex;
  justify-content: center;
  align-items: center;
  background: linear-gradient(145deg, #e8e8e8, #f5f5f5);
  cursor: pointer;
  transition: all 0.15s ease;
  font-weight: bold;
  user-select: none;
}

#board div:hover {
  background: linear-gradient(145deg, #d0d0d0, #e0e0e0);
}

.tile-clicked {
  background: linear-gradient(145deg, #ffffff, #e6e6e6) !important;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

.x1 {
  color: #2196f3;
}

.x2 {
  color: #4caf50;
}

.x3 {
  color: #f44336;
}

.x4 {
  color: #3f51b5;
}

.x5 {
  color: #8b4513;
}

.x6 {
  color: #00bcd4;
}

.x7 {
  color: #212121;
}

.x8 {
  color: #757575;
}

/* Mobile optimization */
@media (max-width: 480px) {
  body {
    padding: 10px;
  }

  .game-header {
    margin-bottom: 16px;
  }

  .flag-button {
    padding: 12px 16px;
  }

  .restart-button {
    padding: 16px 32px;
  }

  .overlay-content {
    padding: 30px 20px;
  }

  .overlay-icon {
    font-size: 60px;
  }

  .overlay-title {
    font-size: 26px;
  }

  .overlay-message {
    font-size: 16px;
  }

  .flag-icon {
    font-size: 28px;
  }

  .flag-status {
    font-size: 24px;
  }

  .flag-label {
    font-size: 10px;
  }

  #board {
    padding: 8px;
    border-radius: 16px;
  }

  #board div {
    font-size: clamp(18px, 4.5vw, 24px);
  }
}