.category-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  row-gap: 60px;
  column-gap: 60px; /* Increased from 40px to 60px for more horizontal spacing */
  max-width: 1200px;
  margin: 80px auto;
  padding: 0 20px; /* Added padding to prevent cards from touching container edges */
  justify-content: center;
  box-sizing: border-box; /* Ensure padding doesn't affect grid width */
}

.category-card {
  perspective: 1000px;
  height: 600px; /* Kept taller height */
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  width: 100%;
  max-width: calc(100% - 10px); /* Slightly reduce width to prevent edge overlap */
  margin: 0 auto;
  box-sizing: border-box; /* Ensure padding/borders are included in width */
}

.category-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 6px 12px rgba(0,0,0,0.08); /* Reduced shadow size to minimize overlap */
}

.category-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, #0066cc, #004999);
  border-radius: 10px 10px 0 0;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.category-card:hover::before {
  opacity: 1;
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  text-align: center;
  transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  transform-style: preserve-3d;
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
  border-radius: 10px;
  background: white;
}

.category-card.flipped .card-inner {
  transform: rotateY(180deg);
}

.card-front, .card-back {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: white;
  border-radius: 10px;
  -webkit-backface-visibility: hidden;
  box-sizing: border-box; /* Ensure padding is included in width */
}

.card-front {
  background: linear-gradient(135deg, #ffffff 0%, #e3f2fd 100%);
  border: 1px solid #e3f2fd;
}

.card-back {
  transform: rotateY(180deg);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #0066cc #f0f0f0;
  background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
  border: 1px solid #90caf9;
  padding: 2.5rem 3rem 2rem 3rem; /* Reduced bottom padding */
}

.card-back::-webkit-scrollbar {
  width: 8px;
}

.card-back::-webkit-scrollbar-track {
  background: #f0f0f0;
  border-radius: 4px;
}

.card-back::-webkit-scrollbar-thumb {
  background: #0066cc;
  border-radius: 4px;
}

.card-front h2, .card-back h3 {
  margin-bottom: 1rem;
  color: #1a237e;
  font-size: 1.5rem;
  line-height: 1.3;
  font-weight: 600;
}

.card-front p {
  color: #283593;
  line-height: 1.5;
  margin: 0;
  font-size: 1.1rem;
}

.article-list {
  list-style: none;
  padding: 0;
  margin: 0 0 0.75rem 0;
  text-align: left;
  width: 100%;
  max-height: 400px;
  overflow-y: auto;
}

.article-list li {
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid rgba(25, 118, 210, 0.15);
  transition: transform 0.2s ease;
}

.article-list li:hover {
  transform: translateX(5px);
}

.article-list li:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.article-list a {
  color: #1565c0;
  text-decoration: none;
  transition: all 0.2s ease;
  display: block;
  padding: 0.25rem 0;
  font-weight: 500;
}

.article-list a:hover {
  color: #0d47a1;
  text-decoration: none;
}

.view-all {
  display: inline-block;
  padding: 0.5rem 1rem;
  background: linear-gradient(135deg, #1976d2 0%, #0d47a1 100%);
  color: white;
  text-decoration: none;
  border-radius: 5px;
  margin-top: 0.75rem;
  margin-bottom: 0; /* Ensure no bottom margin */
  transition: all 0.3s ease;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-size: 0.9rem;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.view-all:hover {
  background: linear-gradient(135deg, #1565c0 0%, #0a3d91 100%);
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}

.view-all:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(0,102,204,0.3);
}

/* Focus styles for accessibility */
.category-card:focus-within {
  outline: none;
  box-shadow: 0 0 0 3px rgba(0,102,204,0.3);
}

/* Loading state */
.category-card.loading .card-inner {
  opacity: 0.7;
  pointer-events: none;
}

/* Article count badge */
.article-count {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: linear-gradient(135deg, #1976d2 0%, #0d47a1 100%);
  color: white;
  padding: 0.25rem 0.75rem;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 600;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* Featured article highlight */
.article-list li.featured {
  background: rgba(25, 118, 210, 0.1);
  padding: 0.75rem;
  border-radius: 4px;
  margin: 0.75rem 0;
  border: 1px solid rgba(25, 118, 210, 0.2);
  border-bottom: none;
}

.article-list li.featured:last-child {
  margin-bottom: 0;
}

.article-list li.featured::before {
  content: 'Featured';
  display: inline-block;
  background: linear-gradient(135deg, #1976d2 0%, #0d47a1 100%);
  color: white;
  padding: 0.1rem 0.5rem;
  border-radius: 3px;
  font-size: 0.7rem;
  margin-right: 0.5rem;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

a {
  text-decoration: none;
  background-image: none;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .category-grid {
    grid-template-columns: 1fr;
    row-gap: 30px;
    margin: 40px auto;
    padding: 0 15px; /* Added padding for mobile */
    max-width: 400px;
  }
  
  .category-card {
    height: 550px; /* Kept taller height */
    max-width: 100%; /* Reset to 100% for mobile single-column layout */
  }
  
  .card-front h2, .card-back h3 {
    font-size: 1.25rem;
  }
  
  .card-front, .card-back {
    padding: 2.5rem;
  }

  .view-all {
    width: 100%;
    text-align: center;
    margin-top: 1rem;
  }
}