/// MIXINS

@mixin viewport-small {
  @media (width < 600px) {
    @content;
  }
}

@mixin viewport-medium {
  @media (width >= 600px) {
    @content;
  }
}

@mixin viewport-large {
  @media (width >= 950px) {
    @content;
  }
}

:root {
  /* z-index enum */
  --z-index-popup: 2;

  /* various dimensions */
  --logo-size: 64px;
  --toolbar-height: 50px;

  /* colors related to torrent status */
  --black: #000;
  --blue-100: #51b3f7;
  --blue-200: #357aaa;
  --blue-300: #2c7fea;
  --blue-400: #1847d4;
  --dark-mode-black: #121212;
  --dark-mode-white: #c9d1d9;
  --default-accent-color-dark: #0c2d6b;
  --default-border-dark: #575757;
  --default-border-light: #aeaeae;
  --default-tinted: rgba(128, 128, 144, 0.125);
  --green-100: #26aa55;
  --green-300: #7cef99;
  --green-400: #67c87f;
  --green-500: #34dc70;
  --grey: rgba(128, 128, 130, 0.66);
  --grey-200: #e1e4e8;
  --grey-40: #666;
  --grey-500: #828282;
  --grey-900: #191919;
  --nice-grey: #f8f8f8;
  --red-500: #d73a49;
  --white: #fff;
  --yellow-300: #ffea7f;

  /* ICONS -- see assets/img/README.md for sources and license details */
  /* Are you a designer? New icon PRs welcomed! */
  --image-baseline: url('../img/horizontal-rule.svg');
  --image-chevron-dn: url('../img/chevron-down.svg');
  --image-chevron-up: url('../img/chevron-up.svg');
  --image-lock-fill: url('../img/lock-fill.svg');
  --image-magnet: url('../img/magnet.svg');
  --image-turtle: url('../img/turtle.svg');

  --app-image-url: url('../img/box.svg');
  --audio-image-url: url('../img/music.svg');
  --folder-image-url: url('../img/folder.svg');
  --font-image-url: url('../img/type.svg');
  --image-image-url: url('../img/image.svg');
  --package-image-url: url('../img/package.svg');
  --text-image-url: url('../img/file-text.svg');
  --video-image-url: url('../img/film.svg');

  --progress: 100%;

  --color-bg-even: var(--default-tinted);
  --color-bg-tabs: var(--default-tinted);
  --color-fg-error: var(--red-500);
  --color-fg-port-closed: var(--red-500);
  --color-fg-port-open: var(--green-100);
  --color-progressbar-background-2: var(--green-400);
  --color-progressbar-leech: var(--blue-200);
  --color-progressbar-magnet: var(--yellow-300);
  --color-progressbar-paused: var(--grey-200);
  --color-progressbar-queued: var(--blue-400);
  --color-progressbar-verify: var(--yellow-300);
  --color-toolbar-background: var(--default-tinted);

  color-scheme: light dark;

  @media (prefers-color-scheme: dark) {
    --color-bg-hover: var(--grey-40);
    --color-bg-odd: var(--black);
    --color-bg-popup: var(--black);
    --color-bg-primary: var(--black);
    --color-bg-selected: var(--default-accent-color-dark);
    --color-bg-warn: #cf6679;
    --color-border-default: var(--default-border-dark);
    --color-border-stark: var(--dark-mode-white);
    --color-border-starkest: var(--grey-500);
    --color-fg-disabled: var(--grey);
    --color-fg-on-popup: var(--nice-grey);
    --color-fg-primary: var(--dark-mode-white);
    --color-fg-secondary: var(--nice-grey);
    --color-fg-selected: var(--dark-mode-white);
    --color-fg-tertiary: var(--grey-500);
    --color-fg-warn: var(--dark-mode-black);
    --color-progressbar-fg-1: #edefff;
    --color-progressbar-fg-2: #edefff;
    --color-progressbar-fg-3: #edefff;
    --color-progressbar-paused: var(--grey-500);
    --color-progressbar-seed-1: var(--green-100);
    --color-progressbar-seed-2: var(--green-400);
    --color-progressbar-seed-paused: var(--grey-500);
    --progress-bar-shadow-1: 1px 1px #000;
    --progress-bar-shadow-2: 1px 1px #000;
    --progress-bar-shadow-3: 1px 1px #000;

    .contrast-more {
      --color-bg-even: var(--black);
      --color-bg-hover: var(--grey-40);
      --color-bg-selected: var(--blue-300);
      --color-bg-tabs: var(--black);
      --color-bg-warn: #cf6679;
      --color-border-default: var(--white);
      --color-border-stark: var(--white);
      --color-border-starkest: var(--white);
      --color-fg-disabled: var(--white);
      --color-fg-error: var(--red-500);
      --color-fg-on-popup: var(--white);
      --color-fg-port-closed: var(--red-500);
      --color-fg-port-open: var(--green-100);
      --color-fg-primary: var(--white);
      --color-fg-secondary: var(--white);
      --color-fg-selected: var(--white);
      --color-fg-tabs: var(--white);
      --color-fg-tertiary: var(--white);
      --color-fg-warn: var(--black);
      --color-progressbar-fg-1: #fff;
      --color-progressbar-fg-2: #fff;
      --color-progressbar-fg-3: #000;
      --color-progressbar-background-2: var(--white);
      --color-progressbar-magnet: var(--yellow-300);
      --color-progressbar-paused: var(--grey-500);
      --color-progressbar-queued: var(--blue-400);
      --color-progressbar-seed-1: var(--black);
      --color-progressbar-seed-2: var(--white);
      --color-progressbar-seed-paused: var(--grey-500);
      --color-progressbar-verify: var(--yellow-300);
      --color-toolbar-background: var(--black);
      --progress-bar-shadow-3: 0;
    }
  }
  @media (prefers-color-scheme: light) {
    --color-bg-hover: var(--nice-grey);
    --color-bg-odd: var(--white);
    --color-bg-popup: var(--white);
    --color-bg-primary: var(--white);
    --color-bg-selected: var(--blue-300);
    --color-bg-warn: #e4606d5b;
    --color-border-default: var(--default-border-light);
    --color-border-stark: var(--grey-500);
    --color-border-starkest: #d0d7de;
    --color-dialog-border: var(--nice-grey);
    --color-fg-disabled: var(--grey);
    --color-fg-error: var(--red-500);
    --color-fg-on-popup: var(--grey-900);
    --color-fg-port-closed: var(--red-500);
    --color-fg-port-open: var(--green-400);
    --color-fg-primary: #404040;
    --color-fg-secondary: var(--grey-500);
    --color-fg-selected: var(--nice-grey);
    --color-fg-tertiary: var(--grey-500);
    --color-fg-warn: #cf212e;
    --color-progressbar-fg-1: #303030;
    --color-progressbar-fg-2: #edefff;
    --color-progressbar-fg-3: #edefff;
    --color-progressbar-leech: var(--blue-100);
    --color-progressbar-magnet: var(--yellow-300);
    --color-progressbar-paused: var(--grey-200);
    --color-progressbar-queued: var(--blue-400);
    --color-progressbar-seed-1: var(--green-500);
    --color-progressbar-seed-2: var(--green-300);
    --color-progressbar-seed-paused: var(--grey-200);
    --color-progressbar-verify: var(--yellow-300);
    --progress-bar-shadow-1: 0;
    --progress-bar-shadow-2: 1px 1px #000;
    --progress-bar-shadow-3: 1px 1px #000;

    .contrast-more {
      --color-bg-even: var(--white);
      --color-bg-hover: var(--grey-40);
      --color-bg-selected: var(--blue-300);
      --color-bg-tabs: var(--white);
      --color-bg-warn: #cf6679;
      --color-border-default: var(--black);
      --color-border-stark: var(--black);
      --color-border-starkest: var(--black);
      --color-fg-disabled: var(--black);
      --color-fg-error: var(--red-500);
      --color-fg-on-popup: var(--black);
      --color-fg-port-closed: var(--red-500);
      --color-fg-port-open: var(--green-400);
      --color-fg-primary: var(--black);
      --color-fg-secondary: var(--black);
      --color-fg-selected: var(--white);
      --color-fg-tabs: var(--black);
      --color-fg-tertiary: var(--black);
      --color-fg-warn: var(--white);
      --color-progressbar-background-2: var(--white);
      --color-progressbar-fg-1: #fff;
      --color-progressbar-fg-2: #fff;
      --color-progressbar-fg-3: #000;
      --color-progressbar-leech: var(--blue-200);
      --color-progressbar-magnet: var(--yellow-300);
      --color-progressbar-paused: var(--grey-500);
      --color-progressbar-queued: var(--blue-400);
      --color-progressbar-seed-1: var(--black);
      --color-progressbar-seed-2: var(--white);
      --color-progressbar-seed-paused: var(--grey-500);
      --color-progressbar-verify: var(--yellow-300);
      --color-toolbar-background: var(--white);
      --progress-bar-shadow-1: 1px 1px #000;
      --progress-bar-shadow-3: 0;
    }
  }
}

