/* Age Group Cards */
.age-group-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: var(--space-4);
}

.age-card {
  background: var(--color-linen);
  border: 2px solid var(--color-stone);
  border-radius: var(--radius-xl);
  padding: var(--space-5);
  text-align: center;
  cursor: pointer;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

@media (hover: hover) {
  .age-card:hover {
    border-color: var(--color-sage);
    background: rgba(168, 181, 160, 0.03);
    box-shadow: 
      0 12px 24px -6px rgba(168, 181, 160, 0.12),
      0 4px 12px rgba(0, 0, 0, 0.06);
    transform: translateY(-4px) scale(1.01);
  }
}

.age-card.selected {
  border-color: var(--color-sage);
  background: rgba(168, 181, 160, 0.08);
  transform: translateY(-2px) scale(1.02);
  box-shadow: 
    0 16px 32px -8px rgba(168, 181, 160, 0.15),
    0 6px 16px rgba(168, 181, 160, 0.1),
    0 0 0 2px rgba(168, 181, 160, 0.1);
}

.age-icon {
  font-size: var(--text-4xl);
  margin-bottom: var(--space-4);
}

.age-card h4 {
  font-size: var(--text-lg);
  margin-bottom: var(--space-2);
}

.age-card p {
  font-size: var(--text-sm);
  color: var(--color-gray-warm);
}

/* Character Cards */
.character-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-4);
  justify-items: center;
  max-width: 900px;
  margin: 0 auto;
}

.character-card {
  position: relative;
  width: 100%;
  max-width: 420px;
  height: 240px;
  border-radius: var(--radius-2xl);
  cursor: pointer;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
  box-shadow: 
    0 8px 32px -8px rgba(0, 0, 0, 0.12),
    0 4px 16px -4px rgba(0, 0, 0, 0.08);
}

/* Character background image */
.character-background {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-color: var(--color-sage);
  background-image: linear-gradient(135deg, 
    var(--color-sage) 0%, 
    var(--color-dusty-rose) 100%);
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Character overlay for text content */
.character-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    to top,
    rgba(0, 0, 0, 0.8) 0%,
    rgba(0, 0, 0, 0.5) 30%,
    rgba(0, 0, 0, 0.2) 60%,
    transparent 100%
  );
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: var(--space-4);
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Character content container */
.character-content {
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(12px) saturate(1.2);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-xl);
  padding: var(--space-3);
  box-shadow: 
    0 8px 24px -4px rgba(0, 0, 0, 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

/* Character header with name and badge */
.character-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--space-2);
}

/* Character name styling */
.character-name {
  color: white;
  font-size: var(--text-xl);
  font-weight: 700;
  margin: 0;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  line-height: 1.2;
}

