/*
 * Photographic surfaces, shared by all six documents (/ , /play/ and the four
 * info pages). This is the only copy of the texture custom properties: the app's
 * shared.css and the static pages' site.css both consume --tex-* from here, so
 * the format and resolution steps cannot drift apart.
 *
 * Widths: 900 px phones, 1920 px desktops, 2880 px for 2x screens from 900 px
 * and for 1x screens from 2200 px, 3840 px for 2x screens from 1800 px and for
 * 1x screens from 3200 px. Retina phones below 900 px also take the 1920 px
 * crop: a phone at 2-3x was upscaling the 900 px tile over the whole page.
 * Every step is AVIF first with the matching JPEG as the fallback: the plain
 * JPEG declarations are what browsers without typed image-set() get, and
 * image-set() swaps in AVIF everywhere else.
 */

:root {
  --tex-asphalt: url('/textures/asphalt_02.jpg');
  --tex-concrete: url('/textures/concrete_wall_008.jpg');
  --tex-brick: url('/textures/worn_brick_wall.jpg');
}

/* Retina phones: 900 px over a 600 px tall hero or a full-page body is a
   2-3x upscale, which is what read as blur. The desktop crop is 2.1x sharper. */
@media (max-width: 899px) and (min-resolution: 2dppx) {
  :root {
    --tex-asphalt: url('/textures/asphalt_02-hd.jpg');
    --tex-concrete: url('/textures/concrete_wall_008-hd.jpg');
    --tex-brick: url('/textures/worn_brick_wall-hd.jpg');
  }
}

@media (min-width: 900px) {
  :root {
    --tex-asphalt: url('/textures/asphalt_02-hd.jpg');
    --tex-concrete: url('/textures/concrete_wall_008-hd.jpg');
    --tex-brick: url('/textures/worn_brick_wall-hd.jpg');
  }
}

@media (min-width: 900px) and (min-resolution: 2dppx) {
  :root {
    --tex-asphalt: url('/textures/asphalt_02-2x.jpg');
    --tex-concrete: url('/textures/concrete_wall_008-2x.jpg');
    --tex-brick: url('/textures/worn_brick_wall-2x.jpg');
  }
}

/* 1440p and ultrawide monitors at 1x would otherwise stretch the 1920 crop. */
@media (min-width: 2200px) {
  :root {
    --tex-asphalt: url('/textures/asphalt_02-2x.jpg');
    --tex-concrete: url('/textures/concrete_wall_008-2x.jpg');
    --tex-brick: url('/textures/worn_brick_wall-2x.jpg');
  }
}

@media (min-width: 3200px) {
  :root {
    --tex-asphalt: url('/textures/asphalt_02-4k.jpg');
    --tex-concrete: url('/textures/concrete_wall_008-4k.jpg');
    --tex-brick: url('/textures/worn_brick_wall-4k.jpg');
  }
}

/* Keep last: a 2x display at 1800 px or wider outranks the 1x width steps. */
@media (min-width: 1800px) and (min-resolution: 2dppx) {
  :root {
    --tex-asphalt: url('/textures/asphalt_02-4k.jpg');
    --tex-concrete: url('/textures/concrete_wall_008-4k.jpg');
    --tex-brick: url('/textures/worn_brick_wall-4k.jpg');
  }
}