/* If browser can support using 'system color' keywords (i.e. way to inherit browser colors), use these variables instead */
@supports (background-color: Canvas) {
  :root {
    .contrast-less {
      --color-bg-odd: Canvas;
      --color-bg-primary: Canvas;
      --color-bg-popup: Canvas;
    }
  }
}

html,
body {
  background-color: var(--color-bg-primary);
  color: var(--color-fg-primary);
  font-family:
    -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial,
    sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
  -webkit-text-size-adjust: none;
  height: 100%;
  margin: 0;
}

img {
  border: 0;
}

a {
  color: var(--color-fg-primary);
  outline: 0;
  text-decoration: underline;
}

.flexible-space {
  flex-grow: 1;
}

.hidden {
  display: none;
}

#mainwin {
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;

  > * {
    margin: 0;
    padding: 0;
  }
}

#mainwin-workarea {
  display: flex;
  flex: 1;
  overflow: auto;
}

.popup,
.tabs-container {
  box-shadow:
    0 3px 6px -4px rgba(0, 0, 0, 0.12),
    0 6px 16px rgba(0, 0, 0, 0.08),
    0 9px 28px 8px rgba(0, 0, 0, 0.06);
  position: absolute;
}

/// TOOLBAR

#mainwin-toolbar {
  align-items: center;
  background: var(--color-toolbar-background);
  border-bottom: 1px solid var(--color-border-default);
  display: flex;
  height: var(--toolbar-height);
  margin: 0;
  width: 100%;

  button {
    background-color: transparent;
    background-position: center;
    background-repeat: no-repeat;
    border: 0;
    border-radius: 5px;
    color: var(--color-fg-primary);
    cursor: pointer;
    height: var(--toolbar-height);
    margin-right: 6px;
    user-select: none;
    -webkit-user-select: none;
    min-width: var(--toolbar-height);

    svg {
      stroke: var(--color-fg-primary);

      g path {
        fill: var(--color-fg-primary);
      }
    }

    &:disabled {
      color: var(--color-fg-disabled);
      cursor: default;

      svg {
        stroke: var(--color-fg-disabled);

        g path {
          fill: var(--color-fg-disabled);
        }
      }
    }
  }

  > .toolbar-separator {
    border-left: 1px solid var(--color-border-default);
    height: 25px;
    margin: 0 6px 0 0;
  }
}

