@function color-yiq($color) {
  $r: red($color);
  $g: green($color);
  $b: blue($color);

  $yiq: (($r * 299) + ($g * 587) + ($b * 114)) / 1000;

  @if ($yiq >= 150) {
    @return #111;
  } @else {
    @return #fff;
  }
}

@function theme-color($name) {
  @return map-get($theme-colors, $name);
}

@function theme-color-level($name, $level: 0) {
  $theme-color-interval: 8;
  $color: theme-color($name);
  $color-base: if($level > 0, #000, #fff);

  @if $level < 0 {
    // Lighter values need a quick double negative for the Sass math to work
    @return mix($color-base, $color, $level * -1 * $theme-color-interval);
  } @else {
    @return mix($color-base, $color, $level * $theme-color-interval);
  }
}

@function colors() {
  @return map_merge($colors, $theme-colors);
}

@function color($name) {
  @return map-get(colors(), $name);
}

@function gray($level) {
  @return map-get($grays, $level);
}

@function random-color() {
  $list: map_values(colors());
  $index: random(length($list));
  @return nth($list, $index);
}
