body {
  font-family: Arial, sans-serif;
  background-color: #f0f0f0;
  margin: 0;
  padding: 20px;
  box-sizing: border-box;
}

.periodic-table {
  display: grid;
  grid-template-columns: repeat(18, 1fr); /* Default desktop view */
  gap: 2px;
  background-color: #fff;
  border: 1px solid #ccc;
  border-radius: 5px;
  width: 100%;         /* Ensures full-width display */
  max-width: 100vw;    /* Prevents horizontal scroll */
  margin: 0 auto;
}

.element {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background-color: #ffffff;
  border: 1px solid #ccc;
  padding: 8px;
  transition: transform 0.3s ease;
  min-height: 80px;
  box-sizing: border-box;
}

.element:hover {
  transform: scale(1.05);
}

.atomic-number {
  font-weight: bold;
  font-size: 0.9em;
  color: #333;
}

.symbol {
  font-size: 1.6em;
  color: #007bff;
}

.name,
.atomic-mass {
  font-size: 0.75em;
  color: #555;
}

/* === Category Background Colors === */
.category-alkali-metal {
  background-color: #ffcc80;
}

.category-alkaline-earth-metal {
  background-color: #ffd180;
}

.category-transition-metal {
  background-color: #b2dfdb;
}

.category-post-transition-metal {
  background-color: #ffab91;
}

.category-metalloid {
  background-color: #c8e6c9;
}

.category-nonmetal {
  background-color: #bbdefb;
}

.category-halogen {
  background-color: #ffccbc;
}

.category-noble-gas {
  background-color: #ffe082;
}

/* === Custom hover colors for specific elements === */
.element.h:hover {
  background-color: #f06292;
}

.element.he:hover {
  background-color: #81d4fa;
}

.element.o:hover {
  background-color: #f48fb1;
}

.element.c:hover {
  background-color: #a5d6a7;
}

.element.pt:hover {
  background-color: #ffcc80;
}

/* === Responsive Design === */
@media (max-width: 1024px) {
  .periodic-table {
    grid-template-columns: repeat(12, 1fr); /* Tablet view */
  }
}

@media (max-width: 768px) {
  .periodic-table {
    grid-template-columns: repeat(6, 1fr); /* Mobile landscape */
  }

  .symbol {
    font-size: 1.4em;
  }

  .element {
    min-height: 60px;
  }
}

@media (max-width: 480px) {
  .periodic-table {
    grid-template-columns: repeat(3, 1fr); /* Mobile portrait */
  }

  .symbol {
    font-size: 1.2em;
  }

  .element {
    padding: 5px;
  }
}
