/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
 */

:root[titlepreface*="="] .titlebar-buttonbox-container {
  display: none !important;
}

@media (-moz-bool-pref: "uc.tweak.no-window-controls") {
  .titlebar-buttonbox-container {
    display: none !important;
  }
}

@media not (-moz-bool-pref: "uc.tweak.no-window-controls") {
  :root:not([inDOMFullscreen], [titlepreface*="="]) {
    & .titlebar-buttonbox-container {
      z-index: 100 !important;
      position: absolute !important;
      height: 40.5px !important;
    }
    &[uidensity="compact"] .titlebar-buttonbox-container {
      height: 34px !important;
    }
    &[uidensity="touch"] .titlebar-buttonbox-container {
      height: 44px !important;
    }

    #TabsToolbar {
      min-height: 0px !important;
    }

    &:not([sizemode="fullscreen"]) {
      @media (-moz-platform: macos) {
        #nav-bar {
          margin-left: 78px !important;
        }
        .titlebar-buttonbox-container {
          width: 78px !important;
          position: fixed !important;
          & .titlebar-buttonbox {
            margin-inline: 12px !important;
          }
        }
      }
    }

    @media (-moz-platform: windows) {
      .titlebar-buttonbox-container {
        top: 0 !important;
        right: 0 !important;
      }
      #nav-bar {
        margin-right: 138px !important;
      }
    }

    /* Linux */
    @media (-moz-gtk-csd-available) {
      &[lwtheme="true"] .titlebar-button > .toolbarbutton-icon {
        border-radius: var(--toolbarbutton-border-radius) !important;
        height: 32px !important;
        width: 32px !important;
      }
      &[lwtheme="true"][uidensity="compact"]
        .titlebar-button
        > .toolbarbutton-icon {
        height: 28px !important;
        width: 28px !important;
      }
      &[lwtheme="true"]:not([uidensity="compact"])
        .titlebar-button
        > .toolbarbutton-icon {
        margin-block: 3px !important;
      }

      @media (-moz-gtk-csd-minimize-button) or (-moz-gtk-csd-maximize-button) or (-moz-gtk-csd-close-button) {
        --gtk-window-button-width: var(--gtk-window-control-single);
      }
      @media ((-moz-gtk-csd-minimize-button) and (-moz-gtk-csd-maximize-button)) or ((-moz-gtk-csd-minimize-button) and (-moz-gtk-csd-close-button)) or ((-moz-gtk-csd-maximize-button) and (-moz-gtk-csd-close-button)) {
        --gtk-window-button-width: var(--gtk-window-control-dual);
      }

      @media (-moz-gtk-csd-minimize-button) and (-moz-gtk-csd-maximize-button) and (-moz-gtk-csd-close-button) {
        --gtk-window-button-width: var(--gtk-window-control-tri);
      }

      @media not (-moz-gtk-csd-reversed-placement) {
        #nav-bar {
          margin-right: var(--gtk-window-button-width) !important;
        }
        .titlebar-buttonbox-container {
          display: none !important;
          right: 0px;
        }
      }
      @media (-moz-gtk-csd-reversed-placement) {
        #nav-bar {
          margin-left: var(--gtk-window-button-width) !important;
        }
        .titlebar-buttonbox-container {
          left: 0px;
        }
      }
    }
    @media (-moz-platform: linux) and (not (-moz-gtk-csd-available)) {
      .titlebar-buttonbox-container {
        display: none !important;
      }
    }
  }
}
