/* Component Styles */
/* Individual component styling with modern CSS practices */

/* Avatar Component with 3D Coin Flip */
.avatar {
  position: relative;
  display: inline-block;
  margin-bottom: var(--space-8);
}

/* 3D Container - Creates perspective for coin flip */
.avatar-container {
  width: var(--avatar-size-md);
  height: var(--avatar-size-md);
  perspective: 1000px;
  cursor: pointer;
  transition: transform var(--duration-fast) var(--easing-ease-out);
  border-radius: var(--radius-full);
  
  /* Make it focusable for keyboard interaction */
  outline: none;
  position: relative;
  
  /* Ensure it's a stacking context */
  z-index: 1;
}

.avatar-container:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 4px;
}

/* 3D Flipper - The rotating element */
.avatar-flipper {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 1.5s cubic-bezier(0.23, 1, 0.32, 1);
  
  /* Optimize for animations */
  will-change: transform;
  backface-visibility: hidden;
}

/* Both faces of the coin */
.avatar-face {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  border-radius: var(--radius-full);
  overflow: hidden;
  
  /* GPU acceleration */
  transform: translateZ(0);
  will-change: transform;
}

/* Front face (default visible) */
.avatar-front {
  transform: rotateY(0deg);
}

/* Back face (initially hidden) */
.avatar-back {
  transform: rotateY(180deg);
}

/* Avatar images styling */
.avatar-image {
  width: 100%;
  height: 100%;
  border-radius: var(--radius-full);
  object-fit: cover;
  object-position: center;
  border: 3px solid var(--color-primary-alpha);
  box-shadow: var(--shadow-lg);
  user-select: none;
  -webkit-user-drag: none;
  display: block;
  
  /* Optimize for animations */
  will-change: auto;
  transform: translateZ(0);
}

/* Container hover effects */
.avatar-container:hover .avatar-flipper {
  transform: scale(1.05);
}

.avatar-container:hover .avatar-image {
  box-shadow: var(--shadow-xl), 0 0 30px var(--color-shadow-hover);
  border-color: var(--color-primary);
}

.avatar-container:active .avatar-flipper {
  transform: scale(1.02);
}

/* Pure GSAP Implementation - No CSS Animation Fallbacks */
/* All animation logic handled by GSAP Timeline for maximum performance and control */

/* Loading state for avatar - Ensure visibility while loading */
.avatar-image[data-loading="true"] {
  /* Show shimmer effect overlay while preserving image visibility */
  position: relative;
}

.avatar-image[data-loading="true"]::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(90deg, 
    rgba(255, 255, 255, 0.05) 0%, 
    rgba(255, 255, 255, 0.15) 50%, 
    rgba(255, 255, 255, 0.05) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: inherit;
  pointer-events: none;
}

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

/* Fallback styles for failed image loads */
.avatar-image.fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-primary);
  font-size: var(--font-size-xl);
  font-weight: 500;
}

.avatar-image.fallback::after {
  content: '👤';
  font-size: 3rem;
}

