// Default integrated theme.

.brackets-viewer {
  /* Colors */
  --primary-background: #fff;
  --secondary-background: #eceff1;
  --match-background: var(--primary-background);
  --font-color: #212529;
  --win-color: #50b649;
  --loss-color: #e61a1a;
  --label-color: grey;
  --hint-color: #a7a7a7;
  --connector-color: #9e9e9e;
  --border-color: #d9d9d9;
  --border-hover-color: #b6b5b5;
  --border-selected-color: rgb(60, 60, 60);

  /* Sizes */
  --text-size: 12px;
  --round-margin: 40px;
  --match-width: 150px;
  --match-horizontal-padding: 8px;
  --match-vertical-padding: 6px;
  --connector-border-width: 2px;
  --match-border-width: 1px;
  --match-border-radius: 0.3em;
  --participant-image-size: 1em;
}

.brackets-viewer {
  $connector-width: var(--round-margin) / 2;
  $connector-border: var(--connector-border-width) solid var(--connector-color);

  $match-border: var(--match-border-width) solid var(--border-color);

  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji",
    "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";

  &:empty {
    // Prevents a FOUC during loading.
    display: none;
  }

  background: var(--primary-background);
  color: var(--font-color);
  font-size: var(--text-size);
  text-align: left;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  overflow: auto;
  user-select: none;
  margin: 0 auto;
  padding: 10px 50px;

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

  h1,
  h2,
  h3 {
    margin-bottom: 0.5em;
    font-weight: 500;
    line-height: 1.2;
  }

  h1 {
    font-size: 2em;
    margin-top: 30px;
    margin-bottom: 20px;
  }

  h2 {
    font-size: 1.7em;
  }

  h3 {
    text-align: center;
    background: var(--secondary-background);
    font-size: 1.1em;
    padding: 10px 0px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: var(--match-width);
  }

  .round-robin {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    row-gap: 24px;

    h1 {
      flex-basis: 100%;
    }

    h2 {
      text-align: center;
    }

    .group {
      &:not(:last-of-type) {
        margin-right: var(--round-margin);
      }

      h2 {
        margin: 0 0 25px 0;
      }

      table {
        font-size: 1em;
        margin: 30px 0 20px 0;
        color: #a7a7a7;
        border-collapse: collapse;
      }

      th {
        font-weight: normal;
        text-align: start;
        cursor: help;
        border-bottom: $match-border;
      }

      td.hover {
        background: var(--secondary-background);
      }

      th,
      td {
        padding: 5px;
      }

      td {
        &:nth-of-type(2),
        &:last-of-type {
          color: var(--font-color);
          font-weight: 500;
        }
      }
    }

    .round {
      width: fit-content;
      margin: 0 auto;
    }
  }

  .bracket {
    h2 {
      font-size: 1.5em;
      color: gray;
    }

    .rounds {
      display: flex;

      &:not(:last-of-type) {
        margin-bottom: 15px;
      }

      .round {
        display: flex;
        flex-direction: column;

        &:not(:last-of-type) {
          margin-right: var(--round-margin);
        }
      }
    }
  }

  .match {
    flex: 1;
    display: flex;
    align-items: center;
    margin: 10px 0;
    width: var(--match-width);
    position: relative;

    &.connect-next {
      &::after {
        content: "";
        display: block;
        position: absolute;
        right: calc(-1 * #{$connector-width});
        width: calc(#{$connector-width});
        height: 50%;
        border-right: $connector-border;
      }

      &:nth-of-type(odd)::after {
        top: 50%;
        border-top: $connector-border;
      }

      &:nth-of-type(even)::after {
        top: 0;
        border-bottom: $connector-border;
      }

      &.straight::after {
        width: var(--round-margin);
        right: calc(-1 * var(--round-margin));
        top: 0;
        border-bottom: $connector-border;
        border-top: unset;
        border-right: unset;
      }
    }
  }

  .opponents {
    width: 100%;
    position: relative;
    border: $match-border;
    border-radius: var(--match-border-radius);
    background: var(--match-background);

    &:hover {
      border: 1px solid var(--border-hover-color);
    }

    &.popover-selected {
      border: 1px solid var(--border-selected-color);
    }

    & > span {
      position: absolute;
      top: -10px;
      font-size: 0.8em;
      padding: 0 5px;
      color: var(--label-color);
      background: var(--primary-background);
      border-radius: 3px;
    }

    // Match hint (e.g. WB 1.1)
    & > span:nth-of-type(1) {
      left: 3px;
    }

    // Child count label (e.g. Bo3)
    & > span:nth-of-type(2) {
      right: 3px;
    }

    &.connect-previous {
      &::before {
        content: "";
        display: block;
        position: absolute;
        left: calc(-1 * #{$connector-width});
        width: calc(#{$connector-width});
        height: 50%;
        border-bottom: $connector-border;
      }

      %straight {
        border-left: unset;
        left: var(--round-margin);
        width: var(--round-margin);
      }

      .bracket:nth-of-type(1) &.straight::before {
        content: unset;
      }

      .bracket:nth-of-type(1) &.straight::after {
        @extend %straight;
      }

      .bracket:nth-of-type(2) &.straight::before {
        @extend %straight;
      }

      .bracket:nth-of-type(2) &.straight::after {
        content: unset;
      }
    }
  }

  .participant {
    display: flex;
    justify-content: space-between;
    padding: 2px var(--match-horizontal-padding);
    background: var(--match-background);

    &.hover {
      background: var(--secondary-background) !important;
    }

    &:nth-of-type(1) {
      border-bottom: none;
      border-top-left-radius: var(--match-border-radius);
      border-top-right-radius: var(--match-border-radius);
      padding-top: var(--match-vertical-padding);
    }

    &:nth-of-type(2) {
      border-top: none;
      border-bottom-left-radius: var(--match-border-radius);
      border-bottom-right-radius: var(--match-border-radius);
      padding-bottom: var(--match-vertical-padding);
    }

    .name {
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      width: 80%;

      // Participant origin hint (e.g. #1)
      &.hint {
        color: var(--hint-color);
      }

      & > img {
        width: var(--participant-image-size);
        height: var(--participant-image-size);
        margin-right: 4px;
        object-fit: cover;
        border-radius: 4px;
        vertical-align: middle;
        position: relative;
        bottom: 1px;
      }

      // Participant name
      & > span {
        color: var(--hint-color);
        font-size: 0.9em;
        font-weight: initial;
      }
    }

    .result {
      margin-left: 10px;
      width: 15%;
      text-align: center;
    }

    &.win .name {
      font-weight: bold;
    }

    &.win .result {
      color: var(--win-color);
    }

    &.loss .result {
      color: var(--loss-color);
    }
  }

  [popover] {
    padding: 0 14px 10px 14px;

    h4 {
      font-size: 1.1em;
      margin-bottom: 24px;
    }

    .match:not(:last-of-type) {
      margin-bottom: 20px;
    }
  }
}
