/* Modern, elegant styling for ottoahoniemi.fi - 2025 Edition */

@layer reset, base, components, utilities;

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

@layer base {
  :root {
    /* Modern OKLCH color palette for better perceptual uniformity */
    --text-primary: oklch(20% 0.01 280);
    --text-secondary: oklch(50% 0.02 270);
    --accent: oklch(62% 0.21 255);
    --accent-hover: oklch(57% 0.23 255);
    --background: oklch(100% 0 0);
    --border: oklch(92% 0.01 280);

    /* Typography */
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
                 'Ubuntu', 'Cantarell', 'Helvetica Neue', sans-serif;

    /* Spacing using logical properties */
    --spacing-unit: 1rem;

    /* Animation timing */
    --transition-fast: 0.2s;
    --transition-medium: 0.3s;
    --transition-slow: 0.8s;
  }

  /* Dark mode with OKLCH colors */
  @media (prefers-color-scheme: dark) {
    :root {
      --text-primary: oklch(98% 0.01 280);
      --text-secondary: oklch(82% 0.02 270);
      --accent: oklch(72% 0.19 255);
      --accent-hover: oklch(80% 0.15 255);
      --background: oklch(18% 0.01 280);
      --border: oklch(30% 0.02 270);
    }
  }

  html {
    font-size: 16px;
    color-scheme: light dark;
  }

  body {
    font-family: var(--font-sans);
    background-color: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    min-block-size: 100dvh; /* Dynamic viewport height for mobile */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    transition: background-color var(--transition-medium) ease,
                color var(--transition-medium) ease;
  }

  /* Custom text selection with modern color-mix */
  ::selection {
    background-color: var(--accent);
    color: var(--background);
  }
}

@layer components {
  .container {
    inline-size: 100%;
    max-inline-size: 42rem;
    margin-inline: auto;
  }

  main {
    animation: fadeIn var(--transition-slow) ease-out;
  }

  .content {
    text-align: center;
  }

  /* Typography with modern text-wrap */
  .greeting {
    font-size: clamp(2.5rem, 8vw, 4rem);
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-block-end: 1.5rem;
    text-wrap: balance; /* Modern CSS for balanced multi-line text */
    background: linear-gradient(135deg, var(--text-primary) 0%, var(--text-secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: slideDown 0.6s ease-out;
  }

  .bio {
    font-size: clamp(1.125rem, 3vw, 1.375rem);
    color: var(--text-secondary);
    margin-block-end: 3rem;
    line-height: 1.8;
    max-inline-size: 34rem;
    margin-inline: auto;
    text-wrap: pretty; /* Modern CSS for better line breaks */
    animation: slideDown 0.6s ease-out 0.2s both;
  }

  /* Social links with modern nesting */
  .social-links {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
    animation: slideUp 0.6s ease-out 0.4s both;
  }

  .social-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding-block: 0.875rem;
    padding-inline: 1.75rem;
    font-size: 1.0625rem;
    font-weight: 600;
    color: var(--accent);
    text-decoration: none;
    border: 2px solid var(--border);
    border-radius: 0.5rem;
    transition: all var(--transition-fast) ease;
    position: relative;
    overflow: hidden;

    &::before {
      content: '';
      position: absolute;
      inset: 0;
      background: var(--accent);
      transform: scaleX(0);
      transform-origin: left;
      transition: transform var(--transition-medium) ease;
      z-index: -1;
    }

    &:hover {
      color: var(--background);
      border-color: var(--accent);
      transform: translateY(-2px);
      box-shadow: 0 10px 25px -5px color-mix(in oklch, var(--accent) 30%, transparent);

      &::before {
        transform: scaleX(1);
      }

      svg {
        transform: scale(1.1);
      }
    }

    &:active {
      transform: translateY(0);
    }

    &:focus-visible {
      outline: 3px solid var(--accent);
      outline-offset: 4px;
    }

    svg {
      flex-shrink: 0;
      transition: transform var(--transition-fast) ease;
    }
  }
}

@layer utilities {
  /* Animations */
  @keyframes fadeIn {
    from {
      opacity: 0;
    }
    to {
      opacity: 1;
    }
  }

  @keyframes slideDown {
    from {
      opacity: 0;
      transform: translateY(-20px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  @keyframes slideUp {
    from {
      opacity: 0;
      transform: translateY(20px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  /* Responsive adjustments */
  @media (max-width: 640px) {
    body {
      padding: 1.5rem;
    }

    .social-links {
      flex-direction: column;
      max-inline-size: 16rem;
      margin-inline: auto;
    }

    .social-link {
      inline-size: 100%;
      justify-content: center;
    }
  }

  /* Reduced motion support */
  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
    }
  }

  /* Print styles */
  @media print {
    body {
      background: white;
      color: black;
    }

    .social-link {
      border-color: black;
      color: black;

      &::before {
        display: none;
      }
    }
  }
}
