.btn {
  display: flex;
  gap: 8px;
  align-items: center;
  background-color: transparent;
  outline: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;

  &:hover {
    color: var(--text);
  }

  &:disabled {
    opacity: 0.5;
    cursor: default;
  }

  .text.red {
    color: #ff5555;
  }
}

.key-container {
  display: flex;
  align-items: center;
  gap: 2px;
}

.key {
  background-color: var(--element);
  padding: 2px 6px;
  font-size: 13px;
  font-family: ChivoMono;
  text-transform: capitalize;
  color: inherit;

  &.red {
    color: #ff5555;
    background-color: #301616;
  }
}

.icon {
  flex-shrink: 0;
}

.input {
  padding-inline: 12px;
  display: flex;
  gap: 8px;
  background-color: transparent;
  border: 1px solid var(--border);
  width: 320px;
  height: 40px;
  border-radius: 12px;
  align-items: center;

  .icon {
    color: var(--text);
    width: 16px;
    height: 16px;
  }

  input {
    height: 100%;
    width: 100%;
    outline: none;
    border: none;
    background-color: transparent;
    color: var(--text);
  }
}

.radio-button {
  display: flex;
  align-items: center;
  cursor: pointer;
  gap: 8px;

  input {
    position: absolute;
    opacity: 0;
    pointer-events: none;

    &:checked + .circle .selected {
      display: block;
    }
  }

  .circle {
    width: 20px;
    height: 20px;
    position: relative;
    display: inline-block;

    .inner {
      width: 100%;
      height: 100%;
      position: absolute;
      background-color: var(--element);
      border-radius: 50%;
    }

    .selected {
      position: absolute;
      left: 3px;
      top: 3px;
      background-color: var(--text-secondary);
      width: calc(100% - 6px);
      height: calc(100% - 6px);
      border-radius: 50%;
      display: none;
    }
  }

  .text {
    color: var(--text-secondary);
  }
}

.modal,
.list-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 1000;
  transform: translate(-50%, -50%);
  border: 1px solid var(--border);
  padding: 24px;
  width: 90%;
  background: var(--background);
  color: var(--text);
  flex-direction: column;
  gap: 16px;
  box-shadow: 0px 4px 16px 0px rgba(0, 0, 0, 0.251);

  &[open] {
    display: flex;
  }

  &::backdrop {
    background-color: rgba(0, 0, 0, 0.5);
  }
}

.modal {
  max-width: 480px;

  form {
    display: flex;
    flex-direction: column;
    gap: 8px;

    .input {
      width: 100%;
    }
  }

  .description {
    color: var(--text-secondary);
    margin-bottom: 8px;
  }

  .modal-buttons {
    display: flex;
    gap: 24px;
    margin-top: 16px;
  }
}

.modal .modal-header,
.list-modal .modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;

  .heading {
    display: flex;
    align-items: baseline;
    gap: 10px;
  }

  .title {
    font-size: 18px;
    font-weight: 500;
    color: var(--text);
  }

  .count {
    font-family: ChivoMono;
    font-size: 13px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
  }

  .close-button {
    display: flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;

    &:hover {
      color: var(--text);
    }
  }
}

.list-modal {
  width: calc(100% - 32px);
  max-width: 640px;
  height: min(720px, calc(100dvh - 64px));
  overflow: hidden;

  &[open] {
    display: grid;
    grid-template-rows: auto auto 1fr;
  }

  .search {
    .input {
      width: 100%;
    }

    input::-webkit-search-cancel-button {
      display: none;
    }
  }

  .list-content {
    min-height: 0;
    overflow-y: auto;
    scrollbar-gutter: stable;
    scrollbar-width: thin;

    .item {
      grid-template-columns: 2.5ch 1fr auto auto;
      flex-shrink: 0;
    }

    .rank {
      font-family: ChivoMono;
      font-size: 12px;
      color: var(--text-muted);
      font-variant-numeric: tabular-nums;
    }

    .name mark {
      background: none;
      color: var(--accent);
    }

    .percentage,
    .time {
      font-variant-numeric: tabular-nums;
    }

    .empty {
      padding: 24px;
      color: var(--text-muted);
      text-align: center;
    }
  }
}