/* Ensure avatar is always visible - responsive minimum size */
.avatar-image {
  min-height: var(--avatar-size-sm); /* Start with small size */
  min-width: var(--avatar-size-sm);
  display: block;
  
  /* Ensure image scales properly within container */
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Personal Motto Component */
.motto {
  margin-bottom: var(--space-12);
  max-width: 800px;
}

.motto-text {
  font-size: var(--font-size-2xl);
  line-height: var(--line-height-relaxed);
  font-weight: 400;
  letter-spacing: 0.02em;
  color: var(--color-text-primary);
  text-shadow: 0 2px 4px var(--color-shadow);
  margin: 0;
  
  /* Enhanced Chinese text rendering */
  -webkit-font-feature-settings: "liga", "kern";
  font-feature-settings: "liga", "kern";
  text-rendering: optimizeLegibility;
  -webkit-text-size-adjust: 100%;
  
  /* Balanced text wrapping */
  text-wrap: balance;
  hyphens: auto;
  word-break: keep-all;
  overflow-wrap: break-word;
}

/* ICP Footer Component */
.icp-footer {
  text-align: center;
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
}

/* Ensure footer content never wraps */
.icp-footer .container {
  white-space: nowrap; /* Prevent line breaks */
  overflow: visible; /* Allow content to extend if needed */
}

.icp-link {
  color: var(--color-text-secondary);
  text-decoration: none;
  transition: 
    color var(--duration-fast) var(--easing-ease-out),
    text-shadow var(--duration-fast) var(--easing-ease-out);
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  
  /* Minimum touch target size for mobile */
  min-height: 44px;
  min-width: 44px;
  
  /* Critical: Never allow text to wrap */
  white-space: nowrap !important;
  word-break: keep-all !important; /* Prevent breaking of Chinese characters */
  overflow-wrap: normal !important;
}

.icp-link::after {
  content: '↗';
  font-size: 0.8em;
  opacity: 0.7;
  margin-left: var(--space-1);
  transition: 
    opacity var(--duration-fast) var(--easing-ease-out),
    transform var(--duration-fast) var(--easing-ease-out);
}

.icp-link:hover {
  color: var(--color-primary);
  text-shadow: 0 1px 2px var(--color-shadow);
  text-decoration: underline;
  text-decoration-color: var(--color-text-secondary);
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}

.icp-link:hover::after {
  opacity: 1;
  transform: translateX(2px) translateY(-2px);
}

.icp-link:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
  color: var(--color-primary);
}

.icp-link:active {
  transform: translateY(1px);
}

/* Reduced motion handled entirely by GSAP - no CSS overrides needed */
@media (prefers-reduced-motion: reduce) {
  .avatar-container:hover .avatar-flipper {
    transform: none;
  }
}

/* Mobile optimization - smaller avatar to save space */
@media (max-width: 575px) {
  .avatar-container {
    width: var(--avatar-size-sm);
    height: var(--avatar-size-sm);
  }
  
  .avatar-image {
    min-height: var(--avatar-size-sm);
    min-width: var(--avatar-size-sm);
  }
  
  /* Reduce margins to prevent overflow */
  .avatar {
    margin-bottom: var(--space-4);
  }
}

/* Medium mobile and small tablets */
@media (min-width: 576px) and (max-width: 767px) {
  .avatar-container {
    width: var(--avatar-size-md);
    height: var(--avatar-size-md);
  }
  
  .avatar-image {
    min-height: var(--avatar-size-md);
    min-width: var(--avatar-size-md);
  }
}

/* Tablets and larger */
@media (min-width: 768px) {
  .avatar-container {
    width: var(--avatar-size-lg);
    height: var(--avatar-size-lg);
  }
  
  .avatar-image {
    min-height: var(--avatar-size-lg);
    min-width: var(--avatar-size-lg);
  }
  
  .motto-text {
    font-size: var(--font-size-3xl);
  }
}

@media (min-width: 768px) {
  .avatar {
    margin-bottom: var(--space-10);
  }
  
  .motto {
    margin-bottom: var(--space-16);
  }
}

@media (min-width: 992px) {
  .avatar {
    margin-bottom: var(--space-12);
  }
  
  .motto {
    margin-bottom: var(--space-20);
  }
}

/* High contrast mode adjustments */
@media (prefers-contrast: high) {
  .avatar-image {
    border-width: 4px;
  }
  
  .motto-text {
    text-shadow: 0 0 8px var(--color-shadow);
  }
  
  .icp-link {
    background: rgba(0, 0, 0, 0.3);
    border-radius: var(--radius-md);
  }
}

/* Print styles */
@media print {
  .avatar-image {
    box-shadow: none;
    border: 2px solid #000;
  }
  
  .icp-link::after {
    content: ' (https://beian.miit.gov.cn/)';
  }
}