.toolbar-icon {
  stroke: var(--color-fg-primary);
}

#toolbar-overflow {
  margin-right: 4px;

  svg {
    fill: var(--color-fg-primary);
    height: 36px;
    width: 36px;
  }
}

/// FILTERBAR

#mainwin-statusbar {
  white-space: nowrap;
  align-items: center;
  background: var(--color-toolbar-background);
  border-bottom: 1px solid var(--color-border-default);
  display: flex;
  height: 30px;
  padding-left: 5px;

  #torrent-search {
    width: 100%;
    min-width: 140px;
    max-width: 226px;
    padding-right: 24px; /* accommodate reset button */

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

  #reset {
    display: none;
    cursor: pointer;
    position: absolute;
    right: 2px;
    border: 0;
    height: 20px;
    width: 20px;
    background: none;
  }

  select {
    width: 70px;
  }

  > * {
    margin-right: 5px;
  }

  .speed-container {
    display: inherit;
    align-items: inherit;
    flex-direction: inherit;

    svg {
      min-width: 20px;
      width: 20px;
    }

    + .speed-container {
      min-width: 100px;
    }
  }

  button {
    background-color: transparent;
    border: 1px solid var(--color-border-default);
    border-radius: 4px;
    cursor: pointer;
    height: 22px;
    user-select: none;
    -webkit-user-select: none;
    width: 36px;
  }

  #turtle {
    &.alt-speed-enabled {
      background-color: var(--color-bg-selected);

      &::before {
        filter: hue-rotate(120deg) saturate(180%);
      }
    }

    &::before {
      content: '';
      background: var(--image-turtle) no-repeat center;
      left: calc(20% - 5px);
      filter: grayscale(100%) brightness(50%);
      padding: 9px;
      position: relative;
    }
  }

  @include viewport-small {
    .speed-container,
    span:not(.flexible-space) {
      display: none;
    }
  }
}

/// TORRENT CONTAINER

#torrent-container {
  flex-grow: 1;
  left: 0;
  margin: 0;
  overflow: auto;
  padding: 0;
  right: 0;
}

