@layer blocks {
  /* ----------------------------------------
     Wrapper — constrains form width on desktop
  ---------------------------------------- */
  .contact-wrapper {
    max-width: 40rem;
  }

  /* ----------------------------------------
     Form layout — single column, consistent gap
  ---------------------------------------- */
  .contact-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
  }

  /* ----------------------------------------
     Field — wraps label + input + error text
     Position relative anchors ::after line
  ---------------------------------------- */
  .contact-field {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    position: relative;
  }

  /* Animated focus border — expands from center */
  .contact-field::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    width: 0;
    height: 2px;
    background: var(--color-accent);
    transition:
      width var(--duration-normal) var(--ease-out-expo),
      left var(--duration-normal) var(--ease-out-expo);
  }

  .contact-field:focus-within::after {
    width: 100%;
    left: 0;
  }

  /* ----------------------------------------
     Label
  ---------------------------------------- */
  .contact-label {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    font-weight: 500;
    letter-spacing: 0.03em;
    text-transform: uppercase;
  }

  /* ----------------------------------------
     Input + Textarea base
  ---------------------------------------- */
  .contact-input {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    color: var(--color-text);
    font-size: var(--font-size-base);
    line-height: 1.6;
    transition:
      border-color var(--duration-normal) ease,
      box-shadow var(--duration-normal) ease;

    /* Remove bottom border radius — the ::after line sits flush */
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
  }

  .contact-input::placeholder {
    color: var(--color-text-muted);
    opacity: 0.6;
  }

  .contact-input:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px var(--color-accent-subtle);
  }

  /* Textarea height override */
  .contact-textarea {
    resize: vertical;
    min-height: 8rem;
  }

  /* ----------------------------------------
     Validation states — :user-invalid targets
     visited invalid fields only (not on page load)
  ---------------------------------------- */
  .contact-input:user-invalid {
    border-color: hsl(0deg 72% 51%);
    box-shadow: 0 0 0 3px hsl(0deg 72% 51% / 0.2);
  }

  /* ----------------------------------------
     Per-field error text
  ---------------------------------------- */
  .contact-error {
    font-size: var(--font-size-sm);
    color: hsl(0deg 72% 65%);
  }

  .contact-error:empty {
    display: none;
  }

  /* ----------------------------------------
     Submit button
  ---------------------------------------- */
  .contact-submit {
    align-self: flex-start;
    padding: var(--space-sm) var(--space-xl);
    background: var(--color-accent);
    color: var(--color-bg);
    font-weight: 600;
    font-size: var(--font-size-base);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    position: relative;
    overflow: hidden;
    min-height: 44px; /* WCAG touch target */
    transition:
      background-color var(--duration-normal) ease,
      transform var(--duration-fast) ease;
  }

  @media (prefers-reduced-motion: no-preference) {
    .contact-submit:hover {
      background: var(--color-accent-hover);
    }

    .contact-submit:active {
      transform: scale(0.97);
    }
  }

  /* Loading state — hides label text, shows spinner */
  .contact-submit[data-loading] {
    color: transparent;
    pointer-events: none;
  }

  .contact-submit[data-loading]::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    border: 2px solid transparent;
    border-top-color: var(--color-bg);
    border-radius: 50%;
    animation: contact-spin 0.6s linear infinite;
    top: 50%;
    left: 50%;
    margin: -10px 0 0 -10px;
  }

  @keyframes contact-spin {
    to {
      transform: rotate(360deg);
    }
  }

  /* ----------------------------------------
     Feedback message (success / error)
     GSAP animates height — no max-height trick
  ---------------------------------------- */
  .contact-feedback {
    overflow: hidden;
    padding: var(--space-md);
    border-radius: var(--radius-md);
    margin-block-end: var(--space-lg);
    font-size: var(--font-size-base);
    line-height: 1.5;
  }

  .contact-feedback[data-variant='success'] {
    background: hsl(142deg 71% 45% / 0.12);
    border: 1px solid hsl(142deg 71% 45% / 0.4);
    color: hsl(142deg 71% 65%);
  }

  .contact-feedback[data-variant='error'] {
    background: hsl(0deg 72% 51% / 0.12);
    border: 1px solid hsl(0deg 72% 51% / 0.4);
    color: hsl(0deg 72% 65%);
  }

  /* ----------------------------------------
     Responsive — form is already single column.
     On mobile, submit button goes full width.
  ---------------------------------------- */
  @media (width <= 480px) {
    .contact-submit {
      align-self: stretch;
    }
  }
}
