$color-primary: #FFC907;
$color-secondary: #29335C;
$color-warning: #ff8f07;
$color-danger: #ff073d;
$color-success: #C2F9BB;

$tablet: 768px;
$mobile: 420px;

.rule-app {
  padding: 2rem;
  position: relative;
  * {
    box-sizing: border-box;
  }
  @media screen and (max-width: $tablet) {
    padding: 2rem .5rem;
  } 
}

.btn {
  border-radius: 4px;
  padding: .2em 1em;

  background-color: transparent;
  border: 1px solid $color-secondary;
  &.has-icon {
    padding-left: .25em;
  }
  &.is-large {
    font-size: 1.2em;
  }
  &.is-loading img {
    animation: rotation 2s infinite linear;
  }
  @keyframes rotation {
    from {
      transform: rotate(0deg);
    }
    to {
      transform: rotate(-359deg);
    }
  }

  &:hover {
    cursor: pointer;
    color: $color-secondary;
    border-color: black;
  }
  &.primary {
    background-color: $color-primary;
    color:darken($color-primary, 80%);
    border: 1px solid darken($color-primary, 10%);
    &:hover {
      cursor: pointer;
      background-color: darken($color-primary, 10%);
    }
  }
  &.warn {
    background-color: $color-warning;
    color:darken($color-warning, 80%);
    border: 1px solid darken($color-warning, 10%);
    &:hover {
      cursor: pointer;
      background-color: darken($color-warning, 10%);
    }
  }
  &.danger {
    background-color: $color-danger;
    color:darken($color-danger, 80%);
    border: 1px solid darken($color-danger, 10%);
    &:hover {
      cursor: pointer;
      background-color: darken($color-danger, 10%);
    }
  }
  &.success {
    background-color: $color-success;
    color:darken($color-success, 80%);
    border: 1px solid darken($color-success, 10%);
    &:hover {
      cursor: pointer;
      background-color: darken($color-success, 10%);
    }
  }
}

.btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin: 1rem 0;
}

.btn {
  position: relative;
  .btn-cover {
    position: absolute;
    font-size: 0.6em;
    background-color: $color-warning;
    width: 110%;
    top: 30%;
    left: -10px;
    box-shadow: 1px 1px 3px #0003;
    transform: rotate(0deg) scale(.01);
    transition: all 0.3s ease;
  }
  &:hover .btn-cover {
    transform: rotate(5deg) scale(1);
  }
}

h1 .icon img {
  width: 50px;
}

h2 .icon img {
  width: 40px;
}

.label {
  display: block;
  flex: 1 1 auto;

  &>span {
    display: block;
  }

  input[type='text'],
  textarea {
    font-size: 1.2rem;
    font-family: monospace;
    margin: .5rem 0 1rem;
    padding: .25rem;
    width: 100%;
  }

  textarea {
    max-width: 65ch;
  }

  input.input-stack {
    margin-bottom: 0;
  }

  small {
    color: #aaa;
  }
}

.label-group {
  display: flex;
  gap: 1rem;
  @media screen and (max-width: $tablet) {
    &:not(.is-mobile){
      gap: 0;
      flex-direction: column;
    }
  }
  @media screen and (max-width: $mobile) {
    gap: 0;
    flex-direction: column;
  }
}

.dropdown {
  $dropdown-border-radius: 4px;
  cursor: pointer;
  flex-direction: column;
  background-color: #fff;
  padding: 2px;
  border-radius: $dropdown-border-radius;

  input[type='radio'] {
    display: none;
  }
  label {
    cursor: pointer;
  }
  label div {
    display: inline-flex;
    padding: 2px;
  }
  input[type='radio']:checked ~ div {
    background-color: $color-primary;
    border-radius: $dropdown-border-radius;
  }

  @media screen and (max-width: $tablet) {
    display: grid;
    grid-template-columns: repeat( auto-fit, minmax(50px, 1fr) );
    
    label.default {
      display: none;
    }
  }

  @media screen and (min-width: $tablet) {
    position: absolute;

    label:not(.selected) {
      display: none;
    }

    &:hover {
      border: 1px solid #ddd;
      box-shadow: 1px 1px 5px #0003;
      display: grid;
      grid-template-columns: 1fr 1fr 1fr;
      label {
        display: block;

        &:hover:not(.selected) div {
          background-color: #ddd;
          border-radius: $dropdown-border-radius;
        }
      }
    }

    &:hover label.default,
    label.selected ~ label.default {
      display: none;
    }
    label.default {
      display: block;
    }
  }
}