.bar-list {
  display: flex;
  flex-direction: column;
  gap: 4px;

  .item {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 1rem;
    align-items: center;
    padding: 8px;
    position: relative;
    height: 34px;

    &::before {
      content: "";
      position: absolute;
      top: 0;
      left: 0;
      height: 100%;
      width: var(--percentage);
      background: var(--element);
      z-index: 0;
    }

    > * {
      position: relative;
      z-index: 1;
      white-space: nowrap;
    }

    .name {
      font-weight: 500;
      color: var(--text);
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .time {
      text-align: right;
      color: var(--text);
      font-weight: 500;
      min-width: 64px;
    }

    .percentage {
      text-align: right;
      color: var(--text-secondary);
      font-weight: 600;
    }
  }
}

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;

  td {
    color: var(--text-secondary);
    padding-inline: 16px;
    white-space: nowrap;

    &.sorted {
      color: var(--text);
    }
  }

  a {
    color: inherit;
  }

  .header {
    user-select: none;

    td {
      position: sticky;
      top: 0;
      z-index: 6;
      background-color: var(--background);
      border-block: 1px solid var(--border);
      cursor: pointer;

      &:first-child {
        border-left: 1px solid var(--border);
      }

      &:last-child {
        border-right: 1px solid var(--border);
      }

      &::after {
        width: 1ch;
        text-align: center;
        opacity: 0;
        content: "↓";
      }

      &.sorted::after {
        opacity: 1;
      }

      &.sorted.asc::after {
        content: "↑";
      }
    }
  }

  .id {
    color: var(--text-muted);
    font-family: ChivoMono;
  }

  .row {
    height: 48px;
  }

  @media (max-width: 768px) {
    .id {
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .hide-mobile {
      display: none;
    }

    .header td:not(.hide-mobile):not(:has(~ td:not(.hide-mobile))) {
      border-right: 1px solid var(--border);
    }
  }
}

.page-login,
.page-stats {
  main {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 24px;
    flex-direction: column;
  }
}

.select-container {
  position: relative;
  cursor: pointer;
  user-select: none;
  outline: none;

  summary {
    list-style: none;

    &::-webkit-details-marker {
      display: none;
    }
  }

  .selected-item {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .dropdown-menu {
    position: absolute;
    bottom: 100%;
    right: 0;
    background-color: var(--background);
    z-index: 10;
    display: flex;
    flex-direction: column;
    margin-bottom: 8px;
    margin-right: -8px;
    border: 1px solid var(--border);
  }

  .dropdown-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 146px;
    padding: 8px;

    &:hover {
      background-color: var(--element);
    }
  }
}

.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 20000000;
  align-items: flex-end;
}

.toast {
  padding: 6px;
  font-weight: 400;
  cursor: pointer;
  display: inline-block;
  max-width: 100%;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;

  &.error {
    background-color: #301616;
    color: #ff5555;
  }

  &.success {
    background-color: #163016;
    color: #4caf50;
  }
}

.password-match {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  transition: color 0.15s;

  > span {
    display: none;
  }

  &[data-state="empty"] .when-empty,
  &[data-state="match"] .when-match,
  &[data-state="mismatch"] .when-mismatch {
    display: inline-flex;
    align-items: center;
    gap: 8px;
  }

  &[data-state="match"] {
    color: var(--accent);
  }

  &[data-state="mismatch"] {
    color: #ff5555;
  }
}

.password-rules.inline {
  position: static;
  width: auto;
  padding: 0;
  border: none;
  background: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}

.password-rules {
  position: absolute;
  left: calc(100% + 12px);
  top: 0;
  width: 220px;
  padding: 12px;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background-color: var(--background);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 13px;
  color: var(--text-muted);
  pointer-events: none;
  z-index: 10;

  li {
    display: flex;
    align-items: center;
    gap: 8px;
    transition: color 0.15s;

    .when-met {
      display: none;
    }

    .when-unmet {
      display: inline-flex;
    }

    &.met {
      color: var(--accent);

      .when-met {
        display: inline-flex;
      }

      .when-unmet {
        display: none;
      }
    }
  }

  @media (max-width: 760px) {
    left: 0;
    top: auto;
    bottom: calc(100% + 12px);
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 12px;
  }
}