#torrent-list {
  cursor: pointer;
  list-style-type: none;
  margin: 0;
  padding: 0;
  text-align: left;
  width: 100%;
  user-select: none;
  -webkit-user-select: none;

  .torrent {
    align-items: center;
    border-bottom: 1px solid var(--color-border-default);
    display: grid;

    &:nth-child(even) {
      background-color: var(--color-bg-even);
    }

    &:nth-child(odd) {
      background-color: var(--color-bg-odd);
    }

    .icon {
      // color the background svg fill
      background-color: var(--color-fg-primary);
      background-position:
        center,
        top left;
      grid-area: icon;
      -webkit-mask-image: var(--mime-icon-url);
      -webkit-mask-repeat: no-repeat;
      mask-image: var(--mime-icon-url);
      mask-repeat: no-repeat;

      &[data-icon-multifile='true'] {
        -webkit-mask-image: var(--mime-icon-url), var(--folder-image-url);
        -webkit-mask-position:
          top left,
          bottom right;
        -webkit-mask-repeat: no-repeat, no-repeat;
        -webkit-mask-size: 16px, 16px;
        mask-image: var(--mime-icon-url), var(--folder-image-url);
        mask-position:
          top left,
          bottom right;
        mask-repeat: no-repeat, no-repeat;
        mask-size: 16px, 16px;
      }

      &[data-icon-mime-type='audio'] {
        --mime-icon-url: var(--audio-image-url);
      }

      &[data-icon-mime-type='application'] {
        --mime-icon-url: var(--app-image-url);
      }

      &[data-icon-mime-type='font'] {
        --mime-icon-url: var(--font-image-url);
      }

      &[data-icon-mime-type='image'] {
        --mime-icon-url: var(--image-image-url);
      }

      &[data-icon-mime-type='model'] {
        --mime-icon-url: var(--package-image-url);
      }

      &[data-icon-mime-type='text'] {
        --mime-icon-url: var(--text-image-url);
      }

      &[data-icon-mime-type='video'] {
        --mime-icon-url: var(--video-image-url);
      }
    }

    .torrent-name {
      grid-area: name;
      margin-bottom: 2px;
      margin-top: 2px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;

      &:not(.compact) {
        font-weight: bold;
      }
    }

    .torrent-labels {
      font-size: 12px;
      font-weight: normal;
      grid-area: labels;
      margin-bottom: 2px;
      margin-top: 2px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      padding: 1px 0;
    }

    .torrent-label {
      padding: 0 8px;
      margin: 0 2px;
      border-radius: 1em;
      border: 1px solid var(--color-border-default);
    }

    .torrent-peer-details {
      grid-area: peers;
    }

    .torrent-progress-bar {
      grid-area: progressbar;
    }

    .torrent-progress-details {
      grid-area: progress-text;
    }

    .torrent-peer-details,
    .torrent-progress-details {
      font-size: small;

      &.error {
        color: var(--color-fg-error);
      }
    }

    &.compact {
      --icon-size: 16px;

      grid-template-areas: 'icon name labels peers progressbar';
      grid-template-columns: calc(var(--icon-size) + 10px) auto 1fr auto auto;

      .icon {
        -webkit-mask-size: var(--icon-size);
        height: var(--icon-size);
        mask-size: var(--icon-size);
        width: var(--icon-size);

        &[data-icon-multifile='true'] {
          -webkit-mask-image: var(--folder-image-url);
          mask-image: var(--folder-image-url);
        }
      }

      .torrent-peer-details {
        white-space: nowrap;
      }

      > * {
        margin: 5px;
      }
    }

    &:not(.compact) {
      --icon-size: 32px;

      grid-column-gap: 12px;
      grid-template-areas:
        'icon name labels'
        'icon progress-text progress-text'
        'icon progressbar progressbar'
        'icon peers peers';
      grid-template-columns: var(--icon-size) auto 1fr;
      padding: 6px 12px;

      .icon {
        background-size: var(--icon-size), calc(var(--icon-size) / 2);
        height: var(--icon-size);
        width: var(--icon-size);
      }

      > * {
        margin: 1px 0;
      }
    }

    &.paused {
      color: var(--color-fg-disabled);

      &:not(.selected) .torrent-progress-bar {
        color: var(--color-fg-primary);
      }

      .icon {
        background-color: var(--color-fg-disabled);
      }
    }

    &.selected {
      background-color: var(--color-bg-selected);
      color: var(--color-fg-selected);

      .icon {
        background-color: var(--color-fg-selected);
      }
    }
  }

  .icon {
    background-position: center;
    background-repeat: no-repeat;
  }

  .torrent-progress-bar {
    font-size: 14px;
    position: relative;
    border: 1px solid var(--color-border-starkest);
    border-radius: 3px;
    height: 18px;

    &:not(.compact) {
      margin: 2px 0;
    }

    &.compact {
      min-width: 100px;
    }

    &.leech {
      &.queued::before {
        background: var(--color-progressbar-queued);
      }

      &::before {
        background: var(--color-progressbar-leech);
        color: var(--color-progressbar-fg-2);
        text-shadow: var(--progress-bar-shadow-2);
      }
    }

    &.magnet::before {
      background: var(--color-progressbar-magnet);
      color: #000;
    }

    &.seed {
      &.paused::before {
        background: var(--color-progressbar-seed-paused);
        color: var(--color-progressbar-fg-1);
        text-shadow: var(--progress-bar-shadow-1);
      }

      &:not(.paused) {
        &::before {
          background: var(--color-progressbar-seed-1);
          color: var(--color-progressbar-fg-2);
          text-shadow: var(--progress-bar-shadow-2);
        }

        &::after {
          background: var(--color-progressbar-seed-2);
          color: var(--color-progressbar-fg-3);
          text-shadow: var(--progress-bar-shadow-3);
        }
      }

      &.queued::before {
        background-color: var(--color-progressbar-seed-1);
      }

      &::before {
        background-color: var(--color-progressbar-seed-1);
        color: var(--color-progressbar-fg-2);
        text-shadow: var(--progress-bar-shadow-2);
      }
    }

    &.verify::before {
      background: var(--color-progressbar-verify);
      color: #000;
    }

    &.paused::before {
      background: var(--color-progressbar-paused);
      color: var(--color-progressbar-fg-1);
      text-shadow: var(--progress-bar-shadow-1);
    }

    &::before,
    &::after {
      content: attr(data-progress);
      height: 100%;
      width: 100%;
      position: absolute;
      border-radius: 2px;
      text-align: center;
    }

    &::before {
      clip-path: polygon(
        0 0,
        var(--progress, 30%) 0,
        var(--progress, 30%) 100%,
        0 100%
      );
    }

    &::after {
      clip-path: polygon(
        var(--progress, 30%) 0,
        100% 0,
        100% 100%,
        var(--progress, 30%) 100%
      );
    }
  }
}

