// Animations
@keyframes ripple_effect {
  from {
    background-image: radial-gradient(circle farthest-corner at center,
                                      gtkalpha(currentColor, 0.1) 0%,
                                      transparent 0%);
  }

  to {
    background-image: radial-gradient(circle farthest-corner at center,
                                      gtkalpha(currentColor, 0.1) 100%,
                                      transparent 0%);
  }
}

// Drawing mixins

@mixin focus-ring($target: null, $width: 1px, $offset: -3px, $focus-state: ':focus:focus-visible') {
  &#{$focus-state} #{$target} {
    outline-color: gtkalpha(currentcolor, 0.3);
    outline-offset: $offset;
    outline-style: dashed;
    outline-width: $width;
  }
}

// Solid color image
@function _solid($c) {
  @return linear-gradient(to bottom, $c, $c);
}

// Entries

@mixin entry($t) {
//
// Entries drawing function
//
// $t: entry type
//

  @if $t==normal {
  //
  // normal entry
  //
    color: $text_color;
    border-color: $entry_border;
    background-color: $entry_bg;
    outline: none;
    box-shadow: none;
  }

  @if $t==focus {
  //
  // focused entry
  //
    color: $text_color;
    border-color: $selected_bg_color;
    background-color: $entry_bg;
    outline: none;
    box-shadow: none;
  }

  @if $t==insensitive {
  //
  // insensitive entry
  //
    color: $insensitive_fg_color;
    border-color: $alt_borders_color;
    background-color: transparentize($entry_bg, 0.45);
  }

  @if $t==header-normal {
  //
  // normal header-bar entry
  //

    color: $header_fg;
    border-color: $header_entry_border;
    background-color: $header_entry_bg;

    image, image:hover { color: inherit; }
  }

  @if $t==header-focus {
  //
  // focused header-bar entry
  //
    outline: none;
    box-shadow: none;
    color: lighten($header_fg, 20%);
    border-color: $selected_bg_color;
    background-color: if($variant=='light', lighten($header_entry_bg, 2%), lighten($header_entry_bg, 5%));
  }

  @if $t==header-insensitive {
  //
  // insensitive header-bar entry
  //
    color: transparentize($header_fg, 0.45);
    border-color: $header_entry_border;
    background-color: transparentize($header_entry_bg, 0.15);
    opacity: 1;
  }

  @else if $t==osd {
  //
  // normal osd entry
  //
    color: $osd_fg_color;
    border-color: $osd_entry_border;
    background-color: $osd_entry_bg;

    image, image:hover { color: inherit; }
  }

  @else if $t==osd-focus {
  //
  // active osd entry
  //
    color: $selected_fg_color;
    border-color: $osd_entry_border;
    background-color: $selected_bg_color;
    outline: none;
    box-shadow: none;
  }

  @else if $t==osd-insensitive {
  //
  // insensitive osd entry
  //
    color: transparentize($osd_fg_color, 0.45);
    background-color: transparentize($osd_entry_bg, 0.15);
    opacity: 1;
  }
}

// Buttons

