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

body {
  font-family: "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  position: relative;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: radial-gradient(
      circle at 20% 50%,
      rgba(120, 119, 198, 0.3) 0%,
      transparent 50%
    ),
    radial-gradient(
      circle at 80% 20%,
      rgba(255, 119, 198, 0.3) 0%,
      transparent 50%
    ),
    radial-gradient(
      circle at 40% 80%,
      rgba(120, 219, 255, 0.3) 0%,
      transparent 50%
    );
  pointer-events: none;
  z-index: -1;
}

.container {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px);
  border-radius: 2rem;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.15);
  padding: 2.5rem;
  max-width: 450px;
  width: 100%;
  position: relative;
  z-index: 1;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

h1 {
  text-align: center;
  font-size: 2.8rem;
  font-weight: 800;
  background: linear-gradient(135deg, #667eea, #764ba2);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 2rem;
  position: relative;
}

h1::after {
  content: "";
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  width: 60px;
  height: 4px;
  background: linear-gradient(135deg, #667eea, #764ba2);
  border-radius: 2px;
}

/* Fixed User Info Section */
.user-info {
  margin-bottom: 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  width: 100%;
  z-index: 10;
  position: relative;
}

/* Fixed Winner/Message Section */
.winner {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 60px;
  margin-bottom: 0;
}

.message {
  display: inline-block;
  font-size: 1.1rem;
  font-weight: 600;
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  color: white;
  padding: 0.8rem 1.5rem;
  border-radius: 2rem;
  box-shadow: 0 8px 20px rgba(240, 147, 251, 0.3);
  animation: pulse 2s infinite;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  transition: all 0.3s ease;
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
    box-shadow: 0 8px 20px rgba(240, 147, 251, 0.3);
  }
  50% {
    transform: scale(1.02);
    box-shadow: 0 10px 25px rgba(240, 147, 251, 0.4);
  }
}

/* Fixed User Mode Section */
.user-mode {
  display: flex;
  gap: 0.8rem;
  justify-content: center;
  align-items: center;
  width: 100%;
  flex-wrap: wrap;
}

.user-mode button {
  background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
  color: white;
  border: none;
  padding: 0.75rem 1.3rem;
  border-radius: 2rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  box-shadow: 0 6px 18px rgba(79, 172, 254, 0.3);
  position: relative;
  overflow: hidden;
  white-space: nowrap;
  flex: 1;
  min-width: 120px;
  max-width: 180px;
  z-index: 5;
}

.user-mode button::before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.2),
    transparent
  );
  transition: left 0.5s;
}

.user-mode button:hover::before {
  left: 100%;
}

.user-mode button:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 8px 22px rgba(79, 172, 254, 0.4);
}

.user-mode button:active {
  transform: translateY(0) scale(0.98);
}

.user-mode button.active {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  box-shadow: 0 6px 18px rgba(240, 147, 251, 0.4);
}

.user-mode button.active:hover {
  box-shadow: 0 8px 22px rgba(240, 147, 251, 0.5);
}

/* Fixed Current Player Section */
.current-player {
  background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
  color: #333;
  padding: 0.9rem 1.8rem;
  border-radius: 2rem;
  display: inline-block;
  font-size: 1.1rem;
  font-weight: 700;
  box-shadow: 0 6px 18px rgba(168, 237, 234, 0.3);
  animation: glow 2s ease-in-out infinite alternate;
  text-align: center;
  width: auto;
  max-width: 100%;
  z-index: 5;
  position: relative;
}

@keyframes glow {
  from {
    box-shadow: 0 6px 18px rgba(168, 237, 234, 0.3);
  }
  to {
    box-shadow: 0 8px 22px rgba(168, 237, 234, 0.5);
  }
}

.current-player span {
  color: #e74c3c;
  font-size: 1.2em;
  font-weight: 800;
}

/* Game Board - Ensure it doesn't overlap */
.game {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.8rem;
  margin-bottom: 2rem;
  padding: 1rem;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 1.5rem;
  box-shadow: inset 0 4px 8px rgba(0, 0, 0, 0.1);
  position: relative;
  z-index: 2;
}

.box {
  aspect-ratio: 1;
  background: white;
  border: none;
  border-radius: 1rem;
  font-size: 2.5rem;
  font-weight: 900;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.box::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, #667eea, #764ba2);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.box:hover::before {
  opacity: 0.05;
}

