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

body {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: radial-gradient(
      circle at 20% 80%,
      rgba(120, 119, 198, 0.3) 0%,
      transparent 50%
    ),
    radial-gradient(
      circle at 80% 20%,
      rgba(255, 255, 255, 0.1) 0%,
      transparent 50%
    ),
    radial-gradient(
      circle at 40% 40%,
      rgba(120, 119, 198, 0.2) 0%,
      transparent 50%
    );
  animation: float 20s ease-in-out infinite;
  pointer-events: none;
  z-index: -1;
}

@keyframes float {
  0%,
  100% {
    transform: translateY(0px) rotate(0deg);
  }
  33% {
    transform: translateY(-20px) rotate(1deg);
  }
  66% {
    transform: translateY(10px) rotate(-1deg);
  }
}

.intro {
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  padding: 2rem;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

.intro h1 {
  color: white;
  font-size: clamp(2rem, 5vw, 3.5rem);
  font-weight: 700;
  text-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  letter-spacing: -0.02em;
  margin: 0;
  animation: slideDown 0.8s ease-out;
}

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

.container {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 2rem;
  gap: 3rem;
  animation: fadeIn 1s ease-out 0.3s both;
}

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

.game {
  height: min(70vmin, 450px);
  width: min(70vmin, 450px);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 12px;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(20px);
  padding: 20px;
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
  position: relative;
  animation: scaleIn 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) 0.5s both;
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.box {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  border: none;
  border-radius: 16px;
  font-size: clamp(2.5rem, 8vmin, 4rem);
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

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

.box:hover::before {
  left: 100%;
}

.box:hover {
  transform: translateY(-4px) scale(1.02);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
  background: rgba(255, 255, 255, 0.95);
}

.box:active {
  transform: translateY(-2px) scale(0.98);
}

.box:disabled {
  cursor: not-allowed;
  opacity: 0.8;
}

.box:not(:empty) {
  animation: popIn 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

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

.box:contains("X") {
  color: #e74c3c;
  text-shadow: 0 2px 10px rgba(231, 76, 60, 0.3);
}

.box:contains("O") {
  color: #3498db;
  text-shadow: 0 2px 10px rgba(52, 152, 219, 0.3);
}

.reset,
.newgame {
  padding: 1rem 2.5rem;
  border: none;
  border-radius: 50px;
  font-size: clamp(1rem, 3vw, 1.2rem);
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  position: relative;
  overflow: hidden;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.reset {
  background: linear-gradient(135deg, #ff6b6b, #ee5a52);
  color: white;
  box-shadow: 0 6px 20px rgba(238, 90, 82, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.reset:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 30px rgba(238, 90, 82, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
  background: linear-gradient(135deg, #ff7979, #ff6b6b);
}

.newgame {
  background: linear-gradient(135deg, #4ecdc4, #44a08d);
  color: white;
  box-shadow: 0 6px 20px rgba(68, 160, 141, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
  margin-top: 1.5rem;
}

.newgame:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 30px rgba(68, 160, 141, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
  background: linear-gradient(135deg, #5dded6, #4ecdc4);
}

.reset:active,
.newgame:active {
  transform: translateY(-1px);
}

.msg-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  animation: fadeInOverlay 0.3s ease-out;
}

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

.winner {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  padding: 3rem 4rem;
  border-radius: 24px;
  font-size: clamp(1.5rem, 4vw, 2.5rem);
  font-weight: 700;
  text-align: center;
  max-width: 90%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.2);
  animation: bounceIn 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

@keyframes bounceIn {
  0% {
    opacity: 0;
    transform: scale(0.3);
  }
  50% {
    transform: scale(1.05);
  }
  70% {
    transform: scale(0.9);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

.hide {
  display: none !important;
}

@media (max-width: 768px) {
   body {
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
  }
  .container {
    padding: 1rem;
    gap: 2rem;
  }

  .game {
    gap: 8px;
    padding: 15px;
  }

  .intro {
    padding: 1.5rem;
  }

  .winner {
    padding: 2rem 2.5rem;
    margin: 1rem;
  }
}

@media (max-width: 480px) {
   body {
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
  }
  .container {
    gap: 1.5rem;
  }

  .game {
    gap: 6px;
    padding: 12px;
  }

  .reset,
  .newgame {
    padding: 0.8rem 2rem;
    font-size: 1rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  body::before {
    animation: none;
  }
}

.box:focus,
.reset:focus,
.newgame:focus {
  outline: 3px solid #ffd700;
  outline-offset: 3px;
  box-shadow: 0 0 0 6px rgba(255, 215, 0, 0.3), 0 8px 25px rgba(0, 0, 0, 0.15);
}

@media (prefers-contrast: high) {
  .box {
    border: 2px solid #000;
  }

  .winner {
    border: 3px solid #fff;
  }
}

@media (prefers-color-scheme: dark) {
  body {
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
  }

  .intro h1 {
    color: #ecf0f1;
  }

  .box {
    background: rgba(52, 73, 94, 0.9);
    color: #ecf0f1;
  }

  .box:hover {
    background: rgba(52, 73, 94, 0.95);
  }
}
