@use "atomic/positioning";
@use "atomic/coordinates";
@use "atomic/border-radius";
@use "atomic/spacing";
@use "atomic/sizes";
@use "utils/variables";
@use "utils/helpers";
@use "_layout";

@import "utils/sizes";

:root {
  @each $key, $value in $sizes {
    --spacing-#{$key}: #{$value};
  }

  @include variables.main;

  .dark {
    @include variables.dark-theme;
  }

  .light {
    @include variables.light-theme;
  }
}

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

body {
  margin: 0 auto;
  max-width: 969px;
  padding: var(--spacing-m);
  font-family: var(--font);
  line-height: 1.4;
  color: var(--text-color);
  background: var(--bg-color);
}

.shrink {
  flex: 2 2;
}

input,
textarea {
  outline: none;
  border: none;
  border-radius: var(--spacing-2xs);
  background: var(--sub-alt-color);
  color: var(--text-color);
  padding: 0.5em;
  font-size: 1em;
  font-family: var(--font);
  caret-color: var(--main-color);
  line-height: 1.25em;
  &:disabled {
    opacity: 0.3;
  }
}

input:focus-visible,
textarea:focus-visible {
  box-shadow:
    0 0 0 0.1rem var(--bg-color),
    0 0 0 0.2rem var(--text-color);
}

textarea {
  resize: vertical;
  width: 100%;
  padding: 10px;
  line-height: 1.2rem;
  min-height: 3rem;
  max-height: 16rem;
}

:autofill,
:-webkit-autofill,
:-webkit-autofill:hover,
:-webkit-autofill:focus,
:-webkit-autofill:active {
  -webkit-text-fill-color: var(--text-color);
  -webkit-box-shadow: 0 0 0 1000px var(--sub-alt-color) inset !important;
  -webkit-background-clip: text !important;
  background-clip: text !important;
}

::-moz-selection {
  background: var(--text-color);
  color: var(--sub-alt-color);
}

::selection {
  background-color: var(--main-color);
  color: var(--sub-alt-color);
}

blockquote {
  border-left: 4px solid var(--main-color);
  margin: 0;
  padding: 0.5rem 1rem;
  font-style: italic;
}

blockquote > footer {
  margin-left: var(--spacing-xs);
  margin-top: var(--spacing-xs);
  font-style: normal;
  font-size: 0.8rem;
  color: var(--main-color);
  border: 0;
}

blockquote cite {
  font-style: normal;
}

h1 {
  font-size: 1.8rem;
  margin: 0;
}

h1,
h2,
h3,
h4,
h5,
h6,
p {
  margin: 0;
}

h1,
h2,
h3,
h4,
h5,
h6,
strong {
  margin: 0;
}

h1,
h2,
h3,
h4,
h5,
h6,
b,
strong,
th {
  font-weight: 600;
}

abbr[title] {
  border-bottom: 1px dotted;
  text-decoration: none;
  cursor: help;
}

small {
  font-size: x-small;
}

sub {
  font-size: x-small;
}

sup {
  font-size: x-small;
}

var {
  font-size: small;
}

ol,
ul,
dl {
  margin: 0;
}

dt {
  font-size: large;
  font-weight: 600;
}

dd {
  margin-left: var(--spacing-28px);
  margin-top: var(--spacing-10px);
}

mark {
  background-color: var(--highlight);
  border-radius: var(--spacing-4px);
  padding: var(--spacing-px);
  color: var(--black);
}

kbd {
  color: var(--bg-color);
  background-color: var(--sub-color);
  border-radius: var(--spacing-2px);
  padding: 0.2rem 0.3rem;
  margin: 0;
  display: inline-block;
  font-size: 0.7rem;
  line-height: 0.7rem;
}

.textButton {
  text-decoration: none;
  font-size: 0.75rem;
  line-height: 1rem;
}