.editor .details {
  .label .dropdown {
    margin-top: calc(.5rem - 2px);
    img {
      width: 30px;
    }
    @media screen and (min-width: $tablet) {
      &:hover {
        grid-template-columns: repeat(4, 1fr);
        z-index: 100;
      }
    }
  }
}

.rule__modules {
  border: 4px dashed $color-primary;
  margin: 1rem 0;
  position: relative;
  @media screen and (max-width: $tablet) {
    margin: 1rem -0.75rem;
  }

  &.target {
    background-color: $color-primary;
  }

  .modules__dropzone {
    padding: 1.25rem 1rem 1rem;
    .module.drag-over {
      background-color: $color-primary;
      border-style: dashed;
    }
  }

  label {
    position: absolute;
    top: -1rem;
    left: 1rem;
    background: $color-primary;
    padding: 0.25rem .5rem;
    border-radius: 3px;
    font-size: 0.8rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }
}

.module-editor__wrapper {
  background-color: #fff;
  border: 1px solid #ccc;
  border-radius: 3px;
  box-shadow: 0 0 5px #0002;
  margin: 2rem 0 1rem;
  padding: 1rem;
  position: relative;

  .module-editor {
    display: flex;
    flex-direction: row-reverse;
    justify-content: space-between;
    padding-top: .5rem;
    .module-editor__right {
      position: absolute;
      top: -1.2rem;
      right: 1rem;
    }
    .module-editor__fields {
      flex: 1 1 auto;
    }
    .label {
      font-size: 0.8em;
      input,
      textarea {
        font-size: 1rem;
        margin-top: 0;
      }
    }
  }
  
  .module-editor__label {
    position: absolute;
    top: -1rem;
    left: 1rem;
    background: #fff;
  }
}

.module {
  align-items: center;
  display: inline-flex;
  gap: 0.5rem;
  margin: 0;
  padding: .25rem;
  flex-wrap: wrap;

  &.in-editor {
    background-color: $color-primary;
  }

  .submodules {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
  }

  .module__grain {
    display: none;
    opacity: .3;
    cursor: grab;
  }

  &.mouse-over > .module__icon-wrapper {
    & > .module__grain {
      display: block;
      opacity: 1;
    }
    & > .module__icon {
      display: none;
    }
  }

  &.module--edit {
    font-family: monospace;
    padding: 0;
    input {
      width: fit-content;
      margin: 0;
      padding: 0.25rem
    }
  }
}

.modules__grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.modules {
  .modules__type {
    margin-bottom: 1rem;
  }
  h2 {
    margin-bottom: 0;

    &::first-letter {
      text-transform: capitalize;
    }
  }
  .modules__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    a {
      cursor: pointer;
    }
  }
}

.rule {
  .rule__creator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    border-top: 1px solid #ccc;
    margin-top: 2rem;
    padding-top: 2rem;
  }
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  .tab__control {
    cursor: pointer;
    border: 1px solid #ccc;
    border-bottom: none;
    background-color: #ccc;
    padding: .5rem 1rem;
    text-align: center;
    flex: 1 1 auto;
    &.active {
      background-color: #fff;
      margin-bottom: -1px;
    }
  }
  @media screen and (max-width: $tablet) {
    gap:.5rem;
    font-size: 0.8rem;
    .tab__control img {
      display: block;
      margin: 0 auto;
    }
  }
  @media screen and (max-width: 550px) {
    gap: 0;
  }

}
.tab__pane {
  border: 1px solid #ccc;
  padding: 1rem;
  margin-bottom: 2rem;
}

.app-wrapper.is-preview {
  max-width: 65ch;
  margin: 0 auto;
}

.editor,
.rule {
  border: 1px solid #ccc;
  border-radius: 3px;
  background-color: #fff;
  margin: 0 auto;
  padding: 2rem;
  position: relative;
  .controls {
    position: absolute;
    top: -1rem;
    right: 2rem;
  }
  @media screen and (max-width: $tablet) {
    padding: 1.5rem 1rem 1rem;
  }
  @media screen and (max-width: $mobile) {
    font-size: 90%;
  }
}

.editor {

}
.rule {
  .modules__grid {
    padding: 1rem 0;
  }

  .module-list {
    margin-bottom: 1rem;
    &, & ul { margin-left: 30px; }
    .submodules { margin-bottom: 1rem;}
    .module-list-item {
      list-style: none;
      position: relative;
      .module__icon {
        position: absolute;
        left:-30px;
        top:-3px;
      }
    }
  }
}

.json {
  white-space: pre-wrap;
}

.legacy {
  .module {
    img,
    a {
      display: none;
    }
  }
}