/* ========================================
   Layout & Components
   ======================================== */

/* Branding */
.branding {
  position: fixed;
  top: var(--sp-5);
  left: var(--sp-5);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);

  & .branding-title {
    display: flex;
    flex-direction: column;
    font-size: 1.5em;
  }

  & .branding-logo {
    display: inline-block;
    width: 0.85em;
    height: 0.85em;
    margin-left: 0.2em;
    background: url('../imgs/mindset.png') center / contain no-repeat;
    vertical-align: middle;
  }

  & .branding-link {
    color: rgba(var(--fh__txt), 0.4);
    text-decoration: none;
    transition: var(--act-transition);

    &:hover {
      color: rgba(var(--fh__txt), 0.6);
    }
  }
}

/* Toolbar */
.toolbar {
  position: fixed;
  top: var(--sp-4);
  right: var(--sp-4);
  width: 17em;
  max-height: calc(100% - var(--sp-3) * 2);
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: calc(var(--sp-4) / 4);
}

/* Workspace & Canvas */
.workspace {
  width: 100dvw;
  max-height: 100dvh;
}

.canvas-container {
  width: 100%;
  height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: var(--sp-4);

  & #resultCanvas {
    max-width: 100%;
    max-height: 80vh;
  }
}

/* ========================================
   Components
   ======================================== */

/* Range Slider */
.range-slider-wrapper {
  width: 100%;
  height: var(--sp-11);
  padding: var(--sp-4);
  position: relative;
  background-color: rgba(var(--fh__accent), 0.1);
  border-radius: var(--rd-lg);
  display: flex;
  justify-content: space-between;
  cursor: ew-resize;
  transform-origin: center;
  overflow: hidden;
  user-select: none;
  transition: var(--deact-transition);

  & > * {
    pointer-events: auto;
    z-index: 1;
  }

  & .range-fill {
    position: absolute;
    top: 0;
    left: 0;
    min-height: 100%;
    width: 22%;
    background-color: rgba(var(--fh__accent), 0.1);
    transition: var(--deact-transition);
    z-index: 0;
    pointer-events: none;
  }

  & .range-label {
    position: absolute;
    left: var(--sp-4);
    top: calc(var(--sp-4) - var(--sp-1));
    transition: var(--deact-transition);
  }
  & .range-value {
  
    transition: var(--deact-transition);
  }
  & .range-values {
    position: absolute;
    left: var(--sp-4);
    bottom: calc(var(--sp-4) - var(--sp-1));
    right: var(--sp-4);
    display: flex;
    flex-direction: row;
    justify-content: space-between;
  }

  & .range-label {
    opacity: 1;
  }

  & .range-min,
  & .range-max {
    color: rgba(var(--fh__txt), 0.4);
  }
}

/* File Input */
.file-input-wrapper {
  width: 100%;
  aspect-ratio: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: var(--sp-4);
  border-radius: var(--rd-xl);
  overflow: hidden;
  cursor: pointer;

  &:hover .input-btn:not(.pressed) {
    transform: translate(-50%, -50%) scale(1.2);
  }
  & .item-head {
    font-size: 1.4em;
    color: rgba(var(--fh__txt), 0.4);
  }

  & .file-preview {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(1.2);
    width: 100%;
    height: 100%;
    filter: blur(20px);
    z-index: -1;
  }

  & .img-data {
    display: flex;
    flex-direction: column;

    & .img-name {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      max-width: 100%;
    }

    & .img-weight {
      color: rgba(var(--fh__txt), 0.4);
    }
  }

  & .input-btn {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: var(--sp-8);
    height: var(--sp-8);
    border-radius: var(--rd-full);
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(var(--fh__accent), 0.2);
    transition: var(--act-transition);
    pointer-events: none;

    &.pressed {
      transform: translate(-50%, -50%) scale(0.9);
    }

    & input {
      position: absolute;
      width: 100%;
      height: 100%;
      opacity: 0;
      cursor: pointer;
      z-index: 2;
      pointer-events: auto;
    }

    & svg {
      width: var(--sp-4);
      height: var(--sp-4);
      pointer-events: none;
      z-index: 1;
    }
  }
}