/* Character subtitle */
.character-subtitle {
  color: rgba(255, 255, 255, 0.9);
  font-size: var(--text-sm);
  font-weight: 500;
  font-style: italic;
  margin-bottom: var(--space-2);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

/* Character description */
.character-description {
  color: rgba(255, 255, 255, 0.85);
  font-size: var(--text-xs);
  line-height: 1.4;
  margin: 0;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

/* Desktop-only hover effects */
@media (hover: hover) {
  .character-card:hover {
    transform: translateY(-4px) scale(1.02);
    box-shadow: 
      0 16px 48px -8px rgba(0, 0, 0, 0.2),
      0 8px 24px -4px rgba(0, 0, 0, 0.12),
      0 0 0 2px rgba(168, 181, 160, 0.3);
  }

  .character-card:hover .character-background {
    transform: scale(1.05);
    filter: brightness(1.1) contrast(1.05);
  }

  .character-card:hover .character-overlay {
    background: linear-gradient(
      to top,
      rgba(0, 0, 0, 0.9) 0%,
      rgba(0, 0, 0, 0.6) 30%,
      rgba(0, 0, 0, 0.3) 60%,
      transparent 100%
    );
  }
}

/* Selected state */
.character-card.selected {
  transform: translateY(-6px) scale(1.03);
  box-shadow: 
    0 20px 60px -8px rgba(168, 181, 160, 0.25),
    0 12px 32px -4px rgba(168, 181, 160, 0.15),
    0 0 0 3px rgba(168, 181, 160, 0.4);
}

.character-card.selected .character-background {
  transform: scale(1.08);
  filter: brightness(1.15) contrast(1.1);
}

.character-card.selected .character-content {
  background: rgba(168, 181, 160, 0.2);
  border-color: rgba(168, 181, 160, 0.4);
  box-shadow: 
    0 12px 32px -4px rgba(168, 181, 160, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

/* Dim non-selected cards once a selection is made */
.character-cards.has-selection .character-card:not(.selected) {
  filter: grayscale(0.9) saturate(0.7) brightness(0.92);
  opacity: 0.65;
  transform: none !important;
  box-shadow: 0 6px 16px -6px rgba(0, 0, 0, 0.08);
  transition: filter 0.25s ease, opacity 0.25s ease, transform 0.25s ease, box-shadow 0.25s ease;
}

@media (hover: hover) {
  .character-cards.has-selection .character-card:not(.selected):hover {
    opacity: 0.8;
    filter: grayscale(0.6) saturate(0.85) brightness(0.96);
    transform: translateY(-2px);
    box-shadow: 0 10px 24px -8px rgba(0, 0, 0, 0.12);
  }
}

.character-card.premium-only {
  border: 2px dashed rgba(165, 196, 212, 0.6);
}

.character-card.premium-only .character-overlay {
  background: linear-gradient(
    135deg,
    rgba(165, 196, 212, 0.2) 0%,
    rgba(165, 196, 212, 0.4) 40%,
    rgba(165, 196, 212, 0.7) 100%
  );
}

.character-card.coming-soon {
  opacity: 0.7;
  pointer-events: none;
  filter: grayscale(0.4);
  border: 2px dashed rgba(155, 150, 137, 0.6);
}

.character-card.coming-soon .character-background {
  filter: grayscale(0.6) brightness(0.8);
}

.character-card.coming-soon .character-overlay {
  background: linear-gradient(
    135deg,
    rgba(155, 150, 137, 0.3) 0%,
    rgba(155, 150, 137, 0.5) 40%,
    rgba(155, 150, 137, 0.8) 100%
  );
}

.character-card.coming-soon::after {
  content: 'Coming Soon';
  position: absolute;
  top: var(--space-4);
  right: var(--space-4);
  background: var(--color-gray-soft);
  color: white;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-xs);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  z-index: 10;
}

/* Character emoji fallback when no image */
.character-emoji {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 80px;
  z-index: 1;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.2));
}

.tier-badge {
  display: inline-block;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  backdrop-filter: blur(8px) saturate(1.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  flex-shrink: 0;
}

.tier-badge.free {
  background: rgba(168, 181, 160, 0.8);
  color: white;
}

.tier-badge.premium {
  background: rgba(165, 196, 212, 0.8);
  color: white;
}

.stat-card {
  background: var(--color-linen);
  border: 1px solid var(--color-stone);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

/* Universal Story Card Design - Image-based */
.story-card, .library-story-card {
  position: relative;
  border-radius: var(--radius-2xl);
  overflow: hidden;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
  height: 280px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

/* Story Image Background */
.story-card-image {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

.story-card-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Image Placeholder */
.story-image-placeholder {
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg,
    var(--pastel-lavender) 0%,
    var(--pastel-mint) 25%,
    var(--pastel-peach) 50%,
    var(--pastel-sky) 75%,
    var(--pastel-lavender) 100%);
  background-size: 400% 400%;
  animation: gradientShift 15s ease infinite;
  display: flex;
  align-items: center;
  justify-content: center;
}

.story-image-placeholder .placeholder-icon {
  font-size: 48px;
  opacity: 0.4;
}

/* Glassmorphism Overlay */
.story-card-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: var(--space-5);
  background: linear-gradient(to top,
    rgba(0, 0, 0, 0.7) 0%,
    rgba(0, 0, 0, 0.4) 70%,
    transparent 100%);
  backdrop-filter: blur(10px);
  z-index: 1;
}

/* Character Badge - Floating */
.story-character-badge {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  z-index: 2;
}

/* Story Content in Overlay */
.story-card-content {
  position: relative;
  z-index: 2;
  color: white;
}

.story-title {
  font-family: var(--font-heading);
  font-size: var(--text-lg);
  font-weight: 600;
  color: white;
  margin: 0 0 var(--space-2) 0;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.story-metadata {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-sm);
  color: rgba(255, 255, 255, 0.9);
}

.story-date {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.story-age-tag {
  display: inline-block;
  padding: 2px var(--space-2);
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
  border-radius: var(--radius-md);
  font-size: var(--text-xs);
  font-weight: 500;
}

/* Desktop-only hover effects */
@media (hover: hover) {
  .story-card:hover, .library-story-card:hover {
    transform: translateY(-6px) scale(1.02);
    box-shadow: 
      0 20px 40px rgba(0, 0, 0, 0.15),
      0 8px 16px rgba(0, 0, 0, 0.1);
  }

  .story-card:hover .story-card-overlay,
  .library-story-card:hover .story-card-overlay {
    background: linear-gradient(to top,
      rgba(0, 0, 0, 0.8) 0%,
      rgba(0, 0, 0, 0.5) 70%,
      transparent 100%);
  }

  .story-card:hover .story-character-badge,
  .library-story-card:hover .story-character-badge {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  }
}

/* Active State */
.story-card:active, .library-story-card:active {
  transform: translateY(-4px) scale(1.01);
}

/* Loading State for Images */
.story-card-image img {
  transition: opacity 0.3s ease;
}

/* Mobile touch feedback */
@media (hover: none) {
  .age-card:active {
    transform: scale(0.98);
    transition: transform 0.1s ease;
  }
  
  .character-card:active {
    transform: scale(0.97);
    transition: transform 0.1s ease;
  }
  
  .story-card:active,
  .library-story-card:active {
    transform: scale(0.97);
    transition: transform 0.1s ease;
  }
  
  .recent-story-card:active {
    transform: scale(0.98);
    transition: transform 0.1s ease;
  }
}

/* Character Cards Mobile Optimization */
@media (max-width: 480px) {
  /* Switch to single column layout on mobile */
  .character-cards {
    grid-template-columns: 1fr;
    gap: var(--space-6);
    max-width: 100%;
    padding: 0 var(--space-4);
  }
  
  /* Increase card height for better visibility */
  .character-card {
    height: 300px;
    max-width: none;
  }
  
  /* Enhance content readability */
  .character-name {
    font-size: var(--text-2xl);
  }
  
  .character-subtitle {
    font-size: var(--text-base);
    margin-bottom: var(--space-3);
  }
  
  .character-description {
    font-size: var(--text-sm);
    line-height: 1.5;
  }
  
  /* Increase padding for better touch targets */
  .character-overlay {
    padding: var(--space-6);
  }
  
  .character-content {
    padding: var(--space-4);
  }
  
  /* Enhance glassmorphism effect on mobile */
  .character-content {
    background: rgba(255, 255, 255, 0.18);
    backdrop-filter: blur(16px) saturate(1.3);
    border: 1px solid rgba(255, 255, 255, 0.25);
  }
  
  /* Subtle mobile-specific hover effects */
  .character-card:hover {
    transform: translateY(-2px) scale(1.01);
  }
  
  .character-card.selected {
    transform: translateY(-3px) scale(1.02);
  }
  
  /* Larger tier badges for better visibility */
  .tier-badge {
    padding: var(--space-2) var(--space-4);
    font-size: var(--text-sm);
  }
  
  /* Larger character emoji for mobile */
  .character-emoji {
    font-size: 100px;
  }
}

/* Tablet adjustments */
@media (max-width: 768px) and (min-width: 481px) {
  .character-cards {
    gap: var(--space-5);
    padding: 0 var(--space-2);
  }
  
  .character-card {
    height: 260px;
  }
  
  .character-name {
    font-size: var(--text-xl);
  }
  
  .character-overlay {
    padding: var(--space-6);
  }
}

/* Story Cards Responsive Design */
@media (max-width: 768px) {
  .story-card, .library-story-card {
    height: 240px;
  }
  
  .story-character-badge {
    width: 36px;
    height: 36px;
    font-size: 18px;
  }
  
  .story-title {
    font-size: var(--text-base);
  }
  
  .story-metadata {
    font-size: var(--text-xs);
  }
}

/* Loading State */
.story-card-skeleton {
  background: var(--color-linen);
  border: 1px solid var(--color-stone);
  border-radius: var(--radius-2xl);
  height: 280px;
  position: relative;
  overflow: hidden;
}

.story-card-skeleton::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.4) 50%,
    transparent 100%
  );
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(200%); }
}