@supports (background-image: image-set(url('/textures/asphalt_02-hd.jpg') type('image/jpeg'))) {
  :root {
    --tex-asphalt: image-set(
      url('/textures/asphalt_02.avif') type('image/avif'),
      url('/textures/asphalt_02.jpg') type('image/jpeg')
    );
    --tex-concrete: image-set(
      url('/textures/concrete_wall_008.avif') type('image/avif'),
      url('/textures/concrete_wall_008.jpg') type('image/jpeg')
    );
    --tex-brick: image-set(
      url('/textures/worn_brick_wall.avif') type('image/avif'),
      url('/textures/worn_brick_wall.jpg') type('image/jpeg')
    );
  }

  @media (max-width: 899px) and (min-resolution: 2dppx) {
    :root {
      --tex-asphalt: image-set(
        url('/textures/asphalt_02-hd.avif') type('image/avif'),
        url('/textures/asphalt_02-hd.jpg') type('image/jpeg')
      );
      --tex-concrete: image-set(
        url('/textures/concrete_wall_008-hd.avif') type('image/avif'),
        url('/textures/concrete_wall_008-hd.jpg') type('image/jpeg')
      );
      --tex-brick: image-set(
        url('/textures/worn_brick_wall-hd.avif') type('image/avif'),
        url('/textures/worn_brick_wall-hd.jpg') type('image/jpeg')
      );
    }
  }

  @media (min-width: 900px) {
    :root {
      --tex-asphalt: image-set(
        url('/textures/asphalt_02-hd.avif') type('image/avif'),
        url('/textures/asphalt_02-hd.jpg') type('image/jpeg')
      );
      --tex-concrete: image-set(
        url('/textures/concrete_wall_008-hd.avif') type('image/avif'),
        url('/textures/concrete_wall_008-hd.jpg') type('image/jpeg')
      );
      --tex-brick: image-set(
        url('/textures/worn_brick_wall-hd.avif') type('image/avif'),
        url('/textures/worn_brick_wall-hd.jpg') type('image/jpeg')
      );
    }
  }

  @media (min-width: 900px) and (min-resolution: 2dppx) {
    :root {
      --tex-asphalt: image-set(
        url('/textures/asphalt_02-2x.avif') type('image/avif'),
        url('/textures/asphalt_02-2x.jpg') type('image/jpeg')
      );
      --tex-concrete: image-set(
        url('/textures/concrete_wall_008-2x.avif') type('image/avif'),
        url('/textures/concrete_wall_008-2x.jpg') type('image/jpeg')
      );
      --tex-brick: image-set(
        url('/textures/worn_brick_wall-2x.avif') type('image/avif'),
        url('/textures/worn_brick_wall-2x.jpg') type('image/jpeg')
      );
    }
  }

  @media (min-width: 2200px) {
    :root {
      --tex-asphalt: image-set(
        url('/textures/asphalt_02-2x.avif') type('image/avif'),
        url('/textures/asphalt_02-2x.jpg') type('image/jpeg')
      );
      --tex-concrete: image-set(
        url('/textures/concrete_wall_008-2x.avif') type('image/avif'),
        url('/textures/concrete_wall_008-2x.jpg') type('image/jpeg')
      );
      --tex-brick: image-set(
        url('/textures/worn_brick_wall-2x.avif') type('image/avif'),
        url('/textures/worn_brick_wall-2x.jpg') type('image/jpeg')
      );
    }
  }

  @media (min-width: 3200px) {
    :root {
      --tex-asphalt: image-set(
        url('/textures/asphalt_02-4k.avif') type('image/avif'),
        url('/textures/asphalt_02-4k.jpg') type('image/jpeg')
      );
      --tex-concrete: image-set(
        url('/textures/concrete_wall_008-4k.avif') type('image/avif'),
        url('/textures/concrete_wall_008-4k.jpg') type('image/jpeg')
      );
      --tex-brick: image-set(
        url('/textures/worn_brick_wall-4k.avif') type('image/avif'),
        url('/textures/worn_brick_wall-4k.jpg') type('image/jpeg')
      );
    }
  }

  @media (min-width: 1800px) and (min-resolution: 2dppx) {
    :root {
      --tex-asphalt: image-set(
        url('/textures/asphalt_02-4k.avif') type('image/avif'),
        url('/textures/asphalt_02-4k.jpg') type('image/jpeg')
      );
      --tex-concrete: image-set(
        url('/textures/concrete_wall_008-4k.avif') type('image/avif'),
        url('/textures/concrete_wall_008-4k.jpg') type('image/jpeg')
      );
      --tex-brick: image-set(
        url('/textures/worn_brick_wall-4k.avif') type('image/avif'),
        url('/textures/worn_brick_wall-4k.jpg') type('image/jpeg')
      );
    }
  }
}
