:root {
  --primary-color: #ffffff;
  --primary-dark: #f8f9fa;
  --primary-light: #e9ecef;
  --accent-color: #27ae60;
  --text-color: #000000;
  --bg-light: #fafafa;
  --card-border: #e0e0e0;
  --region-bg: #f0f0f0;
}

body.dark-mode {
  --primary-color: #000000;
  --primary-dark: #111111;
  --primary-light: #1a1a1a;
  --accent-color: #2ecc71;
  --text-color: #ffffff;
  --bg-light: #000000;
  --card-border: #444444;
  --region-bg: #1a1a1a;
}

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

body {
  font-family: 'Tajawal', sans-serif;
  background: var(--bg-light);
  color: var(--text-color);
  min-height: 100vh;
  text-align: center;
  overflow-x: hidden;
  overflow-y: auto;
  transition: background-color 0.3s ease, color 0.3s ease;
}

.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 12px;
  position: relative;
  z-index: 1;
  overflow: visible;
}

.filter-modal {
  display: none;
  position: absolute;
  top: 100%;
  right: 20px;
  background: var(--primary-color);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  box-shadow: 0 5px 15px rgba(0,0,0,0.1);
  z-index: 1000;
  min-width: 180px;
}

.filter-modal.show {
  display: block;
}

.filter-modal-content {
  padding: 15px;
  position: relative;
}

.filter-modal-content h3 {
  margin-bottom: 10px;
  font-size: 14px;
  color: var(--text-color);
  border-bottom: 1px solid var(--card-border);
  padding-bottom: 8px;
}

.filter-option {
  display: block;
  width: 100%;
  padding: 8px 12px;
  margin-bottom: 5px;
  background: var(--primary-light);
  border: 1px solid var(--card-border);
  border-radius: 5px;
  color: var(--text-color);
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 13px;
  text-align: left;
}

.filter-option:hover {
  background: var(--accent-color);
  color: white;
  border-color: var(--accent-color);
}

.filter-close {
  position: absolute;
  top: 10px;
  right: 10px;
  background: none;
  border: none;
  color: #666;
  cursor: pointer;
  font-size: 14px;
  padding: 5px;
}

.filter-close:hover {
  color: var(--accent-color);
}

.featured-games-bar {
  width: 100%;
  background: var(--primary-dark);
  padding: 10px 0 12px;
  position: relative;
  overflow: visible;
  border-bottom: 1px solid var(--card-border);
  contain: layout paint style;
  z-index: 100;
}

.featured-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 12px;
  overflow: visible;
}

.featured-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.featured-title {
  font-size: 1.2rem;
  color: var(--accent-color);
  font-weight: 700;
  position: relative;
  display: inline-block;
}

.featured-title::after {
  content: '';
  position: absolute;
  bottom: -5px;
  right: 0;
  width: 50%;
  height: 2px;
  background: var(--accent-color);
  transition: width 0.3s ease;
}

.featured-games {
  display: flex;
  gap: 10px;
  overflow-x: visible;
  overflow-y: visible;
  padding: 7px 0;
  scroll-behavior: smooth;
  position: relative;
  isolation: isolate;
}

.featured-games-wrapper {
  display: flex;
  width: max-content;
  animation: scroll-featured 120s linear infinite;
}

.featured-games-wrapper::after {
  content: '';
  display: flex;
}

@keyframes scroll-featured {
  0% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(-50%);
  }
}

.featured-games:hover .featured-games-wrapper {
  animation-play-state: paused;
}

.featured-game {
  flex: 0 0 160px;
  background: var(--primary-color);
  border-radius: 7px;
  overflow: visible;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  transition: all 0.3s ease;
  cursor: pointer;
  border: 1px solid var(--card-border);
  text-align: center;
  padding: 10px;
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
  will-change: transform;
  backface-visibility: hidden;
  z-index: 1;
}

.featured-game:hover {
  transform: translateY(-8px) scale(1.05);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
  border-color: var(--accent-color);
  z-index: 10;
}

.featured-game img {
  width: 100%;
  height: 170px;
  object-fit: contain;
  border-radius: 4px;
  margin-bottom: 8px;
  flex-shrink: 0;
  display: block;
  transition: opacity 0.3s ease, transform 0.3s ease;
  position: relative;
  z-index: 1;
}

.featured-game:hover img {
  transform: scale(1.05);
}

.featured-game-content {
  padding: 0;
  text-align: center;
  flex-grow: 1;
  display: flex;
  flex-direction: column;
}

.featured-game-title {
  font-size: 12px;
  font-weight: bold;
  color: var(--text-color);
  line-height: 1.4;
  height: 34px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: auto;
}

.featured-game-platform {
  font-size: 0.7rem;
  color: var(--accent-color);
  font-weight: 600;
  background: var(--region-bg);
  padding: 2px 7px;
  border-radius: 10px;
  display: inline-block;
  margin-top: 7px;
}

.featured-game-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 7px;
  font-size: 11px;
  color: #666;
}

.featured-download-count {
  display: flex;
  align-items: center;
  gap: 3px;
}

.featured-rating {
  display: flex;
  align-items: center;
  gap: 2px;
}

.featured-rating i {
  color: #ffc107;
  font-size: 9px;
}

.featured-game img[data-game-id] {
  min-height: 170px;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: loading 1.5s infinite;
}

.featured-game img.loaded {
  background: none !important;
  animation: none !important;
}

@keyframes loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.platform-section {
  margin: 35px 0;
  width: 100%;
}

.platform-section:first-of-type {
  margin-top: 50px;
}