button,
.button,
input[type="button"],
input[type="reset"],
input[type="submit"] {
  text-align: center;
  color: var(--text-color);
  cursor: pointer;
  transition:
    background 0.125s,
    color 0.125s,
    opacity 0.125s;
  padding: 0.5em;
  border-radius: var(--spacing-xs);
  background: var(--sub-alt-color);
  text-align: center;
  -webkit-user-select: none;
  user-select: none;
  align-content: center;
  height: -moz-min-content;
  height: min-content;
  line-height: 1.25;
  appearance: none;
  border: none;
  font-family: inherit;
  font-size: 1em;
  display: inline-flex;
  gap: 0.5em;
  align-items: baseline;
  justify-content: center;

  &.outline {
    @include helpers.outline-property-basis(text);

    &.success {
      @include helpers.outline-property-basis(success);

      &:hover {
        border: 2px solid var(--success-color);
        background: var(--success-color);
        color: var(--bg-color);
      }
    }
    &.info {
      @include helpers.outline-property-basis(info);

      &:hover {
        border: 2px solid var(--info-color);
        background: var(--info-color);
        color: var(--bg-color);
      }
    }
    &.danger {
      @include helpers.outline-property-basis(error);

      &:hover {
        border: 2px solid var(--error-color);
        background: var(--error-color);
        color: var(--bg-color);
      }
    }
  }

  &.text {
    background: var(--bg-color);
    color: var(--text-color);
    &:hover {
      color: var(--text-color);
      background: var(--sub-alt-color);
    }
    &:active {
      opacity: 0.8;
      color: var(--text-color);
    }
  }

  &.link {
    background: none;
    color: var(--sub-color);

    &:hover {
      background: none;
      color: var(--text-color);
    }
    &:active {
      color: var(--sub-color);
    }
  }

  &.active {
    background: var(--main-color);
    color: var(--bg-color);
    &:hover {
      background: var(--text-color);
    }
    &:active {
      background: var(--sub-color);
      color: var(--bg-color);
    }
  }

  @include helpers.button-style(success);
  @include helpers.button-style(info);
  @include helpers.button-style(error);

  &[disabled],
  &.disabled {
    opacity: 0.33;
    pointer-events: none;

    &:hover {
      background: var(--text-color);
      outline: none;
    }
    &:active {
      background: var(--sub-color);
      color: var(--bg-color);
    }
  }

  &:hover {
    color: var(--bg-color);
    background: var(--text-color);
    outline: none;
  }
  &:focus-visible {
    box-shadow:
      0 0 0 0.1rem var(--bg-color),
      0 0 0 0.2rem var(--text-color);
    outline: none;
  }
  &:active {
    background: var(--sub-color);
    color: var(--bg-color);
  }
  &[smallest] {
    padding: 0.3rem 0.5rem;
    font-size: 0.65rem;
  }
  &[small] {
    padding: 0.3rem 0.6rem;
    font-size: 0.9rem;
  }
  &[large] {
    padding: 0.4rem 0.8rem;
    font-size: 1.5rem;
  }
  &[largest] {
    padding: 0.6rem 1.2rem;
    font-size: 1.7rem;
  }
}

a {
  display: inline-block;
  color: var(--sub-color);
  transition:
    color 0.125s,
    opacity 0.125s,
    background 0.125s;

  &.text,
  &.button {
    height: min-content;
    line-height: 1.25;
    display: inline-flex;
    gap: 0.5em;
    text-decoration: none;
    align-items: center;
    &:focus-visible {
      border-radius: var(--spacing-xs);
    }
  }
  &:hover {
    color: var(--text-color);
  }
  &:focus-visible {
    outline: none;
    box-shadow:
      0 0 0 0.1rem var(--bg-color),
      0 0 0 0.2rem var(--text-color);
    border-radius: calc(var(--spacing-xs) / 2);
  }
}

fieldset {
  border: none;
  padding: 0;
  margin: 0;
}

fieldset[bordered] {
  border: 2px solid var(--main-color);
  border-radius: var(--spacing-6px);
  padding: 10px;
}

legend {
  margin-bottom: var(--spacing-8px);
}

label {
  width: fit-content;
  display: block;
}

label:has([type="checkbox"], [type="radio"]) {
  cursor: pointer;
}

label:has([type="checkbox"]:disabled, [type="radio"]:disabled) {
  cursor: default;
  opacity: 0.3;
}

input[type="checkbox"]:indeterminate,
input[type="radio"]:indeterminate {
  opacity: 0.5;
}

input[type="checkbox"] {
  @include helpers.checkbox-and-radio-style();
  border-radius: var(--spacing-4px);
}

input[type="radio"] {
  @include helpers.checkbox-and-radio-style();
  border-radius: 100%;
}

[type="checkbox"] ~ label,
[type="radio"] ~ label {
  margin-bottom: 0;
  display: inline-block;
  cursor: pointer;
  &:disabled {
    opacity: 0.3;
  }
}

[type="checkbox"]:disabled ~ label,
[type="radio"]:disabled ~ label {
  opacity: 0.3;
}
