@import '../font-faces/font-faces';

// line-height + margin-top + margin-bottom must be a multiple of 1.5rem to maintain vertical rhythm.
$base-line-height: 1.5;

// The following base gives us 2 fixed points on the scale at
// 15px and ~13px, expressed in rems because I am a pedant.
$ms-base: (13 / 15) * 1rem 1rem;
$ms-ratio: $fourth;

$heading-style-params-h1:    ('style': 'shout', 'font-size': font-size(4));
$heading-style-params-h2:    ('style': 'blurt', 'font-size': font-size(3));
$heading-style-params-h3:    ('style': 'blurt', 'font-size': font-size(2));
$heading-style-params-h4-h6: ('style': 'blurt', 'font-size': font-size(0));

// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// We load fonts with a 2-stage strategy to eliminate flash of invisible text (FOIT) and
// minimize flash of unstyled text (FOUT). See https://www.zachleat.com/web/comprehensive-webfonts/
// and see https://codepen.io/kendrick/pen/QxZoyK for a testing Pen.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
.fonts-loaded-subset,
.fonts-loaded {
  body {
    word-spacing: initial;
    letter-spacing: initial;
    font-size: font-size(0);
    font-family: font-family(default);
  }

  h1 {
    @include heading-style($heading-style-params-h1);
  }

  h2 {
    @include heading-style($heading-style-params-h2);
  }

  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    text-transform: none;
    letter-spacing: 0;
  }
}

:root {
  font-size: 15px;
}

body {
  $sans-base-letter-spacing: -0.15px;
  $sans-base-word-spacing: 1.0px;

  margin: 0;
  color: color(black);

  word-spacing: $sans-base-word-spacing;
  letter-spacing: $sans-base-letter-spacing;
  font-size: font-size(0);
  font-family: font-family(loading);
  line-height: $base-line-height;

  -webkit-font-smoothing: antialiased; // sass-lint:disable-line no-vendor-prefixes
  -moz-osx-font-smoothing: grayscale;  // sass-lint:disable-line no-vendor-prefixes
}

p {
  margin-top: 0;
}

h1 {
  $sans-h1-word-spacing: 0.05em;
  $sans-h1-letter-spacing: 0.045em;

  @include heading-style($heading-style-params-h1);

  margin: 0;
  word-spacing: $sans-h1-word-spacing;
  letter-spacing: $sans-h1-letter-spacing; // Need to override what comes back from `heading-style` to minimize FOUT jank.
}

h2 {
  $sans-h2-word-spacing: 0.0125em;
  $sans-h2-letter-spacing: 0.025e;

  @include heading-style($heading-style-params-h2);

  margin: 0;
  word-spacing: $sans-h2-word-spacing;
  letter-spacing: $sans-h2-letter-spacing; // Need to override what comes back from `heading-style` to minimize FOUT jank.
}

h3 {
  @include heading-style($heading-style-params-h3);

  margin: 0;
}

h4,
h5,
h6 {
  @include heading-style($heading-style-params-h4-h6);

  margin: 0;
  font-weight: font-weight(bold);
}

h1,
h2,
h3,
h4,
h5,
h6 {
  text-transform: none;
  letter-spacing: 0;
}

.heading-group {
  .preheading,
  .heading,
  .subheading {
    display: block;
    line-height: 1.1;
  }
  .preheading {
    font-size: font-size(0);
  }

  .heading {
    font-size: font-size(4);
  }

  .subheading {
    font-size: font-size(2);
  }

  &.display {
    text-align: center;
    .preheading { font-style: italic; }
    .subheading { text-transform: uppercase; }
  }
}

// @include media('>=md') {
//   h1 {
//     font-size: font-size(4);
//   }

//   h2 {
//     font-size: font-size(3);
//   }

//   h3 {
//     font-size: font-size(2);
//   }

//   h4 {
//     font-size: font-size(1);
//   }

//   h5,
//   h6 {
//     font-size: font-size(0);
//   }
// }

// @include media('>=lg') {
//   h1 {
//     font-size: font-size(5);
//   }

//   h2 {
//     font-size: font-size(4);
//   }

//   h3 {
//     font-size: font-size(3);
//   }

//   h4 {
//     font-size: font-size(2);
//   }
// }

// @include media('>=xl') {
//   h1 {
//     font-size: font-size(6);
//   }

//   h2 {
//     font-size: font-size(5);
//   }

//   h3 {
//     font-size: font-size(4);
//   }

//   h4 {
//     font-size: font-size(3);
//   }
// }

.font-minus-2 {
  font-size: font-size(-2);
}

.font-minus-1 {
  font-size: font-size(-1);
}

.font-plus-1 {
  font-size: font-size(1);
}

.font-plus-2 {
  font-size: font-size(2);
}

.font-plus-3 {
  font-size: font-size(3);
}

.font-plus-4 {
  font-size: font-size(4);
}

.list-reset {
  @include list-reset();
}

.list-inline,
.list-reset-horizontal {
  @include list-reset($horizontal: true);
}

pre,
code,
.code {
  white-space: pre-line;
  font-weight: font-weight(light);
  font-family: font-family(monospace);
}

ul {
  &.horizontal {
    li {
      display: inline-block;
    }
  }
}

.text-with-rule {
  display: flex;
  margin: auto;
  text-align: center;
  text-transform: uppercase;
  font-size: font-size(-1);

  &::before,
  &::after {
    display: inline-block;
    flex: 1;
    margin: auto 0.6rem;
    border-top: 1px solid color(gray, plus2);
    content: '';
    vertical-align: middle;
  }

  &::before {
    margin-left: 0;
  }

  &::after {
    margin-right: 0;
  }
}

@import 'typography-anchors';
@import 'typography-text-with-icon';
@import 'typography-cta';
@import 'typography-link-lists';
@import 'typography-clamping';
