:root {
  --accent: hsl(198, 93%, 60%);
  --text: hsl(214, 32%, 97%);
  --text-secondary: hsl(214, 31%, 83%);
  --background: hsl(218, 32%, 18%);
  --card-bg: hsl(35, 100%, 76%, 0.1);
  --card-border: hsl(218, 17%, 47%, 0.3);
  --hover: hsl(0, 0%, 100%, 0.05);
  --border-color: hsl(35, 100%, 76%, 0.15);
  --avatar-bg: hsl(207, 100%, 76%, 0.1);
  --content-width: 1100px;
  --focus-ring: 3px solid hsl(198, 93%, 70%);
}

@layer base, layout, components, utilities, print;

@layer base {
  html {
    scroll-behavior: smooth;
  }

  @media (prefers-reduced-motion: reduce) {
    html {
      scroll-behavior: auto;
    }
  }

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

  *:focus {
    outline: var(--focus-ring);
    outline-offset: 2px;
  }

  body {
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 16px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background-image: url(/assets/img/background_pglazkov.webp), linear-gradient(135deg, hsl(222, 47%, 11%, 0.92) 0%, hsl(218, 32%, 18%, 0.95) 100%);
    background-repeat: repeat, no-repeat;
    background-size: contain, cover;
    background-blend-mode: soft-light;
    background-color: var(--background);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
  }

  strong {
    color: var(--text);
    font-weight: 600;
  }
}

@layer layout {
  .page-wrapper {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
  }

  main {
    max-width: clamp(320px, 90vw, var(--content-width));
    width: 100%;
    margin-inline: auto;
    padding-block: 60px;
    padding-inline: 20px;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    content-visibility: auto;
    contain-intrinsic-size: 1px 500px;

    @media (max-width: 960px) {
      padding-block: 40px;
    }
  }

  footer {
    padding: 20px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: auto;
    background-color: hsl(222, 47%, 11%, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);

    & p {
      max-width: var(--content-width);
      margin-inline: auto;
    }
  }
}