@mixin button($t, $actionb_bg:red, $actionb_fg: green) {
//
// Button drawing function
//
// $t:    button type,
// $actionb_bg, $actionb_fg: used for destructive and suggested action buttons

  @if $t==normal {
  //
  // normal button
  //
    color: $fg_color;
    border-color: $button_border;
    background-color: $button_bg;
  }

  @else if $t==hover {
  //
  // hovered button
  //
    color: darken($fg_color, 15%);
    border-color: if($variant=='light', darken($button_border, 5%), lighten($button_border, 5%));
    background-color: lighten($button_bg, 8%);
    box-shadow: none;
  }

  @else if $t==active {
  //
  // pushed button
  //
    color: $selected_fg_color;
    border-color: if($variant == 'light', $sec_selected_bg_color, $alt_selected_bg_color);
    background-color: $selected_bg_color;
    box-shadow: none;
  }

  @else if $t==insensitive {
  //
  // insensitive button
  //
    label, & {
      color: $insensitive_fg_color;
      opacity: 1;
    }

    border-color: $alt_borders_color;
    background-color: transparentize($button_bg, 0.45);
  }

  @else if $t==insensitive-active {
  //
  // insensitive pushed button
  //
    label, & { color: transparentize($selected_fg_color, 0.2); }

    border-color: transparentize($selected_bg_color, 0.25);
    background-color: transparentize($selected_bg_color, 0.25);
    opacity: 0.6;
  }

  @if $t==header-normal {
  //
  // normal header-bar button
  //
    color: $header_fg;
    outline-offset: -3px;
    background-color: transparentize($header_bg, 1);
    border-color: transparentize($header_bg, 1);
  }

  @else if $t==header-hover {
  //
  // hovered header-bar button
  //
    color: $header_fg;
    border-color: if($titlebar == 'light', rgba(black, 0.12), rgba(white, 0.12));
    background-color: if($titlebar == 'light', darken($header_bg, 5%), lighten($header_bg, 5%));
  }

  @else if $t==header-active {
  //
  // pushed header-bar button
  //
    color: $selected_fg_color;
    border-color: if($titlebar == 'light', $sec_selected_bg_color, $alt_selected_bg_color);
    background-color: $selected_bg_color;
  }

  @else if $t==header-insensitive {
  //
  // insensitive header-bar button
  //
    label, & {
      color: transparentize($header_fg, 0.5);
      opacity: 1;
    }

    background-color: transparentize($header_bg, 1);
    border-color: transparentize($header_bg, 1);
  }

  @else if $t==header-insensitive-active {
  //
  // header-bar insensitive pushed button
  //
    color: transparentize($selected_fg_color, 0.5);
    border-color: transparentize($selected_bg_color, 0.35);
    background-color: transparentize($selected_bg_color, 0.35);
  }

  @else if $t==osd {
  //
  // normal osd button
  //
    color: $osd_fg_color;
    border-color: $osd_button_border;
    background-color: $osd_button_bg;
  }

  @else if $t==osd-hover {
  //
  // active osd button
  //
    color: $selected_bg_color;
    border-color: $osd_button_border;
    background-color: lighten($osd_button_bg, 5%);
  }

  @else if $t==osd-active {
  //
  // active osd button
  //
    color: $selected_fg_color;
    border-color: $selected_bg_color;
    background-color: $selected_bg_color;
    background-clip: border-box;
  }

  @else if $t==osd-insensitive {
  //
  // insensitive osd button
  //
    opacity: 1;
    color: $osd_insensitive_fg_color;
    border-color: $osd_button_border;
    background-color: transparentize($osd_button_bg, 0.15);
  }

  @else if $t==suggested_destructive {
  //
  // suggested or destructive action buttons
  //
    background-clip: border-box;

    color: $actionb_fg;
    background-color: $actionb_bg;
    border-color: darken($actionb_bg, 5%);
  }

  @else if $t==undecorated {
  //
  // reset
  //
    border-color: transparent;
    background-color: transparent;
    background-image: none;
  }
}

//
// Overshoot
//
@mixin overshoot($p, $t:normal, $c:$fg_color) {
//
// overshoot
//
// $p: position
// $t: type
// $c: base color
//
// possible $p values:
// top, bottom, right, left
//
// possible $t values:
// normal, backdrop
//

  $_small_gradient_length: 3%;
  $_big_gradient_length: 50%;

  $_small_gradient_size: 100% $_small_gradient_length;
  $_big_gradient_size: 100% $_big_gradient_length;

  @if $p==right or $p==left {
    $_small_gradient_size: $_small_gradient_length 100%;
    $_big_gradient_size: $_big_gradient_length 100%;
  }

  $_small_gradient_color: $c;
  $_big_gradient_color: transparentize($c, 0.93);

  @if $c==$fg_color {
    $_small_gradient_color: darken($borders_color, 10%);
    $_big_gradient_color: transparentize($fg_color, 0.93);

    @if $t==backdrop { $_small_gradient_color: $backdrop_borders_color; }
  }

  $_small_gradient: radial-gradient(farthest-side at $p,
                                    $_small_gradient_color 85%,
                                    transparentize($_small_gradient_color, 1));

  $_big_gradient: radial-gradient(farthest-side at $p,
                                  $_big_gradient_color,
                                  transparentize($_big_gradient_color, 1));

  @if $t==normal {
    background-image: $_small_gradient, $_big_gradient;
    background-size: $_small_gradient_size, $_big_gradient_size;
  }

  @else if $t==backdrop {
    background-image: $_small_gradient;
    background-size: $_small_gradient_size;
  }

  background-repeat: no-repeat;
  background-position: $p;

  background-color: transparent; // reset some properties to be sure to not inherit them somehow
  border: none;                  //
  box-shadow: none;              //
}

//
// Undershoot
//
@mixin undershoot($p) {
// $p: position
//
// possible $p values:
// top, bottom, right, left
//

  $_undershoot_color_dark: transparentize(black, 0.8);
  $_undershoot_color_light: transparentize(white, 0.8);

  $_gradient_dir: left;
  $_dash_bg_size: 10px 1px;
  $_gradient_repeat: repeat-x;
  $_bg_pos: center $p;

  background-color: transparent; // shouldn't be needed, but better to be sure;

  @if ($p == left) or ($p == right) {
    $_gradient_dir: top;
    $_dash_bg_size: 1px 10px;
    $_gradient_repeat: repeat-y;
    $_bg_pos: $p center;
  }

  background-image: linear-gradient(to $_gradient_dir, // this is the dashed line
                                       $_undershoot_color_light 50%,
                                       $_undershoot_color_dark 50%);

  padding-#{$p}: 1px;
  background-size: $_dash_bg_size;
  background-repeat: $_gradient_repeat;
  background-origin: content-box;
  background-position: $_bg_pos;
  border: none;
}
