/* Reset and base styles */
* {
  box-sizing: border-box;
}

/* Base typography and layout styles */
html {
  font-size: 18px;
  line-height: 1.618;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
  font-weight: 400;
  color: #2c3e50;
  background-color: #f8f9fa;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Typography */
h1,
h2,
h3,
h4,
h5,
h6 {
  font-weight: 700;
  margin: 3rem 0 1.38rem;
  line-height: 1.3;
}

h1 {
  font-size: 2.488rem;
  color: #2c3e50;
}

h2 {
  font-size: 2.074rem;
}

h3 {
  font-size: 1.728rem;
}

p {
  margin-bottom: 1rem;
  color: #34495e;
  line-height: 1.6;
}

a {
  color: #3498db;
  text-decoration: none;
  transition: color 0.2s ease;
}

a:hover {
  color: #2980b9;
  text-decoration: underline;
}

/* Layout */

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 40px 20px;
  text-align: center;
}

h1 {
  margin: 0 0 3rem 0;
  font-size: 3rem;
  color: #2c3e50;
  font-weight: 300;
}

article {
  margin-bottom: 4rem;
}

article p {
  margin-bottom: 1.5rem;
  font-size: 1.1rem;
  max-width: 600px;
  margin-left: auto;
  margin-right: auto;
}

/* Apps grid layout */
.apps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 32px;
  margin-top: 4rem;
  justify-items: center;
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
}

/* App container - creates visual separation between apps */
.app-container {
  display: contents;
}

/* Card descriptions - hidden on desktop, visible on mobile */
.card-description {
  display: none;
  padding: 20px 24px;
  text-align: left;
  background: #ffffff;
  border-radius: 0 0 12px 12px;
  border-top: none;
}

.card-description h3 {
  font-size: 1.3rem;
  margin: 0 0 10px 0;
  color: #2c3e50;
  font-weight: 600;
}

.card-description p {
  font-size: 1rem;
  margin: 0;
  color: #6c757d;
  line-height: 1.5;
}

/* Mobile responsive */
@media (max-width: 768px) {
  .apps-grid {
    grid-template-columns: 1fr;
    gap: 0;
    margin-top: 3rem;
  }

  main {
    padding: 20px 15px;
  }

  h1 {
    font-size: 2.5rem;
    margin-bottom: 2rem;
  }

  article p {
    font-size: 1rem;
  }

  /* App containers on mobile */
  .app-container {
    display: block;
    margin-bottom: 40px;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
    overflow: hidden;
    width: 100%;
  }

  /* Show descriptions on mobile */
  .card-description {
    display: block;
  }

  /* Hide overlay on mobile since descriptions are shown below */
  .card-overlay {
    display: none;
  }

  /* Adjust card hover behavior for touch */
  .app-card:hover {
    transform: none;
    box-shadow: none;
  }

  .app-card:active {
    transform: scale(0.98);
    transition: transform 0.1s ease;
  }

  /* Make cards fit containers on mobile */
  .app-card {
    height: 180px;
    min-height: 180px;
    border-radius: 12px 12px 0 0;
    box-shadow: none;
    border: none;
  }
}

/* App card styles */
.app-card {
  position: relative;
  width: 100%;
  height: 220px;
  min-height: 220px;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
  display: block;
  text-decoration: none;
  color: inherit;
}

.app-card:hover {
  transform: translateY(-8px);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.15);
}

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

/* Touch-friendly active state */
.app-card:focus {
  outline: 2px solid #3498db;
  outline-offset: 2px;
}

/* Card background */
.card-background {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  z-index: 1;
  transition: transform 0.3s ease;
}

.app-card:hover .card-background {
  transform: scale(1.05);
}

/* Card foreground */
.card-foreground {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  transition: opacity 0.3s ease;
}

.foreground-image {
  max-width: 60%;
  max-height: 60%;
  object-fit: contain;
  transition: opacity 0.3s ease;
}

.foreground-image.error {
  display: none;
}

.fallback-text {
  position: absolute;
  font-size: 1.5rem;
  font-weight: bold;
  color: white;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.7);
  text-align: center;
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 3;
  background: rgba(0, 0, 0, 0.4);
  padding: 12px 20px;
  border-radius: 12px;
  backdrop-filter: blur(15px);
  font-weight: 500;
  font-size: 1.1rem;
  letter-spacing: 0.5px;
}

/* Show fallback text when image fails to load or doesn't exist */
.card-foreground:not(:has(.foreground-image)) .fallback-text,
.foreground-image.error+.fallback-text {
  opacity: 1;
}

/* Card overlay */
.card-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg,
      rgba(0, 0, 0, 0.8) 0%,
      rgba(0, 0, 0, 0.6) 50%,
      rgba(0, 0, 0, 0.8) 100%);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 20px;
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.3s ease;
  z-index: 4;
}

.app-card:hover .card-overlay {
  opacity: 1;
  transform: translateY(0);
}

.app-card:hover .card-overlay h2,
.app-card:hover .card-overlay p {
  transform: translateY(0);
}

.card-overlay h2 {
  color: white;
  font-size: 1.4rem;
  font-weight: 600;
  margin: 0 0 12px 0;
  text-align: center;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.7);
  transform: translateY(10px);
  transition: transform 0.3s ease;
}

.card-overlay p {
  color: rgba(255, 255, 255, 0.95);
  font-size: 0.95rem;
  margin: 0;
  text-align: center;
  line-height: 1.5;
  font-weight: 300;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
  transform: translateY(10px);
  transition: transform 0.3s ease;
}

/* Hide foreground on hover */
.app-card:hover .card-foreground {
  opacity: 0.3;
}

/* Loading states */
.app-card.loading .card-background {
  animation: pulse 2s infinite;
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.7;
  }
}

/* Additional mobile optimizations */
@media (max-width: 480px) {
  .apps-grid {
    gap: 0;
    margin-top: 2rem;
  }

  .app-container {
    margin-bottom: 32px;
  }

  .app-card {
    height: 160px;
    min-height: 160px;
  }

  .card-description {
    padding: 16px 20px 0 20px;
  }

  .card-description h3 {
    font-size: 1.2rem;
  }

  .card-description p {
    font-size: 0.9rem;
  }

  main {
    padding: 15px 10px 0 10px;
  }
}

/* Ensure links work properly */
.app-card {
  pointer-events: auto;
}

.app-card * {
  pointer-events: none;
}

/* Re-enable pointer events for interactive elements */
.app-card a,
.app-card button,
.app-card input,
.app-card select,
.app-card textarea {
  pointer-events: auto;
}

/* Additional fallback for browsers without :has() support */
@supports not selector(:has(*)) {
  .fallback-text {
    opacity: 1;
  }

  .foreground-image {
    position: relative;
    z-index: 1;
  }

  .foreground-image+.fallback-text {
    opacity: 0;
  }
}

/* Ensure cards are visible and properly sized */
.app-card {
  opacity: 1 !important;
  transform: translateY(0) !important;
  display: block !important;
  visibility: visible !important;
}

/* Fallback support for browsers without :has() */
@supports not selector(:has(*)) {
  .fallback-text {
    opacity: 1;
  }

  .card-foreground img+.fallback-text {
    opacity: 0;
  }
}

/* Add subtle gradient overlay for better text readability */
.card-background::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(45deg, rgba(0, 0, 0, 0.1) 0%, transparent 50%, rgba(0, 0, 0, 0.1) 100%);
  z-index: 1;
}