.box:hover {
  transform: scale(1.05) translateY(-2px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.box:active {
  transform: scale(0.95);
}

.box.x {
  color: #e74c3c;
  animation: popIn 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.box.o {
  color: #3498db;
  animation: popIn 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes popIn {
  0% {
    transform: scale(0) rotate(180deg);
    opacity: 0;
  }
  100% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
}

/* Control Buttons */
.control-btns {
  display: flex;
  gap: 1rem;
  margin-bottom: 2rem;
  flex-wrap: wrap;
  position: relative;
  z-index: 3;
}

.control-btns button {
  flex: 1;
  min-width: 140px;
  padding: 1rem 1.5rem;
  font-size: 1.1rem;
  font-weight: 600;
  color: white;
  border: none;
  border-radius: 2rem;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  position: relative;
  overflow: hidden;
}

#new-game {
  background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
  box-shadow: 0 8px 20px rgba(79, 172, 254, 0.3);
}

#clear-score {
  background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
  box-shadow: 0 8px 20px rgba(250, 112, 154, 0.3);
}

.control-btns button::before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.2),
    transparent
  );
  transition: left 0.5s;
}

.control-btns button:hover::before {
  left: 100%;
}

.control-btns button:hover {
  transform: translateY(-3px);
}

/* Score Board */
.score-board {
  background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
  padding: 1.5rem;
  border-radius: 1.5rem;
  color: #333;
  box-shadow: 0 8px 20px rgba(252, 182, 159, 0.3);
  position: relative;
  z-index: 2;
}

.score-board h3 {
  text-align: center;
  margin-bottom: 1rem;
  font-size: 1.5rem;
  font-weight: 700;
  background: linear-gradient(135deg, #667eea, #764ba2);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.score-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.8rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.3);
  font-weight: 600;
}

.score-item:last-child {
  border-bottom: none;
}

.score-item span:last-child {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  padding: 0.3rem 0.8rem;
  border-radius: 1rem;
  min-width: 30px;
  text-align: center;
  font-weight: 700;
}

/* Responsive Design - Fixed Mobile Issues */
@media (max-width: 480px) {
  .container {
    padding: 1.5rem;
    margin: 0.5rem;
    max-width: 95vw;
  }

  h1 {
    font-size: 2.2rem;
  }

  .user-info {
    gap: 0.8rem;
  }

  .winner {
    min-height: 50px;
  }

  .message {
    font-size: 0.95rem;
    padding: 0.6rem 1.2rem;
    max-width: 90%;
  }

  .user-mode {
    flex-direction: column;
    gap: 0.6rem;
    width: 100%;
  }

  .user-mode button {
    width: 100%;
    max-width: none;
    min-width: auto;
    padding: 0.7rem 1rem;
    font-size: 0.9rem;
  }

  .current-player {
    font-size: 1rem;
    padding: 0.8rem 1.5rem;
  }

  .box {
    font-size: 2rem;
  }

  .control-btns {
    flex-direction: column;
    gap: 0.8rem;
  }

  .control-btns button {
    width: 100%;
    min-width: auto;
  }
}

@media (max-width: 360px) {
  .container {
    padding: 1rem;
    margin: 0.3rem;
  }

  h1 {
    font-size: 1.8rem;
  }

  .message {
    font-size: 0.85rem;
    padding: 0.5rem 1rem;
  }

  .user-mode button {
    padding: 0.6rem 0.8rem;
    font-size: 0.85rem;
  }

  .current-player {
    font-size: 0.9rem;
    padding: 0.7rem 1.2rem;
  }

  .box {
    font-size: 1.5rem;
  }

  .game {
    gap: 0.5rem;
    padding: 0.8rem;
  }
}

/* Additional Fixes for UI Blocking */

/* Ensure proper stacking context */
.user-info > * {
  position: relative;
  z-index: auto;
}

/* Fix any potential overflow issues */
.winner,
.user-mode,
.current-player {
  overflow: visible;
}

/* Ensure buttons don't get cut off */
.user-mode button,
.control-btns button {
  min-height: 44px; /* Minimum touch target size */
}

/* Fix text wrapping on very small screens */
@media (max-width: 320px) {
  .message {
    white-space: normal;
    word-wrap: break-word;
  }

  .user-mode button {
    font-size: 0.8rem;
  }
}

/* Winning animation */
.box.winning {
  animation: winPulse 0.6s ease-in-out infinite alternate;
}

@keyframes winPulse {
  from {
    background: #fff;
    transform: scale(1);
  }
  to {
    background: #f1f8ff;
    transform: scale(1.1);
    box-shadow: 0 0 20px rgba(52, 152, 219, 0.5);
  }
}

/* Loading animation for game start */
.game.loading .box {
  animation: loadingPulse 1.5s ease-in-out infinite;
}

@keyframes loadingPulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.pattern-winner {
  background: red;
  color: #fff;
}

.ai-thinking {
  background-color: #ffeb3b; /* màu vàng nổi bật */
  animation: blink 1s infinite;
}

@keyframes blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}