/* File Input Label (Upload Texture) */
.file-input-label {
  padding: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  width: 100%;
  border-radius: var(--rd-xl);
  background-color: rgba(var(--fh__accent), 0.1);
  cursor: pointer;
  transition: var(--act-transition);

  & span {
    color: rgba(var(--fh__txt), 0.4);
  }

  &:hover {
    background-color: rgba(var(--fh__accent), 0.15);
  }
}

/* Selector */
.selector-wrapper {
  width: 100%;
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: visible;
  cursor: pointer;

  & .sel-body {
    position: relative;
  }

  & .sel-trigger {
    padding: var(--sp-4);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-2);
    border-radius: var(--rd-xl);
    background-color: rgba(var(--fh__accent), 0.1);
    transition: var(--act-transition);
    user-select: none;

    &.pressed {
      transform: scale(0.975);
    }
  }

  & .sel-arrow {
    color: rgba(var(--fh__txt), 0.4);
    transition: var(--act-transition);
    flex-shrink: 0;
  }

  & .sel-list.opened ~ .sel-trigger .sel-arrow,
  &:has(.sel-list.opened) .sel-arrow {
    transform: rotate(180deg);
  }

  & .sel-list {
    position: absolute;
    top: 100%;
    left: calc(var(--sp-1) * -1);
    right: calc(var(--sp-1) * -1);
    margin-top: var(--sp-1);
    padding: var(--sp-1);
    padding-top: var(--sp-2);
    border-radius: var(--rd-xl);
    background-color: #252525;
    z-index: 32;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: scale(0.975);
    transform-origin: top center;
    transition: var(--deact-transition);
    display: flex;
    flex-direction: column;

    &.opened {
      opacity: 1;
      visibility: visible;
      pointer-events: auto;
      transform: scale(1);
      transition: var(--act-transition);
    }

    & > .sel-head,
    & > .sel-item {
      opacity: 0.7;
      transform: translateY(calc(var(--sp-2) * -1));
      transition: var(--deact-transition);
      transition-delay: calc(var(--item-index, 0) * 0.04s);
    }

    &.opened > .sel-head,
    &.opened > .sel-item {
      opacity: 1;
      transform: translateY(0);
      transition: var(--act-transition);
      transition-delay: calc(var(--item-index, 0) * 0.02s);
    }
  }

  & .sel-head {
    padding: var(--sp-3) var(--sp-4);
    color: rgba(var(--fh__txt), 0.4);
    user-select: none;
  }

  & .sel-item {
    padding: var(--sp-3) var(--sp-4);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-2);
    border-radius: calc(var(--rd-xl) - var(--sp-1));
    user-select: none;

    &:hover {
      background-color: rgba(var(--fh__accent), 0.1);
    }

    &.selected {
      color: rgba(var(--fh__txt), 0.6);
    }
  }
}

/* Pattern Selector */
.pattern-selector {
  width: 100%;
  aspect-ratio: 1;
  padding: var(--sp-4);
  border-radius: var(--rd-xl);
  background-color: rgba(var(--fh__accent), 0.1);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;

  & .pattern-header {
    display: flex;
    flex-direction: column;
    font-size: 1.4em;
  }

  & .pattern-label {
    color: rgba(var(--fh__txt), 0.6);
  }

  & .pattern-preview {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;

    & img {
      width: var(--sp-7);
      height: var(--sp-7);
      object-fit: contain;
      image-rendering: pixelated;
      filter: invert(1)
    }
  }

  & .pattern-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  & .pattern-arrow {
    width: var(--sp-5);
    height: var(--sp-5);
    border-radius: var(--rd-full);
    border: none;
    background: transparent;
    color: rgba(var(--fh__txt), 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--act-transition);

    &:hover {
      color: rgba(var(--fh__txt), 1);
    }

    &:active {
      transform: scale(0.9);
    }
  }

  & .pattern-counter {
    display: flex;
    align-items: center;
    gap: var(--sp-1);
  }

  & .pattern-sep {
    color: rgba(var(--fh__txt), 0.3);
  }

  & .pattern-data {
    display: none;
  }
}

/* Export Button */
.download-btn {
  padding: var(--sp-3) var(--sp-4);
  width: fit-content;
  border: none;
  border-radius: var(--rd-xl);
  background: rgba(var(--fh__txt), 1);
  color: rgba(var(--fh__txt-invert), 1);
  cursor: pointer;
  transition: var(--act-transition);

  &:hover {
    background: rgba(var(--fh__accent), 1);
  }

  &:active {
    transform: scale(0.975);
  }
}