@layer components {
  .card {
    width: 100%;
    background: var(--card-bg);
    border-radius: 16px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--card-border);
    box-shadow: 0 20px 25px -5px hsl(0, 0%, 0%, 0.2), 0 8px 10px -6px hsl(0, 0%, 0%, 0.1);
    overflow: hidden;
    transition: transform 0.3s ease, box-shadow 0.3s ease;

    &:hover {
      transform: translateY(-5px);
      box-shadow: 0 25px 50px -12px hsl(0, 0%, 0%, 0.25);
    }
    
    @supports not (backdrop-filter: blur(8px)) {
      background: hsl(218, 32%, 15%, 0.9);
    }
  }

  .about {
    display: grid;
    grid-template-columns: 300px 1fr;
    padding: 0;

    @media (max-width: 960px) {
      grid-template-columns: 1fr;
    }
  }

  .avatar-container {
    padding: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-inline-end: 1px solid var(--border-color);
    background: var(--avatar-bg);
    position: relative;
    overflow: hidden;

    &::before {
      content: '';
      position: absolute;
      inset: 0;
      background-image: url(/assets/img/background_pglazkov.webp);
      background-repeat: repeat;
      background-size: 200px;
      opacity: 0.05;
      mix-blend-mode: soft-light;
    }

    @media (max-width: 960px) {
      border-inline-end: none;
      border-block-end: 1px solid var(--border-color);
      padding: 40px 20px;
    }
  }

  .avatar-frame {
    border-radius: 50%;
    overflow: hidden;
    border: 3px solid hsl(0, 0%, 100%, 0.7);
    box-shadow: 0 20px 25px -5px hsl(0, 0%, 0%, 0.3);
    transition: transform 0.5s ease;
    width: min(100%, 250px);
    aspect-ratio: 1 / 1;
    will-change: transform;

    @supports not (aspect-ratio: 1 / 1) {
      height: 250px;
      width: 250px;
    }

    &:hover {
      transform: scale(1.05);
    }

    & img {
      display: block;
      width: 100%;
      height: auto;
      border-radius: 50%;
      transition: filter 0.3s ease;
    }

    @media (max-width: 960px) {
      width: 200px;
      
      @supports not (aspect-ratio: 1 / 1) {
        height: 200px;
      }
    }
  }

  .about-text-container {
    padding: 40px;
    display: flex;
    flex-direction: column;
    justify-content: center;

    & .description {
      margin-block-end: 32px;
      color: var(--text-secondary);
      font-size: clamp(1rem, 2vw, 1.1rem);
      line-height: 1.6;
      padding-block-end: 24px;
      border-block-end: 1px solid var(--border-color);
    }

    @media (max-width: 960px) {
      padding: 30px 20px;
    }

    @media (max-width: 600px) {
      & p {
        font-size: 1rem;
      }
    }
  }

  .header {
    margin-block-end: 24px;
  }

  h1 {
    font-size: clamp(1.75rem, 4vw, 2.5rem);
    font-weight: 700;
    margin-block-end: 8px;
    background: linear-gradient(to right, var(--text), hsl(214, 20%, 75%));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 2px 10px hsl(0, 0%, 0%, 0.1);
    
    @supports not (background-clip: text) {
      background: unset;
      -webkit-text-fill-color: unset;
      color: var(--text);
    }
  }

  .highlight {
    color: var(--accent);
    -webkit-text-fill-color: var(--accent);
    font-weight: 700;
    text-shadow: 0 0 15px hsl(198, 93%, 60%, 0.5);
  }

  .title {
    font-size: clamp(1.1rem, 2vw, 1.25rem);
    margin-block-start: 8px;
    font-weight: 500;
    letter-spacing: 0.5px;
  }

  .tech-section {
    margin-block-end: 32px;
    padding-block-end: 24px;
    border-block-end: 1px solid var(--border-color);

    & h3 {
      font-size: 1.2rem;
      margin-block-end: 16px;
      color: var(--text);
      font-weight: 600;
    }
  }

  .tech-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-block-end: 8px;

    @media (max-width: 960px) {
      gap: 10px;
    }

    @media (max-width: 600px) {
      gap: 10px;
    }
  }

  .badge {
    display: flex;
    align-items: center;
    justify-content: center;
    padding-block: 8px;
    padding-inline: 16px;
    background: hsl(35, 100%, 76%, 0.05);
    border-radius: 8px;
    box-shadow: 0 2px 4px hsl(0, 0%, 0%, 0.1);
    border-inline-start: 3px solid var(--accent);
    transition: all 0.3s ease;
    will-change: transform;

    &:nth-child(2n) {
      border-inline-start-color: hsl(246, 76%, 59%);
    }

    &:nth-child(3n) {
      border-inline-start-color: hsl(178, 50%, 45%);
    }

    &:nth-child(4n) {
      border-inline-start-color: hsl(263, 55%, 60%);
    }

    &:hover, &:focus-within {
      transform: translateY(-3px);
      box-shadow: 0 4px 8px hsl(0, 0%, 0%, 0.2);
      background: hsl(246, 76%, 59%, 0.15);
    }

    & span {
      font-size: 0.9rem;
      color: var(--text-secondary);
      white-space: nowrap;
      text-align: center;
    }

    &:hover span, &:focus-within span {
      color: var(--text);
    }

    @media (max-width: 600px) {
      padding: 7px 14px;
      flex-basis: calc(50% - 10px);

      & span {
        font-size: 0.85rem;
      }
    }

    @media (max-width: 480px) {
      flex-basis: 100%;
      padding-inline: 10px;
    }
    
    @media (prefers-reduced-motion: reduce) {
      transition: none;
      &:hover, &:focus-within {
        transform: none;
      }
    }
  }

  .links-section {
    margin-block-end: 24px;

    & h3 {
      font-size: 1.2rem;
      margin-block-end: 16px;
      color: var(--text);
      font-weight: 600;
    }
  }

  .social-links {
    list-style-type: none;
    display: flex;
    gap: 16px;
    margin-block-start: 16px;

    & li {
      display: flex;
    }

    @media (max-width: 600px) {
      flex-direction: column;
      gap: 10px;
    }
  }

  .social-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-block: 10px;
    padding-inline: 16px;
    text-decoration: none;
    color: var(--text-secondary);
    border-radius: 8px;
    background: hsl(222, 47%, 11%, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    transition: all 0.3s ease;
    border: 1px solid var(--card-border);
    box-shadow: 0 4px 6px -1px hsl(0, 0%, 0%, 0.1);
    width: 100%;
    will-change: transform;

    & svg {
      font-size: 1.2rem;
      color: var(--accent);
    }

    &:hover, &:focus {
      background: hsl(246, 76%, 59%, 0.2);
      color: var(--text);
      border-color: hsl(244, 85%, 67%, 0.4);
      transform: translateY(-2px);
      box-shadow: 0 10px 15px -3px hsl(0, 0%, 0%, 0.2);
    }

    @media (max-width: 600px) {
      justify-content: center;
    }
    
    @media (prefers-reduced-motion: reduce) {
      transition: none;
      &:hover, &:focus {
        transform: none;
      }
    }
  }
}

@container (max-width: 500px) {
  .about-text-container {
    padding-inline: 15px;
  }
  
  .tech-badges {
    justify-content: center;
  }
}