.leaderboard-setup {
  background-color: color-mix(in srgb, var(--accent) 30%, transparent);
  border: 1px solid var(--accent);
  width: 100%;
  padding: 16px;
  display: flex;
  justify-content: space-between;

  .buttons {
    display: flex;
    gap: 24px;
  }

  .title {
    font-size: 18px;
    font-weight: 500;
  }

  .description {
    font-size: 12px;
    color: var(--text-secondary);
  }

  @media (max-width: 726px) {
    flex-direction: column;
    gap: 16px;
  }
}

.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;

  .title {
    display: flex;
    align-items: center;
  }

  .actions {
    display: flex;
    gap: 24px;

    a {
      color: var(--text-secondary);

      &:hover {
        color: var(--text);
      }
    }

    .router-link-active {
      color: var(--text);
    }
  }
}

.layout {
  --bar: 18px;
  width: 100dvw;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 24px;
  position: relative;

  > .navbar,
  > .bottombar {
    position: relative;
    z-index: 10;
    height: var(--bar);
  }

  .viewport {
    position: absolute;
    inset: 0;
    --top: calc(24px + var(--bar));
    --bottom: 0px;
  }

  &:has(> .bottombar) .viewport {
    --bottom: calc(24px + var(--bar));
  }

  .content {
    position: relative;
    z-index: 0;
    height: 100%;
    overflow-y: auto;
    padding: calc(var(--top) + 24px) 24px calc(var(--bottom) + 24px);
  }

  .content:has(.data-table) > .blur.top {
    --edge: calc(var(--top) + 24px + 48px);
  }

  .blur {
    position: sticky;
    left: 0;
    height: 0;
    z-index: 5;
    pointer-events: none;

    &.top {
      top: 0;
      --edge: var(--top);
      --dir: to bottom;

      > div {
        top: calc(-1 * (var(--top) + 24px));
        animation: blur-in linear both;
        animation-timeline: scroll(nearest);
        animation-range: 0 24px;
      }
    }

    &.bottom {
      bottom: 0;
      --edge: var(--bottom);
      --dir: to top;

      > div {
        top: 0;
      }
    }

    > div {
      position: absolute;
      left: -24px;
      right: -24px;
      height: calc(var(--edge) + 24px);
      backdrop-filter: blur(var(--blur));
      -webkit-backdrop-filter: blur(var(--blur));
      mask-image: linear-gradient(var(--dir), var(--mask));
    }

    > :nth-child(1) {
      --blur: 8px;
      --mask: #000 0, #000 calc(var(--edge) + 4.8px), transparent calc(var(--edge) + 9.6px);
    }

    > :nth-child(2) {
      --blur: 4px;
      --mask: #000 0, #000 calc(var(--edge) + 9.6px), transparent calc(var(--edge) + 14.4px);
    }

    > :nth-child(3) {
      --blur: 2px;
      --mask: transparent calc(var(--edge) + 0px), #000 calc(var(--edge) + 4.8px), #000 calc(var(--edge) + 14.4px), transparent calc(var(--edge) + 19.2px);
    }

    > :nth-child(4) {
      --blur: 1px;
      --mask: transparent calc(var(--edge) + 4.8px), #000 calc(var(--edge) + 9.6px), #000 calc(var(--edge) + 19.2px), transparent calc(var(--edge) + 24px);
    }

    > :nth-child(5) {
      --blur: 0.5px;
      --mask: transparent calc(var(--edge) + 9.6px), #000 calc(var(--edge) + 14.4px), #000 calc(var(--edge) + 24px);
    }
  }

  .bottombar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    overflow: visible;
    color: var(--text-secondary);
  }
}

@keyframes blur-in {
  from {
    opacity: 0;
  }
}
