*, *::after, *::before {
  box-sizing: border-box;
}

:root {
  --cell-size: 100px;
  --mark-size: calc(var(--cell-size) * 0.9);
  --primary-color: #d2691e; /* chocolate */
  --secondary-color: #f4a261; /* warm orange */
  --background-gradient: linear-gradient(135deg, #fefcea, #f1daaa);
  --cell-bg: #fff8f0;
  --cell-hover-bg: #f4e1c1;
  --mark-x-color: #a0522d; /* sienna */
  --mark-o-color: #e76f51; /* coral */
  --shadow-color: rgba(160, 82, 45, 0.5);
  --font-family-header: 'Comic Sans MS', cursive, sans-serif;
  --font-family-body: 'Comic Sans MS', cursive, sans-serif;
}

body {
  margin: 0;
  background: var(--background-gradient);
  font-family: var(--font-family-body);
  color: white;
  overflow-x: hidden;
}

.floating-header {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
  color: white;
  padding: 20px 40px;
  font-size: 3rem;
  font-weight: 900;
  letter-spacing: 5px;
  border-radius: 0 0 20px 20px;
  box-shadow: 0 6px 20px var(--shadow-color);
  z-index: 1000;
  font-family: var(--font-family-header);
  text-transform: uppercase;
  user-select: none;
  text-shadow: 0 0 10px rgba(255,255,255,0.3);
}

.board {
  width: 100vw;
  height: 100vh;
  display: grid;
  justify-content: center;
  align-content: center;
  justify-items: center;
  align-items: center;
  grid-template-columns: repeat(3, var(--cell-size));
  grid-template-rows: repeat(3, var(--cell-size));
  gap: 10px;
  padding-top: 100px;
  box-shadow: 0 0 30px rgba(255, 255, 255, 0.1);
  background: transparent;
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  background-color: var(--cell-bg);
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  cursor: pointer;
  border-radius: 15px;
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.1);
  transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

.cell:hover:not(.x):not(.circle) {
  background-color: var(--cell-hover-bg);
  box-shadow: 0 0 15px var(--primary-color);
}

.cell.x,
.cell.circle {
  cursor: not-allowed;
}

.cell.x::before,
.cell.x::after,
.cell.circle::before {
  background-color: rgba(255, 255, 255, 0.15);
  transition: background-color 0.3s ease;
}

.board.x .cell:not(.x):not(.circle):hover::before,
.board.x .cell:not(.x):not(.circle):hover::after,
.board.circle .cell:not(.x):not(.circle):hover::before {
  background-color: rgba(255, 255, 255, 0.3);
}

.cell.x::before,
.cell.x::after,
.board.x .cell:not(.x):not(.circle):hover::before,
.board.x .cell:not(.x):not(.circle):hover::after {
  content: 'X';
  position: absolute;
  width: 100%;
  height: 100%;
  font-size: calc(var(--mark-size) * 0.9);
  font-weight: 900;
  color: var(--mark-x-color);
  text-shadow: 0 0 10px var(--mark-x-color);
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 5px;
  animation: mark-appear 0.5s ease forwards;
  user-select: none;
}

.cell.x::before,
.board.x .cell:not(.x):not(.circle):hover::before {
  transform: none;
}

.cell.x::after,
.board.x .cell:not(.x):not(.circle):hover::after {
  display: none;
}

.cell.circle::before,
.cell.circle::after,
.board.circle .cell:not(.x):not(.circle):hover::before,
.board.circle .cell:not(.x):not(.circle):hover::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  box-shadow: 0 0 10px var(--mark-o-color);
  animation: mark-appear 0.5s ease forwards;
}

.cell.circle::before,
.board.circle .cell:not(.x):not(.circle):hover::before {
  width: var(--mark-size);
  height: var(--mark-size);
  border: 4px solid var(--mark-o-color);
  background-color: transparent;
}

.cell.circle::after,
.board.circle .cell:not(.x):not(.circle):hover::after {
  width: calc(var(--mark-size) * 0.7);
  height: calc(var(--mark-size) * 0.7);
  background-color: var(--cell-bg);
}

@keyframes mark-appear {
  from {
    opacity: 0;
    transform: scale(0.5);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.winMessage {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(26, 26, 26, 0.95);
  backdrop-filter: blur(8px);
  justify-content: center;
  align-items: center;
  color: var(--secondary-color);
  font-size: 5rem;
  flex-direction: column;
  font-family: var(--font-family-header);
  text-shadow: 0 0 15px var(--secondary-color);
  animation: fadeIn 0.5s ease forwards;
  z-index: 2000;
}

.winMessage.show {
  display: flex;
}

.winMessage button {
  font-size: 2.5rem;
  font-family: var(--font-family-body);
  background: var(--primary-color);
  border: none;
  padding: 15px 40px;
  cursor: pointer;
  border-radius: 30px;
  margin-top: 30px;
  color: white;
  font-weight: 700;
  box-shadow: 0 0 15px var(--primary-color);
  transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

.winMessage button:hover {
  background: var(--secondary-color);
  box-shadow: 0 0 20px var(--secondary-color);
}

#muteToggle {
  position: fixed;
  top: 20px;
  right: 20px;
  font-size: 1.8rem;
  padding: 12px 18px;
  background: var(--primary-color);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  color: white;
  box-shadow: 0 0 15px var(--primary-color);
  transition: background-color 0.3s ease, box-shadow 0.3s ease;
  user-select: none;
}

#muteToggle:hover {
  background: var(--secondary-color);
  box-shadow: 0 0 20px var(--secondary-color);
}

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

/* Responsive Design for Tablet, Phone, and Laptop */
@media (max-width: 900px) {
  .floating-header {
    font-size: 2.2rem;
    padding: 14px 20px;
  }
  .board {
    --cell-size: 70px;
    padding-top: 70px;
    gap: 7px;
  }
  .winMessage {
    font-size: 3rem;
  }
  .winMessage button {
    font-size: 1.5rem;
    padding: 10px 25px;
  }
}

@media (max-width: 600px) {
  .floating-header {
    font-size: 1.2rem;
    padding: 8px 10px;
    border-radius: 0 0 10px 10px;
  }
  .board {
    --cell-size: 40px;
    padding-top: 40px;
    gap: 4px;
  }
  .winMessage {
    font-size: 1.5rem;
    padding: 10px;
  }
  .winMessage button {
    font-size: 1rem;
    padding: 6px 12px;
    margin-top: 15px;
    border-radius: 15px;
  }
  #muteToggle {
    position: static;
    display: block;
    margin: 12px auto 0 auto;
    font-size: 1rem;
    padding: 6px 10px;
    border-radius: 8px;
    width: fit-content;
    box-shadow: 0 0 10px var(--primary-color);
  }
}