/// PREFERENCES DIALOG

#inspector {
  @include viewport-large {
    box-shadow: initial;
    position: initial;
  }
}

#prefs-dialog {
  .tabs-page {
    grid-column-gap: 8px;
    grid-row-gap: 5px;
    grid-template-columns: 1fr 1fr;
    margin: 20px;

    &:not(.hidden) {
      display: grid;
    }

    .section-label {
      font-weight: bold;
      grid-column: span 2;
      padding-bottom: 5px;

      &:not(:first-of-type) {
        margin-top: 20px;
      }
    }
  }

  .alt-speed-section-label::before {
    content: '';
    background: var(--image-turtle) no-repeat left / 20px;
    filter: hue-rotate(120deg) saturate(180%);
    padding: 0 11px;
  }

  :disabled,
  .disabled {
    color: var(--color-fg-disabled);
  }

  #alt-times-div,
  #autostart-div,
  #port-forwarding,
  #randomize-port,
  #suffix-div,
  #use-dht-div,
  #use-lpd-div,
  #use-pex-div,
  #utp-enabled,
  .alt-speed-label {
    grid-column: span 2;
  }

  #default-trackers {
    height: 300px;
  }

  .blocklist-size-label,
  .blocklist-update-button,
  .register-handler-button,
  .port-status {
    grid-column: 2 / 3;
  }

  .blocklist-size-label {
    font-size: smaller;
  }

  .blocklist-size-number {
    font-weight: bolder;
  }

  .port-status-label {
    display: inline-block;
    font-weight: bold;
    margin-left: 5px;

    &[data-open='true'] {
      color: var(--color-fg-port-open);
    }

    &[data-open='false'] {
      color: var(--color-fg-port-closed);
    }
  }

  #default-trackers,
  .default-trackers-label {
    grid-column: 1 / 3;
  }

  .alt-speed-label {
    font-size: smaller;
    // nudge it up next to the section label
    margin: -10px 0 10px;
  }
}

#prefs-dialog.ui-tabs .ui-tabs-panel {
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

/// TABS

.tabs-container {
  align-items: stretch;
  background: var(--color-bg-primary);
  bottom: 0;
  display: flex;
  flex-direction: column;
  position: absolute;
  right: 0;
  top: 82px;
  z-index: var(--z-index-popup);

  @include viewport-small {
    top: 0;
    left: 0;
  }
  @include viewport-medium {
    border-left: 1px solid var(--color-border-default);
    min-width: 570px;
    width: 570px;
  }
}

.tabs-container-close {
  font-size: 150%;
  cursor: pointer;
  background: var(--color-bg-primary);
  border: 0;
  color: var(--color-fg-primary);
  position: absolute;
  padding: 10px 16px;
}

.tabs-buttons {
  align-self: center;
  background-color: var(--color-bg-tabs);
  border: 1px solid var(--color-border-starkest);
  border-radius: 6px;
  display: flex;
  margin: 10px 0;

  button {
    appearance: none;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--color-fg-primary);
  }
}

.tabs-pages {
  box-sizing: border-box;
  overflow-x: hidden;
  overflow-y: auto;

  @include viewport-small {
    padding: 0 8px 20px;
  }
  @include viewport-medium {
    padding: 0 20px 20px;
  }
}

.tabs-button {
  background: none;
  border: 1px solid transparent;
  font-size: 14px;
  padding: 3px 8px;

  &:active,
  &:checked,
  &.selected {
    background-color: var(--color-bg-odd);
    border: 1px solid var(--color-fg-primary);
    border-radius: 5px;
  }
}

