// --- Layout --- //

$w-layout: 980px !default;
$w-layout-large: 1280px !default;

// Breakpoints
$breakpoints: (
  xxs: 0,
  xs: 320px,
  s: 576px,
  m: 768px,
  l: 992px,
  xl: 1200px
) !default;
$breakpoint-names: map-keys($breakpoints) !default;

// Breakpoint viewport sizes and media queries.
//
// Breakpoints are defined as a map of (name: minimum width), order from small to large:
//
//    (xxs: 0, xs: 320px, sm: 576px, md: 768px)

// Name of the next breakpoint, or null for the last breakpoint.
//
//    >> breakpoint-next(sm)
//    md
@function breakpoint-next($name) {
  $n: index($breakpoint-names, $name);
  @return if(
    $n < length($breakpoint-names),
    nth($breakpoint-names, $n + 1),
    null
  );
}

// Maximum breakpoint width. Null for the largest (last) breakpoint.
// The maximum value is calculated as the minimum of the next one less 0.1.
//
//    >> breakpoint-max(sm)
//    767px
@function breakpoint-max($name) {
  $next: breakpoint-next($name);
  @return if($next, breakpoint-min($next) - 1px, null);
}

// Media of at most the maximum breakpoint width. No query for the largest breakpoint.
// Makes the @content apply to the given breakpoint and narrower.
@mixin media-breakpoint-down($name) {
  $max: breakpoint-max($name);
  @if $max {
    @media (max-width: $max) {
      @content;
    }
  } @else {
    @content;
  }
}

// Media that spans multiple breakpoint widths.
// Makes the @content apply between the min and max breakpoints
@mixin media-breakpoint-between($lower, $upper) {
  @include media-breakpoint-up($lower) {
    @include media-breakpoint-down($upper) {
      @content;
    }
  }
}

// Media between the breakpoint's minimum and maximum widths.
// No minimum for the smallest breakpoint, and no maximum for the largest one.
// Makes the @content apply only to the given breakpoint, not viewports any wider or narrower.
@mixin media-breakpoint-only($name) {
  @include media-breakpoint-between($name, $name) {
    @content;
  }
}
