/* -------------------------------- 

File#: _1_custom-checkbox
Title: Custom Checkbox
Descr: Replace the native checkbox button with a custom element (e.g., an icon)
Usage: codyhouse.co/license

-------------------------------- */
/* reset */
*, *::after, *::before {
  box-sizing: border-box;
}

* {
  font: inherit;
  margin: 0;
  padding: 0;
  border: 0;
}

body {
  background-color: hsl(0, 0%, 100%);
  font-family: system-ui, sans-serif;
  color: hsl(230, 7%, 23%);
  font-size: 1rem;
}

h1, h2, h3, h4 {
  line-height: 1.2;
  color: hsl(230, 13%, 9%);
  font-weight: 700;
}

h1 {
  font-size: 2.0736rem;
}

h2 {
  font-size: 1.728rem;
}

h3 {
  font-size: 1.25rem;
}

h4 {
  font-size: 1.2rem;
}

ol, ul, menu {
  list-style: none;
}

button, input, textarea, select {
  background-color: transparent;
  border-radius: 0;
  color: inherit;
  line-height: inherit;
  appearance: none;
}

textarea {
  resize: vertical;
  overflow: auto;
  vertical-align: top;
}

a {
  color: hsl(250, 84%, 54%);
}

table {
  border-collapse: collapse;
  border-spacing: 0;
}

img, video, svg {
  display: block;
  max-width: 100%;
}

@media (min-width: 64rem) {
  body {
    font-size: 1.25rem;
  }

  h1 {
    font-size: 3.051rem;
  }

    h2 {
    font-size: 2.44rem;
  }

    h3 {
    font-size: 1.75rem;
  }

    h4 {
    font-size: 1.5625rem;
  }
}

/* variables */
:root {
  /* colors */
  --cs6-color-primary-hsl: 250, 84%, 54%;
  --cs6-color-bg-hsl: 0, 0%, 100%;
  --cs6-color-contrast-high-hsl: 230, 7%, 23%;
  --cs6-color-contrast-higher-hsl: 230, 13%, 9%;
  --cs6-color-contrast-low-hsl: 240, 4%, 65%;
}

/* icons */
.cs6-icon {
  height: var(--cs6-size, 1em);
  width: var(--cs6-size, 1em);
  display: inline-block;
  color: inherit;
  fill: currentColor;
  line-height: 1;
  flex-shrink: 0;
  max-width: initial;
}

/* component */
:root {
  --custom-checkbox-size: 20px;
  --custom-checkbox-radius: 4px;
  --custom-checkbox-border-width: 1px;
  --custom-checkbox-marker-size: 18px;
}

.custom-checkbox {
  position: relative;
  z-index: 1;
  display: inline-block;
  font-size: var(--custom-checkbox-size);
}

.custom-checkbox__input {
  position: relative;
  /* hide native input */
  margin: 0;
  padding: 0;
  opacity: 0;
  height: 1em;
  width: 1em;
  display: block;
  z-index: 1;
}

.custom-checkbox__control {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0px;
  left: 0;
  z-index: -1;
  pointer-events: none;
  transition: -webkit-transform 0.2s;
  transition: transform 0.2s;
  transition: transform 0.2s, -webkit-transform 0.2s;
  color: hsla(var(--cs6-color-contrast-low-hsl), 0.65);
  /* unchecked color */
}
.custom-checkbox__control::before, .custom-checkbox__control::after {
  content: "";
  position: absolute;
}
.custom-checkbox__control::before {
  /* focus circle */
  width: 160%;
  height: 160%;
  background-color: currentColor;
  top: 50%;
  left: 50%;
  -webkit-transform: translate(-50%, -50%) scale(0);
  transform: translate(-50%, -50%) scale(0);
  opacity: 0;
  border-radius: 50%;
  will-change: transform;
  transition: -webkit-transform 0.2s;
  transition: transform 0.2s;
  transition: transform 0.2s, -webkit-transform 0.2s;
}
.custom-checkbox__control::after {
  /* custom checkbox */
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  /* custom checkbox style */
  background-color: hsl(var(--cs6-color-bg-hsl));
  border-radius: var(--custom-checkbox-radius);
  box-shadow: inset 0 0 0 var(--custom-checkbox-border-width) currentColor, 0 0.1px 0.3px rgba(0, 0, 0, 0.06),0 1px 2px rgba(0, 0, 0, 0.12);
  /* border */
}

.custom-checkbox__input:checked ~ .custom-checkbox__control::after,
.custom-checkbox__input:indeterminate ~ .custom-checkbox__control::after {
  background-color: currentColor;
  background-repeat: no-repeat;
  background-position: center;
  background-size: var(--custom-checkbox-marker-size);
  box-shadow: none;
}

.custom-checkbox__input:checked ~ .custom-checkbox__control {
  color: var(--color-success-dark);
  /* checked color */
}
.custom-checkbox__input:checked ~ .custom-checkbox__control::after {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpolyline points='2.5 8 6.5 12 13.5 3' fill='none' stroke='%23fff' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5'/%3E%3C/svg%3E");
}

.custom-checkbox__input:indeterminate ~ .custom-checkbox__control::after {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cline x1='2' y1='8' x2='14' y2='8' fill='none' stroke='%23fff' stroke-linecap='round' stroke-linejoin='round' stroke-width='2'/%3E%3C/svg%3E");
}

.custom-checkbox__input:active ~ .custom-checkbox__control {
  -webkit-transform: scale(0.9);
          transform: scale(0.9);
}

.custom-checkbox__input:checked:active ~ .custom-checkbox__control,
.custom-checkbox__input:indeterminate:active ~ .custom-checkbox__control {
  -webkit-transform: scale(1);
          transform: scale(1);
}

.custom-checkbox__input:focus ~ .custom-checkbox__control::before {
  opacity: 0.2;
  -webkit-transform: translate(-50%, -50%) scale(1);
          transform: translate(-50%, -50%) scale(1);
}

/* --icon */
.custom-checkbox--icon {
  --custom-checkbox-size: 32px;
}
.custom-checkbox--icon .custom-checkbox__control::after {
  display: none;
}
.custom-checkbox--icon svg {
  display: block;
  color: inherit;
  position: relative;
  z-index: 1;
  top: -2px;
  right: 1px;
}