.plan-card {
  background: var(--color-cream);
  border: 1px solid var(--color-stone);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
}

.plan-card.current {
  border-color: var(--color-sage);
  background: var(--color-sage-light);
}

/* Recent Story Card */
.recent-story-card {
  flex: 0 0 auto;
  width: 280px; /* Fixed width for carousel items */
  background: var(--color-linen);
  border: 1px solid var(--color-stone);
  border-radius: var(--radius-xl);
  overflow: hidden;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
}

@media (hover: hover) {
  .recent-story-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
  }
}

.recent-story-thumbnail {
  height: 160px;
  background: linear-gradient(135deg, var(--pastel-lavender), var(--pastel-mint));
  display: flex;
  align-items: center;
  justify-content: center;
}

.recent-story-info {
  padding: var(--space-4);
}

.recent-story-title {
  font-family: var(--font-heading);
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--color-charcoal);
  margin-bottom: var(--space-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recent-story-character, .recent-story-date {
  font-size: var(--text-sm);
  color: var(--color-gray-warm);
  display: block;
  margin-bottom: var(--space-2);
}

.recent-story-read-btn {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  background: var(--color-sage);
  color: white;
  border: none;
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

@media (hover: hover) {
  .recent-story-read-btn:hover {
    background: #98a890;
  }
}