/// INSPECTOR

.inspector-info-page {
  font-size: 14px;
  // TODO: this is (mostly) copied from prefs-dialog.
  // can it be folded into a single set of rules?

  grid-column-gap: 8px;
  grid-row-gap: 8px;
  grid-template-columns: auto 1fr;
  margin: 20px;
  padding: 12px;

  &:not(.hidden) {
    display: grid;
  }

  .section-label {
    font-size: 16px;
    font-weight: bold;
    grid-column: span 2;
    padding-bottom: 5px;

    &:not(:first-of-type) {
      margin-top: 20px;
    }
  }

  :not(.section-label) {
    // this section is not copied
    overflow-x: hidden;
    text-overflow: ellipsis;
  }
}

.inspector-info-magnet button {
  background-color: var(--color-fg-primary);

  background-position: top;
  background-repeat: no-repeat;
  border: 0;
  cursor: pointer;
  height: 1rem;
  -webkit-mask: var(--image-magnet) no-repeat center / 14px;
  mask: var(--image-magnet) no-repeat center / 14px;
  vertical-align: middle;
  width: 1rem;
}

#inspector,
#prefs-dialog {
  .tabs-button {
    height: 30px;
    margin: 0;
    min-width: 40px;
  }
}

#inspector-file-list {
  margin: 0;
  padding: 0;

  .inspector-torrent-file-list-entry {
    user-select: none;
    -webkit-user-select: none;
    display: grid;
    grid-column-gap: 5px;
    grid-template-areas:
      'check   name  priority'
      'blank1  info  blank2';
    grid-template-columns: 20px 1fr 65px;
    margin-bottom: 4px;
    padding: 5px;

    &:nth-child(even) {
      background-color: var(--color-bg-even);
    }

    &:nth-child(odd) {
      background-color: var(--color-bg-odd);
    }

    .inspector-torrent-file-list-entry-name {
      cursor: pointer;
      font-size: 14px;
      grid-area: name;
      overflow-wrap: anywhere;
    }

    .inspector-torrent-file-list-entry-progress {
      font-size: 12px;
      grid-area: info;
    }

    .file-wanted-control {
      grid-area: check;
    }

    &.skip {
      opacity: 0.5;

      > .inspector-torrent-file-list-entry-name {
        color: var(--color-fg-disabled);
      }
    }

    &:not(.selected) {
      .inspector-torrent-file-list-entry-name {
        color: var(--color-fg-primary);
      }

      .inspector-torrent-file-list-entry-progress {
        color: var(--color-fg-secondary);
      }
    }

    &.selected {
      background: var(--color-bg-selected);
      color: var(--color-fg-selected);
    }
  }
}

#inspector-header {
  margin: 8px 0;
}

#torrent-inspector-name {
  font-size: large;
  font-weight: bold;
}

#inspector-tiers-list {
  color: var(--color-fg-primary);
  margin: 0 10px;
  padding: 0;

  .tier-list-row {
    display: grid;
    font-size: 12px;
    grid-column-gap: 8px;
    grid-row-gap: 4px;
    padding: 8px 12px;

    &:nth-child(even of .tier-list-row) {
      background-color: var(--color-bg-even);
    }

    &:nth-child(odd of .tier-list-row) {
      background-color: var(--color-bg-odd);
    }
  }

  .tier-list-torrent {
    color: var(--color-fg-primary);
    font-weight: bolder;
    overflow-x: hidden;
    padding-top: 12px;
    padding-bottom: 8px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .tier-list-tracker {
    font-size: 14px;
    font-weight: bolder;
    grid-column: span 2;
    padding-bottom: 4px;
  }

  .tier-announce,
  .tier-scrape,
  .tier-state {
    text-align: left;
  }

  .tier-downloads,
  .tier-leechers,
  .tier-seeders {
    text-align: right;
  }
}

// Peers Tab

