@use "./wiiu.scss";

$checkbox-unchecked: url("data:image/svg+xml,%3Csvg width='128' height='128' viewBox='0 0 128 128' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Crect width='128' height='128' rx='27' fill='%23FF5C4A'/%3E%3Cpath d='M88 40L40 88' stroke='white' stroke-width='14' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M40 40L88 88' stroke='white' stroke-width='14' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
$checkbox-checked: url("data:image/svg+xml,%3Csvg width='128' height='128' viewBox='0 0 128 128' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Crect width='128' height='128' rx='27' fill='%2300BF50'/%3E%3Cpath d='M100 38L50.5 88L28 65.2727' stroke='white' stroke-width='14' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");

@font-face {
  font-family: "NTLG";
  src: url("../assets/fonts/NTLG.woff2");
  font-display: swap;
}

html,
body {
  background-color: white;
  color: #000;
  font-family: "NTLG", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;

  width: 100%;
  height: 100%;
  margin: 0;

  --eye-color: #6c7070;
  --selection-color: rgb(0, 145, 255);
  --primary-color: rgb(87, 199, 255);
  --error-color: rgb(255, 96, 87);
  --gold-color: rgb(255, 191, 0);

  font-size: 16px;

  // iOS
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;

  &[data-theme="default"] {
    &,
    & > body {
      background-image: url("../assets/images/main_bg.svg");
      background-size: cover;
      background-position: center;
      background-repeat: no-repeat;
    }
  }

  // UI colors
  --root: #ffffffee;
  --text: #000000;
  --label: #666666;
  --stroke: #dddddd;
  --stroke-dim: #e8e8e8;
  --stroke-rgb: 221, 221, 221;
  --container: #eeeeee77;
  --container-solid: #eeeeee;
  --sub-container: #ececec77;
  --hover: #dddddd;
  --hover-transparent: #dddddd77;
  --focus: #e7e7e7ee;

  --icon-face-fill: #ffffff;
  --icon-face-stroke: #6f6f6f;
  --icon-face-detail: #8d8d8d;
  --icon-face-makeup: #ffbaba;
  --icon-face-wrinkles: #996d54;
  --icon-head-fill: #ffffff;
  --icon-head-stroke: #999999;
  --icon-hair-fill: currentColor;
  --icon-eyebrow-fill: currentColor;
  --icon-facial-hair-fill: currentColor;
  --icon-mouth-tooth: #ffffff;
  --icon-glasses-fill: #000000;
  --icon-glasses-shade: #606060;
  --icon-lip-color-top: #712a04;
  --icon-lip-color-bottom: #be4e26;

  @media (prefers-color-scheme: dark) {
    color: white;

    --eye-color: #6c7070;
    --selection-color: rgb(0, 145, 255);
    --primary-color: rgb(23, 96, 118);
    --error-color: rgb(255, 96, 87);
    --gold-color: rgb(255, 191, 0);

    // UI colors
    --root: #000000ee;
    --text: #ffffff;
    --label: #cccccc;
    --stroke: #484848;
    --stroke-dim: #333333;
    --stroke-rgb: 102, 102, 102;
    --container: #2a2d2f77;
    --container-solid: #2a2d2f;
    --sub-container: #1d1f2077;
    --hover: #2d3336;
    --hover-transparent: #2d333677;
    --focus: #2e363aee;

    --icon-face-fill: #000000;
    --icon-face-stroke: #ffffff;
    --icon-face-detail: #ffffff;
    --icon-face-makeup: #ffbaba;
    --icon-face-wrinkles: #996d54;
    --icon-head-fill: #333333;
    --icon-head-stroke: #474747;
    --icon-hair-fill: currentColor;
    --icon-eyebrow-fill: currentColor;
    --icon-facial-hair-fill: currentColor;
    --icon-mouth-tooth: #000000;
    --icon-glasses-fill: #ffffff;
    --icon-glasses-shade: #606060;
    --icon-lip-color-top: #712a04;
    --icon-lip-color-bottom: #be4e26;
  }

  @supports not selector(::-webkit-scrollbar) {
    scrollbar-color: var(--label) var(--container);
    scrollbar-width: thin;
  }
}

.modal-body small {
  margin: -6px 0;
}
small {
  color: var(--label);
}

button.danger {
  background-color: var(--error-color);
  border-color: var(--stroke-dim);
  &:hover {
    background-color: var(--error-color);
    filter: brightness(1.3);
  }
}
button.primary {
  background-color: var(--primary-color);
  border-color: var(--stroke-dim);
  &:hover {
    background-color: var(--primary-color);
    filter: brightness(1.3);
  }
}
button.selected {
  border: 0.1rem solid var(--selection-color);
}
button.selected-setting {
  border: 0.1rem solid var(--selection-color);
  background-color: var(--selection-color);
}

.h4 {
  font-size: 1.2rem;
  font-weight: 550;
  color: var(--text);
}
.pre-wrap {
  overflow: auto;
  user-select: all;
  -webkit-user-select: all;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.mb-0 {
  margin-bottom: 0;
}
[disabled] {
  opacity: 0.5 !important;
}

a,
a:visited {
  color: var(--selection-color);
  text-decoration: underline;
  &:hover {
    filter: brightness(1.3);
  }
}
* {
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
}
div::-webkit-scrollbar {
  width: 12px !important;
  background-color: transparent !important;
  height: 6px !important;
}
div::-webkit-scrollbar-thumb {
  border-radius: 10px !important;
  background-color: var(--label) !important;
}
div::-webkit-scrollbar-track {
  -webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3) !important;
  border-radius: 10px !important;
  background-color: transparent !important;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  font-weight: 550;
  margin: 0;
}

$animation-duration: 0.8s;
$easing-function: cubic-bezier(0.16, 1, 0.3, 1);
$tabletWidth: 960px;
$desktopWidth: 1280px;

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
@keyframes shortSlideUp {
  from {
    transform: translateY(-25%);
  }
  to {
    transform: translateY(0);
  }
}
@keyframes fadeOut {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}
@keyframes shortSlideDown {
  from {
    transform: translateY(0);
  }
  to {
    transform: translateY(25%);
  }
}
@keyframes spinTranslated {
  from {
    transform: translate(-50%, -50%) rotate(0deg);
  }
  to {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}
@keyframes spinInPlaceAndCry {
  from {
    transform: rotate(0deg) scale(1);
    opacity: 1;
  }
  to {
    transform: rotate(360deg) scale(0);
    opacity: 0;
  }
}

.rotateAndCry {
  animation: spinInPlaceAndCry 2s cubic-bezier(0.075, 0.82, 0.165, 1) forwards;
}

.modal-selectable {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  .modal-body {
    > span {
      user-select: auto !important;
    }
  }
}
.modal {
  position: fixed;
  width: 100%;
  height: 100%;
  background-color: #0009;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 999999999;
  top: 0;
  left: 0;
  animation: fadeIn $animation-duration $easing-function;
  &.closing {
    animation: fadeOut $animation-duration $easing-function;
    // pointer-events: none !important;
    .modal-content {
      animation: shortSlideDown $animation-duration $easing-function forwards;
    }
  }
  .modal-content {
    display: flex;
    flex-direction: column;
    border: 2px solid var(--stroke);
    border-radius: 8px;
    min-width: 200px;
    min-height: 140px;
    // max-width: 480px;
    max-height: 440px;
    overflow: clip;
    animation: shortSlideUp $animation-duration $easing-function;
    .modal-header {
      padding: 8px;
      display: flex;
      justify-content: center;
      background-color: var(--hover);
      flex-shrink: 0;
      border-radius: 5px 5px 0 0;
      position: relative;
      .close-button {
        background: var(--error-color);
        &:hover {
          filter: brightness(0.8);
        }
        border-width: 0.1rem;
        border-radius: 50%;
        width: 1.25rem;
        height: 1.25rem;
        padding: 0;
        min-width: 0;
        position: absolute;
        top: 50%;
        right: 0.5rem;
        transform: translateY(-50%);
      }
    }
    .modal-body {
      padding: 16px 18px;
      background-color: var(--root);
      height: 100%;
      flex: 1;
      display: flex;
      flex-direction: column;
      gap: 16px;
      border-radius: 0 0 5px 5px;
      overflow: auto;
      > span {
        display: block;
        white-space: pre-wrap;
        width: 100%;
        overflow: auto;
        text-align: center;
      }
    }
  }
  &.random-mii-grid {
    .modal-content {
      width: 100%;
      .modal-body {
        .random-mii-container {
          display: grid;
          grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
          grid-auto-rows: min-content;
          grid-auto-flow: row dense;
          grid-gap: 1rem;
          place-items: center;
          button {
            padding: 0;
            display: flex;
            img {
              width: 100%;
              height: 100%;
              object-fit: cover;
              // fight against wii u theme adding background and border
              background: unset !important;
              box-shadow: unset !important;
              border: unset !important;
              margin: 0 !important;
            }
          }
        }
      }
    }
  }
}

.modal-body.force-start .flex-group {
  justify-content: flex-start !important;
}
.flex-group {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  span {
    text-align: center;
  }
}
.col {
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  gap: 16px;
}
.no-pad {
  padding: 0 !important;
}

button {
  font: inherit;
  background-color: var(--root);
  color: var(--text);
  border: 2px solid var(--stroke);
  border-radius: 8px;
  cursor: pointer;
  min-width: 64px;
  padding: 8px 14px;

  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;

  &:hover {
    background-color: var(--focus);
  }
  &,
  &:focus {
    outline: none;
  }
  &:focus {
    box-shadow: 0 0 0 0.15rem var(--selection-color);
  }
}

.disabled {
  transition: opacity 0.5s linear;
  opacity: 0.5;
  pointer-events: none;
}

video {
  background-color: var(--root);
  border: 2px solid var(--stroke);
}

input,
select {
  display: block;
  font: inherit;
  background-color: var(--root);
  color: var(--text);
  padding: 8px;
  border: 2px solid var(--stroke);
  border-radius: 8px;
  outline: 0;
  &:disabled {
    background-color: var(--container);
    color: var(--label);
    cursor: not-allowed;
    user-select: none;
  }
  &:focus {
    outline: 0;
    box-shadow: 0 0 0 0.2rem var(--selection-color);
  }
  &.invalid {
    box-shadow: 0 0 0 0.2rem var(--error-color) !important;
  }
  &[type="range"] {
    width: 100%;
  }
  // Hack for SVG checkbox icons.
  &[type="checkbox"] {
    width: 1.3rem;
    height: 1.3rem;
    appearance: none !important;
    border-radius: 4px !important;
    border: 0 !important;
    background-size: cover !important;
    background-image: $checkbox-unchecked !important;
    &:checked {
      background-image: $checkbox-checked !important;
    }
  }
}

.input-group {
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  align-items: center;
  label {
    font-size: 1.2rem;
    color: var(--label);
  }
}

.fadeIn {
  pointer-events: none;
  animation: fadeIn $animation-duration $easing-function !important;
}
.fadeOut {
  pointer-events: none;
  animation: fadeOut $animation-duration $easing-function !important;
}

.loader {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  opacity: 0;
  transition: opacity 0.1s linear;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 52px;
  height: 52px;
  pointer-events: none;
  &.active {
    opacity: 1;
    animation: spinTranslated 0.5s linear infinite;
  }
}

.separator {
  background: var(--stroke);
  width: 100%;
  height: 0.1rem;
  margin: 8px;
}
.separator-gap {
  width: 100%;
  height: 0;
  margin: 8px;
}
.separator-gap-thin {
  width: 100%;
  height: 0;
  margin: 0;
}

.ui-base {
  position: fixed;
  top: 0;
  left: 0;
  background-color: var(--root);
  color: var(--text);
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-areas: "tabList tabList" "mii tabContent";
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto 1fr;
  animation: fadeIn $animation-duration $easing-function;

  &.not-fixed {
    position: static;
  }

  &.closing {
    pointer-events: none;
    animation: fadeOut $animation-duration $easing-function !important;
  }
  @media screen and (max-width: $tabletWidth) {
    //1100px) {
    & {
      grid-template-areas: "mii" "tabList" "tabContent";
      grid-template-columns: auto;
      grid-template-rows: 1fr auto auto;
    }
    .tab-list {
      gap: 0.5rem;
      padding: 8px;
      .tab {
        &.tab-square {
          min-width: 64px;
          min-height: 64px;
          padding: 8px;
          &.active {
            box-shadow: 0 0 0 0.3rem var(--selection-color);
          }
        }
        &.tab-rectangle {
          min-width: 64px;
          padding: 14px 24px;
        }
        width: auto !important;
        height: auto !important;
      }
    }
    .tab-content {
      max-height: 30vmax;
    }
  }
  @media screen and (min-width: $tabletWidth) and (max-width: $desktopWidth) {
    grid-template-areas:
      "tabList tabList"
      "mii tabContent";
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto 1fr;
    > .tab-list {
      display: flex;
      flex-direction: row;
    }
    .tab-square:last-child {
      margin-top: auto;
    }
  }

  .tab-square:last-child {
    margin-left: auto;
  }

  & {
    padding: 1rem;
    grid-gap: 1rem;
  }

  > div {
    border-radius: 8px;
    overflow: auto;
  }

  .mii-holder {
    grid-area: mii;
    background-color: var(--hover-transparent);
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;

    .render-mode-toggle {
      position: absolute;
      top: 1rem;
      right: 1rem;
    }
    img,
    canvas {
      width: 100%;
      height: 100%;
      object-fit: contain;
      overflow: hidden;
      transition: opacity 0.5s cubic-bezier(0.215, 0.61, 0.355, 1);
    }
  }
  > .tab-list {
    grid-area: tabList;
  }
  > .tab-content {
    grid-area: tabContent;
    border: 2px solid var(--stroke-dim);
  }
}

.tab-save {
  width: max-content !important;
  gap: 8px;
  padding: 0 12px;
  background-color: var(--container-solid);
}

.tab-list {
  display: flex;
  background-color: var(--container);
  padding: 8px;
  gap: 8px;
  .tab {
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 12px;
    cursor: pointer;
    &:hover {
      background-color: var(--hover);
    }
    &.tab-square {
      width: 48px;
      height: 48px;
      &.active {
        box-shadow: 0 0 0 0.3rem var(--selection-color);
      }
    }
    &.active {
      background-color: var(--focus);
    }
    overflow: visible;
    position: relative;
    &::after {
      content: "";
      position: absolute;
      top: 100%;
      left: 0;
      width: 100%;
      height: 0;
      background-color: var(--selection-color);
    }
    &.tab-rectangle {
      min-width: 64px;
      padding: 14px 24px;
      &.active {
        border-radius: 12px 12px 12px 12px;
        &::after {
          height: 0.3rem;
        }
      }
    }
  }
}
.tab-content {
  background-color: var(--sub-container);
  // backdrop-filter: blur(10px) contrast(1.3) brightness(0.9);
  // stacking tab-content should not overlap background
  .tab-content {
    background-color: unset !important;
    backdrop-filter: unset !important;
  }
  display: flex;
  flex-direction: column;

  .feature-set-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    flex: 1;
    gap: 0.75rem;
    .tab-list {
      width: max-content;
      margin: 0 auto;
      background-color: var(--container);
      border-radius: 0 0 8px 8px;
      border-width: 0 2px 2px 2px;
      border-style: solid;
      border-color: var(--stroke-dim);
      .tab-rectangle {
        padding: 10px 14px;
        &.active::after {
          top: -8px;
          left: 50%;
          transform: translateX(-50%);
          width: 1.75rem;
          height: 0.3rem;
        }
      }
    }
    .tab-content {
      overflow: auto;
      flex: 1;
    }
  }
  .feature-set-group {
    padding: 8px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    width: 100%;
    .feature-set-header {
      width: 100%;
      padding: 14px 18px;
      background: var(--hover);
      color: var(--text);
      border: 1px solid var(--stroke);
      border-radius: 6px;
      margin: 4px;
    }
    .feature-switch {
      display: flex;
      .feature-switch-left {
        border-radius: 8px 0 0 8px;
      }
      .feature-switch-right {
        border-radius: 0 8px 8px 0;
      }
      .feature-switch-left,
      .feature-switch-right {
        padding: 2.5px 14px;
        flex: 1;
        display: flex;
        min-width: 64px;
        height: max-content;
        justify-content: center;
        align-items: center;
        border-right-width: 1px;
        &.active {
          // Fully highlight selected option.
          border-radius: 8px;
          z-index: 1;
          background-color: var(--focus);
          box-shadow: 0 0 0 0.3rem var(--selection-color);
        }
      }
    }
    .feature-slider,
    .feature-range {
      display: flex;
      width: 100%;
      justify-content: center;
      align-items: center;
      gap: 1rem;
      span {
        border: 2px solid var(--stroke-dim);
        border-radius: 6px;
        display: flex;
        justify-content: center;
        align-items: center;
      }
    }
    .feature-item {
      min-width: 52px;
      min-height: 52px;
      display: flex;
      justify-content: center;
      align-items: center;
      border-radius: 8px;
      cursor: pointer;
      &:hover {
        background-color: var(--hover);
      }
      &.active {
        box-shadow: 0 0 0 0.3rem var(--selection-color);
      }
      &.is-color {
        position: relative;
        &::after {
          $sp: 4px;
          border-radius: 8px;
          content: "";
          position: absolute;
          top: $sp;
          left: $sp;
          width: calc(100% - ($sp * 2) - 4px);
          height: calc(100% - ($sp * 2) - 4px);
          background-color: var(--color);
          border: 2px solid var(--hover);
          // border: 0.1rem solid rgba(var(--stroke-rgb), 0.4);
        }
      }
    }
  }
}

// Fix the dark-only drop shadow so it's only on normal theme.
:root[data-theme="default"] .tab-content .feature-set-group .feature-item {
  @media screen and (prefers-color-scheme: dark) {
    svg {
      $distance: 1px;
      $blur: 0;
      $color: #666666;
      filter: drop-shadow($distance 0px 0px $color)
        drop-shadow((-$distance) 0px 0px $color)
        drop-shadow(0px $distance 0px $color)
        drop-shadow(0px (-$distance) 0px $color);
    }
  }
}

.mii-library {
  animation: fadeIn $animation-duration $easing-function;

  display: grid;
  grid-template-areas: "sidebar miiList" "sidebar miiList";
  grid-template-columns: auto 1fr;

  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;

  .library-sidebar {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 2rem;
    background: var(--sub-container);
    grid-area: sidebar;
    .sidebar-buttons {
      display: flex;
      flex-direction: column;
      gap: 1rem;
    }
    .sidebar-credits {
      display: flex;
      flex-direction: column;
      gap: 0.65rem;
      justify-content: center;
      align-items: flex-start;
      span {
        color: var(--label);
        font-size: 0.8rem;
        font-weight: 600;
      }
    }
  }
  .library-list {
    padding: 2rem;
    display: grid;
    grid-area: miiList;
    position: relative;
    overflow: auto;

    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    grid-auto-rows: min-content;
    grid-auto-flow: row dense;
    grid-gap: 1rem;

    .library-list-mii {
      display: flex;
      flex-direction: column;
      background: var(--color);
      background-image: linear-gradient(0deg, #fff6, #fff6);

      border-radius: 8px;
      overflow: visible;
      position: relative;
      cursor: pointer;

      transition: box-shadow $easing-function $animation-duration;
      box-shadow: 0 0 0 0 var(--selection-color);

      &.highlight {
        box-shadow: 0 0 0 0.3rem var(--selection-color);
      }

      &:hover {
        background-image: linear-gradient(0deg, #fff8, #fff8);
      }

      img {
        width: 100%;
        object-fit: contain;
        aspect-ratio: 1 / 1;
      }
      span {
        width: 100%;
        background: #0008;
        color: white !important;
        text-align: center;
        font-size: 16px;
        text-align: center;
        flex: 1;
        padding: 8px 0;
        border-radius: 0 0 8px 8px;
      }

      @media screen and (prefers-color-scheme: dark) {
        // background-image: unset !important;
        // background-image: linear-gradient(
        //   180deg,
        //   rgba(255, 255, 255, 0.3333333333),
        //   rgba(82, 82, 82, 0.63)
        // );
        // background-image: linear-gradient(180deg, #fff5, #fff3);
        background-image: linear-gradient(180deg, #fff5, #fff5);
        &:hover {
          background-image: linear-gradient(180deg, #fff7, #fff7);
        }
      }
    }
  }

  @media screen and (max-width: $tabletWidth) {
    grid-template-areas: "miiList miiList" "sidebar sidebar";
    grid-template-rows: 1fr auto;
    .library-sidebar {
      flex-direction: row;
      button {
        flex: 1;
      }
      h1 {
        display: none;
      }
      .sidebar-buttons {
        flex: 1;
      }
      .sidebar-credits {
        flex-shrink: 1;
      }
    }
  }
}

@media screen and (min-width: $tabletWidth) {
  .responsive-row-lg {
    flex-direction: row !important;
  }
}