.platform-header {
  background: transparent;
  color: var(--text-color);
  padding: 12px 0;
  margin-bottom: 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px solid var(--card-border);
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
}

.platform-title {
  font-size: 1.3rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--text-color);
}

.view-all-btn {
  background: var(--accent-color);
  color: white;
  text-decoration: none;
  padding: 8px 16px;
  border-radius: 5px;
  font-size: 0.85rem;
  font-weight: 600;
  transition: all 0.3s ease;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.view-all-btn:hover {
  background: #219a52;
  transform: translateY(-1px);
  box-shadow: 0 3px 6px rgba(0,0,0,0.1);
}

.games-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  padding: 18px 12px;
  max-width: 1400px;
  margin: 0 auto;
  position: relative;
  z-index: 1;
}

.games-grid .game-card img {
  min-height: auto !important;
  background: none !important;
  animation: none !important;
}

.game-card {
  background: var(--primary-color);
  border: 1px solid var(--card-border);
  text-align: center;
  padding: 10px;
  border-radius: 5px;
  transition: all 0.2s ease;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: 100%;
  will-change: transform;
  backface-visibility: hidden;
  transform: translateZ(0);
}

.game-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(0,0,0,0.08);
  border-color: var(--accent-color);
}

.game-card img {
  width: 100%;
  height: 170px;
  object-fit: contain;
  border-radius: 3px;
  margin-bottom: 8px;
  flex-shrink: 0;
}

.game-card img.loaded {
  background: none !important;
  animation: none !important;
}

.game-title {
  color: var(--text-color);
  font-weight: bold;
  font-size: 12px;
  line-height: 1.4;
  height: 34px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: auto;
}

.game-translation {
  position: absolute;
  top: 7px;
  left: 7px;
  background: #28a745;
  color: white;
  font-size: 0.65rem;
  font-weight: bold;
  padding: 2px 5px;
  border-radius: 3px;
  z-index: 2;
}

.game-card.arabic-game::before {
  display: none;
}

.game-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 7px;
  font-size: 11px;
  color: #666;
}

.download-count {
  display: flex;
  align-items: center;
  gap: 3px;
}

.rating {
  display: flex;
  align-items: center;
  gap: 2px;
}

.rating i {
  color: #ffc107;
  font-size: 9px;
}

.new-game-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: linear-gradient(45deg, #ff4757, #ff3838);
  color: white;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 0.65rem;
  font-weight: bold;
  z-index: 2;
  box-shadow: 0 2px 4px rgba(255, 71, 87, 0.3);
  animation: pulse-small 2s infinite;
}

@keyframes pulse-small {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.comments-section {
  margin: 35px 0;
  width: 100%;
}

.comments-container-full {
  max-width: 1200px;
  margin: 0 auto;
  padding: 25px;
  background: var(--primary-color);
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.05);
  border: 1px solid var(--card-border);
}

.comments-title {
  font-size: 1.5rem;
  color: var(--accent-color);
  margin-bottom: 10px;
  font-weight: 700;
}

.comments-description {
  color: #666;
  margin-bottom: 20px;
  font-size: 0.9rem;
}

.footer {
  margin-top: 35px;
  padding: 25px 0;
  color: #666;
  font-size: 0.8rem;
  border-top: 1px solid var(--card-border);
  background: var(--primary-color);
  width: 100%;
}

.footer-social {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 10px;
}

.footer-social a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--accent-color);
  font-size: 0.9rem;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.footer-social a::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--accent-color);
  border-radius: 50%;
  transform: scale(0);
  transition: transform 0.3s ease;
}

.footer-social a:hover::before {
  transform: scale(1);
}

.footer-social a i {
  position: relative;
  z-index: 1;
}

.footer-social a:hover i {
  color: white;
}

.footer-social a:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.footer-links {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 8px;
}

.footer-links a {
  color: var(--accent-color);
  text-decoration: none;
  transition: all 0.2s ease;
  font-weight: 500;
  font-size: 0.8rem;
  position: relative;
}

.footer-links a::after {
  content: '';
  position: absolute;
  bottom: -2px;
  right: 0;
  width: 0;
  height: 1px;
  background: var(--accent-color);
  transition: width 0.3s ease;
}

.footer-links a:hover::after {
  width: 100%;
}

.site-header {
  position: relative;
  z-index: 99;
}

@media (max-width: 768px) {
  .games-grid {
    grid-template-columns: repeat(2, 1fr);
    padding: 12px 10px;
    gap: 10px;
  }
  
  .game-card img {
    height: 150px;
  }
  
  .game-info {
    font-size: 10px;
  }
  
  .footer-links {
    gap: 8px;
  }

  .featured-game:hover {
    transform: translateY(-5px) scale(1.03);
  }
  
  .platform-section:first-of-type {
    margin-top: 35px;
  }
}

@media (max-width: 480px) {
  .games-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
  
  .game-card img {
    height: 140px;
  }
  
  .game-title {
    font-size: 11px;
  }
  
  .header-top-links {
    gap: 8px;
    font-size: 10px;
  }
  
  .category-nav .nav-link {
    padding: 6px 10px;
    font-size: 0.7rem;
  }
  
  .search-input-header {
    width: 120px;
    font-size: 12px;
  }
}

@media (min-width: 768px) {
  .games-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (min-width: 1024px) {
  .container { 
    max-width: 100%; 
  }
  
  .games-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}

.game-card,
.featured-game {
  transform: translateZ(0);
  backface-visibility: hidden;
}

img[loading="lazy"] {
  opacity: 0;
  transition: opacity 0.3s ease;
}

img[loading="lazy"].loaded {
  opacity: 1;
}