.peer-list {
  --table-border: 1px solid var(--color-border-default);

  border: var(--table-border);
  border-collapse: collapse;
  cursor: default;
  table-layout: fixed;
  text-align: left;
  width: 100%;

  td,
  th {
    font-size: smaller;
    padding: 5px;
  }

  td {
    border: var(--table-border);
    color: var(--color-fg-secondary);
    // padding: 5px 10px;
  }

  .torrent-row td {
    background: var(--color-bg-odd);
    color: var(--color-fg-primary);
    font-weight: bolder;
    overflow-x: hidden;
    padding: 10px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .encryption[data-encrypted='true'] {
    background-color: var(--color-border-starkest);
    -webkit-mask: var(--image-lock-fill) no-repeat center / 14px;
    mask: var(--image-lock-fill) no-repeat center / 14px;
    width: 10px;
  }

  .peer-address,
  .percent-done,
  .speed-down,
  .speed-up {
    text-align: right;
  }

  .percent-done {
    width: 10%;
  }

  .speed-down,
  .speed-up {
    width: 15%;
  }

  .peer-address {
    width: 25%;
    overflow-x: hidden;
    text-overflow: ellipsis;

    @include viewport-small {
      text-align: left;
    }
  }

  .peer-app-name {
    overflow-x: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 20%;
  }

  .status {
    cursor: pointer;
    width: 10%;
  }
}

/// FILE PRIORITY BUTTONS

.file-priority-radiobox {
  grid-area: priority;

  > * {
    appearance: none;
    background-color: var(--color-bg-tabs);
    border: 1px solid var(--color-border-default);
    border-radius: 0;
    height: 20px;
    margin: 0;
    padding: 0;
    width: 20px;

    &.low {
      &::after {
        mask-image: var(--image-chevron-dn);
      }
    }

    &.normal {
      border-width: 1px 0;
      width: 19px;

      &::after {
        mask-image: var(--image-baseline);
      }
    }

    &.high {
      &::after {
        mask-image: var(--image-chevron-up);
      }
    }

    &.checked {
      background-color: var(--color-bg-selected);

      &::after {
        background-color: var(--color-fg-selected);
      }
    }

    &::after {
      content: '';
      background-color: var(--color-fg-primary);
      display: inline-block;
      height: 20px;
      mask-position: center;
      mask-repeat: no-repeat;
      mask-size: 14px;
      width: 18px;
    }
  }
}

/// CONTEXT MENU

.context-menu {
  background-color: var(--color-bg-primary);
  border-radius: 5px;
  color: var(--color-fg-on-popup);
  padding: 10px 5px;
  z-index: 2;
  user-select: none;
  -webkit-user-select: none;

  .arrow {
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
    border-left: 4px solid var(--color-fg-secondary);
    float: right;
    left: 5px;
    pointer-events: none;
    position: relative;
    top: 5px;

    .submenu {
      display: none;
      margin: 0 3px;
      pointer-events: auto;
      position: absolute;
      overflow: hidden;
      transform: translate(7px, -18px);
      z-index: 3;
      border-radius: 5px;
      animation: shadow 200ms ease-in normal forwards;

      @keyframes shadow {
        0% {
          background: rgba(0, 0, 0, 0);
          box-shadow: none;
        }

        100% {
          background: rgba(0, 0, 0, 0.04);
          box-shadow:
            0 3px 6px -4px rgba(0, 0, 0, 0.12),
            0 6px 16px rgba(0, 0, 0, 0.08),
            0 9px 28px 8px rgba(0, 0, 0, 0.06);
        }
      }

      .open {
        background-color: var(--color-bg-primary);
        border-radius: 5px;
        color: var(--color-fg-on-popup);
        padding: 5px;
        right: 0;
        white-space: nowrap;

        &.left {
          position: relative;
          display: block;
          animation: left 200ms linear 1;
        }

        &.right {
          position: relative;
          display: block;
          animation: right 200ms linear 1;
        }

        @keyframes left {
          0% {
            transform: translateX(100%);
          }

          100% {
            transform: translateX(0%);
          }
        }

        @keyframes right {
          0% {
            transform: translateX(-100%);
          }

          100% {
            transform: translateX(0%);
          }
        }
      }
    }
  }

  .context-menuitem {
    font-size: 13px;
    list-style: none;
    padding: 5px 15px;

    &:hover:not(:disabled),
    &:focus:not(:disabled) {
      background-color: var(--color-bg-hover);
      border-radius: 6px;
      cursor: pointer;
    }

    &:disabled {
      color: var(--color-fg-disabled);
      cursor: none;
    }

    &.warning:hover {
      background-color: var(--color-bg-warn);
      color: var(--color-fg-warn);
    }
  }
}

.context-menu-separator {
  border-bottom: 1px solid var(--color-fg-secondary);
  margin-bottom: 10px;
  padding-bottom: 10px;
}

/// OVERFLOW MENU

.overflow-menu {
  background: var(--color-bg-popup);
  border-radius: 5px;
  color: var(--color-fg-on-popup);
  overflow: auto;
  padding: 10px;

  right: 0;
  margin: 6px;
  top: 50px;
  z-index: var(--z-index-popup);

  fieldset {
    border: 0;
    display: block;
    margin: 8px 0;

    ul {
      margin: 0;
      padding-left: 0;

      li {
        list-style-type: none;
      }

      a {
        cursor: pointer;
      }
    }
  }

  .table-row {
    align-items: center;
    border-radius: 6px;
    display: flex;
    padding: 3px 0;
  }

  legend {
    color: var(--color-fg-primary);
    font-weight: bolder;
    margin: 12px 0 4px;
  }

  button,
  label {
    color: var(--color-fg-primary);
    display: inline-flex;
    font-size: 1em;
    width: 100%;
  }

  button {
    background: transparent;
    border: 0;
    cursor: pointer;
    display: block;
    padding: 4px 0;
    text-align: left;
    text-decoration: none;
    width: 150px;
  }

  .input-and-label {
    align-items: center;
    display: inline-flex;
  }

  #display-options {
    display: flex;
    flex-direction: column;
  }

  #speed-options {
    display: flex;
    flex-direction: column;

    > .speed-up,
    > .speed-down {
      align-items: center;
      display: flex;
      padding: 4px 0;

      > label {
        overflow: hidden;
        width: 80px;
      }
    }

    .alt-speed {
      display: grid;
      gap: 4px;
      grid-template-areas:
        'check  text'
        'turtle parentheses';
    }

    :nth-child(1) {
      grid-area: check;

      &:not(:checked) ~ #alt-speed-image {
        filter: grayscale(100%) brightness(50%);
      }
    }

    :nth-child(2) {
      grid-area: text;
    }

    #alt-speed-image {
      background: var(--image-turtle) no-repeat;
      filter: hue-rotate(120deg) saturate(180%);
      grid-area: turtle;
      height: 18px;
    }

    :nth-child(4) {
      font-size: small;
      grid-area: parentheses;
    }
  }
}

/// DIALOGS

.dialog-buttons {
  display: flex;
  grid-area: buttons;
  margin: 10px 0 0;
  text-align: center;

  button {
    appearance: none;
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border-default);
    border-radius: 5px;
    color: var(--color-fg-primary);
    margin-left: 8px;
    padding: 8px;
    text-decoration: none;
  }
}

dialog {
  border: 0;
}

.dialog-container {
  max-width: 500px;
  top: 102px;
  width: calc(100vw - 20px);

  color: var(--color-fg-primary);
  display: block;
  padding: 0;
  z-index: var(--z-index-popup);

  border: 0;
  border-radius: 8px;
}

.dialog-heading {
  display: flex;
  font-size: 1.2em;
  font-weight: bold;
  grid-area: heading;
  overflow-wrap: anywhere;
}

.dialog-logo {
  background: transparent url('../img/logo.png') top left no-repeat;
  grid-area: icon;
  height: var(--logo-size);
  width: var(--logo-size);
}

.dialog-message {
  grid-area: message;
  width: 100%;
  margin: 10px 0 0;
}

.dialog-window {
  background-color: var(--color-bg-popup);
  color: var(--color-fg-on-popup);
  border-radius: 8px;
  padding: 20px;

  @include viewport-small {
    align-items: center;
    display: flex;
    flex-direction: column;
  }

  @include viewport-medium {
    display: grid;
    grid-column-gap: 12px;
    grid-template-areas:
      'icon heading'
      'icon message'
      'icon workarea'
      'icon buttons';
    grid-template-columns: var(--logo-size) 1fr;
  }
}

.dialog-workarea {
  width: 100%;
  display: flex;
  flex-direction: column;
  grid-area: workarea;
  margin: 10px 0 0;

  > * {
    margin-bottom: 5px;
  }
}

/// ABOUT DIALOG

.about-dialog .dialog-workarea > * {
  margin-bottom: 10px;
}

.about-dialog-version-number {
  margin-left: 4px;
}

.about-dialog-version-checksum {
  font-size: small;
  font-style: italic;
  font-weight: normal;
  margin-left: auto;
  padding-left: 10px;
}

/// OPEN TORRENT DIALOG
.open-torrent {
  input {
    margin-bottom: 15px;

    &[type='file'] {
      width: 100%;
      box-sizing: border-box;
    }
  }

  #auto-start-label {
    margin-left: 5px;
  }
}

/// HOTKEYS DIALOG

.shortcuts-dialog {
  table {
    border-collapse: collapse;
    width: 100%;
  }

  th,
  td {
    border: 1px solid var(--color-border-stark);
    padding: 5px 10px;
  }
}

/// SET-LOCATION DIALOG

#move-container #torrent-path {
  min-width: 400px;
}

/// STATISTICS DIALOG

.tabs-pages,
.inspector-info-page,
.statistics-dialog {
  .content {
    column-gap: 16px;
    display: grid;
    grid-row-gap: 6px;
    grid-template-columns: auto 1fr;
    margin: 4px 16px 16px;

    div {
      word-break: break-word;
    }
  }

  fieldset {
    border: 0;
    margin: 0;
    padding: 0;
  }

  legend {
    font-weight: bolder;
    margin-bottom: 4px;
  }

  span {
    overflow-wrap: anywhere;
  }
}

/// UPLOAD DIALOG

#free-space-text {
  display: inline-block;
  font-size: smaller;
  font-style: italic;
}

.upload-div {
  display: none;
}
